1 |
buchmann |
1.1 |
#include <iostream>
|
2 |
|
|
#include <vector>
|
3 |
|
|
#include <sys/stat.h>
|
4 |
buchmann |
1.31 |
#include <algorithm>
|
5 |
|
|
#include <cmath>
|
6 |
buchmann |
1.1 |
|
7 |
|
|
#include <TMath.h>
|
8 |
|
|
#include <TColor.h>
|
9 |
|
|
#include <TPaveText.h>
|
10 |
|
|
#include <TRandom.h>
|
11 |
|
|
#include <TF1.h>
|
12 |
|
|
|
13 |
|
|
#ifndef SampleClassLoaded
|
14 |
|
|
#include "ActiveSamples.C"
|
15 |
|
|
#endif
|
16 |
|
|
|
17 |
|
|
#ifndef Verbosity
|
18 |
|
|
#define Verbosity 0
|
19 |
|
|
#endif
|
20 |
|
|
|
21 |
|
|
#include <TFile.h>
|
22 |
|
|
#include <TTree.h>
|
23 |
|
|
#include <TH1.h>
|
24 |
|
|
#include <TCut.h>
|
25 |
|
|
#include <TMath.h>
|
26 |
|
|
#include <TLine.h>
|
27 |
|
|
#include <TCanvas.h>
|
28 |
|
|
#include <TProfile.h>
|
29 |
|
|
#include <TF1.h>
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
Int_t nBins = 100;
|
34 |
|
|
Float_t jzbMin = -207;
|
35 |
|
|
Float_t jzbMax = 243;
|
36 |
|
|
Float_t jzbSel = 100;
|
37 |
|
|
int iplot=0;
|
38 |
|
|
int verbose=0;
|
39 |
buchmann |
1.2 |
string geqleq;
|
40 |
|
|
string mcjzbexpression;
|
41 |
buchmann |
1.4 |
bool automatized=false;//if we're running this fully automatized we don't want each function to flood the screen
|
42 |
buchmann |
1.2 |
|
43 |
|
|
TString geq_or_leq() {
|
44 |
|
|
if(geqleq=="geq") return TString(">=");
|
45 |
|
|
if(geqleq=="leq") return TString("<=");
|
46 |
|
|
return TString("GEQ_OR_LEQ_ERROR");
|
47 |
|
|
}
|
48 |
buchmann |
1.1 |
|
49 |
buchmann |
1.6 |
TString ngeq_or_leq() {
|
50 |
|
|
if(geqleq=="geq") return TString("<=");
|
51 |
|
|
if(geqleq=="leq") return TString(">=");
|
52 |
|
|
return TString("NGEQ_OR_LEQ_ERROR");
|
53 |
|
|
}
|
54 |
|
|
|
55 |
buchmann |
1.1 |
//______________________________________________________________________________
|
56 |
|
|
Double_t Interpolate(Double_t x, TH1 *histo)
|
57 |
|
|
{
|
58 |
|
|
// Given a point x, approximates the value via linear interpolation
|
59 |
|
|
// based on the two nearest bin centers
|
60 |
|
|
// Andy Mastbaum 10/21/08
|
61 |
|
|
// in newer ROOT versions but not in the one I have so I had to work around that ...
|
62 |
|
|
|
63 |
|
|
Int_t xbin = histo->FindBin(x);
|
64 |
|
|
Double_t x0,x1,y0,y1;
|
65 |
|
|
|
66 |
|
|
if(x<=histo->GetBinCenter(1)) {
|
67 |
|
|
return histo->GetBinContent(1);
|
68 |
|
|
} else if(x>=histo->GetBinCenter(histo->GetNbinsX())) {
|
69 |
|
|
return histo->GetBinContent(histo->GetNbinsX());
|
70 |
|
|
} else {
|
71 |
|
|
if(x<=histo->GetBinCenter(xbin)) {
|
72 |
|
|
y0 = histo->GetBinContent(xbin-1);
|
73 |
|
|
x0 = histo->GetBinCenter(xbin-1);
|
74 |
|
|
y1 = histo->GetBinContent(xbin);
|
75 |
|
|
x1 = histo->GetBinCenter(xbin);
|
76 |
|
|
} else {
|
77 |
|
|
y0 = histo->GetBinContent(xbin);
|
78 |
|
|
x0 = histo->GetBinCenter(xbin);
|
79 |
|
|
y1 = histo->GetBinContent(xbin+1);
|
80 |
|
|
x1 = histo->GetBinCenter(xbin+1);
|
81 |
|
|
}
|
82 |
|
|
return y0 + (x-x0)*((y1-y0)/(x1-x0));
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
buchmann |
1.7 |
//____________________________________________________________________________________
|
87 |
|
|
// Plotting with all contributions, i.e. sidebands, peak, osof,ossf ... (for a systematic)
|
88 |
|
|
float allcontributionsplot(TTree* events, TCut kBaseCut, TCut kMassCut, TCut kSidebandCut, TCut JZBPosCut, TCut JZBNegCut) {
|
89 |
|
|
iplot++;
|
90 |
|
|
int count=iplot;
|
91 |
|
|
// Define new histogram
|
92 |
|
|
string hname=GetNumericHistoName();
|
93 |
|
|
TH1F* hossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
94 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSSF,"goff");
|
95 |
|
|
hname=GetNumericHistoName();
|
96 |
|
|
TH1F* hossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
97 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSSF,"goff");
|
98 |
|
|
|
99 |
|
|
hname=GetNumericHistoName();
|
100 |
|
|
TH1F* hosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
101 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSOF,"goff");
|
102 |
|
|
hname=GetNumericHistoName();
|
103 |
|
|
TH1F* hosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
104 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSOF,"goff");
|
105 |
|
|
|
106 |
|
|
hname=GetNumericHistoName();
|
107 |
|
|
TH1F* sbhossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
108 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSSF,"goff");
|
109 |
|
|
hname=GetNumericHistoName();
|
110 |
|
|
TH1F* sbhossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
111 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSSF,"goff");
|
112 |
|
|
|
113 |
|
|
hname=GetNumericHistoName();
|
114 |
|
|
TH1F* sbhosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
115 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSOF,"goff");
|
116 |
|
|
hname=GetNumericHistoName();
|
117 |
|
|
TH1F* sbhosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
|
118 |
|
|
events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSOF,"goff");
|
119 |
|
|
|
120 |
|
|
float obs = hossfp->Integral();
|
121 |
|
|
float pred= hossfn->Integral() + (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
|
122 |
|
|
|
123 |
|
|
delete hossfp,hossfn,hosofp,hosofn;
|
124 |
|
|
delete sbhossfp,sbhossfn,sbhosofp,sbhosofn;
|
125 |
|
|
return obs-pred;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
buchmann |
1.1 |
|
129 |
|
|
//____________________________________________________________________________________
|
130 |
|
|
// Efficiency plot
|
131 |
|
|
TH1F* plotEff(TTree* events, TCut kbase, TString informalname) {
|
132 |
|
|
iplot++;
|
133 |
|
|
int count=iplot;
|
134 |
|
|
// Define new histogram
|
135 |
|
|
char hname[30]; sprintf(hname,"hJzbEff%d",count);
|
136 |
|
|
TH1F* hJzbEff = new TH1F(hname,"JZB selection efficiency ; JZB (GeV/c); Efficiency",
|
137 |
|
|
nBins,jzbMin,jzbMax);
|
138 |
|
|
Float_t step = (jzbMax-jzbMin)/static_cast<Float_t>(nBins);
|
139 |
|
|
|
140 |
buchmann |
1.6 |
events->Draw(mcjzbexpression.c_str(),"genJZB>-400"&&kbase,"goff");
|
141 |
buchmann |
1.1 |
Float_t maxEff = events->GetSelectedRows();
|
142 |
buchmann |
1.5 |
if(verbose>0) dout << hname << " (" << informalname <<") " << maxEff << std::endl;
|
143 |
buchmann |
1.1 |
|
144 |
buchmann |
1.5 |
if(verbose>0) dout << "JZB max = " << jzbMax << std::endl;
|
145 |
buchmann |
1.1 |
// Loop over steps to get efficiency curve
|
146 |
|
|
char cut[256];
|
147 |
|
|
for ( Int_t iBin = 0; iBin<nBins; ++iBin ) {
|
148 |
buchmann |
1.6 |
sprintf(cut,"genJZB>%3f",jzbMin+iBin*step);
|
149 |
buchmann |
1.2 |
events->Draw(mcjzbexpression.c_str(),TCut(cut)&&kbase,"goff");
|
150 |
buchmann |
1.1 |
Float_t eff = static_cast<Float_t>(events->GetSelectedRows())/maxEff;
|
151 |
buchmann |
1.5 |
// dout << "COUCOU " << __LINE__ << std::endl;
|
152 |
buchmann |
1.1 |
hJzbEff->SetBinContent(iBin+1,eff);
|
153 |
|
|
hJzbEff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/maxEff));
|
154 |
|
|
}
|
155 |
|
|
return hJzbEff;
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
//________________________________________________________________________________________
|
162 |
pablom |
1.23 |
// Master Formula
|
163 |
|
|
void master_formula(std::vector<float> eff, float &errHi, float &errLo) {
|
164 |
|
|
|
165 |
|
|
float x0 = eff[0];
|
166 |
|
|
float deltaPos = 0, deltaNeg = 0;
|
167 |
|
|
for(int k = 0; k < (eff.size()-1)/2; k++) {
|
168 |
|
|
float xneg = eff[2*k+2];
|
169 |
|
|
float xpos = eff[2*k+1];
|
170 |
|
|
if(xpos-x0>0 || xneg-x0>0) {
|
171 |
|
|
if(xpos-x0 > xneg-x0) {
|
172 |
|
|
deltaPos += (xpos-x0)*(xpos-x0);
|
173 |
|
|
} else {
|
174 |
|
|
deltaPos += (xneg-x0)*(xneg-x0);
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
if(x0-xpos>0 || x0-xneg>0) {
|
178 |
|
|
if(x0-xpos > x0-xneg) {
|
179 |
|
|
deltaNeg += (xpos-x0)*(xpos-x0);
|
180 |
|
|
} else {
|
181 |
|
|
deltaNeg += (xneg-x0)*(xneg-x0);
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
errHi = sqrt(deltaPos);
|
186 |
|
|
errLo = sqrt(deltaNeg);
|
187 |
|
|
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
//________________________________________________________________________________________
|
192 |
|
|
// Get normalization factor for the PDFs
|
193 |
|
|
float get_norm_pdf_factor(TTree *events, int k) {
|
194 |
|
|
|
195 |
buchmann |
1.25 |
TH1F *haux = new TH1F("haux", "", 10000, 0, 5);
|
196 |
pablom |
1.23 |
char nameVar[20];
|
197 |
|
|
sprintf(nameVar, "pdfW[%d]", k);
|
198 |
|
|
events->Project("haux", nameVar);
|
199 |
buchmann |
1.24 |
float thisW = haux->Integral();
|
200 |
|
|
events->Project("haux", "pdfW[0]");
|
201 |
|
|
float normW = haux->Integral();
|
202 |
|
|
|
203 |
|
|
float factor=thisW/normW;
|
204 |
pablom |
1.23 |
|
205 |
|
|
delete haux;
|
206 |
|
|
|
207 |
|
|
return factor;
|
208 |
|
|
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
//________________________________________________________________________________________
|
214 |
buchmann |
1.1 |
// Pile-up efficiency
|
215 |
buchmann |
1.10 |
float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) {
|
216 |
buchmann |
1.1 |
nBins = 16;
|
217 |
|
|
jzbMax = myJzbMax;
|
218 |
|
|
|
219 |
|
|
// Acceptance cuts
|
220 |
buchmann |
1.6 |
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
|
221 |
buchmann |
1.10 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
222 |
|
|
|
223 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
224 |
buchmann |
1.1 |
TH1F* hLM4 = plotEff(events,kbase,informalname);
|
225 |
|
|
hLM4->SetMinimum(0.);
|
226 |
|
|
|
227 |
|
|
// Nominal function
|
228 |
|
|
TF1* func = new TF1("func","0.5*TMath::Erfc([0]*x-[1])",jzbMin,jzbMax);
|
229 |
|
|
func->SetParameter(0,0.03);
|
230 |
|
|
func->SetParameter(1,0.);
|
231 |
|
|
hLM4->Fit(func,"Q");
|
232 |
|
|
|
233 |
|
|
// Pimped-up function
|
234 |
|
|
TF1* funcUp = (TF1*)func->Clone();
|
235 |
|
|
funcUp->SetParameter( 0., func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
|
236 |
buchmann |
1.5 |
if(!automatized) dout << " PU: " << funcUp->Eval(jzbSel) << " " << func->Eval(jzbSel)
|
237 |
buchmann |
1.1 |
<< "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl;
|
238 |
|
|
|
239 |
buchmann |
1.18 |
return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel);
|
240 |
buchmann |
1.1 |
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
//____________________________________________________________________________________
|
244 |
buchmann |
1.6 |
// Effect of peak shifting
|
245 |
buchmann |
1.10 |
void PeakError(TTree *events,float &result, string mcjzb, float peakerr,string addcut="") {
|
246 |
buchmann |
1.6 |
TString peakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
|
247 |
|
|
TString peakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
|
248 |
|
|
TString peakcentral("("+TString(mcjzb)+")"+geq_or_leq()+TString(any2string(jzbSel)));
|
249 |
|
|
TString npeakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
|
250 |
|
|
TString npeakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
|
251 |
|
|
TString npeakcentral("("+TString(mcjzb)+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
|
252 |
|
|
|
253 |
|
|
nBins = 1;
|
254 |
|
|
string informalname="PeakErrorCalculation";
|
255 |
|
|
float resup,resdown,rescent;
|
256 |
|
|
for(int i=0;i<3;i++) {
|
257 |
|
|
string poscut,negcut;
|
258 |
|
|
if(i==0) {
|
259 |
|
|
poscut=peakcentral;
|
260 |
|
|
negcut=npeakcentral;
|
261 |
|
|
} else if(i==1) {
|
262 |
|
|
poscut=peakdown;
|
263 |
|
|
negcut=npeakdown;
|
264 |
|
|
} else if(i==2) {
|
265 |
|
|
poscut=peakup;
|
266 |
|
|
negcut=npeakup;
|
267 |
|
|
}
|
268 |
buchmann |
1.10 |
float res;
|
269 |
|
|
if(addcut=="") res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
|
270 |
|
|
else res=allcontributionsplot(events,cutnJets&&addcut.c_str(),cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
|
271 |
buchmann |
1.7 |
if(i==0) rescent=res;
|
272 |
|
|
else if(i==1) resdown=res;
|
273 |
|
|
else if(i==2) resup=res;
|
274 |
buchmann |
1.6 |
}
|
275 |
buchmann |
1.18 |
if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent);
|
276 |
|
|
else result=(TMath::Abs(rescent-resdown)/rescent);
|
277 |
buchmann |
1.6 |
}
|
278 |
|
|
|
279 |
|
|
//____________________________________________________________________________________
|
280 |
buchmann |
1.1 |
// Total selection efficiency (MC)
|
281 |
buchmann |
1.33 |
//returns the efficiency WITHOUT signal contamination, and the result and resulterr contain the result and the corresponding error
|
282 |
|
|
Value MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) {
|
283 |
buchmann |
1.1 |
|
284 |
buchmann |
1.36 |
if(!events) {
|
285 |
|
|
write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
|
286 |
|
|
return Value(0,0);
|
287 |
|
|
}
|
288 |
|
|
|
289 |
buchmann |
1.1 |
char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
|
290 |
|
|
// All acceptance cuts at gen. level
|
291 |
buchmann |
1.14 |
//TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
|
292 |
|
|
TCut kbase("");
|
293 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
294 |
buchmann |
1.9 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
295 |
buchmann |
1.1 |
// Corresponding reco. cuts
|
296 |
buchmann |
1.11 |
TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
|
297 |
buchmann |
1.15 |
TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
|
298 |
pablom |
1.23 |
TCut posSide = kbase&&ksel;
|
299 |
|
|
TCut negSide = kbase&&ksel2;
|
300 |
|
|
string sposSide(posSide);
|
301 |
|
|
string snegSide(negSide);
|
302 |
|
|
char var[20];
|
303 |
|
|
sprintf(var, "pdfW[%d]", k);
|
304 |
|
|
string svar(var);
|
305 |
|
|
string newPosSide = "(" + sposSide + ")*" + svar;
|
306 |
|
|
string newNegSide = "(" + snegSide + ")*" + svar;
|
307 |
|
|
|
308 |
buchmann |
1.24 |
TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
|
309 |
buchmann |
1.36 |
cout << "right before drawing" << endl;
|
310 |
|
|
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"");
|
311 |
|
|
else events->Draw((mcjzbexpression+">>effh").c_str(), sposSide.c_str(),"");
|
312 |
|
|
cout << "right after drawing" << endl;
|
313 |
|
|
cout << "consider sigcont?" << ConsiderSignalContaminationForLimits << endl;
|
314 |
buchmann |
1.24 |
Float_t sel = effh->Integral();
|
315 |
buchmann |
1.21 |
Float_t nsel=0;
|
316 |
|
|
if(ConsiderSignalContaminationForLimits) {
|
317 |
buchmann |
1.36 |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"");
|
318 |
|
|
else events->Draw((mcjzbexpression+">>effh").c_str(), snegSide.c_str(),"");
|
319 |
buchmann |
1.24 |
nsel = effh->Integral();
|
320 |
buchmann |
1.21 |
}
|
321 |
pablom |
1.23 |
//Corrections due to normalization in the PDF. This has to be applied as well to the number of events in a file if the definition changes at some point.
|
322 |
buchmann |
1.26 |
float normFactor = 1;
|
323 |
|
|
if(k>=0) get_norm_pdf_factor(events, k);
|
324 |
pablom |
1.23 |
sel = sel/normFactor;
|
325 |
|
|
nsel = nsel/normFactor;
|
326 |
|
|
|
327 |
buchmann |
1.13 |
// events->Draw(mcjzbexpression.c_str(),kbase,"goff");
|
328 |
|
|
// Float_t tot = events->GetSelectedRows();
|
329 |
|
|
Float_t tot = Neventsinfile;
|
330 |
buchmann |
1.1 |
|
331 |
buchmann |
1.33 |
Value result_wo_signalcont;
|
332 |
|
|
|
333 |
buchmann |
1.21 |
if(ConsiderSignalContaminationForLimits) {
|
334 |
|
|
result=(sel-nsel)/tot;
|
335 |
|
|
resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
|
336 |
buchmann |
1.33 |
result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot));
|
337 |
buchmann |
1.21 |
} else {//no signal contamination considered:
|
338 |
|
|
result=(sel)/tot;
|
339 |
|
|
resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
|
340 |
buchmann |
1.33 |
result_wo_signalcont=Value(result,resulterr);
|
341 |
buchmann |
1.21 |
}
|
342 |
buchmann |
1.32 |
if(!automatized && k>0 ) dout << "PDF assessment: ";
|
343 |
buchmann |
1.24 |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl;
|
344 |
|
|
delete effh;
|
345 |
buchmann |
1.34 |
return result_wo_signalcont;
|
346 |
buchmann |
1.1 |
}
|
347 |
|
|
|
348 |
buchmann |
1.29 |
|
349 |
|
|
//____________________________________________________________________________________
|
350 |
buchmann |
1.30 |
// Selection efficiency for one process (MC)
|
351 |
buchmann |
1.29 |
vector<float> processMCefficiency(TTree *events,string mcjzb,bool requireZ,int Neventsinfile, string addcut) {
|
352 |
|
|
vector<float> process_efficiencies;
|
353 |
|
|
for(int iprocess=0;iprocess<=10;iprocess++) {
|
354 |
|
|
float this_process_efficiency,efferr;
|
355 |
|
|
stringstream addcutplus;
|
356 |
|
|
addcutplus<<addcut<<"&&(process=="<<iprocess<<")";
|
357 |
|
|
MCefficiency(events,this_process_efficiency, efferr,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1);
|
358 |
|
|
process_efficiencies.push_back(this_process_efficiency);
|
359 |
|
|
}
|
360 |
|
|
return process_efficiencies;
|
361 |
|
|
}
|
362 |
|
|
|
363 |
|
|
|
364 |
buchmann |
1.10 |
void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
|
365 |
buchmann |
1.6 |
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
|
366 |
buchmann |
1.10 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
367 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
368 |
buchmann |
1.1 |
TH1F* hLM4 = plotEff(events,kbase,informalname);
|
369 |
|
|
Int_t bin = hLM4->FindBin(jzbSel); // To get the error
|
370 |
buchmann |
1.8 |
jzbeff=Interpolate(jzbSel,hLM4);
|
371 |
|
|
jzbefferr=hLM4->GetBinError(bin);
|
372 |
buchmann |
1.5 |
if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
|
373 |
buchmann |
1.8 |
if(!automatized) dout << " " << jzbeff << "+-" << jzbefferr << std::endl;
|
374 |
buchmann |
1.1 |
}
|
375 |
|
|
|
376 |
|
|
//________________________________________________________________________
|
377 |
|
|
// Effect of energy scale on efficiency
|
378 |
buchmann |
1.10 |
void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,string addcut="",float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
|
379 |
buchmann |
1.6 |
TCut kbase("abs(genMll-91.2)<20&&genZPt>0");
|
380 |
buchmann |
1.10 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
381 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
382 |
|
|
|
383 |
buchmann |
1.1 |
TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
|
384 |
|
|
TCut nJets("pfJetGoodNum>2");
|
385 |
|
|
stringstream down,up;
|
386 |
|
|
down << "pfJetGoodNum"<<30*(1-syst)<<">=3";
|
387 |
|
|
up << "pfJetGoodNum"<<30*(1+syst)<<">=3";
|
388 |
|
|
|
389 |
|
|
TCut nJetsP(up.str().c_str());
|
390 |
|
|
TCut nJetsM(down.str().c_str());
|
391 |
|
|
|
392 |
|
|
if ( !(plotName.Length()>1) ) plotName = informalname;
|
393 |
|
|
|
394 |
|
|
nBins = 1; jzbMin = jzbSel*0.95; jzbMax = jzbSel*1.05;
|
395 |
|
|
TH1F* hist = plotEff(events,(kbase&&ksel&&nJets),informalname);
|
396 |
|
|
|
397 |
|
|
TH1F* histp = plotEff(events,(kbase&&ksel&&nJetsP),informalname);
|
398 |
|
|
|
399 |
|
|
TH1F* histm = plotEff(events,(kbase&&ksel&&nJetsM),informalname);
|
400 |
|
|
|
401 |
|
|
// Dump some information
|
402 |
|
|
Float_t eff = Interpolate(jzbSel,hist);
|
403 |
|
|
Float_t effp = Interpolate(jzbSel,histp);
|
404 |
|
|
Float_t effm = Interpolate(jzbSel,histm);
|
405 |
buchmann |
1.5 |
if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
|
406 |
|
|
if(!automatized) dout << " JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
|
407 |
|
|
if(!automatized) dout << " central: " << eff << std::endl;
|
408 |
|
|
if(!automatized) dout << " JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
|
409 |
buchmann |
1.18 |
jesup=(effp-eff)/eff;
|
410 |
|
|
jesdown=(effm-eff)/eff;
|
411 |
buchmann |
1.1 |
}
|
412 |
|
|
|
413 |
|
|
//________________________________________________________________________
|
414 |
|
|
// Effect of energy scale on JZB efficiency
|
415 |
buchmann |
1.10 |
void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ, string addcut) {
|
416 |
buchmann |
1.1 |
|
417 |
buchmann |
1.6 |
TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
|
418 |
buchmann |
1.10 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
419 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
420 |
buchmann |
1.1 |
TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
|
421 |
|
|
|
422 |
|
|
nBins = 50;
|
423 |
|
|
jzbMin = 0.5*jzbSel;
|
424 |
|
|
jzbMax = 2.0*jzbSel;
|
425 |
|
|
|
426 |
|
|
TH1F* hist = plotEff(events,kbase&&ksel,informalname);
|
427 |
|
|
|
428 |
|
|
// Dump some information
|
429 |
|
|
Float_t eff = Interpolate(jzbSel,hist);
|
430 |
|
|
Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
|
431 |
|
|
Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
|
432 |
buchmann |
1.33 |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl;
|
433 |
buchmann |
1.5 |
if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl;
|
434 |
buchmann |
1.33 |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl;
|
435 |
buchmann |
1.18 |
up=((effp-eff)/eff);
|
436 |
|
|
down=((effm-eff)/eff);
|
437 |
buchmann |
1.1 |
}
|
438 |
|
|
|
439 |
|
|
//________________________________________________________________________
|
440 |
|
|
// JZB response (true/reco. vs. true)
|
441 |
buchmann |
1.10 |
void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, string addcut="",bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
|
442 |
buchmann |
1.1 |
|
443 |
|
|
jzbMin = 20;
|
444 |
buchmann |
1.6 |
TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
|
445 |
buchmann |
1.10 |
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
|
446 |
buchmann |
1.8 |
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
|
447 |
buchmann |
1.1 |
TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
|
448 |
|
|
|
449 |
buchmann |
1.8 |
TProfile* hJzbResp = new TProfile("hJzbResp","JZB response ; JZB true (GeV/c); JZB reco. / JZB true", nPeriods, jzbMin, myJzbMax, "" );
|
450 |
buchmann |
1.1 |
|
451 |
buchmann |
1.6 |
if (!isMET) events->Project("hJzbResp","("+TString(mcjzbexpression)+")/genJZB:genJZB",kbase&&ksel);
|
452 |
buchmann |
1.1 |
else events->Project("hJzbResp","met[4]/genMET:genMET",kbase&&ksel);
|
453 |
|
|
|
454 |
|
|
hJzbResp->SetMaximum(1.2);
|
455 |
|
|
hJzbResp->SetMinimum(0.2);
|
456 |
|
|
hJzbResp->Fit("pol0","Q");
|
457 |
|
|
TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
|
458 |
buchmann |
1.32 |
if(!fittedfunction) {
|
459 |
|
|
// in case there are not enough points passing our selection
|
460 |
|
|
cout << "OOPS response function invalid, assuming 100% error !!!!" << endl;
|
461 |
|
|
resp=1;
|
462 |
|
|
resperr=1;
|
463 |
|
|
} else {
|
464 |
|
|
resp=fittedfunction->GetParameter(0);
|
465 |
|
|
resperr=fittedfunction->GetParError(0);
|
466 |
|
|
if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl;
|
467 |
|
|
}
|
468 |
buchmann |
1.5 |
delete hJzbResp;
|
469 |
buchmann |
1.1 |
}
|
470 |
|
|
|
471 |
|
|
|
472 |
pablom |
1.23 |
//________________________________________________________________________________________
|
473 |
|
|
// PDF uncertainty
|
474 |
buchmann |
1.24 |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") {
|
475 |
pablom |
1.23 |
std::vector<float> efficiency;
|
476 |
buchmann |
1.24 |
for(int k = 1; k < NPdfs; k++) {
|
477 |
pablom |
1.23 |
float result, resulterr;
|
478 |
|
|
MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k);
|
479 |
|
|
efficiency.push_back(result);
|
480 |
|
|
}
|
481 |
buchmann |
1.24 |
float errHi, errLow,err;
|
482 |
pablom |
1.23 |
master_formula(efficiency, errHi, errLow);
|
483 |
buchmann |
1.24 |
err=errLow;
|
484 |
|
|
if(errHi>errLow) err=errHi;
|
485 |
|
|
if(!automatized) dout << " Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl;
|
486 |
|
|
return err;
|
487 |
pablom |
1.23 |
|
488 |
|
|
}
|
489 |
|
|
|
490 |
buchmann |
1.24 |
int get_npdfs(TTree *events) {
|
491 |
|
|
int NPDFs;
|
492 |
|
|
events->SetBranchAddress("NPdfs",&NPDFs);
|
493 |
|
|
events->GetEntry(1);
|
494 |
|
|
return NPDFs;
|
495 |
|
|
}
|
496 |
|
|
|
497 |
pablom |
1.23 |
|
498 |
buchmann |
1.22 |
void do_systematics_for_one_file(TTree *events,int Neventsinfile,string informalname, vector<vector<float> > &results,string mcjzb,string datajzb,float peakerror,bool requireZ=false, string addcut="", bool ismSUGRA=false) {
|
499 |
buchmann |
1.1 |
float JetEnergyScaleUncert=0.1;
|
500 |
|
|
float JZBScaleUncert=0.1;
|
501 |
buchmann |
1.2 |
mcjzbexpression=mcjzb;
|
502 |
buchmann |
1.28 |
float triggereff=5.0/100;// in range [0,1]
|
503 |
buchmann |
1.5 |
dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl;
|
504 |
buchmann |
1.18 |
float leptonseleff=2.0/100;// in range [0,1]
|
505 |
buchmann |
1.32 |
leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton
|
506 |
buchmann |
1.5 |
dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl;
|
507 |
buchmann |
1.1 |
|
508 |
buchmann |
1.27 |
int NPdfs=0;
|
509 |
|
|
if(ismSUGRA) NPdfs = get_npdfs(events);
|
510 |
buchmann |
1.29 |
|
511 |
buchmann |
1.8 |
float mceff,mcefferr,jzbeff,jzbefferr;
|
512 |
buchmann |
1.5 |
if(!automatized) dout << "MC efficiencies:" << endl;
|
513 |
buchmann |
1.34 |
Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut,-1);
|
514 |
buchmann |
1.35 |
if(!automatized) cout << " Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl;
|
515 |
|
|
|
516 |
buchmann |
1.32 |
if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
|
517 |
buchmann |
1.8 |
if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
|
518 |
buchmann |
1.1 |
|
519 |
buchmann |
1.6 |
if(!automatized) dout << "Error from Peak position:" << endl;
|
520 |
|
|
float sysfrompeak=0;
|
521 |
buchmann |
1.10 |
PeakError(events,sysfrompeak,mcjzb,peakerror,addcut);
|
522 |
buchmann |
1.6 |
|
523 |
buchmann |
1.5 |
if(!automatized) dout << "Jet energy scale: " << std::endl;
|
524 |
buchmann |
1.1 |
float jesup,jesdown;
|
525 |
buchmann |
1.10 |
JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert);
|
526 |
buchmann |
1.1 |
|
527 |
buchmann |
1.5 |
if(!automatized) dout << "JZB scale: " << std::endl;
|
528 |
buchmann |
1.1 |
float scaleup,scaledown,scalesyst;
|
529 |
buchmann |
1.10 |
doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut);
|
530 |
buchmann |
1.1 |
|
531 |
buchmann |
1.5 |
if(!automatized) dout << "JZB response: " << std::endl;
|
532 |
buchmann |
1.8 |
float resp,resperr;
|
533 |
buchmann |
1.32 |
if(PlottingSetup::computeJZBresponse) {
|
534 |
|
|
if(!automatized) dout << "JZB response: " << std::endl;
|
535 |
|
|
JZBresponse(events,requireZ,resp,resperr,addcut);
|
536 |
|
|
}
|
537 |
buchmann |
1.1 |
|
538 |
buchmann |
1.5 |
if(!automatized) dout << "Pileup: " << std::endl;
|
539 |
buchmann |
1.32 |
float resolution;
|
540 |
|
|
resolution=pileup(events,requireZ,informalname,addcut);
|
541 |
pablom |
1.23 |
|
542 |
buchmann |
1.22 |
float PDFuncert=0;
|
543 |
buchmann |
1.32 |
if(!automatized) dout << "Assessing PDF uncertainty: " << std::endl;
|
544 |
buchmann |
1.24 |
if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut);
|
545 |
pablom |
1.23 |
|
546 |
buchmann |
1.5 |
dout << "_______________________________________________" << endl;
|
547 |
buchmann |
1.10 |
dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) ";
|
548 |
|
|
if(addcut!="") dout << "With additional cut: " << addcut;
|
549 |
|
|
dout << endl;
|
550 |
buchmann |
1.18 |
dout << "MC efficiency: " << mceff << "+/-" << mcefferr << endl; // in range [0,1]
|
551 |
|
|
dout << "Trigger efficiency: " << triggereff << endl; // in range [0,1]
|
552 |
|
|
dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1]
|
553 |
|
|
dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1]
|
554 |
|
|
dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
|
555 |
|
|
dout << "Resolution : " << resolution << endl; // in range [0,1]
|
556 |
|
|
dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
|
557 |
buchmann |
1.24 |
if(ismSUGRA) dout << "PDF uncertainty : " << PDFuncert << endl; // in range [0,1]
|
558 |
buchmann |
1.32 |
if(PlottingSetup::computeJZBefficiency) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
|
559 |
|
|
if(PlottingSetup::computeJZBresponse)dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
|
560 |
buchmann |
1.1 |
|
561 |
buchmann |
1.4 |
float toterr=0;
|
562 |
buchmann |
1.18 |
toterr+=(triggereff)*(triggereff);
|
563 |
|
|
toterr+=(leptonseleff)*(leptonseleff);
|
564 |
|
|
if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown);
|
565 |
|
|
if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
|
566 |
|
|
toterr+=(resolution*resolution);
|
567 |
|
|
toterr+=(sysfrompeak*sysfrompeak);
|
568 |
buchmann |
1.22 |
if(ismSUGRA) toterr+=(PDFuncert*PDFuncert);
|
569 |
buchmann |
1.18 |
dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
|
570 |
buchmann |
1.19 |
float systerr=TMath::Sqrt(toterr)*mceff;
|
571 |
|
|
toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
|
572 |
|
|
|
573 |
|
|
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst) %" << endl;
|
574 |
|
|
dout << " we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
|
575 |
buchmann |
1.36 |
dout << "_______________________________________________" << endl;
|
576 |
buchmann |
1.19 |
|
577 |
|
|
//Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
|
578 |
buchmann |
1.4 |
vector<float> res;
|
579 |
|
|
res.push_back(jzbSel);
|
580 |
|
|
res.push_back(mceff);
|
581 |
|
|
res.push_back(mcefferr);
|
582 |
|
|
res.push_back(toterr);
|
583 |
|
|
res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr)));
|
584 |
buchmann |
1.18 |
if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
|
585 |
|
|
if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
|
586 |
|
|
res.push_back(fabs(resolution));
|
587 |
buchmann |
1.35 |
res.push_back(mceff_nosigcont.getValue());
|
588 |
|
|
res.push_back(mceff_nosigcont.getError());
|
589 |
|
|
if(ismSUGRA) res.push_back(PDFuncert);
|
590 |
buchmann |
1.34 |
results.push_back(res);
|
591 |
buchmann |
1.1 |
}
|
592 |
|
|
|
593 |
buchmann |
1.8 |
vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
|
594 |
buchmann |
1.4 |
automatized=true;
|
595 |
|
|
vector< vector<float> > systematics;
|
596 |
buchmann |
1.1 |
for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
|
597 |
buchmann |
1.5 |
dout << "Looking at signal " << (signalsamples.collection)[isignal].filename << endl;
|
598 |
buchmann |
1.1 |
for(int ibin=0;ibin<bins.size();ibin++) {
|
599 |
|
|
jzbSel=bins[ibin];
|
600 |
buchmann |
1.2 |
geqleq="geq";
|
601 |
buchmann |
1.13 |
do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
|
602 |
buchmann |
1.1 |
}//end of bin loop
|
603 |
|
|
}//end of signal loop
|
604 |
buchmann |
1.4 |
return systematics;
|
605 |
buchmann |
1.1 |
}
|