-
Notifications
You must be signed in to change notification settings - Fork 55
/
remoll.cc
236 lines (197 loc) · 7.42 KB
/
remoll.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
/*!
remoll - 12 GeV Moller Simluation
Seamus Riordan, et al.
*/
#include "G4Types.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
typedef G4MTRunManager RunManager;
#else
#include "G4RunManager.hh"
typedef G4RunManager RunManager;
#endif
#include "G4Version.hh"
#include "G4UImanager.hh"
#include "remollIO.hh"
#include "remollRun.hh"
#include "remollRunData.hh"
#include "remollPhysicsList.hh"
#include "remollActionInitialization.hh"
#include "remollDetectorConstruction.hh"
#include "remollParallelConstruction.hh"
#include "remollSearchPath.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "TROOT.h"
#ifdef __APPLE__
#include <unistd.h>
#endif
#include <ctime>
#include <fstream>
namespace {
void PrintUsage() {
G4cerr << "Usage: " << G4endl;
G4cerr << " remoll [-f] [-g geometry] [-m macro] [-u UIsession] [-r seed] [-o outputfile] ";
#ifdef G4MULTITHREADED
G4cerr << "[-t nThreads] ";
#endif
G4cerr << "[macro]" << G4endl;
}
}
int main(int argc, char** argv) {
// Running time measurement: start
clock_t tStart = clock();
#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
// Fix for #40: avoids LLVM/GL errors, but only for ROOT 6:
// make sure gROOT is loaded before LLVM by using it first
gROOT->Reset();
#endif
// Warn if LIBGL_ALWAYS_INDIRECT is set
if (std::getenv("LIBGL_ALWAYS_INDIRECT") != nullptr) {
G4cerr << "remoll: Environment variable LIBGL_ALWAYS_INDIRECT is set." << G4endl;
G4cerr << "remoll: This may interfere with visualization. Unset wih:" << G4endl;
G4cerr << "remoll: tcsh> unsetenv LIBGL_ALWAYS_INDIRECT" << G4endl;
G4cerr << "remoll: bash> unset LIBGL_ALWAYS_INDIRECT" << G4endl;
}
// Initialize the random seed
G4long seed = time(0) + (int) getpid();
// Open /dev/urandom
std::ifstream urandom("/dev/urandom", std::ios::in | std::ios::binary);
// If stream is open
if (urandom) {
urandom.read(reinterpret_cast<char*>(&seed), sizeof(seed));
urandom.close();
seed = labs(seed);
} else G4cerr << "Can't read /dev/urandom." << G4endl;
// Parse command line options
G4String macro;
G4String session;
G4String geometry_gdmlfile;
G4String parallel_gdmlfile;
G4String outputfile;
__attribute__((unused)) G4bool force = false;
#ifdef G4MULTITHREADED
G4int threads = 0;
#endif
//
for (G4int i = 1; i < argc; ++i) {
if (G4String(argv[i]) == "-m") macro = argv[++i];
else if (G4String(argv[i]) == "-g") geometry_gdmlfile = argv[++i];
else if (G4String(argv[i]) == "-p") parallel_gdmlfile = argv[++i];
else if (G4String(argv[i]) == "-u") session = argv[++i];
else if (G4String(argv[i]) == "-r") seed = atol(argv[++i]);
else if (G4String(argv[i]) == "-o") outputfile = argv[++i];
else if (G4String(argv[i]) == "-f") force = true;
#ifdef G4MULTITHREADED
else if (G4String(argv[i]) == "-t") threads = atoi(argv[++i]);
#endif
else if (argv[i][0] != '-') macro = argv[i];
else {
PrintUsage();
return 1;
}
}
//-------------------------------
// Check dependency versions
//-------------------------------
#if G4VERSION_NUMBER < 1060
if (! force) {
G4cerr << "WARNING: You are running with an older geant4 version." << G4endl;
G4cerr << "WARNING: The encouraged version of geant4 is 10.6.2." << G4endl;
G4cerr << "WARNING: Pass the option '-f' to ignore this warning." << G4endl;
exit(-1);
}
#endif
#if ROOT_VERSION_CODE < ROOT_VERSION(6,14,4)
if (! force) {
G4cerr << "WARNING: You are running with an older ROOT version." << G4endl;
G4cerr << "WARNING: The encouraged version of ROOT is 6.14.4." << G4endl;
G4cerr << "WARNING: Pass the option '-f' to ignore this warning." << G4endl;
exit(-1);
}
#endif
//-------------------------------
// Initialization of Run manager
//-------------------------------
RunManager* runManager = new RunManager;
#ifdef G4MULTITHREADED
if (threads > 0) runManager->SetNumberOfThreads(threads);
#endif
// Set the default random seed
G4cout << G4endl << "remoll: Random seed: " << seed << G4endl;
G4Random::setTheSeed(seed);
// Create remoll IO object with output file name
if (outputfile.size() > 0)
remollIO::GetInstance(outputfile);
else
remollIO::GetInstance();
// Detector geometry
G4String material_name = "material";
remollDetectorConstruction* detector = new remollDetectorConstruction(material_name, geometry_gdmlfile);
// Parallel world geometry
G4String parallel_name = "parallel"; // Note: name must correspond with name of G4ParallelWorldPhysics
remollParallelConstruction* parallel = new remollParallelConstruction(parallel_name, parallel_gdmlfile);
detector->RegisterParallelWorld(parallel);
runManager->SetUserInitialization(detector);
// Physics list
remollPhysicsList* physlist = new remollPhysicsList();
runManager->SetUserInitialization(physlist);
// Run action
remollActionInitialization* useraction = new remollActionInitialization();
runManager->SetUserInitialization(useraction);
//----------------
// Visualization:
//----------------
// Initialize visualization
//
// Verbose level "warnings" (3) as is too noisy during initialization
G4VisManager* visManager = new G4VisExecutive("quiet");
visManager->Initialize();
visManager->SetVerboseLevel("warnings");
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
// use double precision
#if G4VERSION_NUMBER >= 1031
G4UImanager::UseDoublePrecisionStr(true);
#else
G4cout << "remoll: Warning: issue 130, double precision input may be truncated." << G4endl;
G4cout << "remoll: see also https://github.com/JeffersonLab/remoll/issues/130" << G4endl;
#endif
// Define UI session for interactive mode
G4String searchpath = ".";
searchpath += ":" + std::string(CMAKE_INSTALL_FULL_DATADIR) + "/remoll";
searchpath += ":" + std::string(CMAKE_INSTALL_FULL_DATADIR) + "/remoll/macros";
if (macro.size() != 0u)
{
// Run in batch mode
// Copy contents of macro into buffer to be written out into ROOT file
UImanager->SetMacroSearchPath(searchpath);
UImanager->ParseMacroSearchPath();
remollRun::GetRunData()->SetMacroFile((remollSearchPath::resolve(macro)).c_str());
UImanager->ExecuteMacroFile((remollSearchPath::resolve(macro)).c_str());
} else {
// Define UI session for interactive mode
G4UIExecutive* ui = new G4UIExecutive(argc,argv,session);
if (ui->IsGUI()) {
UImanager->SetMacroSearchPath(searchpath);
UImanager->ParseMacroSearchPath();
UImanager->ExecuteMacroFile((remollSearchPath::resolve("macros/gui.mac")).c_str());
}
ui->SessionStart();
delete ui;
}
// 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 !
delete visManager;
delete runManager;
// Running time measurement: end
clock_t tEnd = clock();
G4cout << " Running time[s]: "
<< double(tEnd - tStart) / double(CLOCKS_PER_SEC)
<< G4endl;
// Return success
return 0;
}