1 |
dkralph |
1.1 |
#include "FR_struct.h"
|
2 |
|
|
//----------------------------------------------------------------------------------------
|
3 |
|
|
FR_struct::FR_struct(TString mufile, TString elefile)
|
4 |
|
|
{
|
5 |
|
|
cout << "loading fake file: " << mufile << endl;
|
6 |
|
|
// kevin's format
|
7 |
|
|
mufrfile = TFile::Open(mufile); assert(mufrfile->IsOpen());
|
8 |
|
|
hFRmu = (TH2D*)mufrfile->Get("frEtaPt"); hFRmu->SetDirectory(0);
|
9 |
|
|
hFRmuErrl = (TH2D*)mufrfile->Get("errlEtaPt"); hFRmuErrl->SetDirectory(0);
|
10 |
|
|
hFRmuErrh = (TH2D*)mufrfile->Get("errhEtaPt"); hFRmuErrh->SetDirectory(0);
|
11 |
|
|
mufrfile->Close();
|
12 |
|
|
cout << "loading fake file: " << elefile << endl;
|
13 |
|
|
elefrfile = TFile::Open(elefile); assert(elefrfile->IsOpen());
|
14 |
|
|
hFRele = (TH2D*)elefrfile->Get("frEtaPt"); hFRele->SetDirectory(0);
|
15 |
|
|
hFReleErrl = (TH2D*)elefrfile->Get("errlEtaPt"); hFReleErrl->SetDirectory(0);
|
16 |
|
|
hFReleErrh = (TH2D*)elefrfile->Get("errhEtaPt"); hFReleErrh->SetDirectory(0);
|
17 |
|
|
elefrfile->Close();
|
18 |
|
|
// si's format
|
19 |
|
|
dynamicMuErrHists = dynamicEleErrHists = false;
|
20 |
|
|
if(!hFRmu) {
|
21 |
|
|
TH2DAsymErr *hAsymMu = (TH2DAsymErr*)mufrfile->Get("efficiency_denominator_v1_eta_pt");
|
22 |
|
|
hFRmu = (TH2D*)hAsymMu;
|
23 |
|
|
dynamicMuErrHists = true;
|
24 |
|
|
hFRmuErrl = new TH2D(*hFRmu); hFRmuErrl->Reset();
|
25 |
|
|
hFRmuErrh = new TH2D(*hFRmu); hFRmuErrh->Reset();
|
26 |
|
|
mufr.loadEff(hFRmu,hFRmuErrl,hFRmuErrh);
|
27 |
|
|
setErrors(hAsymMu,&mufr);
|
28 |
|
|
}
|
29 |
|
|
if(!hFRele) {
|
30 |
|
|
TH2DAsymErr *hAsymEle = (TH2DAsymErr*)elefrfile->Get("efficiency_denominator_v3_eta_pt");
|
31 |
|
|
hFRele = (TH2D*)hAsymEle;
|
32 |
|
|
dynamicEleErrHists = true;
|
33 |
|
|
hFReleErrl = new TH2D(*hFRele); hFReleErrl->Reset();
|
34 |
|
|
hFReleErrh = new TH2D(*hFRele); hFReleErrh->Reset();
|
35 |
|
|
elefr.loadEff(hFRele,hFReleErrl,hFReleErrh);
|
36 |
|
|
setErrors(hAsymEle,&elefr);
|
37 |
|
|
}
|
38 |
|
|
mufr.loadEff(hFRmu,hFRmuErrl,hFRmuErrh);
|
39 |
|
|
elefr.loadEff(hFRele,hFReleErrl,hFReleErrh);
|
40 |
|
|
|
41 |
|
|
// figure out whether to use abs eta
|
42 |
|
|
if(hFRmu->GetXaxis()->GetBinLowEdge(1) < 0) absEtaMu = false;
|
43 |
|
|
else absEtaMu = true;
|
44 |
|
|
if(absEtaMu) cout << "\nUsing abs eta in muon fake rates: " << setprecision(3) << hFRmu->GetXaxis()->GetBinLowEdge(1) << endl;
|
45 |
|
|
else cout << "\nNot using abs eta in muon fake rates: " << setprecision(3) << hFRmu->GetXaxis()->GetBinLowEdge(1) << endl;
|
46 |
|
|
if(hFRele->GetXaxis()->GetBinLowEdge(1) < 0) absEtaEle = false;
|
47 |
|
|
else absEtaEle = true;
|
48 |
|
|
if(absEtaEle) cout << "\nUsing abs eta in electron fake rates: " << setprecision(3) << hFRele->GetXaxis()->GetBinLowEdge(1) << endl;
|
49 |
|
|
else cout << "\nNot using abs eta in electron fake rates: " << setprecision(3) << hFRele->GetXaxis()->GetBinLowEdge(1) << endl;
|
50 |
|
|
|
51 |
|
|
// mufr.printEff(cout);
|
52 |
|
|
// elefr.printEff(cout);
|
53 |
|
|
// mufr.printErrLow(cout);
|
54 |
|
|
// elefr.printErrLow(cout);
|
55 |
|
|
// mufr.printErrHigh(cout);
|
56 |
|
|
// elefr.printErrHigh(cout);
|
57 |
|
|
}
|
58 |
|
|
//----------------------------------------------------------------------------------------
|
59 |
|
|
FR_struct::~FR_struct()
|
60 |
|
|
{
|
61 |
|
|
if(dynamicMuErrHists) {
|
62 |
|
|
delete hFRmuErrl;
|
63 |
|
|
delete hFRmuErrh;
|
64 |
|
|
}
|
65 |
|
|
if(dynamicEleErrHists) {
|
66 |
|
|
delete hFReleErrl;
|
67 |
|
|
delete hFReleErrh;
|
68 |
|
|
}
|
69 |
|
|
if(mufrfile && mufrfile->IsOpen()) mufrfile->Close();
|
70 |
|
|
if(elefrfile && elefrfile->IsOpen()) elefrfile->Close();
|
71 |
|
|
}
|
72 |
|
|
//----------------------------------------------------------------------------------------
|
73 |
|
|
double FR_struct::get_fake_weight(TString uncert, SimpleLepton fake_lep)
|
74 |
|
|
{
|
75 |
|
|
double rate=0;
|
76 |
|
|
assert(uncert=="" || uncert=="lo" || uncert=="hi");
|
77 |
|
|
double x = fake_lep.vec.Eta();
|
78 |
|
|
double y = fake_lep.vec.Pt();
|
79 |
|
|
if(abs(fake_lep.type) == 13) { // fake muons:
|
80 |
|
|
if(absEtaMu) x = fabs(x);
|
81 |
|
|
rate = mufr.getEff(x,y,true);
|
82 |
|
|
if(uncert == "lo") rate -= mufr.getErrLow(x,y,true);
|
83 |
|
|
if(uncert == "hi") rate += mufr.getErrHigh(x,y,true);
|
84 |
|
|
} else if(abs(fake_lep.type) == 11) {
|
85 |
|
|
if(absEtaEle) x = fabs(x);
|
86 |
|
|
rate = elefr.getEff(x,y,true);
|
87 |
|
|
if(uncert == "lo") rate -= elefr.getErrLow(x,y,true);
|
88 |
|
|
if(uncert == "hi") rate += elefr.getErrHigh(x,y,true);
|
89 |
|
|
} else { cout << "Bad fake type: " << fake_lep.type << endl; assert(0); }
|
90 |
|
|
|
91 |
|
|
if(rate==1) cout << "ERROR: rate = 1! " << endl;
|
92 |
|
|
|
93 |
|
|
double weight = rate/(1-rate);
|
94 |
|
|
assert(weight == weight);
|
95 |
|
|
return weight;
|
96 |
|
|
}
|
97 |
|
|
//----------------------------------------------------------------------------------------
|
98 |
|
|
void FR_struct::setErrors(TH2DAsymErr *h, CEffUser2D *fr)
|
99 |
|
|
{
|
100 |
|
|
assert(fr->getHerrl() && fr->getHerrl());
|
101 |
|
|
for(int xbin=0; xbin<h->GetXaxis()->GetNbins()+2; xbin++) {
|
102 |
|
|
for(int ybin=0; ybin<h->GetYaxis()->GetNbins()+2; ybin++) {
|
103 |
|
|
int ncell = h->GetBin(xbin,ybin);
|
104 |
|
|
int ncellChk = fr->getHerrl()->GetBin(xbin,ybin);
|
105 |
|
|
assert(ncell==ncellChk);
|
106 |
|
|
|
107 |
|
|
double errl = h->GetBinError(xbin,ybin,TH2DAsymErr::kStatErrLow);
|
108 |
|
|
fr->getHerrl()->SetBinContent(ncell,errl);
|
109 |
|
|
double errh = h->GetBinError(xbin,ybin,TH2DAsymErr::kStatErrHigh);
|
110 |
|
|
fr->getHerrh()->SetBinContent(ncell,errh);
|
111 |
|
|
}
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
//----------------------------------------------------------------------------------------
|
115 |
|
|
void FR_struct::printSiEff(TH2DAsymErr *h, TH2DAsymErr::EErrType errType)
|
116 |
|
|
{
|
117 |
|
|
const Int_t nx = h->GetNbinsX();
|
118 |
|
|
const Int_t ny = h->GetNbinsY();
|
119 |
|
|
|
120 |
|
|
for(Int_t iy=0; iy<=ny; iy++) {
|
121 |
|
|
for(Int_t ix=0; ix<=nx; ix++) {
|
122 |
|
|
if(ix==0 && iy==0) {
|
123 |
|
|
cout << setw(11) << "";
|
124 |
|
|
} else if(ix==0) {
|
125 |
|
|
cout << "[" << setw(4) << h->GetYaxis()->GetBinLowEdge(iy) << "," << setw(4) << h->GetYaxis()->GetBinLowEdge(iy+1) << "]";
|
126 |
|
|
} else if(iy==0) {
|
127 |
|
|
cout << "[" << setw(4) << h->GetXaxis()->GetBinLowEdge(ix) << "," << setw(4) << h->GetXaxis()->GetBinLowEdge(ix+1) << "]";
|
128 |
|
|
} else {
|
129 |
|
|
ios_base::fmtflags flags = cout.flags();
|
130 |
|
|
cout.precision(7);
|
131 |
|
|
cout << " " << setw(9) << fixed << h->GetBinError(ix,iy,errType) << " ";
|
132 |
|
|
cout.flags(flags);
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
cout << endl;
|
136 |
|
|
}
|
137 |
|
|
}
|