-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebl_1.cc
280 lines (231 loc) · 8.64 KB
/
ebl_1.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "EBLsim.h"
#include "B1DetectorConstruction.hh"
#include "B1ActionInitialization.hh"
#include "G4SystemOfUnits.hh"
#include "getopt.h"
#include "B1OpticalPhysics.hh"
#include "G4OpticalPhysics.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#include "QBBC.hh"
#include "G4UIQt.hh"
#include "G4UIterminal.hh"
#include <qmainwindow.h>
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "G4PhysListFactory.hh"
#include "G4StepLimiterPhysics.hh"
#include "Randomize.hh"
#include "B1ParallelWorldConstruction.hh"
#include "G4ParallelWorldPhysics.hh"
bool fexists(const std::string& filename) {
std::ifstream ifile(filename.c_str());
if( ifile ) return true;
return false;
}
//______________________________________________________________________________
void print_help() {
std::cout << "usage: ebl_1 [options] [macro file] \n";
std::cout << "Options: \n";
std::cout << " --run=#, -r set file \"run\" number\n";
std::cout << " --gui=#, -g set to 1 (default) to use qt gui or\n";
std::cout << " 0 to use command line\n";
std::cout << " --vis=#, -V set to 1 (default) to visualization geometry and events\n";
std::cout << " 0 to turn off visualization\n";
std::cout << " --interactive, -i run in interactive mode (default)\n";
std::cout << " --batch, -b run in batch mode\n";
}
//______________________________________________________________________________
int main(int argc,char** argv)
{
int run_number = 0;
std::string output_file_name = "";
std::string output_tree_name = "";
std::string theRest = "";
bool run_manager_init = false;
bool use_gui = true;
bool use_vis = true;
bool is_interactive = true;
bool has_macro_file = false;
//---------------------------------------------------------------------------
int index = 0;
int iarg = 0;
opterr = 1; //turn off getopt error message
const struct option longopts[] =
{
{"run", required_argument, 0, 'r'},
{"gui", required_argument, 0, 'g'},
{"vis", required_argument, 0, 'V'},
{"interactive", no_argument, 0, 'i'},
{"batch", no_argument, 0, 'b'},
{"output", required_argument, 0, 'o'},
{"tree", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{"init", no_argument, 0, 'I'},
{0,0,0,0}
};
while(iarg != -1) {
iarg = getopt_long(argc, argv, "o:h:g:r:V:ibhI", longopts, &index);
switch (iarg)
{
case 'b':
is_interactive = false;
use_gui = false;
use_vis = false;
break;
case 'i':
is_interactive = true;
break;
case 'V':
if( atoi(optarg) == 0 ){
use_vis = false;
} else {
use_vis = true;
}
break;
case 'r':
run_number = atoi( optarg );
break;
case 'g':
if( atoi(optarg) == 0 ){
use_gui = false;
} else {
use_gui = true;
}
break;
case 't':
output_tree_name = optarg;
break;
case 'I':
run_manager_init = true;
break;
case 'o':
output_file_name = optarg;
if( fexists(output_file_name) ) {
std::cout << "Error : " << output_file_name << " already exist" << std::endl;
exit(EXIT_FAILURE);
}
break;
case 'h':
print_help();
exit(0);
break;
case '?':
print_help();
exit(EXIT_FAILURE);
break;
}
}
// here we assume the last argument is a macro file
if( optind < argc ) {
has_macro_file = true;
}
for (int i = optind; i < argc; i++) {
theRest += argv[i];
}
std::cout << " the rest of the arguments: " << theRest << std::endl;
std::cout << "output : " << output_file_name << std::endl;
std::cout << " tree : " << output_tree_name << std::endl;
//---------------------------------------------------------------------------
// Detect interactive mode (if no arguments) and define UI session
// Note third argument of G4UIExecutive can be ("qt", "xm", "win32", "gag", "tcsh", "csh")
G4UIExecutive* ui = 0;
if( is_interactive || use_gui ) {
if( use_gui ) {
ui = new G4UIExecutive(argc, argv, "qt");
} else {
ui = new G4UIExecutive(argc, argv, "tcsh");
}
}
// Choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);
G4long seed = time(NULL);
CLHEP::HepRandom::setTheSeed(seed);
// Construct the default run manager
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
#else
G4RunManager* runManager = new G4RunManager;
#endif
// Set mandatory initialization classes
//
// Detector construction with parallel world
G4String paraWorldName = "ParallelWorld";
B1DetectorConstruction * realWorld = new B1DetectorConstruction();
B1ParallelWorldConstruction * parallelWorld = new B1ParallelWorldConstruction(paraWorldName);
realWorld->RegisterParallelWorld(parallelWorld);
runManager->SetUserInitialization(realWorld);
// Physics list
G4PhysListFactory factory;
//QGSP_BIC_EMY QGSP_BERT_HP_PEN
G4VModularPhysicsList * physicsList = factory.GetReferencePhysList("QGSP_BIC_LIV");
//G4OpticalPhysics* opticalPhysics = new G4OpticalPhysics();
//physicsList->RegisterPhysics( opticalPhysics );
//opticalPhysics->SetWLSTimeProfile("delta");
//opticalPhysics->SetScintillationYieldFactor(1.0);
//opticalPhysics->SetScintillationExcitationRatio(0.0);
//opticalPhysics->SetMaxNumPhotonsPerStep(100);
//opticalPhysics->SetMaxBetaChangePerStep(10.0);
//opticalPhysics->SetTrackSecondariesFirst(kCerenkov,true);
//opticalPhysics->SetTrackSecondariesFirst(kScintillation,true);
physicsList->RegisterPhysics(new B1OpticalPhysics());
// This is needed to make use of the G4UserLimits applied to logical volumes.
physicsList->RegisterPhysics(new G4StepLimiterPhysics());
// This connects the phyics to the parallel world (and sensitive detectors)
//physicsList->RegisterPhysics(new G4ParallelWorldPhysics(paraWorldName,/*layered_mass=*/true));
//physicsList->ReplacePhysics(new G4IonQMDPhysics());
//physicsList->SetDefaultCutValue(0.005*um);
//G4VModularPhysicsList* physicsList = new QBBC;
physicsList->SetVerboseLevel(1);
runManager->SetUserInitialization(physicsList);
// User action initialization
runManager->SetUserInitialization(new B1ActionInitialization(run_number));
// Initialize G4 kernel
runManager->Initialize();
// Initialize visualization
//
G4VisManager* visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
G4UIQt* qui = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
if (qui) {
qui->GetMainWindow()->setVisible(true);
}
// Process macro or start UI session
// batch mode
if( has_macro_file ) {
G4String command = "/control/execute ";
G4String fileName = argv[optind];
UImanager->ApplyCommand(command+fileName);
} else {
// interactive mode
G4String command = "/control/macroPath ";
G4String mac_dir = EBLSIM_MACRO_DIR;
G4String fileName = "init_default.mac";
std::cout << " executing " << command+mac_dir << std::endl;
UImanager->ApplyCommand(command+mac_dir);
command = "/control/execute ";
if( use_vis ) {
std::cout << " executing " << command+fileName << std::endl;
UImanager->ApplyCommand(command+fileName);
}
}
if( is_interactive ) {
ui->SessionStart();
delete ui;
}
// Job termination
// Free the store: user actions, physics_list and detector_description are
// owned and deleted by the run manager, so they should not be deleted
// in the main() program !
delete visManager;
delete runManager;
}
//______________________________________________________________________________