VMC Examples Version 6.6
Loading...
Searching...
No Matches
testE06.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file testE06.cxx
11/// \brief The Geant4 VMC example E06 test application
12///
13/// The Geant4 VMC test application
14/// with explicitely instantiated TGeant3 or TGeant4 and linked
15/// with all libraries.
16///
17/// Usage:
18/// <pre>
19/// testE06
20/// [-g4g, --g4-geometry]: Geant4 VMC geometry option
21/// [-g4pl, --g4-physics-list]: Geant4 physics list selection
22/// [-g4sp, --g4-special-physics]: Geant4 special physics selection
23/// [-g4m, --g4-macro]: Geant4 macro
24/// [-g4m2, --g4-macro2]: Geant4 macro run after initialization
25/// [-g4vm, --g4-vis-macro]: Geant4 visualization macro
26/// [-g3g, --g3-geometry]: Geant3 geometry option
27/// (TGeant3,TGeant3TGeo)
28/// [-rm, --root-macro]: Root macro
29/// [-v, --verbose]: verbose option (yes,no)
30/// </pre>
31///
32/// Note that the g4* and g3* options are available only when built
33/// with the corresponding VMC_WITH_Geant4 or VMC_WITH_Geant3 option.
34/// Root macro with arguments should be passed within '', eg.
35/// --root-macro 'test_E06.C("",kFALSE)'
36///
37/// \date 26/02/2014
38/// \author I. Hrivnacova; IPN, Orsay
39
40#include "Ex06MCApplication.h"
42
43#ifdef USE_GEANT4
44#include "TG4RunConfiguration.h"
45#include "TGeant4.h"
46#endif
47
48#ifdef USE_GEANT3
49#include "TGeant3TGeo.h"
50#endif
51
52#include "TInterpreter.h"
53#include "TROOT.h"
54#include "TThread.h"
55
56#include <iostream>
57#include <string>
58
59namespace
60{
61
62/// Prints usage on error output stream
63void PrintUsage(std::string programName)
64{
65 std::cerr << " Usage: " << std::endl;
66 std::cerr << " " << programName << std::endl;
67#ifdef USE_GEANT4
68 std::cerr << " [-g4g, --g4-geometry]: Geant4 VMC geometry option"
69 << std::endl;
70 std::cerr << " [-g4pl, --g4-physics-list]: Geant4 physics list selection"
71 << std::endl;
72 std::cerr
73 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection"
74 << std::endl;
75 std::cerr << " [-g4m, --g4-macro]: Geant4 macro" << std::endl;
76 std::cerr
77 << " [-g4m2, --g4-macro2]: Geant4 macro run after initialization"
78 << std::endl;
79 std::cerr << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro"
80 << std::endl;
81#endif
82#ifdef USE_GEANT3
83 std::cerr << " [-g3g, --g3-geometry]: Geant3 geometry option "
84 "(TGeant3,TGeant3TGeo)"
85 << std::endl;
86#endif
87 std::cerr << " [-rm, --root-macro]: Root macro" << std::endl;
88 std::cerr << " [-v, --verbose]: verbose option (yes,no)"
89 << std::endl;
90}
91
92#ifdef USE_GEANT4
93/// Prints selected configuration on output stream (Geant4)
94void PrintG4Configuration(const std::string& programName,
95 const std::string& g4Geometry, const std::string& g4PhysicsList,
96 const std::string& g4SpecialPhysics, const std::string& g4Macro,
97 const std::string& g4Macro2, const std::string& g4VisMacro,
98 const std::string& g4Session, const std::string& rootMacro)
99{
100 std::cout << " Running " << programName << " with options:" << std::endl;
101 std::cout << " --g4-geometry: " << g4Geometry << std::endl;
102 std::cout << " --g4-physics-list: " << g4PhysicsList << std::endl;
103 if (g4SpecialPhysics.size()) {
104 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
105 }
106 if (g4Macro.size()) {
107 std::cout << " --g4-macro: " << g4Macro << std::endl;
108 }
109 if (g4Macro2.size()) {
110 std::cout << " --g4-macro2: " << g4Macro2 << std::endl;
111 }
112 if (g4VisMacro.size()) {
113 std::cout << " --g4-vis-macro: " << g4VisMacro << std::endl;
114 }
115 if (g4Session.size()) {
116 std::cout << " --g4-session: " << g4Session << std::endl;
117 }
118 if (rootMacro.size()) {
119 std::cout << " --root-macro: " << rootMacro << std::endl;
120 }
121}
122#endif
123
124#ifdef USE_GEANT3
125/// Prints selected configuration on output stream (Geant3)
126void PrintG3Configuration(const std::string& programName,
127 const std::string& g3Geometry, const std::string& rootMacro)
128{
129 std::cout << " Running: " << std::endl;
130 std::cout << " " << programName << std::endl;
131 std::cout << " --g3-geometry: " << g3Geometry << std::endl;
132 if (rootMacro.size()) {
133 std::cout << " --root-macro]: " << rootMacro << std::endl;
134 }
135}
136#endif
137
138} // namespace
139
140/// Application main program
141int main(int argc, char** argv)
142{
143 // Initialize Root threading.
144 // (Multi-threading is triggered automatically if Geant4 was built
145 // in MT mode.)
146#ifdef G4MULTITHREADED
147 ROOT::EnableThreadSafety();
148#endif
149
150 // Process arguments
151 // This code is generic with the exception of the start values,
152 // the program name and g4Macro2 option (present only in this example)
153#ifdef USE_GEANT4
154 std::string g4Geometry = "geomRootToGeant4";
155 std::string g4PhysicsList = "emStandard+optical";
156 std::string g4SpecialPhysics = "stepLimiter";
157 std::string g4Macro = "g4config.in";
158 std::string g4Macro2 = "g4config2.in";
159 std::string g4VisMacro = "g4vis.in";
160 std::string g4Session = "";
161#endif
162#ifdef USE_GEANT3
163 std::string g3Geometry = "TGeant3TGeo";
164#endif
165 std::string rootMacro = "";
166 std::string verbose = "yes";
167
168 for (Int_t i = 1; i < argc; i = i + 2) {
169 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
170 << std::endl;
171#ifdef USE_GEANT4
172 if (std::string(argv[i]) == "--g4-geometry" ||
173 std::string(argv[i]) == "-g4g")
174 g4Geometry = argv[i + 1];
175 else if (std::string(argv[i]) == "--g4-physics-list" ||
176 std::string(argv[i]) == "-g4pl")
177 g4PhysicsList = argv[i + 1];
178 else if (std::string(argv[i]) == "--g4-special-physics" ||
179 std::string(argv[i]) == "-g4sp")
180 g4SpecialPhysics = argv[i + 1];
181 else if (std::string(argv[i]) == "--g4-macro" ||
182 std::string(argv[i]) == "-g4m")
183 g4Macro = argv[i + 1];
184 else if (std::string(argv[i]) == "--g4-macro2" ||
185 std::string(argv[i]) == "-g4m2")
186 g4Macro2 = argv[i + 1];
187 else if (std::string(argv[i]) == "--g4-vis-macro" ||
188 std::string(argv[i]) == "-g4vm")
189 g4VisMacro = argv[i + 1];
190 else if (std::string(argv[i]) == "--g4-session" ||
191 std::string(argv[i]) == "-g4s")
192 g4Session = argv[i + 1];
193#endif
194#ifdef USE_GEANT3
195 if (std::string(argv[i]) == "--g3-geometry" ||
196 std::string(argv[i]) == "-g3g")
197 g3Geometry = argv[i + 1];
198#endif
199 else if (std::string(argv[i]) == "--root-macro" ||
200 std::string(argv[i]) == "-rm")
201 rootMacro = argv[i + 1];
202 else if (std::string(argv[i]) == "--verbose" ||
203 std::string(argv[i]) == "-v")
204 verbose = argv[i + 1];
205 else {
206 PrintUsage("testE06");
207 return 1;
208 }
209 }
210
211 if (verbose == "yes") {
212#ifdef USE_GEANT4
213 PrintG4Configuration("testE06", g4Geometry, g4PhysicsList, g4SpecialPhysics,
214 g4Macro, g4Macro2, g4VisMacro, g4Session, rootMacro);
215#endif
216#ifdef USE_GEANT3
217 PrintG3Configuration("testE06", g3Geometry, rootMacro);
218#endif
219 }
220 //
221 // end of code to process arguments
222
223 // Create MC application (thread local)
224 Ex06MCApplication* appl =
225 new Ex06MCApplication("ExampleE06", "The exampleE06 MC application");
227 // appl->SetVerboseLevel(3);
228
229#ifdef USE_GEANT4
230 if (g4Geometry.find("VMC") != std::string::npos) {
231 appl->SetOldGeometry(true);
232 }
233#endif
234#ifdef USE_GEANT3
235 if (g3Geometry == "TGeant3") {
236 appl->SetOldGeometry(true);
237 }
238#endif
239
240#ifdef USE_GEANT4
241 // RunConfiguration for Geant4
242 TG4RunConfiguration* runConfiguration =
243 new TG4RunConfiguration(g4Geometry, g4PhysicsList, g4SpecialPhysics);
244
245 // TGeant4
246 // TO DO: pass g4session here
247 TGeant4* geant4 = new TGeant4(
248 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
249
250 // Customise Geant4 setting
251 // (verbose level, global range cut, ..)
252 if (g4Macro.size()) {
253 geant4->ProcessGeantMacro(g4Macro.data());
254 }
255#endif
256
257#ifdef USE_GEANT3
258 TGeant3* geant3 = 0;
259 if (g3Geometry == "TGeant3") {
260 geant3 = new TGeant3("C++ Interface to Geant3");
261 }
262 else if (g3Geometry == "TGeant3TGeo") {
263 geant3 = new TGeant3TGeo("C++ Interface to Geant3");
264 }
265 else {
266 PrintUsage("testE06");
267 return 1;
268 }
269 gMC->SetProcess("CKOV", 1);
270 gMC->SetCut("CUTELE", 10e-06);
271 gMC->SetCut("CUTGAM", 10e-06);
272 geant3->SetSWIT(4, 1000);
273 // reduce printing from GTREVE_ROOT (sets one printing per 1000 tracks)
274#endif
275
276 // Run example
277 if (!rootMacro.size()) {
278 // Initialize MC
279 appl->InitMC("");
280
281 // Activate storing tracks
282 // gMC->SetCollectTracks(kTRUE);
283
284#ifdef USE_GEANT4
285 // Customise Geant4 setting after initialization:
286 // Physics list
287 if (g4Macro.size()) {
288 geant4->ProcessGeantMacro(g4Macro2.data());
289 }
290 // Setting Geant4 visualization
291 if (g4VisMacro.size()) {
292 geant4->ProcessGeantMacro(g4VisMacro.data());
293 }
294#endif
295
296 // Run MC
297 appl->RunMC(5);
298 }
299 else {
300 // Run from Root macro
301 gROOT->Macro(rootMacro.data());
302 }
303
304 delete appl;
305}
Definition of the Ex06MCApplication class.
Definition of the Ex06PrimaryGenerator class.
Implementation of the TVirtualMCApplication.
void RunMC(Int_t nofEvents)
void InitMC(const char *setup)
void SetOldGeometry(Bool_t oldGeometry=kTRUE)
Ex06PrimaryGenerator * GetPrimaryGenerator() const
void SetNofPrimaries(Int_t nofPrimaries)
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74
int main(int argc, char **argv)
Application main program.
Definition testE06.cxx:141