Fork me on GitHub

source: svn/trunk/Delphes.cpp@ 65

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

remove fill bug

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