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 // This is the *BASIC* version of Hadrontherapy, a Geant4-based application >> 27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy >> 28 // >> 29 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request >> 30 // the *COMPLETE* version of this program, together with its documentation; >> 31 // Hadrontherapy (both basic and full version) are supported by the Italian INFN >> 32 // Institute in the framework of the MC-INFN Group >> 33 // 26 // ------------------------------------------- 34 // ---------------------------------------------------------------------------- 27 // GEANT 4 - Hadronthe << 35 // GEANT 4 - Hadrontherapy example 28 // ------------------------------------------- 36 // ---------------------------------------------------------------------------- >> 37 // Main Authors: >> 38 // >> 39 // R. Calcagno(a), G.A.P. Cirrone(a)*, G.Cuttone(a), F.Romano(a,b), A.Varisano(a) >> 40 // >> 41 // Past authors: >> 42 // F.Di Rosa(a), S.Guatelli(d), A.Lechner(f), S.E.Mazzaglia(a), M.G.Pia(c), G.Russo(a), M.Russo(a), >> 43 // P.Kaitaniemi(e), A.Heikkinen(e), G.Danielsen (e) >> 44 // >> 45 // (a) Laboratori Nazionali del Sud >> 46 // of the INFN, Catania, Italy 29 // 47 // 30 // MAIN AU << 48 // (b) Centro Studi e Ricerche e Museo Storico della Fisica E.Fermi, Roma, Italy 31 // ========== << 49 // 32 // G.A.P. Cirrone(a)*, L. Pandola(a), << 50 // (c) INFN Section of Genova, Italy 33 // *Corresponding author, email t << 51 // 34 // << 52 // (d) University of Wallongong, Australia 35 // << 36 // ==========> PAST CONTRIBU << 37 // << 38 // R.Calcagno(a), G.Daniels << 39 // S.Guatelli(c), A.Heikkin << 40 // A.Lechner(d), S.E.Mazzag << 41 // M.G.Pia(e), F.Romano(a), << 42 // M.Russo(a), A.Tramontana << 43 // << 44 // (a) Laboratori Nazionali del S << 45 // (b) Helsinki Institute of Phys << 46 // (c) University of Wallongong, << 47 // (d) CERN, Geneve, Switzwerland << 48 // (e) INFN Section of Genova, Ge << 49 // (f) Physics and Astronomy Depa << 50 // (g) CNR-IBFM, Italy << 51 // (h) Institute of Applied Elect << 52 // Huazhong University of Sci << 53 // << 54 // << 55 // WE << 56 // ====== << 57 // https://twiki.cern.ch/twiki/bin/view/ << 58 // 53 // >> 54 // (e) Helsinki Institute of Physics, Helsinki, Finland >> 55 // >> 56 // (f) CERN, (CH) >> 57 // >> 58 // *Corresponding author, email to cirrone@lns.infn.it 59 // ------------------------------------------- 59 // ---------------------------------------------------------------------------- 60 60 61 #include "G4RunManager.hh" 61 #include "G4RunManager.hh" 62 #include "G4UImanager.hh" 62 #include "G4UImanager.hh" 63 #include "G4PhysListFactory.hh" 63 #include "G4PhysListFactory.hh" 64 #include "G4VModularPhysicsList.hh" 64 #include "G4VModularPhysicsList.hh" 65 #include "HadrontherapyEventAction.hh" 65 #include "HadrontherapyEventAction.hh" 66 #include "HadrontherapyPhysicsList.hh" 66 #include "HadrontherapyPhysicsList.hh" 67 #include "HadrontherapyDetectorSD.hh" 67 #include "HadrontherapyDetectorSD.hh" 68 #include "HadrontherapyPrimaryGeneratorAction. 68 #include "HadrontherapyPrimaryGeneratorAction.hh" 69 #include "HadrontherapyRunAction.hh" 69 #include "HadrontherapyRunAction.hh" 70 #include "HadrontherapyMatrix.hh" 70 #include "HadrontherapyMatrix.hh" 71 #include "Randomize.hh" << 71 #include "Randomize.hh" 72 << 72 #include "G4RunManager.hh" 73 #include "G4UImessenger.hh" 73 #include "G4UImessenger.hh" 74 #include "globals.hh" 74 #include "globals.hh" 75 #include "HadrontherapySteppingAction.hh" 75 #include "HadrontherapySteppingAction.hh" >> 76 #include "HadrontherapyAnalysisManager.hh" 76 #include "HadrontherapyGeometryController.hh" 77 #include "HadrontherapyGeometryController.hh" 77 #include "HadrontherapyGeometryMessenger.hh" 78 #include "HadrontherapyGeometryMessenger.hh" 78 #include "HadrontherapyInteractionParameters.h 79 #include "HadrontherapyInteractionParameters.hh" 79 #include "HadrontherapyLet.hh" 80 #include "HadrontherapyLet.hh" 80 81 81 #include "G4ScoringManager.hh" 82 #include "G4ScoringManager.hh" 82 #include "G4ParallelWorldPhysics.hh" 83 #include "G4ParallelWorldPhysics.hh" 83 #include <time.h> << 84 #include "G4Timer.hh" << 85 #include "G4RunManagerFactory.hh" << 86 #include "HadrontherapyActionInitialization.hh << 87 84 >> 85 >> 86 >> 87 #ifdef G4VIS_USE 88 #include "G4VisExecutive.hh" 88 #include "G4VisExecutive.hh" 89 #include "G4UIExecutive.hh" << 89 #endif 90 90 91 #include "QBBC.hh" << 91 #ifdef G4UI_USE >> 92 #include "G4UIExecutive.hh" >> 93 #endif 92 94 93 ////////////////////////////////////////////// 95 ////////////////////////////////////////////////////////////////////////////////////////////// >> 96 94 int main(int argc ,char ** argv) 97 int main(int argc ,char ** argv) 95 { 98 { 96 // Detect interactive mode (if no argument << 99 // Set the Random engine 97 // << 100 CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine()); 98 G4UIExecutive* ui = nullptr; << 101 99 if ( argc == 1 ) { ui = new G4UIExecutive( << 102 G4RunManager* runManager = new G4RunManager; 100 << 103 // Geometry controller is responsible for instantiating the 101 //Instantiate the G4Timer object, to monit << 104 // geometries. All geometry specific setup tasks are now in class 102 //the entire execution << 105 // HadrontherapyGeometryController. 103 G4Timer* theTimer = new G4Timer(); << 106 HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); 104 //Start the benchmark << 107 105 theTimer->Start(); << 108 // Connect the geometry controller to the G4 user interface 106 << 109 HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); 107 // Set the Random engine << 110 108 // The following guarantees random generat << 111 G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); 109 // in multithread << 112 scoringManager->SetVerboseLevel(1); 110 CLHEP::RanluxEngine defaultEngine( 1234567 << 113 111 G4Random::setTheEngine( &defaultEngine ); << 114 112 G4int seed = (G4int) time( NULL ); << 115 // Initialize the default Hadrontherapy geometry 113 G4Random::setTheSeed( seed ); << 116 geometryController->SetGeometry("default"); 114 << 117 115 // Construct the default run manager << 118 // Initialize command based scoring 116 // << 119 G4ScoringManager::GetScoringManager(); 117 auto* runManager = G4RunManagerFactory::Cr << 120 118 << 121 // Initialize the physics 119 // Define the number of threads for the si << 122 G4PhysListFactory factory; 120 G4int nThreads = 4; << 123 G4VModularPhysicsList* phys = 0; 121 runManager->SetNumberOfThreads(nThreads); << 124 G4String physName = ""; 122 << 125 123 // Geometry controller is responsible for << 126 // Physics List name defined via environment variable 124 // << 127 char* path = getenv("PHYSLIST"); 125 HadrontherapyGeometryController *geometryC << 128 if (path) { physName = G4String(path); } 126 << 129 127 // Connect the geometry controller to the << 130 if(physName != "" && factory.IsReferencePhysList(physName)) 128 // << 129 HadrontherapyGeometryMessenger *geometryMe << 130 << 131 G4ScoringManager *scoringManager = G4Scori << 132 scoringManager->SetVerboseLevel(1); << 133 << 134 // Initialize the default Hadrontherapy ge << 135 geometryController->SetGeometry("default") << 136 << 137 // Initialize the physics << 138 G4PhysListFactory factory; << 139 G4VModularPhysicsList* physicsList = 0; << 140 physicsList = new HadrontherapyPhysicsList << 141 << 142 if (physicsList) << 143 { 131 { 144 G4cout << "Going to register G4Paralle << 132 phys = factory.GetReferencePhysList(physName); 145 physicsList -> RegisterPhysics(new G4P << 133 } >> 134 if (phys) >> 135 { >> 136 G4cout << "Going to register G4ParallelWorldPhysics" << G4endl; >> 137 phys->RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry")); >> 138 } >> 139 else >> 140 { >> 141 G4cout << "Using HadrontherapyPhysicsList()" << G4endl; >> 142 phys = new HadrontherapyPhysicsList(); 146 } 143 } 147 << 148 // Initialisations of physics << 149 runManager->SetUserInitialization(physicsL << 150 << 151 // Initialisation of the Actions << 152 runManager->SetUserInitialization(new Hadr << 153 << 154 // Initialize command based scoring << 155 G4ScoringManager::GetScoringManager(); << 156 << 157 // Interaction data: stopping powers << 158 // << 159 HadrontherapyInteractionParameters* pInter << 160 << 161 // Initialize analysis << 162 // << 163 HadrontherapyAnalysis* analysis = Hadronth << 164 << 165 144 166 // Initialise the Visualisation << 145 167 // << 146 runManager->SetUserInitialization(phys); 168 auto visManager = new G4VisExecutive(argc, << 147 169 visManager -> Initialize(); << 148 170 << 149 // Initialize the primary particles 171 //** Get the pointer to the User Interface << 150 HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction(); 172 // << 151 runManager -> SetUserAction(pPrimaryGenerator); 173 auto UImanager = G4UImanager::GetUIpointer << 152 174 << 153 // Optional UserActions: run, event, stepping 175 if ( !ui ) { << 154 HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction(); 176 // batch mode << 155 runManager -> SetUserAction(pRunAction); 177 G4String command = "/control/execute " << 156 178 G4String fileName = argv[1]; << 157 HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction(); 179 UImanager->ApplyCommand(command+fileNa << 158 runManager -> SetUserAction(pEventAction); >> 159 >> 160 HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction); >> 161 runManager -> SetUserAction(steppingAction); >> 162 >> 163 // Interaction data: stopping powers >> 164 HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true); >> 165 >> 166 // Initialize analysis >> 167 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::GetInstance(); >> 168 #ifdef G4ANALYSIS_USE_ROOT >> 169 analysis -> book(); >> 170 #endif >> 171 >> 172 #ifdef G4VIS_USE >> 173 // Visualization manager >> 174 G4VisManager* visManager = new G4VisExecutive; >> 175 visManager -> Initialize(); >> 176 #endif >> 177 >> 178 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 179 if (argc!=1) // batch mode >> 180 { >> 181 G4String command = "/control/execute "; >> 182 G4String fileName = argv[1]; >> 183 UImanager->ApplyCommand(command+fileName); 180 } 184 } 181 << 185 else 182 else { << 186 { // interactive mode : define UI session 183 UImanager -> ApplyCommand("/control/ma << 187 184 UImanager -> ApplyCommand("/control/ex << 188 185 ui -> SessionStart(); << 189 #ifdef G4UI_USE 186 delete ui; << 190 G4UIExecutive* ui = new G4UIExecutive(argc, argv); >> 191 #ifdef G4VIS_USE >> 192 if(factory.IsReferencePhysList(physName)) >> 193 { >> 194 UImanager->ApplyCommand("/control/execute defaultMacroWithReferencePhysicsList.mac"); >> 195 } >> 196 else >> 197 { >> 198 UImanager->ApplyCommand("/control/execute defaultMacro.mac"); >> 199 } >> 200 >> 201 #endif >> 202 ui->SessionStart(); >> 203 delete ui; >> 204 #endif 187 } 205 } 188 delete visManager; << 206 189 << 207 // Job termination 190 //Stop the benchmark here << 208 // Store dose & fluence data to ASCII & ROOT files 191 theTimer->Stop(); << 209 if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() ) 192 << 193 G4cout << "The simulation took: " << theTi << 194 << G4endl; << 195 << 196 // Job termination << 197 // Free the store: user actions, physics_l << 198 // owned and deleted by the run manager, s << 199 // in the main() program ! << 200 << 201 << 202 if ( HadrontherapyMatrix * pMatrix = H << 203 { 210 { 204 // pMatrix -> TotalEnergyDeposit(); << 211 pMatrix -> TotalEnergyDeposit(); 205 pMatrix -> StoreDoseFluenceAscii(); << 212 pMatrix -> StoreDoseFluenceAscii(); 206 << 213 #ifdef G4ANALYSIS_USE_ROOT >> 214 pMatrix -> StoreDoseFluenceRoot(); >> 215 #endif 207 } 216 } 208 217 209 if (HadrontherapyLet *let = HadrontherapyL 218 if (HadrontherapyLet *let = HadrontherapyLet::GetInstance()) 210 if(let -> doCalculation) << 219 if(let -> doCalculation) 211 { << 220 { 212 let -> LetOutput(); // Calculate << 221 let -> LetOutput(); // Calculate let 213 let -> StoreLetAscii(); // Store i << 222 let -> StoreLetAscii(); // Store it 214 } << 223 #ifdef G4ANALYSIS_USE_ROOT 215 << 224 let -> StoreLetRoot(); 216 delete geometryMessenger; << 225 #endif 217 delete geometryController; << 226 } 218 delete pInteraction; << 227 219 delete runManager; << 228 220 delete analysis; << 229 #ifdef G4ANALYSIS_USE_ROOT 221 return 0; << 230 if (analysis -> IsTheTFile()) analysis -> flush(); // Finalize & write the root file 222 << 231 #endif >> 232 >> 233 >> 234 #ifdef G4VIS_USE >> 235 delete visManager; >> 236 #endif >> 237 >> 238 >> 239 delete geometryMessenger; >> 240 delete geometryController; >> 241 delete pInteraction; >> 242 delete runManager; >> 243 delete analysis; >> 244 return 0; >> 245 223 } 246 } 224 247