1 |
|
#include <iostream> |
2 |
|
#include <vector> |
3 |
|
#include <sys/stat.h> |
4 |
+ |
#include <algorithm> |
5 |
+ |
#include <cmath> |
6 |
|
|
7 |
|
#include <TMath.h> |
8 |
|
#include <TColor.h> |
192 |
|
// Get normalization factor for the PDFs |
193 |
|
float get_norm_pdf_factor(TTree *events, int k) { |
194 |
|
|
195 |
< |
TH1F *haux = new TH1F("haux", "", 1000, 0, 15); |
195 |
> |
TH1F *haux = new TH1F("haux", "", 10000, 0, 5); |
196 |
|
char nameVar[20]; |
197 |
|
sprintf(nameVar, "pdfW[%d]", k); |
198 |
|
events->Project("haux", nameVar); |
199 |
< |
float factor = haux->Integral(); |
199 |
> |
float thisW = haux->Integral(); |
200 |
> |
events->Project("haux", "pdfW[0]"); |
201 |
> |
float normW = haux->Integral(); |
202 |
> |
|
203 |
> |
float factor=thisW/normW; |
204 |
|
|
205 |
|
delete haux; |
206 |
|
|
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))); |
246 |
– |
|
252 |
|
nBins = 1; |
253 |
|
string informalname="PeakErrorCalculation"; |
254 |
|
float resup,resdown,rescent; |
271 |
|
else if(i==1) resdown=res; |
272 |
|
else if(i==2) resup=res; |
273 |
|
} |
274 |
< |
if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent); |
275 |
< |
else result=(TMath::Abs(rescent-resdown)/rescent); |
274 |
> |
if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/(float)rescent); |
275 |
> |
else result=(TMath::Abs(rescent-resdown)/(float)rescent); |
276 |
|
} |
277 |
|
|
278 |
|
//____________________________________________________________________________________ |
279 |
|
// Total selection efficiency (MC) |
280 |
< |
void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) { |
281 |
< |
|
280 |
> |
//returns the efficiency WITHOUT signal contamination, and the result and resulterr contain the result and the corresponding error |
281 |
> |
Value MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) { |
282 |
> |
if(!events) { |
283 |
> |
write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!"); |
284 |
> |
result=0;resulterr=0; |
285 |
> |
return Value(0,0); |
286 |
> |
} |
287 |
|
char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel); |
288 |
|
// All acceptance cuts at gen. level |
289 |
|
//TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2"); |
303 |
|
string newPosSide = "(" + sposSide + ")*" + svar; |
304 |
|
string newNegSide = "(" + snegSide + ")*" + svar; |
305 |
|
|
306 |
< |
events->Draw(mcjzbexpression.c_str(), newPosSide.c_str(),"goff"); |
307 |
< |
Float_t sel = events->GetSelectedRows(); |
306 |
> |
TH1F *effh= new TH1F("effh","effh",1,-14000,14000); |
307 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"goff"); |
308 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), sposSide.c_str(),"goff"); |
309 |
> |
Float_t sel = effh->Integral(); |
310 |
|
Float_t nsel=0; |
311 |
|
if(ConsiderSignalContaminationForLimits) { |
312 |
< |
events->Draw(mcjzbexpression.c_str(), newNegSide.c_str(),"goff"); |
313 |
< |
nsel = events->GetSelectedRows(); |
312 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"goff"); |
313 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), snegSide.c_str(),"goff"); |
314 |
> |
nsel = effh->Integral(); |
315 |
|
} |
316 |
|
//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. |
317 |
< |
float normFactor = get_norm_pdf_factor(events, k); |
317 |
> |
float normFactor = 1; |
318 |
> |
if(k>=0) get_norm_pdf_factor(events, k); |
319 |
|
sel = sel/normFactor; |
320 |
|
nsel = nsel/normFactor; |
321 |
|
|
323 |
|
// Float_t tot = events->GetSelectedRows(); |
324 |
|
Float_t tot = Neventsinfile; |
325 |
|
|
326 |
+ |
Value result_wo_signalcont; |
327 |
+ |
|
328 |
|
if(ConsiderSignalContaminationForLimits) { |
329 |
|
result=(sel-nsel)/tot; |
330 |
|
resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot); |
331 |
+ |
result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot)); |
332 |
|
} else {//no signal contamination considered: |
333 |
|
result=(sel)/tot; |
334 |
|
resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot); |
335 |
+ |
result_wo_signalcont=Value(result,resulterr); |
336 |
|
} |
337 |
< |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl; |
337 |
> |
if(!automatized && k>0 ) dout << "PDF assessment (" << k << ") : "; |
338 |
> |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl; |
339 |
> |
delete effh; |
340 |
> |
return result_wo_signalcont; |
341 |
> |
} |
342 |
> |
|
343 |
> |
|
344 |
> |
//____________________________________________________________________________________ |
345 |
> |
// Selection efficiency for one process (MC) |
346 |
> |
vector<float> processMCefficiency(TTree *events,string mcjzb,bool requireZ,int Neventsinfile, string addcut) { |
347 |
> |
vector<float> process_efficiencies; |
348 |
> |
for(int iprocess=0;iprocess<=10;iprocess++) { |
349 |
> |
float this_process_efficiency,efferr; |
350 |
> |
stringstream addcutplus; |
351 |
> |
addcutplus<<addcut<<"&&(process=="<<iprocess<<")"; |
352 |
> |
MCefficiency(events,this_process_efficiency, efferr,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1); |
353 |
> |
process_efficiencies.push_back(this_process_efficiency); |
354 |
> |
} |
355 |
> |
return process_efficiencies; |
356 |
|
} |
357 |
+ |
|
358 |
|
|
359 |
|
void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") { |
360 |
|
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2"); |
424 |
|
Float_t eff = Interpolate(jzbSel,hist); |
425 |
|
Float_t effp = Interpolate(jzbSel*(1.+systematic),hist); |
426 |
|
Float_t effm = Interpolate(jzbSel*(1.-systematic),hist); |
427 |
< |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl; |
427 |
> |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl; |
428 |
|
if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl; |
429 |
< |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl; |
429 |
> |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl; |
430 |
|
up=((effp-eff)/eff); |
431 |
|
down=((effm-eff)/eff); |
432 |
|
} |
450 |
|
hJzbResp->SetMinimum(0.2); |
451 |
|
hJzbResp->Fit("pol0","Q"); |
452 |
|
TF1 *fittedfunction = hJzbResp->GetFunction("pol0"); |
453 |
< |
resp=fittedfunction->GetParameter(0); |
454 |
< |
resperr=fittedfunction->GetParError(0); |
455 |
< |
if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl; |
453 |
> |
if(!fittedfunction) { |
454 |
> |
// in case there are not enough points passing our selection |
455 |
> |
cout << "OOPS response function invalid, assuming 100% error !!!!" << endl; |
456 |
> |
resp=1; |
457 |
> |
resperr=1; |
458 |
> |
} else { |
459 |
> |
resp=fittedfunction->GetParameter(0); |
460 |
> |
resperr=fittedfunction->GetParError(0); |
461 |
> |
if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl; |
462 |
> |
} |
463 |
|
delete hJzbResp; |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
|
//________________________________________________________________________________________ |
468 |
|
// PDF uncertainty |
469 |
< |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, string addcut="") { |
426 |
< |
|
427 |
< |
int numberOfPDFs = 44; |
469 |
> |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") { |
470 |
|
std::vector<float> efficiency; |
471 |
< |
for(int k = 1; k < numberOfPDFs; k++) { |
471 |
> |
for(int k = 1; k < NPdfs; k++) { |
472 |
|
float result, resulterr; |
473 |
|
MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k); |
474 |
|
efficiency.push_back(result); |
475 |
|
} |
476 |
< |
float errHi, errLow; |
476 |
> |
float errHi, errLow,err; |
477 |
|
master_formula(efficiency, errHi, errLow); |
478 |
< |
if(errHi>errLow) return errHi; |
479 |
< |
return errLow; |
478 |
> |
err=errLow; |
479 |
> |
if(errHi>errLow) err=errHi; |
480 |
> |
if(!automatized) dout << " Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl; |
481 |
> |
return err; |
482 |
|
|
483 |
|
} |
484 |
|
|
485 |
< |
|
485 |
> |
int get_npdfs(TTree *events) { |
486 |
> |
int NPDFs; |
487 |
> |
events->SetBranchAddress("NPdfs",&NPDFs); |
488 |
> |
events->GetEntry(1); |
489 |
> |
return NPDFs; |
490 |
> |
} |
491 |
> |
|
492 |
|
|
493 |
|
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 |
– |
|
494 |
|
float JetEnergyScaleUncert=0.1; |
495 |
|
float JZBScaleUncert=0.1; |
496 |
|
mcjzbexpression=mcjzb; |
497 |
< |
float triggereff=4.0/100;// in range [0,1] |
497 |
> |
float triggereff=5.0/100;// in range [0,1] |
498 |
|
dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl; |
499 |
|
float leptonseleff=2.0/100;// in range [0,1] |
500 |
+ |
leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton |
501 |
|
dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl; |
502 |
|
|
503 |
+ |
int NPdfs=0; |
504 |
+ |
if(ismSUGRA) NPdfs = get_npdfs(events); |
505 |
+ |
|
506 |
|
float mceff,mcefferr,jzbeff,jzbefferr; |
507 |
|
if(!automatized) dout << "MC efficiencies:" << endl; |
508 |
< |
MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut); |
509 |
< |
JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut); |
508 |
> |
Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut,-1); |
509 |
> |
if(!automatized) cout << " Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl; |
510 |
> |
|
511 |
> |
if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut); |
512 |
|
if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl; |
513 |
|
|
514 |
+ |
|
515 |
+ |
if(!(mceff>0)) write_warning(__FUNCTION__,"Efficiency is zero - the systematics will not be computed!"); |
516 |
+ |
|
517 |
+ |
|
518 |
|
if(!automatized) dout << "Error from Peak position:" << endl; |
519 |
|
float sysfrompeak=0; |
520 |
< |
PeakError(events,sysfrompeak,mcjzb,peakerror,addcut); |
520 |
> |
if(mceff>0) PeakError(events,sysfrompeak,mcjzb,peakerror,addcut); |
521 |
> |
else dout << "Not computed." << endl; |
522 |
|
|
523 |
|
if(!automatized) dout << "Jet energy scale: " << std::endl; |
524 |
< |
float jesup,jesdown; |
525 |
< |
JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert); |
524 |
> |
float jesup=0,jesdown=0; |
525 |
> |
if(mceff>0) JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert); |
526 |
> |
else dout << "Not computed." << endl; |
527 |
|
|
528 |
|
if(!automatized) dout << "JZB scale: " << std::endl; |
529 |
< |
float scaleup,scaledown,scalesyst; |
530 |
< |
doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut); |
529 |
> |
float scaleup=0,scaledown=0,scalesyst=0; |
530 |
> |
if(mceff>0) doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut); |
531 |
> |
else dout << "Not computed." << endl; |
532 |
|
|
533 |
|
if(!automatized) dout << "JZB response: " << std::endl; |
534 |
< |
float resp,resperr; |
535 |
< |
JZBresponse(events,requireZ,resp,resperr,addcut); |
534 |
> |
float resp=0,resperr=0; |
535 |
> |
if(PlottingSetup::computeJZBresponse && mceff>0) { |
536 |
> |
if(!automatized) dout << "JZB response: " << std::endl; |
537 |
> |
JZBresponse(events,requireZ,resp,resperr,addcut); |
538 |
> |
} |
539 |
|
|
540 |
|
if(!automatized) dout << "Pileup: " << std::endl; |
541 |
< |
float resolution=pileup(events,requireZ,informalname,addcut); |
541 |
> |
float resolution=0; |
542 |
> |
if(mceff>0) resolution=pileup(events,requireZ,informalname,addcut); |
543 |
> |
else dout << "Not computed." << endl; |
544 |
|
|
545 |
|
float PDFuncert=0; |
546 |
< |
if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, addcut); |
546 |
> |
if(!automatized&&mceff>0) dout << "Assessing PDF uncertainty: " << std::endl; |
547 |
> |
if(ismSUGRA&&mceff>0) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut); |
548 |
|
|
549 |
|
dout << "_______________________________________________" << endl; |
550 |
|
dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) "; |
557 |
|
dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1] |
558 |
|
dout << "Resolution : " << resolution << endl; // in range [0,1] |
559 |
|
dout << "From peak : " << sysfrompeak << endl; // in range [0,1] |
560 |
< |
dout << "PDF uncertainty : " << PDFuncert << " (not yet included below) " << endl; // in range [0,1] |
561 |
< |
dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1] |
562 |
< |
dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1] |
560 |
> |
if(ismSUGRA) dout << "PDF uncertainty : " << PDFuncert << endl; // in range [0,1] |
561 |
> |
if(PlottingSetup::computeJZBefficiency) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1] |
562 |
> |
if(PlottingSetup::computeJZBresponse)dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1] |
563 |
|
|
564 |
|
float toterr=0; |
565 |
|
toterr+=(triggereff)*(triggereff); |
575 |
|
|
576 |
|
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst) %" << endl; |
577 |
|
dout << " we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl; |
578 |
+ |
dout << "_______________________________________________" << endl; |
579 |
|
|
580 |
|
//Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions! |
581 |
|
vector<float> res; |
587 |
|
if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown)); |
588 |
|
if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown)); |
589 |
|
res.push_back(fabs(resolution)); |
590 |
+ |
res.push_back(mceff_nosigcont.getValue()); |
591 |
+ |
res.push_back(mceff_nosigcont.getError()); |
592 |
|
if(ismSUGRA) res.push_back(PDFuncert); |
593 |
|
results.push_back(res); |
594 |
|
} |