1 | /*
|
---|
2 | ---- Delphes ----
|
---|
3 | A Fast Simulator for general purpose LHC detector
|
---|
4 | S. Ovyn ~~~~ severine.ovyn@uclouvain.be
|
---|
5 |
|
---|
6 | Center for Particle Physics and Phenomenology (CP3)
|
---|
7 | Universite Catholique de Louvain (UCL)
|
---|
8 | Louvain-la-Neuve, Belgium
|
---|
9 | */
|
---|
10 |
|
---|
11 | /// \file Delphes.cpp
|
---|
12 | /// \brief executable for the Delphes
|
---|
13 |
|
---|
14 | #include "TChain.h"
|
---|
15 | #include "TApplication.h"
|
---|
16 |
|
---|
17 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeReader.h"
|
---|
18 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h"
|
---|
19 | #include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h"
|
---|
20 |
|
---|
21 | #include "interface/DataConverter.h"
|
---|
22 | #include "interface/HEPEVTConverter.h"
|
---|
23 | #include "interface/LHEFConverter.h"
|
---|
24 | #include "interface/STDHEPConverter.h"
|
---|
25 |
|
---|
26 | #include "interface/SmearUtil.h"
|
---|
27 | #include "interface/BFieldProp.h"
|
---|
28 | #include "interface/TriggerUtil.h"
|
---|
29 | #include "interface/VeryForward.h"
|
---|
30 | #include "interface/JetUtils.h"
|
---|
31 | #include "interface/FrogUtil.h"
|
---|
32 |
|
---|
33 | #include <vector>
|
---|
34 | #include <iostream>
|
---|
35 |
|
---|
36 | using namespace std;
|
---|
37 |
|
---|
38 | //------------------------------------------------------------------------------
|
---|
39 | void todo(string filename) {
|
---|
40 | ifstream infile(filename.c_str());
|
---|
41 | cout << "** TODO list ..." << endl;
|
---|
42 | while(infile.good()) {
|
---|
43 | string temp;
|
---|
44 | getline(infile,temp);
|
---|
45 | cout << "*" << temp << endl;
|
---|
46 | }
|
---|
47 | cout << "** done...\n";
|
---|
48 | }
|
---|
49 |
|
---|
50 | //------------------------------------------------------------------------------
|
---|
51 |
|
---|
52 | int main(int argc, char *argv[])
|
---|
53 | {
|
---|
54 | int appargc = 2;
|
---|
55 | char *appName = "Delphes";
|
---|
56 | char *appargv[] = {appName, "-b"};
|
---|
57 | TApplication app(appName, &appargc, appargv);
|
---|
58 |
|
---|
59 | if(argc != 4 && argc != 3 && argc != 5) {
|
---|
60 | cout << " Usage: " << argv[0] << " input_file output_file [detector_card] [trigger_card] " << endl;
|
---|
61 | cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl;
|
---|
62 | cout << " output_file - output file." << endl;
|
---|
63 | cout << " detector_card - Datacard containing resolution variables for the detector simulation (optional) "<<endl;
|
---|
64 | cout << " trigger_card - Datacard containing the trigger algorithms (optional) "<<endl;
|
---|
65 | exit(1);
|
---|
66 | }
|
---|
67 |
|
---|
68 | srand (time (NULL)); /* Initialisation du générateur */
|
---|
69 |
|
---|
70 | //read the input TROOT file
|
---|
71 | string inputFileList(argv[1]), outputfilename(argv[2]);
|
---|
72 | if(outputfilename.find(".root") > outputfilename.length() ) {
|
---|
73 | cout << "output_file should be a .root file!\n";
|
---|
74 | exit(1);
|
---|
75 | }
|
---|
76 | //create output log-file name
|
---|
77 | string forLog = outputfilename;
|
---|
78 | string LogName = forLog.erase(forLog.find(".root"));
|
---|
79 | LogName = LogName+"_run.log";
|
---|
80 |
|
---|
81 | TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
|
---|
82 | outputFile->Close();
|
---|
83 |
|
---|
84 | string line;
|
---|
85 | ifstream infile(inputFileList.c_str());
|
---|
86 | infile >> line; // the first line determines the type of input files
|
---|
87 |
|
---|
88 | //read the datacard input file
|
---|
89 | string DetDatacard("");
|
---|
90 | if(argc>=4) DetDatacard =argv[3];
|
---|
91 |
|
---|
92 | //Smearing information
|
---|
93 | RESOLution *DET = new RESOLution();
|
---|
94 | DET->ReadDataCard(DetDatacard);
|
---|
95 | DET->Logfile(LogName);
|
---|
96 |
|
---|
97 | //read the trigger input file
|
---|
98 | string TrigDatacard("data/trigger.dat");
|
---|
99 | if(argc==5) TrigDatacard =argv[4];
|
---|
100 |
|
---|
101 | //Trigger information
|
---|
102 | TriggerTable *TRIGT = new TriggerTable();
|
---|
103 | TRIGT->TriggerCardReader(TrigDatacard.c_str());
|
---|
104 | TRIGT->PrintTriggerTable(LogName);
|
---|
105 |
|
---|
106 | //Propagation of tracks in the B field
|
---|
107 | TrackPropagation *TRACP = new TrackPropagation();
|
---|
108 |
|
---|
109 | //Jet information
|
---|
110 | JetsUtil *JETRUN = new JetsUtil();
|
---|
111 |
|
---|
112 | //VFD information
|
---|
113 | VeryForward * VFD = new VeryForward();
|
---|
114 |
|
---|
115 | //todo(LogName.c_str());
|
---|
116 |
|
---|
117 | DataConverter *converter=0;
|
---|
118 |
|
---|
119 | if(strstr(line.c_str(),".hep"))
|
---|
120 | {
|
---|
121 | cout<<"#**********************************************************************"<<endl;
|
---|
122 | cout<<"#********** StdHEP file format detected *************"<<endl;
|
---|
123 | cout<<"#*********** Starting convertion to TRoot format **************"<<endl;
|
---|
124 | cout<<"#**********************************************************************"<<endl;
|
---|
125 | converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
126 | }
|
---|
127 | else if(strstr(line.c_str(),".lhe"))
|
---|
128 | {
|
---|
129 | cout<<"#**********************************************************************"<<endl;
|
---|
130 | cout<<"#*********** LHEF file format detected ************"<<endl;
|
---|
131 | cout<<"#*********** Starting convertion to TRoot format ************"<<endl;
|
---|
132 | cout<<"#**********************************************************************"<<endl;
|
---|
133 | converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
134 | }
|
---|
135 | else if(strstr(line.c_str(),".root"))
|
---|
136 | {
|
---|
137 | cout<<"#**********************************************************************"<<endl;
|
---|
138 | cout<<"#********** h2root file format detected *************"<<endl;
|
---|
139 | cout<<"#********** Starting convertion to TRoot format *************"<<endl;
|
---|
140 | cout<<"#**********************************************************************"<<endl;
|
---|
141 | converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
|
---|
142 | }
|
---|
143 | else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;};
|
---|
144 |
|
---|
145 | TChain chain("GEN");
|
---|
146 | chain.Add(outputfilename.c_str());
|
---|
147 | ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
|
---|
148 | const TClonesArray *branchGen = treeReader->UseBranch("Particle");
|
---|
149 | TIter itGen((TCollection*)branchGen);
|
---|
150 |
|
---|
151 | //write the output root file
|
---|
152 | ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
|
---|
153 | ExRootTreeBranch *branchJet = treeWriter->NewBranch("Jet", TRootJet::Class());
|
---|
154 | ExRootTreeBranch *branchTauJet = treeWriter->NewBranch("TauJet", TRootTauJet::Class());
|
---|
155 | ExRootTreeBranch *branchElectron = treeWriter->NewBranch("Electron", TRootElectron::Class());
|
---|
156 | ExRootTreeBranch *branchMuon = treeWriter->NewBranch("Muon", TRootMuon::Class());
|
---|
157 | ExRootTreeBranch *branchPhoton = treeWriter->NewBranch("Photon", TRootPhoton::Class());
|
---|
158 | ExRootTreeBranch *branchTracks = treeWriter->NewBranch("Tracks", TRootTracks::Class());
|
---|
159 | ExRootTreeBranch *branchETmis = treeWriter->NewBranch("ETmis", TRootETmis::Class());
|
---|
160 | ExRootTreeBranch *branchCalo = treeWriter->NewBranch("CaloTower", TRootCalo::Class());
|
---|
161 | ExRootTreeBranch *branchZDC = treeWriter->NewBranch("ZDChits", TRootZdcHits::Class());
|
---|
162 | ExRootTreeBranch *branchRP220 = treeWriter->NewBranch("RP220hits", TRootRomanPotHits::Class());
|
---|
163 | ExRootTreeBranch *branchFP420 = treeWriter->NewBranch("FP420hits", TRootRomanPotHits::Class());
|
---|
164 |
|
---|
165 |
|
---|
166 | TRootGenParticle *particle;
|
---|
167 | TRootETmis *elementEtmis;
|
---|
168 | TRootElectron *elementElec;
|
---|
169 | TRootMuon *elementMu;
|
---|
170 | TRootPhoton *elementPhoton;
|
---|
171 | TRootTracks *elementTracks;
|
---|
172 | TRootCalo *elementCalo;
|
---|
173 |
|
---|
174 | TLorentzVector genMomentum(0,0,0,0);
|
---|
175 | TLorentzVector genMomentumCalo(0,0,0,0);
|
---|
176 | LorentzVector jetMomentum;
|
---|
177 |
|
---|
178 | vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
|
---|
179 | vector<fastjet::PseudoJet> sorted_jets;
|
---|
180 |
|
---|
181 | vector<TLorentzVector> TrackCentral;
|
---|
182 | vector<PhysicsTower> towers;
|
---|
183 |
|
---|
184 | vector<ParticleUtil> electron;
|
---|
185 | vector<ParticleUtil> muon;
|
---|
186 | vector<ParticleUtil> gamma;
|
---|
187 | TSimpleArray<TRootGenParticle> NFCentralQ;
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 | // Loop over all events
|
---|
192 | Long64_t entry, allEntries = treeReader->GetEntries();
|
---|
193 | cout << "** Chain contains " << allEntries << " events" << endl;
|
---|
194 | for(entry = 0; entry < allEntries; ++entry)
|
---|
195 | {
|
---|
196 | TLorentzVector PTmis(0,0,0,0);
|
---|
197 | treeReader->ReadEntry(entry);
|
---|
198 | treeWriter->Clear();
|
---|
199 | if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
|
---|
200 |
|
---|
201 | electron.clear();
|
---|
202 | muon.clear();
|
---|
203 | gamma.clear();
|
---|
204 | NFCentralQ.Clear();
|
---|
205 |
|
---|
206 | TrackCentral.clear();
|
---|
207 | towers.clear();
|
---|
208 | input_particles.clear();
|
---|
209 |
|
---|
210 | // Loop over all particles in event
|
---|
211 | itGen.Reset();
|
---|
212 | while( (particle = (TRootGenParticle*) itGen.Next()) )
|
---|
213 | {
|
---|
214 | int pid = abs(particle->PID);
|
---|
215 | //// This subarray is needed for the B-jet algorithm
|
---|
216 | // optimization for speed : put first PID condition, then ETA condition, then either pt or status
|
---|
217 | if( (pid <= pB || pid == pGLUON) &&// is it a light quark or a gluon, i.e. is it one of these : u,d,c,s,b,g ?
|
---|
218 | fabs(particle->Eta) < DET->CEN_max_tracker &&
|
---|
219 | particle->Status != 1 &&
|
---|
220 | particle->PT > DET->PT_QUARKS_MIN ) {
|
---|
221 | NFCentralQ.Add(particle);
|
---|
222 | }
|
---|
223 |
|
---|
224 | // keeps only final particles, visible by the central detector, including the fiducial volume
|
---|
225 | // the ordering of conditions have been optimised for speed : put first the STATUS condition
|
---|
226 | //
|
---|
227 | //
|
---|
228 | if( (particle->Status == 1) &&
|
---|
229 | ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
|
---|
230 | (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
|
---|
231 | )
|
---|
232 | {
|
---|
233 | genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
|
---|
234 | if(DET->FLAG_bfield==1)TRACP->Propagation(particle,genMomentum);
|
---|
235 | float eta=fabs(genMomentum.Eta());
|
---|
236 |
|
---|
237 | switch(pid) {
|
---|
238 |
|
---|
239 | case pE: // all electrons with eta < DET->MAX_CALO_FWD
|
---|
240 | DET->SmearElectron(genMomentum);
|
---|
241 | if(genMomentum.E()!=0 && eta < DET->CEN_max_tracker && genMomentum.Pt() > DET->PTCUT_elec){
|
---|
242 | electron.push_back(ParticleUtil(genMomentum,particle->PID));
|
---|
243 | }
|
---|
244 | break; // case pE
|
---|
245 | case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
|
---|
246 | DET->SmearElectron(genMomentum);
|
---|
247 | if(genMomentum.E()!=0 && eta < DET->CEN_max_tracker && genMomentum.Pt() > DET->PTCUT_gamma) {
|
---|
248 | gamma.push_back(ParticleUtil(genMomentum,particle->PID));
|
---|
249 | }
|
---|
250 | break; // case pGAMMA
|
---|
251 | case pMU: // all muons with eta < DET->MAX_MU
|
---|
252 | DET->SmearMu(genMomentum);
|
---|
253 | if(genMomentum.E()!=0 && eta < DET->CEN_max_mu && genMomentum.Pt() > DET->PTCUT_muon){
|
---|
254 | muon.push_back(ParticleUtil(genMomentum,particle->PID));
|
---|
255 | }
|
---|
256 | break; // case pMU
|
---|
257 | case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
|
---|
258 | case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
|
---|
259 | DET->SmearHadron(genMomentum, 0.7);
|
---|
260 | break; // case hadron
|
---|
261 | default: // all other final particles with eta < DET->MAX_CALO_FWD
|
---|
262 | DET->SmearHadron(genMomentum, 1.0);
|
---|
263 | break;
|
---|
264 | } // switch (pid)
|
---|
265 |
|
---|
266 | // all final particles but muons and neutrinos
|
---|
267 | // for calorimetric towers and mission PT
|
---|
268 | int charge=Charge(pid);
|
---|
269 | if(genMomentum.E() !=0 && pid != pMU) {
|
---|
270 | if(charge == 0 || (charge !=0 && genMomentum.Pt() >= DET->TRACK_ptmin)){
|
---|
271 | PhysicsTower CaloTower = PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
272 | towers.push_back(CaloTower);
|
---|
273 | // create a fastjet::PseudoJet with these components and put it onto
|
---|
274 | // back of the input_particles vector
|
---|
275 | input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
|
---|
276 |
|
---|
277 | genMomentumCalo.SetPxPyPzE(CaloTower.fourVector.px,CaloTower.fourVector.py,CaloTower.fourVector.pz,CaloTower.fourVector.E);
|
---|
278 |
|
---|
279 | elementCalo = (TRootCalo*) branchCalo->NewEntry();
|
---|
280 | elementCalo->Set(genMomentumCalo);
|
---|
281 | DET->BinEtaPhi(genMomentumCalo.Phi(), genMomentumCalo.Eta(), elementCalo->Phi, elementCalo->Eta);
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 | // all final charged particles
|
---|
286 | if(
|
---|
287 | (genMomentum.E()!=0) &&
|
---|
288 | (fabs(genMomentum.Eta()) < DET->CEN_max_tracker) &&
|
---|
289 | (genMomentum.Pt() > DET->TRACK_ptmin ) && // pt too small to be taken into account
|
---|
290 | ((rand()%100) < DET->TRACK_eff) &&
|
---|
291 | (charge!=0)
|
---|
292 | )
|
---|
293 | {
|
---|
294 | elementTracks = (TRootTracks*) branchTracks->NewEntry();
|
---|
295 | elementTracks->Set(genMomentum);
|
---|
296 | TrackCentral.push_back(genMomentum);
|
---|
297 | }
|
---|
298 |
|
---|
299 | } // switch
|
---|
300 |
|
---|
301 | if(DET->FLAG_vfd==1)
|
---|
302 | {
|
---|
303 | VFD->ZDC(treeWriter,branchZDC,particle);
|
---|
304 | VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
|
---|
305 | }
|
---|
306 |
|
---|
307 | } // while
|
---|
308 |
|
---|
309 | DET->SortedVector(electron);
|
---|
310 | for(unsigned int i=0; i < electron.size(); i++) {
|
---|
311 | elementElec = (TRootElectron*) branchElectron->NewEntry();
|
---|
312 | elementElec->Set(electron[i].Px(),electron[i].Py(),electron[i].Pz(),electron[i].E());
|
---|
313 | elementElec->Charge = sign(electron[i].PID());
|
---|
314 | elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
|
---|
315 | }
|
---|
316 | DET->SortedVector(muon);
|
---|
317 | for(unsigned int i=0; i < muon.size(); i++) {
|
---|
318 | elementMu = (TRootMuon*) branchMuon->NewEntry();
|
---|
319 | elementMu->Charge = sign(muon[i].PID());
|
---|
320 | elementMu->Set(muon[i].Px(),muon[i].Py(),muon[i].Pz(),muon[i].E());
|
---|
321 | elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
|
---|
322 | }
|
---|
323 | DET->SortedVector(gamma);
|
---|
324 | for(unsigned int i=0; i < gamma.size(); i++) {
|
---|
325 | elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
|
---|
326 | elementPhoton->Set(gamma[i].Px(),gamma[i].Py(),gamma[i].Pz(),gamma[i].E());
|
---|
327 | }
|
---|
328 |
|
---|
329 | // computes the Missing Transverse Momentum
|
---|
330 | TLorentzVector Att(0.,0.,0.,0.);
|
---|
331 | for(unsigned int i=0; i < towers.size(); i++)
|
---|
332 | {
|
---|
333 | Att.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E);
|
---|
334 | PTmis = PTmis + Att;
|
---|
335 | }
|
---|
336 | elementEtmis = (TRootETmis*) branchETmis->NewEntry();
|
---|
337 | elementEtmis->ET = (PTmis).Pt();
|
---|
338 | elementEtmis->Phi = (-PTmis).Phi();
|
---|
339 | elementEtmis->Px = (-PTmis).Px();
|
---|
340 | elementEtmis->Py = (-PTmis).Py();
|
---|
341 |
|
---|
342 | //*****************************
|
---|
343 |
|
---|
344 | sorted_jets=JETRUN->RunJets(input_particles);
|
---|
345 | JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
|
---|
346 | JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
|
---|
347 |
|
---|
348 | // Add here the trigger
|
---|
349 | // Should test all the trigger table on the event, based on reconstructed objects
|
---|
350 | treeWriter->Fill();
|
---|
351 |
|
---|
352 | } // Loop over all events
|
---|
353 |
|
---|
354 | treeWriter->Write();
|
---|
355 | delete treeWriter;
|
---|
356 |
|
---|
357 | //running the trigger in case the FLAG trigger is put to 1 in the datacard
|
---|
358 |
|
---|
359 | if(DET->FLAG_trigger == 1)
|
---|
360 | {
|
---|
361 | TChain chainT("Analysis");
|
---|
362 | chainT.Add(outputfilename.c_str());
|
---|
363 | ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
|
---|
364 |
|
---|
365 | TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
|
---|
366 | TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
|
---|
367 | TClonesArray *branchJetTrig = treeReaderT->UseBranch("Jet");
|
---|
368 | TClonesArray *branchTauJetTrig = treeReaderT->UseBranch("TauJet");
|
---|
369 | TClonesArray *branchPhotonTrig = treeReaderT->UseBranch("Photon");
|
---|
370 | TClonesArray *branchETmisTrig = treeReaderT->UseBranch("ETmis");
|
---|
371 |
|
---|
372 | ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
|
---|
373 | ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
|
---|
374 |
|
---|
375 | Long64_t entryT, allEntriesT = treeReaderT->GetEntries();
|
---|
376 | cout << "** Chain contains " << allEntriesT << " events" << endl;
|
---|
377 | for(entryT = 0; entryT < allEntriesT; ++entryT)
|
---|
378 | {
|
---|
379 | treeWriterT->Clear();
|
---|
380 | treeReaderT->ReadEntry(entryT);
|
---|
381 | TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
|
---|
382 | treeWriterT->Fill();
|
---|
383 | }
|
---|
384 |
|
---|
385 | treeWriterT->Write();
|
---|
386 | delete treeWriterT;
|
---|
387 | }
|
---|
388 |
|
---|
389 | //FROG display
|
---|
390 | if(DET->FLAG_frog == 1)
|
---|
391 | {
|
---|
392 | FrogDisplay *FROG = new FrogDisplay();
|
---|
393 | FROG->BuidEvents(outputfilename,DET->NEvents_Frog);
|
---|
394 | FROG->BuildGeom();
|
---|
395 | }
|
---|
396 |
|
---|
397 | cout << "** Exiting..." << endl;
|
---|
398 |
|
---|
399 | delete treeReader;
|
---|
400 | delete DET;
|
---|
401 | delete TRIGT;
|
---|
402 | delete TRACP;
|
---|
403 | delete JETRUN;
|
---|
404 | delete VFD;
|
---|
405 |
|
---|
406 | if(converter) delete converter;
|
---|
407 |
|
---|
408 | todo("TODO");
|
---|
409 | }
|
---|
410 |
|
---|