VMC Examples Version 6.8
Loading...
Searching...
No Matches
testE03a.cxx File Reference
#include "Ex03MCApplication.h"
#include "TROOT.h"
#include <iostream>
#include <string>
Include dependency graph for testE03a.cxx:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Application main program.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Application main program.

Definition at line 146 of file testE03a.cxx.

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}
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.
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74