-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmmSim.cc
More file actions
195 lines (167 loc) · 5.69 KB
/
mmSim.cc
File metadata and controls
195 lines (167 loc) · 5.69 KB
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
#include "MMActionInitialization.hh"
#include "MMDetectorConstruction.hh"
#include "BinaryReactionPhysics.hh"
#include "NucleonStates.hh"
#include "QGSP_BERT.hh"
#include "G4StepLimiterPhysics.hh"
#include "G4MTRunManager.hh"
#include "G4RadioactiveDecayPhysics.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4VModularPhysicsList.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
#include "json/json.h"
#include "Randomize.hh"
#include "time.h"
int main(int argc,char** argv)
{
if(argc < 2) {
std::cout << "Usage: mmSim config-file" << std::endl;
return 0;
}
// Get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
//CREATE AND READ JSON CONFIG
Json::Value config;
std::string configFileName = argv[1];
std::ifstream configStream(configFileName.c_str());
configStream >> config;
configStream.close();
//Parse JSON
G4double gasPressure = config["gasPressure"].asDouble(); // Torr
G4double gasTemperature = config["gasTemperature"].asDouble(); // K
G4String gasType = config["gasType"].asString();
G4int numGrids = config["numberGrids"].asInt();
G4double gridSize = config["gridSize"].asDouble();
G4double gridRadius = config["gridRadius"].asDouble();
G4double gridDist = config["gridDistance"].asDouble();
G4double scintDist = config["scintDistance"].asDouble();
G4double wireThickness = config["wireThickness"].asDouble();
G4bool useInches = config["useInches"].asBool();
G4double scintResolution = config["scintResolution"].asDouble();
G4double extraGridResolution = config["extraGridResolution"].asDouble();
G4String macroName = config["macroName"].asString();
G4bool isInteractive = config["interactive"].asBool();
// Work out fanoFactor and workFunction from gasType
G4double fanoFactor;
G4double workFunction;
if(gasType == "P10" || gasType == "p10") {
fanoFactor = 0.17;
workFunction = 28.0;
}
else if(gasType == "CO2" || gasType == "co2") {
fanoFactor = 0.33;
workFunction = 34.2;
}
else if(gasType == "Methane" || gasType == "methane" || gasType == "METHANE" || gasType == "CH4") {
fanoFactor = 0.26;
workFunction = 29.1;
}
else if(gasType == "CF4" || gasType == "cf4") {
fanoFactor = 0.2;
workFunction = 33.8;
}
else {
fanoFactor = 0.26;
workFunction = 29.1;
}
//choose the Random engine
CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine());
//set random seed with system time
G4long seed = time(NULL);
if(argc>2) seed += 473879*atoi(argv[2]);
CLHEP::HepRandom::setTheSeed(seed);
#ifdef G4MULTITHREADED
G4int nThreads = 0;
#endif
for(G4int i = 1; i < argc; i++) {
G4cout << argv[i] << G4endl;
#ifdef G4MULTITHREADED
if(G4String(argv[i]) == "-t") {
nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
}
#endif
}
// Construct the default run manager
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
if(nThreads > 0) {
runManager->SetNumberOfThreads(nThreads);
}
#else
G4RunManager* runManager = new G4RunManager;
#endif
// Mandatory user initialization classes
MMDetectorConstruction* detector = new MMDetectorConstruction();
detector->SetGasType(gasType);
detector->SetGasTemperature(gasTemperature);
detector->SetGasPressure(gasPressure);
detector->SetNumGrids(numGrids);
detector->SetUseInches(useInches);
detector->SetGridSize(gridSize);
detector->SetGridRadius(gridRadius);
detector->SetGridDistance(gridDist);
detector->SetScintDistance(scintDist);
detector->SetWireThickness(wireThickness);
runManager->SetUserInitialization(detector);
NucleonStates* states = NucleonStates::Instance();
G4VModularPhysicsList* physicsList = new QGSP_BERT(0);
BinaryReactionPhysics* reactionPhysics = new BinaryReactionPhysics();
reactionPhysics->SetNumGrids(numGrids);
physicsList->RegisterPhysics(new G4StepLimiterPhysics());
physicsList->RegisterPhysics(reactionPhysics);
runManager->SetUserInitialization(physicsList);
// User action initialization
MMActionInitialization* actionInit = new MMActionInitialization(detector);
actionInit->SetFanoFactor(fanoFactor);
actionInit->SetWorkFunction(workFunction);
actionInit->SetNumGrids(numGrids);
actionInit->SetScintillatorResolution(scintResolution);
actionInit->SetGridResolution(extraGridResolution);
runManager->SetUserInitialization(actionInit);
// Initialize Geant4 kernel
runManager->Initialize();
#ifdef G4VIS_USE
// Visualization manager construction
// G4VisManager* visManager = new G4VisExecutive();
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
#endif
if(!isInteractive) {
// execute an argument macro file if exists
G4String command = "/control/execute ";
G4String filename = macroName;
UImanager->ApplyCommand(command + filename);
}
else {
// start interactive 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 gui.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;
}