Index: trunk/examples/advanced/hadrontherapy/include/CVS/Entries
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/CVS/Entries	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/CVS/Entries	(revision 1230)
@@ -0,0 +1,34 @@
+/Decay.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyAnalysisFileMessenger.hh/1.4/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyAnalysisManager.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyDetectorConstruction.hh/1.24/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyDetectorHit.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyDetectorMessenger.hh/1.15/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyDetectorROGeometry.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyDetectorSD.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyDummySD.hh/1.6/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyEventAction.hh/1.15/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyEventActionMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyGeometryController.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyGeometryMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyInteractionParameters.hh/1.5/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyMatrix.hh/1.6/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyModulator.hh/1.5/Thu Jun 29 15:58:08 2006//Tgeant4-09-03
+/HadrontherapyParameterMessenger.hh/1.5/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyParticles.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyPhysicsList.hh/1.21/Fri Jan  8 13:32:05 2010//Tgeant4-09-03
+/HadrontherapyPhysicsListMessenger.hh/1.9/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyPrimaryGeneratorAction.hh/1.17/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyPrimaryGeneratorMessenger.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyRunAction.hh/1.14/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyStepMax.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapyStepMaxMessenger.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/HadrontherapySteppingAction.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/IAEADetectorConstruction.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/IAEADetectorMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/IAEAScoreWriter.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/LocalINCLIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/LocalIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/PassiveProtonBeamLine.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+/PassiveProtonBeamLineMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-03
+D
Index: trunk/examples/advanced/hadrontherapy/include/CVS/Repository
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/CVS/Repository	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/CVS/Repository	(revision 1230)
@@ -0,0 +1,1 @@
+geant4/examples/advanced/hadrontherapy/include
Index: trunk/examples/advanced/hadrontherapy/include/CVS/Root
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/CVS/Root	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/CVS/Root	(revision 1230)
@@ -0,0 +1,1 @@
+:ext:lgarnier@geant4.cvs.cern.ch:/cvs/Geant4
Index: trunk/examples/advanced/hadrontherapy/include/CVS/Tag
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/CVS/Tag	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/CVS/Tag	(revision 1230)
@@ -0,0 +1,1 @@
+Ngeant4-09-03
Index: trunk/examples/advanced/hadrontherapy/include/Decay.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/Decay.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/Decay.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyDetectorMessenger.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// $Id: HadrontherapyDetectorMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 // ==============================
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisFileMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisFileMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisFileMessenger.hh	(revision 1230)
@@ -0,0 +1,74 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyAnalysisFileMessenger.hh.
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
+
+#ifndef HadrontherapyAnalysisFileMessenger_h
+#define HadrontherapyAnalysisFileMessenger_h 1
+
+#ifdef ANALYSIS_USE
+
+#include "G4UImessenger.hh"
+#include "globals.hh"
+
+class HadrontherapyAnalysisManager; ///< Provides SetanalysisFileName()
+class G4UIcmdWithAString; ///< Provides possibility to add commands
+
+/**
+* A messenger object of this class is created by the AnalysisManager.
+* The point of a messenger is to connect the G4UI with the simulation
+* functionality.
+* The messenger needs to contain a command object and to have SetValue
+* method that is called once a command is set.
+* 
+* @see HadrontherapyAnalysisManager
+*/
+class HadrontherapyAnalysisFileMessenger: public G4UImessenger
+{
+  public:
+    HadrontherapyAnalysisFileMessenger(HadrontherapyAnalysisManager*);
+   ~HadrontherapyAnalysisFileMessenger();
+
+	/**   
+	* Called when new command given.
+	* @param command is a pointer to the given command object
+	* @param newValue holds the argument given as a G4String
+	* @return is void   
+	*/     
+    void SetNewValue(G4UIcommand* command, G4String newValue);
+    
+  private:
+    HadrontherapyAnalysisManager* AnalysisManager; ///< handle to AnalysisManager
+
+	/**   
+	* G4 user interface command (that takes a string argument) object
+	* Constructor requires command name and messenger class(this).
+	*/ 
+    G4UIcmdWithAString* FileNameCmd;
+};
+
+#endif
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisManager.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisManager.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisManager.hh	(revision 1230)
@@ -24,101 +24,157 @@
 // ********************************************************************
 //
-// ----------------------------------------------------------------------------
-// $Id: HadrontherapyAnalysisManager.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
-
-#ifdef G4ANALYSIS_USE
+// HadrontherapyAnalysisManager.hh; May 2005
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
 #ifndef HADRONTHERAPYANALYSISMANAGER_HH
 #define HADRONTHERAPYANALYSISMANAGER_HH 1
 
 #include "globals.hh"
-# include <AIDA/AIDA.h>
+
+#ifdef ANALYSIS_USE ///< If we use analysis
+
+#ifdef G4ANALYSIS_USE ///< If analysis is done via AIDA
+#include <AIDA/AIDA.h>
 
 namespace AIDA{
-  class ITree; 
+  class ITree;
   class IAnalysisFactory;
   class ITreeFactory;
 }
-
+#endif
+
+#ifdef G4ANALYSIS_USE_ROOT ///< If analysis is done directly with ROOT
+#include "TROOT.h"
+#include "TFile.h"
+#include "TNtuple.h"
+#include "TH1F.h"
+#endif
+
+/**
+ * Messenger class for analysis-settings for HadronTherapyAnalysisManager 
+ */
+class HadrontherapyAnalysisFileMessenger;
+
+/**
+ * A class for connecting the simulation to an analysis package.
+ */
 class HadrontherapyAnalysisManager
 {
 private:
+	/**
+	 * Analysis manager is a singleton object (there is only one instance).
+	 * The pointer to this object is available through the use of the method getInstance();
+	 *
+	 * @see getInstance
+	 */
   HadrontherapyAnalysisManager();
-
+  
 public:
   ~HadrontherapyAnalysisManager();
+
+  /**
+   * Get the pointer to the analysis manager.
+   */
+  static HadrontherapyAnalysisManager* getInstance();
+
+  /**
+  * Book the histograms and ntuples in an AIDA or ROOT file.
+  */
+  void book();
+  /**
+   * Set name for the analysis file .root (used by macro)
+   */
+  void SetAnalysisFileName(G4String);
   
-  static HadrontherapyAnalysisManager* getInstance();
-  
-  void book();
-  // Book the histograms and ntuples in a .hbk file
-  
-  void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId, 
+  /**
+  * Fill the ntuple with the energy deposit in the phantom
+  */
+  void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId,
                          G4double energyDeposit);
-  // Fill the ntuple with the energy deposit in the phantom 
-
-  void BraggPeak(G4int, G4double);
-  // Fill 1D histogram with the Bragg peak in the phantom
+
+  void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom
 
   void SecondaryProtonEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary protons
+  ///< Fill 1D histogram with the energy deposit of secondary protons
 
    void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary neutrons
+  ///< Fill 1D histogram with the energy deposit of secondary neutrons
 
   void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary alpha particles
+  ///< Fill 1D histogram with the energy deposit of secondary alpha particles
 
   void SecondaryGammaEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary gamma
+  ///< Fill 1D histogram with the energy deposit of secondary gamma
 
   void SecondaryElectronEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary electrons
+  ///< Fill 1D histogram with the energy deposit of secondary electrons
 
   void SecondaryTritonEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary tritons
+  ///< Fill 1D histogram with the energy deposit of secondary tritons
 
   void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary deuterons
+  ///< Fill 1D histogram with the energy deposit of secondary deuterons
 
   void SecondaryPionEnergyDeposit(G4int slice, G4double energy);
-  // Fill 1D histogram with the energy deposit of secondary pions
+  ///< Fill 1D histogram with the energy deposit of secondary pions
 
   void electronEnergyDistribution(G4double secondaryParticleKineticEnergy);
-  // Energy distribution of secondary electrons originated in the phantom
+  ///< Energy distribution of secondary electrons originated in the phantom
 
   void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy);
-  // Energy distribution of secondary gamma originated in the phantom
+  ///< Energy distribution of secondary gamma originated in the phantom
 
   void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy);
-  // Energy distribution of secondary deuterons originated in the phantom
+  ///< Energy distribution of secondary deuterons originated in the phantom
 
   void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy);
-  // Energy distribution of secondary tritons originated in the phantom
+  ///< Energy distribution of secondary tritons originated in the phantom
 
   void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy);
-  // Energy distribution of secondary alpha originated in the phantom
+  ///< Energy distribution of secondary alpha originated in the phantom
+
+  void heliumEnergy(G4double secondaryParticleKineticEnergy);
+  ///< Energy distribution of the helium (He3 and alpha) particles after the phantom
+
+  void hydrogenEnergy(G4double secondaryParticleKineticEnergy);
+  ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom
+
+  void fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ);
+  ///< Energy ntuple
 
   void genericIonInformation(G4int, G4double, G4int, G4double);
- 
+
+  void ThintargetBeamDisp(G4double,G4double);
+
+  void startNewEvent();
+  ///< Tell the analysis manager that a new event is starting
+
+  void setGeometryMetaData(G4double, G4double, G4double);
+  ///< from the detector construction information about the geometry can be written as metadata
+
+  void setBeamMetaData(G4double, G4double);
+  ///< metadata about the beam can be written this way
+
   void finish();
-  // Close the .hbk file with the histograms and the ntuples
+  ///< Close the .hbk file with the histograms and the ntuples
+
+void flush();
+
+#ifdef G4ANALYSIS_USE_ROOT
+private:
+  TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) {
+    TH1F *histo = new TH1F(name, title, bins, xmin, xmax);
+    histo->SetLineWidth(2);
+    return histo;
+  }
+#endif
 
 private:
   static HadrontherapyAnalysisManager* instance;
+  HadrontherapyAnalysisFileMessenger* fMess;
+  G4String analysisFileName;
+#ifdef G4ANALYSIS_USE
   AIDA::IAnalysisFactory* aFact;
-  AIDA::ITree* theTree; 
+  AIDA::ITree* theTree;
   AIDA::IHistogramFactory *histFact;
   AIDA::ITupleFactory *tupFact;
@@ -129,16 +185,51 @@
   AIDA::IHistogram1D *h5;
   AIDA::IHistogram1D *h6;
-  AIDA::IHistogram1D *h7; 
-  AIDA::IHistogram1D *h8; 
+  AIDA::IHistogram1D *h7;
+  AIDA::IHistogram1D *h8;
   AIDA::IHistogram1D *h9;
   AIDA::IHistogram1D *h10;
   AIDA::IHistogram1D *h11;
-  AIDA::IHistogram1D *h12; 
-  AIDA::IHistogram1D *h13; 
+  AIDA::IHistogram1D *h12;
+  AIDA::IHistogram1D *h13;
   AIDA::IHistogram1D *h14;
+  AIDA::IHistogram1D *h15;
+  AIDA::IHistogram1D *h16;
   AIDA::ITuple *ntuple;
   AIDA::ITuple *ionTuple;
+  AIDA::ITuple *fragmentTuple;
+#endif
+#ifdef G4ANALYSIS_USE_ROOT
+  TFile *theTFile;
+  TH1F *histo1;
+  TH1F *histo2;
+  TH1F *histo3;
+  TH1F *histo4;
+  TH1F *histo5;
+  TH1F *histo6;
+  TH1F *histo7;
+  TH1F *histo8;
+  TH1F *histo9;
+  TH1F *histo10;
+  TH1F *histo11;
+  TH1F *histo12;
+  TH1F *histo13;
+  TH1F *histo14;
+  TH1F *histo15;
+  TH1F *histo16;
+  
+  TNtuple *theROOTNtuple;
+  TNtuple *theROOTIonTuple;
+  TNtuple *fragmentNtuple; // fragments
+  TNtuple *metaData;
+#endif
+  G4long eventCounter;      // Simulation metadata
+  G4double detectorDistance;
+  G4double phantomDepth;
+  G4double beamEnergy;
+  G4double energyError;
+  G4double phantomCenterDistance;
 };
 #endif
-#endif
-
+
+#endif
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorConstruction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorConstruction.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorConstruction.hh	(revision 1230)
@@ -24,120 +24,175 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyDetectorConstruction.hh; Version 4.0 May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyDetectorConstruction.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
 
 #ifndef HadrontherapyDetectorConstruction_H
 #define HadrontherapyDetectorConstruction_H 1
 
+#include "G4Box.hh"
 #include "globals.hh"
-#include "G4VUserDetectorConstruction.hh"
+#include "G4VisAttributes.hh"
+#include "G4LogicalVolume.hh"
+#include "G4UnitsTable.hh"
 
 class G4VPhysicalVolume;
 class G4LogicalVolume;
-class HadrontherapyPhantomROGeometry;
-class HadrontherapyBeamLine;
+class HadrontherapyDetectorROGeometry;
 class HadrontherapyDetectorMessenger;
-class HadrontherapyModulator;
-class HadrontherapyPhantomSD;
-class HadrontherapyMaterial;
+class HadrontherapyDetectorSD;
+class HadrontherapyMatrix;
 
-class HadrontherapyDetectorConstruction : public G4VUserDetectorConstruction
+class HadrontherapyDetectorConstruction 
 {
 public:
 
-  HadrontherapyDetectorConstruction();
+  HadrontherapyDetectorConstruction(G4VPhysicalVolume*);
 
   ~HadrontherapyDetectorConstruction();
 
-  G4VPhysicalVolume* Construct();  
 
 private: 
 
-  void ConstructBeamLine();
-  // This method allows to define the beam line geometry in the
-  // experimental set-up
+  void ConstructPhantom();
+  void ConstructDetector();
+  void ConstructSensitiveDetector(G4ThreeVector position_respect_to_WORLD);
+  
+public: 
+// Get detector position relative to WORLD
+inline G4ThreeVector GetDetectorToWorldPosition()
+  {
+    return phantomPosition + detectorPosition;
+  }
+/////////////////////////////////////////////////////////////////////////////
+// Get displacement between phantom and detector by detector position, phantom and detector sizes
+inline G4ThreeVector GetDetectorToPhantomPosition()
+{
+    return G4ThreeVector(phantomSizeX - detectorSizeX + detectorPosition.getX(),
+                         phantomSizeY - detectorSizeY + detectorPosition.getY(),
+                         phantomSizeZ - detectorSizeZ + detectorPosition.getZ()
+		          );
+}
 
- void ConstructPhantom(); 
- // This method allows to define the phantom geometry in the
- // experimental set-up
- 
- void ConstructSensitiveDetector();
-  // The sensitive detector is associated to the phantom volume
+/////////////////////////////////////////////////////////////////////////////
+// Calculate (and set) detector position by displacement, phantom and detector sizes
+inline void SetDetectorPosition()
+  {
+	  // Adjust detector position
+	  detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX + detectorSizeX);
+	  detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY + detectorSizeY);
+	  detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ + detectorSizeZ);
+     
+      if (detectorPhysicalVolume) detectorPhysicalVolume -> SetTranslation(detectorPosition); 
+  }
+/////////////////////////////////////////////////////////////////////////////
+// Check whether detector is inside phantom
+inline bool IsInside(G4double detectorHalfX,
+		     G4double detectorHalfY,
+		     G4double detectorHalfZ,
+		     G4double phantomHalfX,
+		     G4double phantomHalfY,
+		     G4double phantomHalfZ,
+		     G4ThreeVector detectorToPhantomPosition)
+{
+// Dimensions check... X Y and Z
+// Firstly check what dimension we are modifying
+	if (detectorHalfX > 0. && phantomHalfX > 0. && detectorToPhantomPosition.getX() >=0.)
+	{
+	    if (detectorHalfX > phantomHalfX) 
+		 {
+		    G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
+		    return false;
+		 }
+	    if ( 2*(phantomHalfX - detectorHalfX) < detectorToPhantomPosition.getX()) 
+	         {
+		    G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl;
+		    return false;
+	         }
+	}
 
-public: 
+	if (detectorHalfY > 0. && phantomHalfY > 0.&& detectorToPhantomPosition.getY() >=0.)
+	{
+	    if (detectorHalfY > phantomHalfY) 
+		 {
+		    G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
+		    return false;
+		 }
+	    if ( 2*(phantomHalfY - detectorHalfY) < detectorToPhantomPosition.getY()) 
+	     {
+		   G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl;
+		   return false;
+	     }
+	}			 
 
-  void SetModulatorAngle(G4double angle);
-  // This method allows moving the modulator through UI commands
+	if (detectorHalfZ > 0. && phantomHalfZ > 0.&& detectorToPhantomPosition.getZ() >=0.)
+	{
+	    if (detectorHalfZ > phantomHalfZ) 
+		 {
+		    G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl;
+		    return false;
+		 }
+	    if ( 2*(phantomHalfZ - detectorHalfZ) < detectorToPhantomPosition.getZ()) 
+	     {
+		   G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl;
+		   return false;
+	     }
+	}
+/*
+    G4cout << "Displacement between Phantom and Detector is: "; 
+    G4cout << "DX= "<< G4BestUnit(detectorToPhantomPosition.getX(),"Length") << 
+              "DY= "<< G4BestUnit(detectorToPhantomPosition.getY(),"Length") << 
+              "DZ= "<< G4BestUnit(detectorToPhantomPosition.getZ(),"Length") << G4endl;
+*/
+	return true;
+}
+/////////////////////////////////////////////////////////////////////////////
 
-  void SetRangeShifterXPosition(G4double translation);
-  // This method allows to move the Range Shifter along
-  // the X axis through UI commands
+  G4bool SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ);
+  G4bool SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ);
+  G4bool SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ);
+  G4bool SetPhantomPosition(G4ThreeVector);
+  G4bool SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition);
+  G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;}
 
-  void SetRangeShifterXSize(G4double halfSize);
-  // This method allows to change the size of the range shifter along
-  // the X axis through UI command.
 
-  void SetFirstScatteringFoilSize(G4double halfSize);
-  // This method allows to change the size of the first scattering foil
-  // along the X axis through UI command.
+private:
 
-  void SetSecondScatteringFoilSize (G4double halfSize); 
-  // This method allows to change the size of the second scattering foil
-  // along the X axis through UI command.
+  HadrontherapyDetectorMessenger* detectorMessenger; 
 
-  void SetOuterRadiusStopper (G4double value); 
-  // This method allows to change the size of the outer radius of the stopper
-  // through UI command.
+  G4VisAttributes* skyBlue;
+  G4VisAttributes* red;
 
-  void SetInnerRadiusFinalCollimator (G4double value);
-  // This method allows to change the size of the inner radius of the 
-  // final collimator through UI command.
+  G4VPhysicalVolume* motherPhys;
 
-  void SetRSMaterial(G4String material);
-  // This method allows to change the material 
-  // of the range shifter through UI command.
+  HadrontherapyDetectorSD*         detectorSD; // Pointer to sensitive detector
+  HadrontherapyDetectorROGeometry* detectorROGeometry; // Pointer to ROGeometry 
+  HadrontherapyMatrix*             matrix;
 
-  G4double ComputeVoxelSize() {return phantomSizeX/numberOfVoxelsAlongX;};
-  // Returns the size of the voxel along the X axis
- 
-private:
+  G4VPhysicalVolume* phantomPhysicalVolume;
+  G4LogicalVolume*   phantomLogicalVolume; 
+  G4LogicalVolume*   detectorLogicalVolume;
+  G4VPhysicalVolume* detectorPhysicalVolume;
   
-  HadrontherapyPhantomSD* phantomSD; // Pointer to sensitive detector
-
-  HadrontherapyPhantomROGeometry* phantomROGeometry; // Pointer to ROGeometry 
-
-  HadrontherapyBeamLine* beamLine; // Pointer to the beam line 
-                                   // geometry component
-
-  HadrontherapyModulator* modulator; // Pointer to the modulator 
-                                     // geometry component
-
-  G4VPhysicalVolume* physicalTreatmentRoom;
-  G4VPhysicalVolume* patientPhysicalVolume;
-  G4LogicalVolume* phantomLogicalVolume;
-  G4VPhysicalVolume* phantomPhysicalVolume;
-  
-  HadrontherapyDetectorMessenger* detectorMessenger; 
-  HadrontherapyMaterial* material;
-
   G4double phantomSizeX; 
   G4double phantomSizeY; 
   G4double phantomSizeZ;
-   
+
+  G4double detectorSizeX; 
+  G4double detectorSizeY; 
+  G4double detectorSizeZ;
+
+  G4ThreeVector phantomPosition, detectorPosition, detectorToPhantomPosition; //  phantom center, detector center, detector to phantom relative position
+
+  G4double sizeOfVoxelAlongX; 
+  G4double sizeOfVoxelAlongY; 
+  G4double sizeOfVoxelAlongZ; 
+
   G4int numberOfVoxelsAlongX; 
   G4int numberOfVoxelsAlongY;
   G4int numberOfVoxelsAlongZ;  
+
+  G4Box* phantom;
+  G4Box* detector;
+
 };
 #endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorHit.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorHit.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorHit.hh	(revision 1230)
@@ -0,0 +1,101 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyDetectorHit.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
+
+#ifndef HadrontherapyDetectorHit_h
+#define HadrontherapyDetectorHit_h 1
+
+#include "G4VHit.hh"
+#include "G4THitsCollection.hh"
+#include "G4Allocator.hh"
+
+class HadrontherapyDetectorHit : public G4VHit
+{
+public:
+  HadrontherapyDetectorHit();
+  ~HadrontherapyDetectorHit();
+ 
+  HadrontherapyDetectorHit(const HadrontherapyDetectorHit &right);
+ 
+  const HadrontherapyDetectorHit& operator = (const HadrontherapyDetectorHit &right);
+ 
+  int operator == (const HadrontherapyDetectorHit &right) const;
+
+  inline void *operator new(size_t);
+  inline void operator delete(void *aHit);
+
+private:
+  G4int xHitID; // Hit x voxel 
+  G4int zHitID; // Hit z voxel
+  G4int yHitID; // Hit y voxel 
+  G4double energyDeposit; // Energy deposit associated with the hit
+
+public:
+  // Methods to get the information - energy deposit and associated
+  // position in the phantom - of the hits stored in the hits collection  
+ 
+  inline G4int GetXID() // Get x index of the voxel 
+  {return xHitID;}
+
+  inline G4int GetZID() // Get y index of the voxel   
+  {return zHitID;}
+
+  inline G4int GetYID() // Get z index of the voxel  
+  {return yHitID;}
+   
+  inline G4double GetEdep() // Get energy deposit
+  {return energyDeposit;}
+ 
+  // Methods to store the information of the hit ( energy deposit, position in the phantom )
+  // in the hits collection
+
+  inline void SetEdepAndPosition(G4int xx, G4int yy, G4int zz, G4double eDep)
+  {
+    xHitID = xx;
+    yHitID = yy;
+    zHitID = zz;
+    energyDeposit = eDep;
+  }
+};
+
+typedef G4THitsCollection<HadrontherapyDetectorHit> HadrontherapyDetectorHitsCollection;
+extern G4Allocator<HadrontherapyDetectorHit> HadrontherapyDetectorHitAllocator;
+
+inline void* HadrontherapyDetectorHit::operator new(size_t)
+{
+  void *aHit;
+  aHit = (void *) HadrontherapyDetectorHitAllocator.MallocSingle();
+  return aHit;
+}
+
+inline void HadrontherapyDetectorHit::operator delete(void *aHit)
+{
+  HadrontherapyDetectorHitAllocator.FreeSingle((HadrontherapyDetectorHit*) aHit);
+}
+#endif
+
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorMessenger.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorMessenger.hh	(revision 1230)
@@ -24,18 +24,7 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyDetectorMessenger.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyDetectorMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//
+
 #ifndef HadrontherapyDetectorMessenger_h
 #define HadrontherapyDetectorMessenger_h 1
@@ -48,4 +37,5 @@
 class G4UIcmdWithADoubleAndUnit;
 class G4UIcmdWithAString;
+class G4UIcmdWith3VectorAndUnit;
 
 class HadrontherapyDetectorMessenger: public G4UImessenger
@@ -55,59 +45,18 @@
   ~HadrontherapyDetectorMessenger();
     
-    void SetNewValue(G4UIcommand*, G4String);
+  void SetNewValue(G4UIcommand*, G4String);
     
 private:
 
-  // Pointer to the detector component
+  // Pointer to the phantom/detector 
   HadrontherapyDetectorConstruction* hadrontherapyDetector;
-  
-  G4UIdirectory* modulatorDir; // Control of the modulator 
-  G4UIdirectory* beamLineDir;  // Control of the beam line
- 
-  G4UIdirectory* rangeShifterDir; 
-  // Control of the range shifter component of the beam line
 
-  G4UIdirectory* firstScatteringFoilDir;
-  // Control of the first scattering foil component of the beam line
-  
-  G4UIdirectory* secondScatteringFoilDir;
-  // Control of the first scattering foil component of the beam line
-  
-  G4UIdirectory* rangeStopperDir;
-  // Control of the range stopper component of the beam line
-  
-  G4UIdirectory* finalCollimatorDir;
-  // Control of the final collimator component of the beam line
-  
-  G4UIcmdWithADoubleAndUnit* modulatorAngleCmd;
-  // UI command to rotate the modulator wheel
+  G4UIdirectory *changeThePhantomDir,  *changeTheDetectorDir; 
 
-  G4UIcmdWithAString*   rangeShifterMatCmd;
-  // UI command to set the material of the rangeShifter component of 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* rangeShifterXSizeCmd;
-  // UI command to set half of the X size of the rangeShifter component of 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* rangeShifterXPositionCmd;
-  // UI command to change the X position of the rangeShifter component of 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* firstScatteringFoilXSizeCmd;
-  // UI command to set half X size of the first scattering foil of 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* secondScatteringFoilXSizeCmd;
-  // UI command to set half X size of the second scattering foil 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* outerRadiusStopperCmd;
-  // UI command to set the outer radius of the range stopper component of 
-  // the beam line 
-
-  G4UIcmdWithADoubleAndUnit* innerRadiusFinalCollimatorCmd;
-  // UI command to set the inner radius of the final collimator component of 
-  // the beam line 
+  G4UIcmdWith3VectorAndUnit *changeThePhantomSizeCmd,
+			    *changeThePhantomPositionCmd, 
+			    *changeTheDetectorSizeCmd, 
+			    *changeTheDetectorToPhantomPositionCmd,
+			    *changeTheDetectorVoxelCmd;
 };
 #endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorROGeometry.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorROGeometry.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorROGeometry.hh	(revision 1230)
@@ -0,0 +1,66 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyDetectorROGeometry.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+//The detectior is devided in voxels. 
+//
+//
+#ifndef HadrontherapyDetectorROGeometry_h
+#define HadrontherapyDetectorROGeometry_h 
+
+#include "G4VReadOutGeometry.hh"
+
+class HadrontherapyDetectorROGeometry : public G4VReadOutGeometry
+{
+public:
+  HadrontherapyDetectorROGeometry(G4String aString,
+		         G4ThreeVector detectorPos,
+				 G4double detectorDimX,
+				 G4double detectorDimY,
+				 G4double detectorDimZ,
+				 G4int numberOfVoxelsX,
+				 G4int numberOfVoxelsY,
+				 G4int numberOfVoxelsZ);
+
+  ~HadrontherapyDetectorROGeometry();
+
+private:
+  G4VPhysicalVolume* Build();
+
+private:  
+  const G4ThreeVector detectorToWorldPosition; 
+  const G4double detectorSizeX;
+  const G4double detectorSizeY; 
+  const G4double detectorSizeZ;
+
+  const G4int numberOfVoxelsAlongX;
+  const G4int numberOfVoxelsAlongY; 
+  const G4int numberOfVoxelsAlongZ; 
+  
+  G4VPhysicalVolume *RODetectorZDivisionPhys;
+};
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorSD.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorSD.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorSD.hh	(revision 1230)
@@ -0,0 +1,57 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: HadrontherapyDetectorSD.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyDetectorSD_h
+#define HadrontherapyDetectorSD_h 1
+
+#include "G4VSensitiveDetector.hh"
+#include "HadrontherapyDetectorHit.hh"
+#include "globals.hh"
+
+class G4Step;
+class G4HCofThisEvent;
+class G4TouchableHistory;
+class HadrontherapyDetectorSD : public G4VSensitiveDetector
+{
+public:
+  HadrontherapyDetectorSD(G4String name);
+  ~HadrontherapyDetectorSD();
+
+  void Initialize(G4HCofThisEvent*);
+ 
+  G4bool ProcessHits(G4Step*aStep,G4TouchableHistory*ROhist);
+ 
+  void EndOfEvent(G4HCofThisEvent*HCE);
+ 
+private:
+  HadrontherapyDetectorHitsCollection *HitsCollection;
+  G4String sensitiveDetectorName;	
+};
+#endif
+
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyDummySD.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyDummySD.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyDummySD.hh	(revision 1230)
@@ -24,17 +24,6 @@
 // ********************************************************************
 //
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// --------------------------------------------------------------
+// HadrontherapyDummySD.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyDummySD_h
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventAction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventAction.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventAction.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyEventAction.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// --------------------------------------------------------------
+// HadrontherapyEventAction.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyEventAction_h
@@ -46,9 +34,10 @@
 
 class HadrontherapyMatrix;
+class HadrontherapyEventActionMessenger;
 
 class HadrontherapyEventAction : public G4UserEventAction
 {
 public:
-  HadrontherapyEventAction(HadrontherapyMatrix*);
+  HadrontherapyEventAction();
   ~HadrontherapyEventAction();
 
@@ -56,9 +45,21 @@
   void BeginOfEventAction(const G4Event*);
   void EndOfEventAction(const G4Event*);
-    
+
+  void SetPrintModulo(G4int val)
+  {
+    printModulo = val;
+  };
+
+  void SetDrawFlag(G4String val)
+  {
+    drawFlag = val;
+  };
+
 private: 
   G4String drawFlag; //Visualisation flag
   G4int hitsCollectionID;
   HadrontherapyMatrix *matrix; 
+  G4int printModulo;  
+  HadrontherapyEventActionMessenger* pointerEventMessenger;
 };
 
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventActionMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventActionMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventActionMessenger.hh	(revision 1230)
@@ -0,0 +1,55 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyEventActionMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyEventActionMessenger_h
+#define HadrontherapyEventActionMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class HadrontherapyEventAction;
+class G4UIdirectory;
+class G4UIcmdWithAString;
+class G4UIcmdWithAnInteger;
+
+class HadrontherapyEventActionMessenger: public G4UImessenger
+{
+  public:
+    HadrontherapyEventActionMessenger(HadrontherapyEventAction*);
+   ~HadrontherapyEventActionMessenger();
+    
+    void SetNewValue(G4UIcommand*, G4String);
+    
+  private:
+    HadrontherapyEventAction*          eventAction;
+    G4UIdirectory*        eventDir;        
+    G4UIcmdWithAString*   DrawCmd;
+    G4UIcmdWithAnInteger* PrintCmd;    
+};
+
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryController.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryController.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryController.hh	(revision 1230)
@@ -0,0 +1,58 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyGeometryController.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyGeometryController_hh
+#define HadrontherapyGeometryController_hh 1
+
+#include "globals.hh"
+#include "G4String.hh"
+#include "G4VUserDetectorConstruction.hh"
+
+/**
+ * Controller for geometry selection
+ *
+ * This controller is called by the geometry messenger and used to
+ * select the geometry. Each available geometry must have unique name
+ * and it must be known by the geometry controller.
+ */
+class HadrontherapyGeometryController
+{
+public:
+  HadrontherapyGeometryController();
+  ~HadrontherapyGeometryController();
+
+  /**
+   * Select a geometry by name.
+   */
+  void SetGeometry(G4String);
+
+private:
+  void registerGeometry(G4VUserDetectorConstruction *detector);
+};
+
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyGeometryMessenger.hh	(revision 1230)
@@ -0,0 +1,58 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: HadrontherapyGeometryMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyGeometryMessenger_h
+#define HadrontherapyGeometryMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+#include "G4String.hh"
+
+class HadrontherapyGeometryController;
+class G4UIdirectory;
+class G4UIcmdWithADoubleAndUnit;
+class G4UIcmdWithAString;
+
+class HadrontherapyGeometryMessenger: public G4UImessenger
+{
+  public:
+  HadrontherapyGeometryMessenger(HadrontherapyGeometryController* );
+  ~HadrontherapyGeometryMessenger();
+    
+  void SetNewValue(G4UIcommand*, G4String);
+    
+private:
+
+  // Pointer to the detector component
+  HadrontherapyGeometryController* hadrontherapyGeometryController;
+
+  G4UIdirectory *changeTheGeometryDir;      ///> UI directory for the geometry control
+  G4UIcmdWithAString *changeTheGeometryCmd; ///> Select the geometry
+};
+#endif
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyInteractionParameters.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyInteractionParameters.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyInteractionParameters.hh	(revision 1230)
@@ -0,0 +1,71 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: HadrontherapyInteractionParameters.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyInteractionParameters_H
+#define HadrontherapyInteractionParameters_H 1
+
+#include "G4EmCalculator.hh"
+#include "G4NistMaterialBuilder.hh"
+#include "G4NistElementBuilder.hh"
+
+class HadrontherapyDetectorConstruction;
+class HadrontherapyParameterMessenger; 
+class HadrontherapyInteractionParameters : public G4EmCalculator 
+{
+public:
+
+    HadrontherapyInteractionParameters();
+	~HadrontherapyInteractionParameters();
+
+// Get data for Mass SP (MeV*cm2/g)   
+// G4NistMaterialBuilder class materials
+// User must provide: material kinetic energy lower limit, kinetic energy upper limit, number of points to retrieve,
+// [particle], [output filename].
+
+    bool GetStoppingTable (const G4String& vararg);
+    void ListOfNistMaterials (const G4String& vararg);
+    void BeamOn();
+    bool ParseArg (const G4String& vararg);	
+
+private:
+    G4Material* GetNistMaterial(G4String material);
+
+    G4NistElementBuilder* nistEle;
+    G4NistMaterialBuilder* nistMat;
+    G4double kinEmin, kinEmax, npoints;
+    G4String particle, material, filename; 
+    std::ofstream outfile;
+    std::ostream data;
+    G4Material* Pmaterial;
+    G4double density;
+    G4EmCalculator* emCal;
+    HadrontherapyParameterMessenger* pMessenger; 
+    bool beamFlag;
+};
+#endif
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyMatrix.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyMatrix.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyMatrix.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyMatrix.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyMatrix.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyMatrix_H
@@ -43,4 +31,5 @@
 
 #include "globals.hh"
+#include <vector>
 
 // The information: energy deposit and position in the phantom
@@ -49,11 +38,20 @@
 class HadrontherapyMatrix 
 {
+private:
+  HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ); //<--- this is supposed to be a singleton
+
 public:
-  HadrontherapyMatrix();
+
   ~HadrontherapyMatrix();
+// Get object instance only
+  static HadrontherapyMatrix* getInstance();
+// Make & Get instance
+  static HadrontherapyMatrix* getInstance(G4int nX, G4int nY, G4int nZ);
+ 
+  void flush();
  
   void Initialize(); 
   // All the elements of the matrix are initialised to zero
- 
+   
   void Fill(G4int i, G4int j, G4int k, G4double energyDeposit);
   // The matrix is filled with the energy deposit 
@@ -64,6 +62,11 @@
   // Store the information of the matrix in a ntuple and in 
   // a 1D Histogram
+  
+  inline G4int Index(G4int i, G4int j, G4int k){ return (i * numberVoxelY + j) * numberVoxelZ + k; } 
+  // Get a unique index from a three dimensional voxel information
 
 private:
+
+  static HadrontherapyMatrix* instance;
   G4int numberVoxelX;
   G4int numberVoxelY;
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyParameterMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyParameterMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyParameterMessenger.hh	(revision 1230)
@@ -0,0 +1,56 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyParametersMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyParameterMessenger_h
+#define HadrontherapyParameterMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class HadrontherapyInteractionParameters;
+class G4UIdirectory;
+//class G4UIcmdWithADoubleAndUnit;
+class G4UIcmdWithAString;
+class G4UIcmdWithoutParameter;
+
+class HadrontherapyParameterMessenger : public G4UImessenger
+{
+    public:
+    HadrontherapyParameterMessenger(HadrontherapyInteractionParameters* );
+    ~HadrontherapyParameterMessenger();
+
+    void SetNewValue(G4UIcommand*, G4String);
+
+    private:
+    HadrontherapyInteractionParameters* pParam;
+
+    G4UIdirectory           *paramDir;
+    G4UIcmdWithAString      *dedxCmd, *listCmd;  
+
+};
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyParticles.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyParticles.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyParticles.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyParticles.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyParticles.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HADRONTHERAPYPARTICLES_HH
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsList.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsList.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsList.hh	(revision 1230)
@@ -24,24 +24,16 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyPhysicsList.hh,v 1.0
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
-#ifndef HADRONTHERAPYPHYSICSLIST_H
-#define HADRONTHERAPYPHYSICSLIST_H 1
+// HadrontherapyPhysicsList.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyPhysicsList_h
+#define HadrontherapyPhysicsList_h 1
 
 #include "G4VModularPhysicsList.hh"
+#include "G4EmConfigurator.hh"
 #include "globals.hh"
 
+class G4VPhysicsConstructor;
+class HadrontherapyStepMax;
 class HadrontherapyPhysicsListMessenger;
 
@@ -49,28 +41,45 @@
 {
 public:
+
   HadrontherapyPhysicsList();
   virtual ~HadrontherapyPhysicsList();
 
-  virtual void SetCuts();
-  void AddPhysicsList(const G4String& name);  
-  
+  void ConstructParticle();
+
+  void SetCuts();
+  void SetCutForGamma(G4double);
+  void SetCutForElectron(G4double);
+  void SetCutForPositron(G4double);
+
+  void AddPhysicsList(const G4String& name);
+  void ConstructProcess();
+
+  void AddStepMax();
+  HadrontherapyStepMax* GetStepMaxProcess() {return stepMaxProcess;};
+  void AddPackage(const G4String& name);
+
 private:
-  G4bool decayIsRegistered;
-  G4bool emElectronIsRegistered;
-  G4bool emPositronIsRegistered;
-  G4bool emPhotonIsRegistered;
-  G4bool emIonIsRegistered;
-  G4bool emMuonIsRegistered;
-  G4bool hadrElasticHadronIonIsRegistered;
-  G4bool hadrInelasticPionIsRegistered;
-  G4bool hadrInelasticIonIsRegistered;
-  G4bool hadrInelasticProtonNeutronIsRegistered;
-  G4bool hadrAtRestMuonIsRegistered;
 
-  HadrontherapyPhysicsListMessenger* messenger;
+  G4EmConfigurator em_config;
+
+  G4double cutForGamma;
+  G4double cutForElectron;
+  G4double cutForPositron;
+
+  G4bool helIsRegisted;
+  G4bool bicIsRegisted;
+  G4bool biciIsRegisted;
+  G4bool locIonIonInelasticIsRegistered;
+  G4bool radioactiveDecayIsRegisted;
+
+  G4String                             emName;
+  G4VPhysicsConstructor*               emPhysicsList;
+  G4VPhysicsConstructor*               decPhysicsList;
+  std::vector<G4VPhysicsConstructor*>  hadronPhys;
+
+  HadrontherapyStepMax* stepMaxProcess;
+
+  HadrontherapyPhysicsListMessenger* pMessenger;
 };
 
 #endif
-
-
-
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsListMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsListMessenger.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsListMessenger.hh	(revision 1230)
@@ -24,21 +24,9 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyPhisicsListMessenger.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyPhysicsListsMessenger.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
-#ifndef HADRONTHERAPYPHYSICSLISTMESSENGER_HH
-#define HADRONTHERAPYPHYSICSLISTMESSENGER_HH 1
+#ifndef HadrontherapyPhysicsListMessenger_h
+#define HadrontherapyPhysicsListMessenger_h 1
 
 #include "globals.hh"
@@ -47,34 +35,33 @@
 class HadrontherapyPhysicsList;
 class G4UIdirectory;
-class G4UIcmdWithoutParameter;
-class G4UIcmdWithADouble;
 class G4UIcmdWithADoubleAndUnit;
-class G4UIcmdWithABool;
 class G4UIcmdWithAString;
 
-class HadrontherapyPhysicsListMessenger: public G4UImessenger {
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
-public:
+class HadrontherapyPhysicsListMessenger: public G4UImessenger
+{
+  public:
   
-  HadrontherapyPhysicsListMessenger(HadrontherapyPhysicsList* physList);
+    HadrontherapyPhysicsListMessenger(HadrontherapyPhysicsList* );
+   ~HadrontherapyPhysicsListMessenger();
+    
+    void SetNewValue(G4UIcommand*, G4String);
+    
+  private:
   
-  ~HadrontherapyPhysicsListMessenger();
-  
-  void SetNewValue(G4UIcommand*, G4String);
-  
-private:
-  
-  HadrontherapyPhysicsList* physicsList;   
-  G4UIdirectory* listDir;
-  G4UIcmdWithAString* physicsListCmd;
+  HadrontherapyPhysicsList* pPhysicsList;
+    
+  G4UIdirectory*             physDir;        
+  G4UIcmdWithADoubleAndUnit* gammaCutCmd;
+  G4UIcmdWithADoubleAndUnit* electCutCmd;
+  G4UIcmdWithADoubleAndUnit* protoCutCmd;    
+  G4UIcmdWithADoubleAndUnit* allCutCmd;    
+  G4UIcmdWithAString*        pListCmd;
+  G4UIcmdWithAString* packageListCmd;    
 };
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
 #endif
 
-
-
-
-
-
-
-
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorAction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorAction.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorAction.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyPrimaryGeneratorAction.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyPrimaryGeneratorAction.hh; May 2005
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyPrimaryGeneratorAction_h
@@ -68,4 +56,5 @@
   void SetsigmaMomentumY(G4double);
   void SetsigmaMomentumZ(G4double);
+  G4double GetmeanKineticEnergy(void);
     
 private:
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorMessenger.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorMessenger.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyPrimaryGeneratorMessenger.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the National Institute for Nuclear Physics, Catania, Italy
-// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyPrimaryGeneratorMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyPrimaryGeneratorMessenger_h
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyRunAction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyRunAction.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyRunAction.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyRunAction.hh,v 3.0, September 2004;
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyRunAction.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapyRunAction_h
@@ -51,8 +39,4 @@
 class HadrontherapyRunMessenger;
 class HadrontherapyFactory;
-class HadrontherapyFactoryIr;
-class HadrontherapyFactoryI;
-
-
 
 class HadrontherapyRunAction : public G4UserRunAction
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMax.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMax.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMax.hh	(revision 1230)
@@ -0,0 +1,67 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyStepMax.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyStepMax_h
+#define HadrontherapyStepMax_h 1
+
+#include "globals.hh"
+#include "G4VDiscreteProcess.hh"
+#include "G4ParticleDefinition.hh"
+#include "G4Step.hh"
+
+class HadrontherapyStepMaxMessenger;
+
+/////////////////////////////////////////////////////////////////////////////
+class HadrontherapyStepMax : public G4VDiscreteProcess
+{
+  public:     
+
+     HadrontherapyStepMax(const G4String& processName ="UserStepMax");
+    ~HadrontherapyStepMax();
+
+     G4bool   IsApplicable(const G4ParticleDefinition&);    
+     void     SetMaxStep(G4double);
+     G4double GetMaxStep() {return MaxChargedStep;};
+     
+     G4double PostStepGetPhysicalInteractionLength( const G4Track& track,
+			                     G4double   previousStepSize,
+			                     G4ForceCondition* condition);
+
+     G4VParticleChange* PostStepDoIt(const G4Track&, const G4Step&);
+
+     G4double GetMeanFreePath(const G4Track&, G4double, G4ForceCondition*)
+       {return 0.;};     // it is not needed here !
+
+  private:
+
+     G4double    MaxChargedStep;
+     HadrontherapyStepMaxMessenger* pMess;
+};
+
+#endif
+
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMaxMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMaxMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapyStepMaxMessenger.hh	(revision 1230)
@@ -0,0 +1,52 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyStepMaxMessenger.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyStepMaxMessenger_h
+#define HadrontherapyStepMaxMessenger_h 1
+
+#include "G4UImessenger.hh"
+#include "globals.hh"
+
+class HadrontherapyStepMax;
+class G4UIcmdWithADoubleAndUnit;
+
+/////////////////////////////////////////////////////////////////////////////
+class HadrontherapyStepMaxMessenger: public G4UImessenger
+{
+  public:
+    HadrontherapyStepMaxMessenger(HadrontherapyStepMax*);
+   ~HadrontherapyStepMaxMessenger();
+    
+    void SetNewValue(G4UIcommand*, G4String);
+    
+  private:
+    HadrontherapyStepMax* stepMax;
+    G4UIcmdWithADoubleAndUnit* StepMaxCmd;
+};
+
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/HadrontherapySteppingAction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/HadrontherapySteppingAction.hh	(revision 812)
+++ trunk/examples/advanced/hadrontherapy/include/HadrontherapySteppingAction.hh	(revision 1230)
@@ -24,18 +24,6 @@
 // ********************************************************************
 //
-// $Id: HadrontherapyProtonSteppingAction.hh; May 2005
-// ----------------------------------------------------------------------------
-//                 GEANT 4 - Hadrontherapy example
-// ----------------------------------------------------------------------------
-// Code developed by:
-//
-// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
-// 
-// (a) Laboratori Nazionali del Sud 
-//     of the INFN, Catania, Italy
-// (b) INFN Section of Genova, Genova, Italy
-// 
-// * cirrone@lns.infn.it
-// ----------------------------------------------------------------------------
+// HadrontherapyProtonSteppingAction.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
 
 #ifndef HadrontherapySteppingAction_h
Index: trunk/examples/advanced/hadrontherapy/include/IAEADetectorConstruction.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/IAEADetectorConstruction.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/IAEADetectorConstruction.hh	(revision 1230)
@@ -0,0 +1,123 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// IAEADetectorConstruction.hh; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef IAEADetectorConstruction_H
+#define IAEADetectorConstruction_H 1
+
+#include "globals.hh"
+#include "G4VUserDetectorConstruction.hh"
+#include "G4VisAttributes.hh"
+class G4VPhysicalVolume;
+class G4LogicalVolume;
+class HadrontherapyDetectorROGeometry;
+class PassiveProtonBeamLine;
+class IAEADetectorMessenger;
+class HadrontherapyModulator;
+class HadrontherapyDetectorSD;
+
+/**
+ * Geometry for the IAEA benchmark
+ *
+ * This geometry includes two main components: water target and a
+ * detector that counts the particles that go through the phantom.
+ *
+ */
+class IAEADetectorConstruction : public G4VUserDetectorConstruction
+{
+public:
+
+  IAEADetectorConstruction();
+
+  ~IAEADetectorConstruction();
+
+  G4VPhysicalVolume* Construct();  
+
+private: 
+  void ConstructPassiveProtonBeamLine();
+  void ConstructDetector();
+ 
+  void ConstructSensitiveDetector();
+
+ 
+  //  G4VisAttributes* redWire;
+  
+public: 
+  void setWaterThickness(G4double); //< sets thickness of water phantom, zero or negative value removes phantom and plexiedges from the simulation.
+  G4double ComputeVoxelSize() {return detectorSizeX/numberOfVoxelsAlongX;};
+  //<Returns the size of the voxel along the X axis
+ 
+private:
+  G4VisAttributes* skyBlue;
+  G4VisAttributes* red;
+
+  G4String emName;
+  HadrontherapyDetectorSD* detectorSD; //<Pointer to sensitive detector
+
+  HadrontherapyDetectorROGeometry* detectorROGeometry; //<Pointer to ROGeometry 
+
+  PassiveProtonBeamLine* passiveProtonBeamLine; //<Pointer to the beam line 
+                                   // geometry component
+
+  HadrontherapyModulator* modulator; // Pointer to the modulator 
+                                     // geometry component
+
+  G4VPhysicalVolume* physicalTreatmentRoom;
+  G4VPhysicalVolume* phantomPhysicalVolume;
+  G4VPhysicalVolume* phantomEdge1PhysicalVolume;
+  G4VPhysicalVolume* phantomEdge2PhysicalVolume;
+  
+  G4LogicalVolume* detectorLogicalVolume;
+  G4LogicalVolume* beamWindowLogicalVolume; //<Logical volume for beam source window
+  G4LogicalVolume* NewDetectorLogicalVolume; //<Logical volume for end-detector
+  
+  G4VPhysicalVolume* detectorPhysicalVolume;
+  G4VPhysicalVolume* beamWindowPhysicalVolume; ///<Logical volume for end-detector
+  G4VPhysicalVolume* NewDetectorPhysicalVolume; ///<Physical volume for end-detector
+
+  G4double startDetectorThickness;
+  G4double phantomCenter;
+  G4double phantomDepth;
+  G4double plexiThickness;
+  G4double aluWindowThickness;
+  G4double endDetectorThickness;
+  G4double endDetectorPosition;
+  G4double moveEndDetectorForward;
+
+  IAEADetectorMessenger* detectorMessenger; 
+
+  G4double detectorSizeX; 
+  G4double detectorSizeY; 
+  G4double detectorSizeZ;
+   
+  G4int numberOfVoxelsAlongX; 
+  G4int numberOfVoxelsAlongY;
+  G4int numberOfVoxelsAlongZ; 
+ 
+  G4bool noPhantom; //<If true no water-phantom is constructed
+};
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/IAEADetectorMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/IAEADetectorMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/IAEADetectorMessenger.hh	(revision 1230)
@@ -0,0 +1,56 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyDetectorMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef IAEADetectorMessenger_h
+#define IAEADetectorMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class IAEADetectorConstruction;
+class G4UIdirectory;
+class G4UIcmdWithADoubleAndUnit;
+
+class IAEADetectorMessenger: public G4UImessenger
+{
+  public:
+  IAEADetectorMessenger(IAEADetectorConstruction* );
+  ~IAEADetectorMessenger();
+    
+    void SetNewValue(G4UIcommand*, G4String);
+    
+private:
+
+  // Pointer to the detector component
+  IAEADetectorConstruction* IAEADetector;
+
+  G4UIcmdWithADoubleAndUnit* setIAEAWaterPhantomThicknessCmd;
+  //< UI command to set the thickness of the water phantom (also moves other objects accordingly)
+};
+#endif
+
Index: trunk/examples/advanced/hadrontherapy/include/IAEAScoreWriter.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/IAEAScoreWriter.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/IAEAScoreWriter.hh	(revision 1230)
@@ -0,0 +1,54 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// IAEAScorerWriter.hh
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef IAEAScoreWriter_h
+#define IAEAScoreWriter_h 1
+
+#include "globals.hh"
+#include "G4VScoreWriter.hh"
+
+// class description:
+//
+//  This class represents storing the scored quantity into a file.
+//
+
+
+class IAEAScoreWriter : public G4VScoreWriter {
+
+public:
+  IAEAScoreWriter();
+  virtual ~IAEAScoreWriter();
+
+public:
+  // store a quantity into a file
+  void DumpQuantityToFiles(G4String & psName, G4String & option);
+};
+
+#endif
+
+
Index: trunk/examples/advanced/hadrontherapy/include/LocalINCLIonIonInelasticPhysic.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/LocalINCLIonIonInelasticPhysic.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/LocalINCLIonIonInelasticPhysic.hh	(revision 1230)
@@ -0,0 +1,53 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// LocalINCLIonIonInelasticPhysic.cc
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef LOCALINCLIONINELASTICPHYSIC_H
+#define LOCALINCLIONIONINELASTICPHYSIC_H 1
+
+#include "G4VPhysicsConstructor.hh"
+#include "globals.hh" 
+
+class LocalINCLIonIonInelasticPhysic: public G4VPhysicsConstructor 
+{
+ public:
+  LocalINCLIonIonInelasticPhysic (const G4String& name = "local_ion_ion_inelastic");
+   virtual ~LocalINCLIonIonInelasticPhysic();
+
+ protected:
+   void ConstructParticle(){};
+   void ConstructProcess();
+};
+#endif 
+
+
+
+
+
+
+
+
Index: trunk/examples/advanced/hadrontherapy/include/LocalIonIonInelasticPhysic.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/LocalIonIonInelasticPhysic.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/LocalIonIonInelasticPhysic.hh	(revision 1230)
@@ -0,0 +1,53 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// LocalIonIonInelasticPhysic.cc
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef LOCALIONINELASTICPHYSIC_H
+#define LOCALIONIONINELASTICPHYSIC_H 1
+
+#include "G4VPhysicsConstructor.hh"
+#include "globals.hh" 
+
+class LocalIonIonInelasticPhysic: public G4VPhysicsConstructor 
+{
+ public:
+  LocalIonIonInelasticPhysic (const G4String& name = "local_ion_ion_inelastic");
+   virtual ~LocalIonIonInelasticPhysic();
+
+ protected:
+   void ConstructParticle(){};
+   void ConstructProcess();
+};
+#endif 
+
+
+
+
+
+
+
+
Index: trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLine.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLine.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLine.hh	(revision 1230)
@@ -0,0 +1,340 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// PassiveProtonBeamLine.cc; 
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef PassiveProtonBeamLine_H
+#define PassiveProtonBeamLine_H 1
+
+#include "globals.hh"
+#include "G4VUserDetectorConstruction.hh"
+#include "G4Box.hh"
+#include "G4Tubs.hh"
+#include "G4VisAttributes.hh"
+#include "G4LogicalVolume.hh"
+
+class G4VPhysicalVolume;
+class HadrontherapyDetectorConstruction;
+class HadrontherapyModulator;
+class PassiveProtonBeamLineMessenger;
+
+class PassiveProtonBeamLine : public G4VUserDetectorConstruction
+{
+public:
+
+  //PassiveProtonBeamLine(G4VPhysicalVolume*);
+  PassiveProtonBeamLine();
+  ~PassiveProtonBeamLine();
+
+  G4VPhysicalVolume* Construct();  
+
+  void HadrontherapyBeamLineSupport();
+  // Definition of the beam line support
+
+  void HadrontherapyBeamScatteringFoils();
+  // Definition of the first scattering foil, 
+  // of the Kapton window, of the stopper 
+
+  void HadrontherapyRangeShifter();
+  // This defines the "range shifter". Is is a slab
+  // (usually of PMMA" acting as energy degrader
+  // of primary beam
+  
+  void HadrontherapyBeamCollimators();
+  // Definition of the first collimator, of the range shifter, 
+  // of the second collimator, of the first and second 
+  // collimator modulators
+ 
+  void HadrontherapyBeamMonitoring();
+  // Definition of three monitor chambers
+
+  void HadrontherapyMOPIDetector();
+  // Construct the MOPI on-line detector 
+  
+  void HadrontherapyBeamNozzle();
+  // Definition of the beam noozle
+
+  void HadrontherapyBeamFinalCollimator();
+  // Definition of the final collimator
+
+  // The following methods allow to change parameters
+  // of some beam line components
+
+  void SetRangeShifterXPosition(G4double value);
+  // This method allows to move the Range Shifter along
+  // the X axis
+
+  void SetRangeShifterXSize(G4double halfSize);
+  // This method allows to change the size of the range shifter along
+  // the X axis
+ 
+  void SetFirstScatteringFoilXSize(G4double);
+  // This method allows to change the size of the first scattering foil
+  // along the X axis
+
+  void SetSecondScatteringFoilXSize(G4double);
+  // This method allows to change the size of the second scattering foil
+  // along the X axis 
+  
+  void SetOuterRadiusStopper(G4double);
+  // This method allows to change the size of the outer radius of the stopper
+ 
+  void SetInnerRadiusFinalCollimator(G4double);
+  // This method allows to change the size of the inner radius of the 
+  // final collimator
+  
+  void SetRSMaterial(G4String);
+  // This method allows to change the material 
+  // of the range shifter
+  
+  void SetModulatorAngle(G4double angle);
+  // This method allows moving the modulator through UI commands
+
+
+private:
+
+  void SetDimensions(); //passive proton line dimensions
+  void ConstructPassiveProtonBeamLine();
+
+  HadrontherapyModulator* modulator; // Pointer to the modulator 
+                                     // geometry component
+  PassiveProtonBeamLineMessenger* passiveMessenger;  
+  G4VPhysicalVolume* physicalTreatmentRoom;
+  HadrontherapyDetectorConstruction* hadrontherapyDetectorConstruction; 
+
+  G4Material* kapton;
+	
+  G4double vacuumZoneXSize;
+  G4double vacuumZoneYSize;
+  G4double vacuumZoneZSize;
+  G4double vacuumZoneXPosition;
+  
+  G4double firstScatteringFoilXSize;
+  G4double firstScatteringFoilYSize;
+  G4double firstScatteringFoilZSize;
+  G4double firstScatteringFoilXPosition;
+
+  G4double kaptonWindowXSize;
+  G4double kaptonWindowYSize;
+  G4double kaptonWindowZSize;
+  G4double kaptonWindowXPosition;
+
+  G4double innerRadiusStopper;
+  G4double heightStopper;
+  G4double startAngleStopper;
+  G4double spanningAngleStopper;
+  G4double stopperXPosition;
+  G4double stopperYPosition;
+  G4double stopperZPosition;
+  G4double outerRadiusStopper;
+
+  G4double secondScatteringFoilXSize;
+  G4double secondScatteringFoilYSize;
+  G4double secondScatteringFoilZSize;
+  G4double secondScatteringFoilXPosition;
+  G4double secondScatteringFoilYPosition;
+  G4double secondScatteringFoilZPosition;
+
+  G4double rangeShifterXSize;
+  G4double rangeShifterYSize;
+  G4double rangeShifterZSize;
+  G4double rangeShifterXPosition;
+  G4double rangeShifterYPosition;
+  G4double rangeShifterZPosition;
+
+
+  G4VPhysicalVolume* physiBeamLineSupport; 
+  G4VPhysicalVolume* physiBeamLineCover; 
+  G4VPhysicalVolume* physiBeamLineCover2;
+  G4Box* firstScatteringFoil;
+  G4VPhysicalVolume* physiFirstScatteringFoil;
+  G4VPhysicalVolume* physiKaptonWindow;
+  G4Tubs* solidStopper;
+  G4VPhysicalVolume* physiStopper; 
+  G4Box* secondScatteringFoil;  
+  G4VPhysicalVolume* physiSecondScatteringFoil;  
+  G4VPhysicalVolume* physiFirstCollimator;  
+  G4VPhysicalVolume* physiHoleFirstCollimator;
+  G4Box* solidRangeShifterBox;
+  G4LogicalVolume* logicRangeShifterBox;
+  G4VPhysicalVolume* physiRangeShifterBox;
+  G4VPhysicalVolume* physiSecondCollimator;
+  G4VPhysicalVolume* physiHoleSecondCollimator; 
+
+  G4VPhysicalVolume* physiFirstCollimatorModulatorBox;
+  G4VPhysicalVolume* physiHoleFirstCollimatorModulatorBox; 
+ 
+  G4VPhysicalVolume* physiSecondCollimatorModulatorBox;
+  G4VPhysicalVolume* physiHoleSecondCollimatorModulatorBox;
+
+  // MOPI Detector
+  // Mother volume
+  G4VPhysicalVolume* physiMOPIMotherVolume;
+  G4LogicalVolume* logicMOPIMotherVolume;
+  G4Box* solidMOPIMotherVolume;
+
+  G4double MOPIMotherVolumeXSize;
+  G4double MOPIMotherVolumeYSize;
+  G4double MOPIMotherVolumeZSize;
+  G4double MOPIMotherVolumeXPosition;
+  G4double MOPIMotherVolumeYPosition;
+  G4double MOPIMotherVolumeZPosition;
+
+  // First Kapton layer
+  G4double MOPIFirstKaptonLayerXSize;
+  G4double MOPIFirstKaptonLayerYSize;
+  G4double MOPIFirstKaptonLayerZSize;
+  G4double MOPIFirstKaptonLayerXPosition;
+  G4double MOPIFirstKaptonLayerYPosition;
+  G4double MOPIFirstKaptonLayerZPosition;
+  G4Box* solidMOPIFirstKaptonLayer;
+  G4LogicalVolume* logicMOPIFirstKaptonLayer;
+  G4VPhysicalVolume* physiMOPIFirstKaptonLayer;
+
+  // First Aluminum layer
+  G4double MOPIFirstAluminumLayerXSize;
+  G4double MOPIFirstAluminumLayerYSize;
+  G4double MOPIFirstAluminumLayerZSize;
+  G4double MOPIFirstAluminumLayerXPosition;
+  G4double MOPIFirstAluminumLayerYPosition;
+  G4double MOPIFirstAluminumLayerZPosition;
+  G4Box* solidMOPIFirstAluminumLayer;
+  G4LogicalVolume* logicMOPIFirstAluminumLayer;
+  G4VPhysicalVolume* physiMOPIFirstAluminumLayer;
+
+  // First Air Gap
+  G4double MOPIFirstAirGapXSize;
+  G4double MOPIFirstAirGapYSize;
+  G4double MOPIFirstAirGapZSize;
+  G4double MOPIFirstAirGapXPosition;
+  G4double MOPIFirstAirGapYPosition;
+  G4double MOPIFirstAirGapZPosition;
+  G4Box* solidMOPIFirstAirGap;
+  G4LogicalVolume* logicMOPIFirstAirGap;
+  G4VPhysicalVolume* physiMOPIFirstAirGap;
+
+  // Cathode
+  G4double MOPICathodeXSize;
+  G4double MOPICathodeYSize;
+  G4double MOPICathodeZSize;
+  G4double MOPICathodeXPosition;
+  G4double MOPICathodeYPosition;
+  G4double MOPICathodeZPosition;
+  G4Box* solidMOPICathode;
+  G4LogicalVolume* logicMOPICathode;
+  G4VPhysicalVolume* physiMOPICathode;
+
+  G4VisAttributes* redWire;
+
+  // First Air Gap
+  G4double MOPISecondAirGapXSize;
+  G4double MOPISecondAirGapYSize;
+  G4double MOPISecondAirGapZSize;
+  G4double MOPISecondAirGapXPosition;
+  G4double MOPISecondAirGapYPosition;
+  G4double MOPISecondAirGapZPosition;
+  G4Box* solidMOPISecondAirGap;
+  G4LogicalVolume* logicMOPISecondAirGap;
+  G4VPhysicalVolume* physiMOPISecondAirGap;
+
+  // First Aluminum layer
+  G4double MOPISecondAluminumLayerXSize;
+  G4double MOPISecondAluminumLayerYSize;
+  G4double MOPISecondAluminumLayerZSize;
+  G4double MOPISecondAluminumLayerXPosition;
+  G4double MOPISecondAluminumLayerYPosition;
+  G4double MOPISecondAluminumLayerZPosition;
+  G4Box* solidMOPISecondAluminumLayer;
+  G4LogicalVolume* logicMOPISecondAluminumLayer;
+  G4VPhysicalVolume* physiMOPISecondAluminumLayer;
+  
+  // Second Kapton layer
+  G4double MOPISecondKaptonLayerXSize;
+  G4double MOPISecondKaptonLayerYSize;
+  G4double MOPISecondKaptonLayerZSize;
+  G4double MOPISecondKaptonLayerXPosition;
+  G4double MOPISecondKaptonLayerYPosition;
+  G4double MOPISecondKaptonLayerZPosition;
+  G4Box* solidMOPISecondKaptonLayer;
+  G4LogicalVolume* logicMOPISecondKaptonLayer;
+  G4VPhysicalVolume* physiMOPISecondKaptonLayer;
+
+  G4double innerRadiusFinalCollimator;
+  G4VPhysicalVolume* mother;
+  
+  G4VPhysicalVolume* physiFirstMonitorLayer1;
+  G4VPhysicalVolume* physiFirstMonitorLayer2;
+  G4VPhysicalVolume* physiFirstMonitorLayer3;
+  G4VPhysicalVolume* physiFirstMonitorLayer4;
+  G4VPhysicalVolume* physiSecondMonitorLayer1;
+  G4VPhysicalVolume* physiSecondMonitorLayer2;
+  G4VPhysicalVolume* physiSecondMonitorLayer3;
+  G4VPhysicalVolume* physiSecondMonitorLayer4;
+  G4VPhysicalVolume* physiNozzleSupport;
+  G4VPhysicalVolume* physiHoleNozzleSupport; 
+  G4VPhysicalVolume* physiSecondHoleNozzleSupport;
+  G4Tubs* solidFinalCollimator; 
+  G4VPhysicalVolume* physiFinalCollimator; 
+  
+  G4VisAttributes* blue;
+  G4VisAttributes* gray;
+  G4VisAttributes* white;
+  G4VisAttributes* red;
+  G4VisAttributes* yellow;
+  G4VisAttributes* green;
+  G4VisAttributes* darkGreen;
+  G4VisAttributes* darkOrange3;
+  G4VisAttributes* skyBlue;
+  
+  G4Material* rangeShifterMaterial;
+  G4Material* beamLineSupportMaterial;
+  G4Material* vacuumZoneMaterial;
+  G4Material* firstScatteringFoilMaterial;
+  G4Material* kaptonWindowMaterial;
+  G4Material* stopperMaterial;
+  G4Material* secondScatteringFoilMaterial;
+  G4Material* firstCollimatorMaterial;
+  G4Material* holeFirstCollimatorMaterial;
+  G4Material* modulatorBoxMaterial;
+  G4Material* holeModulatorBoxMaterial;
+  G4Material* layer1MonitorChamberMaterial;
+  G4Material* layer2MonitorChamberMaterial;
+  G4Material* layer3MonitorChamberMaterial;
+  G4Material* layer4MonitorChamberMaterial;
+  G4Material* MOPIMotherVolumeMaterial;
+  G4Material* MOPIFirstKaptonLayerMaterial;
+  G4Material* MOPIFirstAluminumLayerMaterial;
+  G4Material* MOPIFirstAirGapMaterial;
+  G4Material* MOPICathodeMaterial;
+  G4Material* MOPISecondAirGapMaterial;
+  G4Material* MOPISecondAluminumLayerMaterial;
+  G4Material* MOPISecondKaptonLayerMaterial;
+  G4Material* nozzleSupportMaterial;
+  G4Material* holeNozzleSupportMaterial;
+  G4Material* seconHoleNozzleSupportMaterial;
+  G4Material* finalCollimatorMaterial;
+};
+#endif
Index: trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLineMessenger.hh
===================================================================
--- trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLineMessenger.hh	(revision 1230)
+++ trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLineMessenger.hh	(revision 1230)
@@ -0,0 +1,106 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// HadrontherapyDetectorMessenger.hh;
+// See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
+
+#ifndef HadrontherapyDetectorMessenger_h
+#define HadrontherapyDetectorMessenger_h 1
+
+#include "globals.hh"
+#include "G4UImessenger.hh"
+
+class PassiveProtonBeamLine;
+class G4UIdirectory;
+class G4UIcmdWithADoubleAndUnit;
+class G4UIcmdWithAString;
+
+class PassiveProtonBeamLineMessenger: public G4UImessenger
+{
+  public:
+  PassiveProtonBeamLineMessenger(PassiveProtonBeamLine*);
+  ~PassiveProtonBeamLineMessenger();
+    
+    void SetNewValue(G4UIcommand*, G4String);
+    
+private:
+
+  // Pointer to the detector component
+  PassiveProtonBeamLine* passiveProton;
+
+  G4UIdirectory* changeTheBeamLineDir;
+  G4UIcmdWithAString*        changeTheBeamLineNameCmd; // Control the name of the beam line 
+
+  G4UIdirectory* modulatorDir; // Control of the modulator 
+  G4UIdirectory* beamLineDir;  // Control of the beam line
+ 
+  G4UIdirectory* rangeShifterDir; 
+  // Control of the range shifter component of the beam line
+
+  G4UIdirectory* firstScatteringFoilDir;
+  // Control of the first scattering foil component of the beam line
+  
+  G4UIdirectory* secondScatteringFoilDir;
+  // Control of the first scattering foil component of the beam line
+  
+  G4UIdirectory* rangeStopperDir;
+  // Control of the range stopper component of the beam line
+  
+  G4UIdirectory* finalCollimatorDir;
+  // Control of the final collimator component of the beam line
+  
+  G4UIcmdWithADoubleAndUnit* modulatorAngleCmd;
+  // UI command to rotate the modulator wheel
+
+  G4UIcmdWithAString*   rangeShifterMatCmd;
+  // UI command to set the material of the rangeShifter component of 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* rangeShifterXSizeCmd;
+  // UI command to set half of the X size of the rangeShifter component of 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* rangeShifterXPositionCmd;
+  // UI command to change the X position of the rangeShifter component of 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* firstScatteringFoilXSizeCmd;
+  // UI command to set half X size of the first scattering foil of 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* secondScatteringFoilXSizeCmd;
+  // UI command to set half X size of the second scattering foil 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* outerRadiusStopperCmd;
+  // UI command to set the outer radius of the range stopper component of 
+  // the beam line 
+
+  G4UIcmdWithADoubleAndUnit* innerRadiusFinalCollimatorCmd;
+  // UI command to set the inner radius of the final collimator component of 
+  // the beam line 
+};
+#endif
+
