-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHGCALTB.cc
165 lines (149 loc) · 4.58 KB
/
HGCALTB.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
//**************************************************
// \file HGCALTB.cc
// \brief: main() of HGCALTB
// \author: Lorenzo Pezzotti (CERN EP-SFT-sim)
// @lopezzot
// \start date: 10 January 2024
//**************************************************
// Includers from project files
//
#include "HGCALTBActInitialization.hh"
#include "HGCALTBDetConstruction.hh"
// Includers from Geant4
//
#ifdef G4MULTITHREADED
# include "G4MTRunManager.hh"
# include "G4Threading.hh"
#else
# include "G4RunManager.hh"
#endif
// #include "G4RunManagerFactory.hh" //only available from 10.7 on
#include "G4PhysListFactory.hh"
#include "G4UIExecutive.hh"
#include "G4UIcommand.hh"
#include "G4UImanager.hh"
#include "G4Version.hh"
#include "G4VisExecutive.hh"
// CLI string outputs
namespace CLIOutputs
{
void PrintHelp()
{
G4cout << "Usage: HGCALTB [OPTION...]\n\n"
<< "Options:\n"
<< " -m MACRO path to macro file to run\n"
<< " -u UISESSION string of the Geant4 UI session to use\n"
<< " -t THREADS number of threads to use in the simulation\n"
<< " -p PHYSICSLIST string of the physics list to use\n"
<< " -f FILENAME optional string with custom file name\n"
<< " -h print this help and exit\n"
<< G4endl;
}
void PrintError()
{
G4cerr << "Wrong usage, see 'HGCALTB -h' for more information" << G4endl;
}
} // namespace CLIOutputs
// G4err output for PhysListFactory usage error
//
namespace PrintPLFactoryUsageError
{
void PLFactoryUsageError()
{
G4cerr << "Wrong PLFactory usage: no name for selected PL. " << G4endl;
}
} // namespace PrintPLFactoryUsageError
int main(int argc, char** argv)
{
// CLI variables
G4String macro;
G4String session;
G4String custom_pl = "FTFP_BERT"; // default physics list
G4String custom_filename = ""; // default file name selected by RunAction
#ifdef G4MULTITHREADED
G4int nThreads = G4Threading::G4GetNumberOfCores();
#endif
// CLI parsing
for (G4int i = 1; i < argc; i = i + 2) {
if (G4String(argv[i]) == "-m")
macro = argv[i + 1];
else if (G4String(argv[i]) == "-u")
session = argv[i + 1];
else if (G4String(argv[i]) == "-p")
custom_pl = argv[i + 1];
else if (G4String(argv[i]) == "-f")
custom_filename = argv[i + 1];
#ifdef G4MULTITHREADED
else if (G4String(argv[i]) == "-t") {
nThreads = G4UIcommand::ConvertToInt(argv[i + 1]);
}
#endif
else if (G4String(argv[i]) == "-h") {
CLIOutputs::PrintHelp();
return 0;
}
else {
CLIOutputs::PrintError();
return 1;
}
}
// Activate interaction mode if no macro card is provided and define UI
// session
//
G4UIExecutive* ui = nullptr;
if (!macro.size()) { // if macro card is not passed
ui = new G4UIExecutive(argc, argv, session);
}
// Construct the run manager
//
#ifdef G4MULTITHREADED
auto runManager = new G4MTRunManager;
if (nThreads > 0) {
runManager->SetNumberOfThreads(nThreads);
}
#else
auto runManager = new G4RunManager;
#endif
// Manadatory Geant4 classes
//
auto physListFactory = new G4PhysListFactory();
if (!physListFactory->IsReferencePhysList(custom_pl)) { // if custom_pl is not a PLname exit
PrintPLFactoryUsageError::PLFactoryUsageError();
return 1;
}
auto physicsList = physListFactory->GetReferencePhysList(custom_pl);
runManager->SetUserInitialization(physicsList);
runManager->SetUserInitialization(new HGCALTBDetConstruction());
runManager->SetUserInitialization(new HGCALTBActInitialization(custom_filename));
// Visualization manager construction
//
auto visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
// Get the pointer to the User Interface manager
//
auto UImanager = G4UImanager::GetUIpointer();
if (!ui) {
// execute an argument macro file if exist (second parser argument)
G4String command = "/control/execute ";
UImanager->ApplyCommand(command + macro);
}
else {
UImanager->ApplyCommand("/control/execute init_vis.mac");
if (ui->IsGUI()) {
UImanager->ApplyCommand("/control/execute gui.mac");
}
// start interactive session
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;
}
//**************************************************