Geant4 Cross Reference |
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 // ---------------------------------------------------------------------------- 27 // GEANT 4 - Hadrontherapy example 28 // ---------------------------------------------------------------------------- 29 // 30 // MAIN AUTHORS 31 // ==================== 32 // G.A.P. Cirrone(a)*, L. Pandola(a), G. Petringa(a), S.Fattori(a), A.Sciuto(a) 33 // *Corresponding author, email to pablo.cirrone@lns.infn.it 34 // 35 // 36 // ==========> PAST CONTRIBUTORS <========== 37 // 38 // R.Calcagno(a), G.Danielsen (b), F.Di Rosa(a), 39 // S.Guatelli(c), A.Heikkinen(b), P.Kaitaniemi(b), 40 // A.Lechner(d), S.E.Mazzaglia(a), Z. Mei(h), G.Milluzzo(a), 41 // M.G.Pia(e), F.Romano(a), G.Russo(a,g), 42 // M.Russo(a), A.Tramontana (a), A.Varisano(a) 43 // 44 // (a) Laboratori Nazionali del Sud of INFN, Catania, Italy 45 // (b) Helsinki Institute of Physics, Helsinki, Finland 46 // (c) University of Wallongong, Australia 47 // (d) CERN, Geneve, Switzwerland 48 // (e) INFN Section of Genova, Genova, Italy 49 // (f) Physics and Astronomy Department, Univ. of Catania, Catania, Italy 50 // (g) CNR-IBFM, Italy 51 // (h) Institute of Applied Electromagnetic Engineering(IAEE) 52 // Huazhong University of Science and Technology(HUST), Wuhan, China 53 // 54 // 55 // WEB 56 // =========== 57 // https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy 58 // 59 // ---------------------------------------------------------------------------- 60 61 #include "G4RunManager.hh" 62 #include "G4UImanager.hh" 63 #include "G4PhysListFactory.hh" 64 #include "G4VModularPhysicsList.hh" 65 #include "HadrontherapyEventAction.hh" 66 #include "HadrontherapyPhysicsList.hh" 67 #include "HadrontherapyDetectorSD.hh" 68 #include "HadrontherapyPrimaryGeneratorAction.hh" 69 #include "HadrontherapyRunAction.hh" 70 #include "HadrontherapyMatrix.hh" 71 #include "Randomize.hh" 72 73 #include "G4UImessenger.hh" 74 #include "globals.hh" 75 #include "HadrontherapySteppingAction.hh" 76 #include "HadrontherapyGeometryController.hh" 77 #include "HadrontherapyGeometryMessenger.hh" 78 #include "HadrontherapyInteractionParameters.hh" 79 #include "HadrontherapyLet.hh" 80 81 #include "G4ScoringManager.hh" 82 #include "G4ParallelWorldPhysics.hh" 83 #include <time.h> 84 #include "G4Timer.hh" 85 #include "G4RunManagerFactory.hh" 86 #include "HadrontherapyActionInitialization.hh" 87 88 #include "G4VisExecutive.hh" 89 #include "G4UIExecutive.hh" 90 91 #include "QBBC.hh" 92 93 ////////////////////////////////////////////////////////////////////////////////////////////// 94 int main(int argc ,char ** argv) 95 { 96 // Detect interactive mode (if no arguments) and define UI session 97 // 98 G4UIExecutive* ui = nullptr; 99 if ( argc == 1 ) { ui = new G4UIExecutive(argc, argv); } 100 101 //Instantiate the G4Timer object, to monitor the CPU time spent for 102 //the entire execution 103 G4Timer* theTimer = new G4Timer(); 104 //Start the benchmark 105 theTimer->Start(); 106 107 // Set the Random engine 108 // The following guarantees random generation also for different runs 109 // in multithread 110 CLHEP::RanluxEngine defaultEngine( 1234567, 4 ); 111 G4Random::setTheEngine( &defaultEngine ); 112 G4int seed = (G4int) time( NULL ); 113 G4Random::setTheSeed( seed ); 114 115 // Construct the default run manager 116 // 117 auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default); 118 119 // Define the number of threads for the simulation runs 120 G4int nThreads = 4; 121 runManager->SetNumberOfThreads(nThreads); 122 123 // Geometry controller is responsible for instantiating the geometries. 124 // 125 HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); 126 127 // Connect the geometry controller to the G4 user interface 128 // 129 HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); 130 131 G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); 132 scoringManager->SetVerboseLevel(1); 133 134 // Initialize the default Hadrontherapy geometry 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 { 144 G4cout << "Going to register G4ParallelWorldPhysics" << G4endl; 145 physicsList -> RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry")); 146 } 147 148 // Initialisations of physics 149 runManager->SetUserInitialization(physicsList); 150 151 // Initialisation of the Actions 152 runManager->SetUserInitialization(new HadrontherapyActionInitialization); 153 154 // Initialize command based scoring 155 G4ScoringManager::GetScoringManager(); 156 157 // Interaction data: stopping powers 158 // 159 HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true); 160 161 // Initialize analysis 162 // 163 HadrontherapyAnalysis* analysis = HadrontherapyAnalysis::GetInstance(); 164 165 166 // Initialise the Visualisation 167 // 168 auto visManager = new G4VisExecutive(argc, argv); 169 visManager -> Initialize(); 170 171 //** Get the pointer to the User Interface manager 172 // 173 auto UImanager = G4UImanager::GetUIpointer(); 174 175 if ( !ui ) { 176 // batch mode 177 G4String command = "/control/execute "; 178 G4String fileName = argv[1]; 179 UImanager->ApplyCommand(command+fileName); 180 } 181 182 else { 183 UImanager -> ApplyCommand("/control/macroPath macro"); 184 UImanager -> ApplyCommand("/control/execute macro/defaultMacro.mac"); 185 ui -> SessionStart(); 186 delete ui; 187 } 188 delete visManager; 189 190 //Stop the benchmark here 191 theTimer->Stop(); 192 193 G4cout << "The simulation took: " << theTimer->GetRealElapsed() << " s to run (real time)" 194 << G4endl; 195 196 // Job termination 197 // Free the store: user actions, physics_list and detector_description are 198 // owned and deleted by the run manager, so they should not be deleted 199 // in the main() program ! 200 201 202 if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() ) 203 { 204 // pMatrix -> TotalEnergyDeposit(); 205 pMatrix -> StoreDoseFluenceAscii(); 206 207 } 208 209 if (HadrontherapyLet *let = HadrontherapyLet::GetInstance()) 210 if(let -> doCalculation) 211 { 212 let -> LetOutput(); // Calculate let 213 let -> StoreLetAscii(); // Store it 214 } 215 216 delete geometryMessenger; 217 delete geometryController; 218 delete pInteraction; 219 delete runManager; 220 delete analysis; 221 return 0; 222 223 } 224