forked from ALLPix/allpix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allpix.cc
317 lines (257 loc) · 10.4 KB
/
allpix.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// ********************************************************************
// AllPix Geant4 *
// Generic Geant4 implementation for pixel detectors *
// Laboratoire de l'Accélérateur Linéaire Université Paris-Sud 11 *
// *
// John Idarraga <[email protected]> *
// Mathieu Benoit <[email protected]> *
// ********************************************************************
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: exampleN06.cc,v 1.14 2006/06/29 17:53:52 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include <time.h>
#include <string>
using namespace std;
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "G4ios.hh"
#include "AllPixPhysicsList.hh"
#include "AllPixDetectorConstruction.hh"
#include "AllPixPostDetConstruction.hh"
#include "AllPixSteppingVerbose.hh"
#include "AllPixRunAction.hh"
#include "AllPixPrimaryGeneratorAction.hh"
#include "AllPixEventAction.hh"
#include "AllPixRun.hh"
#include "AllPixRunAction.hh"
#include "AllPixTrackingAction.hh"
#include "AllPixExtDecayerPhysics.hh"
#include "FTFP_BERT.hh"
#include "QGSP_BERT.hh"
// digits, frames
#include "AllPix_Frames_WriteToEntuple.h"
// hits
#include "AllPix_Hits_WriteToEntuple.h"
#include "AllPixWriteROOTFile.hh" //nalipour
#include "Randomize.hh"
#include "ExExChStackingAction.hh"
#include "ExExChPhysicsList.hh"
#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif
/*
#if defined(G4UI_USE_TCSH)
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#elif defined(G4UI_USE_XM)
#include "G4UIXm.hh"
#elif defined(G4UI_USE_WIN32)
#include "G4UIWin32.hh"
#elif defined(G4UI_USE_QT)
#include "G4UIQt.hh"
#include "G4Qt.hh"
#else
#include "G4UIterminal.hh"
#endif
*/
#include "TH1F.h"
//#include "G4Qt.hh"
//#include "G4UIQt.hh"
// Input parameters
// indexes for argv[]
typedef enum {
_MACRO = 1,
_RUN_BATCH // run batch mode in this case
} inputPars;
void checkflags(int,char**);
void SplashWindow();
#include "TMatrix.h"
#include "TRotMatrix.h"
// geometry
#include "ReadGeoDescription.hh"
int main(int argc, char** argv)
{
// Flags
checkflags(argc, argv);
G4String fileName = argv[_MACRO];
// Seed the random number generator manually
time_t rawtime;
time(&rawtime);
G4long myseed = G4long(rawtime);
SplashWindow();
G4cout << "The random seed (localtime): " << myseed << G4endl;
// User Verbose output class
G4VSteppingVerbose* verbosity = new AllPixSteppingVerbose;
G4VSteppingVerbose::SetInstance(verbosity);
G4RunManager* runManager = new G4RunManager;
// UserInitialization classes - mandatory;
AllPixDetectorConstruction * detector =
new AllPixDetectorConstruction();
runManager->SetUserInitialization(detector);
//G4VModularPhysicsList * physics = new AllPixPhysicsList();
//G4VModularPhysicsList* physics = new FTFP_BERT;
G4VModularPhysicsList* physics = new ExExChPhysicsList();
//physics->RegisterPhysics(new AllPixExtDecayerPhysics());
runManager-> SetUserInitialization(physics);
// Hits ! --> Ntuple to store hits
// creates AllPixRun to analyze hits at the end of event
TString dataset = "allPix";
TString tempdir = "";
AllPixRunAction * run_action = new AllPixRunAction(detector, dataset, tempdir,
"lciobridge_allpix.txt",
"lciobridge_allpix_dut.txt"); // dataset
runManager->SetUserAction(run_action);
runManager->SetUserAction(new ExExChStackingAction());
// Particle gun
SourceType st = _GeneralParticleSource;
for(int i=0;i<argc;i++) {
if(!strcmp(argv[i],"-pgun")) st=_ParticleGun;
if(!strcmp(argv[i],"-gps")) st=_GeneralParticleSource;
if(!strcmp(argv[i],"-pythia")) st=_HepMCPythia8;
if(!strcmp(argv[i],"-hepevt")) st=_HEPEvtInterface;
if(!strcmp(argv[i],"-herwigpp")) st=_HepMCHerwig7;
}
AllPixPrimaryGeneratorAction * gen_action = new AllPixPrimaryGeneratorAction(st);
runManager->SetUserAction(gen_action);
// Get the PrimaryGeneratorMessenger to get a hold of some of its member variables
run_action->GetPrimaryGeneratorMessenger(gen_action);
// Digits ! --> calls Digitize, and makes ntuple to store digits
AllPixEventAction * event_action = new AllPixEventAction(run_action);
runManager->SetUserAction(event_action);
AllPixTrackingAction * tracking_action = new AllPixTrackingAction(run_action);
runManager->SetUserAction(tracking_action);
// Initialize G4 kernel
//
// ATTENTION ! runManager->Initialize() calls AllPixDetectorConstruction::Construct()
// but the macro has not been read and the position of the Medipixes is decided in the macro.
// This automatic call won't have any effect. It only build devices when the use calls
// /allpix/det/update from the macro. AllPixDetectorConstruction::Construct() is called from
// AllPixDetectorConstruction::UpdateGeometry()
//runManager->Initialize();
// now done through the DetectorConstructor Messenger via the macro
// Set digitizers. I need to do it after
// DetectorConstruction::Construct() is called
// event_action->SetupDigitizers();
//event_action->SetDetectorDigitInput(8.*keV); // thl !!!
CLHEP::HepRandom::setTheSeed(myseed);
//G4cout << *(G4Material::GetMaterialTable()) << G4endl;
#ifdef G4VIS_USE
// Initialize visualization
//
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
#endif
// Get the pointer to the User Interface manager
//
G4UImanager* UI = G4UImanager::GetUIpointer();
//UI->ApplyCommand("/tracking/verbose 1"); //nalipour: get information from secondary vertices???
G4String command = "/control/execute ";
if (argc-1 >= _RUN_BATCH) // batch mode
{
//G4String command = "/control/execute ";
//G4String fileName = argv[_MACRO];
UI->ApplyCommand(command+fileName);
}
else
{
G4UIsession * session = 0;
/*
#if defined(G4UI_USE_TCSH)
session = new G4UIterminal(new G4UItcsh);
#elif defined(G4UI_USE_XM)
session = new G4UIXm(argc,argv);
UI->ApplyCommand("/control/execute visTutor/gui.mac");
#elif defined(G4UI_USE_WIN32)
session = new G4UIWin32();
UI->ApplyCommand("/control/execute visTutor/gui.mac");
#elif defined(G4UI_USE_QT)
session = new G4UIQt(argc,argv);
UI->ApplyCommand("/control/execute visTutor/gui.mac");
#else
session = new G4UIterminal();
#endif
#ifdef G4VIS_USE
UI->ApplyCommand(command+fileName);
//AllPixPostDetConstruction::GetInstance()->WriteTracks("tracks_G4.root");
#endif
*/
//session = new G4UIQt(argc,argv);
//session = new G4UIXm(argc, argv);
session = new G4UIterminal();
UI->ApplyCommand(command+fileName);
//UI->ApplyCommand("/control/execute visTutor/gui.mac");
session->SessionStart();
delete session;
}
#ifdef G4VIS_USE
delete visManager;
#endif
// Geo description
extern ReadGeoDescription * g_GeoDsc; // already loaded ! :)
map<int, AllPixGeoDsc *> * geoMap = g_GeoDsc->GetDetectorsMap();
map<int, AllPixGeoDsc *>::iterator detItr;
// Frames ntuple closing
// G4int nDigitizers = event_action->GetNumberOfDigitizers();
for( detItr = geoMap->begin() ; detItr != geoMap->end() ; detItr++) {
WriteToNtuple::GetInstance("", "", "", (int)geoMap->size(), (*detItr).first)->closeNtuple();
//nalipour: Close and write the ROOT files
if(run_action->writeROOTFile !=NULL)
{
run_action->writeROOTFile[run_action->ReturnAllPixRun()->return_detIdToIndex((*detItr).first)]->AllPixCloseROOTFile();
}
}
// hits ntuple closing
G4int nHC = event_action->GetNumberOfHC();
for(G4int i = 0 ; i < nHC ; i++)
Hits_WriteToNtuple::GetInstance("", "", "", nHC, i)->closeNtuple();
G4cout << "[DONE]" << G4endl;
delete runManager;
delete verbosity;
return 0;
}
void checkflags(int argc, char** argv){
if(argc < 2){
G4cout << "use: " << G4endl;
G4cout << " " << argv[0] << " macro[filename]" << G4endl;
G4cout << "Default generator is GPS, you can change it by setting a flag: -pgun, -gps, -pythia, -hepevt, -herwigpp" << G4endl;
exit(1);
}
}
void SplashWindow(){
G4cout << "*************************************************************" << G4endl;
G4cout << " AllPix Geant4" << G4endl;
G4cout << " Generic Geant4 implementation for pixel detectors" << G4endl;
G4cout << " " << G4endl;
G4cout << " John Idarraga, NIKHEF <[email protected]>" << G4endl;
G4cout << " Mathieu Benoit, UNIGE <[email protected]>" << G4endl;
G4cout << "*************************************************************" << G4endl;
G4cout << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......