ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Systematics.C
(Generate patch)

Comparing UserCode/cbrown/AnalysisFramework/Plotting/Modules/Systematics.C (file contents):
Revision 1.23 by pablom, Wed Aug 31 10:21:17 2011 UTC vs.
Revision 1.37 by buchmann, Wed Sep 28 15:59:39 2011 UTC

# Line 1 | Line 1
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>
# Line 190 | Line 192 | void master_formula(std::vector<float> e
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  
# Line 272 | Line 278 | void PeakError(TTree *events,float &resu
278  
279   //____________________________________________________________________________________
280   // Total selection efficiency (MC)
281 < void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) {
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 >        if(!events) {
285 >          write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
286 >          return Value(0,0);
287 >        }
288          
289          char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
290          // All acceptance cuts at gen. level
# Line 293 | Line 305 | void MCefficiency(TTree *events,float &r
305          string newPosSide = "(" + sposSide + ")*" + svar;
306          string newNegSide = "(" + snegSide + ")*" + svar;
307  
308 <        events->Draw(mcjzbexpression.c_str(), newPosSide.c_str(),"goff");
309 <        Float_t sel = events->GetSelectedRows();
308 >        TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
309 >        if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"goff");
310 >        else events->Draw((mcjzbexpression+">>effh").c_str(), sposSide.c_str(),"goff");
311 >        Float_t sel = effh->Integral();
312          Float_t nsel=0;
313          if(ConsiderSignalContaminationForLimits) {
314 <          events->Draw(mcjzbexpression.c_str(), newNegSide.c_str(),"goff");
315 <          nsel = events->GetSelectedRows();
314 >          if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"");
315 >          else events->Draw((mcjzbexpression+">>effh").c_str(), snegSide.c_str(),"");
316 >          nsel = effh->Integral();
317          }
318          //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.
319 <        float normFactor = get_norm_pdf_factor(events, k);
319 >        float normFactor = 1;
320 >        if(k>=0) get_norm_pdf_factor(events, k);
321          sel = sel/normFactor;
322          nsel = nsel/normFactor;
323  
# Line 309 | Line 325 | void MCefficiency(TTree *events,float &r
325   //      Float_t tot = events->GetSelectedRows();
326          Float_t tot = Neventsinfile;
327          
328 +        Value result_wo_signalcont;
329 +
330          if(ConsiderSignalContaminationForLimits) {
331            result=(sel-nsel)/tot;
332            resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
333 +          result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot));
334          } else {//no signal contamination considered:
335            result=(sel)/tot;
336            resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
337 +          result_wo_signalcont=Value(result,resulterr);
338          }
339 <        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
339 >        if(!automatized && k>0 ) dout << "PDF assessment: ";
340 >        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl;
341 >        delete effh;
342 >        return result_wo_signalcont;
343 > }
344 >
345 >
346 > //____________________________________________________________________________________
347 > // Selection efficiency for one process (MC)
348 > vector<float> processMCefficiency(TTree *events,string mcjzb,bool requireZ,int Neventsinfile, string addcut) {
349 >  vector<float> process_efficiencies;
350 >  for(int iprocess=0;iprocess<=10;iprocess++) {
351 >    float this_process_efficiency,efferr;
352 >    stringstream addcutplus;
353 >    addcutplus<<addcut<<"&&(process=="<<iprocess<<")";
354 >    MCefficiency(events,this_process_efficiency, efferr,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1);
355 >    process_efficiencies.push_back(this_process_efficiency);
356 >  }
357 >  return process_efficiencies;
358   }
359 +        
360  
361   void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
362          TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
# Line 387 | Line 426 | void doJZBscale(TTree *events, float &do
426          Float_t eff  = Interpolate(jzbSel,hist);
427          Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
428          Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
429 <        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
429 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
430          if(!automatized) dout << "  efficiency at JZB==" << jzbSel  << ": " << eff << std::endl;
431 <        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
431 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
432          up=((effp-eff)/eff);
433          down=((effm-eff)/eff);
434   }
# Line 413 | Line 452 | void JZBresponse(TTree *events, bool req
452          hJzbResp->SetMinimum(0.2);
453          hJzbResp->Fit("pol0","Q");
454          TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
455 <        resp=fittedfunction->GetParameter(0);
456 <        resperr=fittedfunction->GetParError(0);
457 <        if(!automatized) dout << "  Response: " << resp << " +/- " << resperr << endl;
455 >        if(!fittedfunction) {
456 >                // in case there are not enough points passing our selection
457 >                cout << "OOPS response function invalid, assuming 100% error !!!!" << endl;
458 >                resp=1;
459 >                resperr=1;
460 >        } else {
461 >                resp=fittedfunction->GetParameter(0);
462 >                resperr=fittedfunction->GetParError(0);
463 >                if(!automatized) dout << "  Response: " << resp << " +/- " << resperr << endl;
464 >        }
465          delete hJzbResp;
466   }
467  
468  
469   //________________________________________________________________________________________
470   // PDF uncertainty  
471 < float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, string addcut="") {
426 <
427 <  int numberOfPDFs = 44;
471 > float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") {
472    std::vector<float> efficiency;
473 <  for(int k = 1; k < numberOfPDFs; k++) {
473 >  for(int k = 1; k < NPdfs; k++) {
474      float result, resulterr;
475      MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k);  
476      efficiency.push_back(result);
477    }
478 <  float errHi, errLow;
478 >  float errHi, errLow,err;
479    master_formula(efficiency, errHi, errLow);
480 <  if(errHi>errLow) return errHi;
481 <  return errLow;
480 >  err=errLow;
481 >  if(errHi>errLow) err=errHi;
482 >  if(!automatized) dout << "  Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl;
483 >  return err;
484  
485   }
486  
487 <
487 > int get_npdfs(TTree *events) {
488 >  int NPDFs;
489 >  events->SetBranchAddress("NPdfs",&NPDFs);
490 >  events->GetEntry(1);
491 >  return NPDFs;
492 > }
493 >  
494  
495   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  
496    float JetEnergyScaleUncert=0.1;
497    float JZBScaleUncert=0.1;
498    mcjzbexpression=mcjzb;
499 <  float triggereff=4.0/100;// in range [0,1]
499 >  float triggereff=5.0/100;// in range [0,1]
500    dout << "Trigger efficiency not implemented in this script  yet, still using external one" << endl;
501    float leptonseleff=2.0/100;// in range [0,1]
502 +  leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton
503    dout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
504    
505 +  int NPdfs=0;
506 +  if(ismSUGRA) NPdfs = get_npdfs(events);
507 +  
508    float mceff,mcefferr,jzbeff,jzbefferr;
509    if(!automatized) dout << "MC efficiencies:" << endl;
510 <  MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut);
511 <  JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
510 >  Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut,-1);
511 >  if(!automatized) cout << "   Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl;
512 >
513 >  if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
514    if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
515    
516    if(!automatized) dout << "Error from Peak position:" << endl;
# Line 470 | Line 527 | void do_systematics_for_one_file(TTree *
527    
528    if(!automatized) dout << "JZB response: " << std::endl;
529    float resp,resperr;
530 <  JZBresponse(events,requireZ,resp,resperr,addcut);
530 >  if(PlottingSetup::computeJZBresponse) {
531 >        if(!automatized) dout << "JZB response: " << std::endl;
532 >        JZBresponse(events,requireZ,resp,resperr,addcut);
533 >  }
534  
535    if(!automatized) dout << "Pileup: " << std::endl;
536 <  float resolution=pileup(events,requireZ,informalname,addcut);
536 >  float resolution;
537 >  resolution=pileup(events,requireZ,informalname,addcut);
538  
539    float PDFuncert=0;
540 <  if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, addcut);
540 >  if(!automatized) dout << "Assessing PDF uncertainty: " << std::endl;
541 >  if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut);
542  
543    dout << "_______________________________________________" << endl;
544    dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
# Line 489 | Line 551 | void do_systematics_for_one_file(TTree *
551    dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
552    dout << "Resolution : " << resolution << endl; // in range [0,1]
553    dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
554 <  dout << "PDF uncertainty  : " << PDFuncert << " (not yet included below) " << endl; // in range [0,1]
555 <  dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
556 <  dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
554 >  if(ismSUGRA) dout << "PDF uncertainty  : " << PDFuncert << endl; // in range [0,1]
555 >  if(PlottingSetup::computeJZBefficiency) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
556 >  if(PlottingSetup::computeJZBresponse)dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
557    
558    float toterr=0;
559    toterr+=(triggereff)*(triggereff);
# Line 507 | Line 569 | void do_systematics_for_one_file(TTree *
569    
570    dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst)   %" << endl;
571    dout << "     we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
572 +  dout << "_______________________________________________" << endl;
573    
574    //Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
575    vector<float> res;
# Line 518 | Line 581 | void do_systematics_for_one_file(TTree *
581    if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
582    if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
583    res.push_back(fabs(resolution));
584 +  res.push_back(mceff_nosigcont.getValue());
585 +  res.push_back(mceff_nosigcont.getError());
586    if(ismSUGRA) res.push_back(PDFuncert);
587    results.push_back(res);
588   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines