Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 177

Last change on this file since 177 was 107, checked in by Xavier Rouby, 16 years ago

modifications FROG lyon

File size: 15.9 KB
Line 
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
36using namespace std;
37
38//------------------------------------------------------------------------------
39void 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
52int 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(DetDatacard);
108
109 //Jet information
110 JetsUtil *JETRUN = new JetsUtil(DetDatacard);
111
112 //VFD information
113 VeryForward * VFD = new VeryForward(DetDatacard);
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
188 TSimpleArray<TRootGenParticle> NFCentralQ;
189
190
191 float iPhi=0,iEta=0;
192
193 // Loop over all events
194 Long64_t entry, allEntries = treeReader->GetEntries();
195 cout << "** Chain contains " << allEntries << " events" << endl;
196 for(entry = 0; entry < 200; ++entry)
197 {
198 TLorentzVector PTmis(0,0,0,0);
199 treeReader->ReadEntry(entry);
200 treeWriter->Clear();
201 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
202
203 electron.clear();
204 muon.clear();
205 gamma.clear();
206 NFCentralQ.Clear();
207
208 TrackCentral.clear();
209 towers.clear();
210 input_particles.clear();
211
212 // Loop over all particles in event
213 itGen.Reset();
214 while( (particle = (TRootGenParticle*) itGen.Next()) )
215 {
216 int pid = abs(particle->PID);
217 //// This subarray is needed for the B-jet algorithm
218 // optimization for speed : put first PID condition, then ETA condition, then either pt or status
219 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 ?
220 fabs(particle->Eta) < DET->CEN_max_tracker &&
221 particle->Status != 1 &&
222 particle->PT > DET->PT_QUARKS_MIN ) {
223 NFCentralQ.Add(particle);
224 }
225
226 // keeps only final particles, visible by the central detector, including the fiducial volume
227 // the ordering of conditions have been optimised for speed : put first the STATUS condition
228 //
229 //
230 if( (particle->Status == 1) &&
231 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
232 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
233 )
234 {
235 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
236 if(DET->FLAG_bfield==1)TRACP->Propagation(particle,genMomentum);
237 float eta=fabs(genMomentum.Eta());
238
239 switch(pid) {
240
241 case pE: // all electrons with eta < DET->MAX_CALO_FWD
242 DET->SmearElectron(genMomentum);
243 if(genMomentum.E()!=0 && eta < DET->CEN_max_tracker && genMomentum.Pt() > DET->PTCUT_elec){
244 electron.push_back(ParticleUtil(genMomentum,particle->PID));
245 }
246 break; // case pE
247 case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
248 DET->SmearElectron(genMomentum);
249 if(genMomentum.E()!=0 && eta < DET->CEN_max_tracker && genMomentum.Pt() > DET->PTCUT_gamma) {
250 gamma.push_back(ParticleUtil(genMomentum,particle->PID));
251 }
252 break; // case pGAMMA
253 case pMU: // all muons with eta < DET->MAX_MU
254 DET->SmearMu(genMomentum);
255 if(genMomentum.E()!=0 && eta < DET->CEN_max_mu && genMomentum.Pt() > DET->PTCUT_muon){
256 muon.push_back(ParticleUtil(genMomentum,particle->PID));
257 }
258 break; // case pMU
259 case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
260 case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
261 DET->SmearHadron(genMomentum, 0.7);
262 break; // case hadron
263 default: // all other final particles with eta < DET->MAX_CALO_FWD
264 DET->SmearHadron(genMomentum, 1.0);
265 break;
266 } // switch (pid)
267
268 // all final particles but muons and neutrinos
269 // for calorimetric towers and missing PT
270 int charge=Charge(pid);
271 if(genMomentum.E() !=0 && pid != pMU) {
272 if(charge == 0 || (charge !=0 && genMomentum.Pt() >= DET->TRACK_ptmin)){
273 DET->BinEtaPhi(genMomentum.Phi(), genMomentum.Eta(), iPhi, iEta);
274 if(iEta != -100 && iPhi != -100)
275 {
276 genMomentumCalo.SetPtEtaPhiE(genMomentum.Pt(),iEta,iPhi,genMomentum.E());
277 elementCalo = (TRootCalo*) branchCalo->NewEntry();
278 elementCalo->Set(genMomentumCalo);
279
280// CalTower myCaloTower(genMomentumCalo.Et,genMomentumCalo.Eta,genMomentumCalo.Phi,iEta,iPhi);
281// PhysicsTower Tower(LorentzVector(genMomentumCalo.Px(),genMomentumCalo.Py(),genMomentumCalo.Pz(), genMomentumCalo.E()),myCaloTower);
282 PhysicsTower Tower(LorentzVector(genMomentumCalo.Px(),genMomentumCalo.Py(),genMomentumCalo.Pz(), genMomentumCalo.E()));
283 towers.push_back(Tower);
284 }
285 }
286 }
287
288 // all final charged particles
289 if(
290 (genMomentum.E()!=0) &&
291 (fabs(genMomentum.Eta()) < DET->CEN_max_tracker) &&
292 (genMomentum.Pt() > DET->TRACK_ptmin ) && // pt too small to be taken into account
293 ((rand()%100) < DET->TRACK_eff) &&
294 (charge!=0)
295 )
296 {
297 elementTracks = (TRootTracks*) branchTracks->NewEntry();
298 elementTracks->Set(genMomentum);
299 TrackCentral.push_back(genMomentum);
300 }
301
302 } // switch
303
304 if(DET->FLAG_vfd==1)
305 {
306 VFD->ZDC(treeWriter,branchZDC,particle);
307 VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
308 }
309
310 } // while
311
312 DET->SortedVector(electron);
313 for(unsigned int i=0; i < electron.size(); i++) {
314 elementElec = (TRootElectron*) branchElectron->NewEntry();
315 elementElec->Set(electron[i].Px(),electron[i].Py(),electron[i].Pz(),electron[i].E());
316 elementElec->Charge = sign(electron[i].PID());
317 elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
318 }
319 DET->SortedVector(muon);
320 for(unsigned int i=0; i < muon.size(); i++) {
321 elementMu = (TRootMuon*) branchMuon->NewEntry();
322 elementMu->Charge = sign(muon[i].PID());
323 elementMu->Set(muon[i].Px(),muon[i].Py(),muon[i].Pz(),muon[i].E());
324 elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
325 }
326 DET->SortedVector(gamma);
327 for(unsigned int i=0; i < gamma.size(); i++) {
328 elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
329 elementPhoton->Set(gamma[i].Px(),gamma[i].Py(),gamma[i].Pz(),gamma[i].E());
330 }
331
332 // computes the Missing Transverse Momentum
333 TLorentzVector Att(0.,0.,0.,0.);
334 for(unsigned int i=0; i < towers.size(); i++)
335 {
336 Att.SetPxPyPzE(towers[i].fourVector.px, towers[i].fourVector.py, towers[i].fourVector.pz, towers[i].fourVector.E);
337 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
338 {
339 PTmis = PTmis + Att;
340 // create a fastjet::PseudoJet with these components and put it onto
341 // back of the input_particles vector
342 input_particles.push_back(fastjet::PseudoJet(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E));
343 }
344 }
345 elementEtmis = (TRootETmis*) branchETmis->NewEntry();
346 elementEtmis->ET = (PTmis).Pt();
347 elementEtmis->Phi = (-PTmis).Phi();
348 elementEtmis->Px = (-PTmis).Px();
349 elementEtmis->Py = (-PTmis).Py();
350
351 //*****************************
352
353 sorted_jets=JETRUN->RunJets(input_particles);
354 JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
355 JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
356
357 // Add here the trigger
358 // Should test all the trigger table on the event, based on reconstructed objects
359 treeWriter->Fill();
360
361 } // Loop over all events
362
363 treeWriter->Write();
364 delete treeWriter;
365
366 //running the trigger in case the FLAG trigger is put to 1 in the datacard
367
368 if(DET->FLAG_trigger == 1)
369 {
370 TChain chainT("Analysis");
371 chainT.Add(outputfilename.c_str());
372 ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
373
374 TClonesArray *branchElecTrig = treeReaderT->UseBranch("Electron");
375 TClonesArray *branchMuonTrig = treeReaderT->UseBranch("Muon");
376 TClonesArray *branchJetTrig = treeReaderT->UseBranch("Jet");
377 TClonesArray *branchTauJetTrig = treeReaderT->UseBranch("TauJet");
378 TClonesArray *branchPhotonTrig = treeReaderT->UseBranch("Photon");
379 TClonesArray *branchETmisTrig = treeReaderT->UseBranch("ETmis");
380
381 ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
382 ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
383
384 Long64_t entryT, allEntriesT = treeReaderT->GetEntries();
385 cout << "** Chain contains " << allEntriesT << " events" << endl;
386 for(entryT = 0; entryT < allEntriesT; ++entryT)
387 {
388 treeWriterT->Clear();
389 treeReaderT->ReadEntry(entryT);
390 TRIGT->GetGlobalResult(branchElecTrig, branchMuonTrig,branchJetTrig, branchTauJetTrig,branchPhotonTrig, branchETmisTrig,branchTrigger);
391 treeWriterT->Fill();
392 }
393
394 treeWriterT->Write();
395 delete treeWriterT;
396 }
397
398 //FROG display
399 if(DET->FLAG_frog == 1)
400 {
401 FrogDisplay *FROG = new FrogDisplay();
402 FROG->BuidEvents(outputfilename,DET->NEvents_Frog);
403 FROG->BuildGeom(DetDatacard);
404 }
405
406 cout << "** Exiting..." << endl;
407
408 delete treeReader;
409 delete DET;
410 delete TRIGT;
411 delete TRACP;
412 delete JETRUN;
413 delete VFD;
414
415 if(converter) delete converter;
416
417 todo("TODO");
418}
419
Note: See TracBrowser for help on using the repository browser.