Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 71

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

iEta et iPhi. Verification non complete.

File size: 13.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"
[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
[71]97 //Trigger *TRIG = new Trigger();
98 //TRIG->TriggerReader("data/trigger.dat");
[55]99
100 //Propagation of tracks in the B field
101 TrackPropagation *TRACP = new TrackPropagation();
102
103 //Jet information
104 JetsUtil *JETRUN = new JetsUtil();
105
106 //VFD information
107 VeryForward * VFD = new VeryForward();
108
109 //todo(LogName.c_str());
[2]110
111 DataConverter *converter=0;
112
113 if(strstr(line.c_str(),".hep"))
114 {
[44]115 cout<<"#**********************************************************************"<<endl;
116 cout<<"#********** StdHEP file format detected *************"<<endl;
117 cout<<"#*********** Starting convertion to TRoot format **************"<<endl;
118 cout<<"#**********************************************************************"<<endl;
[2]119 converter = new STDHEPConverter(inputFileList,outputfilename);//case ntpl file in input list
120 }
121 else if(strstr(line.c_str(),".lhe"))
122 {
[44]123 cout<<"#**********************************************************************"<<endl;
124 cout<<"#*********** LHEF file format detected ************"<<endl;
125 cout<<"#*********** Starting convertion to TRoot format ************"<<endl;
126 cout<<"#**********************************************************************"<<endl;
[2]127 converter = new LHEFConverter(inputFileList,outputfilename);//case ntpl file in input list
128 }
129 else if(strstr(line.c_str(),".root"))
130 {
[44]131 cout<<"#**********************************************************************"<<endl;
132 cout<<"#********** h2root file format detected *************"<<endl;
133 cout<<"#********** Starting convertion to TRoot format *************"<<endl;
134 cout<<"#**********************************************************************"<<endl;
[2]135 converter = new HEPEVTConverter(inputFileList,outputfilename);//case ntpl file in input list
136 }
137 else { cout << "*** " << line.c_str() << "\n*** file format not identified\n*** Exiting\n"; return -1;};
[30]138
[2]139 TChain chain("GEN");
140 chain.Add(outputfilename.c_str());
141 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
142 const TClonesArray *branchGen = treeReader->UseBranch("Particle");
143 TIter itGen((TCollection*)branchGen);
144
145 //write the output root file
146 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
147 ExRootTreeBranch *branchJet = treeWriter->NewBranch("Jet", TRootJet::Class());
148 ExRootTreeBranch *branchTauJet = treeWriter->NewBranch("TauJet", TRootTauJet::Class());
149 ExRootTreeBranch *branchElectron = treeWriter->NewBranch("Electron", TRootElectron::Class());
150 ExRootTreeBranch *branchMuon = treeWriter->NewBranch("Muon", TRootMuon::Class());
151 ExRootTreeBranch *branchPhoton = treeWriter->NewBranch("Photon", TRootPhoton::Class());
152 ExRootTreeBranch *branchTracks = treeWriter->NewBranch("Tracks", TRootTracks::Class());
153 ExRootTreeBranch *branchETmis = treeWriter->NewBranch("ETmis", TRootETmis::Class());
154 ExRootTreeBranch *branchCalo = treeWriter->NewBranch("CaloTower", TRootCalo::Class());
155 ExRootTreeBranch *branchZDC = treeWriter->NewBranch("ZDChits", TRootZdcHits::Class());
156 ExRootTreeBranch *branchRP220 = treeWriter->NewBranch("RP220hits", TRootRomanPotHits::Class());
157 ExRootTreeBranch *branchFP420 = treeWriter->NewBranch("FP420hits", TRootRomanPotHits::Class());
[30]158
159
[2]160 TRootGenParticle *particle;
161 TRootETmis *elementEtmis;
162 TRootElectron *elementElec;
163 TRootMuon *elementMu;
164 TRootPhoton *elementPhoton;
165 TRootTracks *elementTracks;
166 TRootCalo *elementCalo;
167
168 TLorentzVector genMomentum(0,0,0,0);
[38]169 TLorentzVector genMomentumCalo(0,0,0,0);
[2]170 LorentzVector jetMomentum;
[55]171
172 vector<fastjet::PseudoJet> input_particles;//for FastJet algorithm
173 vector<fastjet::PseudoJet> sorted_jets;
174
[2]175 vector<TLorentzVector> TrackCentral;
176 vector<PhysicsTower> towers;
[11]177
[30]178 vector<TLorentzVector> electron;
179 vector<int> elecPID;
180 vector<TLorentzVector> muon;
181 vector<int> muonPID;
182 TSimpleArray<TRootGenParticle> NFCentralQ;
183
[55]184
185
[30]186 // Loop over all events
[2]187 Long64_t entry, allEntries = treeReader->GetEntries();
188 cout << "** Chain contains " << allEntries << " events" << endl;
189 for(entry = 0; entry < allEntries; ++entry)
190 {
191 TLorentzVector PTmis(0,0,0,0);
192 treeReader->ReadEntry(entry);
193 treeWriter->Clear();
194 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
195
[30]196 electron.clear();
197 muon.clear();
198 elecPID.clear();
199 muonPID.clear();
200 NFCentralQ.Clear();
201
[2]202 itGen.Reset();
203 TrackCentral.clear();
204 towers.clear();
[11]205 input_particles.clear();
[30]206
[2]207 // Loop over all particles in event
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());
[55]232 switch(pid) {
[30]233
234 case pE: // all electrons with eta < DET->MAX_CALO_FWD
235 DET->SmearElectron(genMomentum);
236 electron.push_back(genMomentum);
237 elecPID.push_back(particle->PID);
238 break; // case pE
239 case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD
240 DET->SmearElectron(genMomentum);
241 if(genMomentum.E()!=0 && eta < DET->MAX_TRACKER) {
242 elementPhoton = (TRootPhoton*) branchPhoton->NewEntry();
243 elementPhoton->Set(genMomentum);
244 }
245 break; // case pGAMMA
246 case pMU: // all muons with eta < DET->MAX_MU
247 DET->SmearMu(genMomentum);
248 muonPID.push_back(particle->PID);
249 muon.push_back(genMomentum);
250 break; // case pMU
251 case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD
252 case pK0S: // all K0s with eta < DET->MAX_CALO_FWD
253 DET->SmearHadron(genMomentum, 0.7);
254 break; // case hadron
255 default: // all other final particles with eta < DET->MAX_CALO_FWD
256 DET->SmearHadron(genMomentum, 1.0);
257 break;
258 } // switch (pid)
[59]259
[30]260 // all final particles but muons and neutrinos
261 // for calorimetric towers and mission PT
[43]262
263 if(genMomentum.E() !=0) {
[30]264 if(pid !=pMU) {
[38]265 PhysicsTower CaloTower = PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
266 towers.push_back(CaloTower);
[30]267 // create a fastjet::PseudoJet with these components and put it onto
268 // back of the input_particles vector
269 input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
[71]270
[38]271 genMomentumCalo.SetPxPyPzE(CaloTower.fourVector.px,CaloTower.fourVector.py,CaloTower.fourVector.pz,CaloTower.fourVector.E);
[30]272 elementCalo = (TRootCalo*) branchCalo->NewEntry();
[38]273 elementCalo->Set(genMomentumCalo);
[71]274 DET->BinEtaPhi(genMomentumCalo.Phi(), genMomentumCalo.Eta(), elementCalo->Phi, elementCalo->Eta);
[30]275 }
276 }
277
278 // all final charged particles
279 if(
280 ((rand()%100) < DET->TRACKING_EFF) &&
281 (genMomentum.E()!=0) &&
[55]282 (fabs(genMomentum.Eta()) < DET->MAX_TRACKER) &&
[30]283 (genMomentum.Pt() > DET->PT_TRACKS_MIN ) && // pt too small to be taken into account
284 (pid != pGAMMA) &&
285 (pid != pPI0) &&
286 (pid != pK0L) &&
287 (pid != pN) &&
288 (pid != pSIGMA0) &&
289 (pid != pDELTA0) &&
290 (pid != pK0S) // not charged particles : invisible by tracker
291 )
292 {
293 elementTracks = (TRootTracks*) branchTracks->NewEntry();
294 elementTracks->Set(genMomentum);
295 TrackCentral.push_back(genMomentum);
296 }
[59]297
[49]298 } // switch
[30]299
[55]300 VFD->ZDC(treeWriter,branchZDC,particle);
301 VFD->RomanPots(treeWriter,branchRP220,branchFP420,particle);
[11]302
[2]303 } // while
[71]304
[30]305 for(unsigned int i=0; i < electron.size(); i++) {
[33]306 if(electron[i].E()!=0 && fabs(electron[i].Eta()) < DET->MAX_TRACKER && electron[i].Pt() > DET->ELEC_pt)
[30]307 {
308 elementElec = (TRootElectron*) branchElectron->NewEntry();
309 elementElec->Set(electron[i]);
310 elementElec->Charge = sign(elecPID[i]);
311 elementElec->IsolFlag = DET->Isolation(electron[i].Phi(),electron[i].Eta(),TrackCentral,2.0);
312 }
313 }
314 for(unsigned int i=0; i < muon.size(); i++) {
[33]315 if(muon[i].E()!=0 && fabs(muon[i].Eta()) < DET->MAX_MU && muon[i].Pt() > DET->MUON_pt)
[30]316 {
317 elementMu = (TRootMuon*) branchMuon->NewEntry();
318 elementMu->Charge = sign(muonPID[i]);
319 elementMu->Set(muon[i]);
320 elementMu->IsolFlag = DET->Isolation(muon[i].Phi(),muon[i].Eta(),TrackCentral,2.0);
321 }
322 }
323
[71]324 // computes the Missing Transverse Momentum
325 TLorentzVector Att(0.,0.,0.,0.);
326 for(unsigned int i=0; i < towers.size(); i++)
327 {
328 Att.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E);
329 PTmis = PTmis + Att;
330 }
331 elementEtmis = (TRootETmis*) branchETmis->NewEntry();
332 elementEtmis->ET = (PTmis).Pt();
333 elementEtmis->Phi = (-PTmis).Phi();
334 elementEtmis->Px = (-PTmis).Px();
335 elementEtmis->Py = (-PTmis).Py();
336
337 //*****************************
338 treeWriter->Fill();
339
[55]340 sorted_jets=JETRUN->RunJets(input_particles);
341 JETRUN->RunJetBtagging(treeWriter, branchJet,sorted_jets,NFCentralQ);
342 JETRUN->RunTauJets(treeWriter,branchTauJet,sorted_jets,towers, TrackCentral);
343
[2]344 // Add here the trigger
345 // Should test all the trigger table on the event, based on reconstructed objects
[71]346
[2]347 } // Loop over all events
[71]348
[2]349 treeWriter->Write();
[70]350
[2]351 cout << "** Exiting..." << endl;
352
[71]353 delete treeWriter;
[2]354 delete treeReader;
355 delete DET;
356 if(converter) delete converter;
[71]357
[2]358 todo("TODO");
359}
360
Note: See TracBrowser for help on using the repository browser.