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
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.cpp
35/// \brief Resolution for CMS
36
37#include "TChain.h"
38#include "TApplication.h"
39#include "TFile.h"
40
41#include "ExRootTreeReader.h"
42#include "ExRootTreeWriter.h"
43#include "ExRootTreeBranch.h"
44#include "TreeClasses.h"
45
46#include "SmearUtil.h"
47#include "JetsUtil.h"
48#include "BFieldProp.h"
49
50#include<vector>
51#include<iostream>
52
53using namespace std;
54
55//------------------------------------------------------------------------------
56
57// //********************************** PYTHIA INFORMATION*********************************
58
59TSimpleArray<TRootGenParticle> TauHadr(const TClonesArray *GEN)
60 {
61 TIter it((TCollection*)GEN);
62 it.Reset();
63 TRootGenParticle *gen1;
64 TSimpleArray<TRootGenParticle> array,array2;
65
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++)
83 {
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
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}
103
104
105void PairingJet(TLorentzVector &JETSm, const TLorentzVector &JET, const TClonesArray *branchJet)
106{
107 JETSm.SetPxPyPzE(0,0,0,0);
108 float deltaRtest=5000;
109 TIter itJet((TCollection*)branchJet);
110 TRootJet *jet;
111 itJet.Reset();
112 while( (jet = (TRootJet*) itJet.Next()) )
113 {
114 TLorentzVector Att;
115 Att.SetPtEtaPhiE(jet->PT,jet->Eta,jet->Phi,jet->E);
116 if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest)
117 {
118 deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta());
119 if(deltaRtest < 0.25)
120 {
121 JETSm = Att;
122 }
123 }
124 }
125}
126
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;
137 Att.SetPtEtaPhiE(elec->PT,elec->Eta,elec->Phi,elec->E);
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
188int main(int argc, char *argv[])
189{
190 int appargc = 2;
191 char *appName = "Resolution";
192 char *appargv[] = {appName, "-b"};
193 TApplication app(appName, &appargc, appargv);
194
195 if(argc != 3) {
196 cout << " Usage: " << argv[0] << " input_file" << " output_file" << endl;
197 cout << " input_list - list of files in root format," << endl;
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
205 string inputfilename(argv[1]), outputfilename(argv[2]);
206
207 if(outputfilename.find(".root") > outputfilename.length() ) {
208 cout << "output_file should be a .root file!\n";
209 return -1;
210 }
211
212
213
214 TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after
215 outputFile->Close();
216
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());
222 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
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");
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());
238
239 TRootGenParticle *particle;
240
241 RESOLELEC * elementElec;
242 RESOLMUON *elementMuon;
243 RESOLJET *elementJet;
244 TAUHAD *elementTaujet;
245 ETMIS *elementEtmis;
246
247 int numTau=0;
248 int numTauRec=0;
249
250 RESOLution *DET = new RESOLution();
251 DET->ReadDataCard("data/DetectorCard_CMS.dat");
252
253
254 //Jet information
255 JetsUtil *JETRUN = new JetsUtil("data/DetectorCard_CMS.dat");
256
257 TLorentzVector genMomentum(0,0,0,0);//TLorentzVector containing generator level information
258 TLorentzVector recoMomentum(0,0,0,0);//TLorentzVector containing generator level information
259 LorentzVector jetMomentum;
260
261 vector<fastjet::PseudoJet> input_particlesGEN;//for FastJet algorithm
262 vector<fastjet::PseudoJet> sorted_jetsGEN;
263
264 vector<int> NTrackJet;
265
266 vector<TLorentzVector> towers;
267
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 {
273 TLorentzVector PTmisReco(0,0,0,0);
274 TLorentzVector PTmisGEN(0,0,0,0);
275 treeReader->ReadEntry(entry);
276 treeReaderGEN->ReadEntry(entry);
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;
283
284 input_particlesGEN.clear();
285 towers.clear();
286
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);
291
292 int pid = abs(particle->PID);
293 float eta = fabs(particle->Eta);
294
295 //input generator level particle for jet algorithm
296 if(particle->Status == 1 && eta < DET->CEN_max_calo_fwd)
297 {
298 input_particlesGEN.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()));
299 }
300
301 //Calculate ETMIS from generated particles
302 if((pid == pNU1) || (pid == pNU2) || (pid == pNU3))PTmisGEN = PTmisGEN + genMomentum;
303
304 if( (particle->Status == 1) &&
305 ((pid != pNU1) && (pid != pNU2) && (pid != pNU3)) &&
306 (fabs(particle->Eta) < DET->CEN_max_calo_fwd)
307 )
308 {
309 eta=fabs(genMomentum.Eta());
310
311 switch(pid) {
312
313 case pE: // all electrons with eta < DET->MAX_CALO_FWD
314 PairingElec(recoMomentum,genMomentum,branchElec);
315 if(recoMomentum.E()!=0){
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);
322 if(recoMomentum.E() !=0){
323 elementMuon = (RESOLMUON*) branchmuon->NewEntry();
324 elementMuon->OverPT = (1/genMomentum.Pt());
325 elementMuon->OverSmearedPT = (1/recoMomentum.Pt());}
326 break; // case pMU
327 default:
328 break;
329 } // switch (pid)
330 }
331
332 } // while
333
334 //compute missing transverse energy from calo towers
335 TIter itCalo((TCollection*)branchTowers);
336 TRootCalo *calo;
337 itCalo.Reset();
338 TLorentzVector Att(0.,0.,0.,0.);
339 float ScalarEt=0;
340 while( (calo = (TRootCalo*) itCalo.Next()) )
341 {
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 }
352 elementEtmis= (ETMIS*) branchetmis->NewEntry();
353 elementEtmis->Et = (PTmisGEN).Pt();
354 elementEtmis->Ex = (-PTmisGEN).Px();
355 elementEtmis->SEt = ScalarEt;
356
357 elementEtmis->EtSmeare = (PTmisReco).Pt()-(PTmisGEN).Pt();
358 elementEtmis->ExSmeare = (-PTmisReco).Px()-(PTmisGEN).Px();
359
360 //*****************************
361 sorted_jetsGEN=JETRUN->RunJetsResol(input_particlesGEN);
362
363 TSimpleArray<TRootGenParticle> TausHadr = TauHadr(branchGen);
364
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());
369 PairingJet(JETreco,JETgen,branchJet);
370 if(JETreco.Pt()>1)
371 {
372 elementJet= (RESOLJET*) branchjet->NewEntry();
373 elementJet->PT = JETgen.Et();
374 elementJet->SmearedPT = JETreco.Et()/JETgen.Et();
375 }
376 }
377 numTau = numTau+TausHadr.GetEntries();
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))
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();
393 elementTaujet->EnergieCen = (EnergySmallCone(towers,JETT.Eta(),JETT.Phi(),DET->TAU_energy_scone,DET->JET_seed)/JETT.E());
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++;
397 }
398 }
399 }
400
401
402 } // for itJet : loop on all jets
403//cout<<"i"<<endl;
404
405 treeWriter->Fill();
406 } // Loop over all events
407 treeWriter->Write();
408float frac = numTauRec/numTau;
409cout<<numTauRec<<endl;
410cout<<numTau<<endl;
411
412 cout << "** Exiting..." << endl;
413 cout<<frac<<endl;
414
415
416 delete treeWriter;
417 delete treeReader;
418 delete DET;
419}
420
Note: See TracBrowser for help on using the repository browser.