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.21 by buchmann, Mon Aug 29 06:30:21 2011 UTC vs.
Revision 1.25 by buchmann, Wed Aug 31 13:04:10 2011 UTC

# Line 157 | Line 157 | TH1F* plotEff(TTree* events, TCut kbase,
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", "", 10000, 0, 5);
194 +  char nameVar[20];
195 +  sprintf(nameVar, "pdfW[%d]", k);
196 +  events->Project("haux", nameVar);
197 +  float thisW = haux->Integral();
198 +  events->Project("haux", "pdfW[0]");
199 +  float normW = haux->Integral();
200 +
201 +  float factor=thisW/normW;
202 +
203 +  delete haux;
204 +
205 +  return factor;
206 +
207 + }
208 +
209 +
210 +
211 + //________________________________________________________________________________________
212   // Pile-up efficiency
213   float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) {
214          nBins = 16;
# Line 224 | Line 276 | void PeakError(TTree *events,float &resu
276  
277   //____________________________________________________________________________________
278   // Total selection efficiency (MC)
279 < void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") {
279 > void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) {
280          
281          char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
282          // All acceptance cuts at gen. level
# Line 235 | Line 287 | void MCefficiency(TTree *events,float &r
287          // Corresponding reco. cuts
288          TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
289          TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
290 <        events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff");
291 <        Float_t sel = events->GetSelectedRows();
290 >        TCut posSide = kbase&&ksel;
291 >        TCut negSide = kbase&&ksel2;
292 >        string sposSide(posSide);
293 >        string snegSide(negSide);
294 >        char var[20];
295 >        sprintf(var, "pdfW[%d]", k);
296 >        string svar(var);
297 >        string newPosSide = "(" + sposSide + ")*" + svar;
298 >        string newNegSide = "(" + snegSide + ")*" + svar;
299 >
300 >        TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
301 >        events->Draw((mcjzbexpression+">>effh").c_str(), newPosSide.c_str(),"goff");
302 >        Float_t sel = effh->Integral();
303          Float_t nsel=0;
304          if(ConsiderSignalContaminationForLimits) {
305 <          events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff");
306 <          nsel = events->GetSelectedRows();
305 >          events->Draw((mcjzbexpression+">>effh").c_str(), newNegSide.c_str(),"goff");
306 >          nsel = effh->Integral();
307          }
308 +        //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.
309 +        float normFactor = get_norm_pdf_factor(events, k);
310 +        sel = sel/normFactor;
311 +        nsel = nsel/normFactor;
312 +
313   //      events->Draw(mcjzbexpression.c_str(),kbase,"goff");
314   //      Float_t tot = events->GetSelectedRows();
315          Float_t tot = Neventsinfile;
# Line 253 | Line 321 | void MCefficiency(TTree *events,float &r
321            result=(sel)/tot;
322            resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
323          }
324 <        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
324 >        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl;
325 >        delete effh;
326   }
327  
328   void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
# Line 357 | Line 426 | void JZBresponse(TTree *events, bool req
426   }
427  
428  
429 < 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="") {
429 > //________________________________________________________________________________________
430 > // PDF uncertainty  
431 > float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") {
432 >  std::vector<float> efficiency;
433 >  for(int k = 1; k < NPdfs; k++) {
434 >    float result, resulterr;
435 >    MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k);  
436 >    efficiency.push_back(result);
437 >  }
438 >  float errHi, errLow,err;
439 >  master_formula(efficiency, errHi, errLow);
440 >  err=errLow;
441 >  if(errHi>errLow) err=errHi;
442 >  if(!automatized) dout << "  Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl;
443 >  return err;
444 >
445 > }
446 >
447 > int get_npdfs(TTree *events) {
448 >  int NPDFs;
449 >  events->SetBranchAddress("NPdfs",&NPDFs);
450 >  events->GetEntry(1);
451 >  return NPDFs;
452 > }
453    
454 +
455 + 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) {
456    float JetEnergyScaleUncert=0.1;
457    float JZBScaleUncert=0.1;
458    mcjzbexpression=mcjzb;
# Line 367 | Line 461 | void do_systematics_for_one_file(TTree *
461    float leptonseleff=2.0/100;// in range [0,1]
462    dout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
463    
464 +  int NPdfs=get_npdfs(events);
465 +
466    float mceff,mcefferr,jzbeff,jzbefferr;
467    if(!automatized) dout << "MC efficiencies:" << endl;
468    MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut);
# Line 391 | Line 487 | void do_systematics_for_one_file(TTree *
487  
488    if(!automatized) dout << "Pileup: " << std::endl;
489    float resolution=pileup(events,requireZ,informalname,addcut);
490 <  
490 >
491 >  float PDFuncert=0;
492 >  if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, NPdfs, addcut);
493 >
494    dout << "_______________________________________________" << endl;
495    dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
496    if(addcut!="") dout << "With additional cut: " << addcut;
# Line 403 | Line 502 | void do_systematics_for_one_file(TTree *
502    dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
503    dout << "Resolution : " << resolution << endl; // in range [0,1]
504    dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
505 +  if(ismSUGRA) dout << "PDF uncertainty  : " << PDFuncert << endl; // in range [0,1]
506    dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
507    dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
508    
# Line 413 | Line 513 | void do_systematics_for_one_file(TTree *
513    if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
514    toterr+=(resolution*resolution);
515    toterr+=(sysfrompeak*sysfrompeak);
516 +  if(ismSUGRA) toterr+=(PDFuncert*PDFuncert);
517    dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
518    float systerr=TMath::Sqrt(toterr)*mceff;
519    toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
# Line 430 | Line 531 | void do_systematics_for_one_file(TTree *
531    if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
532    if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
533    res.push_back(fabs(resolution));
534 +  if(ismSUGRA) res.push_back(PDFuncert);
535    results.push_back(res);
536   }
537  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines