Fork me on GitHub

source: svn/trunk/Resolutions_ATLAS.cpp@ 472

Last change on this file since 472 was 469, checked in by Xavier Rouby, 15 years ago

property 'invisible()' added to PdgParticle

File size: 18.7 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \------------- arXiv:0903.2225v1 ------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** ROOT: Nucl. Inst. & Meth. in Phys. Res. A389 (1997) 81-86 **
12** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
13** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
14** FROG: [hep-ex/0901.2718v1] **
15** HepMC: Comput. Phys. Commun.134 (2001) 41 **
16** **
17** ------------------------------------------------------------------ **
18** **
19** Main authors: **
20** ------------- **
21** **
22** Severine Ovyn Xavier Rouby **
23** severine.ovyn@uclouvain.be xavier.rouby@cern **
24** **
25** Center for Particle Physics and Phenomenology (CP3) **
26** Universite catholique de Louvain (UCL) **
27** Louvain-la-Neuve, Belgium **
28** **
29** Copyright (C) 2008-2009, **
30** All rights reserved. **
31** **
32***********************************************************************/
33
34/// \file Resolution_ATLAS.cpp
35/// \brief Resolution for Atlas
36
37#include "TChain.h"
38#include "TApplication.h"
39#include "TFile.h"
40#include "TStopwatch.h"
41
42#include "ExRootTreeReader.h"
43#include "ExRootTreeWriter.h"
44#include "ExRootTreeBranch.h"
45#include "ExRootProgressBar.h"
46#include "TreeClasses.h"
47
48#include "SmearUtil.h"
49#include "JetsUtil.h"
50#include "BFieldProp.h"
51#include "PdgParticle.h"
52
53#include<vector>
54#include<iostream>
55
56using namespace std;
57
58//------------------------------------------------------------------------------
59
60// //********************************** PYTHIA INFORMATION*********************************
61
62TSimpleArray<TRootGenParticle> TauHadr(const TClonesArray *GEN)
63 {
64 TIter it((TCollection*)GEN);
65 it.Reset();
66 TRootGenParticle *gen1;
67 TSimpleArray<TRootGenParticle> array,array2;
68
69 while((gen1 = (TRootGenParticle*) it.Next()))
70 {
71 array.Add(gen1);
72 }
73 it.Reset();
74 bool tauhad;
75 while((gen1 = (TRootGenParticle*) it.Next()))
76 {
77 tauhad=false;
78 if(abs(gen1->PID)==15)
79 {
80 int d1=gen1->D1;
81 int d2=gen1->D2;
82 if((d1 < array.GetEntries()) && (d1 > 0) && (d2 < array.GetEntries()) && (d2 > 0))
83 {
84 tauhad=true;
85 for(int d=d1; d < d2+1; d++)
86 {
87 if(abs(array[d]->PID)== pE || abs(array[d]->PID)== pMU)tauhad=false;
88 }
89 }
90 }
91 if(tauhad)array2.Add(gen1);
92 }
93 return array2;
94 }
95
96double EnergySmallCone(const vector<TLorentzVector> &towers, const float eta, const float phi,float energy_scone,float JET_seed) {
97 double Energie=0;
98 for(unsigned int i=0; i < towers.size(); i++) {
99 if(towers[i].Pt() < JET_seed) continue;
100 if((DeltaR(phi,eta,towers[i].Phi(),towers[i].Eta()) < energy_scone)) {
101 Energie += towers[i].E();
102 }
103 }
104 return Energie;
105}
106
107
108void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, const TClonesArray *branchJet, const float dR=0.25)
109{
110 JETSm.SetPxPyPzE(0,0,0,0);
111 float deltaRtest=5000;
112 TIter itJet((TCollection*)branchJet);
113 TRootJet *jet;
114 itJet.Reset();
115 while( (jet = (TRootJet*) itJet.Next()) )
116 {
117 TLorentzVector Att;
118 Att.SetPtEtaPhiE(jet->PT,jet->Eta,jet->Phi,jet->E);
119 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
120 {
121 deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
122 if(deltaRtest < dR)
123 {
124 JETSm = Att;
125 }
126 }
127 }
128}
129
130void PairingElec(TLorentzVector &ELECSm, const TLorentzVector &ELEC, const TClonesArray *branchElec)
131{
132 ELECSm.SetPxPyPzE(0,0,0,0);
133 float deltaRtest=5000;
134 TIter itElec((TCollection*)branchElec);
135 TRootElectron *elec;
136 itElec.Reset();
137 while( (elec = (TRootElectron*) itElec.Next()) )
138 {
139 TLorentzVector Att;
140 Att.SetPtEtaPhiE(elec->PT,elec->Eta,elec->Phi,elec->E);
141 if(DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
142 {
143 deltaRtest = DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta());
144 if(deltaRtest < 0.025)
145 {
146 ELECSm = Att;
147 }
148 }
149 }
150}
151
152void PairingMuon(TLorentzVector &MUONSm, const TLorentzVector &MUON, const TClonesArray *branchMuon)
153{
154 MUONSm.SetPxPyPzE(0,0,0,0);
155 float deltaRtest=5000;
156 TIter itMuon((TCollection*)branchMuon);
157 TRootMuon *muon;
158 itMuon.Reset();
159 while( (muon = (TRootMuon*) itMuon.Next()) )
160 {
161 TLorentzVector Att;
162 Att.SetPxPyPzE(muon->Px,muon->Py,muon->Pz,muon->E);
163 if(DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
164 {
165 deltaRtest = DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta());
166 if(deltaRtest < 0.025)
167 {
168 MUONSm = Att;
169 }
170 }
171 }
172}
173
174unsigned int NumTracks(const TClonesArray *branchTracks, const float pt_track, const float eta, const float phi,float track_scone) {
175 unsigned int numtrack=0;
176 TIter itTrack((TCollection*)branchTracks);
177 TRootTracks *track;
178 itTrack.Reset();
179 while( (track = (TRootTracks*) itTrack.Next()) )
180 {
181 if((track->PT < pt_track )||
182 (DeltaR(phi,eta,track->Phi,track->Eta) > track_scone)
183 )continue;
184 numtrack++;
185 }
186 return numtrack;
187}
188
189
190
191int main(int argc, char *argv[])
192{
193 int appargc = 2;
194 char *appName= new char[20];
195 char *appOpt= new char[20];
196 sprintf(appName,"Resolution_ATLAS");
197 sprintf(appOpt,"-b");
198 char *appargv[] = {appName,appOpt};
199 TApplication app(appName, &appargc, appargv);
200 delete [] appName;
201 delete [] appOpt;
202
203 if(argc != 3) {
204 cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl;
205 cout << " input_file - input file in Delphes-root format," << endl;
206 cout << " output_file - output file." << endl;
207 exit(1);
208 }
209
210
211 // 1. ********** initialisation ***********
212
213 srand (time (NULL));
214 TStopwatch globalwatch;
215 globalwatch.Start();
216
217 string inputfilename(argv[1]), outputfilename(argv[2]);
218
219 // 1.1 checks the input file
220 if(inputfilename.find(".root") > inputfilename.length() ) {
221 cout << "input_file should be a .root file from Delphes!\n";
222 return -1;
223 }
224 TFile f(inputfilename.c_str());
225 if (!f.FindKey("GEN") || !f.FindKey("Analysis") ) {
226 cout << "input_file should be a .root file from Delphes!\n";
227 cout << "it should contain both \"GEN\" and \"Analysis\" trees at least.\n";
228 return -1;
229 }
230 f.Close();
231
232 // 1.2 checks the output file
233 if(outputfilename.find(".root") > outputfilename.length() ) {
234 cout << "output_file should be a .root file!\n";
235 return -1;
236 }
237 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE");// Creates the file, but should be closed just after
238 outputFile->Close();
239
240 // 1.3 Reads the trees in input file
241 TChain chainGEN("GEN");
242 chainGEN.Add(inputfilename.c_str());
243 ExRootTreeReader *treeReaderGEN = new ExRootTreeReader(&chainGEN);
244 TChain chain("Analysis");
245 chain.Add(inputfilename.c_str());
246 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
247 const TClonesArray *branchJet = treeReader->UseBranch("Jet");
248 const TClonesArray *branchElec = treeReader->UseBranch("Electron");
249 const TClonesArray *branchMuon = treeReader->UseBranch("Muon");
250 const TClonesArray *branchTracks = treeReader->UseBranch("Tracks");
251 const TClonesArray *branchTowers = treeReader->UseBranch("CaloTower");
252 const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle");
253 TIter itGen((TCollection*)branchGen);
254
255
256 // 1.4 Prepares the output root file
257 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
258 ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
259 ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
260 ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
261 ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
262 ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
263
264 // 1.5 other initialisations
265 TRootGenParticle *particle;
266 RESOLELEC * elementElec;
267 RESOLMUON *elementMuon;
268 RESOLJET *elementJet;
269 TAUHAD *elementTaujet;
270 ETMIS *elementEtmis;
271
272 int numTau=0, numTauRec=0;
273
274 RESOLution *DET = new RESOLution();
275 /*
276 string detectorcard = "data/DetectorCard_CMS.dat";
277 const float dR_jetpairing = 0.25;
278 const float jet_pt_cut = 1;
279 */
280 string detectorcard = "data/DetectorCard_ATLAS.dat";
281 const float dR_jetpairing = 0.2;
282 const float jet_pt_cut = 7;
283 DET->ReadDataCard(detectorcard);
284
285 JetsUtil *JETRUN = new JetsUtil(detectorcard);
286
287 TLorentzVector genMomentum(0,0,0,0); // generator level information
288 TLorentzVector recoMomentum(0,0,0,0);// reconstruction level information
289 LorentzVector jetMomentum;
290
291 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
292 vector<fastjet::PseudoJet> sorted_jetsGEN;
293 vector<int> NTrackJet;
294 vector<TLorentzVector> towers;
295
296 // 2. Loop over all events
297 Long64_t entry, allEntries = treeReader->GetEntries();
298 cout << endl << endl;
299 cout <<"*********************************************************************"<< endl;
300 cout <<"** **"<< endl;
301 cout <<"** **"<< endl;
302 cout <<"** **"<< endl;
303 cout <<"** ####### Start resolution processing ######## **"<< endl;
304 cout << left << setw(52) <<"** Total number of events to run: "<<""
305 << left << setw(15) << allEntries <<""
306 << right << setw(2) <<"**"<<endl;
307
308 ExRootProgressBar *Progress = new ExRootProgressBar(allEntries);
309
310 for(entry = 0; entry < allEntries; ++entry)
311 {
312 Progress->Update(entry);
313 TLorentzVector PTmisReco(0,0,0,0);
314 TLorentzVector PTmisGEN(0,0,0,0);
315 treeReader->ReadEntry(entry);
316 treeReaderGEN->ReadEntry(entry);
317 treeWriter->Clear();
318
319 TSimpleArray<TRootGenParticle> bGen;
320 itGen.Reset();
321 TSimpleArray<TRootGenParticle> NFCentralQ;
322
323 input_particlesGEN.clear();
324 towers.clear();
325
326 // Loop over all particles in event
327 while( (particle = (TRootGenParticle*) itGen.Next()) )
328 {
329 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
330 PdgParticle pdg_part = DET->PDGtable[particle->PID];
331
332 int pid = abs(particle->PID);
333 float eta = fabs(particle->Eta);
334
335 //input generator level particle for jet algorithm
336 if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
337 {
338 input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
339 }
340
341 //Calculate ETMIS from generated particles
342 //if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
343 if( (particle->Status == 1) && pdg_part.invisible() )PTmisGEN = PTmisGEN + genMomentum;
344
345 //Electrons and muons
346 if( (particle->Status == 1) &&
347 //((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
348 (! pdg_part.invisible() ) &&
349 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
350 )
351 {
352 eta=fabs(genMomentum.Eta());
353
354 switch(pid) {
355
356 case pE: // all electrons with eta < DET->MAX_CALO_FWD
357 PairingElec(recoMomentum,genMomentum,branchElec);
358 if(recoMomentum.E()!=0){
359 elementElec=(RESOLELEC*) branchelec->NewEntry();
360 elementElec->E = genMomentum.E();
361 elementElec->SmearedE = recoMomentum.E();}
362 break; // case pE
363 case pMU: // all muons with eta < DET->MAX_MU
364 PairingMuon(recoMomentum,genMomentum,branchMuon);
365 if(recoMomentum.E()!=0){
366 elementMuon = (RESOLMUON*) branchmuon->NewEntry();
367 elementMuon->OverPT = 1./genMomentum.Pt();
368 elementMuon->OverSmearedPT = 1./recoMomentum.Pt();}
369 break; // case pMU
370 default:
371 break;
372 } // switch (pid)
373 }
374
375 } // while
376
377 //compute missing transverse energy from calo towers
378 TIter itCalo((TCollection*)branchTowers);
379 TRootCalo *calo;
380 itCalo.Reset();
381 TLorentzVector Att(0.,0.,0.,0.);
382 float ScalarEt=0;
383 while( (calo = (TRootCalo*) itCalo.Next()) )
384 {
385 if(calo->E !=0){
386 Att.SetPtEtaPhiE(calo->getET(),calo->Eta,calo->Phi,calo->E);
387 towers.push_back(Att);
388 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
389 {
390 ScalarEt = ScalarEt + calo->getET();
391 PTmisReco = PTmisReco + Att;
392 }
393 }
394 }
395 elementEtmis= (ETMIS*) branchetmis->NewEntry();
396 elementEtmis->Et = (PTmisGEN).Pt();
397 elementEtmis->Ex = (-PTmisGEN).Px();
398 elementEtmis->SEt = ScalarEt;
399 elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
400 elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
401
402 //*****************************
403 sorted_jetsGEN=JETRUN->RunJetsResol(input_particlesGEN);
404
405 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
406 TLorentzVector JETreco(0,0,0,0);
407 for (unsigned int i = 0; i < sorted_jetsGEN.size(); i++) {
408 TLorentzVector JETgen(0,0,0,0);
409 JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
410 PairingJet(JETreco,JETgen,branchJet,dR_jetpairing);
411 if(JETreco.Pt()>jet_pt_cut)
412 {
413 elementJet= (RESOLJET*) branchjet->NewEntry();
414 elementJet->PT = JETgen.Et();
415 elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
416 elementJet->E = JETgen.E();
417 elementJet->dE = (JETreco.E()-JETgen.E())/JETgen.E() ;
418 elementJet->dE2 = pow( (JETreco.E()-JETgen.E())/JETgen.E() , 2.) ;
419 }
420 }
421 numTau += TausHadr.GetEntries();
422
423 TIter itJet((TCollection*)branchJet);
424 TRootJet *jet;
425 itJet.Reset();
426 while( (jet = (TRootJet*) itJet.Next()) )
427 {
428 TLorentzVector JETT(0,0,0,0);
429 JETT.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E);
430 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone))
431 {
432 for(Int_t i=0; i<TausHadr.GetEntries();i++)
433 {
434 if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1)
435 {
436 elementTaujet= (TAUHAD*) branchtaujet->NewEntry();
437 elementTaujet->EnergieCen = EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E();
438 elementTaujet->NumTrack = NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone);
439 if( (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()) > 0.95
440 && (NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone))==1)numTauRec++;
441 }
442 }
443 }
444
445
446 } // for itJet : loop on all jets
447
448 treeWriter->Fill();
449 } // Loop over all events
450 treeWriter->Write();
451 globalwatch.Stop();
452
453
454 // Screen output
455 cout <<"** **"<< endl;
456 cout <<"** **"<< endl;
457 cout <<"** ################## Time report ################# **"<< endl;
458 cout << left << setw(32) <<"** Time report for "<<""
459 << left << setw(15) << allEntries <<""
460 << right << setw(22) <<"events **"<<endl;
461 cout <<"** **"<< endl;
462 cout << left << setw(10) <<"**"<<""
463 << left << setw(15) <<"Time (s):"<<""
464 << right << setw(15) <<"CPU"<<""
465 << right << setw(15) <<"Real"<<""
466 << right << setw(14) <<"**"<<endl;
467 cout << left << setw(10) <<"**"<<""
468 << left << setw(15) <<" + Global:"<<""
469 << right << setw(15) <<globalwatch.CpuTime()<<""
470 << right << setw(15) <<globalwatch.RealTime()<<""
471 << right << setw(14) <<"**"<<endl;
472
473
474 string tempstring = detectorcard + " has been used.";
475 cout <<"** ################## Configuration ############### **"<< endl;
476 cout << left << setw(16) << "** " << ""
477 << left << setw(51) << tempstring << "**" << endl;
478
479 tempstring = outputfilename + " has been created.";
480 cout << left << setw(16) << "** " << ""
481 << left << setw(51) << tempstring << "**" << endl;
482
483 cout << left << setw(16) << "** " << ""
484 << left << setw(51) << get_time_date() << "**" << endl;
485
486 cout <<"** **"<< endl;
487 cout <<"** Exiting ... **"<< endl;
488 cout <<"** **"<< endl;
489 cout <<"** **"<< endl;
490 cout <<"*********************************************************************"<< endl;
491
492
493 delete treeWriter;
494 delete treeReader;
495 delete DET;
496}
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
Note: See TracBrowser for help on using the repository browser.