-
Notifications
You must be signed in to change notification settings - Fork 0
/
CALICESiWTB.cc
243 lines (218 loc) · 7.47 KB
/
CALICESiWTB.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//**************************************************
// \file CALICESiWTB.cc
// \brief: main() of CALICESiWTB project
// \author: Lorenzo Pezzotti (CERN EP-SFT-sim)
// @lopezzot
// \start date: 17 February 2022
//**************************************************
//Includers from project files
//
#include "CaliceDetectorConstruction.hh"
#include "CaliceActionInitialization.hh"
#include "CalicePrimaryGeneratorAction.hh"
#include "CaliceRunAction.hh"
#include "CaliceEventAction.hh"
#include "CaliceTrackingAction.hh"
#include "CaliceSteppingAction.hh"
//Includers from Geant4 and C++
//
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include <cstring>
#include <climits>
#include <errno.h>
#include "G4SystemOfUnits.hh"
#include "G4ProcessManager.hh"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.hh"
#include "G4GenericPhysicsList.hh"
#include "FTFP_BERT.hh"
#include "FTFP_BERT_HP.hh"
#include "QGSP_BERT.hh"
#include "QGSP_FTFP_BERT.hh"
#include "QBBC.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "G4GDMLParser.hh"
#include "G4Version.hh"
#if G4VERSION_NUMBER >= 1110 // >= Geant4-11.1.0
#include "G4FTFTunings.hh"
#endif
#include <fstream>
using namespace std;
//G4err output for parser usage error
//
namespace PrintUsageError {
void UsageError() {
G4cerr << " Usage: " << G4endl;
G4cerr << " ./CALICESiWTB [macro] [physlist (default: FTFP_BERT)] "
<< " [nthreads (default: 1)] [geantval (default: false)] " << G4endl;
}
} // namespace PrintUsageError
//G4err output for FTFTune usage error
//
namespace PrintFTFTuneUsageError {
void FTFTuneUsageError() {
G4cerr << "Wrong FTF Alternative Tune Name selected. " << G4endl;
G4cerr << "(As of Geant4-11.1.0) Valid indeces/names are: " << G4endl;
G4cerr << "0(default)\n1(baryon-tune2022-v0)\n2(pion-tune2022-v0)\n3("
"combined-tune2022-v0)"
<< G4endl;
}
} // namespace PrintFTFTuneUsageError
//G4err output for PhysListFactory usage error
//
namespace PrintPLFactoryUsageError {
void PLFactoryUsageError() {
G4cerr << "Wrong PLFactory usage: no name for selected PL!!! " << G4endl;
}
} // namespace PrintPLFactoryUsageError
//main() of CALICESiWTB
//
int main( int argc, char** argv ) {
//Set Random Seed Engine and intial seed
//
//CLHEP::HepRandomEngine* defaultEngine;
//defaultEngine = new CLHEP::Ranlux64Engine(1234567,4);
//CLHEP::HepRandom::setTheEngine( /*&*/defaultEngine );
//G4long seed = time( NULL );
//CLHEP::HepRandom::setTheSeed( seed );
if ( argc>5 ){
PrintUsageError::UsageError();
return 1;
}
//Initializing RunManager
//
G4int nthreads = 2;
if (argc >= 4){
nthreads = G4UIcommand::ConvertToInt(argv[3]);
}
#ifdef G4MULTITHREADED
auto runManager = new G4MTRunManager;
if ( nthreads > 0 ) {
runManager->SetNumberOfThreads(nthreads);
}
#else
auto runManager = new G4RunManager;
#endif
//Mandatory User Actions: 1- Detector
//
G4GDMLParser parser;
parser.Read("myCaliceGeometry.gdml");
runManager->SetUserInitialization( new CaliceDetectorConstruction(parser) );
//Mandatory User Actions: 2- Physics List
//
G4String custom_pl = "FTFP_BERT"; //FTFP_BERT default PL
if (argc >= 3) { //argv[2] usage
custom_pl = argv[2];
}
//Select FTF tune
//
#if G4VERSION_NUMBER >= 1110 // >= Geant4-11.1.0
G4bool UseFTFTune = false;
G4int FTFTuneIndex = 99;
if (custom_pl.find("tune") != std::string::npos) {
UseFTFTune = true;
std::string pltune = custom_pl;
char tuneidx = pltune.back();
FTFTuneIndex = tuneidx - '0'; // convert char to int
custom_pl = custom_pl.substr(0, custom_pl.size() - 6);
G4cout << "---> Using FTF alternative tune index: " << FTFTuneIndex
<< " and PL: " << custom_pl << " <---" << G4endl;
}
#endif
//Select PhysicsList
//
auto physListFactory = new G4PhysListFactory();
if (!physListFactory->IsReferencePhysList(custom_pl)) { // if custom_pl is not
PrintPLFactoryUsageError::PLFactoryUsageError(); // a PLname exit
return 1;
}
auto physicsList = physListFactory->GetReferencePhysList(custom_pl);
runManager->SetUserInitialization(physicsList);
// Set FTF tune (only => Geant4-11.1.0)
//
#if G4VERSION_NUMBER >= 1110
if (UseFTFTune) {
auto FTFTunings = G4FTFTunings::Instance();
if (FTFTuneIndex == 0) FTFTunings->SetTuneApplicabilityState(0, 1);
else if (FTFTuneIndex == 1) FTFTunings->SetTuneApplicabilityState(1, 1);
else if (FTFTuneIndex == 2) FTFTunings->SetTuneApplicabilityState(2, 1);
else if (FTFTuneIndex == 3) FTFTunings->SetTuneApplicabilityState(3, 1);
else {
PrintFTFTuneUsageError::FTFTuneUsageError();
return 1;
}
}
#endif
G4String outputname = "CALICESiWTBout.root";
if (argc != 1){
//argv[1] usage
G4String particleName = ((string)argv[1]).substr(4);
particleName = particleName.substr(0,3);
G4String particleEnergy = ((string)argv[1]).substr(8);
particleEnergy = particleEnergy.substr(0,particleEnergy.find("GeV"));
outputname = "Calice_" + custom_pl + "_" + particleName + "_" + particleEnergy + "GeV.root";
}
if (argc == 5){
G4bool geantval = G4UIcommand::ConvertToBool(argv[4]);
if (geantval){
outputname = "CALICESiWTBout.root";
G4cout<<"Setup for geantval usage"<<G4endl;
}
}
//Mandatory User Action (for multi-threading): 3- ActionInitialization
//
auto actioninitialization = new CaliceActionInitialization( outputname );
runManager->SetUserInitialization( actioninitialization );
/*
//Mandatory User Actions: 3- PrimaryGeneratorAction
//
runManager->SetUserAction( new CalicePrimaryGeneratorAction );
//Optional user actions
//
auto evtaction = new CaliceEventAction;
runManager->SetUserAction( new CaliceRunAction(outputname, evtaction) );
runManager->SetUserAction( evtaction );
//runManager->SetUserAction( new CaliceTrackingAction );
runManager->SetUserAction( new CaliceSteppingAction() );
*/
// Initialize run manager, not needed can be done in macros, to be removed
//
//runManager->Initialize();
//Visualization
//
auto visManager = new G4VisExecutive;
visManager->Initialize();
//User Interface initialization
//
G4UImanager* UI = G4UImanager::GetUIpointer();
if ( argc == 1 ) { // Define UI session for interactive mode
G4cout<<"-->CALICESiWTB: interactive mode"<<G4endl;
G4UIExecutive* session = new G4UIExecutive(argc,argv);
UI->ApplyCommand( "/control/execute CALICESiWTB_init_vis.mac" );
if ( session->IsGUI() ) {
UI->ApplyCommand( "/control/execute CALICESiWTB_gui.mac" );
}
session->SessionStart();
delete session;
delete UI;
}
else { // Batch mode (macros)
G4String command = "/control/execute ";
G4cout<<"-->CALICESiWTB: batch mode"<<G4endl;
G4String fileName = argv[1];
UI->ApplyCommand(command+fileName);
}
//Job termination
//
delete visManager;
delete runManager;
//delete defaultEngine;
}
//**************************************************