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 |
> |
void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) { |
282 |
|
|
283 |
|
char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel); |
284 |
|
// All acceptance cuts at gen. level |
289 |
|
// Corresponding reco. cuts |
290 |
|
TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)); |
291 |
|
TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)); |
292 |
< |
events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff"); |
293 |
< |
Float_t sel = events->GetSelectedRows(); |
294 |
< |
events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff"); |
295 |
< |
Float_t nsel = events->GetSelectedRows(); |
292 |
> |
TCut posSide = kbase&&ksel; |
293 |
> |
TCut negSide = kbase&&ksel2; |
294 |
> |
string sposSide(posSide); |
295 |
> |
string snegSide(negSide); |
296 |
> |
char var[20]; |
297 |
> |
sprintf(var, "pdfW[%d]", k); |
298 |
> |
string svar(var); |
299 |
> |
string newPosSide = "(" + sposSide + ")*" + svar; |
300 |
> |
string newNegSide = "(" + snegSide + ")*" + svar; |
301 |
> |
|
302 |
> |
TH1F *effh= new TH1F("effh","effh",1,-14000,14000); |
303 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"goff"); |
304 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), sposSide.c_str(),"goff"); |
305 |
> |
Float_t sel = effh->Integral(); |
306 |
> |
Float_t nsel=0; |
307 |
> |
if(ConsiderSignalContaminationForLimits) { |
308 |
> |
if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"goff"); |
309 |
> |
else events->Draw((mcjzbexpression+">>effh").c_str(), snegSide.c_str(),"goff"); |
310 |
> |
nsel = effh->Integral(); |
311 |
> |
} |
312 |
> |
//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. |
313 |
> |
float normFactor = 1; |
314 |
> |
if(k>=0) get_norm_pdf_factor(events, k); |
315 |
> |
sel = sel/normFactor; |
316 |
> |
nsel = nsel/normFactor; |
317 |
> |
|
318 |
|
// events->Draw(mcjzbexpression.c_str(),kbase,"goff"); |
319 |
|
// Float_t tot = events->GetSelectedRows(); |
320 |
|
Float_t tot = Neventsinfile; |
321 |
|
|
322 |
< |
result=(sel-nsel)/tot; |
323 |
< |
resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot); |
324 |
< |
dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl; |
322 |
> |
if(ConsiderSignalContaminationForLimits) { |
323 |
> |
result=(sel-nsel)/tot; |
324 |
> |
resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot); |
325 |
> |
} else {//no signal contamination considered: |
326 |
> |
result=(sel)/tot; |
327 |
> |
resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot); |
328 |
> |
} |
329 |
> |
if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl; |
330 |
> |
delete effh; |
331 |
|
} |
332 |
|
|
333 |
+ |
|
334 |
+ |
//____________________________________________________________________________________ |
335 |
+ |
// Selection efficiency for one process (MC) |
336 |
+ |
vector<float> processMCefficiency(TTree *events,string mcjzb,bool requireZ,int Neventsinfile, string addcut) { |
337 |
+ |
vector<float> process_efficiencies; |
338 |
+ |
for(int iprocess=0;iprocess<=10;iprocess++) { |
339 |
+ |
float this_process_efficiency,efferr; |
340 |
+ |
stringstream addcutplus; |
341 |
+ |
addcutplus<<addcut<<"&&(process=="<<iprocess<<")"; |
342 |
+ |
MCefficiency(events,this_process_efficiency, efferr,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1); |
343 |
+ |
process_efficiencies.push_back(this_process_efficiency); |
344 |
+ |
} |
345 |
+ |
return process_efficiencies; |
346 |
+ |
} |
347 |
+ |
|
348 |
+ |
|
349 |
|
void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") { |
350 |
|
TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2"); |
253 |
– |
cout << "Getting started with JZB efficiency" << endl; |
351 |
|
if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses) |
352 |
|
if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23"; |
353 |
|
TH1F* hLM4 = plotEff(events,kbase,informalname); |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
< |
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="") { |
450 |
> |
//________________________________________________________________________________________ |
451 |
> |
// PDF uncertainty |
452 |
> |
float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") { |
453 |
> |
std::vector<float> efficiency; |
454 |
> |
for(int k = 1; k < NPdfs; k++) { |
455 |
> |
float result, resulterr; |
456 |
> |
MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k); |
457 |
> |
efficiency.push_back(result); |
458 |
> |
} |
459 |
> |
float errHi, errLow,err; |
460 |
> |
master_formula(efficiency, errHi, errLow); |
461 |
> |
err=errLow; |
462 |
> |
if(errHi>errLow) err=errHi; |
463 |
> |
if(!automatized) dout << " Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl; |
464 |
> |
return err; |
465 |
> |
|
466 |
> |
} |
467 |
> |
|
468 |
> |
int get_npdfs(TTree *events) { |
469 |
> |
int NPDFs; |
470 |
> |
events->SetBranchAddress("NPdfs",&NPDFs); |
471 |
> |
events->GetEntry(1); |
472 |
> |
return NPDFs; |
473 |
> |
} |
474 |
|
|
475 |
+ |
|
476 |
+ |
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) { |
477 |
|
float JetEnergyScaleUncert=0.1; |
478 |
|
float JZBScaleUncert=0.1; |
479 |
|
mcjzbexpression=mcjzb; |
480 |
< |
float triggereff=4.0/100;// in range [0,1] |
480 |
> |
float triggereff=5.0/100;// in range [0,1] |
481 |
|
dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl; |
482 |
|
float leptonseleff=2.0/100;// in range [0,1] |
483 |
|
dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl; |
484 |
|
|
485 |
+ |
int NPdfs=0; |
486 |
+ |
if(ismSUGRA) NPdfs = get_npdfs(events); |
487 |
+ |
|
488 |
|
float mceff,mcefferr,jzbeff,jzbefferr; |
489 |
|
if(!automatized) dout << "MC efficiencies:" << endl; |
490 |
< |
MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut); |
490 |
> |
MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut,-1); |
491 |
|
JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut); |
492 |
|
if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl; |
493 |
|
|
509 |
|
|
510 |
|
if(!automatized) dout << "Pileup: " << std::endl; |
511 |
|
float resolution=pileup(events,requireZ,informalname,addcut); |
512 |
< |
|
512 |
> |
|
513 |
> |
float PDFuncert=0; |
514 |
> |
if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut); |
515 |
> |
|
516 |
|
dout << "_______________________________________________" << endl; |
517 |
|
dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) "; |
518 |
|
if(addcut!="") dout << "With additional cut: " << addcut; |
524 |
|
dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1] |
525 |
|
dout << "Resolution : " << resolution << endl; // in range [0,1] |
526 |
|
dout << "From peak : " << sysfrompeak << endl; // in range [0,1] |
527 |
+ |
if(ismSUGRA) dout << "PDF uncertainty : " << PDFuncert << endl; // in range [0,1] |
528 |
|
dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1] |
529 |
|
dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1] |
530 |
|
|
535 |
|
if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown); |
536 |
|
toterr+=(resolution*resolution); |
537 |
|
toterr+=(sysfrompeak*sysfrompeak); |
538 |
+ |
if(ismSUGRA) toterr+=(PDFuncert*PDFuncert); |
539 |
|
dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl; |
540 |
< |
toterr=TMath::Sqrt(toterr)*mceff; |
541 |
< |
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*toterr << " (syst) %" << endl; |
542 |
< |
dout << " we thus use the sqrt of the sum of the squares which is : " << 100*toterr << endl; |
540 |
> |
float systerr=TMath::Sqrt(toterr)*mceff; |
541 |
> |
toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err! |
542 |
> |
|
543 |
> |
dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst) %" << endl; |
544 |
> |
dout << " we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl; |
545 |
> |
|
546 |
> |
//Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions! |
547 |
|
vector<float> res; |
548 |
|
res.push_back(jzbSel); |
549 |
|
res.push_back(mceff); |
553 |
|
if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown)); |
554 |
|
if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown)); |
555 |
|
res.push_back(fabs(resolution)); |
556 |
+ |
if(ismSUGRA) res.push_back(PDFuncert); |
557 |
|
results.push_back(res); |
558 |
|
} |
559 |
|
|