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