-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComptonG4.cc
226 lines (183 loc) · 6.3 KB
/
ComptonG4.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
/*!
* @brief A Compton Polarimeter GEANT4 based Simulation Package
*
* This is a Compton Polarimeter GEANT4 based Simulation Package. It can load
* specified Geometry files and output a ROOT file with the results.
*
* @author Juan Carlos Cornejo <[email protected]>
*
* $Header $
!*/
// Standard G4 includes
#include <G4RunManager.hh>
//#include <QGSP_BERT.hh>
#include <FTFP_BERT.hh>
#include <G4UImanager.hh>
#include <G4UIterminal.hh>
#include <G4String.hh>
#include <G4OpticalPhysics.hh>
// Standard Lib includes
#include <fstream>
#ifdef G4UI_USE_QT
#include "G4UIQt.hh"
#endif
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
// Includes for this project
#include "ComptonG4DetectorConstruction.hh"
#include "ComptonG4Analysis.hh"
#include "ComptonG4PrimaryGeneratorAction.hh"
#include "ComptonG4EventAction.hh"
#include "ComptonG4RunAction.hh"
#include "ComptonG4SteppingAction.hh"
#include "ComptonG4SensitiveDetectorManager.hh"
// Include BOOST headers and setup boost namespace
#include <boost/program_options.hpp>
namespace po = boost::program_options;
// ... IT BEGIIINNNNSSSS!!!!
int main( int argc, char **argv)
{
G4String geometry_file;
G4String config_file;
G4String batch_file;
// Prepare the command line options
// Generic command line options
po::options_description generic("Generic options");
generic.add_options()
("help,h","print this help message") // help
("config,c",po::value<std::string>(&geometry_file)->default_value("./")
,"config file") // config file
;
// Shared with configuration file
po::options_description config("Configuration");
config.add_options()
("geometry-file",po::value<std::string>(),"Geometry filename")
("batch-file",po::value<std::string>(),"Batch filename")
("output-dir",po::value<std::string>(),"path output directory")
;
// Finally, add them to boost
po::options_description cmdline_options;
cmdline_options.add(generic).add(config);
po::options_description config_file_options;
config_file_options.add(config);
po::options_description visible("Allowed options");
visible.add(generic).add(config);
// Now process them generic options
po::variables_map vm;
po::store(po::parse_command_line(argc,argv,cmdline_options),vm);
po::notify(vm);
// First, check for the config file before parsing
if(vm.count("config")) { // was specified!
config_file = vm["config"].as<std::string>();
// Open the file as a stream for boost
std::ifstream ifs(config_file);
if(ifs) {
// Process config
po::store(parse_config_file(ifs,config_file_options),vm);
}
}
// Process help
if(vm.count("help")) {
std::cout << generic << "\n";
return 1;
}
// Process the mandatory geometry file
if(!vm.count("geometry-file")){
G4cerr << "Did not specify a geometry file!" << G4endl;
return -1;
} else {
geometry_file = vm["geometry-file"].as<std::string>();
}
#ifdef COMPTONG4_BATCH_MODE // We are in batch mode
// Process the batch file
if(!vm.count("geometry-file")){
G4cerr << "Did not specify a batch file!" << G4endl;
return -1;
} else {
batch_file = vm["batch-file"].as<std::string>();
}
#endif
// Seed the random number generator with a constant seed...cause, you know,
// confusion is great!!!
CLHEP::HepRandom::setTheSeed(20091010.);
//CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
// Run Manager
G4RunManager *runManager = new G4RunManager();
// Auxiliary DataIO class
ComptonG4Analysis *analysis = new ComptonG4Analysis();
// Sensitive Detector Manager
ComptonG4SensitiveDetectorManager* sensManager = new ComptonG4SensitiveDetectorManager(analysis);
// Create the default /Compton directory for all messengers
G4UIdirectory *compDir = new G4UIdirectory("/Compton/");
compDir->SetGuidance("UI commands for the ComptonG4 simulation");
// Mandatory Detector Constructor
runManager->SetUserInitialization(new ComptonG4DetectorConstruction(geometry_file,sensManager));
//runManager->SetUserInitialization( new QGSP_BERT() );
FTFP_BERT *physicsList = new FTFP_BERT();
physicsList->RegisterPhysics(new G4OpticalPhysics() );
runManager->SetUserInitialization( physicsList );
if(physicsList->GetPhysics("Optical") ){
G4cout << "***Optical Processes ON***" << G4endl;
} else {
G4cout << "***Optical Processes OFF***" << G4endl;
}
// Are we in interactive mode (GUI) or batch-mode?
#ifndef COMPTONG4_BATCH_MODE // Interactive mode
// UI Session pointer
G4UIsession *session = 0;
#ifdef G4UI_USE_QT
session = new G4UIQt(argc,argv);
#else
session = new G4UIterminal(argc,argv);
#endif
#ifdef G4VIS_USE
// Visualization, if you choose to have it!
//
// Simple graded message scheme - give first letter or a digit:
// 0) quiet, // Nothing is printed.
// 1) startup, // Startup and endup messages are printed...
// 2) errors, // ...and errors...
// 3) warnings, // ...and warnings...
// 4) confirmations, // ...and confirming messages...
// 5) parameters, // ...and parameters of scenes and views...
// 6) all // ...and everything available.
G4VisManager* visManager = new G4VisExecutive;
//visManager -> SetVerboseLevel (1);
visManager ->Initialize();
#endif
#endif
// Set user action classes
runManager->SetUserAction(new ComptonG4PrimaryGeneratorAction(analysis));
runManager->SetUserAction(new ComptonG4SteppingAction(analysis));
runManager->SetUserAction(new ComptonG4EventAction(analysis));
runManager->SetUserAction(new ComptonG4RunAction(analysis));
// Initialize G4 kernel
runManager->Initialize();
// get the pointer to the User Interface manager
G4UImanager* UI = G4UImanager::GetUIpointer();
#ifndef COMPTONG4_BATCH_MODE // Interactive mode
#if defined(G4UI_USE_XM) || defined(G4UI_USE_WIN32) || defined(G4UI_USE_QT)
// Read default GUI mac file
char *guiFile= getenv("COMPTONG4_GUI_MAC_FILE");
if(guiFile!=NULL) {
G4String cmd("/control/execute");
cmd += guiFile;
UI->ApplyCommand(cmd );
} else {
UI->ApplyCommand("/control/execute ComptonG4_GUI.mac");
}
#endif
session->SessionStart();
delete session;
#ifdef G4VIS_USE
delete visManager;
#endif
#else // Batch-mode
G4String command = "/control/execute ";
UI->ApplyCommand(command+batch_file);
#endif
delete compDir;
delete runManager;
return 0;
}