forked from ANNIEsoft/WCSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WCSim.cc
139 lines (120 loc) · 4.75 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
#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 "G4VisExecutive.hh"
#include "WCSimRandomParameters.hh"
#include <unistd.h>
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;
G4cout<<"Making detector"<<G4endl;
WCSimDetectorConstruction* WCSimdetector = new
WCSimDetectorConstruction(WCSimConfiguration,tuningpars);
runManager->SetUserInitialization(WCSimdetector);
G4cout<<"Making the physics"<<G4endl;
// 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();
G4cout<<"Getting job options from jobOptions.mac"<<G4endl;
// 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");
G4cout<<"Initialising physics factories"<<G4endl;
// Initialize the physics factory to register the selected physics.
physFactory->InitializeList();
runManager->SetUserInitialization(physFactory);
#ifdef G4VIS_USE
// Visualization
G4cout<<"Creating visualisation manager"<<G4endl;
//G4VisManager* visManager = new WCSimVisManager;
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
#endif
G4cout<<"Creating Primary Generator Action"<<G4endl;
// Set user action classes
WCSimPrimaryGeneratorAction* myGeneratorAction = new
WCSimPrimaryGeneratorAction(WCSimdetector);
runManager->SetUserAction(myGeneratorAction);
// read primaries from the mac file - proper way to do it
if(access("macros/primaries_directory.mac", F_OK)!=-1){
UI->ApplyCommand("/control/execute macros/primaries_directory.mac");
}
G4cout<<"Creating Run Action"<<G4endl;
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);
G4cout<<"Creating Event Action"<<G4endl;
runManager->SetUserAction(new WCSimEventAction(myRunAction, WCSimdetector,
myGeneratorAction));
G4cout<<"Creating Tracking Action"<<G4endl;
runManager->SetUserAction(new WCSimTrackingAction);
G4cout<<"Creating Stacking Action"<<G4endl;
runManager->SetUserAction(new WCSimStackingAction(WCSimdetector));
G4cout<<"Creating Stepping Action"<<G4endl;
runManager->SetUserAction(new WCSimSteppingAction);
G4cout<<"Initialising G4 kernel"<<G4endl;
// Initialize G4 kernel
runManager->Initialize();
if (argc==1) // Define UI terminal for interactive mode
{
// Start UI Session
G4UIsession* session = new G4UIterminal(new G4UItcsh);
G4cout<<"Executing WCSim.mac"<<G4endl;
// Visualization Macro
UI->ApplyCommand("/control/execute WCSim.mac");
G4cout<<"Starting session"<<G4endl;
// Start Interactive Mode
session->SessionStart();
delete session;
}
else // Batch mode
{
G4String command = "/control/execute ";
G4String fileName = argv[1];
UI->ApplyCommand(command+fileName);
}
#ifdef G4VIS_USE
delete visManager;
#endif
delete runManager;
return 0;
}