Geant4  10.00.p03
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 // 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 //
34 // ----------------------------------------------------------------------------
35 // GEANT 4 - Hadrontherapy example
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
47 //
48 // (b) Centro Studi e Ricerche e Museo Storico della Fisica E.Fermi, Roma, Italy
49 //
50 // (c) INFN Section of Genova, Italy
51 //
52 // (d) University of Wallongong, Australia
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 // ----------------------------------------------------------------------------
60 
61 #include "G4RunManager.hh"
62 #include "G4UImanager.hh"
63 #include "G4PhysListFactory.hh"
64 #include "G4VModularPhysicsList.hh"
70 #include "HadrontherapyMatrix.hh"
71 #include "Randomize.hh"
72 #include "G4RunManager.hh"
73 #include "G4UImessenger.hh"
74 #include "globals.hh"
80 #include "HadrontherapyLet.hh"
81 
82 #include "G4ScoringManager.hh"
84 
85 
86 
87 #ifdef G4VIS_USE
88 #include "G4VisExecutive.hh"
89 #endif
90 
91 #ifdef G4UI_USE
92 #include "G4UIExecutive.hh"
93 #endif
94 
96 
97 int main(int argc ,char ** argv)
98 {
99  // Set the Random engine
100  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
101 
102  G4RunManager* runManager = new G4RunManager;
103  // Geometry controller is responsible for instantiating the
104  // geometries. All geometry specific setup tasks are now in class
105  // HadrontherapyGeometryController.
107 
108  // Connect the geometry controller to the G4 user interface
109  HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
110 
112  scoringManager->SetVerboseLevel(1);
113 
114 
115  // Initialize the default Hadrontherapy geometry
116  geometryController->SetGeometry("default");
117 
118  // Initialize command based scoring
120 
121  // Initialize the physics
122  G4PhysListFactory factory;
123  G4VModularPhysicsList* phys = 0;
124  G4String physName = "";
125 
126  // Physics List name defined via environment variable
127  char* path = getenv("PHYSLIST");
128  if (path) { physName = G4String(path); }
129 
130  if(physName != "" && factory.IsReferencePhysList(physName))
131  {
132  phys = factory.GetReferencePhysList(physName);
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();
143  }
144 
145 
146  runManager->SetUserInitialization(phys);
147 
148 
149  // Initialize the primary particles
151  runManager -> SetUserAction(pPrimaryGenerator);
152 
153  // Optional UserActions: run, event, stepping
155  runManager -> SetUserAction(pRunAction);
156 
158  runManager -> SetUserAction(pEventAction);
159 
160  HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction);
161  runManager -> SetUserAction(steppingAction);
162 
163  // Interaction data: stopping powers
165 
166  // Initialize analysis
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);
184  }
185  else
186  { // interactive mode : define UI session
187 
188 
189 #ifdef G4UI_USE
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
205  }
206 
207  // Job termination
208  // Store dose & fluence data to ASCII & ROOT files
210  {
211  pMatrix -> TotalEnergyDeposit();
212  pMatrix -> StoreDoseFluenceAscii();
213 #ifdef G4ANALYSIS_USE_ROOT
214  pMatrix -> StoreDoseFluenceRoot();
215 #endif
216  }
217 
219  if(let -> doCalculation)
220  {
221  let -> LetOutput(); // Calculate let
222  let -> StoreLetAscii(); // Store it
223 #ifdef G4ANALYSIS_USE_ROOT
224  let -> StoreLetRoot();
225 #endif
226  }
227 
228 
229 #ifdef G4ANALYSIS_USE_ROOT
230  if (analysis -> IsTheTFile()) analysis -> flush(); // Finalize & write the root file
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 
246 }
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:96
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