Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 97

Last change on this file since 97 was 94, checked in by severine ovyn, 16 years ago

Add frog plus cleaning + bugs remove

File size: 15.4 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
107 TrackPropagation *TRACP = new TrackPropagation();
[94]108
[55]109 //Jet information
110 JetsUtil *JETRUN = new JetsUtil();
[94]111
[55]112 //VFD information
113 VeryForward * VFD = new VeryForward();
[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;
[30]187 TSimpleArray<TRootGenParticle> NFCentralQ;
188
[94]189
190
[30]191 // Loop over all events
[2]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
[30]201 electron.clear();
202 muon.clear();
[74]203 gamma.clear();
[30]204 NFCentralQ.Clear();
205
[2]206 TrackCentral.clear();
207 towers.clear();
[11]208 input_particles.clear();
[30]209
[2]210 // Loop over all particles in event
[74]211 itGen.Reset();
[2]212 while( (particle = (TRootGenParticle*) itGen.Next()) )
213 {
[55]214 int pid = abs(particle->PID);
[94]215 //// This subarray is needed for the B-jet algorithm
[2]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 ?
[94]218 fabs(particle->Eta) < DET->CEN_max_tracker &&
[2]219 particle->Status != 1 &&
220 particle->PT > DET->PT_QUARKS_MIN ) {
221 NFCentralQ.Add(particle);
222 }
[94]223
[2]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
[55]226 //
227 //
[2]228 if( (particle->Status == 1) &&
[59]229 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
[94]230 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
231 )
[59]232 {
[94]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());
[30]236
[94]237 switch(pid) {
[74]238
[94]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 }
[30]283 }
[94]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
[74]299 } // switch
[30]300
[94]301 if(DET->FLAG_vfd==1)
302 {
303 VFD->ZDC(treeWriter,branchZDC,particle);
304 VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
305 }
[11]306
[2]307 } // while
[71]308
[74]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);
[30]315 }
[74]316 DET->SortedVector(muon);
[30]317 for(unsigned int i=0; i < muon.size(); i++) {
[74]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);
[30]322 }
[74]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 }
[30]328
[71]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();
[74]341
[71]342 //*****************************
343
[55]344 sorted_jets=JETRUN->RunJets(input_particles);
345 JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
346 JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
[74]347
[2]348 // Add here the trigger
349 // Should test all the trigger table on the event, based on reconstructed objects
[72]350 treeWriter->Fill();
[74]351
[2]352 } // Loop over all events
[74]353
[2]354 treeWriter->Write();
[77]355 delete treeWriter;
[94]356
[74]357 //running the trigger in case the FLAG trigger is put to 1 in the datacard
[94]358
359 if(DET->FLAG_trigger == 1)
[72]360 {
361 TChain chainT("Analysis");
362 chainT.Add(outputfilename.c_str());
363 ExRootTreeReader *treeReaderT = new ExRootTreeReader(&chainT);
[74]364
[72]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");
[74]371
[72]372 ExRootTreeWriter *treeWriterT = new ExRootTreeWriter(outputfilename, "Trigger");
373 ExRootTreeBranch *branchTrigger = treeWriterT->NewBranch("TrigResult", TRootTrigger::Class());
[74]374
[72]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 }
[94]384
[72]385 treeWriterT->Write();
386 delete treeWriterT;
387 }
[94]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
[2]397 cout << "** Exiting..." << endl;
398
399 delete treeReader;
400 delete DET;
[74]401 delete TRIGT;
402 delete TRACP;
403 delete JETRUN;
404 delete VFD;
[94]405
[2]406 if(converter) delete converter;
[94]407
[2]408 todo("TODO");
409}
410
Note: See TracBrowser for help on using the repository browser.