forked from WCSim/WCSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WCSim.cc
146 lines (111 loc) · 4.21 KB
/
WCSim.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
#include "G4ios.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "WCSimDetectorConstruction.hh"
#include "WCSimPhysicsListFactory.hh"
#include "WCSimPhysicsListFactoryMessenger.hh"
#include "WCSimTuningParameters.hh"
#include "WCSimTuningMessenger.hh"
#include "WCSimPrimaryGeneratorAction.hh"
#include "WCSimEventAction.hh"
#include "WCSimRunAction.hh"
#include "WCSimStackingAction.hh"
#include "WCSimTrackingAction.hh"
#include "WCSimSteppingAction.hh"
#include "WCSimVisManager.hh"
#include "WCSimRandomParameters.hh"
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
void file_exists(const char * filename) {
bool exists = access(filename, F_OK) != -1;
if(!exists) {
G4cerr << filename << " not found or inaccessible. Exiting" << G4endl;
exit(-1);
}
}
int main(int argc,char** argv)
{
// Construct the default run manager
G4RunManager* runManager = new G4RunManager;
// get the pointer to the UI manager
G4UImanager* UI = G4UImanager::GetUIpointer();
// Set up the tuning parameters that need to be read before the detector
// construction is done
WCSimTuningParameters* tuningpars = new WCSimTuningParameters();
// Get the tuning parameters
file_exists("macros/tuning_parameters.mac");
UI->ApplyCommand("/control/execute macros/tuning_parameters.mac");
// define random number generator parameters
WCSimRandomParameters *randomparameters = new WCSimRandomParameters();
// UserInitialization classes (mandatory)
enum DetConfiguration {wfm=1,fwm=2};
G4int WCSimConfiguration = fwm;
WCSimDetectorConstruction* WCSimdetector = new
WCSimDetectorConstruction(WCSimConfiguration,tuningpars);
runManager->SetUserInitialization(WCSimdetector);
// Added selectable physics lists 2010-07 by DMW
// Set up the messenger hooks here, initialize the actual list after loading jobOptions.mac
WCSimPhysicsListFactory *physFactory = new WCSimPhysicsListFactory();
// Currently, default physics list is set to FTFP_BERT
// The custom WCSim physics list option is removed in versions later than WCSim1.6.0
file_exists("macros/jobOptions.mac");
UI->ApplyCommand("/control/execute macros/jobOptions.mac");
// Initialize the physics factory to register the selected physics.
physFactory->InitializeList();
runManager->SetUserInitialization(physFactory);
// Visualization
G4VisManager* visManager = new WCSimVisManager;
visManager->Initialize();
// Set user action classes
WCSimPrimaryGeneratorAction* myGeneratorAction = new
WCSimPrimaryGeneratorAction(WCSimdetector);
runManager->SetUserAction(myGeneratorAction);
WCSimRunAction* myRunAction = new WCSimRunAction(WCSimdetector, randomparameters);
//save all the options from WCSimTuningParameters & WCSimPhysicsListFactory
//(set in tuning_parameters.mac & jobOptions*.mac)
tuningpars->SaveOptionsToOutput(myRunAction->GetRootOptions());
physFactory->SaveOptionsToOutput(myRunAction->GetRootOptions());
runManager->SetUserAction(myRunAction);
runManager->SetUserAction(new WCSimEventAction(myRunAction, WCSimdetector,
myGeneratorAction));
runManager->SetUserAction(new WCSimTrackingAction);
runManager->SetUserAction(new WCSimStackingAction(WCSimdetector));
runManager->SetUserAction(new WCSimSteppingAction);
// Initialize G4 kernel
runManager->Initialize();
if (argc==1) // Define UI terminal for interactive mode
{
// Start UI Session
// G4UIsession* session = new G4UIterminal(new G4UItcsh);
//using working example N04 for Qt UI Compatible code
#ifdef G4UI_USE
G4UIExecutive * ui = new G4UIExecutive(argc,argv);
#ifdef G4VIS_USE
// Visualization Macro
UI->ApplyCommand("/control/execute WCSim.mac");
#endif
ui->SessionStart();
delete ui;
#endif
// Start Interactive Mode
//session->SessionStart();
//delete session;
}
else // Batch mode
{
G4String command = "/control/execute ";
G4String fileName = argv[1];
file_exists(fileName);
if(fileName == "vis.mac"){
G4cout << "ERROR: Execute without arg for interactive mode" << G4endl;
//return -1;
}
UI->ApplyCommand(command+fileName);
}
delete visManager;
delete runManager;
return 0;
}