-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
206 lines (178 loc) · 5.82 KB
/
main.cpp
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
#include <time.h>
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#include "G4Threading.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "QGSP_BERT_HP.hh"
#include "QGSP_BIC_HP.hh"
#include "Shielding.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#include "G4TrajectoryParticleFilter.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
// Remove?
#include "Randomize.hh"
#include "BIDNAPhysicsList.hpp"
#include "BIDetectorConstruction.hpp"
#include "BIActionInitialization.hpp"
#include "BIPrimaryGeneratorAction.hpp"
namespace {
void PrintUsage()
{
G4cerr << " Usage: " << G4endl;
G4cerr << " ./LG [-m macro filename]\n"
<< " -a Show all trajectory (default show only ploton)\n"
<< " -q Using only quarter region of the plate\n"
<< " -b [beam profile number] Choose beam profile\n"
<< " -h cutting and showing the geometry\n"
<< " Can I use some option of Geant4 itself?\n"
<< " --grid For Grid system, output is only a few parameters\n"
<< " --tile Using tile attenuator\n"
<< G4endl;
}
}
unsigned int GetRandomSeed()
{
// Using /dev/urandom for generating random number.
// If it is not, I have to think solution.
// And also think /dev/random or /dev/urandom
// Using std::random_device of C++11 is better
unsigned int seed;
std::ifstream file("/dev/urandom", std::ios::binary);
if (file.is_open()) {
char *memblock;
int size = sizeof(int);
memblock = new char[size];
file.read(memblock, size);
file.close();
seed = *reinterpret_cast<unsigned int *>(memblock);
delete[] memblock;
} else {
seed = 0;
}
return seed;
}
int main(int argc, char **argv)
{
G4String macro = "";
G4bool showAll = false;
BeamType beamType = kThirdBeam;
G4bool forGrid = false;
G4bool useTile = false;
G4bool useQuarter = false;
G4bool cutGeo = false;
for (G4int i = 1; i < argc; i++) {
if (G4String(argv[i]) == "-m") macro = argv[++i];
else if (G4String(argv[i]) == "-a") showAll = true;
else if (G4String(argv[i]) == "-q") useQuarter = true;
else if (G4String(argv[i]) == "-h") cutGeo = true;
else if (G4String(argv[i]) == "-b"){
G4String type = *argv[++i];
if(type == "1") beamType = kFirstBeam;
else if(type == "2") beamType = kSecondBeam;
else if(type == "3") beamType = kThirdBeam;
else if(type == "4") beamType = kElectronTest;
else if(type == "5") beamType = kXTest;
else if(type == "6") beamType = kIonTest;
else{
G4cout << "Beam type is wrong" << G4endl;
PrintUsage();
return 1;
}
}
else if (G4String(argv[i]) == "--grid") forGrid = true;
else if (G4String(argv[i]) == "--tile") useTile = true;
else {
PrintUsage();
return 1;
}
}
G4cout << "Beam type is " << beamType << G4endl;
if (forGrid) {
G4cout << "Small output mode" << G4endl;
}
// Choose the Random engine
// Need both?
unsigned int seed = GetRandomSeed();
if (seed == 0) seed = time(0);
G4cout << "\nseed = " << seed << G4endl;
CLHEP::HepRandom::setTheEngine(new CLHEP::MTwistEngine(seed));
G4Random::setTheEngine(new CLHEP::MTwistEngine(seed));
// Construct the default run manager
//
#ifdef G4MULTITHREADED
G4MTRunManager *runManager = new G4MTRunManager();
runManager->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
//runManager->SetNumberOfThreads(1);
#else
G4RunManager *runManager = new G4RunManager();
#endif
// Set mandatory initialization classes
//
// Detector construction
runManager->SetUserInitialization(new BIDetectorConstruction(forGrid, useTile, cutGeo));
// Physics list
//G4VModularPhysicsList *physicsList = new FTFP_BERT;
//G4VModularPhysicsList *physicsList = new QGSP_BERT_HP;
//G4VModularPhysicsList *physicsList = new QGSP_BIC_HP;
G4VModularPhysicsList *physicsList = new Shielding;
//G4VModularPhysicsList *physicsList = new BIDNAPhysicsList;
physicsList->SetVerboseLevel(0);
//physicsList->SetCutValue(1.*um, "proton");
//physicsList->SetCuts();
//physicsList->SetDefaultCutValue(100.*um);
runManager->SetUserInitialization(physicsList);
// Primary generator action and User action intialization
runManager->SetUserInitialization(new BIActionInitialization(beamType, forGrid, useQuarter));
// Initialize G4 kernel
//
runManager->Initialize();
#ifdef G4VIS_USE
// Initialize visualization
G4VisManager *visManager = new G4VisExecutive;
visManager->Initialize();
if (!showAll) { //Show only proton
G4TrajectoryParticleFilter *filterp = new G4TrajectoryParticleFilter;
filterp->Add("proton");
visManager->RegisterModel(filterp);
}
#endif
// Get the pointer to the User Interface manager
G4UImanager *UImanager = G4UImanager::GetUIpointer();
if (macro != "") {
// batch mode
G4String command = "/control/execute ";
UImanager->ApplyCommand(command + macro);
} else {
// interactive mode : define UI session
#ifdef G4UI_USE
G4UIExecutive *ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
UImanager->ApplyCommand("/control/execute init_vis.mac");
#else
UImanager->ApplyCommand("/control/execute init.mac");
#endif
if (ui->IsGUI()) {
UImanager->ApplyCommand("/control/execute icons.mac");
}
ui->SessionStart();
delete ui;
#endif
}
// 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 !
#ifdef G4VIS_USE
delete visManager;
#endif
delete runManager;
return 0;
}