VMC Examples Version 6.6
Loading...
Searching...
No Matches
testE03c.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 testE03c.cxx
11/// \brief The Geant4 VMC example E03c 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/// testE03c
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/// [-r4m, --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_E03c_1.C("",kFALSE)'
34/// </pre>
35///
36/// \date 30/04/2019
37/// Benedikt Volkel, CERN
38
39#include "Ex03PrimaryGenerator.h"
40#include "Ex03cMCApplication.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
60// Define application parameters in global space
61#ifdef USE_GEANT4
62std::string g4Geometry = "geomRoot";
63std::string g4PhysicsList = "FTFP_BERT";
64std::string g4SpecialPhysics = "stepLimiter";
65std::string g4Macro = "g4config.in";
66std::string g4VisMacro = "g4vis.in";
67std::string g4Session = "";
68std::string g4UserClass = "";
69#endif
70#ifdef USE_GEANT3
71std::string g3Geometry = "TGeant3TGeo";
72#endif
73std::string firstEngine = "g3";
74std::string rootMacro = "";
75std::string verbose = "yes";
76
77namespace
78{
79
80/// Prints usage on error output stream
81void PrintUsage(const std::string& programName)
82{
83 std::cerr
84 << "\nUsage:\n"
85 << " " << programName << "\n"
86#ifdef USE_GEANT4
87 << " [-g4g, --g4-geometry]: Geant4 VMC geometry option\n"
88 << " [-g4pl, --g4-physics-list]: Geant4 physics list selection\n"
89 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection\n"
90 << " [-g4m, --g4-macro]: Geant4 macro\n"
91 << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro\n"
92 << " [-g4uc, --g4-user-class]: Geant4 user class \n"
93 << " (geometry, regions, physics-list, "
94 "field)\n"
95#endif
96#ifdef USE_GEANT3
97 << " [-g3g, --g3-geometry]: Geant3 geometry option "
98 "(TGeant3[TGeo])\n"
99#endif
100 << " [-r4m, --root-macro]: Root macro\n"
101 << " [-v, --verbose]: verbose option (yes,no)\n"
102#ifdef USE_MULTI
103 << " [-fe, --first-engine]: first engine (g3,g4)\n"
104#endif
105 << std::endl;
106}
107
108/// Prints selected configuration on output stream (Geant4)
109void PrintConfiguration(const std::string& programName)
110{
111 std::cout << " Running " << programName << " with options:" << std::endl;
112#ifdef USE_GEANT4
113 std::cout << " --g4-geometry: " << g4Geometry << std::endl
114 << " --g4-physics-list: " << g4PhysicsList << std::endl;
115 if (g4SpecialPhysics.size()) {
116 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
117 }
118 if (g4Macro.size()) {
119 std::cout << " --g4-macro: " << g4Macro << std::endl;
120 }
121 if (g4VisMacro.size()) {
122 std::cout << " --g4-vis-macro: " << g4VisMacro << std::endl;
123 }
124 if (g4Session.size()) {
125 std::cout << " --g4-session: " << g4Session << std::endl;
126 }
127 if (g4UserClass.size()) {
128 std::cout << " --g4-user-class: " << g4UserClass << std::endl;
129 }
130#endif
131#ifdef USE_GEANT3
132 std::cout << " --g3-geometry: " << g3Geometry << std::endl;
133#endif
134#ifdef USE_MULTI
135 std::cout << " --first-engine: " << firstEngine << std::endl;
136#endif
137 if (rootMacro.size()) {
138 std::cout << " --root-macro: " << rootMacro << std::endl;
139 }
140}
141
142void CreateGeant4(int argc, char** argv)
143{
144#ifdef USE_GEANT4
145 // RunConfiguration for Geant4
146 TG4RunConfiguration* runConfiguration = 0;
147 if (!g4UserClass.size()) {
148 runConfiguration = new TG4RunConfiguration(
149 g4Geometry, g4PhysicsList, g4SpecialPhysics, false, false);
150 }
151 else if (g4UserClass == "geometry") {
152 runConfiguration =
153 new Ex03RunConfiguration1(g4PhysicsList, g4SpecialPhysics);
154 }
155 else if (g4UserClass == "physics-list") {
156 runConfiguration = new Ex03RunConfiguration2(g4Geometry, g4SpecialPhysics);
157 }
158 else if (g4UserClass == "regions") {
159 runConfiguration =
160 new Ex03RunConfiguration3(g4Geometry, g4PhysicsList, g4SpecialPhysics);
161 }
162 else if (g4UserClass == "field") {
163 runConfiguration = new Ex03RunConfiguration4(
164 g4Geometry, g4PhysicsList, g4SpecialPhysics, false, false);
165 }
166 else {
167 PrintUsage("testE03s");
168 return;
169 }
170
171 // TGeant4
172 TGeant4* geant4 = new TGeant4(
173 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
174
175 // Customise Geant4 setting
176 // (verbose level, global range cut, ..)
177 if (g4Macro.size()) {
178 geant4->ProcessGeantMacro(g4Macro.data());
179 }
180#endif
181}
182
183void CreateGeant3()
184{
185#ifdef USE_GEANT3
186 TGeant3TGeo* geant3 = new TGeant3TGeo("C++ Interface to Geant3");
187 geant3->SetProcess("DRAY", 1);
188 geant3->SetProcess("LOSS", 1);
189 geant3->SetProcess("HADR", 0);
190#endif
191}
192
193} // namespace
194
195/// Application main program
196int main(int argc, char** argv)
197{
198// Initialize Root threading.
199// (Multi-threading is triggered automatically if Geant4 was built
200// in MT mode.)
201#ifdef G4MULTITHREADED
202 ROOT::EnableThreadSafety();
203#endif
204
205 // Process arguments
206 for (Int_t i = 1; i < argc; i = i + 2) {
207 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
208 << std::endl;
209 if (std::string(argv[i]) == "--root-macro" || std::string(argv[i]) == "-rm")
210 rootMacro = argv[i + 1];
211 else if (std::string(argv[i]) == "--verbose" ||
212 std::string(argv[i]) == "-v")
213 verbose = argv[i + 1];
214#ifdef USE_GEANT4
215 else if (std::string(argv[i]) == "--g4-geometry" ||
216 std::string(argv[i]) == "-g4g")
217 g4Geometry = argv[i + 1];
218 else if (std::string(argv[i]) == "--g4-physics-list" ||
219 std::string(argv[i]) == "-g4pl")
220 g4PhysicsList = argv[i + 1];
221 else if (std::string(argv[i]) == "--g4-special-physics" ||
222 std::string(argv[i]) == "-g4sp")
223 g4SpecialPhysics = argv[i + 1];
224 else if (std::string(argv[i]) == "--g4-macro" ||
225 std::string(argv[i]) == "-g4m")
226 g4Macro = argv[i + 1];
227 else if (std::string(argv[i]) == "--g4-vis-macro" ||
228 std::string(argv[i]) == "-g4vm")
229 g4VisMacro = argv[i + 1];
230 else if (std::string(argv[i]) == "--g4-session" ||
231 std::string(argv[i]) == "-g4s")
232 g4Session = argv[i + 1];
233 // the following option is specific to use of Geant4 dependent classes
234 else if (std::string(argv[i]) == "--g4-user-class" ||
235 std::string(argv[i]) == "-g4uc")
236 g4UserClass = argv[i + 1];
237#endif
238#ifdef USE_GEANT3
239 else if (std::string(argv[i]) == "--g3-geometry" ||
240 std::string(argv[i]) == "-g3g")
241 g3Geometry = argv[i + 1];
242#endif
243#ifdef USE_MULTI
244 else if (std::string(argv[i]) == "--first-engine" ||
245 std::string(argv[i]) == "-fe")
246 firstEngine = argv[i + 1];
247#endif
248 else {
249 PrintUsage("testE03c");
250 return 1;
251 }
252 }
253
254 if (verbose == "yes") {
255 PrintConfiguration("testE03c");
256 }
257 //
258 // end of code to process arguments
259
260 Bool_t isMulti = false;
261 Int_t debug = 0;
262#ifdef USE_MULTI
263 isMulti = true;
264 debug = 1;
265#endif
266
267 // Create MC application (thread local)
269 "ExampleE03", "The exampleE03 MC application", isMulti, isMulti);
270 appl->SetDebug(debug);
271
272 if (firstEngine == "g3") {
273 CreateGeant3();
274 CreateGeant4(argc, argv);
275 }
276 else {
277 CreateGeant4(argc, argv);
278 CreateGeant3();
279 }
280
281 if (!rootMacro.size()) {
282 // Run example without Root macro
283#ifdef USE_MULTI
284 appl->InitMC();
285#else
286 appl->InitMC("");
287#endif
288
289 // Setting Geant4 visualization
290 // #ifdef USE_GEANT4
291 // #ifndef USE_MULTI
292 // if (g4VisMacro.size()) {
293 // geant4->ProcessGeantMacro(g4VisMacro.data());
294 // }
295 // #endif
296 // #endif
297 appl->RunMC(5);
298 }
299 else {
300 // Run from Root macro
301 std::cout << "Go to call macro" << std::endl;
302 gROOT->Macro(rootMacro.data());
303 }
304
305 delete appl;
306}
Definition of the Ex03cMCApplication class.
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
User Geant4 VMC run configuration.
Implementation of the TVirtualMCApplication.
void InitMC(const char *setup)
void RunMC(Int_t nofEvents)
void SetDebug(Int_t debug)
Set debug option for multiple run.
std::string firstEngine
Definition testE03c.cxx:73
int main(int argc, char **argv)
Application main program.
Definition testE03c.cxx:196
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74