157 |
|
|
158 |
|
|
159 |
|
//________________________________________________________________________________________ |
160 |
+ |
// Master Formula |
161 |
+ |
void master_formula(std::vector<float> eff, float &errHi, float &errLo) { |
162 |
+ |
|
163 |
+ |
float x0 = eff[0]; |
164 |
+ |
float deltaPos = 0, deltaNeg = 0; |
165 |
+ |
for(int k = 0; k < (eff.size()-1)/2; k++) { |
166 |
+ |
float xneg = eff[2*k+2]; |
167 |
+ |
float xpos = eff[2*k+1]; |
168 |
+ |
if(xpos-x0>0 || xneg-x0>0) { |
169 |
+ |
if(xpos-x0 > xneg-x0) { |
170 |
+ |
deltaPos += (xpos-x0)*(xpos-x0); |
171 |
+ |
} else { |
172 |
+ |
deltaPos += (xneg-x0)*(xneg-x0); |
173 |
+ |
} |
174 |
+ |
} |
175 |
+ |
if(x0-xpos>0 || x0-xneg>0) { |
176 |
+ |
if(x0-xpos > x0-xneg) { |
177 |
+ |
deltaNeg += (xpos-x0)*(xpos-x0); |
178 |
+ |
} else { |
179 |
+ |
deltaNeg += (xneg-x0)*(xneg-x0); |
180 |
+ |
} |
181 |
+ |
} |
182 |
+ |
} |
183 |
+ |
errHi = sqrt(deltaPos); |
184 |
+ |
errLo = sqrt(deltaNeg); |
185 |
+ |
|
186 |
+ |
} |
187 |
+ |
|
188 |
+ |
|
189 |
+ |
//________________________________________________________________________________________ |
190 |
+ |
// Get normalization factor for the PDFs |
191 |
+ |
float get_norm_pdf_factor(TTree *events, int k) { |
192 |
+ |
|
193 |
+ |
TH1F *haux = new TH1F("haux", "", 1000, 0, 15); |
194 |
+ |
char nameVar[20]; |
195 |
+ |
sprintf(nameVar, "pdfW[%d]", k); |
196 |
+ |
events->Project("haux", nameVar); |
197 |
+ |
float factor = haux->Integral(); |
198 |
+ |
|
199 |
+ |
delete haux; |
200 |
+ |
|
201 |
+ |
return factor; |
202 |
+ |
|
203 |
+ |
} |
204 |
+ |
|
205 |
+ |
|
206 |
+ |
|
207 |
+ |
//________________________________________________________________________________________ |
208 |
|
// Pile-up efficiency |
209 |
|
float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) { |
210 |
|
nBins = 16; |
230 |
|
if(!automatized) dout << " PU: " << funcUp->Eval(jzbSel) << " " << func->Eval(jzbSel) |
231 |
|
<< "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl; |
232 |
|
|
233 |
< |
return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100.; |
233 |
> |
return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel); |
234 |
|
|
235 |
|
} |
236 |
|
|
266 |
|
else if(i==1) resdown=res; |
267 |
|
else if(i==2) resup=res; |
268 |
|
} |
269 |
< |
if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent)*100; |
270 |
< |
else result=(TMath::Abs(rescent-resdown)/rescent)*100; |
269 |
> |
if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent); |
270 |
> |
else result=(TMath::Abs(rescent-resdown)/rescent); |
271 |
|
} |
272 |
|
|
273 |
|
//____________________________________________________________________________________ |
274 |
|
// Total selection efficiency (MC) |
275 |
< |
void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") { |
275 |
> |
void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) { |
276 |
|
|
277 |
|
char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel); |
278 |
|
// All acceptance cuts at gen. level |
279 |
< |
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2"); |
279 |
> |
//TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2"); |
280 |
> |
TCut kbase(""); |
281 |
|
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23"; |
282 |
|
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses) |
283 |
|
// Corresponding reco. cuts |
284 |
|
TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)); |
285 |
< |
|
286 |
< |
events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff"); |
285 |
> |
TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)); |
286 |
> |
TCut posSide = kbase&&ksel; |
287 |
> |
TCut negSide = kbase&&ksel2; |
288 |
> |
string sposSide(posSide); |
289 |
> |
string snegSide(negSide); |
290 |
> |
char var[20]; |
291 |
> |
sprintf(var, "pdfW[%d]", k); |
292 |
> |
string svar(var); |
293 |
> |
string newPosSide = "(" + sposSide + ")*" + svar; |
294 |
> |
string newNegSide = "(" + snegSide + ")*" + svar; |
295 |
> |
|
296 |
> |
events->Draw(mcjzbexpression.c_str(), newPosSide.c_str(),"goff"); |
297 |
|
Float_t sel = events->GetSelectedRows(); |
298 |
+ |
Float_t nsel=0; |
299 |
+ |
if(ConsiderSignalContaminationForLimits) { |
300 |
+ |
events->Draw(mcjzbexpression.c_str(), newNegSide.c_str(),"goff"); |
301 |
+ |
nsel = events->GetSelectedRows(); |
302 |
+ |
} |
303 |
+ |
//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. |
304 |
+ |
float normFactor = get_norm_pdf_factor(events, k); |
305 |
+ |
sel = sel/normFactor; |
306 |
+ |
nsel = nsel/normFactor; |
307 |
+ |
|
308 |
|
// events->Draw(mcjzbexpression.c_str(),kbase,"goff"); |
309 |
|
// Float_t tot = events->GetSelectedRows(); |
310 |
|
Float_t tot = Neventsinfile; |
311 |
|
|
312 |
< |
result=sel/tot; |
313 |
< |
resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot); |
314 |
< |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << std::endl; |
312 |
> |
if(ConsiderSignalContaminationForLimits) { |
313 |
> |
result=(sel-nsel)/tot; |
314 |
> |
resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot); |
315 |
> |
} else {//no signal contamination considered: |
316 |
> |
result=(sel)/tot; |
317 |
> |
resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot); |
318 |
> |
} |
319 |
> |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl; |
320 |
|
} |
321 |
|
|
322 |
|
void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") { |
323 |
|
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2"); |
250 |
– |
cout << "Getting started with JZB efficiency" << endl; |
324 |
|
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses) |
325 |
|
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23"; |
326 |
|
TH1F* hLM4 = plotEff(events,kbase,informalname); |
364 |
|
if(!automatized) dout << " JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl; |
365 |
|
if(!automatized) dout << " central: " << eff << std::endl; |
366 |
|
if(!automatized) dout << " JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl; |
367 |
< |
jesup=(effp-eff)/eff*100.; |
368 |
< |
jesdown=(effm-eff)/eff*100.; |
367 |
> |
jesup=(effp-eff)/eff; |
368 |
> |
jesdown=(effm-eff)/eff; |
369 |
|
} |
370 |
|
|
371 |
|
//________________________________________________________________________ |
390 |
|
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl; |
391 |
|
if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl; |
392 |
|
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl; |
393 |
< |
up=((effp-eff)/eff)*100; |
394 |
< |
down=((effm-eff)/eff)*100; |
393 |
> |
up=((effp-eff)/eff); |
394 |
> |
down=((effm-eff)/eff); |
395 |
|
} |
396 |
|
|
397 |
|
//________________________________________________________________________ |
420 |
|
} |
421 |
|
|
422 |
|
|
423 |
< |
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="") { |
423 |
> |
//________________________________________________________________________________________ |
424 |
> |
// PDF uncertainty |
425 |
> |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, string addcut="") { |
426 |
> |
|
427 |
> |
int numberOfPDFs = 44; |
428 |
> |
std::vector<float> efficiency; |
429 |
> |
for(int k = 1; k < numberOfPDFs; k++) { |
430 |
> |
float result, resulterr; |
431 |
> |
MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k); |
432 |
> |
efficiency.push_back(result); |
433 |
> |
} |
434 |
> |
float errHi, errLow; |
435 |
> |
master_formula(efficiency, errHi, errLow); |
436 |
> |
if(errHi>errLow) return errHi; |
437 |
> |
return errLow; |
438 |
> |
|
439 |
> |
} |
440 |
> |
|
441 |
> |
|
442 |
> |
|
443 |
> |
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) { |
444 |
|
|
445 |
|
float JetEnergyScaleUncert=0.1; |
446 |
|
float JZBScaleUncert=0.1; |
447 |
|
mcjzbexpression=mcjzb; |
448 |
< |
float triggereff=4;//percent! |
448 |
> |
float triggereff=4.0/100;// in range [0,1] |
449 |
|
dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl; |
450 |
< |
float leptonseleff=2;//percent! |
450 |
> |
float leptonseleff=2.0/100;// in range [0,1] |
451 |
|
dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl; |
452 |
|
|
453 |
|
float mceff,mcefferr,jzbeff,jzbefferr; |
474 |
|
|
475 |
|
if(!automatized) dout << "Pileup: " << std::endl; |
476 |
|
float resolution=pileup(events,requireZ,informalname,addcut); |
477 |
< |
|
477 |
> |
|
478 |
> |
float PDFuncert=0; |
479 |
> |
if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, addcut); |
480 |
> |
|
481 |
|
dout << "_______________________________________________" << endl; |
482 |
|
dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) "; |
483 |
|
if(addcut!="") dout << "With additional cut: " << addcut; |
484 |
|
dout << endl; |
485 |
< |
dout << "MC efficiency: " << 100*mceff << "+/-" << 100*mcefferr << endl; |
486 |
< |
dout << "Trigger efficiency: " << triggereff << endl; |
487 |
< |
dout << "Lepton Sel Eff: " << leptonseleff << endl; |
488 |
< |
dout << "Jet energy scale: " << jesup << " " << jesdown << endl; |
489 |
< |
dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; |
490 |
< |
dout << "Resolution : " << resolution << endl; |
491 |
< |
dout << "From peak : " << sysfrompeak << endl; |
492 |
< |
dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; |
493 |
< |
dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; |
485 |
> |
dout << "MC efficiency: " << mceff << "+/-" << mcefferr << endl; // in range [0,1] |
486 |
> |
dout << "Trigger efficiency: " << triggereff << endl; // in range [0,1] |
487 |
> |
dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1] |
488 |
> |
dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1] |
489 |
> |
dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1] |
490 |
> |
dout << "Resolution : " << resolution << endl; // in range [0,1] |
491 |
> |
dout << "From peak : " << sysfrompeak << endl; // in range [0,1] |
492 |
> |
dout << "PDF uncertainty : " << PDFuncert << " (not yet included below) " << endl; // in range [0,1] |
493 |
> |
dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1] |
494 |
> |
dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1] |
495 |
|
|
496 |
|
float toterr=0; |
497 |
< |
toterr+=(triggereff/100)*(triggereff/100); |
498 |
< |
toterr+=(leptonseleff/100)*(leptonseleff/100); |
499 |
< |
if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup/100)*(jesup/100); else toterr+=(jesdown/100)*(jesdown/100); |
500 |
< |
if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup/100)*(scaleup/100); else toterr+=(scaledown/100)*(scaledown/100); |
501 |
< |
toterr+=(resolution/100)*(resolution/100); |
502 |
< |
toterr+=(sysfrompeak/100)*(sysfrompeak/100); |
503 |
< |
toterr=TMath::Sqrt(toterr); |
504 |
< |
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*toterr << " (syst) %" << endl; |
505 |
< |
dout << " we thus use the sqrt of the sum of the squares which is : " << 100*TMath::Sqrt(mcefferr*mcefferr+(toterr*toterr)) << endl; |
497 |
> |
toterr+=(triggereff)*(triggereff); |
498 |
> |
toterr+=(leptonseleff)*(leptonseleff); |
499 |
> |
if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown); |
500 |
> |
if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown); |
501 |
> |
toterr+=(resolution*resolution); |
502 |
> |
toterr+=(sysfrompeak*sysfrompeak); |
503 |
> |
if(ismSUGRA) toterr+=(PDFuncert*PDFuncert); |
504 |
> |
dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl; |
505 |
> |
float systerr=TMath::Sqrt(toterr)*mceff; |
506 |
> |
toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err! |
507 |
> |
|
508 |
> |
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst) %" << endl; |
509 |
> |
dout << " we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl; |
510 |
> |
|
511 |
> |
//Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions! |
512 |
|
vector<float> res; |
513 |
|
res.push_back(jzbSel); |
514 |
|
res.push_back(mceff); |
515 |
|
res.push_back(mcefferr); |
516 |
|
res.push_back(toterr); |
517 |
|
res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr))); |
518 |
< |
if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup/100)); else res.push_back(fabs(jesdown)/100); |
519 |
< |
if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)/100); else res.push_back(fabs(scaledown)/100); |
520 |
< |
res.push_back(fabs(resolution)/100); |
518 |
> |
if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown)); |
519 |
> |
if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown)); |
520 |
> |
res.push_back(fabs(resolution)); |
521 |
> |
if(ismSUGRA) res.push_back(PDFuncert); |
522 |
|
results.push_back(res); |
523 |
|
} |
524 |
|
|