VMC Examples Version 6.6
Loading...
Searching...
No Matches
testTR.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 2015 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 testTR.cxx
11/// \brief The Geant4 VMC example TR 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/// testTR
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_TR_1.C("",kFALSE)'
34/// </pre>
35///
36/// \date 18/12/2015
37/// \author I. Hrivnacova; IPN, Orsay
38
39#include "MCApplication.h"
40#include "PrimaryGenerator.h"
41
42#ifdef USE_GEANT4
43#include "TG4RunConfiguration.h"
44#include "TGeant4.h"
45#endif
46
47#ifdef USE_GEANT3
48#include "TGeant3TGeo.h"
49#endif
50
51#include "TInterpreter.h"
52#include "TROOT.h"
53#include "TThread.h"
54
55#include <iostream>
56#include <string>
57
58namespace
59{
60
61/// Prints usage on error output stream
62void PrintUsage(std::string programName)
63{
64 std::cerr << " Usage: " << std::endl;
65 std::cerr << " " << programName << std::endl;
66#ifdef USE_GEANT4
67 std::cerr << " [-g4g, --g4-geometry]: Geant4 VMC geometry option"
68 << std::endl;
69 std::cerr << " [-g4pl, --g4-physics-list]: Geant4 physics list selection"
70 << std::endl;
71 std::cerr
72 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection"
73 << std::endl;
74 std::cerr << " [-g4m, --g4-macro]: Geant4 macro" << std::endl;
75 std::cerr << " [-g4m2, --g4-macro2]: Geant4 post-init macro "
76 << std::endl;
77 std::cerr << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro"
78 << std::endl;
79#endif
80#ifdef USE_GEANT3
81 std::cerr << " [-g3g, --g3-geometry]: Geant3 geometry option "
82 "(TGeant3,TGeant3TGeo)"
83 << std::endl;
84#endif
85 std::cerr << " [-rm, --root-macro]: Root macro" << std::endl;
86 std::cerr << " [-v, --verbose]: verbose option (yes,no)"
87 << std::endl;
88}
89
90#ifdef USE_GEANT4
91/// Prints selected configuration on output stream (Geant4)
92void PrintG4Configuration(const std::string& programName,
93 const std::string& g4Geometry, const std::string& g4PhysicsList,
94 const std::string& g4SpecialPhysics, const std::string& g4Macro,
95 const std::string& g4Macro2, const std::string& g4VisMacro,
96 const std::string& g4Session, const std::string& rootMacro)
97{
98 std::cout << " Running " << programName << " with options:" << std::endl;
99 std::cout << " --g4-geometry: " << g4Geometry << std::endl;
100 std::cout << " --g4-physics-list: " << g4PhysicsList << std::endl;
101 if (g4SpecialPhysics.size()) {
102 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
103 }
104 if (g4Macro.size()) {
105 std::cout << " --g4-macro: " << g4Macro << std::endl;
106 }
107 if (g4Macro2.size()) {
108 std::cout << " --g4-macro2: " << g4Macro2 << 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 (rootMacro.size()) {
117 std::cout << " --root-macro: " << rootMacro << std::endl;
118 }
119}
120#endif
121
122#ifdef USE_GEANT3
123/// Prints selected configuration on output stream (Geant3)
124void PrintG3Configuration(const std::string& programName,
125 const std::string& g3Geometry, const std::string& rootMacro)
126{
127 std::cout << " Running: " << std::endl;
128 std::cout << " " << programName << std::endl;
129 std::cout << " --g3-geometry: " << g3Geometry << std::endl;
130 if (rootMacro.size()) {
131 std::cout << " --root-macro]: " << rootMacro << std::endl;
132 }
133}
134#endif
135
136} // namespace
137
138/// Application main program
139int main(int argc, char** argv)
140{
141 // Initialize Root threading.
142 // (Multi-threading is triggered automatically if Geant4 was built
143 // in MT mode.)
144#ifdef G4MULTITHREADED
145 ROOT::EnableThreadSafety();
146#endif
147
148 // Process arguments
149 // This code is generic with the exception of the start values and
150 // the program name
151#ifdef USE_GEANT4
152 std::string g4Geometry = "geomRootToGeant4";
153 std::string g4PhysicsList = "emStandard";
154 std::string g4SpecialPhysics = "stepLimiter";
155 std::string g4Macro = "g4config.in";
156 std::string g4Macro2 = "g4config2.in";
157 // std::string g4VisMacro = "g4vis.in";
158 std::string g4VisMacro = "";
159 std::string g4Session = "";
160#endif
161#ifdef USE_GEANT3
162 std::string g3Geometry = "TGeant3TGeo";
163#endif
164 std::string rootMacro = "";
165 std::string verbose = "yes";
166
167 for (Int_t i = 1; i < argc; i = i + 2) {
168 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
169 << std::endl;
170#ifdef USE_GEANT4
171 if (std::string(argv[i]) == "--g4-geometry" ||
172 std::string(argv[i]) == "-g4g")
173 g4Geometry = argv[i + 1];
174 else if (std::string(argv[i]) == "--g4-physics-list" ||
175 std::string(argv[i]) == "-g4pl")
176 g4PhysicsList = argv[i + 1];
177 else if (std::string(argv[i]) == "--g4-special-physics" ||
178 std::string(argv[i]) == "-g4sp")
179 g4SpecialPhysics = argv[i + 1];
180 else if (std::string(argv[i]) == "--g4-macro" ||
181 std::string(argv[i]) == "-g4m")
182 g4Macro = argv[i + 1];
183 else if (std::string(argv[i]) == "--g4-vis-macro" ||
184 std::string(argv[i]) == "-g4vm")
185 g4VisMacro = argv[i + 1];
186 else if (std::string(argv[i]) == "--g4-session" ||
187 std::string(argv[i]) == "-g4s")
188 g4Session = argv[i + 1];
189#endif
190#ifdef USE_GEANT3
191 if (std::string(argv[i]) == "--g3-geometry" ||
192 std::string(argv[i]) == "-g3g")
193 g3Geometry = argv[i + 1];
194#endif
195 else if (std::string(argv[i]) == "--root-macro" ||
196 std::string(argv[i]) == "-rm")
197 rootMacro = argv[i + 1];
198 else if (std::string(argv[i]) == "--verbose" ||
199 std::string(argv[i]) == "-v")
200 verbose = argv[i + 1];
201 else {
202 PrintUsage("testTR");
203 return 1;
204 }
205 }
206
207 if (verbose == "yes") {
208#ifdef USE_GEANT4
209 PrintG4Configuration("testTR", g4Geometry, g4PhysicsList, g4SpecialPhysics,
210 g4Macro, g4Macro2, g4VisMacro, g4Session, rootMacro);
211#endif
212#ifdef USE_GEANT3
213 PrintG3Configuration("testTR", g3Geometry, rootMacro);
214#endif
215 }
216 //
217 // end of code to process arguments
218
219 // Create MC application (thread local)
221 new VMC::TR::MCApplication("ExampleTR", "The exampleTR MC application");
223 appl->SetPrintModulo(10000);
224
225#ifdef USE_GEANT4
226 // RunConfiguration for Geant4
227 TG4RunConfiguration* runConfiguration = new TG4RunConfiguration(
228 g4Geometry, g4PhysicsList, g4SpecialPhysics, false, false);
229
230 // TGeant4
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#endif
240
241#ifdef USE_GEANT3
242 if (g3Geometry == "TGeant3") {
243 new TGeant3("C++ Interface to Geant3");
244 }
245 else if (g3Geometry == "TGeant3TGeo") {
246 new TGeant3TGeo("C++ Interface to Geant3");
247 }
248 else {
249 PrintUsage("testTR");
250 return 1;
251 }
252 gMC->SetProcess("DRAY", 1);
253 gMC->SetProcess("LOSS", 1);
254 gMC->SetProcess("HADR", 0);
255#endif
256
257 // Run example
258 if (!rootMacro.size()) {
259 appl->InitMC("");
260#ifdef USE_GEANT4
261 if (g4Macro2.size()) {
262 // Customise Geant4 setting after initialization:
263 geant4->ProcessGeantMacro("g4config2.in");
264 }
265
266 // Setting Geant4 visualization
267 if (g4VisMacro.size()) {
268 geant4->ProcessGeantMacro(g4VisMacro.data());
269 }
270#endif
271 appl->RunMC(5000);
272 }
273 else {
274 // Run from Root macro
275 gROOT->Macro(rootMacro.data());
276 }
277
278 delete appl;
279}
Implementation of the TVirtualMCApplication.
PrimaryGenerator * GetPrimaryGenerator() const
void SetPrintModulo(Int_t value)
void RunMC(Int_t nofEvents)
void InitMC(const char *setup)
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 testTR.cxx:139