Fork me on GitHub

source: svn/trunk/Resolutions_ATLAS.cpp@ 494

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

minor change

File size: 19.0 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 chainGEN.Add("all_dijets_atlas_kt.root");
244 chainGEN.Add("all_dijets_atlas_kt_2.root");
245 ExRootTreeReader *treeReaderGEN = new ExRootTreeReader(&chainGEN);
246 TChain chain("Analysis");
247 //chain.Add(inputfilename.c_str());
248 chain.Add("all_dijets_atlas_kt.root");
249 chain.Add("all_dijets_atlas_kt_2.root");
250 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
251 const TClonesArray *branchJet = treeReader->UseBranch("Jet");
252 const TClonesArray *branchElec = treeReader->UseBranch("Electron");
253 const TClonesArray *branchMuon = treeReader->UseBranch("Muon");
254 const TClonesArray *branchTracks = treeReader->UseBranch("Tracks");
255 const TClonesArray *branchTowers = treeReader->UseBranch("CaloTower");
256 const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle");
257 TIter itGen((TCollection*)branchGen);
258
259
260 // 1.4 Prepares the output root file
261 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
262 ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
263 ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
264 ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
265 ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
266 ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
267
268 // 1.5 other initialisations
269 TRootGenParticle *particle;
270 RESOLELEC * elementElec;
271 RESOLMUON *elementMuon;
272 RESOLJET *elementJet;
273 TAUHAD *elementTaujet;
274 ETMIS *elementEtmis;
275
276 int numTau=0, numTauRec=0;
277
278 RESOLution *DET = new RESOLution();
279 /*
280 string detectorcard = "data/DetectorCard_CMS.dat";
281 const float dR_jetpairing = 0.25;
282 const float jet_pt_cut = 1;
283 */
284 string detectorcard = "data/DetectorCard_ATLAS.dat";
285 const float dR_jetpairing = 0.2;
286 const float jet_pt_cut = 7;
287 DET->ReadDataCard(detectorcard);
288
289 JetsUtil *JETRUN = new JetsUtil(detectorcard);
290
291 TLorentzVector genMomentum(0,0,0,0); // generator level information
292 TLorentzVector recoMomentum(0,0,0,0);// reconstruction level information
293 LorentzVector jetMomentum;
294
295 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
296 vector<fastjet::PseudoJet> sorted_jetsGEN;
297 vector<int> NTrackJet;
298 vector<TLorentzVector> towers;
299
300 // 2. Loop over all events
301 Long64_t entry, allEntries = treeReader->GetEntries();
302 cout << endl << endl;
303 cout <<"*********************************************************************"<< endl;
304 cout <<"** **"<< endl;
305 cout <<"** ####### RESOLUTION STUDIES FOR ATLAS ######## **"<< endl;
306 cout <<"** **"<< endl;
307 cout <<"** ####### Start resolution processing ######## **"<< endl;
308 cout << left << setw(52) <<"** Total number of events to run: "<<""
309 << left << setw(15) << allEntries <<""
310 << right << setw(2) <<"**"<<endl;
311
312 ExRootProgressBar *Progress = new ExRootProgressBar(allEntries);
313
314 for(entry = 0; entry < allEntries; ++entry)
315 {
316 Progress->Update(entry);
317 TLorentzVector PTmisReco(0,0,0,0);
318 TLorentzVector PTmisGEN(0,0,0,0);
319 treeReader->ReadEntry(entry);
320 treeReaderGEN->ReadEntry(entry);
321 treeWriter->Clear();
322
323 TSimpleArray<TRootGenParticle> bGen;
324 itGen.Reset();
325 TSimpleArray<TRootGenParticle> NFCentralQ;
326
327 input_particlesGEN.clear();
328 towers.clear();
329
330 // Loop over all particles in event
331 while( (particle = (TRootGenParticle*) itGen.Next()) )
332 {
333 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
334 PdgParticle pdg_part = DET->PDGtable[particle->PID];
335
336 int pid = abs(particle->PID);
337 float eta = fabs(particle->Eta);
338
339 //input generator level particle for jet algorithm
340 if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
341 {
342 input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
343 }
344
345 //Calculate ETMIS from generated particles
346 //if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
347 if( (particle->Status == 1) && pdg_part.invisible() )PTmisGEN = PTmisGEN + genMomentum;
348
349 //Electrons and muons
350 if( (particle->Status == 1) &&
351 //((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
352 (! pdg_part.invisible() ) &&
353 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
354 )
355 {
356 eta=fabs(genMomentum.Eta());
357
358 switch(pid) {
359
360 case pE: // all electrons with eta < DET->MAX_CALO_FWD
361 PairingElec(recoMomentum,genMomentum,branchElec);
362 if(recoMomentum.E()!=0){
363 elementElec=(RESOLELEC*) branchelec->NewEntry();
364 elementElec->E = genMomentum.E();
365 elementElec->SmearedE = recoMomentum.E();}
366 break; // case pE
367 case pMU: // all muons with eta < DET->MAX_MU
368 PairingMuon(recoMomentum,genMomentum,branchMuon);
369 if(recoMomentum.E()!=0){
370 elementMuon = (RESOLMUON*) branchmuon->NewEntry();
371 elementMuon->OverPT = 1./genMomentum.Pt();
372 elementMuon->OverSmearedPT = 1./recoMomentum.Pt();}
373 break; // case pMU
374 default:
375 break;
376 } // switch (pid)
377 }
378
379 } // while
380
381 //compute missing transverse energy from calo towers
382 TIter itCalo((TCollection*)branchTowers);
383 TRootCalo *calo;
384 itCalo.Reset();
385 TLorentzVector Att(0.,0.,0.,0.);
386 float ScalarEt=0;
387 while( (calo = (TRootCalo*) itCalo.Next()) )
388 {
389 if(calo->E !=0){
390 Att.SetPtEtaPhiE(calo->getET(),calo->Eta,calo->Phi,calo->E);
391 towers.push_back(Att);
392 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
393 {
394 ScalarEt = ScalarEt + calo->getET();
395 PTmisReco = PTmisReco + Att;
396 }
397 }
398 }
399 elementEtmis= (ETMIS*) branchetmis->NewEntry();
400 elementEtmis->Et = (PTmisGEN).Pt();
401 elementEtmis->Ex = (-PTmisGEN).Px();
402 elementEtmis->SEt = ScalarEt;
403 elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
404 elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
405
406 //*****************************
407 sorted_jetsGEN=JETRUN->RunJetsResol(input_particlesGEN);
408
409 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
410 TLorentzVector JETreco(0,0,0,0);
411 for (unsigned int i = 0; i < sorted_jetsGEN.size(); i++) {
412 TLorentzVector JETgen(0,0,0,0);
413 JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
414 PairingJet(JETreco,JETgen,branchJet,dR_jetpairing);
415 if(JETreco.Pt()>jet_pt_cut)
416 {
417 elementJet= (RESOLJET*) branchjet->NewEntry();
418 elementJet->PT = JETgen.Et();
419 elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
420 elementJet->E = JETgen.E();
421 elementJet->dE = (JETreco.E()-JETgen.E())/JETgen.E() ;
422 elementJet->dE2 = pow( (JETreco.E()-JETgen.E())/JETgen.E() , 2.) ;
423 elementJet->Eta = JETgen.Eta();
424 elementJet->dE_reco = (JETreco.E()-JETgen.E())/JETreco.E() ;
425 elementJet->dE2_reco = pow( (JETreco.E()-JETgen.E())/JETreco.E() , 2.) ;
426 }
427 }
428 numTau += TausHadr.GetEntries();
429
430 TIter itJet((TCollection*)branchJet);
431 TRootJet *jet;
432 itJet.Reset();
433 while( (jet = (TRootJet*) itJet.Next()) )
434 {
435 TLorentzVector JETT(0,0,0,0);
436 JETT.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E);
437 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone))
438 {
439 for(Int_t i=0; i<TausHadr.GetEntries();i++)
440 {
441 if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1)
442 {
443 elementTaujet= (TAUHAD*) branchtaujet->NewEntry();
444 elementTaujet->EnergieCen = EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E();
445 elementTaujet->NumTrack = NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone);
446 if( (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()) > 0.95
447 && (NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone))==1)numTauRec++;
448 }
449 }
450 }
451
452
453 } // for itJet : loop on all jets
454
455 treeWriter->Fill();
456 } // Loop over all events
457 treeWriter->Write();
458 globalwatch.Stop();
459
460
461 // Screen output
462 cout <<"** **"<< endl;
463 cout <<"** **"<< endl;
464 cout <<"** ################## Time report ################# **"<< endl;
465 cout << left << setw(32) <<"** Time report for "<<""
466 << left << setw(15) << allEntries <<""
467 << right << setw(22) <<"events **"<<endl;
468 cout <<"** **"<< endl;
469 cout << left << setw(10) <<"**"<<""
470 << left << setw(15) <<"Time (s):"<<""
471 << right << setw(15) <<"CPU"<<""
472 << right << setw(15) <<"Real"<<""
473 << right << setw(14) <<"**"<<endl;
474 cout << left << setw(10) <<"**"<<""
475 << left << setw(15) <<" + Global:"<<""
476 << right << setw(15) <<globalwatch.CpuTime()<<""
477 << right << setw(15) <<globalwatch.RealTime()<<""
478 << right << setw(14) <<"**"<<endl;
479
480
481 string tempstring = detectorcard + " has been used.";
482 cout <<"** ################## Configuration ############### **"<< endl;
483 cout << left << setw(16) << "** " << ""
484 << left << setw(51) << tempstring << "**" << endl;
485
486 tempstring = outputfilename + " has been created.";
487 cout << left << setw(16) << "** " << ""
488 << left << setw(51) << tempstring << "**" << endl;
489
490 cout << left << setw(16) << "** " << ""
491 << left << setw(51) << get_time_date() << "**" << endl;
492
493 cout <<"** **"<< endl;
494 cout <<"** Exiting ... **"<< endl;
495 cout <<"** **"<< endl;
496 cout <<"** **"<< endl;
497 cout <<"*********************************************************************"<< endl;
498
499
500 delete treeWriter;
501 delete treeReader;
502 delete DET;
503}
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
Note: See TracBrowser for help on using the repository browser.