Fork me on GitHub

source: svn/trunk/Resolutions_ATLAS.cpp@ 484

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

new leaves in RESOLJET needed for atlas resolution

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