ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/SchieferD/jetcalib/mcfakerate_x.cpp
Revision: 1.6
Committed: Mon Oct 8 12:15:44 2007 UTC (17 years, 6 months ago) by schiefer
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +11 -12 lines
Error occurred while calculating annotation data.
Log Message:
*** empty log message ***

File Contents

# Content
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // mcfakerate_x
4 // ------------
5 //
6 // 06/28/2007 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
7 ////////////////////////////////////////////////////////////////////////////////
8
9
10 #include "utils/cmdline.h"
11
12 #include <TROOT.h>
13 #include <TStyle.h>
14 #include <TRint.h>
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TH1F.h>
18 #include <TCanvas.h>
19 #include <TLegend.h>
20 #include <TMath.h>
21
22 #include <iostream>
23 #include <iomanip>
24 #include <cmath>
25 #include <string>
26 #include <vector>
27
28
29 using namespace std;
30
31
32 ////////////////////////////////////////////////////////////////////////////////
33 // declare global functions
34 ////////////////////////////////////////////////////////////////////////////////
35
36 //______________________________________________________________________________
37 void setBinomialErrors(TH1F* hEff,const TH1F* hFake, const TH1F* hAll);
38 string getLegLabel(const string& jetalg);
39
40 ////////////////////////////////////////////////////////////////////////////////
41 // main
42 ////////////////////////////////////////////////////////////////////////////////
43
44 //______________________________________________________________________________
45 int main(int argc,char**argv)
46 {
47 cmdline cl;
48 cl.parse(argc,argv);
49
50 vector<string> input = cl.get_vector<string>("input");
51 string treename = cl.get_value<string> ("treename", "t");
52 float drmax = cl.get_value<float> ("drmax", 0.5);
53 int netbins = cl.get_value<int> ("netbins", 50);
54 int netabins = cl.get_value<int> ("netabins", 25);
55 int nphibins = cl.get_value<int> ("nphibins", 25);
56 int nemfbins = cl.get_value<int> ("nemfbins", 15);
57 float etmin = cl.get_value<float> ("etmin", 0.0);
58 float etmax = cl.get_value<float> ("etmax", 200.0);
59 float etamin = cl.get_value<float> ("etamin", -5.0);
60 float etamax = cl.get_value<float> ("etamax", 5.0);
61 float phimin = cl.get_value<float> ("phimin", -3.2);
62 float phimax = cl.get_value<float> ("phimax", 3.2);
63 float emfmin = cl.get_value<float> ("emfmin", 0.0);
64 float emfmax = cl.get_value<float> ("emfmax", 1.0);
65 short applyjes = cl.get_value<short> ("applyjes", 0);
66
67 if (!cl.check()) return 0;
68 cl.print();
69
70
71 // jetalgs
72 vector<string> jetalgs;
73 for (vector<string>::const_iterator it=input.begin();it!=input.end();++it) {
74 string jetalg = *it;
75 string::size_type pos;
76 while ((pos=jetalg.find('/'))!=string::npos) jetalg = jetalg.substr(pos+1);
77 jetalg = jetalg.substr(0,jetalg.find(".root"));
78 jetalgs.push_back(jetalg);
79 }
80
81 // loop over all input samples
82 vector<TH1F*> etHistos;
83 vector<TH1F*> etaHistos;
84 vector<TH1F*> phiHistos;
85 vector<TH1F*> emfHistos;
86 for (unsigned int i=0;i<input.size();++i) {
87 TFile* f = new TFile(input[i].c_str(),"READ");
88 TTree* t = (TTree*)f->Get(treename.c_str());
89 cout<<jetalgs[i]<<" sample has "<<t->GetEntries()<<" entries."<<endl;
90
91 string nameEtAll = "EtAll_" +jetalgs[i];
92 string nameEtFake = "EtFake_"+jetalgs[i];
93 string nameEtEff = "EtEff_" +jetalgs[i];
94
95 TH1F* hEtAll = new TH1F(nameEtAll.c_str(),nameEtAll.c_str(),
96 netbins,etmin,etmax);
97 TH1F* hEtFake = new TH1F(nameEtFake.c_str(),nameEtFake.c_str(),
98 netbins,etmin,etmax);
99 TH1F* hEtEff = new TH1F(nameEtEff.c_str(),nameEtEff.c_str(),
100 netbins,etmin,etmax);
101
102 hEtAll->Sumw2();
103 hEtFake->Sumw2();
104 hEtEff->Sumw2();
105
106 string nameEtaAll = "EtaAll_"+jetalgs[i];
107 string nameEtaFake = "EtaFake_"+jetalgs[i];
108 string nameEtaEff = "EtaEff_"+jetalgs[i];
109
110 TH1F* hEtaAll = new TH1F(nameEtaAll.c_str(),nameEtaAll.c_str(),
111 netabins,etamin,etamax);
112 TH1F* hEtaFake = new TH1F(nameEtaFake.c_str(),nameEtaFake.c_str(),
113 netabins,etamin,etamax);
114 TH1F* hEtaEff = new TH1F(nameEtaEff.c_str(),nameEtaEff.c_str(),
115 netabins,etamin,etamax);
116
117 hEtaAll->Sumw2();
118 hEtaFake->Sumw2();
119 hEtaEff->Sumw2();
120
121 string namePhiAll = "PhiAll_"+jetalgs[i];
122 string namePhiFake = "PhiFake_"+jetalgs[i];
123 string namePhiEff = "PhiEff_"+jetalgs[i];
124
125 TH1F* hPhiAll = new TH1F(namePhiAll.c_str(),namePhiAll.c_str(),
126 nphibins,phimin,phimax);
127 TH1F* hPhiFake = new TH1F(namePhiFake.c_str(),namePhiFake.c_str(),
128 nphibins,phimin,phimax);
129 TH1F* hPhiEff = new TH1F(namePhiEff.c_str(),namePhiEff.c_str(),
130 nphibins,phimin,phimax);
131
132 hPhiAll->Sumw2();
133 hPhiFake->Sumw2();
134 hPhiEff->Sumw2();
135
136 string nameEmfAll = "EmfAll_"+jetalgs[i];
137 string nameEmfFake = "EmfFake_"+jetalgs[i];
138 string nameEmfEff = "EmfEff_"+jetalgs[i];
139
140 TH1F* hEmfAll = new TH1F(nameEmfAll.c_str(),nameEmfAll.c_str(),
141 nemfbins,emfmin,emfmax);
142 TH1F* hEmfFake = new TH1F(nameEmfFake.c_str(),nameEmfFake.c_str(),
143 nemfbins,emfmin,emfmax);
144 TH1F* hEmfEff = new TH1F(nameEmfEff.c_str(),nameEmfEff.c_str(),
145 nemfbins,emfmin,emfmax);
146
147 hEmfAll->Sumw2();
148 hEmfFake->Sumw2();
149 hEmfEff->Sumw2();
150
151 float weight; t->SetBranchAddress("weight",&weight);
152 char njt; t->SetBranchAddress("njt", &njt);
153 float jtet[100]; t->SetBranchAddress("jtet", jtet);
154 float jteta[100]; t->SetBranchAddress("jteta", jteta);
155 float jtphi[100]; t->SetBranchAddress("jtphi", jtphi);
156 float jtemf[100]; t->SetBranchAddress("jtemf", jtemf);
157 float jtgendr[100]; t->SetBranchAddress("jtgendr",jtgendr);
158 float jtjes[100][3];
159 if (applyjes>0&&t->FindBranch("jtjes")) t->SetBranchAddress("jtjes",jtjes);
160
161 int nevts=t->GetEntries();
162
163 for (int ievt=0;ievt<nevts;ievt++) {
164
165 t->GetEntry(ievt);
166
167 for (int ijt=0;ijt<njt;ijt++) {
168
169 float dr = jtgendr[ijt];
170 float et = (applyjes==0) ? jtet[ijt]:jtet[ijt]*jtjes[ijt][applyjes-1];
171 float eta = jteta[ijt];
172 float phi = jtphi[ijt];
173 float emf = jtemf[ijt]; if (TMath::IsNaN(emf)) emf = 0.0;
174
175 if (et <etmin ||et >etmax) continue;
176 if (eta<etamin||eta>etamax) continue;
177 if (phi<phimin||phi>phimax) continue;
178 if (emf<emfmin||emf>emfmax) continue;
179
180 hEtAll ->Fill(et, weight);
181 hEtaAll->Fill(eta,weight);
182 hPhiAll->Fill(phi,weight);
183 hEmfAll->Fill(emf,weight);
184
185 if (dr<0.0||dr>drmax) {
186 hEtFake ->Fill(et, weight);
187 hEtaFake->Fill(eta,weight);
188 hPhiFake->Fill(phi,weight);
189 hEmfFake->Fill(emf,weight);
190 }
191 }
192 }
193
194 hEtEff->Divide(hEtFake,hEtAll,1.0,1.0,"B");
195 setBinomialErrors(hEtEff,hEtFake,hEtAll);
196 etHistos.push_back(hEtEff);
197
198 hEtaEff->Divide(hEtaFake,hEtaAll,1.0,1.0,"B");
199 setBinomialErrors(hEtaEff,hEtaFake,hEtaAll);
200 etaHistos.push_back(hEtaEff);
201
202 hPhiEff->Divide(hPhiFake,hPhiAll,1.0,1.0,"B");
203 setBinomialErrors(hPhiEff,hPhiFake,hPhiAll);
204 phiHistos.push_back(hPhiEff);
205
206 hEmfEff->Divide(hEmfFake,hEmfAll,1.0,1.0,"B");
207 setBinomialErrors(hEmfEff,hEmfFake,hEmfAll);
208 emfHistos.push_back(hEmfEff);
209 }
210
211
212 // make plots
213 argc=1;
214 TRint* app = new TRint(argv[0],&argc,argv);
215
216 gStyle->SetOptStat(0);
217
218 Color_t color;
219
220 // emf canvas
221 TCanvas* cEmfEff = new TCanvas("FakeVsEmf", "FakeVsEmf",10,420,400,400);
222 TLegend* lEmfEff = new TLegend(0.65,0.85-emfHistos.size()*0.05,0.86,0.85);
223 cEmfEff->cd();
224 lEmfEff->SetFillColor(10);
225
226 color = kBlack;
227 for (unsigned int i=0;i<emfHistos.size();i++) {
228 TH1F* h = emfHistos[i];
229 lEmfEff->AddEntry(h,getLegLabel(jetalgs[i]).c_str(),"lp");
230 h->SetLineWidth(1);
231 h->SetMarkerColor(color);
232 h->SetLineColor(color++);
233 h->SetMarkerStyle(kFullCircle);
234 h->SetMarkerSize(0.5);
235 if (i==0) {
236 h->SetTitle("#epsilon_{FAKE} vs emf");
237 h->SetXTitle("emf");
238 h->SetYTitle("#epsilon_{FAKE}");
239 h->Draw("E");
240 h->SetMinimum(0.0);
241 h->SetMaximum(1.05);
242 }
243 else h->Draw("ESAME");
244 }
245 lEmfEff->Draw();
246
247 // phi canvas
248 TCanvas* cPhiEff = new TCanvas("FakeVsPhi", "FakeVsPhi",830,10,400,400);
249 TLegend* lPhiEff = new TLegend(0.65,0.85-phiHistos.size()*0.05,0.86,0.85);
250 cPhiEff->cd();
251 lPhiEff->SetFillColor(10);
252
253 color = kBlack;
254 for (unsigned int i=0;i<phiHistos.size();i++) {
255 TH1F* h = phiHistos[i];
256 lPhiEff->AddEntry(h,getLegLabel(jetalgs[i]).c_str(),"lp");
257 h->SetLineWidth(1);
258 h->SetMarkerColor(color);
259 h->SetLineColor(color++);
260 h->SetMarkerStyle(kFullCircle);
261 h->SetMarkerSize(0.5);
262 if (i==0) {
263 h->SetTitle("#epsilon_{FAKE} vs #phi");
264 h->SetXTitle("#phi");
265 h->SetYTitle("#epsilon_{FAKE}");
266 h->Draw("E");
267 h->SetMinimum(0.0);
268 h->SetMaximum(1.05);
269 }
270 else h->Draw("ESAME");
271 }
272 lPhiEff->Draw();
273
274 // eta canvas
275 TCanvas* cEtaEff = new TCanvas("FakeVsEta", "FakeVsEta",420,10,400,400);
276 TLegend* lEtaEff = new TLegend(0.65,0.85-etaHistos.size()*0.05,0.86,0.85);
277 cEtaEff->cd();
278 lEtaEff->SetFillColor(10);
279
280 color = kBlack;
281 for (unsigned int i=0;i<etaHistos.size();i++) {
282 TH1F* h = etaHistos[i];
283 lEtaEff->AddEntry(h,getLegLabel(jetalgs[i]).c_str(),"lp");
284 h->SetLineWidth(1);
285 h->SetMarkerColor(color);
286 h->SetLineColor(color++);
287 h->SetMarkerStyle(kFullCircle);
288 h->SetMarkerSize(0.5);
289 if (i==0) {
290 h->SetTitle("#epsilon_{FAKE} vs #eta");
291 h->SetXTitle("#eta");
292 h->SetYTitle("#epsilon_{FAKE}");
293 h->Draw("E");
294 h->SetMinimum(0.0);
295 h->SetMaximum(1.05);
296 }
297 else h->Draw("ESAME");
298
299 }
300 lEtaEff->Draw();
301
302 // et canvas
303 TCanvas* cEtEff = new TCanvas("FakeVsEt", "FakeVsEt",10,10,400,400);
304 TLegend* lEtEff = new TLegend(0.65,0.85-etHistos.size()*0.05,0.86,0.85);
305 cEtEff->cd();
306 lEtEff->SetFillColor(10);
307
308 color = kBlack;
309 for (unsigned int i=0;i<etHistos.size();i++) {
310 TH1F* h = etHistos[i];
311 lEtEff->AddEntry(h,getLegLabel(jetalgs[i]).c_str(),"lp");
312 h->SetLineWidth(1);
313 h->SetMarkerColor(color);
314 h->SetLineColor(color++);
315 h->SetMarkerStyle(kFullCircle);
316 h->SetMarkerSize(0.5);
317 if (i==0) {
318 h->SetTitle("#epsilon_{FAKE} vs E_{T}");
319 h->SetXTitle("E_{T} [GeV]");
320 h->SetYTitle("#epsilon_{FAKE}");
321 h->Draw("E");
322 h->SetMinimum(0.0);
323 h->SetMaximum(1.05);
324 }
325 else h->Draw("ESAME");
326 }
327 lEtEff->Draw();
328
329 app->Run();
330
331 return 0;
332 }
333
334
335 ////////////////////////////////////////////////////////////////////////////////
336 // implementation of global function
337 ////////////////////////////////////////////////////////////////////////////////
338
339 //______________________________________________________________________________
340 void setBinomialErrors(TH1F* hEff,const TH1F* hFake, const TH1F* hAll)
341 {
342 for (int i=1;i<hEff->GetNbinsX();i++) {
343 float nfake = hFake->GetBinContent(i);
344 float nall = hAll ->GetBinContent(i);
345 float eeff = (nall>0.0) ? std::sqrt(nfake/(nall*nall)*(1-nfake/nall)):0.0;
346 hEff->SetBinError(i,eeff);
347 }
348 }
349
350
351 //______________________________________________________________________________
352 string getLegLabel(const string& jetalg)
353 {
354 string result;
355 string tmp(jetalg);
356
357 if (tmp.find("kt")==0) {
358 result = "fast k_{T}, D=";
359 tmp=tmp.substr(2);
360 }
361 else if (tmp.find("sc")==0) {
362 result = "SISCone, R=";
363 tmp = tmp.substr(2);
364 }
365 else if (tmp.find("ic")==0) {
366 result = "Iterative Cone, R=";
367 tmp = tmp.substr(2);
368 }
369 else if (tmp.find("mc")==0) {
370 result = "Midpoint, R=";
371 tmp = tmp.substr(2);
372 }
373 else return result;
374
375 stringstream ssparam;
376 ssparam<<tmp;
377 float param;
378 ssparam>>param;
379 param = 0.1*param;
380 stringstream ssparam2;
381 ssparam2<<param;
382 result += ssparam2.str();
383
384 return result;
385 }