-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathG4simu.cc
178 lines (139 loc) · 4.05 KB
/
G4simu.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
#include <string>
#include <sstream>
#include <unistd.h>
#include <G4RunManager.hh>
#include <G4UImanager.hh>
#include <G4UIterminal.hh>
#include <G4UItcsh.hh>
#include <G4VisExecutive.hh>
#include <G4GeneralParticleSource.hh>
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "PrimaryGeneratorAction.hh"
#include "AnalysisManager.hh"
#include "StackingAction.hh"
#include "SteppingAction.hh"
#include "RunAction.hh"
#include "EventAction.hh"
#include "fileMerger.hh"
// SVN
void usage();
/*
* Main: G4simu
*
* Goal: simulation of Modulation setup
*
* A.P. Colijn -- jun 2015 --
*/
int
main(int argc, char **argv)
{
// switches
int c = 0;
std::stringstream hStream;
bool bInteractive = false;
bool bPreInitFromFile = false;
bool bMacroFile = false;
std::string hMacroFilename, hDataFilename, hPreInitFilename;
std::string hCommand;
int iNbEventsToSimulate = 0;
// parse switches ...
while((c = getopt(argc,argv,"f:o:p:n:i")) != -1){
switch(c) {
case 'f':
bMacroFile = true;
hMacroFilename = optarg;
break;
case 'o':
hDataFilename = optarg;
break;
case 'p':
bPreInitFromFile = true;
hPreInitFilename = optarg;
break;
case 'n':
hStream.str(optarg);
hStream.clear();
hStream >> iNbEventsToSimulate;
break;
case 'i':
bInteractive = true;
break;
default:
usage();
}
}
//
if(hDataFilename.empty()) hDataFilename = "events.root";
// create the run manager
G4RunManager *pRunManager = new G4RunManager;
// Detector Construction
G4String detectorRoot = hDataFilename+".DET";
DetectorConstruction *detCon = new DetectorConstruction(detectorRoot);
pRunManager->SetUserInitialization(detCon);
// Physics List
G4String physicsRoot = hDataFilename+".PHYS";
PhysicsList *physList = new PhysicsList(physicsRoot);
pRunManager->SetUserInitialization(physList);
// Visualization Manager
G4VisManager* pVisManager = new G4VisExecutive;
pVisManager->Initialize();
// create the primary generator action
G4String generatorRoot = hDataFilename+".GEN";
PrimaryGeneratorAction *pPrimaryGeneratorAction = new PrimaryGeneratorAction(generatorRoot);
// create an analysis manager object
AnalysisManager *pAnalysisManager = new AnalysisManager(pPrimaryGeneratorAction);
pAnalysisManager->SetDataFilename(hDataFilename);
if(iNbEventsToSimulate) pAnalysisManager->SetNbEventsToSimulate(iNbEventsToSimulate);
// set user-defined action classes
pRunManager->SetUserAction(pPrimaryGeneratorAction);
pRunManager->SetUserAction(new StackingAction(pAnalysisManager));
pRunManager->SetUserAction(new SteppingAction(pAnalysisManager));
pRunManager->SetUserAction(new RunAction(pAnalysisManager));
pRunManager->SetUserAction(new EventAction(pAnalysisManager));
// geometry IO
G4UImanager* pUImanager = G4UImanager::GetUIpointer();
if(bPreInitFromFile)
{
hCommand = "/control/execute " + hPreInitFilename;
pUImanager->ApplyCommand(hCommand);
}
// initialize it all....
pRunManager->Initialize();
G4UIsession * pUIsession = 0;
if(bInteractive) pUIsession = new G4UIterminal(new G4UItcsh);
// run time parameter settings
if(bMacroFile)
{
hCommand = "/control/execute " + hMacroFilename;
pUImanager->ApplyCommand(hCommand);
}
if(iNbEventsToSimulate)
{
hStream.str("");
hStream.clear();
hStream << "/run/beamOn " << iNbEventsToSimulate;
pUImanager->ApplyCommand(hStream.str());
}
if(bInteractive)
{
pUIsession->SessionStart();
delete pUIsession;
}
delete pAnalysisManager;
delete pRunManager;
// merge the output files to one .... events.root
vector<std::string> auxfiles;
auxfiles.push_back(detectorRoot);
auxfiles.push_back(physicsRoot);
auxfiles.push_back(generatorRoot);
fileMerger myMerger(hDataFilename,auxfiles);
myMerger.Merge();
myMerger.CleanUp();
return 0;
}
void
usage()
{
exit(0);
}