Fork me on GitHub

source: git/examples/Validation.C@ e55f5b0

ImprovedOutputFile Timing dual_readout llp
Last change on this file since e55f5b0 was f01dee6, checked in by Alexandre Mertens <alexandre.mertens@…>, 8 years ago

Adding script for running the validation

  • Property mode set to 100644
File size: 24.9 KB
RevLine 
[734b267]1#ifdef __CLING__
2R__LOAD_LIBRARY(libDelphes)
3#include "classes/DelphesClasses.h"
4#include "external/ExRootAnalysis/ExRootTreeReader.h"
5#include "external/ExRootAnalysis/ExRootResult.h"
6#else
7class ExRootTreeReader;
8class ExRootResult;
9#endif
10
11#include "TCanvas.h"
12#include "TSystem.h"
13#include "TStyle.h"
14#include "TLegend.h"
15#include <TH1.h>
16#include "TString.h"
17#include "vector"
18#include <TMath.h>
19#include <iostream>
20#include "TGraph.h"
21#include "TGraphErrors.h"
22#include "TMultiGraph.h"
23#include <typeinfo>
24#include "TLorentzVector.h"
25
26//------------------------------------------------------------------------------
27
28double ptrangemin = 10;
29double ptrangemax = 10000;
[fe3908f]30static const int Nbins = 20;
[734b267]31
32int objStyle = 1;
33int trackStyle = 7;
34int towerStyle = 5;
35
36Color_t objColor = kBlack;
37Color_t trackColor = kBlack;
38Color_t towerColor = kBlack;
39
40double effLegXmin = 0.22;
41double effLegXmax = 0.5;
42double effLegYmin = 0.22;
43double effLegYmax = 0.4;
44
45struct resolPlot
46{
47 TH1 *cenResolHist;
48 TH1 *fwdResolHist;
49 double ptmin;
50 double ptmax;
51 TString obj;
52
53 resolPlot();
54 resolPlot(double ptdown, double ptup, TString object);
55 void set(double ptdown, double ptup, TString object);
56 void print(){std::cout << ptmin << std::endl;}
57};
58
59
60resolPlot::resolPlot()
61{
62}
63
64resolPlot::resolPlot(double ptdown, double ptup, TString object)
65{
66 this->set(ptdown,ptup,object);
67}
68
69void resolPlot::set(double ptdown, double ptup, TString object){
70 ptmin = ptdown;
71 ptmax = ptup;
72 obj = object;
73
[a3a556c]74 cenResolHist = new TH1D(obj+"_delta_pt_"+Form("%4.2f",ptmin)+"_"+Form("%4.2f",ptmax)+"_cen", obj+"_delta_pt_"+Form("%4.2f",ptmin)+"_"+Form("%4.2f",ptmax)+"_cen", 500, 0, 2);
[734b267]75 fwdResolHist = new TH1D(obj+"_delta_pt_"+Form("%4.2f",ptmin)+"_"+Form("%4.2f",ptmax)+"_fwd", obj+"_delta_pt_"+Form("%4.2f",ptmin)+"_"+Form("%4.2f",ptmax)+"_fwd", 500, 0.4, 0.4);
76
77}
78
79void HistogramsCollection(std::vector<resolPlot> *histos, double ptmin, double ptmax, TString obj)
80{
81 double width;
82 double ptdown;
83 double ptup;
84 resolPlot ptemp;
85
86 for (int i = 0; i < Nbins; i++)
87 {
88 width = (ptmax - ptmin) / Nbins;
89 ptdown = TMath::Power(10,ptmin + i * width );
90 ptup = TMath::Power(10,ptmin + (i+1) * width );
91 ptemp.set(ptdown, ptup, obj);
92 histos->push_back(ptemp);
93 }
94}
95
96//------------------------------------------------------------------------------
97
98class ExRootResult;
99class ExRootTreeReader;
100
101//------------------------------------------------------------------------------
102
103void BinLogX(TH1*h)
104{
105
106 TAxis *axis = h->GetXaxis();
107 int bins = axis->GetNbins();
108
109 Axis_t from = axis->GetXmin();
110 Axis_t to = axis->GetXmax();
111 Axis_t width = (to - from) / bins;
112 Axis_t *new_bins = new Axis_t[bins + 1];
113
114 for (int i = 0; i <= bins; i++) {
115 new_bins[i] = TMath::Power(10, from + i * width);
116
117 }
118 axis->Set(bins, new_bins);
119 delete new_bins;
120}
121
122
123//------------------------------------------------------------------------------
124
125template<typename T>
126std::pair<TH1D*, TH1D*> GetEff(TClonesArray *branchReco, TClonesArray *branchParticle, TString name, int pdgID, ExRootTreeReader *treeReader)
127{
128
129 cout << "** Computing Efficiency of reconstructing "<< branchReco->GetName() << " induced by " << branchParticle->GetName() << " with PID " << pdgID << endl;
130
131 Long64_t allEntries = treeReader->GetEntries();
132
133 GenParticle *particle;
134 T *recoObj;
135
136 TLorentzVector recoMomentum, genMomentum, bestRecoMomentum;
137
138 Float_t deltaR;
139 Float_t pt, eta;
140 Long64_t entry;
141
142 Int_t i, j;
143
144 TH1D *histGenPt = new TH1D(name+" gen spectra Pt",name+" gen spectra Pt", Nbins, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax));
145 TH1D *histRecoPt = new TH1D(name+" reco spectra Pt",name+" reco spectra Pt", Nbins, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax));
146 TH1D *histGenEta = new TH1D(name+" gen spectra Eta",name+" gen spectra Eta", 12, -3, 3);
147 TH1D *histRecoEta = new TH1D(name+" reco spectra Eta",name+" reco spectra Eta", 12, -3, 3);
148
149
150 BinLogX(histGenPt);
151 BinLogX(histRecoPt);
152
153 // Loop over all events
154 for(entry = 0; entry < allEntries; ++entry)
155 {
156 // Load selected branches with data from specified event
157 treeReader->ReadEntry(entry);
158
159 // Loop over all generated particle in event
160 for(i = 0; i < branchParticle->GetEntriesFast(); ++i)
161 {
162
163 particle = (GenParticle*) branchParticle->At(i);
164 genMomentum = particle->P4();
165
166 deltaR = 999;
167
168 if (particle->PID == pdgID && genMomentum.Pt() > ptrangemin && genMomentum.Pt() < ptrangemax )
169 {
170
171 // Loop over all reco object in event
172 for(j = 0; j < branchReco->GetEntriesFast(); ++j)
173 {
174 recoObj = (T*)branchReco->At(j);
175 recoMomentum = recoObj->P4();
176 // this is simply to avoid warnings from initial state particle
177 // having infite rapidity ...
178 //if(Momentum.Px() == 0 && genMomentum.Py() == 0) continue;
179
180 // take the closest parton candidate
181 if(genMomentum.DeltaR(recoMomentum) < deltaR)
182 {
183 deltaR = genMomentum.DeltaR(recoMomentum);
184 bestRecoMomentum = recoMomentum;
185 }
186 }
187
188 pt = genMomentum.Pt();
189 eta = genMomentum.Eta();
190
191 histGenPt->Fill(pt);
192 histGenEta->Fill(eta);
193
194 if(deltaR < 0.3)
195 {
196 histRecoPt->Fill(pt);
197 histRecoEta->Fill(eta);
198 }
199 }
200 }
201 }
202
203
204 std::pair<TH1D*,TH1D*> histos;
205
206 histRecoPt->Divide(histGenPt);
207 histRecoEta->Divide(histGenEta);
208
209 histos.first = histRecoPt;
210 histos.second = histRecoEta;
211
212 return histos;
213}
214
215template<typename T>
216void GetEres(std::vector<resolPlot> *histos, TClonesArray *branchReco, TClonesArray *branchParticle, int pdgID, ExRootTreeReader *treeReader)
217{
218 Long64_t allEntries = treeReader->GetEntries();
219
220 cout << "** Computing resolution of " << branchReco->GetName() << " induced by " << branchParticle->GetName() << " with PID " << pdgID << endl;
221
222 GenParticle *particle;
223 T* recoObj;
224
225 TLorentzVector recoMomentum, genMomentum, bestGenMomentum;
226
227 Float_t deltaR;
228 Float_t pt, eta;
229 Long64_t entry;
230
231 Int_t i, j, bin;
232
233 // Loop over all events
234 for(entry = 0; entry < allEntries; ++entry)
235 {
236 // Load selected branches with data from specified event
237 treeReader->ReadEntry(entry);
238
239 // Loop over all reconstructed jets in event
240 for(i = 0; i < branchReco->GetEntriesFast(); ++i)
241 {
242 recoObj = (T*) branchReco->At(i);
243 recoMomentum = recoObj->P4();
244
245 deltaR = 999;
246
247 // Loop over all hard partons in event
248 for(j = 0; j < branchParticle->GetEntriesFast(); ++j)
249 {
250 particle = (GenParticle*) branchParticle->At(j);
251 if (particle->PID == pdgID && particle->Status == 1)
252 {
253 genMomentum = particle->P4();
254
255 // this is simply to avoid warnings from initial state particle
256 // having infite rapidity ...
257 if(genMomentum.Px() == 0 && genMomentum.Py() == 0) continue;
258
259 // take the closest parton candidate
260 if(genMomentum.DeltaR(recoMomentum) < deltaR)
261 {
262 deltaR = genMomentum.DeltaR(recoMomentum);
263 bestGenMomentum = genMomentum;
264 }
265 }
266 }
267
268 if(deltaR < 0.3)
269 {
270 pt = bestGenMomentum.Pt();
271 eta = TMath::Abs(bestGenMomentum.Eta());
272
273 for (bin = 0; bin < Nbins; bin++)
274 {
275 if(pt > histos->at(bin).ptmin && pt < histos->at(bin).ptmax && eta > 0.0 && eta < 2.5)
276 {
[f01dee6]277 if (eta < 1.5) {histos->at(bin).cenResolHist->Fill(recoMomentum.Pt()/bestGenMomentum.Pt());}
278 else if (eta < 2.5) {histos->at(bin).fwdResolHist->Fill(recoMomentum.Pt()/bestGenMomentum.Pt());}
[734b267]279 }
280 }
281 }
282 }
283 }
284}
285void GetJetsEres(std::vector<resolPlot> *histos, TClonesArray *branchJet, TClonesArray *branchGenJet, ExRootTreeReader *treeReader)
286{
287
288 Long64_t allEntries = treeReader->GetEntries();
289
[fe3908f]290 cout << "** Computing resolution of " << branchJet->GetName() << " induced by " << branchGenJet->GetName() << endl;
[734b267]291
292 Jet *jet, *genjet;
293
294 TLorentzVector jetMomentum, genJetMomentum, bestGenJetMomentum;
295
296 Float_t deltaR;
297 Float_t pt, eta;
298 Long64_t entry;
299
300 Int_t i, j, bin;
301
302 // Loop over all events
303 for(entry = 0; entry < allEntries; ++entry)
304 {
305 // Load selected branches with data from specified event
306 treeReader->ReadEntry(entry);
307
308 if(entry%10000 == 0) cout << "Event number: "<< entry <<endl;
309
310 // Loop over all reconstructed jets in event
[fe3908f]311 for(i = 0; i < TMath::Min(2,branchJet->GetEntriesFast()); ++i) //branchJet->GetEntriesFast(); ++i)
[734b267]312 {
313
314 jet = (Jet*) branchJet->At(i);
315 jetMomentum = jet->P4();
316
317 deltaR = 999;
318
319 // Loop over all hard partons in event
[fe3908f]320 for(j = 0; j < TMath::Min(2,branchGenJet->GetEntriesFast()); ++j)
[734b267]321 {
322 genjet = (Jet*) branchGenJet->At(j);
323
324 genJetMomentum = genjet->P4();
325
326 // this is simply to avoid warnings from initial state particle
327 // having infite rapidity ...
328 if(genJetMomentum.Px() == 0 && genJetMomentum.Py() == 0) continue;
329
330 // take the closest parton candidate
331 if(genJetMomentum.DeltaR(jetMomentum) < deltaR)
332 {
333 deltaR = genJetMomentum.DeltaR(jetMomentum);
334 bestGenJetMomentum = genJetMomentum;
335 }
336 }
337
[a3a556c]338 if(deltaR < 0.25)
[734b267]339 {
340 pt = genJetMomentum.Pt();
341 eta = TMath::Abs(genJetMomentum.Eta());
342
343 for (bin = 0; bin < Nbins; bin++)
344 {
[a3a556c]345 if(pt > histos->at(bin).ptmin && pt < histos->at(bin).ptmax && eta > 0.0 && eta < 1.5)
[734b267]346 {
[a3a556c]347 histos->at(bin).cenResolHist->Fill(jetMomentum.Pt()/bestGenJetMomentum.Pt());
[734b267]348 }
349 }
350 }
351 }
352 }
353}
354std::pair<Double_t, Double_t> GausFit(TH1* hist)
355{
356 TF1 *f1 = new TF1("f1", "gaus", hist->GetMean()-2*hist->GetRMS(), hist->GetMean()+2*hist->GetRMS());
357 hist->Fit("f1","RQ");
358 Double_t sig = f1->GetParameter(2);
359 Double_t sigErr = f1->GetParError(2);
360 delete f1;
361 return make_pair (sig, sigErr);
[fe3908f]362 //return make_pair (hist->GetRMS(), hist->GetRMSError());
[734b267]363}
364
365
366TGraphErrors EresGraph(std::vector<resolPlot> *histos, bool central)
367{
368 Int_t bin;
[fe3908f]369 Int_t count = 0;
370 TGraphErrors gr = TGraphErrors(Nbins/2);
[734b267]371 Double_t sig = 0;
372 Double_t sigErr = 0;
373 for (bin = 0; bin < Nbins; bin++)
374 {
375 if (central == true && histos->at(bin).cenResolHist->GetEntries() > 100)
376 {
377 std::cout << " pt : " << (histos->at(bin).ptmin+histos->at(bin).ptmax)/2.0;
378 std::cout << " mean : " << histos->at(bin).cenResolHist->GetMean() << " RMS : " << histos->at(bin).cenResolHist->GetRMS();
379 std::cout << " entries : " << histos->at(bin).cenResolHist->GetEntries() << std::endl;
380 std::pair<Double_t, Double_t> sigvalues = GausFit(histos->at(bin).cenResolHist);
[fe3908f]381 gr.SetPoint(count,(histos->at(bin).ptmin+histos->at(bin).ptmax)/2.0, sigvalues.first);
382 gr.SetPointError(count,0, sigvalues.second);
383 count++;
[734b267]384 }
385 /*
386 else if (histos->at(bin).cenResolHist->GetEntries() > 10)
387 {
388 histos->at(bin).fwdResolHist->Fit("gaus","","", -2*histos->at(bin).fwdResolHist->GetRMS(), 2*histos->at(bin).fwdResolHist->GetRMS());
389 TF1 *f = histos->at(bin).fwdResolHist->GetFunction("gaus");
390 Double_t sig = f->GetParameter(2);
391 Double_t sigErr = f->GetParError(2);
392 gr.SetPoint(bin,(histos->at(bin).ptmin+histos->at(bin).ptmax)/2.0, sig);
393 gr.SetPointError(bin,0, sigErr);
394 }
395 */
396 }
397 return gr;
398}
399
400
401//------------------------------------------------------------------------------
402
403
404// type 1 : object, 2 : track, 3 : tower
405
406void addGraph(TMultiGraph *mg, TGraphErrors *gr, TLegend *leg, int type)
407{
408
409 gr->SetLineWidth(3);
410
411 switch ( type )
412 {
413 case 1:
414 gr->SetLineColor(objColor);
415 gr->SetLineStyle(objStyle);
416 std::cout << "Adding " << gr->GetName() << std::endl;
417 mg->Add(gr);
418 leg->AddEntry(gr,"Reco","l");
419 break;
420
421 case 2:
422 gr->SetLineColor(trackColor);
423 gr->SetLineStyle(trackStyle);
424 mg->Add(gr);
425 leg->AddEntry(gr,"Track","l");
426 break;
427
428 case 3:
429 gr->SetLineColor(towerColor);
430 gr->SetLineStyle(towerStyle);
431 mg->Add(gr);
432 leg->AddEntry(gr,"Tower","l");
433 break;
434
435 default:
436 std::cout << "wrong type, possibles choices are Object, Track and Tower" << std::endl;
437 break;
438 }
439}
440
441void addHist(TH1D *h, TLegend *leg, int type)
442{
443 h->SetLineWidth(3);
444
445 switch ( type )
446 {
447 case 1:
448 h->SetLineColor(objColor);
449 h->SetLineStyle(objStyle);
450 leg->AddEntry(h,"Reco","l");
451 break;
452
453 case 2:
454 h->SetLineColor(trackColor);
455 h->SetLineStyle(trackStyle);
456 leg->AddEntry(h,"Track","l");
457 break;
458
459 case 3:
460 h->SetLineColor(towerColor);
461 h->SetLineStyle(towerStyle);
462 leg->AddEntry(h,"Tower","l");
463 break;
464
465 default:
466 std::cout << "wrong type, possibles choices are Object, Track and Tower" << std::endl;
467 break;
468 }
469}
470
471void DrawAxis(TMultiGraph *mg, TLegend *leg, double max)
472{
473 mg->SetMinimum(0.);
474 mg->SetMaximum(max);
475 mg->GetXaxis()->SetLimits(ptrangemin,ptrangemax);
476 mg->GetYaxis()->SetTitle("#sigma (E) / E_{gen}");
477 mg->GetXaxis()->SetTitle("E_{gen}");
478 mg->GetYaxis()->SetTitleSize(0.07);
479 mg->GetXaxis()->SetTitleSize(0.07);
480 mg->GetYaxis()->SetLabelSize(0.07);
481 mg->GetXaxis()->SetLabelSize(0.07);
482
483 leg->SetLineStyle(0);
484 leg->SetFillStyle(0);
485 leg->SetLineWidth(0);
486 leg->SetLineColor(0);
487
488 gStyle->SetOptTitle(0);
489 gPad->SetLogx();
490 gPad->SetBottomMargin(0.2);
491 gPad->SetLeftMargin(0.2);
[fe3908f]492 gPad->Modified();
493 gPad->Update();
[734b267]494
495}
496
497void DrawAxis(TH1D *h, TLegend *leg, int type)
498{
499
500 h->GetYaxis()->SetRangeUser(0,1.2);
501 if (type == 0) h->GetXaxis()->SetTitle("E_{gen}");
502 else h->GetXaxis()->SetTitle("#eta");
503 h->GetYaxis()->SetTitle("#epsilon");
504 h->GetYaxis()->SetTitleSize(0.07);
505 h->GetXaxis()->SetTitleSize(0.07);
506 h->GetYaxis()->SetLabelSize(0.07);
507 h->GetXaxis()->SetLabelSize(0.07);
508 leg->SetLineStyle(0);
509 leg->SetFillStyle(0);
510 leg->SetLineWidth(0);
511 leg->SetLineColor(0);
512
513 gStyle->SetOptTitle(0);
514 gStyle->SetOptStat(0);
515 gPad->SetBottomMargin(0.2);
516 gPad->SetLeftMargin(0.2);
517
518 gPad->Modified();
519 gPad->Update();
520
521}
522
523
524void Validation(const char *inputFile, const char *outputFile)
525{
526 //gSystem->Load("libDelphes");
527
528 std::cout << "input file : " << inputFile << " " << " , output file : " << outputFile << std::endl;
529
530 TChain *chain = new TChain("Delphes");
531 chain->Add(inputFile);
532
533 ExRootTreeReader *treeReader = new ExRootTreeReader(chain);
534 TClonesArray *branchParticle = treeReader->UseBranch("Particle");
535 TClonesArray *branchElectron = treeReader->UseBranch("Electron");
536 TClonesArray *branchMuon = treeReader->UseBranch("Muon");
537 TClonesArray *branchPhoton = treeReader->UseBranch("Photon");
538 TClonesArray *branchTrack = treeReader->UseBranch("Track");
539 TClonesArray *branchTower = treeReader->UseBranch("Tower");
540 TClonesArray *branchGenJet = treeReader->UseBranch("GenJet");
541 TClonesArray *branchPFJet = treeReader->UseBranch("Jet");
542 TClonesArray *branchCaloJet = treeReader->UseBranch("CaloJet");
543
544
545
546 ///////////////
547 // Electrons //
548 ///////////////
549
550 // Reconstruction efficiency
551 TString elecs = "Electron";
552 int elID = 11;
553 std::pair<TH1D*,TH1D*> histos_el = GetEff<Electron>(branchElectron, branchParticle, "Electron", elID, treeReader);
554
555 // tracking reconstruction efficiency
556 std::pair <TH1D*,TH1D*> histos_eltrack = GetEff<Track>(branchTrack, branchParticle, "electronTrack", elID, treeReader);
557
558 // Tower reconstruction efficiency
559 std::pair <TH1D*,TH1D*> histos_eltower = GetEff<Tower>(branchTower, branchParticle, "electronTower", elID, treeReader);
560
561 // Electron Energy Resolution
562 std::vector<resolPlot> plots_el;
563 HistogramsCollection(&plots_el, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "electrons");
564 GetEres<Electron>( &plots_el, branchElectron, branchParticle, elID, treeReader);
565 TGraphErrors gr_el = EresGraph(&plots_el, true);
566 gr_el.SetName("Electron");
567
568 // Electron Track Energy Resolution
569 std::vector<resolPlot> plots_eltrack;
570 HistogramsCollection(&plots_eltrack, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "electronsTracks");
571 GetEres<Track>( &plots_eltrack, branchTrack, branchParticle, elID, treeReader);
572 TGraphErrors gr_eltrack = EresGraph(&plots_eltrack, true);
573 gr_eltrack.SetName("ElectronTracks");
574
575 // Electron Tower Energy Resolution
576 std::vector<resolPlot> plots_eltower;
577 HistogramsCollection(&plots_eltower, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "electronsTower");
578 GetEres<Tower>( &plots_eltower, branchTower, branchParticle, elID, treeReader);
579 TGraphErrors gr_eltower = EresGraph(&plots_eltower, true);
580 gr_eltower.SetName("ElectronTower");
581
582 // Canvases
583 TString elEff = "electronEff";
584 TCanvas *C_el1 = new TCanvas(elEff,elEff, 1000, 500);
585 C_el1->Divide(2);
586 C_el1->cd(1);
587 TLegend *leg_el1 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
588
589 gPad->SetLogx();
590 histos_eltrack.first->Draw();
591 addHist(histos_eltrack.first, leg_el1, 2);
592 histos_eltower.first->Draw("same");
593 addHist(histos_eltower.first, leg_el1, 3);
594 histos_el.first->Draw("same");
595 addHist(histos_el.first, leg_el1, 1);
596
597 DrawAxis(histos_eltrack.first, leg_el1, 0);
598 leg_el1->Draw();
599
600 C_el1->cd(2);
601 TLegend *leg_el2 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
602
603 histos_eltrack.second->Draw();
604 addHist(histos_eltrack.second, leg_el2, 2);
605 histos_eltower.second->Draw("same");
606 addHist(histos_eltower.second, leg_el2, 3);
607 histos_el.second->Draw("same");
608 addHist(histos_el.second, leg_el2, 1);
609
610 DrawAxis(histos_eltrack.second, leg_el2, 1);
611 delete(leg_el2);
612 C_el1->cd(0);
613
614 TString elRes = "electronERes";
615 TCanvas *C_el2 = new TCanvas(elRes,elRes, 1000, 500);
616 TMultiGraph *mg_el = new TMultiGraph(elRes,elRes);
617 TLegend *leg_el = new TLegend(0.52,0.7,0.9,0.9);
618
619 addGraph(mg_el, &gr_eltower, leg_el, 3);
620 addGraph(mg_el, &gr_eltrack, leg_el, 2);
621 addGraph(mg_el, &gr_el, leg_el, 1);
622
623 mg_el->Draw("ACX");
624 leg_el->Draw();
625
626 DrawAxis(mg_el, leg_el, 0.1);
627
628 C_el1->SaveAs(elEff+".eps");
629 C_el2->SaveAs(elRes+".eps");
630
[fe3908f]631 gDirectory->cd(0);
[734b267]632
633 ///////////
634 // Muons //
635 ///////////
636
637 // Reconstruction efficiency
638 int muID = 13;
639 std::pair<TH1D*,TH1D*> histos_mu = GetEff<Muon>(branchMuon, branchParticle,"Muon", muID, treeReader);
640
641 // muon tracking reconstruction efficiency
642 std::pair <TH1D*,TH1D*> histos_mutrack = GetEff<Track>(branchTrack, branchParticle, "muonTrack", muID, treeReader);
643
644 // Muon Energy Resolution
645 std::vector<resolPlot> plots_mu;
646 HistogramsCollection(&plots_mu, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "muons");
647 GetEres<Muon>( &plots_mu, branchMuon, branchParticle, muID, treeReader);
648 TGraphErrors gr_mu = EresGraph(&plots_mu, true);
649 gr_mu.SetName("Muon");
650
651 // Muon Track Energy Resolution
652 std::vector<resolPlot> plots_mutrack;
653 HistogramsCollection(&plots_mutrack, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "muonsTracks");
654 GetEres<Track>( &plots_mutrack, branchTrack, branchParticle, muID, treeReader);
655 TGraphErrors gr_mutrack = EresGraph(&plots_mutrack, true);
656 gr_eltrack.SetName("MuonTracks");
657
658 // Canvas
659
660 TString muEff = "muonEff";
661 TCanvas *C_mu1 = new TCanvas(muEff,muEff, 1000, 500);
662 C_mu1->Divide(2);
663 C_mu1->cd(1);
664 TLegend *leg_mu1 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
665
666 gPad->SetLogx();
667 histos_mutrack.first->Draw();
668 addHist(histos_mutrack.first, leg_mu1, 2);
669 histos_mu.first->Draw("same");
670 addHist(histos_mu.first, leg_mu1, 1);
671
672 DrawAxis(histos_mutrack.first, leg_mu1, 0);
673 leg_mu1->Draw();
674
675 C_mu1->cd(2);
676 TLegend *leg_mu2 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
677
678 histos_mutrack.second->Draw();
679 addHist(histos_mutrack.second, leg_mu2, 2);
680 histos_mu.second->Draw("same");
681 addHist(histos_mu.second, leg_mu2, 1);
682
683 DrawAxis(histos_mutrack.second, leg_mu2, 1);
684
685 TString muRes = "muonERes";
686 TCanvas *C_mu = new TCanvas(muRes,muRes, 1000, 500);
687 TMultiGraph *mg_mu = new TMultiGraph(muRes,muRes);
688 TLegend *leg_mu = new TLegend(0.52,0.7,0.9,0.9);
689
690 addGraph(mg_mu, &gr_mutrack, leg_mu, 2);
691 addGraph(mg_mu, &gr_mu, leg_mu, 1);
692
693 mg_mu->Draw("ACX");
694 leg_mu->Draw();
695
696 DrawAxis(mg_mu, leg_mu, 0.3);
697
698 C_mu1->SaveAs(muEff+".eps");
699 C_mu->SaveAs(muRes+".eps");
700
701 /////////////
702 // Photons //
703 /////////////
704
705 // Reconstruction efficiency
706 int phID = 22;
707 std::pair<TH1D*,TH1D*> histos_ph = GetEff<Electron>(branchPhoton, branchParticle, "Photon", phID, treeReader);
708 std::pair<TH1D*,TH1D*> histos_phtower = GetEff<Electron>(branchTower, branchParticle, "Photon", phID, treeReader);
709
710 // Photon Energy Resolution
711 std::vector<resolPlot> plots_ph;
712 HistogramsCollection(&plots_ph, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "photons");
713 GetEres<Photon>( &plots_ph, branchPhoton, branchParticle, phID, treeReader);
714 TGraphErrors gr_ph = EresGraph(&plots_ph, true);
715 gr_ph.SetName("Photon");
716
717 // Photon Tower Energy Resolution
718 std::vector<resolPlot> plots_phtower;
719 HistogramsCollection(&plots_phtower, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "photonsTower");
720 GetEres<Tower>( &plots_phtower, branchTower, branchParticle, phID, treeReader);
721 TGraphErrors gr_phtower = EresGraph(&plots_phtower, true);
722 gr_phtower.SetName("PhotonTower");
723
724 // Canvas
725
726 TString phEff = "photonEff";
727 TCanvas *C_ph1 = new TCanvas(phEff,phEff, 1000, 500);
728 C_ph1->Divide(2);
729 C_ph1->cd(1);
730 TLegend *leg_ph1 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
731
732 gPad->SetLogx();
733 histos_phtower.first->Draw();
734 addHist(histos_phtower.first, leg_ph1, 3);
735 histos_ph.first->Draw("same");
736 addHist(histos_ph.first, leg_ph1, 1);
737
738 DrawAxis(histos_phtower.first, leg_ph1, 0);
739 leg_ph1->Draw();
740
741 C_ph1->cd(2);
742 TLegend *leg_ph2 = new TLegend(effLegXmin,effLegYmin,effLegXmax,effLegYmax);
743
744 histos_phtower.second->Draw("same");
745 addHist(histos_phtower.second, leg_ph2, 3);
746 histos_ph.second->Draw("same");
747 addHist(histos_ph.second, leg_ph2, 1);
748
749 DrawAxis(histos_phtower.second, leg_ph2, 1);
750
751 C_ph1->SaveAs(phEff+".eps");
752
753 TString phRes = "phERes";
754 TCanvas *C_ph = new TCanvas(phRes,phRes, 1000, 500);
755 TMultiGraph *mg_ph = new TMultiGraph(phRes,phRes);
756 TLegend *leg_ph = new TLegend(0.52,0.7,0.9,0.9);
757
758 addGraph(mg_ph, &gr_phtower, leg_ph, 3);
759 addGraph(mg_ph, &gr_ph, leg_ph, 1);
760
761 mg_ph->Draw("ACX");
762 leg_ph->Draw();
763
764 DrawAxis(mg_ph, leg_ph, 0.3);
765
766 C_ph->SaveAs(phRes+".eps");
767
768 //////////
769 // Jets //
770 //////////
771
772 // PFJets Energy Resolution
773 std::vector<resolPlot> plots_pfjets;
774 HistogramsCollection(&plots_pfjets, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "PFJet");
775 GetJetsEres( &plots_pfjets, branchPFJet, branchGenJet, treeReader);
776 TGraphErrors gr_pfjets = EresGraph(&plots_pfjets, true);
777 gr_pfjets.SetName("pfJet");
778
[fe3908f]779
780 // PFJets Energy Resolution
781 std::vector<resolPlot> plots_calojets;
782 HistogramsCollection(&plots_calojets, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "CaloJet");
783 GetJetsEres( &plots_calojets, branchCaloJet, branchGenJet, treeReader);
784 TGraphErrors gr_calojets = EresGraph(&plots_calojets, true);
785 gr_calojets.SetName("caloJet");
786
787
788 TString jetRes = "jetERes";
789 TCanvas *C_jet = new TCanvas(jetRes,jetRes, 1000, 500);
790 TMultiGraph *mg_jet = new TMultiGraph(jetRes,jetRes);
791 TLegend *leg_jet = new TLegend(0.52,0.7,0.9,0.9);
792
793 addGraph(mg_jet, &gr_calojets, leg_jet, 3);
794 addGraph(mg_jet, &gr_pfjets, leg_jet, 1);
795
796 mg_jet->Draw("ACX");
797 leg_jet->Draw();
798
799 DrawAxis(mg_jet, leg_jet, 0.25);
800
801 C_jet->SaveAs(jetRes+".eps");
802
[734b267]803
804 /*
805 // CaloJets Energy Resolution
806 std::vector<resolPlot> plots_calojets;
807 HistogramsCollection(&plots_calojets, TMath::Log10(ptrangemin), TMath::Log10(ptrangemax), "caloJet");
808 GetJetsEres( &plots_calojets, branchCaloJet, branchGenJet, treeReader);
809 TGraphErrors gr_calojets = EresGraph(&plots_calojets, true);
810 gr_calojets.SetName("caloJet");
811 */
812
813
814
815 TFile *fout = new TFile(outputFile,"recreate");
816
817 for (int bin = 0; bin < Nbins; bin++)
818 {
819 plots_pfjets.at(bin).cenResolHist->Write();
[fe3908f]820 plots_calojets.at(bin).cenResolHist->Write();
[734b267]821 plots_el.at(bin).cenResolHist->Write();
822 plots_eltrack.at(bin).cenResolHist->Write();
823 plots_eltower.at(bin).cenResolHist->Write();
824 }
825
[f01dee6]826
[734b267]827 // gr.Write();
828 histos_el.first->Write();
829 //histos_el.second->Write();
830 histos_eltrack.first->Write();
831 //histos_eltrack.second->Write();
832 histos_eltower.first->Write();
833
834 histos_mu.first->Write();
835 histos_mu.second->Write();
836 histos_mutrack.first->Write();
837 histos_mutrack.second->Write();
838
839 histos_ph.first->Write();
840 histos_ph.second->Write();
841
842 //gr_el.Write();
843 //gr_eltrack.Write();
844 //gr_eltower.Write();
[f01dee6]845
[734b267]846
847 C_el1->Write();
848 C_el2->Write();
[fe3908f]849 C_jet->Write();
[f01dee6]850
[734b267]851 C_mu->Write();
852 C_ph->Write();
[f01dee6]853
[734b267]854 gr_pfjets.Write();
[fe3908f]855 gr_calojets.Write();
[734b267]856
857 fout->Write();
858
859
860 cout << "** Exiting..." << endl;
861
862 //delete plots;
863 //delete result;
864 delete treeReader;
865 delete chain;
866}
867
868//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.