VMC Examples Version 6.6
Loading...
Searching...
No Matches
testE01.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 testE01.cxx
11/// \brief The Geant4 VMC example E01 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/// testE01
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/// </pre>
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_E01.C("",kFALSE)'
35///
36/// \date 26/02/2014
37/// \author I. Hrivnacova; IPN, Orsay
38
39#include "Ex01MCApplication.h"
40
41#ifdef USE_GEANT4
42#include "TG4RunConfiguration.h"
43#include "TGeant4.h"
44#endif
45
46#ifdef USE_GEANT3
47#include "TGeant3TGeo.h"
48#endif
49
50#include "TROOT.h"
51
52#include <iostream>
53#include <string>
54
55namespace
56{
57
58/// Prints usage on error output stream
59void PrintUsage(std::string programName)
60{
61 std::cerr << " Usage: " << std::endl;
62 std::cerr << " " << programName << std::endl;
63#ifdef USE_GEANT4
64 std::cerr << " [-g4g, --g4-geometry]: Geant4 VMC geometry option"
65 << std::endl;
66 std::cerr << " [-g4pl, --g4-physics-list]: Geant4 physics list selection"
67 << std::endl;
68 std::cerr
69 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection"
70 << std::endl;
71 std::cerr << " [-g4m, --g4-macro]: Geant4 macro" << std::endl;
72 std::cerr << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro"
73 << std::endl;
74#endif
75#ifdef USE_GEANT3
76 std::cerr << " [-g3g, --g3-geometry]: Geant3 geometry option "
77 "(TGeant3,TGeant3TGeo)"
78 << std::endl;
79#endif
80 std::cerr << " [-rm, --root-macro]: Root macro" << std::endl;
81 std::cerr << " [-v, --verbose]: verbose option (yes,no)"
82 << std::endl;
83}
84
85#ifdef USE_GEANT4
86/// Prints selected configuration on output stream (Geant4)
87void PrintG4Configuration(const std::string& programName,
88 const std::string& g4Geometry, const std::string& g4PhysicsList,
89 const std::string& g4SpecialPhysics, const std::string& g4Macro,
90 const std::string& g4VisMacro, const std::string& g4Session,
91 const std::string& rootMacro)
92{
93 std::cout << " Running " << programName << " with options:" << std::endl;
94 std::cout << " --g4-geometry: " << g4Geometry << std::endl;
95 std::cout << " --g4-physics-list: " << g4PhysicsList << std::endl;
96 if (g4SpecialPhysics.size()) {
97 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
98 }
99 if (g4Macro.size()) {
100 std::cout << " --g4-macro: " << g4Macro << std::endl;
101 }
102 if (g4VisMacro.size()) {
103 std::cout << " --g4-vis-macro: " << g4VisMacro << std::endl;
104 }
105 if (g4Session.size()) {
106 std::cout << " --g4-session: " << g4Session << std::endl;
107 }
108 if (rootMacro.size()) {
109 std::cout << " --root-macro: " << rootMacro << std::endl;
110 }
111}
112#endif
113
114#ifdef USE_GEANT3
115/// Prints selected configuration on output stream (Geant3)
116void PrintG3Configuration(const std::string& programName,
117 const std::string& g3Geometry, const std::string& rootMacro)
118{
119 std::cout << " Running: " << std::endl;
120 std::cout << " " << programName << std::endl;
121 std::cout << " --g3-geometry: " << g3Geometry << std::endl;
122 if (rootMacro.size()) {
123 std::cout << " --root-macro: " << rootMacro << std::endl;
124 }
125}
126#endif
127
128} // namespace
129
130/// Application main program
131int main(int argc, char** argv)
132{
133 // Initialize Root threading.
134 // (Multi-threading is triggered automatically if Geant4 was built
135 // in MT mode.)
136#ifdef G4MULTITHREADED
137 ROOT::EnableThreadSafety();
138#endif
139
140 // Process arguments
141 // This code is generic with the exception of the start values and
142 // the program name
143#ifdef USE_GEANT4
144 std::string g4Geometry = "geomRootToGeant4";
145 std::string g4PhysicsList = "emStandard";
146 std::string g4SpecialPhysics = "stepLimiter";
147 std::string g4Macro = "";
148 std::string g4VisMacro = "";
149 std::string g4Session = "";
150#endif
151#ifdef USE_GEANT3
152 std::string g3Geometry = "TGeant3TGeo";
153#endif
154 std::string rootMacro = "";
155 std::string verbose = "yes";
156
157 for (Int_t i = 1; i < argc; i = i + 2) {
158 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
159 << std::endl;
160#ifdef USE_GEANT4
161 if (std::string(argv[i]) == "--g4-geometry" ||
162 std::string(argv[i]) == "-g4g")
163 g4Geometry = argv[i + 1];
164 else if (std::string(argv[i]) == "--g4-physics-list" ||
165 std::string(argv[i]) == "-g4pl")
166 g4PhysicsList = argv[i + 1];
167 else if (std::string(argv[i]) == "--g4-special-physics" ||
168 std::string(argv[i]) == "-g4sp")
169 g4SpecialPhysics = argv[i + 1];
170 else if (std::string(argv[i]) == "--g4-macro" ||
171 std::string(argv[i]) == "-g4m")
172 g4Macro = argv[i + 1];
173 else if (std::string(argv[i]) == "--g4-vis-macro" ||
174 std::string(argv[i]) == "-g4vm")
175 g4VisMacro = argv[i + 1];
176 else if (std::string(argv[i]) == "--g4-session" ||
177 std::string(argv[i]) == "-g4s")
178 g4Session = argv[i + 1];
179#endif
180#ifdef USE_GEANT3
181 if (std::string(argv[i]) == "--g3-geometry" ||
182 std::string(argv[i]) == "-g3g")
183 g3Geometry = argv[i + 1];
184#endif
185 else if (std::string(argv[i]) == "--root-macro" ||
186 std::string(argv[i]) == "-rm")
187 rootMacro = argv[i + 1];
188 else if (std::string(argv[i]) == "--verbose" ||
189 std::string(argv[i]) == "-v")
190 verbose = argv[i + 1];
191 else {
192 PrintUsage("testE01");
193 return 1;
194 }
195 }
196
197 if (verbose == "yes") {
198#ifdef USE_GEANT4
199 PrintG4Configuration("testE01", g4Geometry, g4PhysicsList, g4SpecialPhysics,
200 g4Macro, g4VisMacro, g4Session, rootMacro);
201#endif
202#ifdef USE_GEANT3
203 PrintG3Configuration("testE01", g3Geometry, rootMacro);
204#endif
205 }
206 //
207 // end of code to process arguments
208
209 // Create MC application (thread local)
210 Ex01MCApplication* appl =
211 new Ex01MCApplication("ExampleE01", "The exampleE01 MC application");
212
213#ifdef USE_GEANT4
214 if (g4Geometry.find("VMC") != std::string::npos) {
215 appl->SetOldGeometry(true);
216 }
217#endif
218#ifdef USE_GEANT3
219 if (g3Geometry == "TGeant3") {
220 appl->SetOldGeometry(true);
221 }
222#endif
223
224#ifdef USE_GEANT4
225 // RunConfiguration for Geant4
226 TG4RunConfiguration* runConfiguration =
227 new TG4RunConfiguration(g4Geometry, g4PhysicsList, g4SpecialPhysics);
228
229 // TGeant4
230 // TO DO: pass g4session here
231 TGeant4* geant4 = new TGeant4(
232 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
233
234 // Customise Geant4 setting
235 // (verbose level, global range cut, ..)
236 if (g4Macro.size()) {
237 geant4->ProcessGeantMacro(g4Macro.data());
238 }
239 // Geant4 configuration tuning (can be run from a macro
240 geant4->ProcessGeantCommand("/mcVerbose/all 1");
241#endif
242
243#ifdef USE_GEANT3
244 TGeant3* geant3 = 0;
245 if (g3Geometry == "TGeant3") {
246 geant3 = new TGeant3("C++ Interface to Geant3");
247 }
248 else if (g3Geometry == "TGeant3TGeo") {
249 geant3 = new TGeant3TGeo("C++ Interface to Geant3");
250 }
251 else {
252 PrintUsage("testE01");
253 return 1;
254 }
255 geant3->SetHADR(0);
256#endif
257
258 // Run example
259 if (!rootMacro.size()) {
260 // Run from this main
261 appl->InitMC("");
262 appl->RunMC(1);
263 }
264 else {
265 // Run from Root macro
266 gROOT->Macro(rootMacro.data());
267 }
268
269 delete appl;
270}
Definition of the Ex01MCApplication class.
Implementation of the TVirtualMCApplication.
void InitMC(const char *setup)
void RunMC(Int_t nofEvents)
void SetOldGeometry(Bool_t oldGeometry=kTRUE)
int main(int argc, char **argv)
Application main program.
Definition testE01.cxx:131
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74