VMC Examples Version 6.6
Loading...
Searching...
No Matches
testMonopole.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 2019 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 testMonopole.cxx
11/// \brief The Geant4 VMC example Monopole test application
12///
13/// The Geant4 VMC test application
14/// with explicitely instantiated TGeant4 and linked
15/// with all libraries.
16///
17/// <pre>
18/// Usage:
19/// testMonopole
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/// [-g4m2, --g4-macro2]: Geant4 macro run after initialization
25/// [-g4vm, --g4-vis-macro]: Geant4 visualization macro
26/// [-rm, --root-macro]: Root macro
27/// [-v, --verbose]: verbose option (yes,no)
28///
29/// Note that the g4* and g3* options are available only when built
30/// with the corresponding VMC_WITH_Geant4 or VMC_WITH_Geant3 option.
31/// Root macro with arguments should be passed within '', eg.
32/// --root-macro 'test_Monopole_1.C("",kFALSE)'
33/// </pre>
34///
35/// \date 06/03/2019
36/// \author I. Hrivnacova; IPN, Orsay
37
38#include "DetectorConstruction.h"
39#include "MCApplication.h"
40
41#ifdef USE_GEANT4
42#include "TG4RunConfiguration.h"
43#include "TGeant4.h"
44#endif
45
46#include "TInterpreter.h"
47#include "TROOT.h"
48#include "TThread.h"
49
50#include <iostream>
51#include <string>
52
53namespace
54{
55
56/// Prints usage on error output stream
57void PrintUsage(std::string programName)
58{
59 std::cerr << " Usage: " << std::endl;
60 std::cerr << " " << programName << std::endl;
61#ifdef USE_GEANT4
62 std::cerr << " [-g4g, --g4-geometry]: Geant4 VMC geometry option"
63 << std::endl;
64 std::cerr << " [-g4pl, --g4-physics-list]: Geant4 physics list selection"
65 << std::endl;
66 std::cerr
67 << " [-g4sp, --g4-special-physics]: Geant4 special physics selection"
68 << std::endl;
69 std::cerr << " [-g4m, --g4-macro]: Geant4 macro" << std::endl;
70 std::cerr << " [-g4m2, --g4-macro2]: Geant4 post-init macro "
71 << std::endl;
72 std::cerr << " [-g4vm, --g4-vis-macro]: Geant4 visualization macro"
73 << std::endl;
74#endif
75 std::cerr << " [-rm, --root-macro]: Root macro" << std::endl;
76 std::cerr << " [-v, --verbose]: verbose option (yes,no)"
77 << std::endl;
78}
79
80#ifdef USE_GEANT4
81/// Prints selected configuration on output stream (Geant4)
82void PrintG4Configuration(const std::string& programName,
83 const std::string& g4Geometry, const std::string& g4PhysicsList,
84 const std::string& g4SpecialPhysics, const std::string& g4Macro,
85 const std::string& g4Macro2, const std::string& g4VisMacro,
86 const std::string& g4Session, const std::string& rootMacro)
87{
88 std::cout << " Running " << programName << " with options:" << std::endl;
89 std::cout << " --g4-geometry: " << g4Geometry << std::endl;
90 std::cout << " --g4-physics-list: " << g4PhysicsList << std::endl;
91 if (g4SpecialPhysics.size()) {
92 std::cout << " --g4-special-physics: " << g4SpecialPhysics << std::endl;
93 }
94 if (g4Macro.size()) {
95 std::cout << " --g4-macro: " << g4Macro << std::endl;
96 }
97 if (g4Macro2.size()) {
98 std::cout << " --g4-macro2: " << g4Macro2 << std::endl;
99 }
100 if (g4VisMacro.size()) {
101 std::cout << " --g4-vis-macro: " << g4VisMacro << std::endl;
102 }
103 if (g4Session.size()) {
104 std::cout << " --g4-session: " << g4Session << std::endl;
105 }
106 if (rootMacro.size()) {
107 std::cout << " --root-macro: " << rootMacro << std::endl;
108 }
109}
110#endif
111
112} // namespace
113
114/// Application main program
115int main(int argc, char** argv)
116{
117 // Initialize Root threading.
118 // (Multi-threading is triggered automatically if Geant4 was built
119 // in MT mode.)
120#ifdef G4MULTITHREADED
121 ROOT::EnableThreadSafety();
122#endif
123
124 // Process arguments
125 // This code is generic with the exception of the start values and
126 // the program name
127#ifdef USE_GEANT4
128 std::string g4Geometry = "geomRootToGeant4";
129 std::string g4PhysicsList = "FTFP_BERT+monopole";
130 std::string g4SpecialPhysics = "stepLimiter";
131 std::string g4Macro = "g4config.in";
132 std::string g4Macro2 = "g4config2.in";
133 // std::string g4VisMacro = "g4vis.in";
134 std::string g4VisMacro = "";
135 std::string g4Session = "";
136#endif
137 std::string rootMacro = "";
138 std::string verbose = "yes";
139
140 for (Int_t i = 1; i < argc; i = i + 2) {
141 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
142 << std::endl;
143#ifdef USE_GEANT4
144 if (std::string(argv[i]) == "--g4-geometry" ||
145 std::string(argv[i]) == "-g4g")
146 g4Geometry = argv[i + 1];
147 else if (std::string(argv[i]) == "--g4-physics-list" ||
148 std::string(argv[i]) == "-g4pl")
149 g4PhysicsList = argv[i + 1];
150 else if (std::string(argv[i]) == "--g4-special-physics" ||
151 std::string(argv[i]) == "-g4sp")
152 g4SpecialPhysics = argv[i + 1];
153 else if (std::string(argv[i]) == "--g4-macro" ||
154 std::string(argv[i]) == "-g4m")
155 g4Macro = argv[i + 1];
156 else if (std::string(argv[i]) == "--g4-vis-macro" ||
157 std::string(argv[i]) == "-g4vm")
158 g4VisMacro = argv[i + 1];
159 else if (std::string(argv[i]) == "--g4-session" ||
160 std::string(argv[i]) == "-g4s")
161 g4Session = argv[i + 1];
162 else if (std::string(argv[i]) == "--root-macro" ||
163 std::string(argv[i]) == "-rm")
164 rootMacro = argv[i + 1];
165#else
166 if (std::string(argv[i]) == "--root-macro" || std::string(argv[i]) == "-rm")
167 rootMacro = argv[i + 1];
168#endif
169 else if (std::string(argv[i]) == "--verbose" ||
170 std::string(argv[i]) == "-v")
171 verbose = argv[i + 1];
172 else {
173 PrintUsage("testMonopole");
174 return 1;
175 }
176 }
177
178 if (verbose == "yes") {
179#ifdef USE_GEANT4
180 PrintG4Configuration("testMonopole", g4Geometry, g4PhysicsList,
181 g4SpecialPhysics, g4Macro, g4Macro2, g4VisMacro, g4Session, rootMacro);
182#endif
183 }
184 //
185 // end of code to process arguments
186
187 // Create MC application (thread local)
189 "ExampleMonopole", "The example Monopole MC MC application");
190
191 // Set detector parameters
192 // /testex/det/setMat G4_Si
193 // /testex/det/setSizeX 10 cm
194 // /testex/det/setSizeYZ 20 cm
195 // /testex/det/setStepSize 0.2 mm
196 // /testex/run/binSize 0.2 mm
199 detector->SetAbsorberMaterial("Si");
200 detector->SetAbsorberSizeX(10);
201 detector->SetAbsorberSizeYZ(20);
202 detector->SetMaxStepSize(0.02);
203 appl->SetBinSize(0.02);
204
205#ifdef USE_GEANT4
206 // RunConfiguration for Geant4
207 TG4RunConfiguration* runConfiguration = new TG4RunConfiguration(
208 g4Geometry, g4PhysicsList, g4SpecialPhysics, false, false);
209
210 // TGeant4
211 TGeant4* geant4 = new TGeant4(
212 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
213
214 // Customise Geant4 setting
215 // (verbose level, global range cut, ..)
216 if (g4Macro.size()) {
217 geant4->ProcessGeantMacro(g4Macro.data());
218 }
219#endif
220
221 // Run example
222 if (!rootMacro.size()) {
223 appl->InitMC("");
224#ifdef USE_GEANT4
225 if (g4Macro2.size()) {
226 // Customise Geant4 setting after initialization:
227 geant4->ProcessGeantMacro("g4config2.in");
228 }
229
230 // Setting Geant4 visualization
231 if (g4VisMacro.size()) {
232 geant4->ProcessGeantMacro(g4VisMacro.data());
233 }
234#endif
235 appl->RunMC(100);
236 }
237 else {
238 // Run from Root macro
239 gROOT->Macro(rootMacro.data());
240 }
241
242 delete appl;
243}
The detector construction (via TGeo )
void SetAbsorberMaterial(const TString &name)
Implementation of the TVirtualMCApplication.
void InitMC(const char *setup)
void SetBinSize(Double_t binSize)
void RunMC(Int_t nofEvents)
DetectorConstruction * GetDetectorConstruction() const
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74
int main(int argc, char **argv)
Application main program.