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