Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 111

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

modifications FROG lyon

File size: 15.9 KB
RevLine 
[2]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"
[55]27#include "interface/BFieldProp.h"
28#include "interface/TriggerUtil.h"
29#include "interface/VeryForward.h"
30#include "interface/JetUtils.h"
[94]31#include "interface/FrogUtil.h"
[2]32
[55]33#include <vector>
34#include <iostream>
[11]35
[2]36using namespace std;
37
38//------------------------------------------------------------------------------
39void todo(string filename) {
40 ifstream infile(filename.c_str());
41 cout << "** TODO list ..." << endl;
42 while(infile.good()) {
[94]43 string temp;
44 getline(infile,temp);
45 cout << "*" << temp << endl;
[2]46 }
47 cout << "** done...\n";
48}
49
50//------------------------------------------------------------------------------
51
52int main(int argc, char *argv[])
53{
54 int appargc = 2;
[55]55 char *appName = "Delphes";
[2]56 char *appargv[] = {appName, "-b"};
57 TApplication app(appName, &appargc, appargv);
[94]58
[71]59 if(argc != 4 && argc != 3 && argc != 5) {
[94]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);
[2]66 }
[94]67
[2]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() ) {
[94]73 cout << "output_file should be a .root file!\n";
74 exit(1);
[2]75 }
[44]76 //create output log-file name
[45]77 string forLog = outputfilename;
78 string LogName = forLog.erase(forLog.find(".root"));
[44]79 LogName = LogName+"_run.log";
[94]80
[2]81 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
82 outputFile->Close();
[94]83
[2]84 string line;
85 ifstream infile(inputFileList.c_str());
86 infile >> line; // the first line determines the type of input files
[94]87
[44]88 //read the datacard input file
89 string DetDatacard("");
[94]90 if(argc>=4) DetDatacard =argv[3];
91
[55]92 //Smearing information
[44]93 RESOLution *DET = new RESOLution();
94 DET->ReadDataCard(DetDatacard);
95 DET->Logfile(LogName);
[94]96
[79]97 //read the trigger input file
[80]98 string TrigDatacard("data/trigger.dat");
[79]99 if(argc==5) TrigDatacard =argv[4];
[94]100
[55]101 //Trigger information
[72]102 TriggerTable *TRIGT = new TriggerTable();
[80]103 TRIGT->TriggerCardReader(TrigDatacard.c_str());
[72]104 TRIGT->PrintTriggerTable(LogName);
[94]105
[55]106 //Propagation of tracks in the B field
[100]107 TrackPropagation *TRACP = new TrackPropagation(DetDatacard);
[94]108
[55]109 //Jet information
[100]110 JetsUtil *JETRUN = new JetsUtil(DetDatacard);
[94]111
[55]112 //VFD information
[100]113 VeryForward * VFD = new VeryForward(DetDatacard);
[94]114
[55]115 //todo(LogName.c_str());
[94]116
[2]117 DataConverter *converter=0;
[94]118
[2]119 if(strstr(line.c_str(),".hep"))
120 {
[44]121 cout<<"#**********************************************************************"<<endl;
122 cout<<"#********** StdHEP file format detected *************"<<endl;
123 cout<<"#*********** Starting convertion to TRoot format **************"<<endl;
124 cout<<"#**********************************************************************"<<endl;
[2]125 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
126 }
127 else if(strstr(line.c_str(),".lhe"))
128 {
[44]129 cout<<"#**********************************************************************"<<endl;
130 cout<<"#*********** LHEF file format detected ************"<<endl;
131 cout<<"#*********** Starting convertion to TRoot format ************"<<endl;
132 cout<<"#**********************************************************************"<<endl;
[2]133 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
134 }
135 else if(strstr(line.c_str(),".root"))
136 {
[44]137 cout<<"#**********************************************************************"<<endl;
138 cout<<"#********** h2root file format detected *************"<<endl;
139 cout<<"#********** Starting convertion to TRoot format *************"<<endl;
140 cout<<"#**********************************************************************"<<endl;
[2]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;};
[30]144
[2]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());
[30]164
165
[2]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);
[38]175 TLorentzVector genMomentumCalo(0,0,0,0);
[2]176 LorentzVector jetMomentum;
[94]177
[55]178 vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
179 vector<fastjet::PseudoJet> sorted_jets;
[94]180
[2]181 vector<TLorentzVector> TrackCentral;
182 vector<PhysicsTower> towers;
[11]183
[73]184 vector<ParticleUtil> electron;
185 vector<ParticleUtil> muon;
[74]186 vector<ParticleUtil> gamma;
[98]187
[30]188 TSimpleArray<TRootGenParticle> NFCentralQ;
189
[94]190
[100]191 float iPhi=0,iEta=0;
192
[30]193 // Loop over all events
[2]194 Long64_t entry, allEntries = treeReader->GetEntries();
195 cout << "** Chain contains " << allEntries << " events" << endl;
[107]196 for(entry = 0; entry < 200; ++entry)
[2]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
[30]203 electron.clear();
204 muon.clear();
[74]205 gamma.clear();
[30]206 NFCentralQ.Clear();
207
[2]208 TrackCentral.clear();
209 towers.clear();
[11]210 input_particles.clear();
[30]211
[2]212 // Loop over all particles in event
[74]213 itGen.Reset();
[2]214 while( (particle = (TRootGenParticle*) itGen.Next()) )
215 {
[55]216 int pid = abs(particle->PID);
[94]217 //// This subarray is needed for the B-jet algorithm
[2]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 ?
[94]220 fabs(particle->Eta) < DET->CEN_max_tracker &&
[2]221 particle->Status != 1 &&
222 particle->PT > DET->PT_QUARKS_MIN ) {
223 NFCentralQ.Add(particle);
224 }
[94]225
[2]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
[55]228 //
229 //
[2]230 if( (particle->Status == 1) &&
[59]231 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
[94]232 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
233 )
[59]234 {
[94]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());
[30]238
[94]239 switch(pid) {
[74]240
[94]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
[100]269 // for calorimetric towers and missing PT
[94]270 int charge=Charge(pid);
271 if(genMomentum.E() !=0 && pid != pMU) {
272 if(charge == 0 || (charge !=0 && genMomentum.Pt() >= DET->TRACK_ptmin)){
[100]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 }
[94]285 }
[30]286 }
[94]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
[74]302 } // switch
[30]303
[94]304 if(DET->FLAG_vfd==1)
305 {
[100]306 VFD->ZDC(treeWriter,branchZDC,particle);
307 VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
[94]308 }
[11]309
[2]310 } // while
[71]311
[74]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);
[30]318 }
[74]319 DET->SortedVector(muon);
[30]320 for(unsigned int i=0; i < muon.size(); i++) {
[74]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);
[30]325 }
[74]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 }
[30]331
[71]332 // computes the Missing Transverse Momentum
333 TLorentzVector Att(0.,0.,0.,0.);
334 for(unsigned int i=0; i < towers.size(); i++)
335 {
[107]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 }
[71]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();
[74]350
[71]351 //*****************************
352
[55]353 sorted_jets=JETRUN->RunJets(input_particles);
354 JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
355 JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
[74]356
[2]357 // Add here the trigger
358 // Should test all the trigger table on the event, based on reconstructed objects
[72]359 treeWriter->Fill();
[74]360
[2]361 } // Loop over all events
[74]362
[2]363 treeWriter->Write();
[77]364 delete treeWriter;
[94]365
[74]366 //running the trigger in case the FLAG trigger is put to 1 in the datacard
[94]367
368 if(DET->FLAG_trigger == 1)
[72]369 {
370 TChain chainT("Analysis");
371 chainT.Add(outputfilename.c_str());
372 ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
[74]373
[72]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");
[74]380
[72]381 ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
382 ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
[74]383
[72]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 }
[94]393
[72]394 treeWriterT->Write();
395 delete treeWriterT;
396 }
[94]397
398 //FROG display
399 if(DET->FLAG_frog == 1)
400 {
401 FrogDisplay *FROG = new FrogDisplay();
402 FROG->BuidEvents(outputfilename,DET->NEvents_Frog);
[98]403 FROG->BuildGeom(DetDatacard);
[94]404 }
405
[2]406 cout << "** Exiting..." << endl;
407
408 delete treeReader;
409 delete DET;
[74]410 delete TRIGT;
411 delete TRACP;
412 delete JETRUN;
413 delete VFD;
[94]414
[2]415 if(converter) delete converter;
[94]416
[2]417 todo("TODO");
418}
419
Note: See TracBrowser for help on using the repository browser.