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