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.19 by buchmann, Wed Aug 17 17:15:14 2011 UTC vs.
Revision 1.23 by pablom, Wed Aug 31 10:21:17 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", "", 1000, 0, 15);
194 +  char nameVar[20];
195 +  sprintf(nameVar, "pdfW[%d]", k);
196 +  events->Project("haux", nameVar);
197 +  float factor = haux->Integral();
198 +
199 +  delete haux;
200 +
201 +  return factor;
202 +
203 + }
204 +
205 +
206 +
207 + //________________________________________________________________________________________
208   // Pile-up efficiency
209   float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) {
210          nBins = 16;
# Line 224 | Line 272 | void PeakError(TTree *events,float &resu
272  
273   //____________________________________________________________________________________
274   // Total selection efficiency (MC)
275 < void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") {
275 > void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) {
276          
277          char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
278          // All acceptance cuts at gen. level
# Line 235 | Line 283 | void MCefficiency(TTree *events,float &r
283          // Corresponding reco. cuts
284          TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
285          TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
286 <        events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff");
286 >        TCut posSide = kbase&&ksel;
287 >        TCut negSide = kbase&&ksel2;
288 >        string sposSide(posSide);
289 >        string snegSide(negSide);
290 >        char var[20];
291 >        sprintf(var, "pdfW[%d]", k);
292 >        string svar(var);
293 >        string newPosSide = "(" + sposSide + ")*" + svar;
294 >        string newNegSide = "(" + snegSide + ")*" + svar;
295 >
296 >        events->Draw(mcjzbexpression.c_str(), newPosSide.c_str(),"goff");
297          Float_t sel = events->GetSelectedRows();
298 <        events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff");
299 <        Float_t nsel = events->GetSelectedRows();
298 >        Float_t nsel=0;
299 >        if(ConsiderSignalContaminationForLimits) {
300 >          events->Draw(mcjzbexpression.c_str(), newNegSide.c_str(),"goff");
301 >          nsel = events->GetSelectedRows();
302 >        }
303 >        //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.
304 >        float normFactor = get_norm_pdf_factor(events, k);
305 >        sel = sel/normFactor;
306 >        nsel = nsel/normFactor;
307 >
308   //      events->Draw(mcjzbexpression.c_str(),kbase,"goff");
309   //      Float_t tot = events->GetSelectedRows();
310          Float_t tot = Neventsinfile;
311          
312 <        result=(sel-nsel)/tot;
313 <        resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot);
312 >        if(ConsiderSignalContaminationForLimits) {
313 >          result=(sel-nsel)/tot;
314 >          resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
315 >        } else {//no signal contamination considered:
316 >          result=(sel)/tot;
317 >          resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
318 >        }
319          if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
320   }
321  
# Line 349 | Line 420 | void JZBresponse(TTree *events, bool req
420   }
421  
422  
423 < 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="") {
423 > //________________________________________________________________________________________
424 > // PDF uncertainty  
425 > float get_pdf_uncertainty(TTree *events, string mcjzb, bool requireZ, int Neventsinfile, string addcut="") {
426 >
427 >  int numberOfPDFs = 44;
428 >  std::vector<float> efficiency;
429 >  for(int k = 1; k < numberOfPDFs; k++) {
430 >    float result, resulterr;
431 >    MCefficiency(events, result, resulterr, mcjzb, requireZ, Neventsinfile, addcut, k);  
432 >    efficiency.push_back(result);
433 >  }
434 >  float errHi, errLow;
435 >  master_formula(efficiency, errHi, errLow);
436 >  if(errHi>errLow) return errHi;
437 >  return errLow;
438 >
439 > }
440 >
441 >
442 >
443 > 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    
445    float JetEnergyScaleUncert=0.1;
446    float JZBScaleUncert=0.1;
# Line 383 | Line 474 | void do_systematics_for_one_file(TTree *
474  
475    if(!automatized) dout << "Pileup: " << std::endl;
476    float resolution=pileup(events,requireZ,informalname,addcut);
477 <  
477 >
478 >  float PDFuncert=0;
479 >  if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, mcjzb, requireZ, Neventsinfile, addcut);
480 >
481    dout << "_______________________________________________" << endl;
482    dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
483    if(addcut!="") dout << "With additional cut: " << addcut;
# Line 395 | Line 489 | void do_systematics_for_one_file(TTree *
489    dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
490    dout << "Resolution : " << resolution << endl; // in range [0,1]
491    dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
492 +  dout << "PDF uncertainty  : " << PDFuncert << " (not yet included below) " << endl; // in range [0,1]
493    dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
494    dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
495    
# Line 405 | Line 500 | void do_systematics_for_one_file(TTree *
500    if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
501    toterr+=(resolution*resolution);
502    toterr+=(sysfrompeak*sysfrompeak);
503 +  if(ismSUGRA) toterr+=(PDFuncert*PDFuncert);
504    dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
505    float systerr=TMath::Sqrt(toterr)*mceff;
506    toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
# Line 422 | Line 518 | void do_systematics_for_one_file(TTree *
518    if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
519    if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
520    res.push_back(fabs(resolution));
521 +  if(ismSUGRA) res.push_back(PDFuncert);
522    results.push_back(res);
523   }
524  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines