Fork me on GitHub

source: svn/trunk/Resolutions.cpp@ 462

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

minor cosmetic changes

File size: 14.9 KB
RevLine 
[443]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***********************************************************************/
[9]33
[445]34/// \file Resolution.cpp
[447]35/// \brief Resolution for CMS
[264]36
[9]37#include "TChain.h"
38#include "TApplication.h"
[227]39#include "TFile.h"
[9]40
[227]41#include "ExRootTreeReader.h"
42#include "ExRootTreeWriter.h"
43#include "ExRootTreeBranch.h"
44#include "TreeClasses.h"
[9]45
[227]46#include "SmearUtil.h"
47#include "JetsUtil.h"
48#include "BFieldProp.h"
[19]49
50#include<vector>
51#include<iostream>
52
[9]53using namespace std;
54
55//------------------------------------------------------------------------------
56
[39]57// //********************************** PYTHIA INFORMATION*********************************
[26]58
[39]59TSimpleArray<TRootGenParticle> TauHadr(const TClonesArray *GEN)
60 {
61 TIter it((TCollection*)GEN);
62 it.Reset();
63 TRootGenParticle *gen1;
64 TSimpleArray<TRootGenParticle> array,array2;
[26]65
[39]66 while((gen1 = (TRootGenParticle*) it.Next()))
67 {
68 array.Add(gen1);
69 }
70 it.Reset();
71 bool tauhad;
72 while((gen1 = (TRootGenParticle*) it.Next()))
73 {
74 tauhad=false;
75 if(abs(gen1->PID)==15)
76 {
77 int d1=gen1->D1;
78 int d2=gen1->D2;
79 if((d1 < array.GetEntries()) && (d1 > 0) && (d2 < array.GetEntries()) && (d2 > 0))
80 {
81 tauhad=true;
82 for(int d=d1; d < d2+1; d++)
[264]83 {
[39]84 if(abs(array[d]->PID)== pE || abs(array[d]->PID)== pMU)tauhad=false;
85 }
86 }
87 }
88 if(tauhad)array2.Add(gen1);
89 }
90 return array2;
91 }
92
[258]93double EnergySmallCone(const vector<TLorentzVector> &towers, const float eta, const float phi,float energy_scone,float JET_seed) {
94 double Energie=0;
95 for(unsigned int i=0; i < towers.size(); i++) {
96 if(towers[i].Pt() < JET_seed) continue;
97 if((DeltaR(phi,eta,towers[i].Phi(),towers[i].Eta()) < energy_scone)) {
98 Energie += towers[i].E();
99 }
100 }
101 return Energie;
102}
[39]103
104
[447]105void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, const TClonesArray *branchJet)
[9]106{
107 JETSm.SetPxPyPzE(0,0,0,0);
108 float deltaRtest=5000;
[258]109 TIter itJet((TCollection*)branchJet);
110 TRootJet *jet;
111 itJet.Reset();
112 while( (jet = (TRootJet*) itJet.Next()) )
113 {
[19]114 TLorentzVector Att;
[264]115 Att.SetPtEtaPhiE(jet->PT,jet->Eta,jet->Phi,jet->E);
[19]116 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
117 {
118 deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
[447]119 if(deltaRtest < 0.25)
[19]120 {
121 JETSm = Att;
122 }
123 }
124 }
[9]125}
126
[258]127void PairingElec(TLorentzVector &ELECSm, const TLorentzVector &ELEC, const TClonesArray *branchElec)
128{
129 ELECSm.SetPxPyPzE(0,0,0,0);
130 float deltaRtest=5000;
131 TIter itElec((TCollection*)branchElec);
132 TRootElectron *elec;
133 itElec.Reset();
134 while( (elec = (TRootElectron*) itElec.Next()) )
135 {
136 TLorentzVector Att;
[264]137 Att.SetPtEtaPhiE(elec->PT,elec->Eta,elec->Phi,elec->E);
[258]138 if(DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
139 {
140 deltaRtest = DeltaR(ELEC.Phi(),ELEC.Eta(),Att.Phi(),Att.Eta());
141 if(deltaRtest < 0.025)
142 {
143 ELECSm = Att;
144 }
145 }
146 }
147}
148
149void PairingMuon(TLorentzVector &MUONSm, const TLorentzVector &MUON, const TClonesArray *branchMuon)
150{
151 MUONSm.SetPxPyPzE(0,0,0,0);
152 float deltaRtest=5000;
153 TIter itMuon((TCollection*)branchMuon);
154 TRootMuon *muon;
155 itMuon.Reset();
156 while( (muon = (TRootMuon*) itMuon.Next()) )
157 {
158 TLorentzVector Att;
159 Att.SetPxPyPzE(muon->Px,muon->Py,muon->Pz,muon->E);
160 if(DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
161 {
162 deltaRtest = DeltaR(MUON.Phi(),MUON.Eta(),Att.Phi(),Att.Eta());
163 if(deltaRtest < 0.025)
164 {
165 MUONSm = Att;
166 }
167 }
168 }
169}
170
171unsigned int NumTracks(const TClonesArray *branchTracks, const float pt_track, const float eta, const float phi,float track_scone) {
172 unsigned int numtrack=0;
173 TIter itTrack((TCollection*)branchTracks);
174 TRootTracks *track;
175 itTrack.Reset();
176 while( (track = (TRootTracks*) itTrack.Next()) )
177 {
178 if((track->PT < pt_track )||
179 (DeltaR(phi,eta,track->Phi,track->Eta) > track_scone)
180 )continue;
181 numtrack++;
182 }
183 return numtrack;
184}
185
186
187
[9]188int main(int argc, char *argv[])
189{
190 int appargc = 2;
[258]191 char *appName = "Resolution";
[9]192 char *appargv[] = {appName, "-b"};
193 TApplication app(appName, &appargc, appargv);
194
[258]195 if(argc != 3) {
196 cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl;
[447]197 cout << " input_list - list of files in root format," << endl;
[9]198 cout << " output_file - output file." << endl;
199 exit(1);
200 }
201
202 srand (time (NULL)); /* Initialisation du générateur */
203
204 //read the input TROOT file
[258]205 string inputfilename(argv[1]), outputfilename(argv[2]);
206
[9]207 if(outputfilename.find(".root") > outputfilename.length() ) {
208 cout << "output_file should be a .root file!\n";
209 return -1;
210 }
[88]211
[258]212
213
[447]214 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
[9]215 outputFile->Close();
[26]216
[258]217 TChain chainGEN("GEN");
218 chainGEN.Add(inputfilename.c_str());
219 ExRootTreeReader *treeReaderGEN = new ExRootTreeReader(&chainGEN);
220 TChain chain("Analysis");
221 chain.Add(inputfilename.c_str());
[9]222 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
[258]223 const TClonesArray *branchJet = treeReader->UseBranch("Jet");
224 const TClonesArray *branchElec = treeReader->UseBranch("Electron");
225 const TClonesArray *branchMuon = treeReader->UseBranch("Muon");
226 const TClonesArray *branchTracks = treeReader->UseBranch("Tracks");
227 const TClonesArray *branchTowers = treeReader->UseBranch("CaloTower");
228 const TClonesArray *branchGen = treeReaderGEN->UseBranch("Particle");
[9]229 TIter itGen((TCollection*)branchGen);
230
231 //write the output root file
232 ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis");
233 ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class());
234 ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class());
235 ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class());
236 ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class());
237 ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class());
[26]238
[9]239 TRootGenParticle *particle;
[26]240
[39]241 RESOLELEC * elementElec;
[9]242 RESOLMUON *elementMuon;
243 RESOLJET *elementJet;
244 TAUHAD *elementTaujet;
245 ETMIS *elementEtmis;
[26]246
[258]247 int numTau=0;
248 int numTauRec=0;
[26]249
[258]250 RESOLution *DET = new RESOLution();
[447]251 DET->ReadDataCard("data/DetectorCard_CMS.dat");
[88]252
[258]253
[88]254 //Jet information
[447]255 JetsUtil *JETRUN = new JetsUtil("data/DetectorCard_CMS.dat");
[88]256
257 TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information
[258]258 TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing generator level information
[9]259 LorentzVector jetMomentum;
[26]260
[88]261 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
262 vector<fastjet::PseudoJet> sorted_jetsGEN;
[447]263
[307]264 vector<int> NTrackJet;
[447]265
[258]266 vector<TLorentzVector> towers;
[152]267
[9]268 // Loop over all events
269 Long64_t entry, allEntries = treeReader->GetEntries();
270 cout << "** Chain contains " << allEntries << " events" << endl;
271 for(entry = 0; entry < allEntries; ++entry)
272 {
[88]273 TLorentzVector PTmisReco(0,0,0,0);
274 TLorentzVector PTmisGEN(0,0,0,0);
[9]275 treeReader->ReadEntry(entry);
[258]276 treeReaderGEN->ReadEntry(entry);
[9]277 treeWriter->Clear();
278 if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl;
279
280 TSimpleArray<TRootGenParticle> bGen;
281 itGen.Reset();
282 TSimpleArray<TRootGenParticle> NFCentralQ;
[89]283
[88]284 input_particlesGEN.clear();
[23]285 towers.clear();
[26]286
[9]287 // Loop over all particles in event
288 while( (particle = (TRootGenParticle*) itGen.Next()) )
289 {
290 genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E);
[26]291
[9]292 int pid = abs(particle->PID);
293 float eta = fabs(particle->Eta);
[89]294
[88]295 //input generator level particle for jet algorithm
[94]296 if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
[26]297 {
[88]298 input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
[26]299 }
[89]300
[88]301 //Calculate ETMIS from generated particles
302 if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
[447]303
[258]304 if( (particle->Status == 1) &&
305 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
306 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
307 )
[88]308 {
[258]309 eta=fabs(genMomentum.Eta());
[152]310
[258]311 switch(pid) {
312
313 case pE: // all electrons with eta < DET->MAX_CALO_FWD
314 PairingElec(recoMomentum,genMomentum,branchElec);
[264]315 if(recoMomentum.E()!=0){
[258]316 elementElec=(RESOLELEC*) branchelec->NewEntry();
317 elementElec->E = genMomentum.E();
318 elementElec->SmearedE = recoMomentum.E();}
319 break; // case pE
320 case pMU: // all muons with eta < DET->MAX_MU
321 PairingMuon(recoMomentum,genMomentum,branchMuon);
[447]322 if(recoMomentum.E() !=0){
[258]323 elementMuon = (RESOLMUON*) branchmuon->NewEntry();
[447]324 elementMuon->OverPT = (1/genMomentum.Pt());
325 elementMuon->OverSmearedPT = (1/recoMomentum.Pt());}
[258]326 break; // case pMU
327 default:
328 break;
329 } // switch (pid)
330 }
331
[9]332 } // while
[264]333
[89]334 //compute missing transverse energy from calo towers
[258]335 TIter itCalo((TCollection*)branchTowers);
336 TRootCalo *calo;
337 itCalo.Reset();
[89]338 TLorentzVector Att(0.,0.,0.,0.);
339 float ScalarEt=0;
[258]340 while( (calo = (TRootCalo*) itCalo.Next()) )
341 {
[264]342 if(calo->E !=0){
343 Att.SetPtEtaPhiE(calo->getET(),calo->Eta,calo->Phi,calo->E);
344 towers.push_back(Att);
345 if(fabs(Att.Eta()) < DET->CEN_max_calo_fwd)
346 {
347 ScalarEt = ScalarEt + calo->getET();
348 PTmisReco = PTmisReco + Att;
349 }
350 }
351 }
[89]352 elementEtmis= (ETMIS*) branchetmis->NewEntry();
353 elementEtmis->Et = (PTmisGEN).Pt();
354 elementEtmis->Ex = (-PTmisGEN).Px();
355 elementEtmis->SEt = ScalarEt;
[447]356
[89]357 elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
358 elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
[9]359
360 //*****************************
[310]361 sorted_jetsGEN=JETRUN->RunJetsResol(input_particlesGEN);
[88]362
[39]363 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
[447]364
[88]365 TLorentzVector JETreco(0,0,0,0);
366 for (unsigned int i = 0; i < sorted_jetsGEN.size(); i++) {
367 TLorentzVector JETgen(0,0,0,0);
368 JETgen.SetPxPyPzE(sorted_jetsGEN[i].px(),sorted_jetsGEN[i].py(),sorted_jetsGEN[i].pz(),sorted_jetsGEN[i].E());
[258]369 PairingJet(JETreco,JETgen,branchJet);
[447]370 if(JETreco.Pt()>1)
[19]371 {
372 elementJet= (RESOLJET*) branchjet->NewEntry();
[88]373 elementJet->PT = JETgen.Et();
374 elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
[19]375 }
[39]376 }
[152]377 numTau = numTau+TausHadr.GetEntries();
[258]378
379 TIter itJet((TCollection*)branchJet);
380 TRootJet *jet;
381 itJet.Reset();
382 while( (jet = (TRootJet*) itJet.Next()) )
383 {
384 TLorentzVector JETT(0,0,0,0);
385 JETT.SetPxPyPzE(jet->Px,jet->Py,jet->Pz,jet->E);
386 if(fabs(JETT.Eta()) < (DET->CEN_max_tracker - DET->TAU_track_scone))
[39]387 {
388 for(Int_t i=0; i<TausHadr.GetEntries();i++)
389 {
390 if(DeltaR(TausHadr[i]->Phi,TausHadr[i]->Eta,JETT.Phi(),JETT.Eta())<0.1)
391 {
392 elementTaujet= (TAUHAD*) branchtaujet->NewEntry();
[447]393 elementTaujet->EnergieCen = (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E());
[258]394 elementTaujet->NumTrack = NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone);
395 if( (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E()) > 0.95
396 && (NumTracks(branchTracks,DET->TAU_track_pt,JETT.Eta(),JETT.Phi(),DET->TAU_track_scone))==1)numTauRec++;
[39]397 }
398 }
399 }
400
[26]401
402 } // for itJet : loop on all jets
[447]403//cout<<"i"<<endl;
[26]404
[9]405 treeWriter->Fill();
406 } // Loop over all events
407 treeWriter->Write();
[447]408float frac = numTauRec/numTau;
409cout<<numTauRec<<endl;
410cout<<numTau<<endl;
[152]411
[9]412 cout << "** Exiting..." << endl;
[447]413 cout<<frac<<endl;
414
[9]415
416 delete treeWriter;
417 delete treeReader;
418 delete DET;
419}
420
Note: See TracBrowser for help on using the repository browser.