-
Notifications
You must be signed in to change notification settings - Fork 0
/
BETA.cc
385 lines (323 loc) · 10.9 KB
/
BETA.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UIGAG.hh"
//#include "G4UIQt.hh"
#include "G4UItcsh.hh"
//#include "G4UIXm.hh"
#include "G4ios.hh"
#include "BETADetectorConstruction.hh"
#include "BETAPhysicsList.hh"
#include "BETAPrimaryGeneratorAction.hh"
#include "BETARunAction.hh"
#include "BETAEventAction.hh"
#include "BETAStackingAction.hh"
#include "BETASteppingVerbose.hh"
#include "BETASteppingAction.hh"
#include "Randomize.hh"
#include "TROOT.h"
#include "TRint.h"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#include "getopt.h"
#include <math.h>
#include <string>
#define no_argument 0
#define required_argument 1
#define optional_argument 2
void print_usage();
void print_libs();
void print_cflags();
void print_ldflags();
void print_inc();
void print_version();
void print_grid();
/**
* \mainpage
*
* BETAG4 is a simulation designed for the Spin Asymmetries of the Nucleon Experiment (SANE).
* <img src="http://quarks.temple.edu/~whit/SANE/analysis_main/images/BETAG4/BETA-event1.jpg" alt="BETA Event" width="300px"/>
*
* - \subpage intro
* - \subpage eventgenerators
* - \subpage UIcommands
* - \subpage mainprogram
*
* author Whitney Armstrong (whit@temple.edu)
* <img src="http://quarks.temple.edu/~whit/SANE/analysis_main/images/BETAG4/BETA-top.jpg" alt="Top view of BETA" />
*
*/
/*! \page intro Introduction
In addition to the GEANT4 libraries, BETAG4 relies on having the
<a href="http://quarks.temple.edu/~whit/code/InSANE++/html/">InSANE libraries</a>
*/
/*! \page UIcommands User interface commands
\example para_10k_wiser.mac
\example para_10k_dis.mac
See the <a href="http://quarks.temple.edu/~whit/SANE/analysis_main/betag4_commands/_.html">
user interface commands list </a>
*/
/*! \page eventgenerators Event Generators
-
-
*/
/*! \page mainprogram BETA program execution
-# The seed is set for the Geant4 random numbers.
-# G4VSteppingVerbose created
-# G4RunManager created
-# G4VUserDetectorConstruction (BETADetectorConstruction) created
-# G4VUserPhysicsList (BETAPhysicsList)
-# G4UserRunAction (BETARunAction)
-# G4UserRunAction (BETARunAction)
-# G4VUserPrimaryGeneratorAction (BETAPrimaryGeneratorAction)
-# G4UserEventAction (BETAEventAction)
-# G4UserStackingAction (BETAStackingAction)
-# G4UserSteppingAction (BETASteppingAction)
-# Interactive or script session invoked
*/
/** BETAG4 : Big Electron Telescope Array Geant4 Simulation
*
*/
int main(int argc,char** argv)
{
int run_set = 0;
int seed_set = 0;
bool is_interactive = true;
bool is_interactive_with_macro = false;
std::string theMacro = "";
const struct option longopts[] =
{
{"run", required_argument, 0, 'r'},
{"seed", required_argument, 0, 's'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"macro", required_argument, 0, 'm'},
{"cflags", no_argument, 0, 'c'},
{"ldflags", no_argument, 0, 'd'},
{"int", no_argument, 0, 'i'},
{"grid", no_argument, 0, 'g'},
{0,0,0,0}
};
int index = 0;
int iarg = 0;
opterr = 1; //turn off getopt error message
while(iarg != -1) {
iarg = getopt_long(argc, argv, "vhilcdr:m:s:", longopts, &index);
switch (iarg)
{
case 'r':
std::cout << "run should be set to " << optarg << std::endl;
run_set = atoi(optarg);
break;
case 's':
seed_set = seed_set + atoi(optarg);
std::cout << "seed : " << seed_set << std::endl;
break;
case 'm':
std::cout << "Macro set to " << optarg << std::endl;
theMacro = optarg;
is_interactive = false;
break;
case 'h':
print_usage();
exit(0);
break;
case 'v':
print_version();
exit(0);
break;
case 'l':
print_libs();
break;
case 'c':
print_cflags();
break;
case 'i':
print_inc();
is_interactive_with_macro = true;
break;
case 'd':
print_ldflags();
break;
case 'g':
print_grid();
break;
}
}
std::string theRest = "";
for (int i = optind; i < argc; i++) {
is_interactive = false;
theRest += argv[i];
}
//std::cout << " the rest of the arguments: " << theRest << std::endl;
G4long myseed = 0;
if(seed_set == -1) {
// use a file to increment the seed.
std::ifstream input_file ;
std::ofstream output_file ;
input_file.open ( "seed.txt" );
input_file >> myseed;
input_file.close();
myseed++;
output_file.open ( "seed.txt" ,std::ios::trunc); // this incremtents a number
output_file << myseed ;
output_file.close();
CLHEP::HepRandom::setTheSeed(myseed);
TRandom * rand = InSANERunManager::GetRunManager()->GetRandom();
rand->SetSeed(myseed);
} else if( seed_set == 0 ) {
// Random automatic (time-based) random seeds for each run
G4cout << "*******************" << G4endl;
G4cout << "*** AUTOSEED ON ***" << G4endl;
G4cout << "*******************" << G4endl;
long seeds[2];
time_t systime = time(NULL);
seeds[0] = (long) systime;
seeds[1] = (long) (systime*G4UniformRand());
G4Random::setTheSeeds(seeds);
TRandom * rand = InSANERunManager::GetRunManager()->GetRandom();
//TRandom3 * r3 = dynamic_cast<TRandom3*>(rand);
//if(r3) r3->SetSeed(0);
//else rand->SetSeed(0);
} else {
myseed = seed_set;
CLHEP::HepRandom::setTheSeed(myseed);
TRandom * rand = InSANERunManager::GetRunManager()->GetRandom();
//TRandom3 * r3 = dynamic_cast<TRandom3*>(rand);
//if(r3) r3->SetSeed(myseed);
//else rand->SetSeed(myseed);
}
std::cout << "Geant4 random engine:" << std::endl;
G4Random::showEngineStatus();
std::cout << "ROOT random engine:" << std::endl;
InSANERunManager::GetRunManager()->GetRandom()->Dump();
// User Verbose output class
G4VSteppingVerbose* verbosity = new BETASteppingVerbose;
G4VSteppingVerbose::SetInstance(verbosity);
// Run manager
G4RunManager* runManager = new G4RunManager;
runManager->SetVerboseLevel(0);
// UserInitialization classes - mandatory
G4VUserDetectorConstruction* detector = new BETADetectorConstruction;
runManager->SetUserInitialization(detector);
// Physics List
G4VUserPhysicsList* physics = new BETAPhysicsList;
//G4VModularPhysicsList* physics = new FTFP_BERT;
//physics->RegisterPhysics(new G4StepLimiterPhysics());
runManager->SetUserInitialization(physics);
// visualization manager
#ifdef G4VIS_USE
G4VisManager* visManager = new G4VisExecutive;
visManager->SetVerboseLevel(1);
visManager->Initialize();
#endif
// UserAction classes
G4UserRunAction* run_action = new BETARunAction(run_set);
runManager->SetUserAction(run_action);
G4VUserPrimaryGeneratorAction* gen_action = new BETAPrimaryGeneratorAction;
runManager->SetUserAction(gen_action);
G4UserEventAction* event_action = new BETAEventAction;
runManager->SetUserAction(event_action);
G4UserStackingAction* stacking_action = new BETAStackingAction;
runManager->SetUserAction(stacking_action);
G4UserSteppingAction* stepping_action = new BETASteppingAction;
runManager->SetUserAction(stepping_action);
int fnargs = 2;
char arg0[10];
char arg1[10];
strcpy(arg0,"BETAG4");
strcpy(arg1,"-l");
char * fargs[2] = {arg0,arg1};
//char * fargs[2] = {"BETAG4","-l"};
//TRint * fApp =
new TRint("BETAG4", &fnargs,&fargs[0], NULL, 2);
//std::cout << " o Initializing G4 kernel " << std::endl;
// Initialize G4 kernel
runManager->Initialize();
//std::cout << " o Done initializing G4 kernel " << std::endl;
dynamic_cast<BETAPhysicsList*>(physics)->SetVerbose(0);
// Get the pointer to the User Interface manager
G4UImanager* UI = G4UImanager::GetUIpointer();
if(is_interactive) {
G4UIsession* session = 0;
#ifdef G4UI_USE_TCSH
// session = new G4UIGAG;
session = new G4UIterminal(new G4UItcsh);
// session = new G4UIQt(argc, argv);
#else
session = new G4UIterminal();
#endif
//UI->ApplyCommand("/control/execute vis.mac");
session->SessionStart();
delete session;
} else {
// Batch mode, quit at the end
G4String command = "/control/execute ";
G4String fileName;
if(!theMacro.empty()) {
fileName = theMacro;//argv[1];
} else {
fileName = theRest;//argv[1];
}
//UI->ApplyCommand(command+fileName);
G4UIsession* session = 0;
// UI->ApplyCommand("/control/execute vis.mac");
UI->ApplyCommand(command+fileName);
if(is_interactive_with_macro) {
#ifdef G4UI_USE_TCSH
// session = new G4UIGAG;
session = new G4UIterminal(new G4UItcsh);
// session = new G4UIQt(argc, argv);
#else
session = new G4UIterminal();
#endif
//UI->ApplyCommand("/control/execute vis.mac");
session->SessionStart();
}
if(session) delete session;
}
// 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 !
#ifdef G4VIS_USE
//delete visManager;
#endif
delete runManager;
delete verbosity;
return 0;
}
/*! @defgroup EventGen Event Generator
Event generator
*/
/*! @defgroup Detectors Detectors
Detectors
*/
void print_version(){
//std::cout << "InSANE Version " << InSANE_VERSION_MAJOR << "." << InSANE_VERSION_MINOR << " ";
}
void print_usage(){
std::cout << " BETA [OPTIONS...] [MACRO FILE] " << std::endl;
std::cout << " Giving only the argument [MACRO FILE] runs the macro in batch mode," << std::endl;
std::cout << " otherwise GEANT4 runs in interactive mode." << std::endl;
std::cout << " -m MACRO Executes macro in batch mode." << std::endl;
std::cout << " -i Forces interactive mode after running a macro" << std::endl;
std::cout << " -h prints this help " << std::endl;
//std::cout << "insane-config --libs --cflags --ldflags --inc --grid" << " ";
}
void print_libs(){
//std::cout << InSANE_CXX_LIBS << " ";
}
void print_inc(){
//std::cout << InSANE_CXX_INC_DIR << " ";
}
void print_cflags(){
//std::cout << InSANE_CXX_CFLAGS << " ";
}
void print_ldflags(){
//std::cout << InSANE_CXX_LDFLAGS << " ";
}
void print_grid(){
//std::cout << InSANE_GRID_DATA_DIR << " ";
}