-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
136 lines (110 loc) · 3.96 KB
/
main.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
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
//#include "G4UIterminal.hh"
#include "DetectorConstruction.hh"
#include "UserActionInitialization.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif
#include "FTFP_BERT.hh"
#include "G4RadioactiveDecayPhysics.hh"
#define MAIN
#include "global.hh"
namespace CLHEP {}
using namespace CLHEP;
int main(int argc,char** argv) {
namespace po = boost::program_options;
po::options_description description("Usage");
description.add_options()
("help,h", "Display this help message")
("general.config_file,c", po::value<std::string>(), "config file")
("general.num_threads,n", po::value<int>()->default_value(1), "number of threads.")
("general.macro_file,m", po::value<std::string>()->default_value("scripts/vis_T0.mac"), "macro file")
("general.batch_mode,b", po::bool_switch()->default_value(false), "batch mode")
("detector.geometry,g", po::value<std::string>()->default_value(""), "geometry file")
("general.random_seed,r", po::value<int>(), "Seed of random generator")
("generator.beam_particle,p", po::value<int>()->default_value(0), "PDG id of beam")
("generator.target_particle,t", po::value<int>()->default_value(0), "PDG id of target")
("generator.beam_energy,e", po::value<double>()->default_value(1),"energy of beam in MeV");
std::ifstream cfg;
po::store(po::parse_command_line(argc, argv, description), vm);
notify(vm);
if(vm.count("general.config_file")){
cfg.open(vm["general.config_file"].as<std::string>().c_str(),std::ifstream::in);
po::store(po::parse_config_file(cfg, description), vm);
notify(vm);
}
// choose the Random engine
RanecuEngine* theEngine=new RanecuEngine;
if(!vm.count("general.random_seed")){
theEngine->setSeed(time(0));
}
else{
theEngine->setSeed(vm["general.random_seed"].as<int>());
}
HepRandom::setTheEngine(theEngine);
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
runManager->SetNumberOfThreads(vm["general.num_threads"].as<int>());
#else
G4RunManager* runManager = new G4RunManager;
#endif
// set mandatory initialization classes
DetectorConstruction* detector = new DetectorConstruction;
runManager->SetUserInitialization(detector);
// set physics list
G4VModularPhysicsList* physicsList=new FTFP_BERT();
physicsList->RegisterPhysics(new G4RadioactiveDecayPhysics());
physicsList->SetVerboseLevel(0);
runManager->SetUserInitialization(physicsList);
//User action initialization
runManager->SetUserInitialization(new UserActionInitialization);
// Initialize G4 kernel
//
runManager->Initialize();
#ifdef G4VIS_USE
// Initialize visualization
G4VisManager* visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
#endif
// Get the pointer to the User Interface manager
//
G4UImanager* UImanager = G4UImanager::GetUIpointer();
if (!vm["general.batch_mode"].as<bool>()) // Define UI session for interactive mode
{
#ifdef G4UI_USE
G4UIExecutive * ui = new G4UIExecutive(argc,argv);
#ifdef G4VIS_USE
std::stringstream o;
o<<"/control/execute "<<vm["general.macro_file"].as<std::string>().c_str();
UImanager->ApplyCommand(o.str().c_str());
#endif
ui->SessionStart();
delete ui;
#endif
}
else // Batch mode
{
std::stringstream o;
o<<"/control/execute "<<vm["general.macro_file"].as<std::string>().c_str();
UImanager->ApplyCommand(o.str().c_str());
}
// 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;
}