Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 76

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

remove add bug

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