Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "G4ScoringManager.hh"
81 
82 
83 #ifdef G4VIS_USE
84 #include "G4VisExecutive.hh"
85 #endif
86 
87 #ifdef G4UI_USE
88 #include "G4UIExecutive.hh"
89 #endif
90 
92 
93 int main(int argc ,char ** argv)
94 {
95  // Set the Random engine
97 
98  G4RunManager* runManager = new G4RunManager;
99  // Geometry controller is responsible for instantiating the
100  // geometries. All geometry specific setup tasks are now in class
101  // HadrontherapyGeometryController.
103 
104  // Connect the geometry controller to the G4 user interface
105  HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
106 
108  scoringManager->SetVerboseLevel(1);
109 
110 
111  // Initialize the default Hadrontherapy geometry
112  geometryController->SetGeometry("default");
113 
114  // Initialize command based scoring
116 
117  // Initialize the physics
118  G4PhysListFactory factory;
119  G4VModularPhysicsList* phys = 0;
120  G4String physName = "";
121 
122  // Physics List name defined via environment variable
123  char* path = getenv("PHYSLIST");
124  if (path) { physName = G4String(path); }
125 
126  if(physName != "" && factory.IsReferencePhysList(physName))
127  {
128  phys = factory.GetReferencePhysList(physName);
129  }
130 
131  if(!phys) { phys = new HadrontherapyPhysicsList(); }
132 
133  runManager->SetUserInitialization(phys);
134 
135  // runManager -> SetUserInitialization(new HadrontherapyPhysicsList());
136 
137  // Initialize the primary particles
139  runManager -> SetUserAction(pPrimaryGenerator);
140 
141  // Optional UserActions: run, event, stepping
143  runManager -> SetUserAction(pRunAction);
144 
146  runManager -> SetUserAction(pEventAction);
147 
148  HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction);
149  runManager -> SetUserAction(steppingAction);
150 
151  // Interaction data: stopping powers
153 
154  // Initialize analysis
156 #ifdef G4ANALYSIS_USE_ROOT
157  analysis -> book();
158 #endif
159 
160 #ifdef G4VIS_USE
161  // Visualization manager
162  G4VisManager* visManager = new G4VisExecutive;
163  visManager -> Initialize();
164 #endif
165 
166  G4UImanager* UImanager = G4UImanager::GetUIpointer();
167  if (argc!=1) // batch mode
168  {
169  G4String command = "/control/execute ";
170  G4String fileName = argv[1];
171  UImanager->ApplyCommand(command+fileName);
172  }
173  else
174  { // interactive mode : define UI session
175 
176 
177 #ifdef G4UI_USE
178  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
179 #ifdef G4VIS_USE
180  if(factory.IsReferencePhysList(physName))
181  {
182  UImanager->ApplyCommand("/control/execute defaultMacroWithReferencePhysicsList.mac");
183  }
184  else
185  {
186  UImanager->ApplyCommand("/control/execute defaultMacro.mac");
187  }
188 
189 #endif
190  ui->SessionStart();
191  delete ui;
192 #endif
193  }
194 
195  // Job termination
196  // Store dose & fluence data to ASCII & ROOT files
198  {
199  pMatrix -> TotalEnergyDeposit();
200  pMatrix -> StoreDoseFluenceAscii();
201 #ifdef G4ANALYSIS_USE_ROOT
202  pMatrix -> StoreDoseFluenceRoot();
203 #endif
204  }
205 
206 #ifdef G4ANALYSIS_USE_ROOT
207  if (analysis -> IsTheTFile()) analysis -> flush(); // Finalize & write the root file
208 #endif
209 
210 
211 #ifdef G4VIS_USE
212  delete visManager;
213 #endif
214 
215 
216  delete geometryMessenger;
217  delete geometryController;
218  delete pInteraction;
219  delete runManager;
220  delete analysis;
221  return 0;
222 
223 }