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> |
159 |
|
|
160 |
|
|
161 |
|
//________________________________________________________________________________________ |
162 |
+ |
// 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 |
+ |
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 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 |
+ |
|
207 |
+ |
return factor; |
208 |
+ |
|
209 |
+ |
} |
210 |
+ |
|
211 |
+ |
|
212 |
+ |
|
213 |
+ |
//________________________________________________________________________________________ |
214 |
|
// Pile-up efficiency |
215 |
|
float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) { |
216 |
|
nBins = 16; |
278 |
|
|
279 |
|
//____________________________________________________________________________________ |
280 |
|
// Total selection efficiency (MC) |
281 |
< |
void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") { |
281 |
> |
//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 |
|
|
284 |
|
char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel); |
285 |
|
// All acceptance cuts at gen. level |
290 |
|
// Corresponding reco. cuts |
291 |
|
TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)); |
292 |
|
TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)); |
293 |
< |
events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff"); |
294 |
< |
Float_t sel = events->GetSelectedRows(); |
295 |
< |
events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff"); |
296 |
< |
Float_t nsel = events->GetSelectedRows(); |
293 |
> |
TCut posSide = kbase&&ksel; |
294 |
> |
TCut negSide = kbase&&ksel2; |
295 |
> |
string sposSide(posSide); |
296 |
> |
string snegSide(negSide); |
297 |
> |
char var[20]; |
298 |
> |
sprintf(var, "pdfW[%d]", k); |
299 |
> |
string svar(var); |
300 |
> |
string newPosSide = "(" + sposSide + ")*" + svar; |
301 |
> |
string newNegSide = "(" + snegSide + ")*" + svar; |
302 |
> |
|
303 |
> |
TH1F *effh= new TH1F("effh","effh",1,-14000,14000); |
304 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"goff"); |
305 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), sposSide.c_str(),"goff"); |
306 |
> |
Float_t sel = effh->Integral(); |
307 |
> |
Float_t nsel=0; |
308 |
> |
if(ConsiderSignalContaminationForLimits) { |
309 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"goff"); |
310 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), snegSide.c_str(),"goff"); |
311 |
> |
nsel = effh->Integral(); |
312 |
> |
} |
313 |
> |
//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. |
314 |
> |
float normFactor = 1; |
315 |
> |
if(k>=0) get_norm_pdf_factor(events, k); |
316 |
> |
sel = sel/normFactor; |
317 |
> |
nsel = nsel/normFactor; |
318 |
> |
|
319 |
|
// events->Draw(mcjzbexpression.c_str(),kbase,"goff"); |
320 |
|
// Float_t tot = events->GetSelectedRows(); |
321 |
|
Float_t tot = Neventsinfile; |
322 |
|
|
323 |
< |
result=(sel-nsel)/tot; |
324 |
< |
resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot); |
325 |
< |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl; |
323 |
> |
Value result_wo_signalcont; |
324 |
> |
|
325 |
> |
if(ConsiderSignalContaminationForLimits) { |
326 |
> |
result=(sel-nsel)/tot; |
327 |
> |
resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot); |
328 |
> |
result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot)); |
329 |
> |
} else {//no signal contamination considered: |
330 |
> |
result=(sel)/tot; |
331 |
> |
resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot); |
332 |
> |
result_wo_signalcont=Value(result,resulterr); |
333 |
> |
} |
334 |
> |
if(!automatized && k>0 ) dout << "PDF assessment (" << k << ") : "; |
335 |
> |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl; |
336 |
> |
delete effh; |
337 |
> |
return result_wo_signalcont; |
338 |
> |
} |
339 |
> |
|
340 |
> |
|
341 |
> |
//____________________________________________________________________________________ |
342 |
> |
// Selection efficiency for one process (MC) |
343 |
> |
vector<float> processMCefficiency(TTree *events,string mcjzb,bool requireZ,int Neventsinfile, string addcut) { |
344 |
> |
vector<float> process_efficiencies; |
345 |
> |
for(int iprocess=0;iprocess<=10;iprocess++) { |
346 |
> |
float this_process_efficiency,efferr; |
347 |
> |
stringstream addcutplus; |
348 |
> |
addcutplus<<addcut<<"&&(process=="<<iprocess<<")"; |
349 |
> |
MCefficiency(events,this_process_efficiency, efferr,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1); |
350 |
> |
process_efficiencies.push_back(this_process_efficiency); |
351 |
> |
} |
352 |
> |
return process_efficiencies; |
353 |
|
} |
354 |
+ |
|
355 |
|
|
356 |
|
void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") { |
357 |
|
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2"); |
421 |
|
Float_t eff = Interpolate(jzbSel,hist); |
422 |
|
Float_t effp = Interpolate(jzbSel*(1.+systematic),hist); |
423 |
|
Float_t effm = Interpolate(jzbSel*(1.-systematic),hist); |
424 |
< |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl; |
424 |
> |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl; |
425 |
|
if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl; |
426 |
< |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl; |
426 |
> |
if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl; |
427 |
|
up=((effp-eff)/eff); |
428 |
|
down=((effm-eff)/eff); |
429 |
|
} |
447 |
|
hJzbResp->SetMinimum(0.2); |
448 |
|
hJzbResp->Fit("pol0","Q"); |
449 |
|
TF1 *fittedfunction = hJzbResp->GetFunction("pol0"); |
450 |
< |
resp=fittedfunction->GetParameter(0); |
451 |
< |
resperr=fittedfunction->GetParError(0); |
452 |
< |
if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl; |
450 |
> |
if(!fittedfunction) { |
451 |
> |
// in case there are not enough points passing our selection |
452 |
> |
cout << "OOPS response function invalid, assuming 100% error !!!!" << endl; |
453 |
> |
resp=1; |
454 |
> |
resperr=1; |
455 |
> |
} else { |
456 |
> |
resp=fittedfunction->GetParameter(0); |
457 |
> |
resperr=fittedfunction->GetParError(0); |
458 |
> |
if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl; |
459 |
> |
} |
460 |
|
delete hJzbResp; |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
< |
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="") { |
464 |
> |
//________________________________________________________________________________________ |
465 |
> |
// PDF uncertainty |
466 |
> |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") { |
467 |
> |
std::vector<float> efficiency; |
468 |
> |
for(int k = 1; k < NPdfs; k++) { |
469 |
> |
float result, resulterr; |
470 |
> |
MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k); |
471 |
> |
efficiency.push_back(result); |
472 |
> |
} |
473 |
> |
float errHi, errLow,err; |
474 |
> |
master_formula(efficiency, errHi, errLow); |
475 |
> |
err=errLow; |
476 |
> |
if(errHi>errLow) err=errHi; |
477 |
> |
if(!automatized) dout << " Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl; |
478 |
> |
return err; |
479 |
> |
|
480 |
> |
} |
481 |
> |
|
482 |
> |
int get_npdfs(TTree *events) { |
483 |
> |
int NPDFs; |
484 |
> |
events->SetBranchAddress("NPdfs",&NPDFs); |
485 |
> |
events->GetEntry(1); |
486 |
> |
return NPDFs; |
487 |
> |
} |
488 |
|
|
489 |
+ |
|
490 |
+ |
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) { |
491 |
|
float JetEnergyScaleUncert=0.1; |
492 |
|
float JZBScaleUncert=0.1; |
493 |
|
mcjzbexpression=mcjzb; |
494 |
< |
float triggereff=4.0/100;// in range [0,1] |
494 |
> |
float triggereff=5.0/100;// in range [0,1] |
495 |
|
dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl; |
496 |
|
float leptonseleff=2.0/100;// in range [0,1] |
497 |
+ |
leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton |
498 |
|
dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl; |
499 |
|
|
500 |
+ |
int NPdfs=0; |
501 |
+ |
if(ismSUGRA) NPdfs = get_npdfs(events); |
502 |
+ |
|
503 |
|
float mceff,mcefferr,jzbeff,jzbefferr; |
504 |
|
if(!automatized) dout << "MC efficiencies:" << endl; |
505 |
< |
MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut); |
506 |
< |
JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut); |
505 |
> |
Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut,-1); |
506 |
> |
if(!automatized) cout << " Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl; |
507 |
> |
|
508 |
> |
if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut); |
509 |
|
if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl; |
510 |
|
|
511 |
+ |
|
512 |
+ |
if(!(mceff>0)) write_warning(__FUNCTION__,"Efficiency is zero - the systematics will not be computed!"); |
513 |
+ |
|
514 |
+ |
|
515 |
|
if(!automatized) dout << "Error from Peak position:" << endl; |
516 |
|
float sysfrompeak=0; |
517 |
< |
PeakError(events,sysfrompeak,mcjzb,peakerror,addcut); |
517 |
> |
if(mceff>0) PeakError(events,sysfrompeak,mcjzb,peakerror,addcut); |
518 |
> |
else dout << "Not computed." << endl; |
519 |
|
|
520 |
|
if(!automatized) dout << "Jet energy scale: " << std::endl; |
521 |
< |
float jesup,jesdown; |
522 |
< |
JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert); |
521 |
> |
float jesup=0,jesdown=0; |
522 |
> |
if(mceff>0) JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert); |
523 |
> |
else dout << "Not computed." << endl; |
524 |
|
|
525 |
|
if(!automatized) dout << "JZB scale: " << std::endl; |
526 |
< |
float scaleup,scaledown,scalesyst; |
527 |
< |
doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut); |
526 |
> |
float scaleup=0,scaledown=0,scalesyst=0; |
527 |
> |
if(mceff>0) doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut); |
528 |
> |
else dout << "Not computed." << endl; |
529 |
|
|
530 |
|
if(!automatized) dout << "JZB response: " << std::endl; |
531 |
< |
float resp,resperr; |
532 |
< |
JZBresponse(events,requireZ,resp,resperr,addcut); |
531 |
> |
float resp=0,resperr=0; |
532 |
> |
if(PlottingSetup::computeJZBresponse && mceff>0) { |
533 |
> |
if(!automatized) dout << "JZB response: " << std::endl; |
534 |
> |
JZBresponse(events,requireZ,resp,resperr,addcut); |
535 |
> |
} |
536 |
|
|
537 |
|
if(!automatized) dout << "Pileup: " << std::endl; |
538 |
< |
float resolution=pileup(events,requireZ,informalname,addcut); |
539 |
< |
|
538 |
> |
float resolution=0; |
539 |
> |
if(mceff>0) resolution=pileup(events,requireZ,informalname,addcut); |
540 |
> |
else dout << "Not computed." << endl; |
541 |
> |
|
542 |
> |
float PDFuncert=0; |
543 |
> |
if(!automatized&&mceff>0) dout << "Assessing PDF uncertainty: " << std::endl; |
544 |
> |
if(ismSUGRA&&mceff>0) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut); |
545 |
> |
|
546 |
|
dout << "_______________________________________________" << endl; |
547 |
|
dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) "; |
548 |
|
if(addcut!="") dout << "With additional cut: " << addcut; |
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 |
< |
dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1] |
558 |
< |
dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1] |
557 |
> |
if(ismSUGRA) dout << "PDF uncertainty : " << PDFuncert << endl; // in range [0,1] |
558 |
> |
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 |
|
|
561 |
|
float toterr=0; |
562 |
|
toterr+=(triggereff)*(triggereff); |
565 |
|
if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown); |
566 |
|
toterr+=(resolution*resolution); |
567 |
|
toterr+=(sysfrompeak*sysfrompeak); |
568 |
+ |
if(ismSUGRA) toterr+=(PDFuncert*PDFuncert); |
569 |
|
dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl; |
570 |
|
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 |
+ |
dout << "_______________________________________________" << endl; |
576 |
|
|
577 |
|
//Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions! |
578 |
|
vector<float> res; |
584 |
|
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 |
+ |
res.push_back(mceff_nosigcont.getValue()); |
588 |
+ |
res.push_back(mceff_nosigcont.getError()); |
589 |
+ |
if(ismSUGRA) res.push_back(PDFuncert); |
590 |
|
results.push_back(res); |
591 |
|
} |
592 |
|
|