-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPileRoomSim.cc
331 lines (254 loc) · 8.32 KB
/
PileRoomSim.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
//
/// \file electromagnetic/PileRoomSim/PileRoomSim.cc
/// \brief Main program of the electromagnetic/PileRoomSim example
//
//
// $Id: PileRoomSim.cc 76340 2013-11-08 15:21:09Z gcosmo $
#include <algorithm>
#include <sstream>
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "Randomize.hh"
#include "DetectorConstruction.hh"
#include "Commands.h"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.hh"
#include "G4OpticalPhysics.hh"
#include "FTFP_BERT_HP.hh"
#include "G4HadronicProcessStore.hh"
#include "ActionInitialization.hh"
#include "SteppingVerbose.hh"
#include "formattingStrings.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
int main(int argc,char** argv) {
G4String fileName = "";
G4String he3Desc = "";
std::string miscFile = "";
G4String graphiteDesc = "";
bool saveAll=false;
bool verbose=false;
G4String nevents="";
G4String seed="";
G4String outfile="";
bool gui=true;
bool vis=true;
bool saveGeo=true;
//parse command line arguments
for(int i=0; i<argc; i++){
std::string input(argv[i]);
if(input.compare("-m") == 0){ //macro file
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
fileName = string(argv[i+1]);
gui=false;
}
}else if(input.compare("-o")==0){ //misc objects
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
miscFile = string(argv[i+1]);
}
}else if(input.compare("-d")==0){ //he3tube description
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
he3Desc = string(argv[i+1]);
}
}else if(input.compare("-g")==0){ //graphite description
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
graphiteDesc = string(argv[i+1]);
}
}else if(input.compare("-all")==0){ //save all events
saveAll=true;
}else if(input.compare("-noGeo")==0){ //save geometry
saveGeo=false;
}else if(input.compare("-verbose")==0){ //verbose
verbose=true;
}else if(input.compare("-n")==0){ //number of events
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
nevents = "/run/beamOn "+string(argv[i+1]);
gui=false;
}
}else if(input.compare("-s")==0){ //seeds
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
seed = "/random/setSeeds "+ string(argv[i+1]);
}
if(i+2<argc){
std::string next(argv[i+2]);
if(next.compare(0,1,"-") != 0)
seed = seed + " " + string(argv[i+2]);
}
}else if(input.compare("-r")==0){ //root filename
if(i+1<argc){
std::string next(argv[i+1]);
if(next.compare(0,1,"-") != 0)
outfile = "/analysis/setFileName " + string(argv[i+1]);
gui=false;
}
}else if(input.compare("-novis")==0){ //no visualization
vis=false;
}else if(input.compare("-h")==0){ //help
#ifdef PORTABLE
cout<<"Using the portable version: no visualization available\n\n"<<endl;
#endif
help();
return 0;
}
}
if(outfile.size()!=0)
if (outfile.find(".root") == std::string::npos)
outfile = outfile + ".root";
G4cout<<topLeft;
for(int i=0; i<60; i++) G4cout<<line;
G4cout<<topRight<<G4endl;
G4cout<<vertical<<"Summary of settings:";
for(int i=0; i<40; i++) G4cout<<" ";
G4cout<<vertical<<G4endl;
G4cout<<leftDivider;
for(int i=0; i<60; i++) G4cout<<thinLine;
G4cout<<rightDivider<<G4endl;
G4cout<<vertical<<"Helium-3 tube description: "<<left<<setw(33);
if(he3Desc.size()!=0)G4cout<<he3Desc;
else G4cout<<"Default";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Graphite description: "<<left<<setw(38);
if(graphiteDesc.size()!=0)G4cout<<graphiteDesc;
else G4cout<<"Default";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Miscellaneous objects: "<<left<<setw(37);
if(miscFile.size()!=0)G4cout<<miscFile;
else G4cout<<"None";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Saving all events: "<<left<<setw(41);
if(saveAll) G4cout<<"yes";
else G4cout<<"no";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Saving geometry: "<<left<<setw(43);
if(saveGeo) G4cout<<"yes";
else G4cout<<"no";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Verbose mode: "<<left<<setw(46);
if(verbose) G4cout<<"yes";
else G4cout<<"no";
G4cout<<vertical<<G4endl;
if(gui){
G4cout<<vertical<<"Entering interactive mode"<<left<<setw(35);
if(vis) G4cout<<" with visualization";
else G4cout<<" ";
G4cout<<vertical<<G4endl;
}else{
G4cout<<vertical<<"Macro file: "<<left<<setw(48);
if(fileName.size()!=0) G4cout<<fileName;
else G4cout<<"None";
G4cout<<vertical<<G4endl;
if(fileName.size()==0){
G4cout<<vertical<<"Number of events: "<<left<<setw(42);
if(nevents.size()!=0) G4cout<<nevents.substr(12);
else G4cout<<"Not specified";
G4cout<<vertical<<G4endl;
string temp = outfile.substr(22);
G4cout<<vertical<<"Output file: "<<left<<setw(47);
if(outfile.size()!=0) G4cout<<temp;
else G4cout<<"Not specified";
G4cout<<vertical<<G4endl;
G4cout<<vertical<<"Seeds: "<<left<<setw(53);
if(seed.size()!=0) G4cout<<seed.substr(17);
else G4cout<<"Not specified";
G4cout<<vertical<<G4endl;
}
}
G4cout<<bottomLeft;
for(int i=0; i<60; i++) G4cout<<line;
G4cout<<bottomRight<<G4endl;
//make sure environment variables are set
char *checkEnv;
checkEnv = getenv("G4NEUTRONHPDATA");
if(checkEnv==NULL){
cout<<"Need to source geant4.10.02-install/bin/geant4.sh before running\n";
return 0;
}
std::streambuf *coutbuf;
if(!verbose){
stringstream ss;
coutbuf = G4cout.rdbuf(); //save old buf
G4cout.rdbuf(ss.rdbuf());
}
//choose the Random engine
G4Random::setTheEngine(new CLHEP::RanecuEngine);
// Construct the default run manager
G4VSteppingVerbose::SetInstance(new SteppingVerbose);
G4RunManager* runManager = new G4RunManager;
runManager->SetVerboseLevel(verbose);
//physics list
G4VModularPhysicsList* physicsList = new FTFP_BERT_HP(verbose);
runManager->SetUserInitialization(physicsList);
//pass he3tube description and misc object description filenames to DetectorConstruction
DetectorConstruction* detConstruction = new DetectorConstruction(he3Desc, miscFile, graphiteDesc, verbose, saveGeo);
runManager->SetUserInitialization(detConstruction);
// set user action classes
runManager->SetUserInitialization(new ActionInitialization(detConstruction, saveAll));
//Initialize G4 kernel
runManager->Initialize();
G4HadronicProcessStore::Instance()->SetVerbose(verbose);
// get the pointer to the User Interface manager
G4UImanager* UI = G4UImanager::GetUIpointer();
if(!verbose) G4cout.rdbuf(coutbuf);
if(fileName.size()!=0){ //user specified script
G4String command = "/control/execute ";
UI->ApplyCommand(command+fileName);
} else if(!gui){ //user specified seed, number of events, and output file
if(outfile.size()==0){
cout<<bold2<<red2<<"No output file specified! quitting."<<noFormat2<<endl;
help();
return 0;
}if(nevents.size()==0){
cout<<bold2<<red2<<"Number of events not specified! quitting."<<noFormat2<<endl;
help();
return 0;
}
int n = std::count(seed.begin(), seed.end(), ' ');
if(n<2) cout<<bold2<<"Warning: Wrong number of seeds: Using auto generated seeds."<<noFormat2<<endl;
else UI->ApplyCommand(seed);
std::vector<std::string> commands = UICommands();
for(int i=0; i<(int)commands.size(); i++) UI->ApplyCommand(commands[i]);
UI->ApplyCommand(outfile);
UI->ApplyCommand(nevents);
} else // define visualization and UI terminal for interactive mode
{
#ifdef G4VIS_USE
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
#endif
#ifdef G4UI_USE
G4UIExecutive * ui = new G4UIExecutive(argc,argv);
#ifndef PORTABLE
if(vis){
std::vector<std::string> commands = visCommands();
for(int i=0; i<(int)commands.size(); i++) UI->ApplyCommand(commands[i]);
}
#endif
help();
ui->SessionStart();
delete ui;
#endif
#ifdef G4VIS_USE
delete visManager;
#endif
}
// job termination
//
delete runManager;
return 0;
}