Changeset 1313 for trunk/examples/advanced/hadrontherapy
- Timestamp:
- Jun 14, 2010, 3:54:58 PM (14 years ago)
- Location:
- trunk/examples/advanced/hadrontherapy
- Files:
-
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/advanced/hadrontherapy/GNUmakefile
r1230 r1313 1 # $Id: GNUmakefile,v 1.1 2 2009/08/13 20:48:04 kaitanie Exp $1 # $Id: GNUmakefile,v 1.17 2010/05/18 11:14:39 cirrone Exp $ 2 2 # -------------------------------------------------------------- 3 3 # GNUmakefile for examples module. Gabriele Cosmo, 06/04/98. … … 8 8 G4EXLIB := true 9 9 10 # Debug info 11 #CPPFLAGS += -g 12 10 13 ifndef G4INSTALL 11 G4INSTALL = ../.. /..14 G4INSTALL = ../.. 12 15 endif 13 16 … … 17 20 include $(G4INSTALL)/config/architecture.gmk 18 21 19 ifdef G4ANALYSIS_USE 20 CPPFLAGS += -DANALYSIS_USE 21 endif 22 ifndef G4ANALYSIS_USE # If we don't have AIDA 23 ifdef G4ANALYSIS_USE_ROOT # And we have ROOT 24 CPPFLAGS += -DANALYSIS_USE -DG4ANALYSIS_USE_ROOT 22 ifdef G4ANALYSIS_USE_ROOT # If we have ROOT 23 CPPFLAGS += -DG4ANALYSIS_USE_ROOT 25 24 CPPFLAGS += $(shell root-config --cflags) 26 25 LDFLAGS += $(shell root-config --glibs) 27 endif28 26 endif 29 27 30 28 include $(G4INSTALL)/config/binmake.gmk 31 29 32 ifdef G4ANALYSIS_USE33 endif -
trunk/examples/advanced/hadrontherapy/Hadrontherapy.cc
r1230 r1313 24 24 // ******************************************************************** 25 25 // 26 // Hadrontherapy.cc 27 // 28 // Main of the Hadrontherapy example; 29 // Released with the Geant4 9.3 version (December 2009) 30 // 31 // Last modified: G.A.P.Cirrone 32 // 26 // This is the *basic* version of Hadrontherapy, a Geant4-based application 33 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 34 28 // 29 // To obtain the full version visit the pages: http://sites.google.com/site/hadrontherapy/ 30 35 31 // ---------------------------------------------------------------------------- 36 32 // GEANT 4 - Hadrontherapy example 37 33 // ---------------------------------------------------------------------------- 38 // Code developed by:34 // Main Authors: 39 35 // 40 36 // G.A.P. Cirrone(a)°, G.Cuttone(a), F.Di Rosa(a), E.Mazzaglia(a), F.Romano(a) 41 37 // 42 38 // Contributor authors: 43 // P.Kaitaniemi(d), A.Heikkinen(d), G illisDanielsen (d)39 // P.Kaitaniemi(d), A.Heikkinen(d), G.Danielsen (d) 44 40 // 45 41 // Past authors: … … 101 97 #endif 102 98 99 #ifdef G4UI_USE 100 #include "G4UIExecutive.hh" 101 #endif 103 102 ////////////////////////////////////////////////////////////////////////////////////////////// 103 104 104 int main(int argc ,char ** argv) 105 105 { 106 // Set the Random engine 107 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine()); 108 109 G4RunManager* runManager = new G4RunManager; 110 111 //Initialize possible analysis needs, needs to come early in order to pick up metadata 112 #ifdef ANALYSIS_USE 113 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); 114 analysis -> book(); 115 #endif 116 // Geometry controller is responsible for instantiating the 117 // geometries. All geometry specific setup tasks are now in class 118 // HadrontherapyGeometryController. 119 HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); 120 121 // Connect the geometry controller to the G4 user interface 122 HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); 123 124 G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); 125 scoringManager->SetVerboseLevel(1); 126 scoringManager->SetScoreWriter(new IAEAScoreWriter()); 127 128 // Initialize the default Hadrontherapy geometry 129 geometryController->SetGeometry("default"); 130 131 // Initialize command based scoring 132 G4ScoringManager::GetScoringManager(); 133 134 // Initialize the physics 135 runManager -> SetUserInitialization(new HadrontherapyPhysicsList()); 136 137 // Initialize the primary particles 138 HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction(); 139 runManager -> SetUserAction(pPrimaryGenerator); 140 141 // Optional UserActions: run, event, stepping 142 HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction(); 143 runManager -> SetUserAction(pRunAction); 144 145 HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction(); 146 runManager -> SetUserAction(pEventAction); 147 148 HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction); 149 runManager -> SetUserAction(steppingAction); 150 151 // Interaction data: stopping powers 152 HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(); 153 106 // Set the Random engine 107 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine()); 108 109 // Only if an initial random seed is needed 110 // G4int seed = time(0); 111 // CLHEP::HepRandom::setTheSeed(seed); 112 113 G4RunManager* runManager = new G4RunManager; 114 // Geometry controller is responsible for instantiating the 115 // geometries. All geometry specific setup tasks are now in class 116 // HadrontherapyGeometryController. 117 HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); 118 119 // Connect the geometry controller to the G4 user interface 120 HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); 121 122 G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); 123 scoringManager->SetVerboseLevel(1); 124 scoringManager->SetScoreWriter(new IAEAScoreWriter()); 125 126 // Initialize the default Hadrontherapy geometry 127 geometryController->SetGeometry("default"); 128 129 // Initialize command based scoring 130 G4ScoringManager::GetScoringManager(); 131 132 // Initialize the physics 133 runManager -> SetUserInitialization(new HadrontherapyPhysicsList()); 134 135 // Initialize the primary particles 136 HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction(); 137 runManager -> SetUserAction(pPrimaryGenerator); 138 139 // Optional UserActions: run, event, stepping 140 HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction(); 141 runManager -> SetUserAction(pRunAction); 142 143 HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction(); 144 runManager -> SetUserAction(pEventAction); 145 146 HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction); 147 runManager -> SetUserAction(steppingAction); 148 149 // Interaction data: stopping powers 150 HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true); 151 154 152 #ifdef G4VIS_USE 155 156 157 153 // Visualization manager 154 G4VisManager* visManager = new G4VisExecutive; 155 visManager -> Initialize(); 158 156 #endif 159 160 G4UImanager* UI = G4UImanager::GetUIpointer(); 161 162 if (argc!=1) // batch mode 163 { 164 G4String command = "/control/execute "; 165 G4String fileName = argv[1]; 166 UI->ApplyCommand(command+fileName); 167 } 168 169 else // interactive mode : define visualization UI terminal 170 { 171 G4UIsession* session = 0; 172 173 // If the enviroment variable for the TCSH terminal is active, it is used and the 174 // defaultMacro.mac file is executed 157 158 G4UImanager* UI = G4UImanager::GetUIpointer(); 159 160 // Batch mode: in this configuration, i.e. when the User explicitly call a macro file, 161 // the program run and, at the end, authomatically call the exit state. 162 // With a such configuration, it is possible to send in background a simulation 163 // and correctly get the output file. 164 if (argc!=1) 165 { 166 G4UIsession* session = 0; 167 G4String command = "/control/execute "; 168 G4String fileName = argv[1]; 169 UI -> ApplyCommand(command+fileName); 175 170 #if defined(G4UI_USE_TCSH) 176 session = new G4UIterminal(new G4UItcsh); 177 UI->ApplyCommand("/control/execute defaultMacro.mac"); 178 179 // Alternatively (if G4UI_USE_TCSH is not defined) the program search for the 180 // G$UI_USE_QT variable. It starts a graphical user interface based on the QT libraries 181 // In the following case the GUI.mac file is also executed 182 // 171 session = new G4UIterminal(new G4UItcsh); 172 #else 173 session = new G4UIterminal(); 174 #endif 175 // Only if the User Interface is needed! 176 //session -> SessionStart(); 177 //delete session; 178 } 179 else // interactive mode : define visualization UI terminal 180 { 181 G4UIsession* session = 0; 182 183 // If the enviroment variable for the TCSH terminal is active, it is used and the 184 // defaultMacro.mac file is executed 185 #if defined(G4UI_USE_TCSH) 186 session = new G4UIterminal(new G4UItcsh); 187 UI->ApplyCommand("/control/execute defaultMacro.mac"); 188 session -> SessionStart(); 189 190 // Alternatively (if G4UI_USE_TCSH is not defined) the program search for the 191 // G4UI_USE_QT variable. It starts a graphical user interface based on the QT libraries 192 // In the following case the GUI.mac file is also executed 183 193 #elif defined(G4UI_USE_QT) 184 185 186 187 // As final option, the simpleruser interface terminal is opened194 session = new G4UIQt(argc,argv); 195 UI->ApplyCommand("/control/execute macro/GUI.mac"); 196 session -> SessionStart(); 197 // As final option, the basic user interface terminal is opened 188 198 #else 189 session = new G4UIterminal(); 190 UI->ApplyCommand("/control/execute defaultMacro.mac"); 191 #endif 192 session->SessionStart(); 193 delete session; 194 } 195 HadrontherapyMatrix* matrix = HadrontherapyMatrix::getInstance(); 196 if (matrix) matrix -> TotalEnergyDeposit(); 197 198 #ifdef ANALYSIS_USE 199 analysis -> finish(); 200 #endif 201 202 // Job termination 203 #ifdef G4VIS_USE 204 delete visManager; 199 session = new G4UIterminal(); 200 201 UI -> ApplyCommand("/control/execute defaultMacro.mac"); 202 session -> SessionStart(); 203 #endif 204 delete session; 205 } 206 207 // Job termination 208 #ifdef G4ANALYSIS_USE_ROOT 209 HadrontherapyAnalysisManager::GetInstance() -> flush(); // Finalize the root file 210 #endif 211 212 #ifdef G4UI_USE 213 G4UIExecutive * ui = new G4UIExecutive(argc,argv); 214 ui->SessionStart(); 215 delete ui; 205 216 #endif 206 217 … … 210 221 delete runManager; 211 222 return 0; 223 212 224 } -
trunk/examples/advanced/hadrontherapy/History
r1230 r1313 8 8 History file of the Hadrontherapy application 9 9 ==================================================== 10 11 25.11.2009 S.E.Mazzaglia & F.Romano; Tag:Hadrontherapy-V09-02-40 10 03.06.2010 J.Perl; Tag: Hadrontherapy-V09-03-04 11 - Updated vis usage 12 13 01.06.2010: G.A.P.Cirrone; Tag: harontherapy-V09-03-03 14 - Added G4UIExecutive 15 - Main file updated 16 17 22.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-02 18 - Updated ROOT scripts in folder RootScripts/proton/BraggPeak 19 20 21.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-01 21 - Solved some bugs related to the preprocessor variable G4ANALYSIS_USE_ROOT. 22 23 18.05.2010 S.E.Mazzaglia; Tag: hadrontherapy-V09-03-00 24 - Removed the possibility to calculate Let. 25 - Removed AIDA and variables: G4_ANALYSIS_USE and ANALYSIS_USE. 26 - Improved the commands to modify phantom/detector geometry 27 - Added a command to set cuts just only in the detector: /physic/setDetectorCuts 28 - Added the possibility to store dose & fluence for all secondaries 29 produced in the same ASCII file. This feature can be switched on by the macro 30 command: /analysis/secondaries true. 31 32 33 16.12.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-42 34 - Added the possibility to calculate the Let too, using an ASCII file to store it. 35 - Added the new class HadrontherapyLet. 36 - Minor revisions of the code. 37 38 27.11.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-41 39 - Added the possibility to store dose and fluence for every particle/ion 40 produced during the simulation 41 42 25.11.2009 S.E.Mazzaglia & F.Romano; Tag: hadrontherapy-V09-02-40 12 43 - Corrected a bug in HadrontherapyDetectorConstruction class 13 - Added G4Radiactive DecayPhysics class to the Physics List.14 15 22.11.2009 S.E.Mazzaglia; Tag: Hadrontherapy-V09-02-3944 - Added G4RadiactivedecayPhysics class to the Physics List. 45 46 22.11.2009 S.E.Mazzaglia; Tag: hadrontherapy-V09-02-39 16 47 - Correction in the initialization of the passiveProtonBeamLine class. 17 48 -
trunk/examples/advanced/hadrontherapy/README
r807 r1313 1 1 2 ========================================================= 3 Geant4 - Hadrontherapy example 4 ========================================================= 5 6 README file 7 ---------------------- 8 9 AUTHORS 10 11 G.A.P. CIRRONE(a *), G.CUTTONE(a), F. DI ROSA(a), G.RUSSO(a) 12 a. Laboratori Nazionali del Sud - Istituto Nazionale di Fisica Nucleare 13 95123 Catania, Italy 14 * e-mail:cirrone@lns.infn.it 15 16 M.G. PIA(b) 17 b. Istituto Nazionale di Fisica Nucleare, Sezione di Genova Via Dodecaneso, 33 18 16146, Genova, Italy 19 20 A. LECHNER (c) 21 c. CERN, Switzerland 22 23 More informations on the Hadrontherapy example can be found in the 24 Hadrontherapy Documentation available at http://www.ge.infn.it/geant4/examples/ 25 26 Alternatevely send an e-mail to cirrone@lns.infn.it. 27 28 29 ---->0. INTRODUCTION. 30 31 The hadrontherapy example simulates a hadron therapy beam line. 32 In particular the example models the specific proton therapy beam line 33 installed at Laboratori Nazionali del Sud (INFN) in Catania, Sicily (Italy). 34 For more information on the proton therapy center of Catania 35 or/and proton/hadron therapy in general, please visit the 36 pages: 37 http://www.lns.infn.it/catanaweb/catana/ 38 39 ---->1. GEOMETRY SET-UP. 2 ========================================================= 3 Text version of the Hadrontherapy README file 4 ========================================================= 5 6 Last revsion: G.A.P.Cirrone, November 2009; 7 Released with the Geant4 9.3 version (December 2009) 8 9 ------------------------------------------------------------------------------------------------ 10 ADVERTISEMENT: this is the text version of the README file of the hadrontherapy application, 11 as it has been released in the official Geant4 9.3 release 12 13 A more complete and updated version of this file is published inside the web pages of Hadrontherapy: 14 http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 15 16 Please refer to the web-published version to know the last and future developments of hadrontherapy 17 ------------------------------------------------------------------------------------------------- 18 19 ========================================================= 20 HADRONTHERAPY 21 ========================================================= 22 23 Code developed by: 24 G.A.P. Cirrone(a)°, G.Cuttone(a), F.Di Rosa(a), S.E.Mazzaglia(a), F.Romano(a) 40 25 41 The elements simulated are: 26 Contributor authors: 27 P.Kaitaniemi(d), A.Heikkinen(d), G.Danielsen (d) 28 29 Past authors: 30 M.G.Pia(b), S.Guatelli(c), G.Russo(a), M.Russo(a), A.Lechner(e) 31 32 (a) Laboratori Nazionali del Sud 33 of the INFN, Catania, Italy 34 35 (b) INFN Section of Genova, Italy 36 37 (c) University of Wallongong, Australia 38 39 (d) Helsinki Institute of Physics, Helsinki, Finland 40 41 (e) CERN, (CH) 42 43 *Corresponding author, email to cirrone@lns.infn.it 44 ------------------------------------------------------------------------------------------------- 45 46 HADRONTHERAPY: 47 WHAT IT IS, WHAT IT DOES AND WHAT IT WILL PROVIDE 48 Hadrontherapy is a Geant4-based application specifically developed to address typical needs related to the proton and ion therapy. 49 It first release was in 2004. At that time Hadrontherapy was only capable to simulate a well specified proton therapy facility: the passive transport beam line installed at Laboratori Nazionali del Sud (INFN) in Catania, Italy. 50 51 Today Hadrontontherapy, except that it is in continuous development, is more flexible and show many additional capabilities as respect the past. 52 Its geometrical set-up, for example, is now completely interchangeable permitting a simple switch between different geometrical configurations. 53 In the actual version two geometrical configuration are available: the 'passive beam line' 54 and the 'IAEA Benchmark' geometry. See the paragraph Geometry set-up for more information. 55 Folder structure of Hadrontherapy 56 Hadrontherapy distribution contain different sub-folders: 57 58 \src: where source .cc files are stored 59 \include: where header .hh files are stored 60 \macro: where a set of ready-to-use macro files are provided 61 \experimentalData: in this director a set of reference (both experimental and analithycal) data are stored. These data are then used to perform a direct comparison with simulation results that are stored in the simulationResults folder. Data stored are better described in the README file contained inside. 62 \SimulationOutputs: when one of the .mac file contained in the macro folder is used, simulation results are directly stored in this directory. 63 \RootScripts: if the ROOT program is installed the User can use the scripts contained in this directory to compare directly results from the his/her simulation with reference data provided inside the experimentalData folder. 64 65 Currently this folders structure is in development and reference data as well as ROOT scripts will be added in the meanwhile new features and capabilities will be added. Moreover some ROOT script can be missed. Apologize for this and contact author if you need more information, clarification or useful discussion. 66 Description of the \macro folder 67 In the example directory, inside the "macro" folder two macro files are actually provided for the use of hadrontherapy with proton and carbon beams: proton_therapy.mac and ion_therapy.mac. 68 The proton_therapy.mac permits to run a simulation with the whole passive beam line installed in Catania. 69 The carbon_therapy.mac excludes all the elements (moving the origin of the ion beam close to the water phantom) and reproduce a simple passive beam line for the use with carbon beams. 70 The macro iaea.mac uses an alternative geometry that was created for the IAEA benchmark. It features a geometry with water target, aluminum beam window, and a particle detector behind the target. 71 72 73 DOWNLOAD AND INSTALLATION 74 Hadrontherapy source code is actually released inside the official distribution of the Geant4 toolkit in the $G4INSTALL/examples/AdvancedExamples folder. 75 76 To run Hadrontherapy you must first install the Geant4 package. Once Geant4 is installed the example must be first compiled (with the command gmake inside the 77 ../Hadrontherapy folder). When compilation is completed the program can be executed. 78 79 A complete guide for the Geant4 installation in different operating systems can be found inside the official installation Geant4 pages. 80 81 If you have troubles with the Geant4 installation please send an e-mail to us. 82 83 84 SISTEM SET-UP: enviroment variables 85 A standard Geant4 example GNUmakefile is provided 86 87 The following section reports the environment variables that are necessary for the run of Hadrontherapy. 88 #------------------------------------- 89 # SET UP LINUX GCC 90 #------------------------------------- 91 92 VERSION="geant4-09-03" 93 94 # Path to the directory in wich you have put data files and CLHEP 95 LIBPATH=$HOME/Geant4Library 96 97 export G4SYSTEM=Linux-g++ 98 99 # Path to the directory in wich you put your Geant4 installation 100 export G4INSTALL=$HOME/${VERSION} 101 102 export G4LIB=$G4INSTALL/lib 103 export G4WORKDIR=$G4INSTALL/workdir 104 export G4EXE=$G4WORKDIR/bin/$G4SYSTEM 105 106 export CLHEP_BASE_DIR=$LIBPATH/CLHEP2.0.4.5 107 export G4LEDATA=$LIBPATH/G4EMLOW6.9 108 export G4LEVELGAMMADATA=$LIBPATH/PhotonEvaporation2.0 109 export G4NEUTRONHPDATA=$LIBPATH/G4NDL3.13 110 export G4RADIOACTIVEDATA=$LIBPATH/RadioactiveDecay3.2 111 export G4ABLADATA=$LIBPATH/G4ABLA3.0 112 113 export LD_LIBRARY_PATH=$CLHEP_BASE_DIR/lib:$LD_LIBRARY_PATH 114 115 # For the generation .root file directly using the ROOT (if ROOT is 116 # instaled in you machine) 117 export G4ANALYSIS_USE_ROOT=1 118 export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH 119 120 #------------------------------------- 121 # SET UP VRML VIEW 122 #------------------------------------- 123 export G4VIS_BUILD_VRML_DRIVER=1 124 export G4VIS_USE_VRML=1 125 export G4VIS_USE_VRMLFILE=1 126 export G4VRMLFILE_MAX_FILE_NUM=100 127 export G4VRMLFILE_VIEWER=vrmlview #if installed 128 129 # Add path to your VRML installation 130 export PATH=$PATH:~/VRML 131 132 #------------------------------------- 133 # SET UP OpenGL o Mesa 134 #------------------------------------- 135 export G4VIS_BUILD_OPENGLX_DRIVER=1 136 export G4VIS_USE_OPENGLX=1 137 138 # Add path to your OpenGL installation 139 #export OGLHOME=/usr/lib 140 141 142 #------------------------------------- 143 # SET UP DAWN (if installed) 144 #------------------------------------- 145 export G4VIS_BUILD_DAWN_DRIVER=1 146 export G4VIS_BUILD_DOWNFILE_DRIVER=1 147 export G4VIS_USE_DAWN=1 148 export G4VIS_USE_DAWNFILE=1 149 # Add path to your DAWN installation 150 # export PATH=$PATH:~/dawn_3_86a 151 152 # VARIOUS USER INTERFACES 153 export G4UI_USE_XM=1 154 export G4UI_USE_TCSH=1 155 export G4UI_BUILD_QT_SESSION=1 156 export G4UI_USE_QT=1 157 158 # VARIOUS GRPHICAL USER INTERFACES 159 export G4VIS_BUILD_QT_SESSION=1 160 export G4VIS_BUILD_OPENGLQT_DRIVER=1 161 export G4VIS_USE_OPENGLQT=1 162 163 # If the QT libraries want be used for the User interfaces than the 164 # correct path must be addressed 165 export QTHOME=/usr/lib/qt-3.3 166 export PATH=$PATH:/usr/lib/qt-3.3/include/ 167 export PATH=$PATH:/usr/lib/qt-3.3/ 168 169 GEOMETRICAL SET-UP 170 The idea of Hadrontherapy is to provide a tool useful for Users interested in the field of proton and ion therapy. These can include the simple calculation of dose distribution curves in water or other materials, the derivation of important transport parameters (stopping powers, ranges, etc.) in different geometrical set-ups and for different materials, up to the complete simulation of a real transport beam line for therapy. 171 172 The main component of the simulation is the phantom, a box that can be filled with different material and where the score of different information (at moment the dose deposited and fluence in voxels) can be performed. A more complete description of the phantom is given in the next subsection. 173 174 At moment the Hadrontherapy include the simulation of the proton beam line for eye-treatments installed at the INFN-LNS facility in Catania. This is a passive beam line and it is simulated in the file PassiveProtonBeamLine.cc. 175 176 In the next future an ActiveProtonBeamLine.cc will be provided for the simulation of the active scanning treatment modality. 177 Moreover the possibility to add a very simple set-up (a beam, a phantom where collect the informations and some simple component) will be also provided. 178 179 All these configuration will be setted by macro commands. 180 181 There is also a facility that allows the user to make a choice between alternative geometry set-ups. This can be done by using command: 182 /geometrySetup/selectGeometry <name> 183 where <name> is either "default" for the standard hadrontherapy geometry or "IAEA" for the IAEA benchmark geometry. Both geometries are described below. By default the standard "default" geometry is used. 184 The water phantom to collect informations 185 At the end of the beam line a phantom (a box of uniform material) is reproduced. Inside it, a user-defined region is divided (via the ROGeomtry classes of Geant4) in cubic and identical voxels. The voxels size can be varied as well as the voxelized region. 186 At the end of a simulation run the dose deposited by primaries and secondaries in each voxel is collected. This information is available as an .out file or as a .root (if the G4ANALYSIS_USE variable is defined and the AIDA interface is activated). 187 188 The default sizes of the active voxelized region are 40x40x40 mm and actually the default voxel configuration is 200 x 1 x 1, which means 200 slices with 0.2 mm of thickness. 189 Of course this default can be modified in order to obtain, for example, a matrix of 80x80x80 cubic voxels each with a lateral dimension of 0.5 mm. 190 191 As concern the cut and stepMax values, the default configuration implies a cut value of 0.01 mm in the whole world (use the command /physic/setCuts <length> in order to set the cut for all, and the command /physic/setDetectorCuts <length> to set the cut for the detector only) and a stepMax of 0.01 mm just in the phantom (use the command /Step/waterPhantomStepMax 0.01 mm). 192 In any case it is strongly recommended to use a stepMax value not bigger than 5% of the dose slice thickness. 193 The Proton passive beam line class file 194 The following is the description of the elements of the passive proton beam line of the Laboratori Nazionali del Sud in Catania (I). This line is completely simulated inside this class. 195 196 The main elements are: 197 * The SCATTERING SYSTEM: to transversally enlarge the original beam 198 * The COLLIMATORS: placed along the beam line to collimate the beam; 199 * The RANGE SHIFTERS: to decrease the energy of the primary proton beam to a specific value; 200 * The MODULATOR WHEEL: to modulate the energy of the primary and mono-energetic beam in to a wide spectrum. The energy modulation is necessary to homogeneously irradiate a tumour volume that can extends in depth up to 20 mm; 201 * The MONITOR CHAMBERS: very thin ionisation chamber that permit the dose monitoring during the patient irradiation; 202 * The MOPI detector: microstrips, air free detector utilised for the check of the beam symmetry during the treatment; 203 * The PATIENT COLLIMATOR: a brass, tumour-shaped collimator able to confine the proton irradiation field in order to irradiate just the tumour mass in the transverse direction; 204 205 The user has the possibility to vary, via messenger, almost all the geometrical characteristics of the beam line elements (i.e. their position along the beam line, their thickness, etc.). 206 207 The elements simulated in the PassiveBeamLine.cc file are: 42 208 43 209 1. A scattering system, to spread geometrically the beam; … … 45 211 2. A system of collimators, to avoid the scattering radiation; 46 212 47 3. A modulation system that spreads the beam in energy and 48 produces the so-called spread out bragg peak; 49 It is constituted by a rotating wheel of different thichnesses. 50 The wheel rotates around is axis (parallel to the proton 51 beam axis) and its movement can be obtained by means of a 52 messenger between runs. 53 54 4. A set of monitor chambers (special transmission ionisation 55 chambers used to control hadron flux during the irradiation); 56 57 5. A "nozzle" and a final collimator defining the final shape 58 of the beam before reaching the patient. 59 60 6. A water phantom: it is a box of water where the energy deposit is 61 calculated. 62 The use of the water phantom is required by the international protocol 63 on the measure of dose in the case of proton and ion beams (IAEA 398, 2000). 64 65 ---->2. EXPERIMENTAL SET-UP. 66 67 The application simulates the proton therapy beam line 68 installed at Laboratori Nazionali del Sud. 69 The default beam line is a typical treatment line composed by several elements all 70 devoted to create the so-called "terapeutical beam", i.e. a beam ideal 71 for a radiotherapeutic treatment. 72 73 The main elements are: 74 ** The COLLIMATORS: placed along the beam line to collimate the beam; 75 76 ** The RANGE SHIFTERS: to decrease the energy of the primary proton beam 77 to a specific value; 78 79 ** The MODULATOR WHEEL: to modulate the energy of the primary and monoenergetic 80 beam in to a wide spectrum. The energy modulation is necessary to 81 homogeneusly irradiate a tumour volume that can extends in depth 82 up to 20 mm; 83 84 ** The MONITOR CHAMBERS: very thin ionisation chamber that permit the 85 dose monitoring during the patient irradiation; 86 87 ** The PATIENT COLLIMATOR: a brass, tumour-shaped collimator able to 88 confine the proton irradiation field in order to irradiate just the tumour mass 89 in the trasverse direction; 90 91 The user has the possibility to vary, via messenger, almost all the geometrical 92 characteristics of the beam line elements (i.e. their position along the beam line, 93 their thickness, etc.). More details on the available user messengers can be 94 found in the Hadronterapy Documentation (http://www.ge.infn.it/geant4/examples/). 95 96 At the end of the beam line, a typical water phantom is reproduced. 97 A user-defined region of the phantom is divided (via the ROGeomtry class) in 98 cubic and identical voxels. The voxels size can be varied. At the end of the simulation 99 the energy deposited by primary protons, and secondaries in each voxel 100 is collected. This information is available as an .hbk file (if the 101 G4ANALYSIS_USE variable is defined). 102 103 The default sizes of the active voxelized region are 40x40x40 mm corresponding 104 to a matric of 80x80x80 cubic voxels each with a lateral dimension of 0.5 mm. 105 106 ---->3. SET-UP 107 108 - a standard Geant4 example GNUmakefile is provided 109 110 setup with: 111 compiler = gcc-3.2.3 112 G4SYSTEM = linux-g++ 113 114 The following section reports the necessary environment variables 115 necessary for the run of Hadrontherapy. 116 117 ---->3.1 ENVIROMENT VARIABLES 118 119 - G4SYSTEM = Linux-g++ 120 121 - G4INSTALL points to the installation directory of GEANT4; 122 123 - G4LIB point to the compiled libraries of GEANT4; 124 125 - G4WORKDIR points to the work directory; 126 127 - CLHEP_BASE_DIR points to the installation directory of CHLEP; 128 129 - G4LEVELGAMMADATA points to the photoevaporation library; 130 131 - NeutronHPCrossSections points to the neutron data files; 132 133 - G4RADIOACTIVEDATA points to the libraries for radio-active decay 134 hadronic processes; 135 136 - G4LEDATA points to the low energy electromagnetic libraries 137 138 - LD_LIBRARY_PATH = $CLHEP_BASE_DIR/lib 139 140 ---->3.2 VISUALISATION 141 142 The user can visualise the experimental set-up with OpenGL, DAWN and vrml 143 144 ---->4. HOW TO RUN THE EXAMPLE 145 146 In interactive mode: 213 3. A modulation system that spreads the beam in energy and produces the so-called spread out Bragg peak; It is constituted by a rotating wheel of different thicknesses. The wheel rotates around its axis (parallel to the proton beam axis) and its movement can be obtained by means of a messenger between runs. 214 215 4. A set of monitor chambers (special transmission ionisation chambers used to control the particle flux during the irradiation); 216 217 5. A final long collimator and a patient collimator defining the final shape of the beam before reaching the patient. 218 219 6. A water phantom: it is a box of water where the dose deposit is calculated. The use of the water phantom is required by the international protocol on the measure of dose in the case of proton and ion beams (IAEA 398, 2000). 220 Geometry for the IAEA benchmark 221 Simple geometry for benchmark purposes contains water phantom (thickness can be set using a macro command), an aluminum beam window and Plexi-glass. Behind the phantom we have a detector that records outcoming particles. The IAEA geometry can be activated by using the command: 222 /geometrySetup/selectGeometry IAEA 223 224 Example IAEA benchmark run can be done as follows: 225 run: Hadrontherapy macro/iaea.mac 226 analysis: root RootScripts/iaeaBenchmark/fragmentEnergy.C 227 228 PHYSICS PROCESSES AND PHYSICS MODELS IMPLEMENTATION 229 A particular care is addressed to the simulation of the physic processes. 230 Three different approaches can be used for the choose of the physic models. 231 Approach 1: 232 Using the macro command: 233 /physic/addPhysics/<physics List name>. 234 235 In this case the models (for electromagnetic, hadronic elastic and hadronic inelastic) can be activated directly calling the name of the Physics Lists that are available inside the 236 Geant4 kernel in the directory: 237 238 $G4INSTALL/source/physics_lists/builders/include 239 240 An example of the use of the Physics List can be found in the macro files: 241 proton_therapy.mac and ion_therapy.mac 242 Approach 2: 243 A set of built-in physic models are also contained inside the Hadrontherapy directory. These are called Local*.cc and Local*.hh and can be activated using the macro command: 244 /physic/addPhysics/<name>. 245 Approach 3: 246 We developed this approach in order to simplify the choice of the physic models to 247 be used in the application. 248 With this approach the user must only insert a command line in his/her .mac file using the: /physics/addPackage <PACKAGE_NAME> 249 250 This permits to switch-on an already build physic package. 251 Various packages are already present in the Geant4 tree: they are in the directory: geant4/source/physics_lists/lists/include 252 253 In this case hadronic inelastic models are directly activated for every particle. 254 255 NOTE: we do not recommend the use of local physics lists while we recommend the use of the Physics Lists or of the Reference Physics Lists (Approach 1 or 3) 256 257 -------------------------------------------------------------------------------- 258 SUGGESTED PHYSIC FOR ION BEAMS IN THE RANGE 0 - 400 MeV 259 -------------------------------------------------------------------------------- 260 Two macro files (proton_therapy.mac and ion_therapy.mac) can be used for proton and ion 261 simulations. 262 263 Also the QGSP_BIC_EMY package can be used if the *Approach 3* is preferred. 264 265 INTERACTIVE COMMANDS 266 How to change Phantom and Detector geometries 267 In order to let the end user to change phantom and detector geometries and voxelization, some interactive commands have been provided. All parameters are mandatory, except those inside square brackets. 268 269 Detector geometry 270 271 The user can change: 272 273 (1) The detector (box) size. 274 275 (2) The voxels sizes. Changing this parameters, and/or the detector sizes, user should choose values in order to be divisors of the detector correspondent sizes. 276 For both above commands, zero or negative values mean << don't change it >> 277 278 (3) The displacement between the phantom and the detector. Displacement parameters refer to the lower left corner of the detector respect to that of the phantom, by the point of view of the beam. In this case zero or positive values are allowed, while the negatives ones mean: << don't change it>>. 279 280 Command synopsis: the <default values> follow "#" 281 282 283 1. /changeDetector/size <dimX> <dimY> <dimZ> <[unit]> # 4 4 4 cm 284 2. /changeDetector/voxelSize <dimX> <dimY> <dimZ> <[unit]> # 0.2 40 40 mm 285 3. /changeDetector/displacement <dispX> <dispY> <dispZ> <[unit]> # 0 18 18 cm 286 287 where the X dimension is that along the beam direction 288 289 Phantom geometry 290 291 (1) The phantom size. As usually, zero or negatives values mean: <<don't change it>>. 292 (2) The phantom position respect to the world. In this case specified values refer to the three components of the position of the phantom's center respect to the world's. 293 294 Command synopsis: 295 296 1. /changePhantom/size <dimX> <dimY> <dimZ> <[unit]> # 40 40 40 cm 297 2. /changePhantom/position <posX> <posY> <posZ> <[unit]> # 20 0 0 cm 298 299 All these commands must be followed by the command /changePhantom/update 300 in order to check and apply them to the real geometry. 301 Moreover must be issued between runs (so where you want but after the /run/initialize initialization command, or the G4State_Idle Geant4 state machine). 302 Obviously all the previous sizes must be set in order to maintain the detector inside the phantom, otherwise system complains. 303 304 Some examples follow: 305 306 /changeDetector/size 40 0 0 cm 307 # Will extend detector X size to cover in full the phantom X size 308 309 /changeDetector/size 0 4.5 0 cm 310 # Will extend the Y size to 4.5 cm (note that voxel size Y is automatically 311 # rounded to 4.5 cm because the default value along Y is 4 cm) 312 /changePhantom/update 313 # Remember to always update the geometry before the beamOn command!! 314 315 /changeDetector/size 0 8 0 cm 316 # Will extend the Y size to 8 cm. In this case voxel size Y doesn't change, but 317 # the number of voxel along Y doubles. 318 /changePhantom/update 319 320 321 /changeDetector/voxelSize 100 0 0 um 322 # 100 um should be a divisor of detector size X 323 # Will change only slabs X size to 100 um, without affecting the other. 324 /changePhantom/update 325 326 /changeDetector/displacement 0 0 0 # default unit mm 327 # Will place the detector in the left lower corner (from the point of view of the beam) of #the phantom. 328 /changePhantom/update 329 Stopping powers calculation 330 It is possible for the end-user to calculate, via macro command, stopping powers only for those materials inserted into G4NistMaterialBuilder class (about 300). 331 To get stopping powers user must provide this command line on the idle interactive terminal (or into a macro file) : 332 333 /parameter/getstopping <G4_material> <Emin> <Emax> <nPoints> <[particle]> <[output_filename]> 334 335 All parameters are mandatory except those inside square brackets []. 336 Default values for parameters inside square brackets are respectively proton and standard output (usually the user console terminal). 337 338 Parameters are respectively: 339 340 * The material (NIST) name (something like G4_..., the complete list of elements and materials is available into the G4NistMaterialBuilder class and can be printed to the terminal screen via the macro command: /parameter/nist ) 341 * Kinetic energy range in MeV and the number of data points to be retrieved (in a logarithmically uniform space) 342 * The particle name (proton, e+, e-, He3, neutron,... a full list can be gotten via the macro command: /particle/list). 343 Only for ions, user must firstly give them to the particle gun, for example issuing the macro commands: 344 a. /gun/particle ion 345 b. /gun/ion <Z> <A> <[charge]> 346 * The output filename: if users leave this blank then the standard output is used. 347 348 Below is an example in order to calculate the stopping power for alphas into Hydrogen between 1 keV to 150 MeV for 15 points: 349 350 /parameter/getstopping G4_H 0.001 150 15 alpha 351 352 # and for C12 ion: 353 354 /gun/particle ion 355 /gun/ion 6 12 6 356 /parameter/getstopping G4_H 0.001 150 15 C12[0.0] 357 358 # Value inside square brackets is the excitation energy of the ion (ground state). 359 360 HOW RUN HADRONTHERAPY 361 Run the example in interactive mode 147 362 > $G4WORDIR/bin/Linux-g++/Hadrontherapy 148 The defaultMacro.mac is executed 149 150 The primary particle beam parameter are: 151 Radiation: proton beam; 152 Energy distribution: gaussian; 153 Mean energy: 63.4 MeV; 154 Energy spread: 300 keV; 155 Beam spot size: 1 mm; 156 Beam angular spread: 0.057 deg; 157 158 The modulator wheel can be rotated via the messenger: 159 160 Idle>/modulator/angle/xx deg 161 162 To produce a Spread Out Bragg Peak using the modulator a macro 163 (modulatorMacro.mac) is provided. With this macro the modulator is 164 rotated of 360 degree at 1 deg steps. In each run 1000 protons are 165 generated as primary particles. Obviously a bigger resolution can be obtained 166 with smaller angles or increasing the protons number in each run. 167 168 Modulator wheel can be omitted setting its material air. 169 170 run $G4WORKDIR/bin/Linux-g++/Hadrontherapy visualisationMacro.mac 171 to visualise the experimental set-up with OpenGL 172 173 ---->5. PHYSICS 174 175 Both electromagnetic and hadronic physic processes are activated for 176 the particles of the experimental set-up. 177 Different physics models can be activated by the user interactively. 178 179 Examples of activation are provided in the macro files starting 180 with the string "physics": 181 182 All possible physics options are summarized in the file 183 physicsAllOptions.mac. 184 185 Different options concerning electromagnetic interactions of protons 186 and neutrons can be tested with the files: 187 physicsElectromagneticICRU49.mac 188 physicsElectromagneticZiegler77.mac 189 physicsElectromagneticZiegler85.mac 190 191 Different options concerning hadronic interactions of protons and 192 neutrons can be tested with the files: 193 physicsHadronicBertini.mac 194 physicsHadronicBinary.mac 195 physicsHadronicLEP.mac 196 physicsHadronicPrecompound.mac 197 198 NOTE: Apart from the different models for protons and neutrons, a user 199 can also select among several interaction models for particles like 200 electrons or photons. All possible options are listed in the file 201 physicsAllOptions.mac. 202 203 ---->6. SIMULATION OUTPUT 204 205 The output is an .hbk file (hadrontherapy.hbk) produced 206 if the variable G4ANALYSIS_USE is set to 1 and the analysis tool (AIDA 207 interface) correctly installed. 208 The file contains an histogram and an n-tuple. 209 The histogram contains the Bragg curve: energy deposited 210 by the proton beam (in MeV) versus the depth in water (in mm). 211 The n-tuple contains the total 3D energy deposit in the phantom; the information 212 is energy deposit in each voxel with respect to the position of the voxel. 213 214 Setup for analysis: AIDA 3.2.1 215 216 Users can download the analysis tools from: 217 http://aida.freehep.org/ 218 219 Note that the same information can be stored in any different format. 220 Please contact cirrone@lns.infn.it if you want store the information in 221 a different format. 222 223 --------------------------------------------------------------------------- 224 225 for comments, advices, doubts and questions please contact: 226 cirrone@lns.infn.it, giorgiorusso@lns.infn.it 227 228 last modified: A. Lechner, 16/11/2007 229 363 364 In this case the main file (Hadrontherapy.cc) performs different operations depending on which environment variable is activated; 365 For example, if the environment variable G4UI_USE_TCSH is activated, Hadrontherapy will start with the TCSH User Interface that has many useful functionalities. On the other hand, if this first variables is not defined, the program will continue searching for the G4UI_USE_QT variable and, finally, will open the standard G4UITerminal. 366 Run the example using macro files 367 Hadrontherapy can be launched using a macro file: 368 369 > $G4WORDIR/bin/Linux-g++/Hadrontherapy macroFile.mac 370 371 The defaultMacro.mac file is contained in the main directory of Hadrontherapy and is automatically readed in case the user launch the executable without a parameter. A big number of other macro are inside the /macro folder. 372 373 Example use of command based scoring 374 In the IAEA geometry it is possible to collect the energy deposition data using the Geant4 command based scoring feature. This allows the users to define scorers interactively in the user interface without writing a single line of C++. Below is listed an example usage of command based scoring: 375 376 /score/create/boxMesh boxMesh_1 377 #Box size is the radius of the box ie 20x20x20 gives 40x40x40 outer dimensions 378 /score/mesh/boxSize 13.95 16. 16. cm 379 /score/mesh/translate/xyz 69 0.0 0.0 cm 380 /score/mesh/nBin 400 1 1 # 400 bins in x-direction, 1 in y and z directions 381 382 SIMULATION OUTPUT 383 ASCII file 384 A .out file is generated at the end of each run, Dose.out is its default name that can be changed in the HadrontherapyMatrix.cc file. 385 The file can contain four columns; the first three columns represent the voxel indexes (that univocally identify the voxel volume), while the last column represent the dose deposited in the given voxel. 386 Alternatively, if the macro command /analysis/secondaries true is given, ordinated dose and fluence, for every secondary produced, is added to the file. 387 Setting the name of the ROOT output file 388 By default the name of the ROOT output file is DoseDistribution.root. The name of the file can be set by using command: 389 /analysis/setAnalysisFile <filename> 390 391 It is also possible to create multiple new output files in the same simulation session. For example: 392 /beam/energy/meanEnergy 4800 MeV 393 /analysis/setAnalysisFile firstRun.root 394 /run/beamOn 1000 395 /beam/energy/meanEnergy 3000 MeV 396 /analysis/setAnalysisFile secondRun.root 397 /run/beamOn 1000 398 Use of the ROOT analysis 399 It is possible to use ROOT data analysis package directly for the production of output files. 400 In the last version, anyway, this functionality must be implemented by User. This can be accomplished by setting an ad-hoc environment variable (i.e. G4ANALYSIS_USE_ROOT) to 1, adding in the code lines to create outputs with the ROOT libraries and recompiling the application. 401 In this case you must have the ROOT framework installed in your machine. 402 403 404 FUTURE CHALLENGES AND USERS' REQUESTS 405 This is a list of future components that will be added in Hadrontherapy and of main Users requests that we hope to fulfill in the next future. 406 What is in progress 407 1. A module for the simulation of an active beam line will be provided. 408 The Korean Group of the Proton therapy center, National Cancer Center is developing this. 409 2. Modules for LET and RBE (Relative Biological Effectiveness) calculation. The Catania Group in Collaboration with the Turin one is working on this. 410 3. Hadrontherapy will permit the simulation of a 'basic' experiment usefull in hadrontherapy applications. User will be able to simulate thin/thick target configuration to calculate quantities like double differential cross sections of secondaries produces, or fluence and yelds of primary and secondaries in a thick block. This work is maily discussed with P. Kaitaniemi and the Group from the Helsinki Institute of Physics. 411 What is requested from Users 412 1. Dicom interface 413 414 Please contact cirrone@lns.infn.it for more details or suggestions and feedbacks on this document 415 416 -
trunk/examples/advanced/hadrontherapy/defaultMacro.mac
r1230 r1313 1 # G.A.P.Cirrone1 # G.A.P.Cirrone 2 2 # 3 3 # Default macro file. It is called if no argument is provided at run … … 19 19 # Set of the physic models 20 20 # 21 /physic/addPhysics emstandard_opt3# Electromagnetic model21 /physic/addPhysics standard_opt3 # Electromagnetic model 22 22 /physic/addPhysics elastic # Hadronic elastic model 23 23 /physic/addPhysics binary # Hadronic inelastic model 24 24 /physic/addPhysics local_ion_ion_inelastic # Hadronic inelastic model for ions (local physic list) 25 26 25 27 26 28 ########################## … … 32 34 # Visualisation 33 35 # 34 /vis/scene/create 35 #/vis/open OGLIQt # only if QT library are installed 36 /vis/open OGLIX 36 /vis/open OGL 37 37 /vis/viewer/flush 38 38 /vis/viewer/set/viewpointThetaPhi 30 140 deg 39 39 /vis/viewer/zoom 1 40 40 /vis/viewer/pan -10 0 cm 41 /tracking/storeTrajectory 1 42 #/vis/scene/endOfEventAction accumulate 43 /vis/scene/endOfEventAction accumulate -1 44 /vis/viewer/update 41 /vis/scene/add/trajectories 42 /vis/scene/endOfEventAction accumulate 45 43 46 44 ########################## … … 69 67 # Start of the run 70 68 # 71 /run/beamOn 10 69 # If secondaries dose/fluence are needed 70 #/analysis/secondaries true 71 72 /run/beamOn 100 73 74 -
trunk/examples/advanced/hadrontherapy/include/CVS/Entries
r1230 r1313 1 /Decay.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 32 /HadrontherapyAnalysisFileMessenger.hh/1. 4/Fri Jan 8 13:32:05 2010//Tgeant4-09-033 /HadrontherapyAnalysisManager.hh/1. 16/Wed Nov 18 14:37:51 2009//Tgeant4-09-034 /HadrontherapyDetectorConstruction.hh/1.2 4/Fri Jan 8 13:32:05 2010//Tgeant4-09-035 /HadrontherapyDetectorHit.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 36 /HadrontherapyDetectorMessenger.hh/1.1 5/Fri Jan 8 13:32:05 2010//Tgeant4-09-037 /HadrontherapyDetectorROGeometry.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 38 /HadrontherapyDetectorSD.hh/1. 2/Wed Nov 18 14:37:51 2009//Tgeant4-09-039 /HadrontherapyDummySD.hh/1.6/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 310 /HadrontherapyEventAction.hh/1.1 5/Wed Nov 18 14:37:51 2009//Tgeant4-09-0311 /HadrontherapyEventActionMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 312 /HadrontherapyGeometryController.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 313 /HadrontherapyGeometryMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 314 /HadrontherapyInteractionParameters.hh/1. 5/Fri Jan 8 13:32:05 2010//Tgeant4-09-0315 /HadrontherapyMatrix.hh/1. 6/Fri Jan 8 13:32:05 2010//Tgeant4-09-0316 /HadrontherapyModulator.hh/1.5/Thu Jun 29 15:58:08 2006//Tgeant4-09-0 317 /HadrontherapyParameterMessenger.hh/1.5/Fri Jan 8 13:32:05 2010//Tgeant4-09-0 318 /HadrontherapyParticles.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 319 /HadrontherapyPhysicsList.hh/1.2 1/Fri Jan 8 13:32:05 2010//Tgeant4-09-0320 /HadrontherapyPhysicsListMessenger.hh/1. 9/Wed Nov 18 14:37:51 2009//Tgeant4-09-0321 /HadrontherapyPrimaryGeneratorAction.hh/1.1 7/Wed Nov 18 14:37:51 2009//Tgeant4-09-0322 /HadrontherapyPrimaryGeneratorMessenger.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 323 /HadrontherapyRunAction.hh/1.1 4/Wed Nov 18 14:37:51 2009//Tgeant4-09-0324 /HadrontherapyStepMax.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 325 /HadrontherapyStepMaxMessenger.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 326 /HadrontherapySteppingAction.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 327 /IAEADetectorConstruction.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 328 /IAEADetectorMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 329 /IAEAScoreWriter.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 330 /LocalINCLIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 331 /LocalIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-0 332 /PassiveProtonBeamLine.hh/1. 5/Wed Nov 18 14:37:51 2009//Tgeant4-09-0333 /PassiveProtonBeamLineMessenger.hh/1. 2/Wed Nov 18 14:37:51 2009//Tgeant4-09-031 /Decay.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 2 /HadrontherapyAnalysisFileMessenger.hh/1.6/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 3 /HadrontherapyAnalysisManager.hh/1.20/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 4 /HadrontherapyDetectorConstruction.hh/1.28/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 5 /HadrontherapyDetectorHit.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 6 /HadrontherapyDetectorMessenger.hh/1.18/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 7 /HadrontherapyDetectorROGeometry.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 8 /HadrontherapyDetectorSD.hh/1.3/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 9 /HadrontherapyDummySD.hh/1.6/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 10 /HadrontherapyEventAction.hh/1.16/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 11 /HadrontherapyEventActionMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 12 /HadrontherapyGeometryController.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 13 /HadrontherapyGeometryMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 14 /HadrontherapyInteractionParameters.hh/1.8/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 15 /HadrontherapyMatrix.hh/1.12/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 16 /HadrontherapyModulator.hh/1.5/Thu Jun 29 15:58:08 2006//Tgeant4-09-04-beta-cand-00 17 /HadrontherapyParameterMessenger.hh/1.5/Fri Jan 8 13:32:05 2010//Tgeant4-09-04-beta-cand-00 18 /HadrontherapyParticles.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 19 /HadrontherapyPhysicsList.hh/1.22/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 20 /HadrontherapyPhysicsListMessenger.hh/1.10/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 21 /HadrontherapyPrimaryGeneratorAction.hh/1.18/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 22 /HadrontherapyPrimaryGeneratorMessenger.hh/1.7/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 23 /HadrontherapyRunAction.hh/1.16/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 24 /HadrontherapyStepMax.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 25 /HadrontherapyStepMaxMessenger.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 26 /HadrontherapySteppingAction.hh/1.16/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 27 /IAEADetectorConstruction.hh/1.5/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 28 /IAEADetectorMessenger.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 29 /IAEAScoreWriter.hh/1.3/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 30 /LocalINCLIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 31 /LocalIonIonInelasticPhysic.hh/1.2/Wed Nov 18 14:37:51 2009//Tgeant4-09-04-beta-cand-00 32 /PassiveProtonBeamLine.hh/1.6/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 33 /PassiveProtonBeamLineMessenger.hh/1.3/Mon Jun 14 13:47:41 2010//Tgeant4-09-04-beta-cand-00 34 34 D -
trunk/examples/advanced/hadrontherapy/include/CVS/Tag
r1230 r1313 1 Ngeant4-09-0 31 Ngeant4-09-04-beta-cand-00 -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisFileMessenger.hh
r1230 r1313 30 30 #define HadrontherapyAnalysisFileMessenger_h 1 31 31 32 #ifdef ANALYSIS_USE33 32 34 33 #include "G4UImessenger.hh" … … 36 35 37 36 class HadrontherapyAnalysisManager; ///< Provides SetanalysisFileName() 38 class G4UIcmdWithAString; ///< Provides possibility to add commands 37 class G4UIcmdWithAString; 38 class G4UIcmdWithABool; 39 39 40 40 /** … … 68 68 * Constructor requires command name and messenger class(this). 69 69 */ 70 G4UIcmdWithAString* FileNameCmd; 70 G4UIcmdWithABool *secondariesCmd; 71 #ifdef G4ANALYSIS_USE_ROOT 72 G4UIcmdWithAString *FileNameCmd; 73 #endif 71 74 }; 72 75 73 76 #endif 74 #endif -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyAnalysisManager.hh
r1230 r1313 1 //2 // ********************************************************************3 // * License and Disclaimer *4 // * *5 // * The Geant4 software is copyright of the Copyright Holders of *6 // * the Geant4 Collaboration. It is provided under the terms and *7 // * conditions of the Geant4 Software License, included in the file *8 // * LICENSE and available at http://cern.ch/geant4/license . These *9 // * include a list of copyright holders. *10 // * *11 // * Neither the authors of this software system, nor their employing *12 // * institutes,nor the agencies providing financial support for this *13 // * work make any representation or warranty, express or implied, *14 // * regarding this software system or assume any liability for its *15 // * use. Please see the license in the file LICENSE and URL above *16 // * for the full disclaimer and the limitation of liability. *17 // * *18 // * This code implementation is the result of the scientific and *19 // * technical work of the GEANT4 collaboration. *20 // * By using, copying, modifying or distributing the software (or *21 // * any work based on the software) you agree to acknowledge its *22 // * use in resulting scientific publications, and indicate your *23 // * acceptance of all terms of the Geant4 Software license. *24 // ********************************************************************25 //26 // HadrontherapyAnalysisManager.hh; May 200527 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // HadrontherapyAnalysisManager.hh; May 2005 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 28 29 29 #ifndef HADRONTHERAPYANALYSISMANAGER_HH … … 32 32 #include "globals.hh" 33 33 34 #ifdef ANALYSIS_USE ///< If we use analysis35 36 #ifdef G4ANALYSIS_USE ///< If analysis is done via AIDA37 #include <AIDA/AIDA.h>38 39 namespace AIDA{40 class ITree;41 class IAnalysisFactory;42 class ITreeFactory;43 }44 #endif45 34 46 35 #ifdef G4ANALYSIS_USE_ROOT ///< If analysis is done directly with ROOT … … 50 39 #include "TH1F.h" 51 40 #endif 52 53 41 /** 54 42 * Messenger class for analysis-settings for HadronTherapyAnalysisManager … … 64 52 /** 65 53 * Analysis manager is a singleton object (there is only one instance). 66 * The pointer to this object is available through the use of the method getInstance();54 * The pointer to this object is available through the use of the method GetInstance(); 67 55 * 68 * @see getInstance69 */ 70 71 56 * @see GetInstance 57 */ 58 HadrontherapyAnalysisManager(); 59 72 60 public: 73 ~HadrontherapyAnalysisManager(); 74 75 /** 76 * Get the pointer to the analysis manager. 77 */ 78 static HadrontherapyAnalysisManager* getInstance(); 79 80 /** 81 * Book the histograms and ntuples in an AIDA or ROOT file. 82 */ 83 void book(); 84 /** 85 * Set name for the analysis file .root (used by macro) 86 */ 87 void SetAnalysisFileName(G4String); 88 89 /** 90 * Fill the ntuple with the energy deposit in the phantom 91 */ 92 void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId, 93 G4double energyDeposit); 94 95 void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom 96 97 void SecondaryProtonEnergyDeposit(G4int slice, G4double energy); 98 ///< Fill 1D histogram with the energy deposit of secondary protons 99 100 void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy); 101 ///< Fill 1D histogram with the energy deposit of secondary neutrons 102 103 void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy); 104 ///< Fill 1D histogram with the energy deposit of secondary alpha particles 105 106 void SecondaryGammaEnergyDeposit(G4int slice, G4double energy); 107 ///< Fill 1D histogram with the energy deposit of secondary gamma 108 109 void SecondaryElectronEnergyDeposit(G4int slice, G4double energy); 110 ///< Fill 1D histogram with the energy deposit of secondary electrons 111 112 void SecondaryTritonEnergyDeposit(G4int slice, G4double energy); 113 ///< Fill 1D histogram with the energy deposit of secondary tritons 114 115 void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy); 116 ///< Fill 1D histogram with the energy deposit of secondary deuterons 117 118 void SecondaryPionEnergyDeposit(G4int slice, G4double energy); 119 ///< Fill 1D histogram with the energy deposit of secondary pions 120 121 void electronEnergyDistribution(G4double secondaryParticleKineticEnergy); 122 ///< Energy distribution of secondary electrons originated in the phantom 123 124 void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy); 125 ///< Energy distribution of secondary gamma originated in the phantom 126 127 void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy); 128 ///< Energy distribution of secondary deuterons originated in the phantom 129 130 void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy); 131 ///< Energy distribution of secondary tritons originated in the phantom 132 133 void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy); 134 ///< Energy distribution of secondary alpha originated in the phantom 135 136 void heliumEnergy(G4double secondaryParticleKineticEnergy); 137 ///< Energy distribution of the helium (He3 and alpha) particles after the phantom 138 139 void hydrogenEnergy(G4double secondaryParticleKineticEnergy); 140 ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom 141 142 void fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ); 143 ///< Energy ntuple 144 145 void genericIonInformation(G4int, G4double, G4int, G4double); 146 147 void ThintargetBeamDisp(G4double,G4double); 148 149 void startNewEvent(); 150 ///< Tell the analysis manager that a new event is starting 151 152 void setGeometryMetaData(G4double, G4double, G4double); 153 ///< from the detector construction information about the geometry can be written as metadata 154 155 void setBeamMetaData(G4double, G4double); 156 ///< metadata about the beam can be written this way 157 158 void finish(); 159 ///< Close the .hbk file with the histograms and the ntuples 160 161 void flush(); 162 163 #ifdef G4ANALYSIS_USE_ROOT 61 ~HadrontherapyAnalysisManager(); 62 63 /** 64 * Get the pointer to the analysis manager. 65 */ 66 static HadrontherapyAnalysisManager* GetInstance(); 67 68 #ifdef G4ANALYSIS_USE_ROOT 69 /** 70 * Clear analysis manager heap. 71 */ 72 void Clear(); 73 74 /** 75 * Book the histograms and ntuples in an AIDA or ROOT file. 76 */ 77 void book(); 78 /** 79 * Set name for the analysis file .root (used by macro) 80 */ 81 void SetAnalysisFileName(G4String); 82 83 /** 84 * Fill the ntuple with the energy deposit in the phantom 85 */ 86 void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId, 87 G4double energyDeposit); 88 89 void BraggPeak(G4int, G4double); ///< Fill 1D histogram with the Bragg peak in the phantom 90 91 void SecondaryProtonEnergyDeposit(G4int slice, G4double energy); 92 ///< Fill 1D histogram with the energy deposit of secondary protons 93 94 void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy); 95 ///< Fill 1D histogram with the energy deposit of secondary neutrons 96 97 void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy); 98 ///< Fill 1D histogram with the energy deposit of secondary alpha particles 99 100 void SecondaryGammaEnergyDeposit(G4int slice, G4double energy); 101 ///< Fill 1D histogram with the energy deposit of secondary gamma 102 103 void SecondaryElectronEnergyDeposit(G4int slice, G4double energy); 104 ///< Fill 1D histogram with the energy deposit of secondary electrons 105 106 void SecondaryTritonEnergyDeposit(G4int slice, G4double energy); 107 ///< Fill 1D histogram with the energy deposit of secondary tritons 108 109 void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy); 110 ///< Fill 1D histogram with the energy deposit of secondary deuterons 111 112 void SecondaryPionEnergyDeposit(G4int slice, G4double energy); 113 ///< Fill 1D histogram with the energy deposit of secondary pions 114 115 void electronEnergyDistribution(G4double secondaryParticleKineticEnergy); 116 ///< Energy distribution of secondary electrons originated in the phantom 117 118 void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy); 119 ///< Energy distribution of secondary gamma originated in the phantom 120 121 void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy); 122 ///< Energy distribution of secondary deuterons originated in the phantom 123 124 void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy); 125 ///< Energy distribution of secondary tritons originated in the phantom 126 127 void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy); 128 ///< Energy distribution of secondary alpha originated in the phantom 129 130 void heliumEnergy(G4double secondaryParticleKineticEnergy); 131 ///< Energy distribution of the helium (He3 and alpha) particles after the phantom 132 133 void hydrogenEnergy(G4double secondaryParticleKineticEnergy); 134 ///< Energy distribution of the hydrogen (proton, d, t) particles after the phantom 135 136 //Kinetic energy by voxel, mass number A and atomic number Z. 137 void FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy); 138 139 //Kinetic energy by voxel, mass number A and atomic number Z of only primary particles 140 void FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy); 141 142 ///< Energy by voxel, mass number A and atomic number Z. 143 void FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence); 144 145 void FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ); 146 ///< Energy ntuple 147 148 void FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD); 149 ///< let ntuple 150 151 void genericIonInformation(G4int, G4double, G4int, G4double); 152 153 void ThintargetBeamDisp(G4double,G4double); 154 155 void startNewEvent(); 156 ///< Tell the analysis manager that a new event is starting 157 158 void setGeometryMetaData(G4double, G4double, G4double); 159 ///< from the detector construction information about the geometry can be written as metadata 160 161 void setBeamMetaData(G4double, G4double); 162 ///< metadata about the beam can be written this way 163 164 void flush(); 165 ///< Close the .hbk file with the histograms and the ntuples 164 166 private: 165 TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) { 166 TH1F *histo = new TH1F(name, title, bins, xmin, xmax); 167 histo->SetLineWidth(2); 168 return histo; 169 } 170 #endif 171 167 TH1F *createHistogram1D(const TString name, const TString title, int bins, double xmin, double xmax) { 168 TH1F *histo = new TH1F(name, title, bins, xmin, xmax); 169 histo->SetLineWidth(2); 170 return histo; 171 } 172 172 173 private: 173 static HadrontherapyAnalysisManager* instance; 174 HadrontherapyAnalysisFileMessenger* fMess; 175 G4String analysisFileName; 176 #ifdef G4ANALYSIS_USE 177 AIDA::IAnalysisFactory* aFact; 178 AIDA::ITree* theTree; 179 AIDA::IHistogramFactory *histFact; 180 AIDA::ITupleFactory *tupFact; 181 AIDA::IHistogram1D *h1; 182 AIDA::IHistogram1D *h2; 183 AIDA::IHistogram1D *h3; 184 AIDA::IHistogram1D *h4; 185 AIDA::IHistogram1D *h5; 186 AIDA::IHistogram1D *h6; 187 AIDA::IHistogram1D *h7; 188 AIDA::IHistogram1D *h8; 189 AIDA::IHistogram1D *h9; 190 AIDA::IHistogram1D *h10; 191 AIDA::IHistogram1D *h11; 192 AIDA::IHistogram1D *h12; 193 AIDA::IHistogram1D *h13; 194 AIDA::IHistogram1D *h14; 195 AIDA::IHistogram1D *h15; 196 AIDA::IHistogram1D *h16; 197 AIDA::ITuple *ntuple; 198 AIDA::ITuple *ionTuple; 199 AIDA::ITuple *fragmentTuple; 200 #endif 201 #ifdef G4ANALYSIS_USE_ROOT 202 TFile *theTFile; 203 TH1F *histo1; 204 TH1F *histo2; 205 TH1F *histo3; 206 TH1F *histo4; 207 TH1F *histo5; 208 TH1F *histo6; 209 TH1F *histo7; 210 TH1F *histo8; 211 TH1F *histo9; 212 TH1F *histo10; 213 TH1F *histo11; 214 TH1F *histo12; 215 TH1F *histo13; 216 TH1F *histo14; 217 TH1F *histo15; 218 TH1F *histo16; 219 220 TNtuple *theROOTNtuple; 221 TNtuple *theROOTIonTuple; 222 TNtuple *fragmentNtuple; // fragments 223 TNtuple *metaData; 224 #endif 225 G4long eventCounter; // Simulation metadata 226 G4double detectorDistance; 227 G4double phantomDepth; 228 G4double beamEnergy; 229 G4double energyError; 230 G4double phantomCenterDistance; 174 #endif 175 static HadrontherapyAnalysisManager* instance; 176 HadrontherapyAnalysisFileMessenger* fMess; 177 #ifdef G4ANALYSIS_USE_ROOT 178 G4String analysisFileName; 179 TFile *theTFile; 180 TH1F *histo1; 181 TH1F *histo2; 182 TH1F *histo3; 183 TH1F *histo4; 184 TH1F *histo5; 185 TH1F *histo6; 186 TH1F *histo7; 187 TH1F *histo8; 188 TH1F *histo9; 189 TH1F *histo10; 190 TH1F *histo11; 191 TH1F *histo12; 192 TH1F *histo13; 193 TH1F *histo14; 194 TH1F *histo15; 195 TH1F *histo16; 196 197 TNtuple *kinFragNtuple; 198 TNtuple *kineticEnergyPrimaryNtuple; 199 200 // ntuple containing the fluence of all the particle in any voxel 201 TNtuple *doseFragNtuple; 202 203 // ntuple containing the fluence of all the particle in any voxel 204 TNtuple *fluenceFragNtuple; 205 206 // ntuple containing the fluence of all the particle in any voxel 207 TNtuple *letFragNtuple; 208 209 TNtuple *theROOTNtuple; 210 TNtuple *theROOTIonTuple; 211 TNtuple *fragmentNtuple; // fragments 212 TNtuple *metaData; 213 G4long eventCounter; // Simulation metadata 214 G4double detectorDistance; 215 G4double phantomDepth; 216 G4double beamEnergy; 217 G4double energyError; 218 G4double phantomCenterDistance; 219 #endif 231 220 }; 232 221 #endif 233 222 234 #endif 235 223 224 -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorConstruction.hh
r1230 r1313 56 56 void ConstructPhantom(); 57 57 void ConstructDetector(); 58 void ConstructSensitiveDetector(G4ThreeVector position_respect_to_WORLD); 59 58 void ConstructSensitiveDetector(G4ThreeVector positionToWORLD); 59 void ParametersCheck(); 60 60 61 public: 61 62 // Get detector position relative to WORLD … … 65 66 } 66 67 ///////////////////////////////////////////////////////////////////////////// 67 // Get displacement between phantom and detector by detector position , phantomand detector sizes68 // Get displacement between phantom and detector by detector position (center of), phantom (center of) and detector sizes 68 69 inline G4ThreeVector GetDetectorToPhantomPosition() 69 70 { 70 return G4ThreeVector(phantomSizeX - detectorSizeX+ detectorPosition.getX(),71 phantomSizeY - detectorSizeY+ detectorPosition.getY(),72 phantomSizeZ - detectorSizeZ+ detectorPosition.getZ()71 return G4ThreeVector(phantomSizeX/2 - detectorSizeX/2 + detectorPosition.getX(), 72 phantomSizeY/2 - detectorSizeY/2 + detectorPosition.getY(), 73 phantomSizeZ/2 - detectorSizeZ/2 + detectorPosition.getZ() 73 74 ); 74 75 } … … 79 80 { 80 81 // Adjust detector position 81 detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX + detectorSizeX);82 detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY + detectorSizeY);83 detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ + detectorSizeZ);82 detectorPosition.setX(detectorToPhantomPosition.getX() - phantomSizeX/2 + detectorSizeX/2); 83 detectorPosition.setY(detectorToPhantomPosition.getY() - phantomSizeY/2 + detectorSizeY/2); 84 detectorPosition.setZ(detectorToPhantomPosition.getZ() - phantomSizeZ/2 + detectorSizeZ/2); 84 85 85 if (detectorPhysicalVolume) detectorPhysicalVolume -> SetTranslation(detectorPosition); 86 //G4cout << "*************** DetectorToPhantomPosition " << detectorToPhantomPosition/cm << "\n"; 87 //G4cout << "*************** DetectorPosition " << detectorPosition/cm << "\n"; 86 88 } 87 89 ///////////////////////////////////////////////////////////////////////////// 88 90 // Check whether detector is inside phantom 89 inline bool IsInside(G4double detector HalfX,90 G4double detector HalfY,91 G4double detector HalfZ,92 G4double phantom HalfX,93 G4double phantom HalfY,94 G4double phantom HalfZ,91 inline bool IsInside(G4double detectorX, 92 G4double detectorY, 93 G4double detectorZ, 94 G4double phantomX, 95 G4double phantomY, 96 G4double phantomZ, 95 97 G4ThreeVector detectorToPhantomPosition) 96 98 { 97 99 // Dimensions check... X Y and Z 98 100 // Firstly check what dimension we are modifying 99 if (detectorHalfX > 0. && phantomHalfX > 0. && detectorToPhantomPosition.getX() >=0.)100 101 { 101 if (detector HalfX > phantomHalfX)102 if (detectorX > phantomX) 102 103 { 103 104 G4cout << "Error: Detector X dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 104 105 return false; 105 106 } 106 if ( 2*(phantomHalfX - detectorHalfX) < detectorToPhantomPosition.getX())107 if ( (phantomX - detectorX) < detectorToPhantomPosition.getX()) 107 108 { 108 109 G4cout << "Error: X dimension doesn't fit with detector to phantom relative position" << G4endl; … … 111 112 } 112 113 113 if (detectorHalfY > 0. && phantomHalfY > 0.&& detectorToPhantomPosition.getY() >=0.)114 114 { 115 if (detector HalfY > phantomHalfY)115 if (detectorY > phantomY) 116 116 { 117 117 G4cout << "Error: Detector Y dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 118 118 return false; 119 119 } 120 if ( 2*(phantomHalfY - detectorHalfY) < detectorToPhantomPosition.getY())120 if ( (phantomY - detectorY) < detectorToPhantomPosition.getY()) 121 121 { 122 122 G4cout << "Error: Y dimension doesn't fit with detector to phantom relative position" << G4endl; … … 125 125 } 126 126 127 if (detectorHalfZ > 0. && phantomHalfZ > 0.&& detectorToPhantomPosition.getZ() >=0.)128 127 { 129 if (detector HalfZ > phantomHalfZ)128 if (detectorZ > phantomZ) 130 129 { 131 130 G4cout << "Error: Detector Z dimension must be smaller or equal to the corrispondent of the phantom" << G4endl; 132 131 return false; 133 132 } 134 if ( 2*(phantomHalfZ - detectorHalfZ) < detectorToPhantomPosition.getZ())133 if ( (phantomZ - detectorZ) < detectorToPhantomPosition.getZ()) 135 134 { 136 135 G4cout << "Error: Z dimension doesn't fit with detector to phantom relative position" << G4endl; … … 138 137 } 139 138 } 140 /* 141 G4cout << "Displacement between Phantom and Detector is: "; 142 G4cout << "DX= "<< G4BestUnit(detectorToPhantomPosition.getX(),"Length") << 143 "DY= "<< G4BestUnit(detectorToPhantomPosition.getY(),"Length") << 144 "DZ= "<< G4BestUnit(detectorToPhantomPosition.getZ(),"Length") << G4endl; 145 */ 139 146 140 return true; 147 141 } 148 142 ///////////////////////////////////////////////////////////////////////////// 149 143 150 G4bool SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ); 151 G4bool SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ); 152 G4bool SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ); 153 G4bool SetPhantomPosition(G4ThreeVector); 154 G4bool SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition); 144 G4bool SetPhantomMaterial(G4String material); 145 void SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ); 146 void SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ); 147 void SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ); 148 void SetPhantomPosition(G4ThreeVector); 149 void SetDetectorToPhantomPosition(G4ThreeVector DetectorToPhantomPosition); 150 void UpdateGeometry(); 151 void PrintParameters(); 155 152 G4LogicalVolume* GetDetectorLogicalVolume(){ return detectorLogicalVolume;} 156 153 … … 169 166 HadrontherapyMatrix* matrix; 170 167 171 G4VPhysicalVolume* phantomPhysicalVolume; 172 G4LogicalVolume* phantomLogicalVolume; 173 G4LogicalVolume* detectorLogicalVolume; 174 G4VPhysicalVolume* detectorPhysicalVolume; 168 G4Box *phantom , *detector; 169 G4LogicalVolume *phantomLogicalVolume, *detectorLogicalVolume; 170 G4VPhysicalVolume *phantomPhysicalVolume, *detectorPhysicalVolume; 175 171 176 172 G4double phantomSizeX; … … 192 188 G4int numberOfVoxelsAlongZ; 193 189 194 G4Box* phantom; 195 G4Box* detector; 190 G4double volumeOfVoxel, massOfVoxel; 196 191 192 G4Material *phantomMaterial, *detectorMaterial; 193 G4Region* aRegion; 197 194 }; 198 195 #endif -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorMessenger.hh
r1230 r1313 35 35 class HadrontherapyDetectorConstruction; 36 36 class G4UIdirectory; 37 class G4UIcmdWithADoubleAndUnit;38 class G4UIcmdWithAString;39 37 class G4UIcmdWith3VectorAndUnit; 38 class G4UIcmdWithoutParameter; 39 class G4UIcmdWithAString; 40 40 41 41 class HadrontherapyDetectorMessenger: public G4UImessenger … … 54 54 G4UIdirectory *changeThePhantomDir, *changeTheDetectorDir; 55 55 56 G4UIcmdWithoutParameter *updateCmd; 57 G4UIcmdWithAString *changeThePhantomMaterialCmd; 56 58 G4UIcmdWith3VectorAndUnit *changeThePhantomSizeCmd, 57 59 *changeThePhantomPositionCmd, -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyDetectorSD.hh
r1230 r1313 43 43 ~HadrontherapyDetectorSD(); 44 44 45 std::ofstream ofs; 45 46 void Initialize(G4HCofThisEvent*); 46 47 -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyEventAction.hh
r1230 r1313 59 59 G4String drawFlag; //Visualisation flag 60 60 G4int hitsCollectionID; 61 HadrontherapyMatrix *matrix;61 //HadrontherapyMatrix *matrix; 62 62 G4int printModulo; 63 63 HadrontherapyEventActionMessenger* pointerEventMessenger; -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyInteractionParameters.hh
r1230 r1313 34 34 #include "G4NistElementBuilder.hh" 35 35 36 #ifdef G4ANALYSIS_USE_ROOT 37 #include "TROOT.h" 38 #include "TCanvas.h" 39 #include "TFile.h" 40 #include "TH1F.h" 41 #include "TH2F.h" 42 #include "TGraph.h" 43 #include "TLegend.h" 44 #include "TLegendEntry.h" 45 #include "TStyle.h" 46 #endif 47 36 48 class HadrontherapyDetectorConstruction; 37 49 class HadrontherapyParameterMessenger; 50 class G4ParticleDefinition; 51 class G4Material; 52 38 53 class HadrontherapyInteractionParameters : public G4EmCalculator 39 54 { 40 55 public: 41 56 42 HadrontherapyInteractionParameters( );43 57 HadrontherapyInteractionParameters(G4bool); 58 ~HadrontherapyInteractionParameters(); 44 59 45 // Get data for Mass SP (MeV*cm2/g)60 // Get data for Mass SP 46 61 // G4NistMaterialBuilder class materials 47 62 // User must provide: material kinetic energy lower limit, kinetic energy upper limit, number of points to retrieve, 48 63 // [particle], [output filename]. 49 64 50 bool GetStoppingTable (const G4String& vararg); 65 G4bool GetStoppingTable (const G4String& vararg); 66 G4double GetStopping (G4double energy, 67 const G4ParticleDefinition*, 68 const G4Material*, 69 G4double density = 0.); 70 #ifdef G4ANALYSIS_USE_ROOT 71 void PlotStopping(const G4String&); 72 #endif 51 73 void ListOfNistMaterials (const G4String& vararg); 52 74 void BeamOn(); … … 55 77 private: 56 78 G4Material* GetNistMaterial(G4String material); 57 58 79 G4NistElementBuilder* nistEle; 59 80 G4NistMaterialBuilder* nistMat; 60 G4double kinEmin, kinEmax, npoints;61 G4String particle, material, filename;62 81 std::ofstream outfile; 63 82 std::ostream data; 64 83 G4Material* Pmaterial; 65 G4double density;66 G4EmCalculator* emCal;67 84 HadrontherapyParameterMessenger* pMessenger; 68 85 bool beamFlag; 86 87 #ifdef G4ANALYSIS_USE_ROOT 88 TCanvas *theRootCanvas; 89 TGraph *theRootGraph; 90 TAxis *axisX, *axisY; 91 #endif 92 G4double kinEmin, kinEmax, npoints; 93 G4String particle, material, filename; 94 G4double dedxtot, density; 95 std::vector<G4double> energy; 96 std::vector<G4double> massDedx; 97 69 98 }; 70 99 #endif -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyMatrix.hh
r1230 r1313 29 29 #ifndef HadrontherapyMatrix_H 30 30 #define HadrontherapyMatrix_H 1 31 31 #include <G4ParticleDefinition.hh> 32 32 #include "globals.hh" 33 33 #include <vector> 34 #include <fstream> 34 35 35 36 // The information: energy deposit and position in the phantom 36 37 // is stored in a matrix 37 38 39 // type struct useful to store nucludes data 40 struct ion 41 { 42 G4bool isPrimary; // true if particle is primary 43 G4int PDGencoding; // Particle data group id for the particle 44 //G4String extName; // AZ[excitation energy]: like He3[1277.4], He4[0.0], Li7[231.4], ... 45 G4String name; // simple name without excitation energy: He3, He4, Li7, ... 46 G4int len; // name length 47 G4int Z; // atomic number 48 G4int A; // mass number 49 G4double *dose; // pointer to dose matrix 50 unsigned int *fluence; // pointer to fluence matrix 51 //friend bool operator<(const ion& a, const ion& b) {return (a.Z == b.Z) ? b.A < a.A : b.Z < a.Z ;} 52 G4bool operator<(const ion& a) const{return (this->Z == a.Z) ? this-> A < a.A : this->Z < a.Z ;} 53 }; 54 38 55 class HadrontherapyMatrix 39 56 { 40 57 private: 41 HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ); //<--- this is supposed to be a singleton 58 HadrontherapyMatrix(G4int numberOfVoxelAlongX, 59 G4int numberOfVoxelAlongY, 60 G4int numberOfVoxelAlongZ, 61 G4double massOfVoxel); //< this is supposed to be a singleton 62 42 63 43 64 public: 44 65 45 66 ~HadrontherapyMatrix(); 46 // Get object instance only 47 static HadrontherapyMatrix* getInstance(); 48 // Make & Get instance 49 static HadrontherapyMatrix* getInstance(G4int nX, G4int nY, G4int nZ); 50 51 void flush(); 52 67 // Get object instance only 68 static HadrontherapyMatrix* GetInstance(); 69 // Make & Get instance 70 static HadrontherapyMatrix* GetInstance(G4int nX, G4int nY, G4int nZ, G4double mass); 71 72 static G4bool secondaries; 73 // Full list of generated nuclides 74 void PrintNuclides(); 75 // Hit array marker (useful to avoid multiple counts of fluence) 76 void ClearHitTrack(); 77 G4int* GetHitTrack(G4int i, G4int j, G4int k); 78 79 // All the elements of the matrix are initialised to zero 53 80 void Initialize(); 54 // All the elements of the matrix are initialised to zero 55 81 void Clear(); 82 // Fill DOSE/fluence matrix for particle: 83 // if fluence parameter is true then fluence at voxel (i, j, k) is increased 84 // else energyDeposit fill the dose matrix for voxel (i,j,k) 85 G4bool Fill(G4int, G4ParticleDefinition* particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false); 86 87 // Fill TOTAL DOSE matrix for primary particles only 56 88 void Fill(G4int i, G4int j, G4int k, G4double energyDeposit); 57 89 // The matrix is filled with the energy deposit 58 90 // in the element corresponding to the voxel of the phantom where 59 91 // the energy deposit was registered 60 61 void TotalEnergyDeposit(); 92 62 93 // Store the information of the matrix in a ntuple and in 63 94 // a 1D Histogram 64 65 inline G4int Index(G4int i, G4int j, G4int k){ return (i * numberVoxelY + j) * numberVoxelZ + k; } 66 // Get a unique index from a three dimensional voxel information 95 void TotalEnergyDeposit(); 96 97 // Store single matrix data to filename 98 void StoreMatrix(G4String file, void* data,size_t psize); 99 // Store all fluence data to filenames 100 void StoreFluenceData(); 101 // Store all dose data to filenames 102 void StoreDoseData(); 67 103 104 // Store all data (except the total dose) to ONE filename 105 void StoreDoseFluenceAscii(); 106 107 #ifdef G4ANALYSIS_USE_ROOT 108 void StoreDoseFluenceRoot(); 109 #endif 110 111 inline G4int Index(G4int i, G4int j, G4int k) { return (i * numberOfVoxelAlongY + j) * numberOfVoxelAlongZ + k; } 112 // Get a unique index from a three dimensional one 113 114 G4double * GetMatrix(){return matrix;} 115 116 G4int GetNvoxel(){return numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;} 117 // Total number of voxels read only access 118 G4int GetNumberOfVoxelAlongX(){return numberOfVoxelAlongX;} 119 G4int GetNumberOfVoxelAlongY(){return numberOfVoxelAlongY;} 120 G4int GetNumberOfVoxelAlongZ(){return numberOfVoxelAlongZ;} 68 121 private: 69 122 70 123 static HadrontherapyMatrix* instance; 71 G4int numberVoxelX; 72 G4int numberVoxelY; 73 G4int numberVoxelZ; 124 G4int numberOfVoxelAlongX; 125 G4int numberOfVoxelAlongY; 126 G4int numberOfVoxelAlongZ; 127 G4double massOfVoxel; 128 74 129 G4double* matrix; 130 G4int* hitTrack; 131 G4String filename; 132 std::ofstream ofs; 133 134 // Dose&fluence data store 135 std::vector <ion> ionStore; 136 // want secondaries? 137 G4double doseUnit; 75 138 }; 76 139 #endif 140 -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsList.hh
r1230 r1313 51 51 void SetCutForElectron(G4double); 52 52 void SetCutForPositron(G4double); 53 53 void SetDetectorCut(G4double cut); 54 54 void AddPhysicsList(const G4String& name); 55 55 void ConstructProcess(); -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyPhysicsListMessenger.hh
r1230 r1313 58 58 G4UIcmdWithADoubleAndUnit* protoCutCmd; 59 59 G4UIcmdWithADoubleAndUnit* allCutCmd; 60 G4UIcmdWithADoubleAndUnit* allDetectorCmd; 60 61 G4UIcmdWithAString* pListCmd; 61 62 G4UIcmdWithAString* packageListCmd; -
trunk/examples/advanced/hadrontherapy/include/HadrontherapyPrimaryGeneratorAction.hh
r1230 r1313 57 57 void SetsigmaMomentumZ(G4double); 58 58 G4double GetmeanKineticEnergy(void); 59 G4ParticleGun *GetParticleGun(void){return particleGun;} 59 60 60 61 private: … … 71 72 72 73 private: 73 G4ParticleGun* 74 G4ParticleGun* particleGun; 74 75 HadrontherapyPrimaryGeneratorMessenger* gunMessenger; 75 G4double sigmaX;76 G4double sigmaX; 76 77 }; 77 78 -
trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLine.hh
r1230 r1313 116 116 117 117 private: 118 119 void SetD imensions(); //passive proton line dimensions118 //passive proton line dimensions 119 void SetDefaultDimensions(); 120 120 void ConstructPassiveProtonBeamLine(); 121 121 -
trunk/examples/advanced/hadrontherapy/include/PassiveProtonBeamLineMessenger.hh
r1230 r1313 24 24 // ******************************************************************** 25 25 // 26 // HadrontherapyDetectorMessenger.hh;26 // PassiveProtonBeamLineMessenger.hh; 27 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 28 29 #ifndef HadrontherapyDetectorMessenger_h30 #define HadrontherapyDetectorMessenger_h 129 #ifndef PassiveProtonBeamLineMessenger_h 30 #define PassiveProtonBeamLineMessenger_h 1 31 31 32 32 #include "globals.hh" -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyAnalysisManager.cc
r1230 r1313 1 //2 // ********************************************************************3 // * License and Disclaimer *4 // * *5 // * The Geant4 software is copyright of the Copyright Holders of *6 // * the Geant4 Collaboration. It is provided under the terms and *7 // * conditions of the Geant4 Software License, included in the file *8 // * LICENSE and available at http://cern.ch/geant4/license . These *9 // * include a list of copyright holders. *10 // * *11 // * Neither the authors of this software system, nor their employing *12 // * institutes,nor the agencies providing financial support for this *13 // * work make any representation or warranty, express or implied, *14 // * regarding this software system or assume any liability for its *15 // * use. Please see the license in the file LICENSE and URL above *16 // * for the full disclaimer and the limitation of liability. *17 // * *18 // * This code implementation is the result of the scientific and *19 // * technical work of the GEANT4 collaboration. *20 // * By using, copying, modifying or distributing the software (or *21 // * any work based on the software) you agree to acknowledge its *22 // * use in resulting scientific publications, and indicate your *23 // * acceptance of all terms of the Geant4 Software license. *24 // ********************************************************************25 //26 // $Id: HadrontherapyAnalisysManager.cc;27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // $Id: HadrontherapyAnalisysManager.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 28 29 29 #include "HadrontherapyAnalysisManager.hh" … … 31 31 #include "HadrontherapyAnalysisFileMessenger.hh" 32 32 #include <time.h> 33 #ifdef ANALYSIS_USE 33 34 34 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::instance = 0; 35 35 36 #ifdef G4ANALYSIS_USE_ROOT 37 #undef G4ANALYSIS_USE 38 #endif 39 40 ///////////////////////////////////////////////////////////////////////////// 41 42 #ifdef G4ANALYSIS_USE 43 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 44 analysisFileName("DoseDistribution.root"), aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), h2(0), h3(0), 45 h4(0), h5(0), h6(0), h7(0), h8(0), h9(0), h10(0), h11(0), h12(0), h13(0), h14(0), h15(0), h16(0), ntuple(0), 46 ionTuple(0), 47 fragmentTuple(0), 48 eventCounter(0) 49 { 50 fMess = new HadrontherapyAnalysisFileMessenger(this); 51 } 52 #endif 53 #ifdef G4ANALYSIS_USE_ROOT 54 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 55 analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0), 56 histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0), 57 theROOTNtuple(0), 58 theROOTIonTuple(0), 59 fragmentNtuple(0), 60 metaData(0), 61 eventCounter(0) 62 { 63 fMess = new HadrontherapyAnalysisFileMessenger(this); 36 HadrontherapyAnalysisManager::HadrontherapyAnalysisManager(): 37 #ifdef G4ANALYSIS_USE_ROOT 38 analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0), 39 histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0), 40 kinFragNtuple(0), 41 kineticEnergyPrimaryNtuple(0), 42 doseFragNtuple(0), 43 fluenceFragNtuple(0), 44 letFragNtuple(0), 45 theROOTNtuple(0), 46 theROOTIonTuple(0), 47 fragmentNtuple(0), 48 metaData(0), 49 eventCounter(0) 50 { 51 fMess = new HadrontherapyAnalysisFileMessenger(this); 64 52 } 65 53 #endif 66 54 ///////////////////////////////////////////////////////////////////////////// 55 67 56 HadrontherapyAnalysisManager::~HadrontherapyAnalysisManager() 68 57 { 69 delete(fMess); //kill the messenger 70 #ifdef G4ANALYSIS_USE 71 delete fragmentTuple; 72 fragmentTuple = 0; 73 74 delete ionTuple; 75 ionTuple = 0; 76 77 delete ntuple; 78 ntuple = 0; 79 80 delete h16; 81 h16 = 0; 82 83 delete h15; 84 h15 = 0; 85 86 delete h14; 87 h14 = 0; 88 89 delete h13; 90 h13 = 0; 91 92 delete h12; 93 h12 = 0; 94 95 delete h11; 96 h11 = 0; 97 98 delete h10; 99 h10 = 0; 100 101 delete h9; 102 h9 = 0; 103 104 delete h8; 105 h8 = 0; 106 107 delete h7; 108 h7 = 0; 109 110 delete h6; 111 h6 = 0; 112 113 delete h5; 114 h5 = 0; 115 116 delete h4; 117 h4 = 0; 118 119 delete h3; 120 h3 = 0; 121 122 delete h2; 123 h2 = 0; 124 125 delete h1; 126 h1 = 0; 127 128 delete tupFact; 129 tupFact = 0; 130 131 delete histFact; 132 histFact = 0; 133 134 delete theTree; 135 theTree = 0; 136 137 delete aFact; 138 aFact = 0; 58 delete(fMess); 59 #ifdef G4ANALYSIS_USE_ROOT 60 Clear(); 139 61 #endif 62 } 63 64 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::GetInstance() 65 { 66 if (instance == 0) instance = new HadrontherapyAnalysisManager; 67 return instance; 68 } 140 69 #ifdef G4ANALYSIS_USE_ROOT 141 delete metaData; 142 metaData = 0; 143 144 delete fragmentNtuple; 145 fragmentNtuple = 0; 146 147 delete theROOTIonTuple; 148 theROOTIonTuple = 0; 149 150 delete theROOTNtuple; 151 theROOTNtuple = 0; 152 153 delete histo16; 154 histo14 = 0; 155 156 delete histo15; 157 histo14 = 0; 158 159 delete histo14; 160 histo14 = 0; 161 162 delete histo13; 163 histo13 = 0; 164 165 delete histo12; 166 histo12 = 0; 167 168 delete histo11; 169 histo11 = 0; 170 171 delete histo10; 172 histo10 = 0; 173 174 delete histo9; 175 histo9 = 0; 176 177 delete histo8; 178 histo8 = 0; 179 180 delete histo7; 181 histo7 = 0; 182 183 delete histo6; 184 histo6 = 0; 185 186 delete histo5; 187 histo5 = 0; 188 189 delete histo4; 190 histo4 = 0; 191 192 delete histo3; 193 histo3 = 0; 194 195 delete histo2; 196 histo2 = 0; 197 198 delete histo1; 199 histo1 = 0; 70 void HadrontherapyAnalysisManager::Clear() 71 { 72 // XXX delete ALL variables!! 73 // but this seems to be automatically done by 74 // theTFile->Close() command! 75 // so we get a *double free or corruption* 76 77 delete metaData; 78 metaData = 0; 79 80 delete fragmentNtuple; 81 fragmentNtuple = 0; 82 83 delete theROOTIonTuple; 84 theROOTIonTuple = 0; 85 86 delete theROOTNtuple; 87 theROOTNtuple = 0; 88 89 delete histo16; 90 histo16 = 0; 91 92 delete histo15; 93 histo15 = 0; 94 95 delete histo14; 96 histo14 = 0; 97 98 delete histo13; 99 histo13 = 0; 100 101 delete histo12; 102 histo12 = 0; 103 104 delete histo11; 105 histo11 = 0; 106 107 delete histo10; 108 histo10 = 0; 109 110 delete histo9; 111 histo9 = 0; 112 113 delete histo8; 114 histo8 = 0; 115 116 delete histo7; 117 histo7 = 0; 118 119 delete histo6; 120 histo6 = 0; 121 122 delete histo5; 123 histo5 = 0; 124 125 delete histo4; 126 histo4 = 0; 127 128 delete histo3; 129 histo3 = 0; 130 131 delete histo2; 132 histo2 = 0; 133 134 delete histo1; 135 histo1 = 0; 136 } 137 ///////////////////////////////////////////////////////////////////////////// 138 139 void HadrontherapyAnalysisManager::SetAnalysisFileName(G4String aFileName) 140 { 141 this->analysisFileName = aFileName; 142 } 143 144 ///////////////////////////////////////////////////////////////////////////// 145 void HadrontherapyAnalysisManager::book() 146 { 147 delete theTFile; // this is similar to theTFile->Close() => delete all associated variables created via new, moreover it delete itself. 148 149 theTFile = new TFile(analysisFileName, "RECREATE"); 150 151 // Create the histograms with the energy deposit along the X axis 152 histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 80); //<different waterthicknesses are accoutned for in ROOT-analysis stage 153 histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.); 154 histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.); 155 histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.); 156 histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.); 157 histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.); 158 histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.); 159 histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.); 160 histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.); 161 histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.); 162 histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.); 163 histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.); 164 histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.); 165 histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.); 166 histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom", 167 70, 0., 500.); 168 histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom", 169 70, 0., 500.); 170 171 kinFragNtuple = new TNtuple("kinFragNtuple", 172 "Kinetic energy by voxel & fragment", 173 "i:j:k:A:Z:kineticEnergy"); 174 kineticEnergyPrimaryNtuple= new TNtuple("kineticEnergyPrimaryNtuple", 175 "Kinetic energy by voxel of primary", 176 "i:j:k:kineticEnergy"); 177 doseFragNtuple = new TNtuple("doseFragNtuple", 178 "Energy deposit by voxel & fragment", 179 "i:j:k:A:Z:energy"); 180 181 fluenceFragNtuple = new TNtuple("fluenceFragNtuple", 182 "Fluence by voxel & fragment", 183 "i:j:k:A:Z:fluence"); 184 185 letFragNtuple = new TNtuple("letFragNtuple", 186 "Let by voxel & fragment", 187 "i:j:k:A:Z:letT:letD"); 188 189 theROOTNtuple = new TNtuple("theROOTNtuple", 190 "Energy deposit by slice", 191 "i:j:k:energy"); 192 193 theROOTIonTuple = new TNtuple("theROOTIonTuple", 194 "Generic ion information", 195 "a:z:occupancy:energy"); 196 197 fragmentNtuple = new TNtuple("fragmentNtuple", 198 "Fragments", 199 "A:Z:energy:posX:posY:posZ"); 200 201 metaData = new TNtuple("metaData", 202 "Metadata", 203 "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance"); 204 } 205 206 ///////////////////////////////////////////////////////////////////////////// 207 void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i, 208 G4int j, 209 G4int k, 210 G4double energy) 211 { 212 if (theROOTNtuple) { 213 theROOTNtuple->Fill(i, j, k, energy); 214 } 215 } 216 217 ///////////////////////////////////////////////////////////////////////////// 218 void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy) 219 { 220 histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct 221 } 222 223 ///////////////////////////////////////////////////////////////////////////// 224 void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy) 225 { 226 histo2->Fill(slice, energy); 227 } 228 229 ///////////////////////////////////////////////////////////////////////////// 230 void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy) 231 { 232 histo3->Fill(slice, energy); 233 } 234 235 ///////////////////////////////////////////////////////////////////////////// 236 void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy) 237 { 238 histo4->Fill(slice, energy); 239 } 240 241 ///////////////////////////////////////////////////////////////////////////// 242 void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy) 243 { 244 histo5->Fill(slice, energy); 245 } 246 247 ///////////////////////////////////////////////////////////////////////////// 248 void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy) 249 { 250 histo6->Fill(slice, energy); 251 } 252 253 ///////////////////////////////////////////////////////////////////////////// 254 void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy) 255 { 256 histo7->Fill(slice, energy); 257 } 258 259 ///////////////////////////////////////////////////////////////////////////// 260 void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy) 261 { 262 histo8->Fill(slice, energy); 263 } 264 265 ///////////////////////////////////////////////////////////////////////////// 266 void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy) 267 { 268 histo9->Fill(slice, energy); 269 } 270 271 ///////////////////////////////////////////////////////////////////////////// 272 void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy) 273 { 274 histo10->Fill(energy); 275 } 276 277 ///////////////////////////////////////////////////////////////////////////// 278 void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy) 279 { 280 histo11->Fill(energy); 281 } 282 283 ///////////////////////////////////////////////////////////////////////////// 284 void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy) 285 { 286 histo12->Fill(energy); 287 } 288 289 ///////////////////////////////////////////////////////////////////////////// 290 void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy) 291 { 292 histo13->Fill(energy); 293 } 294 295 ///////////////////////////////////////////////////////////////////////////// 296 void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy) 297 { 298 histo14->Fill(energy); 299 } 300 ///////////////////////////////////////////////////////////////////////////// 301 void HadrontherapyAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy) 302 { 303 histo15->Fill(secondaryParticleKineticEnergy); 304 } 305 306 ///////////////////////////////////////////////////////////////////////////// 307 void HadrontherapyAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy) 308 { 309 histo16->Fill(secondaryParticleKineticEnergy); 310 } 311 312 ///////////////////////////////////////////////////////////////////////////// 313 // FillKineticFragmentTuple create an ntuple where the voxel indexs, the atomic number and mass and the kinetic 314 // energy of all the particles interacting with the phantom, are stored 315 void HadrontherapyAnalysisManager::FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy) 316 { 317 kinFragNtuple -> Fill(i, j, k, A, Z, kinEnergy); 318 } 319 320 ///////////////////////////////////////////////////////////////////////////// 321 // FillKineticEnergyPrimaryNTuple creates a ntuple where the voxel indexs and the kinetic 322 // energies of ONLY primary particles interacting with the phantom, are stored 323 void HadrontherapyAnalysisManager::FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy) 324 { 325 kineticEnergyPrimaryNtuple -> Fill(i, j, k, kinEnergy); 326 } 327 328 ///////////////////////////////////////////////////////////////////////////// 329 // This function is called only if ROOT is activated. 330 // It is called by the HadrontherapyMatric.cc class file and it is used to create two ntuples containing 331 // the total energy deposited and the fluence values, in each voxel and per any particle (primary beam 332 // and secondaries ) 333 void HadrontherapyAnalysisManager::FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence) 334 { 335 // Fill the ntuple containing the voxel, mass and atomic number and the energy deposited 336 doseFragNtuple -> Fill( i, j, k, A, Z, energy ); 337 338 // Fill the ntuple containing the voxel, mass and atomic number and the fluence 339 if (i==1 && Z==1) { 340 fluenceFragNtuple -> Fill( i, j, k, A, Z, fluence ); 341 342 } 343 } 344 345 void HadrontherapyAnalysisManager::FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD) 346 { 347 letFragNtuple -> Fill( i, j, k, A, Z, letT, letD); 348 349 } 350 ///////////////////////////////////////////////////////////////////////////// 351 void HadrontherapyAnalysisManager::FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ) 352 { 353 fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ); 354 } 355 356 ///////////////////////////////////////////////////////////////////////////// 357 void HadrontherapyAnalysisManager::genericIonInformation(G4int a, 358 G4double z, 359 G4int electronOccupancy, 360 G4double energy) 361 { 362 if (theROOTIonTuple) { 363 theROOTIonTuple->Fill(a, z, electronOccupancy, energy); 364 } 365 } 366 367 ///////////////////////////////////////////////////////////////////////////// 368 void HadrontherapyAnalysisManager::startNewEvent() 369 { 370 eventCounter++; 371 } 372 ///////////////////////////////////////////////////////////////////////////// 373 void HadrontherapyAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter) 374 { 375 this->detectorDistance = endDetectorPosition; 376 this->phantomDepth = waterThickness; 377 this->phantomCenterDistance = phantomCenter; 378 } 379 void HadrontherapyAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy) 380 { 381 this->beamEnergy = meanKineticEnergy; 382 this->energyError = sigmaEnergy; 383 } 384 ///////////////////////////////////////////////////////////////////////////// 385 // Flush data & close the file 386 void HadrontherapyAnalysisManager::flush() 387 { 388 if (theTFile) 389 { 390 theTFile -> Write(); 391 theTFile -> Close(); 392 } 393 eventCounter = 0; 394 } 395 200 396 #endif 201 }202 /////////////////////////////////////////////////////////////////////////////203 HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::getInstance()204 {205 if (instance == 0) instance = new HadrontherapyAnalysisManager;206 return instance;207 }208 209 /////////////////////////////////////////////////////////////////////////////210 void HadrontherapyAnalysisManager::SetAnalysisFileName(G4String aFileName)211 {212 this->analysisFileName = aFileName;213 }214 215 /////////////////////////////////////////////////////////////////////////////216 void HadrontherapyAnalysisManager::book()217 {218 #ifdef G4ANALYSIS_USE219 // Build up the analysis factory220 aFact = AIDA_createAnalysisFactory();221 AIDA::ITreeFactory* treeFact = aFact -> createTreeFactory();222 223 // Create the .hbk or the .root file224 G4String fileName = "DoseDistribution.hbk";225 226 std::string opts = "export=root";227 228 theTree = treeFact -> create(fileName,"hbook",false,true);229 theTree = treeFact -> create(analysisFileName,"ROOT",false,true,opts);230 231 // Factories are not "managed" by an AIDA analysis system.232 // They must be deleted by the AIDA user code.233 delete treeFact;234 235 // Create the histogram and the ntuple factory236 histFact = aFact -> createHistogramFactory(*theTree);237 tupFact = aFact -> createTupleFactory(*theTree);238 239 // Create the histograms with the enrgy deposit along the X axis240 h1 = histFact -> createHistogram1D("10","slice, energy", 400, 0., 400. );241 242 h2 = histFact -> createHistogram1D("20","Secondary protons - slice, energy", 400, 0., 400. );243 244 h3 = histFact -> createHistogram1D("30","Secondary neutrons - slice, energy", 400, 0., 400. );245 246 h4 = histFact -> createHistogram1D("40","Secondary alpha - slice, energy", 400, 0., 400. );247 248 h5 = histFact -> createHistogram1D("50","Secondary gamma - slice, energy", 400, 0., 400. );249 250 h6 = histFact -> createHistogram1D("60","Secondary electron - slice, energy", 400, 0., 400. );251 252 h7 = histFact -> createHistogram1D("70","Secondary triton - slice, energy", 400, 0., 400. );253 254 h8 = histFact -> createHistogram1D("80","Secondary deuteron - slice, energy", 400, 0., 400. );255 256 h9 = histFact -> createHistogram1D("90","Secondary pion - slice, energy", 400, 0., 400. );257 258 h10 = histFact -> createHistogram1D("100","Energy distribution of secondary electrons", 70, 0., 70. );259 260 h11 = histFact -> createHistogram1D("110","Energy distribution of secondary photons", 70, 0., 70. );261 262 h12 = histFact -> createHistogram1D("120","Energy distribution of secondary deuterons", 70, 0., 70. );263 264 h13 = histFact -> createHistogram1D("130","Energy distribution of secondary tritons", 70, 0., 70. );265 266 h14 = histFact -> createHistogram1D("140","Energy distribution of secondary alpha particles", 70, 0., 70. );267 268 h15 = histFact -> createHistogram1D("150","Energy distribution of helium fragments after the phantom", 70, 0., 500.);269 270 h16 = histFact -> createHistogram1D("160","Energy distribution of hydrogen fragments after the phantom", 70, 0., 500.);271 272 // Create the ntuple273 G4String columnNames = "int i; int j; int k; double energy;";274 G4String options = "";275 if (tupFact) ntuple = tupFact -> create("1","1",columnNames, options);276 277 // Create the ntuple278 G4String columnNames2 = "int a; double z; int occupancy; double energy;";279 G4String options2 = "";280 if (tupFact) ionTuple = tupFact -> create("2","2", columnNames2, options2);281 282 // Create the fragment ntuple283 G4String columnNames3 = "int a; double z; double energy; double posX; double posY; double posZ;";284 G4String options3 = "";285 if (tupFact) fragmentTuple = tupFact -> create("3","3", columnNames3, options3);286 #endif287 #ifdef G4ANALYSIS_USE_ROOT288 // Use ROOT289 theTFile = new TFile(analysisFileName, "RECREATE");290 291 // Create the histograms with the energy deposit along the X axis292 histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 27.9); //<different waterthicknesses are accoutned for in ROOT-analysis stage293 histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.);294 histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.);295 histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.);296 histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.);297 histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.);298 histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.);299 histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.);300 histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.);301 histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.);302 histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.);303 histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.);304 histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.);305 histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);306 histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",307 70, 0., 500.);308 histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",309 70, 0., 500.);310 311 theROOTNtuple = new TNtuple("theROOTNtuple", "Energy deposit by slice", "i:j:k:energy");312 theROOTIonTuple = new TNtuple("theROOTIonTuple", "Generic ion information", "a:z:occupancy:energy");313 fragmentNtuple = new TNtuple("fragmentNtuple", "Fragments", "A:Z:energy:posX:posY:posZ");314 metaData = new TNtuple("metaData", "Metadata", "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance");315 #endif316 }317 318 /////////////////////////////////////////////////////////////////////////////319 void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i,320 G4int j,321 G4int k,322 G4double energy)323 {324 #ifdef G4ANALYSIS_USE325 if (ntuple) {326 G4int iSlice = ntuple -> findColumn("i");327 G4int jSlice = ntuple -> findColumn("j");328 G4int kSlice = ntuple -> findColumn("k");329 G4int iEnergy = ntuple -> findColumn("energy");330 331 ntuple -> fill(iSlice,i);332 ntuple -> fill(jSlice,j);333 ntuple -> fill(kSlice,k);334 ntuple -> fill(iEnergy, energy); }335 336 ntuple -> addRow();337 #endif338 #ifdef G4ANALYSIS_USE_ROOT339 if (theROOTNtuple) {340 theROOTNtuple->Fill(i, j, k, energy);341 }342 #endif343 }344 345 /////////////////////////////////////////////////////////////////////////////346 void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy)347 {348 #ifdef G4ANALYSIS_USE349 h1 -> fill(slice,energy);350 #endif351 #ifdef G4ANALYSIS_USE_ROOT352 histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct353 #endif354 }355 356 /////////////////////////////////////////////////////////////////////////////357 void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)358 {359 #ifdef G4ANALYSIS_USE360 h2 -> fill(slice,energy);361 #endif362 #ifdef G4ANALYSIS_USE_ROOT363 histo2->Fill(slice, energy);364 #endif365 }366 367 /////////////////////////////////////////////////////////////////////////////368 void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)369 {370 #ifdef G4ANALYSIS_USE371 h3 -> fill(slice,energy);372 #endif373 #ifdef G4ANALYSIS_USE_ROOT374 histo3->Fill(slice, energy);375 #endif376 }377 378 /////////////////////////////////////////////////////////////////////////////379 void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)380 {381 #ifdef G4ANALYSIS_USE382 h4 -> fill(slice,energy);383 #endif384 #ifdef G4ANALYSIS_USE_ROOT385 histo4->Fill(slice, energy);386 #endif387 }388 389 /////////////////////////////////////////////////////////////////////////////390 void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)391 {392 #ifdef G4ANALYSIS_USE393 h5 -> fill(slice,energy);394 #endif395 #ifdef G4ANALYSIS_USE_ROOT396 histo5->Fill(slice, energy);397 #endif398 }399 400 /////////////////////////////////////////////////////////////////////////////401 void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)402 {403 #ifdef G4ANALYSIS_USE404 h6 -> fill(slice,energy);405 #endif406 #ifdef G4ANALYSIS_USE_ROOT407 histo6->Fill(slice, energy);408 #endif409 }410 411 /////////////////////////////////////////////////////////////////////////////412 void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)413 {414 #ifdef G4ANALYSIS_USE415 h7 -> fill(slice,energy);416 #endif417 #ifdef G4ANALYSIS_USE_ROOT418 histo7->Fill(slice, energy);419 #endif420 }421 422 /////////////////////////////////////////////////////////////////////////////423 void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)424 {425 #ifdef G4ANALYSIS_USE426 h8 -> fill(slice,energy);427 #endif428 #ifdef G4ANALYSIS_USE_ROOT429 histo8->Fill(slice, energy);430 #endif431 }432 433 /////////////////////////////////////////////////////////////////////////////434 void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)435 {436 #ifdef G4ANALYSIS_USE437 h9 -> fill(slice,energy);438 #endif439 #ifdef G4ANALYSIS_USE_ROOT440 histo9->Fill(slice, energy);441 #endif442 }443 444 /////////////////////////////////////////////////////////////////////////////445 void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy)446 {447 #ifdef G4ANALYSIS_USE448 h10 -> fill(energy);449 #endif450 #ifdef G4ANALYSIS_USE_ROOT451 histo10->Fill(energy);452 #endif453 }454 455 /////////////////////////////////////////////////////////////////////////////456 void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy)457 {458 #ifdef G4ANALYSIS_USE459 h11 -> fill(energy);460 #endif461 #ifdef G4ANALYSIS_USE_ROOT462 histo11->Fill(energy);463 #endif464 }465 466 /////////////////////////////////////////////////////////////////////////////467 void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy)468 {469 #ifdef G4ANALYSIS_USE470 h12 -> fill(energy);471 #endif472 #ifdef G4ANALYSIS_USE_ROOT473 histo12->Fill(energy);474 #endif475 }476 477 /////////////////////////////////////////////////////////////////////////////478 void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy)479 {480 #ifdef G4ANALYSIS_USE481 h13 -> fill(energy);482 #endif483 #ifdef G4ANALYSIS_USE_ROOT484 histo13->Fill(energy);485 #endif486 }487 488 /////////////////////////////////////////////////////////////////////////////489 void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy)490 {491 #ifdef G4ANALYSIS_USE492 h14 -> fill(energy);493 #endif494 #ifdef G4ANALYSIS_USE_ROOT495 histo14->Fill(energy);496 #endif497 }498 /////////////////////////////////////////////////////////////////////////////499 void HadrontherapyAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)500 {501 #ifdef G4ANALYSIS_USE502 h15->fill(secondaryParticleKineticEnergy);503 #endif504 #ifdef G4ANALYSIS_USE_ROOT505 histo15->Fill(secondaryParticleKineticEnergy);506 #endif507 }508 509 /////////////////////////////////////////////////////////////////////////////510 void HadrontherapyAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)511 {512 #ifdef G4ANALYSIS_USE513 h16->fill(secondaryParticleKineticEnergy);514 #endif515 #ifdef G4ANALYSIS_USE_ROOT516 histo16->Fill(secondaryParticleKineticEnergy);517 #endif518 }519 520 521 522 void HadrontherapyAnalysisManager::fillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)523 {524 #ifdef G4ANALYSIS_USE525 if (fragmentTuple) {526 G4int aIndex = fragmentTuple -> findColumn("a");527 G4int zIndex = fragmentTuple -> findColumn("z");528 G4int energyIndex = fragmentTuple -> findColumn("energy");529 G4int posXIndex = fragmentTuple -> findColumn("posX");530 G4int posYIndex = fragmentTuple -> findColumn("posY");531 G4int posZIndex = fragmentTuple -> findColumn("posZ");532 533 fragmentTuple -> fill(aIndex,A);534 fragmentTuple -> fill(zIndex,Z);535 fragmentTuple -> fill(energyIndex, energy);536 fragmentTuple -> fill(posXIndex, posX);537 fragmentTuple -> fill(posYIndex, posY);538 fragmentTuple -> fill(posZIndex, posZ);539 fragmentTuple -> addRow();540 }541 #endif542 #ifdef G4ANALYSIS_USE_ROOT543 //G4cout <<" A = " << A << " Z = " << Z << " energy = " << energy << G4endl;544 fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ);545 #endif546 }547 548 /////////////////////////////////////////////////////////////////////////////549 void HadrontherapyAnalysisManager::genericIonInformation(G4int a,550 G4double z,551 G4int electronOccupancy,552 G4double energy)553 {554 #ifdef G4ANALYSIS_USE555 if (ionTuple) {556 G4int aIndex = ionTuple -> findColumn("a");557 G4int zIndex = ionTuple -> findColumn("z");558 G4int electronIndex = ionTuple -> findColumn("occupancy");559 G4int energyIndex = ionTuple -> findColumn("energy");560 561 ionTuple -> fill(aIndex,a);562 ionTuple -> fill(zIndex,z);563 ionTuple -> fill(electronIndex, electronOccupancy);564 ionTuple -> fill(energyIndex, energy);565 }566 ionTuple -> addRow();567 #endif568 #ifdef G4ANALYSIS_USE_ROOT569 if (theROOTIonTuple) {570 theROOTIonTuple->Fill(a, z, electronOccupancy, energy);571 }572 #endif573 }574 575 /////////////////////////////////////////////////////////////////////////////576 void HadrontherapyAnalysisManager::startNewEvent()577 {578 eventCounter++;579 }580 /////////////////////////////////////////////////////////////////////////////581 void HadrontherapyAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter)582 {583 this->detectorDistance = endDetectorPosition;584 this->phantomDepth = waterThickness;585 this->phantomCenterDistance = phantomCenter;586 }587 void HadrontherapyAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)588 {589 this->beamEnergy = meanKineticEnergy;590 this->energyError = sigmaEnergy;591 }592 /////////////////////////////////////////////////////////////////////////////593 void HadrontherapyAnalysisManager::flush()594 {595 HadrontherapyMatrix* matrix = HadrontherapyMatrix::getInstance();596 597 matrix->TotalEnergyDeposit();598 #ifdef G4ANALYSIS_USE599 theTree -> commit();600 theTree ->close();601 #endif602 #ifdef G4ANALYSIS_USE_ROOT603 metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance);604 metaData->Write();605 theROOTNtuple->Write();606 theROOTIonTuple->Write();607 fragmentNtuple->Write();608 theTFile->Write();609 // theTFile->Clear();610 theTFile->Close();611 #endif612 eventCounter = 0;613 matrix->flush();614 }615 /////////////////////////////////////////////////////////////////////////////616 void HadrontherapyAnalysisManager::finish()617 {618 #ifdef G4ANALYSIS_USE619 // Write all histograms to file620 theTree -> commit();621 // Close (will again commit)622 theTree ->close();623 #endif624 #ifdef G4ANALYSIS_USE_ROOT625 metaData->Fill((Float_t) eventCounter,(Float_t) detectorDistance, (Float_t) phantomDepth, (Float_t) beamEnergy,(Float_t) energyError, (Float_t) phantomCenterDistance);626 metaData->Write();627 theROOTNtuple->Write();628 theROOTIonTuple->Write();629 fragmentNtuple->Write();630 theTFile->Write();631 theTFile->Close();632 #endif633 eventCounter = 0;634 }635 636 #endif637 638 639 640 641 642 643 644 645 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc
r1230 r1313 28 28 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 29 29 30 30 31 #include "G4SDManager.hh" 31 32 #include "G4RunManager.hh" 33 #include "G4GeometryManager.hh" 34 #include "G4SolidStore.hh" 35 #include "G4PhysicalVolumeStore.hh" 36 #include "G4LogicalVolumeStore.hh" 32 37 #include "G4Box.hh" 33 38 #include "G4LogicalVolume.hh" … … 42 47 #include "G4VisAttributes.hh" 43 48 #include "G4NistManager.hh" 49 50 #include "HadrontherapyDetectorConstruction.hh" 44 51 #include "HadrontherapyDetectorROGeometry.hh" 45 52 #include "HadrontherapyDetectorMessenger.hh" 46 53 #include "HadrontherapyDetectorSD.hh" 47 #include "HadrontherapyDetectorConstruction.hh"48 54 #include "HadrontherapyMatrix.hh" 55 #include "HadrontherapyAnalysisManager.hh" 56 57 #include <cmath> 49 58 50 59 ///////////////////////////////////////////////////////////////////////////// 51 60 HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction(G4VPhysicalVolume* physicalTreatmentRoom) 52 : motherPhys(physicalTreatmentRoom), 61 : motherPhys(physicalTreatmentRoom), // pointer to WORLD volume 53 62 detectorSD(0), detectorROGeometry(0), matrix(0), 54 phantom PhysicalVolume(0),55 detectorLogicalVolume(0), detectorPhysicalVolume(0),56 phantom SizeX(20.*cm), phantomSizeY(20.*cm), phantomSizeZ(20.*cm), // Default half dimensions57 detectorSizeX(2.*cm), detectorSizeY(2.*cm), detectorSizeZ(2.*cm),58 phantomPosition(20.*cm, 0.*cm, 0.*cm), 59 detectorToPhantomPosition(0.*cm,18.*cm,18.*cm)// Default displacement of the detector respect to the phantom60 { 63 phantom(0), detector(0), 64 phantomLogicalVolume(0), detectorLogicalVolume(0), 65 phantomPhysicalVolume(0), detectorPhysicalVolume(0), 66 aRegion(0) 67 { 68 HadrontherapyAnalysisManager::GetInstance(); 69 61 70 // NOTE! that the HadrontherapyDetectorConstruction class 62 71 // does NOT inherit from G4VUserDetectorConstruction G4 class … … 69 78 // Default detector voxels size 70 79 // 200 slabs along the beam direction (X) 71 sizeOfVoxelAlongX = 200 *um; 72 sizeOfVoxelAlongY = 2 * detectorSizeY; 73 sizeOfVoxelAlongZ = 2 * detectorSizeZ; 74 75 // Calculate (and eventually set) detector position by displacement, phantom size and detector size 76 SetDetectorPosition(); 77 78 // Build phantom and associated detector 79 ConstructPhantom(); 80 ConstructDetector(); 81 // Set number of the detector voxels along X Y and Z directions. 82 // This will construct also the sensitive detector, the ROGeometry 83 // and the matrix where the energy deposited is collected! 84 SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ); 80 sizeOfVoxelAlongX = 200 *um; 81 sizeOfVoxelAlongY = 4 *cm; 82 sizeOfVoxelAlongZ = 4 *cm; 83 84 // Define here the material of the water phantom and of the detector 85 SetPhantomMaterial("G4_WATER"); 86 // Construct geometry (messenger commands) 87 SetDetectorSize(4.*cm, 4.*cm, 4.*cm); 88 SetPhantomSize(40. *cm, 40. *cm, 40. *cm); 89 SetPhantomPosition(G4ThreeVector(20. *cm, 0. *cm, 0. *cm)); 90 SetDetectorToPhantomPosition(G4ThreeVector(0. *cm, 18. *cm, 18. *cm)); 91 92 93 // Write virtual parameters to the real ones and check for consistency 94 UpdateGeometry(); 85 95 } 86 96 … … 88 98 HadrontherapyDetectorConstruction::~HadrontherapyDetectorConstruction() 89 99 { 90 delete detectorROGeometry; // This should be safe in C++ even if the argument is a NULL pointer100 delete detectorROGeometry; 91 101 delete matrix; 92 102 delete detectorMessenger; 93 103 } 94 104 105 ///////////////////////////////////////////////////////////////////////////// 106 // ConstructPhantom() is the method that reconstuct a water box (called phantom 107 // (or water phantom) in the usual Medical physicists slang). 108 // A water phantom can be considered a good 109 // approximation of a an human body. 95 110 void HadrontherapyDetectorConstruction::ConstructPhantom() 96 111 { 97 //---------------------------------------- 98 // Phantom: 99 // A box used to approximate tissues 100 //---------------------------------------- 101 102 G4bool isotopes = false; 103 G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes); 104 phantom = new G4Box("Phantom",phantomSizeX, phantomSizeY, phantomSizeZ); 112 // Definition of the solid volume of the Phantom 113 phantom = new G4Box("Phantom", 114 phantomSizeX/2, 115 phantomSizeY/2, 116 phantomSizeZ/2); 117 118 // Definition of the logical volume of the Phantom 105 119 phantomLogicalVolume = new G4LogicalVolume(phantom, 106 waterNist,120 phantomMaterial, 107 121 "phantomLog", 0, 0, 0); 108 122 123 // Definition of the physics volume of the Phantom 109 124 phantomPhysicalVolume = new G4PVPlacement(0, 110 125 phantomPosition, … … 119 134 red -> SetVisibility(true); 120 135 red -> SetForceSolid(true); 121 //red -> SetForceWireframe(true);136 //red -> SetForceWireframe(true); 122 137 phantomLogicalVolume -> SetVisAttributes(red); 123 138 } 124 139 125 140 ///////////////////////////////////////////////////////////////////////////// 141 // ConstructDetector() it the method the reconstruct a detector region 142 // inside the water phantom. It is a volume, located inside the water phantom 143 // and with two coincident faces: 144 // 145 // ************************** 146 // * water phantom * 147 // * * 148 // * * 149 // *--------------- * 150 // Beam * - * 151 // -----> * detector - * 152 // * - * 153 // *--------------- * 154 // * * 155 // * * 156 // * * 157 // ************************** 158 // 159 // The detector is the volume that can be dived in slices or voxelized 160 // and in it we can collect a number of usefull information: 161 // dose distribution, fluence distribution, LET and so on 126 162 void HadrontherapyDetectorConstruction::ConstructDetector() 127 163 { 128 //----------- 129 // Detector 130 //----------- 131 G4bool isotopes = false; 132 G4Material* waterNist = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER", isotopes); 133 detector = new G4Box("Detector",detectorSizeX,detectorSizeY,detectorSizeZ); 164 165 // Definition of the solid volume of the Detector 166 detector = new G4Box("Detector", 167 detectorSizeX/2, 168 detectorSizeY/2, 169 detectorSizeZ/2); 170 171 // Definition of the logic volume of the Phantom 134 172 detectorLogicalVolume = new G4LogicalVolume(detector, 135 waterNist,173 detectorMaterial, 136 174 "DetectorLog", 137 175 0,0,0); 138 // De tector is attached by default to the phantom face directly exposed to the beam139 detectorPhysicalVolume = new G4PVPlacement(0, 140 detectorPosition, // Setted by displacement141 "DetectorPhys",142 detectorLogicalVolume,143 phantomPhysicalVolume,144 false,0);145 176 // Definition of the physical volume of the Phantom 177 detectorPhysicalVolume = new G4PVPlacement(0, 178 detectorPosition, // Setted by displacement 179 "DetectorPhys", 180 detectorLogicalVolume, 181 phantomPhysicalVolume, 182 false,0); 183 146 184 // Visualisation attributes of the detector 147 185 skyBlue = new G4VisAttributes( G4Colour(135/255. , 206/255. , 235/255. )); 148 186 skyBlue -> SetVisibility(true); 149 187 skyBlue -> SetForceSolid(true); 150 //skyBlue -> SetForceWireframe(true);188 //skyBlue -> SetForceWireframe(true); 151 189 detectorLogicalVolume -> SetVisAttributes(skyBlue); 190 191 // ************** 192 // Cut per Region 193 // ************** 152 194 153 } 154 ///////////////////////////////////////////////////////////////////////////// 195 // A smaller cut is fixed in the phantom to calculate the energy deposit with the 196 // required accuracy 197 if (!aRegion) 198 { 199 aRegion = new G4Region("DetectorLog"); 200 detectorLogicalVolume -> SetRegion(aRegion); 201 aRegion -> AddRootLogicalVolume(detectorLogicalVolume); 202 } 203 204 } 205 206 ///////////////////////////////////////////////////////////////////////////// 207 155 208 void HadrontherapyDetectorConstruction::ConstructSensitiveDetector(G4ThreeVector detectorToWorldPosition) 156 209 { 157 210 // Install new Sensitive Detector and ROGeometry 158 211 delete detectorROGeometry; // this should be safe in C++ also if we have a NULL pointer 159 212 //if (detectorSD) detectorSD->PrintAll(); 213 //delete detectorSD; 160 214 // Sensitive Detector and ReadOut geometry definition 161 215 G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer(); 162 216 163 G4String sensitiveDetectorName = "Detector";217 static G4String sensitiveDetectorName = "Detector"; 164 218 if (!detectorSD) 165 219 { … … 168 222 } 169 223 // The Read Out Geometry is instantiated 170 G4String ROGeometryName = "DetectorROGeometry";224 static G4String ROGeometryName = "DetectorROGeometry"; 171 225 detectorROGeometry = new HadrontherapyDetectorROGeometry(ROGeometryName, 172 226 detectorToWorldPosition, 173 detectorSizeX ,174 detectorSizeY ,175 detectorSizeZ ,227 detectorSizeX/2, 228 detectorSizeY/2, 229 detectorSizeZ/2, 176 230 numberOfVoxelsAlongX, 177 231 numberOfVoxelsAlongY, … … 193 247 } 194 248 } 195 249 void HadrontherapyDetectorConstruction::ParametersCheck() 250 { 251 // Check phantom/detector sizes & relative position 252 if (!IsInside(detectorSizeX, 253 detectorSizeY, 254 detectorSizeZ, 255 phantomSizeX, 256 phantomSizeY, 257 phantomSizeZ, 258 detectorToPhantomPosition 259 )) 260 G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector is not fully inside Phantom!"); 261 262 // Check Detector sizes respect to the voxel ones 263 264 if ( detectorSizeX < sizeOfVoxelAlongX) { 265 G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector X size must be bigger or equal than that of Voxel X"); 266 } 267 if ( detectorSizeY < sizeOfVoxelAlongY) { 268 G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector Y size must be bigger or equal than that of Voxel Y"); 269 } 270 if ( detectorSizeZ < sizeOfVoxelAlongZ) { 271 G4Exception("Error at HadrontherapyDetectorConstruction::ParametersCheck(). Detector Z size must be bigger or equal than that of Voxel Z"); 272 } 273 274 } 196 275 ///////////////// 197 276 // MESSENGERS // 198 277 //////////////// 199 G4bool HadrontherapyDetectorConstruction::SetNumberOfVoxelBySize(G4double sizeX, G4double sizeY, G4double sizeZ) 200 { 201 // Only change positive dimensions 202 // XXX numberOfVoxels must be an integer, warn the user 203 204 if (sizeX > 0) 278 279 G4bool HadrontherapyDetectorConstruction::SetPhantomMaterial(G4String material) 280 { 281 282 if (G4Material* pMat = G4NistManager::Instance()->FindOrBuildMaterial(material, false) ) 205 283 { 206 if (sizeX > 2*detectorSizeX) 284 phantomMaterial = pMat; 285 detectorMaterial = pMat; 286 if (detectorLogicalVolume && phantomLogicalVolume) 207 287 { 208 G4cout << "WARNING: Voxel X size must be smaller or equal than that of detector X" << G4endl; 209 return false; 288 detectorLogicalVolume -> SetMaterial(pMat); 289 phantomLogicalVolume -> SetMaterial(pMat); 290 291 G4RunManager::GetRunManager() -> PhysicsHasBeenModified(); 292 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 293 G4cout << "The material of Phantom/Detector has been changed to " << material << G4endl; 210 294 } 211 // Round to the nearest integer 212 numberOfVoxelsAlongX = lrint(2 * detectorSizeX / sizeX); 213 sizeOfVoxelAlongX = (2 * detectorSizeX / numberOfVoxelsAlongX ); 214 if(sizeOfVoxelAlongX!=sizeX) G4cout << "Rounding " << 215 G4BestUnit(sizeX, "Length") << " to " << 216 G4BestUnit(sizeOfVoxelAlongX, "Length") << G4endl; 217 } 218 219 if (sizeY > 0) 295 } 296 else 220 297 { 221 if (sizeY > 2*detectorSizeY) 222 { 223 G4cout << "WARNING: Voxel Y size must be smaller or equal than that of detector Y" << G4endl; 224 return false; 225 } 226 numberOfVoxelsAlongY = lrint(2 * detectorSizeY / sizeY); 227 sizeOfVoxelAlongY = (2 * detectorSizeY / numberOfVoxelsAlongY ); 228 if(sizeOfVoxelAlongY!=sizeY) G4cout << "Rounding " << 229 G4BestUnit(sizeY, "Length") << " to " << 230 G4BestUnit(sizeOfVoxelAlongY, "Length") << G4endl; 231 } 232 if (sizeZ > 0) 298 G4cout << "WARNING: material \"" << material << "\" doesn't exist in NIST elements/materials" 299 " table [located in $G4INSTALL/source/materials/src/G4NistMaterialBuilder.cc]" << G4endl; 300 G4cout << "Use command \"/parameter/nist\" to see full materials list!" << G4endl; 301 return false; 302 } 303 304 return true; 305 } 306 ///////////////////////////////////////////////////////////////////////////// 307 void HadrontherapyDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ) 308 { 309 if (sizeX > 0.) phantomSizeX = sizeX; 310 if (sizeY > 0.) phantomSizeY = sizeY; 311 if (sizeZ > 0.) phantomSizeZ = sizeZ; 312 } 313 ///////////////////////////////////////////////////////////////////////////// 314 ///////////////////////////////////////////////////////////////////////////// 315 void HadrontherapyDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ) 316 { 317 if (sizeX > 0.) {detectorSizeX = sizeX;} 318 if (sizeY > 0.) {detectorSizeY = sizeY;} 319 if (sizeZ > 0.) {detectorSizeZ = sizeZ;} 320 SetVoxelSize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ); 321 } 322 ///////////////////////////////////////////////////////////////////////////// 323 324 void HadrontherapyDetectorConstruction::SetVoxelSize(G4double sizeX, G4double sizeY, G4double sizeZ) 325 { 326 if (sizeX > 0.) {sizeOfVoxelAlongX = sizeX;} 327 if (sizeY > 0.) {sizeOfVoxelAlongY = sizeY;} 328 if (sizeZ > 0.) {sizeOfVoxelAlongZ = sizeZ;} 329 } 330 void HadrontherapyDetectorConstruction::SetPhantomPosition(G4ThreeVector pos) 331 { 332 phantomPosition = pos; 333 } 334 335 ///////////////////////////////////////////////////////////////////////////// 336 void HadrontherapyDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displ) 337 { 338 detectorToPhantomPosition = displ; 339 } 340 ///////////////////////////////////////////////////////////////////////////// 341 void HadrontherapyDetectorConstruction::UpdateGeometry() 342 { 343 ParametersCheck(); 344 345 //G4RunManager::GetRunManager() -> PhysicsHasBeenModified(); 346 G4GeometryManager::GetInstance() -> OpenGeometry(); 347 if (phantom) 233 348 { 234 if (sizeZ > 2*detectorSizeZ) 235 { 236 G4cout << "WARNING: Voxel Z size must be smaller or equal than that of detector Z" << G4endl; 237 return false; 238 } 239 numberOfVoxelsAlongZ = lrint(2 * detectorSizeZ / sizeZ); 240 sizeOfVoxelAlongZ = (2 * detectorSizeZ / numberOfVoxelsAlongZ ); 241 if(sizeOfVoxelAlongZ!=sizeZ) G4cout << "Rounding " << 242 G4BestUnit(sizeZ, "Length") << " to " << 243 G4BestUnit(sizeOfVoxelAlongZ, "Length") << G4endl; 244 } 245 246 G4cout << "The (X, Y, Z) sizes of the Voxels are: (" << 247 G4BestUnit(sizeOfVoxelAlongX, "Length") << ", " << 248 G4BestUnit(sizeOfVoxelAlongY, "Length") << ", " << 249 G4BestUnit(sizeOfVoxelAlongZ, "Length") << ')' << G4endl; 349 phantom -> SetXHalfLength(phantomSizeX/2); 350 phantom -> SetYHalfLength(phantomSizeY/2); 351 phantom -> SetZHalfLength(phantomSizeZ/2); 352 phantomPhysicalVolume -> SetTranslation(phantomPosition); 353 } 354 else ConstructPhantom(); 355 356 // Get the center of the detector 357 SetDetectorPosition(); 358 if (detector) 359 { 360 detector -> SetXHalfLength(detectorSizeX/2); 361 detector -> SetYHalfLength(detectorSizeY/2); 362 detector -> SetZHalfLength(detectorSizeZ/2); 363 detectorPhysicalVolume -> SetTranslation(detectorPosition); 364 } 365 else ConstructDetector(); 366 367 // Round to nearest integer number of voxel 368 numberOfVoxelsAlongX = lrint(detectorSizeX / sizeOfVoxelAlongX); 369 sizeOfVoxelAlongX = ( detectorSizeX / numberOfVoxelsAlongX ); 370 371 numberOfVoxelsAlongY = lrint(detectorSizeY / sizeOfVoxelAlongY); 372 sizeOfVoxelAlongY = ( detectorSizeY / numberOfVoxelsAlongY ); 373 374 numberOfVoxelsAlongZ = lrint(detectorSizeZ / sizeOfVoxelAlongZ); 375 sizeOfVoxelAlongZ = ( detectorSizeZ / numberOfVoxelsAlongZ ); 376 377 //G4cout << "*************** DetectorToWorldPosition " << GetDetectorToWorldPosition()/cm << "\n"; 378 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 379 380 volumeOfVoxel = sizeOfVoxelAlongX * sizeOfVoxelAlongY * sizeOfVoxelAlongZ; 381 massOfVoxel = detectorMaterial -> GetDensity() * volumeOfVoxel; 382 // This will clear the existing matrix (together with all data inside it)! 383 matrix = HadrontherapyMatrix::GetInstance(numberOfVoxelsAlongX, 384 numberOfVoxelsAlongY, 385 numberOfVoxelsAlongZ, 386 massOfVoxel); 387 388 // Inform the kernel about the new geometry 389 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 390 G4RunManager::GetRunManager() -> PhysicsHasBeenModified(); 391 392 PrintParameters(); 393 } 394 395 void HadrontherapyDetectorConstruction::PrintParameters() 396 { 397 398 G4cout << "The (X,Y,Z) dimensions of the phantom are : (" << 399 G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ',' << 400 G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ',' << 401 G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl; 402 403 G4cout << "The (X,Y,Z) dimensions of the detector are : (" << 404 G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ',' << 405 G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ',' << 406 G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl; 407 408 G4cout << "Displacement between Phantom and World is: "; 409 G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") << 410 "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") << 411 "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl; 412 413 G4cout << "The (X,Y,Z) sizes of the Voxels are: (" << 414 G4BestUnit(sizeOfVoxelAlongX, "Length") << ',' << 415 G4BestUnit(sizeOfVoxelAlongY, "Length") << ',' << 416 G4BestUnit(sizeOfVoxelAlongZ, "Length") << ')' << G4endl; 250 417 251 418 G4cout << "The number of Voxels along (X,Y,Z) is: (" << 252 numberOfVoxelsAlongX << ", " << 253 numberOfVoxelsAlongY << ", " << 254 numberOfVoxelsAlongZ << ')' << G4endl; 255 256 // This will clear the existing matrix (together with data inside it)! 257 matrix = HadrontherapyMatrix::getInstance(numberOfVoxelsAlongX, 258 numberOfVoxelsAlongY, 259 numberOfVoxelsAlongZ); 260 261 // Here construct the Sensitive Detector and Read Out Geometry 262 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 263 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 264 return true; 265 } 266 ///////////////////////////////////////////////////////////////////////////// 267 G4bool HadrontherapyDetectorConstruction::SetDetectorSize(G4double sizeX, G4double sizeY, G4double sizeZ) 268 { 269 // Check that the detector stay inside the phantom 270 if (sizeX > 0 && sizeX < sizeOfVoxelAlongX) {G4cout << "WARNING: Detector X size must be bigger than that of Voxel X" << G4endl; return false;} 271 if (sizeY > 0 && sizeY < sizeOfVoxelAlongY) {G4cout << "WARNING: Detector Y size must be bigger than that of Voxel Y" << G4endl; return false;} 272 if (sizeZ > 0 && sizeZ < sizeOfVoxelAlongZ) {G4cout << "WARNING: Detector Z size must be bigger than that of Voxel Z" << G4endl; return false;} 273 274 if (!IsInside(sizeX/2, 275 sizeY/2, 276 sizeZ/2, 277 phantomSizeX, 278 phantomSizeY, 279 phantomSizeZ, 280 detectorToPhantomPosition)) 281 {return false;} 282 // Negative or null values mean don't change it! 283 if (sizeX > 0) { 284 detectorSizeX = sizeX/2; 285 detector -> SetXHalfLength(detectorSizeX); 286 } 287 288 if (sizeY > 0) { 289 detectorSizeY = sizeY/2; 290 detector -> SetYHalfLength(detectorSizeY); 291 } 292 293 if (sizeZ > 0) { 294 detectorSizeZ = sizeZ/2; 295 detector -> SetZHalfLength(detectorSizeZ); 296 } 297 298 299 G4cout << "The (X, Y, Z) dimensions of the detector are : (" << 300 G4BestUnit( detector -> GetXHalfLength()*2., "Length") << ", " << 301 G4BestUnit( detector -> GetYHalfLength()*2., "Length") << ", " << 302 G4BestUnit( detector -> GetZHalfLength()*2., "Length") << ')' << G4endl; 303 // Adjust detector position 304 SetDetectorPosition(); 305 // Adjust voxels number accordingly to new detector geometry 306 // Matrix will be re-instantiated! 307 // Voxels and ROGeometry must follow the detector! 308 SetNumberOfVoxelBySize(sizeOfVoxelAlongX, sizeOfVoxelAlongY, sizeOfVoxelAlongZ); 309 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 310 return true; 311 } 312 313 ///////////////////////////////////////////////////////////////////////////// 314 G4bool HadrontherapyDetectorConstruction::SetPhantomSize(G4double sizeX, G4double sizeY, G4double sizeZ) 315 { 316 317 if (!IsInside(detectorSizeX, 318 detectorSizeY, 319 detectorSizeZ, 320 sizeX/2,//method parameters 321 sizeY/2, 322 sizeZ/2, 323 detectorToPhantomPosition 324 )) 325 return false; 326 327 // Only change positive dimensions 328 if (sizeX > 0) { 329 phantomSizeX = sizeX/2; 330 phantom -> SetXHalfLength(phantomSizeX); 331 } 332 if (sizeY > 0) { 333 phantomSizeY = sizeY/2; 334 phantom -> SetYHalfLength(phantomSizeY); 335 } 336 337 if (sizeZ > 0) { 338 phantomSizeZ = sizeZ/2; 339 phantom -> SetZHalfLength(phantomSizeZ); 340 } 341 342 343 G4cout << "The (X, Y, Z) dimensions of the phantom are : (" << 344 G4BestUnit( phantom -> GetXHalfLength()*2., "Length") << ", " << 345 G4BestUnit( phantom -> GetYHalfLength()*2., "Length") << ", " << 346 G4BestUnit( phantom -> GetZHalfLength()*2., "Length") << ')' << G4endl; 347 //G4cout << '\n' << "Coordinate volume: " << phantomPhysicalVolume -> GetTranslation() << G4endl; 348 // Adjust detector position inside phantom 349 SetDetectorPosition(); 350 351 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 352 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 353 return true; 354 } 355 ///////////////////////////////////////////////////////////////////////////// 356 G4bool HadrontherapyDetectorConstruction::SetPhantomPosition(G4ThreeVector displacement) 357 { 358 // Set Phantom position respect to the World 359 // TODO check for overlap! 360 phantomPosition = displacement; 361 if (phantomPhysicalVolume) 362 { 363 phantomPhysicalVolume -> SetTranslation(phantomPosition); 364 G4cout << "Displacement between Phantom and World is: "; 365 G4cout << "DX= "<< G4BestUnit(phantomPosition.getX(),"Length") << ", " << 366 "DY= "<< G4BestUnit(phantomPosition.getY(),"Length") << ", " << 367 "DZ= "<< G4BestUnit(phantomPosition.getZ(),"Length") << G4endl; 368 369 // Redraw ROGeometry! 370 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 371 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 372 } 373 return true; 374 } 375 376 ///////////////////////////////////////////////////////////////////////////// 377 G4bool HadrontherapyDetectorConstruction::SetDetectorToPhantomPosition(G4ThreeVector displacement) 378 { 379 // Ignore negative values 380 if (displacement[0] < 0.) displacement[0] = detectorToPhantomPosition[0]; 381 if (displacement[1] < 0.) displacement[1] = detectorToPhantomPosition[1]; 382 if (displacement[2] < 0.) displacement[2] = detectorToPhantomPosition[2]; 383 384 if (!IsInside(detectorSizeX, 385 detectorSizeY, 386 detectorSizeZ, 387 phantomSizeX, 388 phantomSizeY, 389 phantomSizeZ, 390 displacement // method parameter! 391 )) 392 {return false;} 393 detectorToPhantomPosition = displacement; 394 395 // Adjust detector position inside phantom 396 SetDetectorPosition(); 397 398 ConstructSensitiveDetector(GetDetectorToWorldPosition()); 399 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 400 return true; 401 } 419 numberOfVoxelsAlongX << ',' << 420 numberOfVoxelsAlongY <<',' << 421 numberOfVoxelsAlongZ << ')' << G4endl; 422 423 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorMessenger.cc
r1230 r1313 31 31 #include "HadrontherapyDetectorConstruction.hh" 32 32 #include "G4UIdirectory.hh" 33 #include "G4UIcmdWithADoubleAndUnit.hh" 33 #include "G4UIcmdWith3VectorAndUnit.hh" 34 #include "G4UIcmdWithoutParameter.hh" 34 35 #include "G4UIcmdWithAString.hh" 35 #include "G4UIcmdWith3VectorAndUnit.hh"36 36 37 37 ///////////////////////////////////////////////////////////////////////////// … … 49 49 "PhantomSizeAlongZ", false); 50 50 changeThePhantomSizeCmd -> SetDefaultUnit("mm"); 51 changeThePhantomSizeCmd -> SetUnitCandidates(" um mm cm");51 changeThePhantomSizeCmd -> SetUnitCandidates("nm um mm cm"); 52 52 changeThePhantomSizeCmd -> AvailableForStates(G4State_Idle); 53 53 54 55 // Change Phantom material 56 changeThePhantomMaterialCmd = new G4UIcmdWithAString("/changePhantom/material", this); 57 changeThePhantomMaterialCmd -> SetGuidance("Change the Phantom and the detector material"); 58 changeThePhantomMaterialCmd -> SetParameterName("PhantomMaterial", false); 59 changeThePhantomMaterialCmd -> SetDefaultValue("G4_WATER"); 60 changeThePhantomMaterialCmd -> AvailableForStates(G4State_Idle); 54 61 55 62 // Change Phantom position … … 61 68 "PositionAlongZ", false); 62 69 changeThePhantomPositionCmd -> SetDefaultUnit("mm"); 63 changeThePhantomPositionCmd -> SetUnitCandidates(" mm cm m");70 changeThePhantomPositionCmd -> SetUnitCandidates("um mm cm m"); 64 71 changeThePhantomPositionCmd -> AvailableForStates(G4State_Idle); 65 72 73 74 updateCmd = new G4UIcmdWithoutParameter("/changePhantom/update",this); 75 updateCmd->SetGuidance("Update Phantom/Detector geometry."); 76 updateCmd->SetGuidance("This command MUST be applied before \"beamOn\" "); 77 updateCmd->SetGuidance("if you changed geometrical value(s)."); 78 updateCmd->AvailableForStates(G4State_Idle); 66 79 67 80 // Change detector size … … 74 87 changeTheDetectorSizeCmd -> SetParameterName("DetectorSizeAlongX", "DetectorSizeAlongY", "DetectorSizeAlongZ", false); 75 88 changeTheDetectorSizeCmd -> SetDefaultUnit("mm"); 76 changeTheDetectorSizeCmd -> SetUnitCandidates(" um mm cm");89 changeTheDetectorSizeCmd -> SetUnitCandidates("nm um mm cm"); 77 90 changeTheDetectorSizeCmd -> AvailableForStates(G4State_Idle); 78 91 … … 85 98 "DisplacementAlongZ", false); 86 99 changeTheDetectorToPhantomPositionCmd -> SetDefaultUnit("mm"); 87 changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates(" um mm cm");100 changeTheDetectorToPhantomPositionCmd -> SetUnitCandidates("nm um mm cm"); 88 101 changeTheDetectorToPhantomPositionCmd -> AvailableForStates(G4State_Idle); 89 102 … … 94 107 changeTheDetectorVoxelCmd -> SetParameterName("VoxelSizeAlongX", "VoxelSizeAlongY", "VoxelSizeAlongZ", false); 95 108 changeTheDetectorVoxelCmd -> SetDefaultUnit("mm"); 96 changeTheDetectorVoxelCmd -> SetUnitCandidates(" um mm cm");109 changeTheDetectorVoxelCmd -> SetUnitCandidates("nm um mm cm"); 97 110 changeTheDetectorVoxelCmd -> AvailableForStates(G4State_Idle); 98 111 } … … 104 117 delete changeThePhantomSizeCmd; 105 118 delete changeThePhantomPositionCmd; 119 delete changeThePhantomMaterialCmd; 120 delete updateCmd; 106 121 delete changeTheDetectorDir; 107 122 delete changeTheDetectorSizeCmd; … … 124 139 hadrontherapyDetector -> SetPhantomPosition(size); 125 140 } 141 else if (command == changeThePhantomMaterialCmd) 142 { 143 hadrontherapyDetector -> SetPhantomMaterial(newValue); 144 } 126 145 else if (command == changeTheDetectorSizeCmd) 127 146 { … … 137 156 { 138 157 G4ThreeVector size = changeTheDetectorVoxelCmd -> GetNew3VectorValue(newValue); 139 hadrontherapyDetector -> SetNumberOfVoxelBySize(size.getX(),size.getY(),size.getZ()); 158 hadrontherapyDetector -> SetVoxelSize(size.getX(),size.getY(),size.getZ()); 159 } 160 else if (command == updateCmd) 161 { 162 hadrontherapyDetector -> UpdateGeometry(); 140 163 } 141 164 } -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyEventAction.cc
r1230 r1313 24 24 // ******************************************************************** 25 25 // 26 // $Id: HadrontherapyEventAction.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 26 // $Id: HadrontherapyEventAction.cc; 27 // 28 // See more at: http://workgroup.lngs.infn.it/geant4lns 29 // 30 // ---------------------------------------------------------------------------- 31 // GEANT 4 - Hadrontherapy example 32 // ---------------------------------------------------------------------------- 33 // Code developed by: 34 // 35 // G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) 36 // 37 // (a) Laboratori Nazionali del Sud 38 // of the National Institute for Nuclear Physics, Catania, Italy 39 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy 40 // 41 // * cirrone@lns.infn.it 42 // -------------------------------------------------------------- 29 43 #include "G4Event.hh" 30 44 #include "G4EventManager.hh" 31 45 #include "G4HCofThisEvent.hh" 32 46 #include "G4VHitsCollection.hh" 33 #include "G4TrajectoryContainer.hh"34 #include "G4Trajectory.hh"35 #include "G4VVisManager.hh"36 47 #include "G4SDManager.hh" 37 48 #include "G4VVisManager.hh" 49 38 50 #include "HadrontherapyEventAction.hh" 39 51 #include "HadrontherapyDetectorHit.hh" … … 64 76 //printing survey 65 77 if (evtNb%printModulo == 0) 66 G4cout << "\n---> Begin of Event: " << evtNb << G4endl;78 G4cout << "\n---> Begin of Event: " << evtNb << G4endl; 67 79 68 80 G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); 69 81 if(hitsCollectionID == -1) 70 82 hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection"); 83 71 84 } 72 85 73 86 ///////////////////////////////////////////////////////////////////////////// 74 87 void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt) 75 { 88 { 76 89 if(hitsCollectionID < 0) 77 90 return; 78 91 G4HCofThisEvent* HCE = evt -> GetHCofThisEvent(); 79 92 93 // Clear voxels hit list 94 HadrontherapyMatrix* matrix = HadrontherapyMatrix::GetInstance(); 95 if (matrix) matrix -> ClearHitTrack(); 96 80 97 if(HCE) 81 98 { … … 83 100 if(CHC) 84 101 { 85 matrix = HadrontherapyMatrix::getInstance();86 102 if(matrix) 87 103 { … … 101 117 } 102 118 } 103 // Extract the trajectories and draw them in the visualisation104 105 if (G4VVisManager::GetConcreteInstance())106 {107 G4TrajectoryContainer * trajectoryContainer = evt -> GetTrajectoryContainer();108 G4int n_trajectories = 0;109 if (trajectoryContainer) n_trajectories = trajectoryContainer -> entries();110 111 for (G4int i = 0; i < n_trajectories; i++)112 {113 G4Trajectory* trj = (G4Trajectory*)114 ((*(evt -> GetTrajectoryContainer()))[i]);115 if(drawFlag == "all") trj -> DrawTrajectory(50);116 else if((drawFlag == "charged")&&(trj -> GetCharge() != 0.))117 trj -> DrawTrajectory(50);118 else if ((drawFlag == "neutral")&&(trj -> GetCharge() == 0.))119 trj -> DrawTrajectory(50);120 }121 }122 119 } 123 120 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyMatrix.cc
r1230 r1313 1 //2 // ********************************************************************3 // * License and Disclaimer *4 // * *5 // * The Geant4 software is copyright of the Copyright Holders of *6 // * the Geant4 Collaboration. It is provided under the terms and *7 // * conditions of the Geant4 Software License, included in the file*8 // * LICENSE and available at http://cern.ch/geant4/license . These *9 // * include a list of copyright holders. *10 // * *11 // * Neither the authors of this software system, nor their employing *12 // * institutes,nor the agencies providing financial support for this *13 // * work make any representation or warranty, express or implied, *14 // * regarding this software system or assume any liability for its *15 // * use. Please see the license in the file LICENSE and URL above *16 // * for the full disclaimer and the limitation of liability. *17 // * *18 // * This code implementation is the result of the scientific and *19 // * technical work of the GEANT4 collaboration. *20 // * By using, copying, modifying or distributing the software (or *21 // * any work based on the software) you agree to acknowledge its *22 // * use in resulting scientific publications, and indicate your *23 // * acceptance of all terms of the Geant4 Software license. *24 // ********************************************************************25 //26 // $Id: HadrontherapyMatrix.cc;27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy//1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file* 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // $Id: HadrontherapyMatrix.cc; 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy// 28 28 29 29 #include "HadrontherapyMatrix.hh" 30 30 #include "HadrontherapyAnalysisManager.hh" 31 #include "G4RunManager.hh" 32 #include "HadrontherapyPrimaryGeneratorAction.hh" 33 #include "G4ParticleGun.hh" 34 35 #include <fstream> 36 #include <unistd.h> 37 #include <iostream> 38 #include <sstream> 39 #include <iomanip> 31 40 #include "globals.hh" 32 #include <fstream> 33 41 42 // Units definition: CLHEP/Units/SystemOfUnits.h 43 // 34 44 HadrontherapyMatrix* HadrontherapyMatrix::instance = NULL; 35 // Static method that only return a pointer to the matrix object 36 HadrontherapyMatrix* HadrontherapyMatrix::getInstance() 37 { 38 return instance; 39 } 40 // This STATIC method delete (!) the old matrix and rewrite a new object returning a pointer to it 41 HadrontherapyMatrix* HadrontherapyMatrix::getInstance(G4int voxelX, G4int voxelY, G4int voxelZ) 42 { 43 if (instance) delete instance; 44 instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ); 45 instance -> Initialize(); 46 return instance; 47 } 48 49 HadrontherapyMatrix::HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ): 50 matrix(0) 45 G4bool HadrontherapyMatrix::secondaries = false; 46 // Only return a pointer to matrix 47 HadrontherapyMatrix* HadrontherapyMatrix::GetInstance() 48 { 49 return instance; 50 } 51 // This STATIC method delete (!) the old matrix and rewrite a new object returning a pointer to it 52 // TODO A check on the parameters is required! 53 HadrontherapyMatrix* HadrontherapyMatrix::GetInstance(G4int voxelX, G4int voxelY, G4int voxelZ, G4double mass) 54 { 55 if (instance) delete instance; 56 instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ, mass); 57 instance -> Initialize();// XXX 58 return instance; 59 } 60 HadrontherapyMatrix::HadrontherapyMatrix(G4int voxelX, G4int voxelY, G4int voxelZ, G4double mass): 61 filename("Dose.out"), 62 doseUnit(MeV/g) 51 63 { 52 // Number of the voxels of the phantom 53 // For Y = Z = 1 the phantom is divided in slices (and not in voxels) 54 // orthogonal to the beam axis 55 numberVoxelX = voxelX; 56 numberVoxelY = voxelY; 57 numberVoxelZ = voxelZ; 58 // Create the dose matrix 59 matrix = new G4double[numberVoxelX*numberVoxelY*numberVoxelZ]; 60 if (matrix) G4cout << "Matrix: Memory space to store physical dose into " << 61 numberVoxelX*numberVoxelY*numberVoxelZ << 62 " voxels has been allocated " << G4endl; 63 else G4Exception("Can't allocate memory to store physical dose!"); 64 } 65 64 // Number of the voxels of the phantom 65 // For Y = Z = 1 the phantom is divided in slices (and not in voxels) 66 // orthogonal to the beam axis 67 numberOfVoxelAlongX = voxelX; 68 numberOfVoxelAlongY = voxelY; 69 numberOfVoxelAlongZ = voxelZ; 70 massOfVoxel = mass; 71 // Create the dose matrix 72 matrix = new G4double[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ]; 73 if (matrix) 74 { 75 G4cout << "HadrontherapyMatrix: Memory space to store physical dose into " << 76 numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ << 77 " voxels has been allocated " << G4endl; 78 } 79 else G4Exception(" HadrontherapyMatrix::HadrontherapyMatrix. Can't allocate memory to store physical dose!"); 80 // Hit voxel (TrackID) marker 81 // This array mark the status of voxel, if a hit occur, with the trackID of the particle 82 // Must be initialized 83 hitTrack = new G4int[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ]; 84 ClearHitTrack(); 85 } 86 87 ///////////////////////////////////////////////////////////////////////////// 66 88 HadrontherapyMatrix::~HadrontherapyMatrix() 67 89 { 68 90 delete[] matrix; 69 } 70 71 void HadrontherapyMatrix::flush() 72 { 73 if(matrix) 74 for(int i=0; i<numberVoxelX*numberVoxelY*numberVoxelZ; i++) 75 { 76 matrix[i] = 0; 77 } 78 } 91 delete[] hitTrack; 92 // clear fluences/dose data 93 Clear(); 94 } 95 96 ///////////////////////////////////////////////////////////////////////////// 97 void HadrontherapyMatrix::Clear() 98 { 99 for (size_t i=0; i<ionStore.size(); i++) 100 { 101 delete[] ionStore[i].dose; 102 delete[] ionStore[i].fluence; 103 } 104 ionStore.clear(); 105 } 106 107 ///////////////////////////////////////////////////////////////////////////// 108 // Initialise the elements of the matrix to zero 79 109 void HadrontherapyMatrix::Initialize() 80 110 { 81 // Initialise the elements of the matrix to zero 82 for(G4int i = 0; i < numberVoxelX; i++) 83 { 84 for(G4int j = 0; j < numberVoxelY; j++) 85 { 86 for(G4int k = 0; k < numberVoxelZ; k++) 87 88 matrix[Index(i,j,k)] = 0.; 89 } 90 } 91 } 111 Clear(); 112 for(int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++) 113 { 114 matrix[i] = 0; 115 } 116 } 117 ///////////////////////////////////////////////////////////////////////////// 118 ///////////////////////////////////////////////////////////////////////////// 119 // Print generated nuclides list 120 void HadrontherapyMatrix::PrintNuclides() 121 { 122 for (size_t i=0; i<ionStore.size(); i++) 123 { 124 G4cout << ionStore[i].name << G4endl; 125 } 126 } 127 ///////////////////////////////////////////////////////////////////////////// 128 // Clear Hit voxel (TrackID) markers 129 void HadrontherapyMatrix::ClearHitTrack() 130 { 131 for(G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0; 132 } 133 // Return Hit status 134 G4int* HadrontherapyMatrix::GetHitTrack(G4int i, G4int j, G4int k) 135 { 136 return &(hitTrack[Index(i,j,k)]); 137 } 138 ///////////////////////////////////////////////////////////////////////////// 139 // Dose methods... 140 // Fill DOSE/fluence matrix for particle/ion: 141 // If fluence parameter is true (default value is FALSE) then fluence at voxel (i, j, k) is increased. 142 // The energyDeposit parameter fill the dose matrix for voxel (i,j,k) 143 ///////////////////////////////////////////////////////////////////////////// 144 145 G4bool HadrontherapyMatrix::Fill(G4int trackID, 146 G4ParticleDefinition* particleDef, 147 G4int i, G4int j, G4int k, 148 G4double energyDeposit, 149 G4bool fluence) 150 { 151 if (energyDeposit <=0. && !fluence || !secondaries) return false; 152 // Get Particle Data Group particle ID 153 G4int PDGencoding = particleDef -> GetPDGEncoding(); 154 PDGencoding -= PDGencoding%10; 155 156 // Search for already allocated data... 157 for (size_t l=0; l < ionStore.size(); l++) 158 { 159 if (ionStore[l].PDGencoding == PDGencoding ) 160 { // Is it a primary or a secondary particle? 161 if ( trackID ==1 && ionStore[l].isPrimary || trackID !=1 && !ionStore[l].isPrimary) 162 { 163 if (energyDeposit > 0.) ionStore[l].dose[Index(i, j, k)] += energyDeposit/massOfVoxel; 164 165 // Fill a matrix per each ion with the fluence 166 if (fluence) ionStore[l].fluence[Index(i, j, k)]++; 167 return true; 168 } 169 } 170 } 171 172 G4int Z = particleDef-> GetAtomicNumber(); 173 G4int A = particleDef-> GetAtomicMass(); 174 175 G4String fullName = particleDef -> GetParticleName(); 176 G4String name = fullName.substr (0, fullName.find("[") ); // cut excitation energy 177 // Let's put a new particle in our store... 178 ion newIon = 179 { 180 (trackID == 1) ? true:false, 181 PDGencoding, 182 name, 183 name.length(), 184 Z, 185 A, 186 new G4double[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ], 187 new unsigned int[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ] 188 }; 189 // Initialize data 190 if (newIon.dose && newIon.fluence) 191 { 192 for(G4int m=0; m<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; m++) 193 { 194 newIon.dose[m] = 0.; 195 newIon.fluence[m] = 0; 196 } 197 if (energyDeposit > 0.) newIon.dose[Index(i, j, k)] += energyDeposit/massOfVoxel; 198 if (fluence) newIon.fluence[Index(i, j, k)]++; 199 200 ionStore.push_back(newIon); 201 202 // TODO Put some verbosity check 203 /* 204 G4cout << "Memory space to store the DOSE/FLUENCE into " << 205 numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ << 206 " voxels has been allocated for the nuclide " << newIon.name << 207 " (Z = " << Z << ", A = " << A << ")" << G4endl ; 208 */ 209 return true; 210 } 211 else // XXX Out of memory! XXX 212 { 213 return false; 214 } 215 216 } 217 218 ///////////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////////// 220 // Methods to store data to filenames... 221 //////////////////////////////////////////////////////////////////////////// 222 //////////////////////////////////////////////////////////////////////////// 223 // 224 // General method to store matrix data to filename 225 void HadrontherapyMatrix::StoreMatrix(G4String file, void* data, size_t psize) 226 { 227 if (data) 228 { 229 ofs.open(file, std::ios::out); 230 if (ofs.is_open()) 231 { 232 for(G4int i = 0; i < numberOfVoxelAlongX; i++) 233 for(G4int j = 0; j < numberOfVoxelAlongY; j++) 234 for(G4int k = 0; k < numberOfVoxelAlongZ; k++) 235 { 236 G4int n = Index(i, j, k); 237 // Check for data type: u_int, G4double, XXX 238 if (psize == sizeof(unsigned int)) 239 { 240 unsigned int* pdata = (unsigned int*)data; 241 if (pdata[n]) ofs << i << '\t' << j << '\t' << 242 k << '\t' << pdata[n] << G4endl; 243 } 244 else if (psize == sizeof(G4double)) 245 { 246 G4double* pdata = (G4double*)data; 247 if (pdata[n]) ofs << i << '\t' << j << '\t' << 248 k << '\t' << pdata[n] << G4endl; 249 } 250 } 251 ofs.close(); 252 } 253 } 254 } 255 256 // Store fluence per single ion in multiple files 257 void HadrontherapyMatrix::StoreFluenceData() 258 { 259 for (size_t i=0; i < ionStore.size(); i++){ 260 StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int)); 261 } 262 } 263 // Store dose per single ion in multiple files 264 void HadrontherapyMatrix::StoreDoseData() 265 { 266 267 for (size_t i=0; i < ionStore.size(); i++){ 268 StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double)); 269 } 270 } 271 ///////////////////////////////////////////////////////////////////////// 272 // Store dose for all ions into a single file and into ntuples. 273 // Please note that this function is called via messenger commands 274 // defined in the HadrontherapyAnalysisFileMessenger.cc class file 275 void HadrontherapyMatrix::StoreDoseFluenceAscii() 276 { 277 // Sort like periodic table 278 std::sort(ionStore.begin(), ionStore.end()); 279 #define width 15L 280 ofs.open(filename, std::ios::out); 281 if (ofs.is_open()) 282 { 283 284 // 285 // Write the voxels index and the list of particles/ions 286 ofs << std::setprecision(6) << std::left << 287 "i\tj\tk\t"; 288 /* 289 G4RunManager *runManager = G4RunManager::GetRunManager(); 290 HadrontherapyPrimaryGeneratorAction *pPGA = (HadrontherapyPrimaryGeneratorAction*)runManager -> GetUserPrimaryGeneratorAction(); 291 G4String name = pPGA -> GetParticleGun() -> GetParticleDefinition() -> GetParticleName(); 292 */ 293 // Total dose 294 ofs << std::setw(width) << "Dose"; 295 296 for (size_t l=0; l < ionStore.size(); l++) 297 { 298 G4String a = (ionStore[l].isPrimary) ? "_1":""; // is it a primary? 299 ofs << std::setw(width) << ionStore[l].name + a << 300 std::setw(width) << ionStore[l].name + a; 301 } 302 ofs << G4endl; 303 304 /* 305 // PDGencoding 306 ofs << std::setprecision(6) << std::left << 307 "0\t0\t0\t"; 308 309 // Total dose 310 ofs << std::setw(width) << '0'; 311 for (size_t l=0; l < ionStore.size(); l++) 312 { 313 ofs << std::setw(width) << ionStore[l].PDGencoding << 314 std::setw(width) << ionStore[l].PDGencoding; 315 } 316 ofs << G4endl; 317 */ 318 // Write data 319 for(G4int i = 0; i < numberOfVoxelAlongX; i++) 320 for(G4int j = 0; j < numberOfVoxelAlongY; j++) 321 for(G4int k = 0; k < numberOfVoxelAlongZ; k++) 322 { 323 G4int n = Index(i, j, k); 324 // Write only not identically null data lines 325 if (matrix[n]) 326 { 327 ofs << G4endl; 328 ofs << i << '\t' << j << '\t' << k << '\t'; 329 // Total dose 330 ofs << std::setw(width) << matrix[n]/(doseUnit); 331 { 332 for (size_t l=0; l < ionStore.size(); l++) 333 { 334 // Fill ASCII file rows 335 ofs << std::setw(width) << ionStore[l].dose[n]/(doseUnit) << 336 std::setw(width) << ionStore[l].fluence[n]; 337 } 338 } 339 } 340 } 341 ofs.close(); 342 } 343 } 344 ///////////////////////////////////////////////////////////////////////////// 345 346 #ifdef G4ANALYSIS_USE_ROOT 347 void HadrontherapyMatrix::StoreDoseFluenceRoot() 348 { 349 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance(); 350 for(G4int i = 0; i < numberOfVoxelAlongX; i++) 351 for(G4int j = 0; j < numberOfVoxelAlongY; j++) 352 for(G4int k = 0; k < numberOfVoxelAlongZ; k++) 353 { 354 G4int n = Index(i, j, k); 355 for (size_t l=0; l < ionStore.size(); l++) 356 357 { 358 // Do the same work for .root file: fill dose/fluence ntuple 359 analysis -> FillVoxelFragmentTuple( i, j, k, 360 ionStore[l].A, 361 ionStore[l].Z, 362 ionStore[l].dose[n]/(doseUnit), 363 ionStore[l].fluence[n] ); 364 365 366 } 367 } 368 } 369 #endif 92 370 93 371 void HadrontherapyMatrix::Fill(G4int i, G4int j, G4int k, 94 372 G4double energyDeposit) 95 373 { 96 if (matrix) 97 matrix[Index(i,j,k)] += energyDeposit; 98 99 // Store the energy deposit in the matrix element corresponding 100 // to the phantom voxel i, j, k 101 } 102 374 if (matrix) 375 matrix[Index(i,j,k)] += energyDeposit; 376 377 // Store the energy deposit in the matrix element corresponding 378 // to the phantom voxel 379 } 103 380 void HadrontherapyMatrix::TotalEnergyDeposit() 104 381 { 382 // Convert energy deposited to dose. 105 383 // Store the information of the matrix in a ntuple and in 106 384 // a 1D Histogram 107 385 108 G4int k; 109 G4int j; 110 G4int i; 111 112 if (matrix) 386 #ifdef G4ANALYSIS_USE_ROOT 387 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance(); 388 #endif 389 if (matrix) 113 390 { 114 std::ofstream ofs; 115 ofs.open("DoseDistribution.out"); 116 117 for(G4int l = 0; l < numberVoxelZ; l++) 118 { 119 k = l; 120 121 for(G4int m = 0; m < numberVoxelY; m++) 122 { 123 j = m * numberVoxelZ + k; 124 125 for(G4int n = 0; n < numberVoxelX; n++) 126 { 127 i = n* numberVoxelZ * numberVoxelY + j; 128 if(matrix[i] != 0) 129 { 130 ofs << n << '\t' << m << '\t' << 131 k << '\t' << matrix[i] << G4endl; 132 133 #ifdef ANALYSIS_USE 134 HadrontherapyAnalysisManager* analysis = 135 HadrontherapyAnalysisManager::getInstance(); 136 analysis -> FillEnergyDeposit(n, m, k, matrix[i]); 137 analysis -> BraggPeak(n, matrix[i]); 391 for(G4int i = 0; i < numberOfVoxelAlongX; i++) 392 for(G4int j = 0; j < numberOfVoxelAlongY; j++) 393 for(G4int k = 0; k < numberOfVoxelAlongZ; k++) 394 { 395 G4int n = Index(i,j,k); 396 matrix[n] = matrix[n] / massOfVoxel; 397 #ifdef G4ANALYSIS_USE_ROOT 398 analysis -> FillEnergyDeposit(i, j, k, matrix[n]/doseUnit); 399 analysis -> BraggPeak(i, matrix[n]/doseUnit); 138 400 #endif 139 } 140 } 141 } 142 } 143 } 144 } 401 } 402 } 403 } 404 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsList.cc
r1230 r1313 76 76 // and local physic for ion-ion enelastic processes) 77 77 78 #include "G4RunManager.hh" 79 #include "G4Region.hh" 80 #include "G4RegionStore.hh" 78 81 #include "HadrontherapyPhysicsList.hh" 79 82 #include "HadrontherapyPhysicsListMessenger.hh" … … 86 89 #include "LocalINCLIonIonInelasticPhysic.hh" // Physic dedicated to the ion-ion inelastic processes using INCL/ABLA 87 90 88 // Physic lists (contained inside the Geant4 distribution)91 // Physic lists (contained inside the Geant4 source code, in the 'physicslists folder') 89 92 #include "G4EmStandardPhysics_option3.hh" 90 93 #include "G4EmLivermorePhysics.hh" … … 173 176 { 174 177 // transportation 175 //176 178 AddTransportation(); 177 179 178 180 // electromagnetic physics list 179 //180 181 emPhysicsList->ConstructProcess(); 181 182 em_config.AddModels(); 182 183 183 184 // decay physics list 184 //185 185 decPhysicsList->ConstructProcess(); 186 186 … … 207 207 // ELECTROMAGNETIC MODELS 208 208 ///////////////////////////////////////////////////////////////////////////// 209 210 if (name == "standard_opt3") { 209 if (name == "standard_opt3") { 211 210 emName = name; 212 211 delete emPhysicsList; 213 212 emPhysicsList = new G4EmStandardPhysics_option3(); 213 G4RunManager::GetRunManager() -> PhysicsHasBeenModified(); 214 214 G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmStandardPhysics_option3" << G4endl; 215 215 … … 218 218 delete emPhysicsList; 219 219 emPhysicsList = new G4EmLivermorePhysics(); 220 G4RunManager::GetRunManager()-> PhysicsHasBeenModified(); 220 221 G4cout << "THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmLivermorePhysics" << G4endl; 221 222 … … 308 309 SetCutValue(cutForPositron, "e+"); 309 310 311 // Set cuts for detector 312 SetDetectorCut(defaultCutValue); 310 313 if (verboseLevel>0) DumpCutValuesTable(); 311 314 } … … 331 334 SetParticleCuts(cutForPositron, G4Positron::Positron()); 332 335 } 336 337 void HadrontherapyPhysicsList::SetDetectorCut(G4double cut) 338 { 339 340 G4String regionName = "DetectorLog"; 341 G4Region* region = G4RegionStore::GetInstance()->GetRegion(regionName); 342 343 G4ProductionCuts* cuts = new G4ProductionCuts ; 344 cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("gamma")); 345 cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("e-")); 346 cuts -> SetProductionCut(cut,G4ProductionCuts::GetIndex("e+")); 347 region -> SetProductionCuts(cuts); 348 } 349 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhysicsListMessenger.cc
r1230 r1313 69 69 allCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 70 70 71 allDetectorCmd = new G4UIcmdWithADoubleAndUnit("/physic/setDetectorCuts",this); 72 allDetectorCmd->SetGuidance("Set cut for all. into Detector"); 73 allDetectorCmd->SetParameterName("cut",false); 74 allDetectorCmd->SetUnitCategory("Length"); 75 allDetectorCmd->SetRange("cut>0.0"); 76 allDetectorCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 77 71 78 pListCmd = new G4UIcmdWithAString("/physic/addPhysics",this); 72 79 pListCmd->SetGuidance("Add physics list."); 73 80 pListCmd->SetParameterName("PList",false); 74 pListCmd->AvailableForStates(G4State_PreInit );81 pListCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 75 82 76 83 packageListCmd = new G4UIcmdWithAString("/physic/addPackage",this); 77 84 packageListCmd->SetGuidance("Add physics package."); 78 85 packageListCmd->SetParameterName("package",false); 79 packageListCmd->AvailableForStates(G4State_PreInit );86 packageListCmd->AvailableForStates(G4State_PreInit, G4State_Idle); 80 87 } 81 88 … … 87 94 delete protoCutCmd; 88 95 delete allCutCmd; 96 delete allDetectorCmd; 89 97 delete pListCmd; 90 98 delete physDir; … … 99 107 { pPhysicsList->SetCutForGamma(gammaCutCmd->GetNewDoubleValue(newValue));} 100 108 101 if( command == electCutCmd )109 else if( command == electCutCmd ) 102 110 { pPhysicsList->SetCutForElectron(electCutCmd->GetNewDoubleValue(newValue));} 103 111 104 if( command == protoCutCmd )112 else if( command == protoCutCmd ) 105 113 { pPhysicsList->SetCutForPositron(protoCutCmd->GetNewDoubleValue(newValue));} 106 114 107 if( command == allCutCmd )115 else if( command == allCutCmd ) 108 116 { 109 117 G4double cut = allCutCmd->GetNewDoubleValue(newValue); … … 112 120 pPhysicsList->SetCutForPositron(cut); 113 121 } 114 115 if( command == pListCmd ) 122 else if( command == allDetectorCmd) 123 { 124 G4double cut = allDetectorCmd -> GetNewDoubleValue(newValue); 125 pPhysicsList -> SetDetectorCut(cut); 126 } 127 else if( command == pListCmd ) 116 128 { pPhysicsList->AddPhysicsList(newValue);} 117 129 118 130 119 if( command == packageListCmd )131 else if( command == packageListCmd ) 120 132 { pPhysicsList->AddPackage(newValue);} 121 133 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyPrimaryGeneratorAction.cc
r1230 r1313 86 86 sigmaEnergy = defaultsigmaEnergy; 87 87 88 #ifdef ANALYSIS_USE88 #ifdef G4ANALYSIS_USE_ROOT 89 89 // Write these values into the analysis if needed. Have to be written separately on change. 90 HadrontherapyAnalysisManager:: getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);90 HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 91 91 #endif 92 92 … … 120 120 void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 121 121 { 122 #ifdef ANALYSIS_USE122 #ifdef G4ANALYSIS_USE_ROOT 123 123 // Increment the event counter 124 HadrontherapyAnalysisManager:: getInstance()->startNewEvent();124 HadrontherapyAnalysisManager::GetInstance()->startNewEvent(); 125 125 #endif 126 126 … … 178 178 { 179 179 meanKineticEnergy = val; 180 #ifdef ANALYSIS_USE180 #ifdef G4ANALYSIS_USE_ROOT 181 181 // Update the beam-data in the analysis manager 182 HadrontherapyAnalysisManager:: getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);182 HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 183 183 #endif 184 184 … … 188 188 { 189 189 sigmaEnergy = val; 190 #ifdef ANALYSIS_USE190 #ifdef G4ANALYSIS_USE_ROOT 191 191 // Update the sigmaenergy in the metadata. 192 HadrontherapyAnalysisManager:: getInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy);192 HadrontherapyAnalysisManager::GetInstance()->setBeamMetaData(meanKineticEnergy, sigmaEnergy); 193 193 #endif 194 194 } … … 217 217 G4double HadrontherapyPrimaryGeneratorAction::GetmeanKineticEnergy(void) 218 218 { return meanKineticEnergy;} 219 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapyRunAction.cc
r1230 r1313 27 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy 28 28 29 29 30 #include "HadrontherapyRunAction.hh" 30 31 #include "HadrontherapyEventAction.hh" … … 38 39 #include "HadrontherapyRunAction.hh" 39 40 41 42 #include "HadrontherapyAnalysisManager.hh" 43 #include "HadrontherapyMatrix.hh" 44 40 45 HadrontherapyRunAction::HadrontherapyRunAction() 41 46 { … … 48 53 void HadrontherapyRunAction::BeginOfRunAction(const G4Run* aRun) 49 54 { 50 G4RunManager::GetRunManager()->SetRandomNumberStore(true);51 G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl;55 G4RunManager::GetRunManager()-> SetRandomNumberStore(true); 56 G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl; 52 57 53 electromagnetic = 0; 54 hadronic = 0; 58 // Warning! any beamOn will reset all data (dose, fluence, histograms, etc)! 59 // 60 61 // Initialize matrix with energy of primaries clearing data inside 62 if (HadrontherapyMatrix::GetInstance()) 63 { 64 HadrontherapyMatrix::GetInstance() -> Initialize(); 65 } 66 67 #ifdef G4ANALYSIS_USE_ROOT 68 HadrontherapyAnalysisManager::GetInstance() -> flush(); // Finalize the root file 69 // Initialize root analysis ----> book 70 HadrontherapyAnalysisManager::GetInstance() -> book(); 71 #endif 72 electromagnetic = 0; 73 hadronic = 0; 55 74 } 56 75 57 76 void HadrontherapyRunAction::EndOfRunAction(const G4Run*) 58 77 { 59 // G4cout << " Summary of Run " << aRun -> GetRunID() <<" :"<< G4endl; 60 //G4cout << "Number of electromagnetic processes of primary particles in the phantom:" 61 // << electromagnetic << G4endl; 62 //G4cout << "Number of hadronic processes of primary particles in the phantom:" 63 // << hadronic << G4endl; 78 // Store dose & fluence data to ASCII & ROOT files 79 if ( HadrontherapyMatrix::GetInstance() ) 80 { 81 HadrontherapyMatrix::GetInstance() -> TotalEnergyDeposit(); 82 HadrontherapyMatrix::GetInstance() -> StoreDoseFluenceAscii(); 83 84 #ifdef G4ANALYSIS_USE_ROOT 85 if (HadrontherapyAnalysisManager::GetInstance()) 86 { 87 HadrontherapyMatrix::GetInstance() -> StoreDoseFluenceRoot(); 88 } 89 #endif 90 } 91 92 //G4cout << " Summary of Run " << aRun -> GetRunID() <<" :"<< G4endl; 93 //G4cout << "Number of electromagnetic processes of primary particles in the phantom:" 94 // << electromagnetic << G4endl; 95 //G4cout << "Number of hadronic processes of primary particles in the phantom:" 96 // << hadronic << G4endl; 64 97 } 65 98 void HadrontherapyRunAction::AddEMProcess() … … 72 105 } 73 106 74 75 -
trunk/examples/advanced/hadrontherapy/src/HadrontherapySteppingAction.cc
r1230 r1313 39 39 #include "G4ParticleDefinition.hh" 40 40 #include "G4ParticleTypes.hh" 41 #include "G4UserEventAction.hh" 41 42 42 43 #include "HadrontherapyAnalysisManager.hh" … … 47 48 HadrontherapySteppingAction::HadrontherapySteppingAction( HadrontherapyRunAction *run) 48 49 { 49 runAction = run;50 runAction = run; 50 51 } 51 52 … … 58 59 void HadrontherapySteppingAction::UserSteppingAction(const G4Step* aStep) 59 60 { 61 /* 62 // USEFULL METHODS TO RETRIEVE INFORMATION DURING THE STEPS 63 if( (aStep->GetTrack()->GetVolume()->GetName() == "DetectorPhys") 64 && aStep->GetTrack()->GetDefinition()->GetParticleName() == "proton") 65 //G4int evtNb = G4RunManager::GetRunManager()->GetCurrentEvent() -> GetEventID(); 66 { 67 G4cout << "ENERGIA: " << aStep->GetTrack()->GetKineticEnergy() 68 << " VOLUME " << aStep->GetTrack()->GetVolume()->GetName() 69 << " MATERIALE " << aStep -> GetTrack() -> GetMaterial() -> GetName() 70 << " EVENTO " << G4RunManager::GetRunManager()->GetCurrentEvent() -> GetEventID() 71 << " POS " << aStep->GetTrack()->GetPosition().x() 72 << G4endl; 73 } 74 */ 75 60 76 if( aStep->GetTrack()->GetVolume()->GetName() == "NewDetectorPhys"){ 61 #ifdef ANALYSIS_USE62 63 64 65 66 67 G4int A = def->GetBaryonNumber();68 G4double Z = def->GetPDGCharge();69 G4double posX = aStep->GetTrack()->GetPosition().x() / cm;70 G4double posY = aStep->GetTrack()->GetPosition().y() / cm;71 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm;72 G4double energy = secondaryParticleKineticEnergy / A / MeV;73 74 HadrontherapyAnalysisManager* analysisMgr = HadrontherapyAnalysisManager::getInstance();75 analysisMgr->fillFragmentTuple(A, Z, energy, posX, posY, posZ);76 77 G4double posX = aStep->GetTrack()->GetPosition().x() / cm ;78 G4double posY = aStep->GetTrack()->GetPosition().y() / cm ;79 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ;80 G4double energy = secondaryParticleKineticEnergy * MeV; // Hydrogen-1: A = 1, Z = 181 HadrontherapyAnalysisManager::getInstance()->fillFragmentTuple(1, 1.0, energy, posX, posY, posZ);82 83 84 85 86 87 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager:: getInstance();77 #ifdef G4ANALYSIS_USE_ROOT 78 G4ParticleDefinition *def = aStep->GetTrack()->GetDefinition(); 79 G4double secondaryParticleKineticEnergy = aStep->GetTrack()->GetKineticEnergy(); 80 G4String particleType = def->GetParticleType(); // particle type = nucleus for d, t, He3, alpha, and heavier nuclei 81 G4String particleName = def->GetParticleName(); // e.g. for alpha: the name = "alpha" and type = "nucleus" 82 if(particleType == "nucleus") { 83 G4int A = def->GetBaryonNumber(); 84 G4double Z = def->GetPDGCharge(); 85 G4double posX = aStep->GetTrack()->GetPosition().x() / cm; 86 G4double posY = aStep->GetTrack()->GetPosition().y() / cm; 87 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm; 88 G4double energy = secondaryParticleKineticEnergy / A / MeV; 89 90 HadrontherapyAnalysisManager* analysisMgr = HadrontherapyAnalysisManager::GetInstance(); 91 analysisMgr->FillFragmentTuple(A, Z, energy, posX, posY, posZ); 92 } else if(particleName == "proton") { // proton (hydrogen-1) is a special case 93 G4double posX = aStep->GetTrack()->GetPosition().x() / cm ; 94 G4double posY = aStep->GetTrack()->GetPosition().y() / cm ; 95 G4double posZ = aStep->GetTrack()->GetPosition().z() / cm ; 96 G4double energy = secondaryParticleKineticEnergy * MeV; // Hydrogen-1: A = 1, Z = 1 97 HadrontherapyAnalysisManager::GetInstance()->FillFragmentTuple(1, 1.0, energy, posX, posY, posZ); 98 } 99 100 G4String secondaryParticleName = def -> GetParticleName(); 101 //G4cout <<"Particle: " << secondaryParticleName << G4endl; 102 //G4cout <<"Energy: " << secondaryParticleKineticEnergy << G4endl; 103 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance(); 88 104 //There is a bunch of stuff recorded with the energy 0, something should perhaps be done about this. 89 105 if(secondaryParticleName == "proton") { 90 analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV);106 analysis->hydrogenEnergy(secondaryParticleKineticEnergy / MeV); 91 107 } 92 108 if(secondaryParticleName == "deuteron") { 93 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV);109 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/2) / MeV); 94 110 } 95 111 if(secondaryParticleName == "triton") { 96 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV);112 analysis->hydrogenEnergy((secondaryParticleKineticEnergy/3) / MeV); 97 113 } 98 114 if(secondaryParticleName == "alpha") { 99 analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV);115 analysis->heliumEnergy((secondaryParticleKineticEnergy/4) / MeV); 100 116 } 101 117 if(secondaryParticleName == "He3"){ 102 analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV);118 analysis->heliumEnergy((secondaryParticleKineticEnergy/3) / MeV); 103 119 } 104 120 #endif … … 107 123 } 108 124 109 // Electromagnetic and hadronic processes of primary particles in the phantom 110 //setting phantomPhys correctly will break something here fixme 111 if ((aStep -> GetTrack() -> GetTrackID() == 1) && 112 (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") && 113 (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL)) 125 // Electromagnetic and hadronic processes of primary particles in the phantom 126 //setting phantomPhys correctly will break something here fixme 127 if ((aStep -> GetTrack() -> GetTrackID() == 1) && 128 (aStep -> GetTrack() -> GetVolume() -> GetName() == "PhantomPhys") && 129 (aStep -> GetPostStepPoint() -> GetProcessDefinedStep() != NULL)) 130 { 131 G4String process = aStep -> GetPostStepPoint() -> 132 GetProcessDefinedStep() -> GetProcessName(); 133 134 if ((process == "Transportation") || (process == "StepLimiter")) {;} 135 else 136 { 137 if ((process == "msc") || (process == "hLowEIoni") || (process == "hIoni")) 138 { 139 runAction -> AddEMProcess(); 140 } 141 else 114 142 { 115 G4String process = aStep -> GetPostStepPoint() -> 116 GetProcessDefinedStep() -> GetProcessName(); 117 118 if ((process == "Transportation") || (process == "StepLimiter")) {;} 119 else { 120 if ((process == "msc") || (process == "hLowEIoni") || (process == "hIoni")) 121 { 122 runAction -> AddEMProcess(); 123 } 124 else 125 { 126 runAction -> AddHadronicProcess(); 127 128 if ( (process != "LElastic") && (process != "ProtonInelastic") && (process != "hElastic") ) 129 G4cout << "Warning! Unknown proton process: "<< process << G4endl; 130 } 131 } 143 runAction -> AddHadronicProcess(); 144 145 if ( (process != "LElastic") && (process != "ProtonInelastic") && (process != "hElastic") ) 146 G4cout << "Warning! Unknown proton process: "<< process << G4endl; 132 147 } 133 134 // Retrieve information about the secondaries originated in the phantom 135 136 G4SteppingManager* steppingManager = fpSteppingManager; 137 138 // check if it is alive 139 //if(theTrack-> GetTrackStatus() == fAlive) { return; } 140 141 // Retrieve the secondary particles 142 G4TrackVector* fSecondary = steppingManager -> GetfSecondary(); 143 144 for(size_t lp1=0;lp1<(*fSecondary).size(); lp1++) 148 } 149 } 150 151 // Retrieve information about the secondaries originated in the phantom 152 153 G4SteppingManager* steppingManager = fpSteppingManager; 154 155 // check if it is alive 156 //if(theTrack-> GetTrackStatus() == fAlive) { return; } 157 158 // Retrieve the secondary particles 159 G4TrackVector* fSecondary = steppingManager -> GetfSecondary(); 160 161 for(size_t lp1=0;lp1<(*fSecondary).size(); lp1++) 145 162 { 146 147 148 163 G4String volumeName = (*fSecondary)[lp1] -> GetVolume() -> GetName(); 164 165 if (volumeName == "phantomPhys") 149 166 { 150 #ifdef ANALYSIS_USE151 G4String secondaryParticleName = (*fSecondary)[lp1]->GetDefinition() -> GetParticleName();152 G4double secondaryParticleKineticEnergy = (*fSecondary)[lp1] -> GetKineticEnergy();153 154 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance();155 156 157 158 159 if (secondaryParticleName == "gamma")160 161 162 if (secondaryParticleName == "deuteron")163 164 165 if (secondaryParticleName == "triton")166 167 168 if (secondaryParticleName == "alpha")169 170 171 G4double z = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetPDGCharge();172 if (z > 0.)173 174 175 176 177 178 179 167 #ifdef G4ANALYSIS_USE_ROOT 168 G4String secondaryParticleName = (*fSecondary)[lp1]->GetDefinition() -> GetParticleName(); 169 G4double secondaryParticleKineticEnergy = (*fSecondary)[lp1] -> GetKineticEnergy(); 170 171 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance(); 172 173 if (secondaryParticleName == "e-") 174 analysis -> electronEnergyDistribution(secondaryParticleKineticEnergy/MeV); 175 176 if (secondaryParticleName == "gamma") 177 analysis -> gammaEnergyDistribution(secondaryParticleKineticEnergy/MeV); 178 179 if (secondaryParticleName == "deuteron") 180 analysis -> deuteronEnergyDistribution(secondaryParticleKineticEnergy/MeV); 181 182 if (secondaryParticleName == "triton") 183 analysis -> tritonEnergyDistribution(secondaryParticleKineticEnergy/MeV); 184 185 if (secondaryParticleName == "alpha") 186 analysis -> alphaEnergyDistribution(secondaryParticleKineticEnergy/MeV); 187 188 G4double z = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetPDGCharge(); 189 if (z > 0.) 190 { 191 G4int a = (*fSecondary)[lp1]-> GetDynamicParticle() -> GetDefinition() -> GetBaryonNumber(); 192 G4int electronOccupancy = (*fSecondary)[lp1] -> GetDynamicParticle() -> GetTotalOccupancy(); 193 194 // If a generic ion is originated in the detector, its baryonic number, PDG charge, 195 // total number of electrons in the orbitals are stored in a ntuple 196 analysis -> genericIonInformation(a, z, electronOccupancy, secondaryParticleKineticEnergy/MeV); 180 197 } 181 198 #endif
Note: See TracChangeset
for help on using the changeset viewer.