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 | // To obtain the full version visit the pages: http://sites.google.com/site/hadrontherapy/ |
---|
30 | |
---|
31 | // ---------------------------------------------------------------------------- |
---|
32 | // GEANT 4 - Hadrontherapy example |
---|
33 | // ---------------------------------------------------------------------------- |
---|
34 | // Main Authors: |
---|
35 | // |
---|
36 | // G.A.P. Cirrone(a)°, G.Cuttone(a), F.Di Rosa(a), E.Mazzaglia(a), F.Romano(a) |
---|
37 | // |
---|
38 | // Contributor authors: |
---|
39 | // P.Kaitaniemi(d), A.Heikkinen(d), G.Danielsen (d) |
---|
40 | // |
---|
41 | // Past authors: |
---|
42 | // M.G.Pia(b), S.Guatelli(c), G.Russo(a), M.Russo(a), A.Lechner(e) |
---|
43 | // |
---|
44 | // (a) Laboratori Nazionali del Sud |
---|
45 | // of the INFN, Catania, Italy |
---|
46 | // |
---|
47 | // (b) INFN Section of Genova, Italy |
---|
48 | // |
---|
49 | // (c) University of Wallongong, Australia |
---|
50 | // |
---|
51 | // (d) Helsinki Institute of Physics, Helsinki, Finland |
---|
52 | // |
---|
53 | // (e) CERN, (CH) |
---|
54 | // |
---|
55 | // *Corresponding author, email to cirrone@lns.infn.it |
---|
56 | // ---------------------------------------------------------------------------- |
---|
57 | |
---|
58 | #include "G4RunManager.hh" |
---|
59 | #include "G4UImanager.hh" |
---|
60 | #include "G4UIterminal.hh" |
---|
61 | #include "G4UItcsh.hh" |
---|
62 | #include "HadrontherapyEventAction.hh" |
---|
63 | #include "HadrontherapyPhysicsList.hh" |
---|
64 | #include "HadrontherapyDetectorSD.hh" |
---|
65 | #include "HadrontherapyPrimaryGeneratorAction.hh" |
---|
66 | #include "HadrontherapyRunAction.hh" |
---|
67 | #include "HadrontherapyMatrix.hh" |
---|
68 | #include "Randomize.hh" |
---|
69 | #include "G4RunManager.hh" |
---|
70 | #include "G4UImanager.hh" |
---|
71 | #include "G4UImessenger.hh" |
---|
72 | #include "globals.hh" |
---|
73 | #include "HadrontherapySteppingAction.hh" |
---|
74 | #include "HadrontherapyAnalysisManager.hh" |
---|
75 | #include "HadrontherapyGeometryController.hh" |
---|
76 | #include "HadrontherapyGeometryMessenger.hh" |
---|
77 | #include "HadrontherapyInteractionParameters.hh" |
---|
78 | #include "G4ScoringManager.hh" |
---|
79 | #include "IAEAScoreWriter.hh" |
---|
80 | |
---|
81 | #if defined(G4UI_USE_TCSH) |
---|
82 | #include "G4UIterminal.hh" |
---|
83 | #include "G4UItcsh.hh" |
---|
84 | #endif |
---|
85 | |
---|
86 | #ifdef G4UI_USE_XM |
---|
87 | #include "G4UIXm.hh" |
---|
88 | #endif |
---|
89 | |
---|
90 | #ifdef G4VIS_USE |
---|
91 | #include "G4VisExecutive.hh" |
---|
92 | #endif |
---|
93 | |
---|
94 | #ifdef G4UI_USE_QT |
---|
95 | #include "G4UIQt.hh" |
---|
96 | #include "G4Qt.hh" |
---|
97 | #endif |
---|
98 | |
---|
99 | #ifdef G4UI_USE |
---|
100 | #include "G4UIExecutive.hh" |
---|
101 | #endif |
---|
102 | ////////////////////////////////////////////////////////////////////////////////////////////// |
---|
103 | |
---|
104 | int main(int argc ,char ** argv) |
---|
105 | { |
---|
106 | // Set the Random engine |
---|
107 | CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine()); |
---|
108 | |
---|
109 | // Only if an initial random seed is needed |
---|
110 | // G4int seed = time(0); |
---|
111 | // CLHEP::HepRandom::setTheSeed(seed); |
---|
112 | |
---|
113 | G4RunManager* runManager = new G4RunManager; |
---|
114 | // Geometry controller is responsible for instantiating the |
---|
115 | // geometries. All geometry specific setup tasks are now in class |
---|
116 | // HadrontherapyGeometryController. |
---|
117 | HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController(); |
---|
118 | |
---|
119 | // Connect the geometry controller to the G4 user interface |
---|
120 | HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController); |
---|
121 | |
---|
122 | G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager(); |
---|
123 | scoringManager->SetVerboseLevel(1); |
---|
124 | scoringManager->SetScoreWriter(new IAEAScoreWriter()); |
---|
125 | |
---|
126 | // Initialize the default Hadrontherapy geometry |
---|
127 | geometryController->SetGeometry("default"); |
---|
128 | |
---|
129 | // Initialize command based scoring |
---|
130 | G4ScoringManager::GetScoringManager(); |
---|
131 | |
---|
132 | // Initialize the physics |
---|
133 | runManager -> SetUserInitialization(new HadrontherapyPhysicsList()); |
---|
134 | |
---|
135 | // Initialize the primary particles |
---|
136 | HadrontherapyPrimaryGeneratorAction *pPrimaryGenerator = new HadrontherapyPrimaryGeneratorAction(); |
---|
137 | runManager -> SetUserAction(pPrimaryGenerator); |
---|
138 | |
---|
139 | // Optional UserActions: run, event, stepping |
---|
140 | HadrontherapyRunAction* pRunAction = new HadrontherapyRunAction(); |
---|
141 | runManager -> SetUserAction(pRunAction); |
---|
142 | |
---|
143 | HadrontherapyEventAction* pEventAction = new HadrontherapyEventAction(); |
---|
144 | runManager -> SetUserAction(pEventAction); |
---|
145 | |
---|
146 | HadrontherapySteppingAction* steppingAction = new HadrontherapySteppingAction(pRunAction); |
---|
147 | runManager -> SetUserAction(steppingAction); |
---|
148 | |
---|
149 | // Interaction data: stopping powers |
---|
150 | HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true); |
---|
151 | |
---|
152 | #ifdef G4VIS_USE |
---|
153 | // Visualization manager |
---|
154 | G4VisManager* visManager = new G4VisExecutive; |
---|
155 | visManager -> Initialize(); |
---|
156 | #endif |
---|
157 | |
---|
158 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
159 | |
---|
160 | // Batch mode: in this configuration, i.e. when the User explicitly call a macro file, |
---|
161 | // the program run and, at the end, authomatically call the exit state. |
---|
162 | // With a such configuration, it is possible to send in background a simulation |
---|
163 | // and correctly get the output file. |
---|
164 | if (argc!=1) |
---|
165 | { |
---|
166 | G4UIsession* session = 0; |
---|
167 | G4String command = "/control/execute "; |
---|
168 | G4String fileName = argv[1]; |
---|
169 | UI -> ApplyCommand(command+fileName); |
---|
170 | #if defined(G4UI_USE_TCSH) |
---|
171 | session = new G4UIterminal(new G4UItcsh); |
---|
172 | #else |
---|
173 | session = new G4UIterminal(); |
---|
174 | #endif |
---|
175 | // Only if the User Interface is needed! |
---|
176 | //session -> SessionStart(); |
---|
177 | //delete session; |
---|
178 | } |
---|
179 | else // interactive mode : define visualization UI terminal |
---|
180 | { |
---|
181 | G4UIsession* session = 0; |
---|
182 | |
---|
183 | // If the enviroment variable for the TCSH terminal is active, it is used and the |
---|
184 | // defaultMacro.mac file is executed |
---|
185 | #if defined(G4UI_USE_TCSH) |
---|
186 | session = new G4UIterminal(new G4UItcsh); |
---|
187 | UI->ApplyCommand("/control/execute defaultMacro.mac"); |
---|
188 | session -> SessionStart(); |
---|
189 | |
---|
190 | // Alternatively (if G4UI_USE_TCSH is not defined) the program search for the |
---|
191 | // G4UI_USE_QT variable. It starts a graphical user interface based on the QT libraries |
---|
192 | // In the following case the GUI.mac file is also executed |
---|
193 | #elif defined(G4UI_USE_QT) |
---|
194 | session = new G4UIQt(argc,argv); |
---|
195 | UI->ApplyCommand("/control/execute macro/GUI.mac"); |
---|
196 | session -> SessionStart(); |
---|
197 | // As final option, the basic user interface terminal is opened |
---|
198 | #else |
---|
199 | session = new G4UIterminal(); |
---|
200 | |
---|
201 | UI -> ApplyCommand("/control/execute defaultMacro.mac"); |
---|
202 | session -> SessionStart(); |
---|
203 | #endif |
---|
204 | delete session; |
---|
205 | } |
---|
206 | |
---|
207 | // Job termination |
---|
208 | #ifdef G4ANALYSIS_USE_ROOT |
---|
209 | HadrontherapyAnalysisManager::GetInstance() -> flush(); // Finalize the root file |
---|
210 | #endif |
---|
211 | |
---|
212 | #ifdef G4UI_USE |
---|
213 | G4UIExecutive * ui = new G4UIExecutive(argc,argv); |
---|
214 | ui->SessionStart(); |
---|
215 | delete ui; |
---|
216 | #endif |
---|
217 | |
---|
218 | delete geometryMessenger; |
---|
219 | delete geometryController; |
---|
220 | delete pInteraction; |
---|
221 | delete runManager; |
---|
222 | return 0; |
---|
223 | |
---|
224 | } |
---|