Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // ------------------------------------------- << 26 // ---------------------------------------------------------------------------- 27 // GEANT 4 - Hadronthe << 27 // GEANT 4 - Hadrontherapy example 28 // ------------------------------------------- << 28 // ---------------------------------------------------------------------------- >> 29 // >> 30 // MAIN AUTHOR >> 31 // ==================== >> 32 // G.A.P. Cirrone(a)* >> 33 // >> 34 // *Corresponding author, email to pablo.cirrone@lns.infn.it 29 // 35 // 30 // MAIN AU << 36 // ACTUAL CONTRIBUTORS 31 // ========== 37 // ==================== 32 // G.A.P. Cirrone(a)*, L. Pandola(a), << 38 // G.A.P. Cirrone(a), Z. Mei(i), L. Pandola(a), G. Petringa(a), F. Romano (a,g) 33 // *Corresponding author, email t << 34 // 39 // 35 // 40 // 36 // ==========> PAST CONTRIBU << 41 // ==========> PAST CONTRIBUTORS <========== 37 // 42 // 38 // R.Calcagno(a), G.Daniels << 43 // R. Calcagno(a), G.Danielsen (b), F.Di Rosa(a), 39 // S.Guatelli(c), A.Heikkin << 44 // S.Guatelli(c), A.Heikkinen(b), P.Kaitaniemi(b), 40 // A.Lechner(d), S.E.Mazzag << 45 // A.Lechner(d), S.E.Mazzaglia(a), M.G.Pia(e), 41 // M.G.Pia(e), F.Romano(a), << 46 // G.Russo(a,h), M.Russo(a), A. Tramontana (a), 42 // M.Russo(a), A.Tramontana << 47 // A.Varisano(a) 43 // 48 // 44 // (a) Laboratori Nazionali del S 49 // (a) Laboratori Nazionali del Sud of INFN, Catania, Italy 45 // (b) Helsinki Institute of Phys 50 // (b) Helsinki Institute of Physics, Helsinki, Finland 46 // (c) University of Wallongong, 51 // (c) University of Wallongong, Australia 47 // (d) CERN, Geneve, Switzwerland 52 // (d) CERN, Geneve, Switzwerland 48 // (e) INFN Section of Genova, Ge 53 // (e) INFN Section of Genova, Genova, Italy 49 // (f) Physics and Astronomy Depa 54 // (f) Physics and Astronomy Department, Univ. of Catania, Catania, Italy 50 // (g) CNR-IBFM, Italy << 55 // (g) National Physics Laboratory, Teddington, UK 51 // (h) Institute of Applied Elect << 56 // (h) CNR-IBFM, Italy >> 57 // (i) Institute of Applied Electromagnetic Engineering(IAEE) 52 // Huazhong University of Sci 58 // Huazhong University of Science and Technology(HUST), Wuhan, China 53 // 59 // 54 // 60 // 55 // WE 61 // WEB 56 // ====== 62 // =========== 57 // https://twiki.cern.ch/twiki/bin/view/ 63 // https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy 58 // 64 // 59 // ------------------------------------------- 65 // ---------------------------------------------------------------------------- 60 66 61 #include "G4RunManager.hh" 67 #include "G4RunManager.hh" 62 #include "G4UImanager.hh" 68 #include "G4UImanager.hh" 63 #include "G4PhysListFactory.hh" 69 #include "G4PhysListFactory.hh" 64 #include "G4VModularPhysicsList.hh" 70 #include "G4VModularPhysicsList.hh" 65 #include "HadrontherapyEventAction.hh" 71 #include "HadrontherapyEventAction.hh" 66 #include "HadrontherapyPhysicsList.hh" 72 #include "HadrontherapyPhysicsList.hh" 67 #include "HadrontherapyDetectorSD.hh" 73 #include "HadrontherapyDetectorSD.hh" 68 #include "HadrontherapyPrimaryGeneratorAction. 74 #include "HadrontherapyPrimaryGeneratorAction.hh" 69 #include "HadrontherapyRunAction.hh" 75 #include "HadrontherapyRunAction.hh" 70 #include "HadrontherapyMatrix.hh" 76 #include "HadrontherapyMatrix.hh" 71 #include "Randomize.hh" 77 #include "Randomize.hh" 72 78 73 #include "G4UImessenger.hh" 79 #include "G4UImessenger.hh" 74 #include "globals.hh" 80 #include "globals.hh" 75 #include "HadrontherapySteppingAction.hh" 81 #include "HadrontherapySteppingAction.hh" 76 #include "HadrontherapyGeometryController.hh" 82 #include "HadrontherapyGeometryController.hh" 77 #include "HadrontherapyGeometryMessenger.hh" 83 #include "HadrontherapyGeometryMessenger.hh" 78 #include "HadrontherapyInteractionParameters.h 84 #include "HadrontherapyInteractionParameters.hh" 79 #include "HadrontherapyLet.hh" 85 #include "HadrontherapyLet.hh" 80 86 81 #include "G4ScoringManager.hh" 87 #include "G4ScoringManager.hh" 82 #include "G4ParallelWorldPhysics.hh" 88 #include "G4ParallelWorldPhysics.hh" 83 #include <time.h> 89 #include <time.h> 84 #include "G4Timer.hh" 90 #include "G4Timer.hh" 85 #include "G4RunManagerFactory.hh" << 91 >> 92 //************************MT********************* >> 93 #ifdef G4MULTITHREADED >> 94 #include "G4MTRunManager.hh" >> 95 #else >> 96 #include "G4RunManager.hh" >> 97 #endif >> 98 86 #include "HadrontherapyActionInitialization.hh 99 #include "HadrontherapyActionInitialization.hh" 87 100 88 #include "G4VisExecutive.hh" 101 #include "G4VisExecutive.hh" 89 #include "G4UIExecutive.hh" 102 #include "G4UIExecutive.hh" 90 103 91 #include "QBBC.hh" << 92 << 93 ////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////////////////// 94 int main(int argc ,char ** argv) 105 int main(int argc ,char ** argv) 95 { 106 { 96 // Detect interactive mode (if no argument << 107 G4UIExecutive* ui = 0; 97 // << 108 if ( argc == 1 ) { 98 G4UIExecutive* ui = nullptr; << 109 ui = new G4UIExecutive(argc, argv); 99 if ( argc == 1 ) { ui = new G4UIExecutive( << 110 } 100 << 111 101 //Instantiate the G4Timer object, to monit 112 //Instantiate the G4Timer object, to monitor the CPU time spent for 102 //the entire execution 113 //the entire execution 103 G4Timer* theTimer = new G4Timer(); 114 G4Timer* theTimer = new G4Timer(); 104 //Start the benchmark 115 //Start the benchmark 105 theTimer->Start(); 116 theTimer->Start(); 106 117 107 // Set the Random engine 118 // Set the Random engine 108 // The following guarantees random generat 119 // The following guarantees random generation also for different runs 109 // in multithread 120 // in multithread 110 CLHEP::RanluxEngine defaultEngine( 1234567 121 CLHEP::RanluxEngine defaultEngine( 1234567, 4 ); 111 G4Random::setTheEngine( &defaultEngine ); 122 G4Random::setTheEngine( &defaultEngine ); 112 G4int seed = (G4int) time( NULL ); << 123 G4int seed = time( NULL ); 113 G4Random::setTheSeed( seed ); 124 G4Random::setTheSeed( seed ); 114 125 115 // Construct the default run manager << 126 #ifdef G4MULTITHREADED 116 // << 127 117 auto* runManager = G4RunManagerFactory::Cr << 128 G4MTRunManager* runManager = new G4MTRunManager; 118 << 129 #else 119 // Define the number of threads for the si << 130 G4RunManager* runManager = new G4RunManager; 120 G4int nThreads = 4; << 131 #endif 121 runManager->SetNumberOfThreads(nThreads); << 132 122 << 133 // Geometry controller is responsible for instantiating the 123 // Geometry controller is responsible for << 134 // geometries. All geometry specific m tasks are now in class 124 // << 135 // HadrontherapyGeometryController. 125 HadrontherapyGeometryController *geometryC 136 HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); 126 137 127 // Connect the geometry controller to the 138 // Connect the geometry controller to the G4 user interface 128 // << 129 HadrontherapyGeometryMessenger *geometryMe 139 HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); 130 140 131 G4ScoringManager *scoringManager = G4Scori 141 G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); 132 scoringManager->SetVerboseLevel(1); 142 scoringManager->SetVerboseLevel(1); 133 143 134 // Initialize the default Hadrontherapy ge 144 // Initialize the default Hadrontherapy geometry 135 geometryController->SetGeometry("default") 145 geometryController->SetGeometry("default"); 136 146 137 // Initialize the physics 147 // Initialize the physics 138 G4PhysListFactory factory; 148 G4PhysListFactory factory; 139 G4VModularPhysicsList* physicsList = 0; << 149 G4VModularPhysicsList* phys = 0; 140 physicsList = new HadrontherapyPhysicsList << 150 G4String physName = ""; 141 151 142 if (physicsList) << 152 // Physics List name defined via environment variable >> 153 char* path = std::getenv("PHYSLIST"); >> 154 if (path) { physName = G4String(path); } >> 155 >> 156 if(physName != "" && factory.IsReferencePhysList(physName)) >> 157 { >> 158 phys = factory.GetReferencePhysList(physName); >> 159 } >> 160 if (phys) 143 { 161 { 144 G4cout << "Going to register G4Paralle 162 G4cout << "Going to register G4ParallelWorldPhysics" << G4endl; 145 physicsList -> RegisterPhysics(new G4P << 163 phys->RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry")); >> 164 } >> 165 else >> 166 { >> 167 G4cout << "Using HadrontherapyPhysicsList()" << G4endl; >> 168 phys = new HadrontherapyPhysicsList(); 146 } 169 } 147 170 148 // Initialisations of physics 171 // Initialisations of physics 149 runManager->SetUserInitialization(physicsL << 172 runManager->SetUserInitialization(phys); 150 173 151 // Initialisation of the Actions 174 // Initialisation of the Actions 152 runManager->SetUserInitialization(new Hadr 175 runManager->SetUserInitialization(new HadrontherapyActionInitialization); 153 176 154 // Initialize command based scoring 177 // Initialize command based scoring 155 G4ScoringManager::GetScoringManager(); 178 G4ScoringManager::GetScoringManager(); 156 179 157 // Interaction data: stopping powers 180 // Interaction data: stopping powers 158 // << 159 HadrontherapyInteractionParameters* pInter 181 HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true); 160 182 161 // Initialize analysis 183 // Initialize analysis 162 // << 163 HadrontherapyAnalysis* analysis = Hadronth 184 HadrontherapyAnalysis* analysis = HadrontherapyAnalysis::GetInstance(); 164 185 165 186 166 // Initialise the Visualisation << 187 167 // << 188 // Initialise the Visualisation 168 auto visManager = new G4VisExecutive(argc, << 189 G4VisManager* visManager = new G4VisExecutive; 169 visManager -> Initialize(); 190 visManager -> Initialize(); 170 191 171 //** Get the pointer to the User Interface 192 //** Get the pointer to the User Interface manager 172 // << 193 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 173 auto UImanager = G4UImanager::GetUIpointer << 174 194 175 if ( !ui ) { 195 if ( !ui ) { 176 // batch mode 196 // batch mode 177 G4String command = "/control/execute " 197 G4String command = "/control/execute "; 178 G4String fileName = argv[1]; 198 G4String fileName = argv[1]; 179 UImanager->ApplyCommand(command+fileNa 199 UImanager->ApplyCommand(command+fileName); >> 200 180 } 201 } 181 202 182 else { 203 else { 183 UImanager -> ApplyCommand("/control/ma << 204 184 UImanager -> ApplyCommand("/control/ex 205 UImanager -> ApplyCommand("/control/execute macro/defaultMacro.mac"); 185 ui -> SessionStart(); 206 ui -> SessionStart(); 186 delete ui; 207 delete ui; 187 } 208 } 188 delete visManager; 209 delete visManager; 189 210 190 //Stop the benchmark here 211 //Stop the benchmark here 191 theTimer->Stop(); 212 theTimer->Stop(); 192 213 193 G4cout << "The simulation took: " << theTi 214 G4cout << "The simulation took: " << theTimer->GetRealElapsed() << " s to run (real time)" 194 << G4endl; 215 << G4endl; 195 216 196 // Job termination 217 // Job termination 197 // Free the store: user actions, physics_l 218 // Free the store: user actions, physics_list and detector_description are 198 // owned and deleted by the run manager, s 219 // owned and deleted by the run manager, so they should not be deleted 199 // in the main() program ! 220 // in the main() program ! 200 221 201 222 202 if ( HadrontherapyMatrix * pMatrix = H 223 if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() ) 203 { 224 { 204 // pMatrix -> TotalEnergyDeposit(); 225 // pMatrix -> TotalEnergyDeposit(); 205 pMatrix -> StoreDoseFluenceAscii(); 226 pMatrix -> StoreDoseFluenceAscii(); 206 227 207 } 228 } 208 229 209 if (HadrontherapyLet *let = HadrontherapyL 230 if (HadrontherapyLet *let = HadrontherapyLet::GetInstance()) 210 if(let -> doCalculation) 231 if(let -> doCalculation) 211 { 232 { 212 let -> LetOutput(); // Calculate 233 let -> LetOutput(); // Calculate let 213 let -> StoreLetAscii(); // Store i 234 let -> StoreLetAscii(); // Store it 214 } 235 } 215 236 216 delete geometryMessenger; 237 delete geometryMessenger; 217 delete geometryController; 238 delete geometryController; 218 delete pInteraction; 239 delete pInteraction; 219 delete runManager; 240 delete runManager; 220 delete analysis; 241 delete analysis; 221 return 0; 242 return 0; 222 243 223 } 244 } 224 245