VMC Examples Version 6.8
Loading...
Searching...
No Matches
testE03a.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 2018 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 testE03.cxx
11/// \brief The Geant4 VMC example E03 test application
12///
13/// The Geant4 VMC test application
14/// with explicitely instantiated TGeant3 or TGeant4 and linked
15/// with all libraries.
16///
17/// <pre>
18/// Usage:
19/// testE03
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/// [-g4vm, --g4-vis-macro]: Geant4 visualization macro
25/// [-a, --use-assemblies]: Use the alternative assembly geometry
26/// [-g3g, --g3-geometry]: Geant3 geometry option
27/// (TGeant3,TGeant3TGeo)
28/// [-rm, --root-macro]: Root macro
29/// [-v, --verbose]: verbose option (yes,no)
30///
31/// Note that the g4* and g3* options are available only when built
32/// with the corresponding VMC_WITH_Geant4 or VMC_WITH_Geant3 option.
33/// Root macro with arguments should be passed within '', eg.
34/// --root-macro 'test_E03_1.C("",kFALSE)'
35/// </pre>
36///
37/// \date 26/02/2014
38/// \author I. Hrivnacova; IPN, Orsay
39
40#include "Ex03MCApplication.h"
41
42#ifdef USE_GEANT4
43#include "Ex03RunConfiguration1.h"
44#include "Ex03RunConfiguration2.h"
45#include "Ex03RunConfiguration3.h"
46#include "Ex03RunConfiguration4.h"
47#include "TG4RunConfiguration.h"
48#include "TGeant4.h"
49#endif
50
51#ifdef USE_GEANT3
52#include "TGeant3TGeo.h"
53#endif
54
55#include "TROOT.h"
56
57#include <iostream>
58#include <string>
59
60namespace
61{
62
63/// Prints usage on error output stream
64void PrintUsage(std::string programName)
65{
66 std::cerr << " Usage: " << std::endl;
67 std::cerr << " " << programName << std::endl;
68#ifdef USE_GEANT4
69 std::cerr << " [-g4g, --g4-geometry]: Geant4 VMC geometry option"
70 << std::endl;
71 std::cerr << " [-g4pl, --g4-physics-list]: Geant4 physics list selection"
72 << std::endl;
73 std::cerr
74 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection"
75 << std::endl;
76 std::cerr << " [-g4m, --g4-macro]: Geant4 macro" << std::endl;
77 std::cerr << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro"
78 << std::endl;
79 std::cerr << " [-a, --use-assemblies]: Use the alternative assembly "
80 "geometry (yes,no)"
81 << std::endl;
82 std::cerr << " [-g4uc, --g4-user-class]: Geant4 user class "
83 << " (geometry, regions, "
84 "physics-list, field)"
85 << std::endl;
86#endif
87#ifdef USE_GEANT3
88 std::cerr << " [-g3g, --g3-geometry]: Geant3 geometry option "
89 "(TGeant3,TGeant3TGeo)"
90 << std::endl;
91#endif
92 std::cerr << " [-rm, --root-macro]: Root macro" << std::endl;
93 std::cerr << " [-v, --verbose]: verbose option (yes,no)"
94 << std::endl;
95}
96
97#ifdef USE_GEANT4
98/// Prints selected configuration on output stream (Geant4)
99void PrintG4Configuration(const std::string& programName,
100 const std::string& g4Geometry, const std::string& g4PhysicsList,
101 const std::string& g4SpecialPhysics, const std::string& g4Macro,
102 const std::string& g4VisMacro, const std::string& g4Session,
103 const std::string& g4UserClass, const std::string& rootMacro)
104{
105 std::cout << " Running " << programName << " with options:" << std::endl;
106 std::cout << " --g4-geometry: " << g4Geometry << std::endl;
107 std::cout << " --g4-physics-list: " << g4PhysicsList << std::endl;
108 if (g4SpecialPhysics.size()) {
109 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
110 }
111 if (g4Macro.size()) {
112 std::cout << " --g4-macro: " << g4Macro << std::endl;
113 }
114 if (g4VisMacro.size()) {
115 std::cout << " --g4-vis-macro: " << g4VisMacro << std::endl;
116 }
117 if (g4Session.size()) {
118 std::cout << " --g4-session: " << g4Session << std::endl;
119 }
120 if (g4UserClass.size()) {
121 std::cout << " --g4-user-class: " << g4UserClass << std::endl;
122 }
123 if (rootMacro.size()) {
124 std::cout << " --root-macro: " << rootMacro << std::endl;
125 }
126}
127#endif
128
129#ifdef USE_GEANT3
130/// Prints selected configuration on output stream (Geant3)
131void PrintG3Configuration(const std::string& programName,
132 const std::string& g3Geometry, const std::string& rootMacro)
133{
134 std::cout << " Running: " << std::endl;
135 std::cout << " " << programName << std::endl;
136 std::cout << " --g3-geometry: " << g3Geometry << std::endl;
137 if (rootMacro.size()) {
138 std::cout << " --root-macro]: " << rootMacro << std::endl;
139 }
140}
141#endif
142
143} // namespace
144
145/// Application main program
146int main(int argc, char** argv)
147{
148 // Initialize Root threading.
149 // (Multi-threading is triggered automatically if Geant4 was built
150 // in MT mode.)
151#ifdef G4MULTITHREADED
152 ROOT::EnableThreadSafety();
153#endif
154
155 // Process arguments
156 // This code is generic with the exception of the start values and
157 // the program name
158#ifdef USE_GEANT4
159 std::string g4Geometry = "geomRootToGeant4";
160 std::string g4PhysicsList = "FTFP_BERT";
161 std::string g4SpecialPhysics = "stepLimiter";
162 std::string g4Macro = "g4config.in";
163 std::string g4VisMacro = "g4vis.in";
164 std::string g4Session = "";
165 std::string g4UserClass = "";
166#endif
167#ifdef USE_GEANT3
168 std::string g3Geometry = "TGeant3TGeo";
169#endif
170 std::string rootMacro = "";
171 std::string verbose = "yes";
172 std::string useAssemblies = "no";
173
174 for (Int_t i = 1; i < argc; i = i + 2) {
175 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
176 << std::endl;
177#ifdef USE_GEANT4
178 if (std::string(argv[i]) == "--g4-geometry" ||
179 std::string(argv[i]) == "-g4g")
180 g4Geometry = argv[i + 1];
181 else if (std::string(argv[i]) == "--g4-physics-list" ||
182 std::string(argv[i]) == "-g4pl")
183 g4PhysicsList = argv[i + 1];
184 else if (std::string(argv[i]) == "--g4-special-physics" ||
185 std::string(argv[i]) == "-g4sp")
186 g4SpecialPhysics = argv[i + 1];
187 else if (std::string(argv[i]) == "--g4-macro" ||
188 std::string(argv[i]) == "-g4m")
189 g4Macro = argv[i + 1];
190 else if (std::string(argv[i]) == "--g4-vis-macro" ||
191 std::string(argv[i]) == "-g4vm")
192 g4VisMacro = argv[i + 1];
193 else if (std::string(argv[i]) == "--g4-session" ||
194 std::string(argv[i]) == "-g4s")
195 g4Session = argv[i + 1];
196 // the following option is specific to use of Geant4 dependent classes
197 else if (std::string(argv[i]) == "--g4-user-class" ||
198 std::string(argv[i]) == "-g4uc")
199 g4UserClass = argv[i + 1];
200#endif
201#ifdef USE_GEANT3
202 if (std::string(argv[i]) == "--g3-geometry" ||
203 std::string(argv[i]) == "-g3g")
204 g3Geometry = argv[i + 1];
205#endif
206 else if (std::string(argv[i]) == "--root-macro" ||
207 std::string(argv[i]) == "-rm")
208 rootMacro = argv[i + 1];
209 else if (std::string(argv[i]) == "--verbose" ||
210 std::string(argv[i]) == "-v")
211 verbose = argv[i + 1];
212 else if (std::string(argv[i]) == "--use-assemblies" ||
213 std::string(argv[i]) == "-a")
214 useAssemblies = argv[i + 1];
215 else {
216 PrintUsage("testE03");
217 return 1;
218 }
219 }
220
221 if (useAssemblies != "yes" && useAssemblies != "no") {
222 PrintUsage("testE03");
223 return 1;
224 }
225
226 if (verbose == "yes") {
227#ifdef USE_GEANT4
228 PrintG4Configuration("testE03", g4Geometry, g4PhysicsList, g4SpecialPhysics,
229 g4Macro, g4VisMacro, g4Session, g4UserClass, rootMacro);
230#endif
231#ifdef USE_GEANT3
232 PrintG3Configuration("testE03", g3Geometry, rootMacro);
233#endif
234 }
235 //
236 // end of code to process arguments
237
238 // Create MC application (thread local)
239 Ex03MCApplication* appl =
240 new Ex03MCApplication("ExampleE03", "The exampleE03 MC application");
241
242 if (useAssemblies == "yes") {
244 }
245
246#ifdef USE_GEANT4
247 if (g4Geometry.find("VMC") != std::string::npos) {
248 appl->SetOldGeometry(true);
249 }
250#endif
251#ifdef USE_GEANT3
252 if (g3Geometry == "TGeant3") {
253 appl->SetOldGeometry(true);
254 }
255#endif
256
257#ifdef USE_GEANT4
258 // RunConfiguration for Geant4
259 TG4RunConfiguration* runConfiguration = 0;
260 if (!g4UserClass.size()) {
261 runConfiguration =
262 new TG4RunConfiguration(g4Geometry, g4PhysicsList, g4SpecialPhysics);
263 }
264 else if (g4UserClass == "geometry") {
265 runConfiguration =
266 new Ex03RunConfiguration1(g4PhysicsList, g4SpecialPhysics);
267 }
268 else if (g4UserClass == "physics-list") {
269 runConfiguration = new Ex03RunConfiguration2(g4Geometry, g4SpecialPhysics);
270 }
271 else if (g4UserClass == "regions") {
272 runConfiguration =
273 new Ex03RunConfiguration3(g4Geometry, g4PhysicsList, g4SpecialPhysics);
274 }
275 else if (g4UserClass == "field") {
276 runConfiguration =
277 new Ex03RunConfiguration4(g4Geometry, g4PhysicsList, g4SpecialPhysics);
278 }
279 else {
280 PrintUsage("testE03");
281 return 1;
282 }
283
284 // TGeant4
285 TGeant4* geant4 = new TGeant4(
286 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
287
288 // Customise Geant4 setting
289 // (verbose level, global range cut, ..)
290 if (g4Macro.size()) {
291 geant4->ProcessGeantMacro(g4Macro.data());
292 }
293#endif
294
295#ifdef USE_GEANT3
296 if (g3Geometry == "TGeant3") {
297 new TGeant3("C++ Interface to Geant3");
298 }
299 else if (g3Geometry == "TGeant3TGeo") {
300 new TGeant3TGeo("C++ Interface to Geant3");
301 }
302 else {
303 PrintUsage("testE03");
304 return 1;
305 }
306 gMC->SetProcess("DRAY", 1);
307 gMC->SetProcess("LOSS", 1);
308 gMC->SetProcess("HADR", 0);
309#endif
310
311 // Run example
312 if (!rootMacro.size()) {
313 appl->InitMC("");
314#ifdef USE_GEANT4
315 // Setting Geant4 visualization
316 if (g4VisMacro.size()) {
317 geant4->ProcessGeantMacro(g4VisMacro.data());
318 }
319#endif
320 appl->RunMC(5);
321 }
322 else {
323 // Run from Root macro
324 gROOT->Macro(rootMacro.data());
325 }
326
327 delete appl;
328}
Definition of the Ex03MCApplication class.
Ex03bMCApplication Ex03MCApplication
Implementation of the TVirtualMCApplication.
void InitMC(const char *setup)
void RunMC(Int_t nofEvents)
void SetOldGeometry(Bool_t oldGeometry=kTRUE)
Ex03DetectorConstruction * GetDetectorConstruction() const
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
int main(int argc, char **argv)
Application main program.
Definition testE03a.cxx:146
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74