Geant4  10.01
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 //
31 // ==========> WEB LINK <==========
32 //
33 // http://www.lns.infn.it/link/Hadrontherapy
34 //
35 // ==========> MAIN AUTHORS <==========
36 //
37 // G.A.P. Cirrone(a)*, F.Romano(a), A. Tramontana (a,f)
38 //
39 // ==========> PAST AUTHORS <==========
40 //
41 // R. Calcagno(a), G.Danielsen (b), F.Di Rosa(a),
42 // S.Guatelli(c), A.Heikkinen(b), P.Kaitaniemi(b),
43 // A.Lechner(d), S.E.Mazzaglia(a), M.G.Pia(e), G.Russo(a),
44 // M.Russo(a), A.Varisano(a)
45 //
46 //
47 // (a) Laboratori Nazionali del Sud of the INFN, Catania, Italy
48 // (b) Helsinki Institute of Physics, Helsinki, Finland
49 // (c) University of Wallongong, Australia
50 // (d) CERN, (CH)
51 // (e) INFN Section of Genova, genova, Italy
52 // (f) Physics and Astronomy Department, Universituy of Catania, Catania, Italy
53 //
54 // *Corresponding author, email to pablo.cirrone@lns.infn.it
55 // ----------------------------------------------------------------------------
56 
57 #include "G4RunManager.hh"
58 #include "G4UImanager.hh"
59 #include "G4PhysListFactory.hh"
60 #include "G4VModularPhysicsList.hh"
66 #include "HadrontherapyMatrix.hh"
67 #include "Randomize.hh"
68 
69 #include "G4UImessenger.hh"
70 #include "globals.hh"
76 #include "HadrontherapyLet.hh"
77 
78 #include "G4ScoringManager.hh"
80 #include <time.h>
81 
82 //************************MT*********************
83 #ifdef G4MULTITHREADED
84 #include "G4MTRunManager.hh"
85 #else
86 #include "G4RunManager.hh"
87 #endif
88 
90 
91 //************************MT*********************
92 
93 #ifdef G4VIS_USE
94 #include "G4VisExecutive.hh"
95 #endif
96 
97 #ifdef G4UI_USE
98 #include "G4UIExecutive.hh"
99 #endif
100 
102 int main(int argc ,char ** argv)
103 {
104  // Set the Random engine
105  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
106 
107  // Only if an initial random seed is needed
108  G4int seed =1414159599;// time(0);
109  CLHEP::HepRandom::setTheSeed(seed);
110  // G4cout << "******************************************************************"<< seed << G4endl;
111 
112  //************************MT*********************
113 #ifdef G4MULTITHREADED
114 
115  G4MTRunManager* runManager = new G4MTRunManager;
116  //runManager->SetNumberOfThreads(2); // Is equal to 2 by default, it can be setted also with the macro command: /run/numberOfThread 2
117 #else
118  G4RunManager* runManager = new G4RunManager;
119 #endif
120 
121  //************************MT*********************
122  // G4RunManager* runManager = new G4RunManager;
123 
124  // Geometry controller is responsible for instantiating the
125  // geometries. All geometry specific setup tasks are now in class
126  // HadrontherapyGeometryController.
128 
129  // Connect the geometry controller to the G4 user interface
130  HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
131 
133  scoringManager->SetVerboseLevel(1);
134 
135 
136  // Initialize the default Hadrontherapy geometry
137  geometryController->SetGeometry("default");
138 
139  // Initialize command based scoring
141 
142  // Initialize the physics
143  G4PhysListFactory factory;
144  G4VModularPhysicsList* phys = 0;
145  G4String physName = "";
146 
147  // Physics List name defined via environment variable
148  char* path = getenv("PHYSLIST");
149  if (path) { physName = G4String(path); }
150 
151  if(physName != "" && factory.IsReferencePhysList(physName))
152  {
153  phys = factory.GetReferencePhysList(physName);
154  }
155  if (phys)
156  {
157  G4cout << "Going to register G4ParallelWorldPhysics" << G4endl;
158  phys->RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry"));
159  }
160  else
161  {
162  G4cout << "Using HadrontherapyPhysicsList()" << G4endl;
163  phys = new HadrontherapyPhysicsList();
164  }
165 
166  runManager->SetUserInitialization(phys);
167 
168  //************************MT
170  //************************MT
171 
172 
173  //************************MT: DA SPOSTARE IN hADRONTHERAPYACTIONiNITIALIZATION.CC*********************
174  /*
175  // Initialize the primary particles
176  HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction();
177  runManager -> SetUserAction(pPrimaryGenerator);
178 
179  // Optional UserActions: run, event, stepping
180  HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction();
181  runManager -> SetUserAction(pRunAction);
182 
183  HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction();
184  runManager -> SetUserAction(pEventAction);
185 
186  HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction);
187  runManager -> SetUserAction(steppingAction);
188  */
189  // Interaction data: stopping powers
191 
192  // Initialize analysis
194 #ifdef G4ANALYSIS_USE_ROOT
195  analysis -> book();
196 #endif
197 
198  // Get the pointer to the visualization manager
199 #ifdef G4VIS_USE
200  G4VisManager* visManager = new G4VisExecutive;
201  visManager -> Initialize();
202 #endif
203 
204  // Get the pointer to the User Interface manager
205  G4UImanager* UImanager = G4UImanager::GetUIpointer();
206 
207  // If no macro file is passed as argument,
208  // the User Interface is called
209  if (argc==1)
210  {
211 #ifdef G4UI_USE
212  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
213 #ifdef G4VIS_USE
214 
215  if(factory.IsReferencePhysList(physName))
216  {
217  UImanager->ApplyCommand("/control/execute macro/defaultMacroWithReferencePhysicsList.mac");
218  }
219  else
220  {
221  UImanager->ApplyCommand("/control/execute macro/defaultMacro.mac");
222  }
223 
224 #endif
225  ui->SessionStart();
226  delete ui;
227 #endif
228  }
229  // Batch mode: the following commands are called when a macro file
230  // is passed as argument
231  else
232  {
233  G4String command = "/control/execute ";
234  G4String fileName = argv[1];
235  UImanager->ApplyCommand(command+fileName);
236  }
237 
238  // Job termination
239  // Store dose & fluence data to ASCII & ROOT files
241  {
242  pMatrix -> TotalEnergyDeposit();
243  pMatrix -> StoreDoseFluenceAscii();
244 #ifdef G4ANALYSIS_USE_ROOT
245 
246  pMatrix -> StoreDoseFluenceRoot();
247 #endif
248  }
249 
251  if(let -> doCalculation)
252  {
253  let -> LetOutput(); // Calculate let
254  let -> StoreLetAscii(); // Store it
255 #ifdef G4ANALYSIS_USE_ROOT
256 
257  let -> StoreLetRoot();
258 #endif
259  }
260 
261 
262 #ifdef G4ANALYSIS_USE_ROOT
263  if (analysis -> IsTheTFile()) analysis -> flush(); // Finalize & write the root file
264 #endif
265 
266 
267 #ifdef G4VIS_USE
268  delete visManager;
269 #endif
270 
271  delete geometryMessenger;
272  delete geometryController;
273  delete pInteraction;
274  delete runManager;
275  delete analysis;
276  return 0;
277 
278 }
int main(int argc, char **argv)
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
static HadrontherapyAnalysisManager * GetInstance()
Get the pointer to the analysis manager.
void RegisterPhysics(G4VPhysicsConstructor *)
static HadrontherapyLet * GetInstance()
void Initialize()
Definition: errprop.cc:101
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
static HadrontherapyMatrix * GetInstance()
Controller for geometry selection.
G4GLOB_DLL std::ostream G4cout
void SetGeometry(G4String)
Select a geometry by name.
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
G4bool IsReferencePhysList(const G4String &)
A class for connecting the simulation to an analysis package.
#define G4endl
Definition: G4ios.hh:61
static G4ScoringManager * GetScoringManager()
void SetVerboseLevel(G4int vl)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432