VMC Examples Version 6.6
Loading...
Searching...
No Matches
testA01.cxx File Reference

The Geant4 VMC example A01 test application. More...

#include "A01MCApplication.h"
#include "A01PrimaryGenerator.h"
#include "TInterpreter.h"
#include "TROOT.h"
#include "TThread.h"
#include <iostream>
#include <string>
Include dependency graph for testA01.cxx:

Go to the source code of this file.

Functions

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

Detailed Description

The Geant4 VMC example A01 test application.

The Geant4 VMC test application with explicitely instantiated TGeant3 or TGeant4 and linked with all libraries.

Usage: testA01 [-g4g, –g4-geometry]: Geant4 VMC geometry option [-g4pl, –g4-physics-list]: Geant4 physics list selection [-g4sp, –g4-special-physics]: Geant4 special physics selection [-g4m, –g4-macro]: Geant4 macro [-g4vm, –g4-vis-macro]: Geant4 visualization macro [-g3g, –g3-geometry]: Geant3 geometry option (TGeant3,TGeant3TGeo) [-rm, –root-macro]: Root macro [-v, –verbose]: verbose option (yes,no)

Note that the g4* and g3* options are available only when built with the corresponding VMC_WITH_Geant4 or VMC_WITH_Geant3 option. Root macro with arguments should be passed within '', eg. –root-macro 'test_A01.C("",kFALSE)'

Date
26/02/2014
Author
I. Hrivnacova; IPN, Orsay

Definition in file testA01.cxx.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Application main program.

Definition at line 144 of file testA01.cxx.

145{
146 // Initialize Root threading.
147 // (Multi-threading is triggered automatically if Geant4 was built
148 // in MT mode.)
149#ifdef G4MULTITHREADED
150 ROOT::EnableThreadSafety();
151#endif
152
153 // Process arguments
154 // This code is generic with the exception of the start values and
155 // the program name
156#ifdef USE_GEANT4
157 std::string g4Geometry = "geomRootToGeant4";
158 std::string g4PhysicsList = "FTFP_BERT";
159 std::string g4SpecialPhysics = "stepLimiter";
160 std::string g4Macro = "g4config.in";
161 std::string g4VisMacro = "g4vis.in";
162 std::string g4Session = "";
163 std::string g4UserClass = "";
164 std::string g4LocalField = "";
165#endif
166#ifdef USE_GEANT3
167 std::string g3Geometry = "TGeant3TGeo";
168#endif
169 std::string rootMacro = "";
170 std::string verbose = "yes";
171
172 for (Int_t i = 1; i < argc; i = i + 2) {
173 std::cout << "processing " << argv[i] << " with " << argv[i + 1]
174 << std::endl;
175#ifdef USE_GEANT4
176 if (std::string(argv[i]) == "--g4-geometry" ||
177 std::string(argv[i]) == "-g4g")
178 g4Geometry = argv[i + 1];
179 else if (std::string(argv[i]) == "--g4-physics-list" ||
180 std::string(argv[i]) == "-g4pl")
181 g4PhysicsList = argv[i + 1];
182 else if (std::string(argv[i]) == "--g4-special-physics" ||
183 std::string(argv[i]) == "-g4sp")
184 g4SpecialPhysics = argv[i + 1];
185 else if (std::string(argv[i]) == "--g4-macro" ||
186 std::string(argv[i]) == "-g4m")
187 g4Macro = argv[i + 1];
188 else if (std::string(argv[i]) == "--g4-vis-macro" ||
189 std::string(argv[i]) == "-g4vm")
190 g4VisMacro = argv[i + 1];
191 else if (std::string(argv[i]) == "--g4-session" ||
192 std::string(argv[i]) == "-g4s")
193 g4Session = argv[i + 1];
194 // the following option is specific to use of Geant4 dependent classes
195 else if (std::string(argv[i]) == "--g4-user-class" ||
196 std::string(argv[i]) == "-g4uc")
197 g4UserClass = argv[i + 1];
198 else if (std::string(argv[i]) == "--g4-local-field" ||
199 std::string(argv[i]) == "-g4lf")
200 g4LocalField = argv[i + 1];
201#endif
202#ifdef USE_GEANT3
203 if (std::string(argv[i]) == "--g3-geometry" ||
204 std::string(argv[i]) == "-g3g")
205 g3Geometry = argv[i + 1];
206#endif
207 else if (std::string(argv[i]) == "--root-macro" ||
208 std::string(argv[i]) == "-rm")
209 rootMacro = argv[i + 1];
210 else if (std::string(argv[i]) == "--verbose" ||
211 std::string(argv[i]) == "-v")
212 verbose = argv[i + 1];
213 else {
214 PrintUsage("testA01");
215 return 1;
216 }
217 }
218
219 if (verbose == "yes") {
220#ifdef USE_GEANT4
221 PrintG4Configuration("testA01", g4Geometry, g4PhysicsList, g4SpecialPhysics,
222 g4Macro, g4VisMacro, g4Session, g4UserClass, g4LocalField, rootMacro);
223#endif
224#ifdef USE_GEANT3
225 PrintG3Configuration("testA01", g3Geometry, rootMacro);
226#endif
227 }
228 //
229 // end of code to process arguments
230
231 // Create MC application (thread local)
232 A01MCApplication* appl =
233 new A01MCApplication("ExampleA01", "The exampleA01 MC application");
234#ifdef USE_GEANT4
235 // Local magnetic field option
236 if (g4LocalField.size()) {
237 G4cout << "setting local field to true" << G4endl;
238 appl->SetUseLocalMagField(true);
239 }
240
241 // RunConfiguration for Geant4
242 TG4RunConfiguration* runConfiguration = 0;
243 if (!g4UserClass.size()) {
244 runConfiguration =
245 new TG4RunConfiguration(g4Geometry, g4PhysicsList, g4SpecialPhysics);
246 }
247 else if (g4UserClass == "geometry") {
248 runConfiguration = new A01RunConfiguration(g4PhysicsList, g4SpecialPhysics);
249 // Local magnetic field option
250 if (g4LocalField.size()) {
251 static_cast<A01RunConfiguration*>(runConfiguration)
252 ->SetUseLocalMagField(true);
253 }
254 }
255 else {
256 PrintUsage("testA01");
257 return 1;
258 }
259
260 // TGeant4
261 // TO DO: pass g4session here
262 TGeant4* geant4 = new TGeant4(
263 "TGeant4", "The Geant4 Monte Carlo", runConfiguration, argc, argv);
264
265 // Customise Geant4 setting
266 // (verbose level, global range cut, ..)
267 if (g4Macro.size()) {
268 geant4->ProcessGeantMacro(g4Macro.data());
269 }
270#endif
271
272#ifdef USE_GEANT3
273 if (g3Geometry == "TGeant3") {
274 new TGeant3("C++ Interface to Geant3");
275 }
276 else if (g3Geometry == "TGeant3TGeo") {
277 new TGeant3TGeo("C++ Interface to Geant3");
278 }
279 else {
280 PrintUsage("testA01");
281 return 1;
282 }
283 gMC->SetProcess("DRAY", 1);
284 gMC->SetProcess("LOSS", 1);
285 gMC->SetProcess("HADR", 1);
286#endif
287
288 // Run example
289 if (!rootMacro.size()) {
290 // Run from this main
291 appl->GetPrimaryGenerator()->SetRandomize(false);
292 appl->SetWriteStack(true);
293 appl->SetWriteHits(true);
294 appl->InitMC("");
295#ifdef USE_GEANT4
296 // Setting Geant4 visualization
297 if (g4VisMacro.size()) {
298 geant4->ProcessGeantMacro(g4VisMacro.data());
299 }
300#endif
301 appl->RunMC(5);
302 }
303 else {
304 // Run from Root macro
305 gROOT->Macro(rootMacro.data());
306 }
307
308 delete appl;
309}
Implementation of the TVirtualMCApplication.
void SetWriteHits(Bool_t writeHits)
void RunMC(Int_t nofEvents)
void SetWriteStack(Bool_t writeStack)
A01PrimaryGenerator * GetPrimaryGenerator() const
void InitMC(const char *setup)
void SetUseLocalMagField(Bool_t localMagField)
void SetRandomize(Bool_t val)
User Geant4 VMC run configuration.
std::string verbose
Definition testE03c.cxx:75
std::string rootMacro
Definition testE03c.cxx:74