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.9 by buchmann, Fri Jul 22 10:14:16 2011 UTC vs.
Revision 1.19 by buchmann, Wed Aug 17 17:15:14 2011 UTC

# Line 158 | Line 158 | TH1F* plotEff(TTree* events, TCut kbase,
158  
159   //________________________________________________________________________________________
160   // Pile-up efficiency
161 < float pileup(TTree *events, bool requireZ, string informalname, Float_t myJzbMax = 140. ) {
161 > float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) {
162          nBins = 16;
163          jzbMax = myJzbMax;
164          
165          // Acceptance cuts
166          TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
167 +        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
168 +        
169          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
170          TH1F* hLM4 = plotEff(events,kbase,informalname);
171          hLM4->SetMinimum(0.);
# Line 180 | Line 182 | float pileup(TTree *events, bool require
182          if(!automatized) dout << "  PU: " << funcUp->Eval(jzbSel) << " " <<  func->Eval(jzbSel)
183          << "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl;
184          
185 <        return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100.;
185 >        return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel);
186          
187   }
188  
189   //____________________________________________________________________________________
190   // Effect of peak shifting
191 < void PeakError(TTree *events,float &result, string mcjzb, float peakerr) {
191 > void PeakError(TTree *events,float &result, string mcjzb, float peakerr,string addcut="") {
192          TString peakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
193          TString peakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
194          TString peakcentral("("+TString(mcjzb)+")"+geq_or_leq()+TString(any2string(jzbSel)));
# Line 209 | Line 211 | void PeakError(TTree *events,float &resu
211              poscut=peakup;
212              negcut=npeakup;
213            }
214 <          float res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
214 >          float res;
215 >          if(addcut=="") res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
216 >          else res=allcontributionsplot(events,cutnJets&&addcut.c_str(),cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
217            if(i==0) rescent=res;
218            else if(i==1) resdown=res;
219            else if(i==2) resup=res;
220          }
221 <        if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent)*100;
222 <        else result=(TMath::Abs(rescent-resdown)/rescent)*100;
221 >        if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent);
222 >        else result=(TMath::Abs(rescent-resdown)/rescent);
223   }
224  
225   //____________________________________________________________________________________
226   // Total selection efficiency (MC)
227 < void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,string addcut="") {
227 > void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") {
228          
229          char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
230          // All acceptance cuts at gen. level
231 <        TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
231 >        //TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
232 >        TCut kbase("");
233          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
234          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
235          // Corresponding reco. cuts
236 <        TCut ksel("abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
237 <        
236 >        TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
237 >        TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
238          events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff");
239          Float_t sel = events->GetSelectedRows();
240 <        events->Draw(mcjzbexpression.c_str(),kbase,"goff");
241 <        Float_t tot = events->GetSelectedRows();
240 >        events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff");
241 >        Float_t nsel = events->GetSelectedRows();
242 > //      events->Draw(mcjzbexpression.c_str(),kbase,"goff");
243 > //      Float_t tot = events->GetSelectedRows();
244 >        Float_t tot = Neventsinfile;
245          
246 <        result=sel/tot;
246 >        result=(sel-nsel)/tot;
247          resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot);
248 <        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << std::endl;
248 >        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
249   }
250  
251 < void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ) {
251 > void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
252          TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
253 +        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
254          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
255          TH1F* hLM4 = plotEff(events,kbase,informalname);
256          Int_t bin = hLM4->FindBin(jzbSel); // To get the error
# Line 253 | Line 262 | void JZBefficiency(TTree *events, string
262  
263   //________________________________________________________________________
264   // Effect of energy scale on efficiency
265 < void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
265 > void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,string addcut="",float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
266          TCut kbase("abs(genMll-91.2)<20&&genZPt>0");
267 +        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
268          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
269  
270          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
# Line 283 | Line 293 | void JZBjetScale(TTree *events, float &j
293          if(!automatized) dout << "    JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
294          if(!automatized) dout << "    central:  " << eff << std::endl;
295          if(!automatized) dout << "    JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
296 <        jesup=(effp-eff)/eff*100.;
297 <        jesdown=(effm-eff)/eff*100.;
296 >        jesup=(effp-eff)/eff;
297 >        jesdown=(effm-eff)/eff;
298   }
299  
300   //________________________________________________________________________
301   // Effect of energy scale on JZB efficiency
302 < void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ) {
302 > void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ, string addcut) {
303          
304          TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
305 +        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
306          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
307          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
308          
# Line 308 | Line 319 | void doJZBscale(TTree *events, float &do
319          if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
320          if(!automatized) dout << "  efficiency at JZB==" << jzbSel  << ": " << eff << std::endl;
321          if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
322 <        up=((effp-eff)/eff)*100;
323 <        down=((effm-eff)/eff)*100;
322 >        up=((effp-eff)/eff);
323 >        down=((effm-eff)/eff);
324   }
325  
326   //________________________________________________________________________
327   // JZB response (true/reco. vs. true)
328 < void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
328 > void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, string addcut="",bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
329          
330          jzbMin = 20;
331          TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
332 +        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
333          if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
334          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
335          
# Line 337 | Line 349 | void JZBresponse(TTree *events, bool req
349   }
350  
351  
352 < void do_systematics_for_one_file(TTree *events,string informalname, vector<vector<float> > &results,string mcjzb,string datajzb,float peakerror,bool requireZ=false) {
352 > 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="") {
353    
354    float JetEnergyScaleUncert=0.1;
355    float JZBScaleUncert=0.1;
356    mcjzbexpression=mcjzb;
357 <  
346 <  float triggereff=4;//percent!
357 >  float triggereff=4.0/100;// in range [0,1]
358    dout << "Trigger efficiency not implemented in this script  yet, still using external one" << endl;
359 <  float leptonseleff=2;//percent!
359 >  float leptonseleff=2.0/100;// in range [0,1]
360    dout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
361    
362    float mceff,mcefferr,jzbeff,jzbefferr;
363    if(!automatized) dout << "MC efficiencies:" << endl;
364 <  MCefficiency(events,mceff,mcefferr,mcjzb,requireZ);
365 <  JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ);
364 >  MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut);
365 >  JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
366    if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
367    
368    if(!automatized) dout << "Error from Peak position:" << endl;
369    float sysfrompeak=0;
370 <  PeakError(events,sysfrompeak,mcjzb,peakerror);
370 >  PeakError(events,sysfrompeak,mcjzb,peakerror,addcut);
371      
372    if(!automatized) dout << "Jet energy scale: " << std::endl;
373    float jesup,jesdown;
374 <  JZBjetScale(events,jesdown,jesup,informalname,JetEnergyScaleUncert,requireZ);
374 >  JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert);
375    
376    if(!automatized) dout << "JZB scale: " << std::endl;
377    float scaleup,scaledown,scalesyst;
378 <  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ);
378 >  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut);
379    
380    if(!automatized) dout << "JZB response: " << std::endl;
381    float resp,resperr;
382 <  JZBresponse(events,requireZ,resp,resperr);
382 >  JZBresponse(events,requireZ,resp,resperr,addcut);
383  
384    if(!automatized) dout << "Pileup: " << std::endl;
385 <  float resolution=pileup(events,requireZ,informalname);
385 >  float resolution=pileup(events,requireZ,informalname,addcut);
386    
387    dout << "_______________________________________________" << endl;
388 <  dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) " << endl;
389 <  dout << "MC efficiency: " << 100*mceff << "+/-" << 100*mcefferr << endl;
390 <  dout << "Trigger efficiency: " << triggereff << endl;
391 <  dout << "Lepton Sel Eff: " << leptonseleff << endl;
392 <  dout << "Jet energy scale: " << jesup << " " << jesdown << endl;
393 <  dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl;
394 <  dout << "Resolution : " << resolution << endl;
395 <  dout << "From peak : " << sysfrompeak << endl;
396 <  dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl;
397 <  dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl;
388 >  dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
389 >  if(addcut!="") dout << "With additional cut: " << addcut;
390 >  dout << endl;
391 >  dout << "MC efficiency: " << mceff << "+/-" << mcefferr << endl; // in range [0,1]
392 >  dout << "Trigger efficiency: " << triggereff << endl; // in range [0,1]
393 >  dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1]
394 >  dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1]
395 >  dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
396 >  dout << "Resolution : " << resolution << endl; // in range [0,1]
397 >  dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
398 >  dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
399 >  dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
400    
401    float toterr=0;
402 <  toterr+=(triggereff/100)*(triggereff/100);
403 <  toterr+=(leptonseleff/100)*(leptonseleff/100);
404 <  if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup/100)*(jesup/100); else toterr+=(jesdown/100)*(jesdown/100);
405 <  if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup/100)*(scaleup/100); else toterr+=(scaledown/100)*(scaledown/100);
406 <  toterr+=(resolution/100)*(resolution/100);
407 <  toterr+=(sysfrompeak/100)*(sysfrompeak/100);
408 <  toterr=TMath::Sqrt(toterr);
409 <  dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*toterr << " (syst)   %" << endl;
410 <  dout << "     we thus use the sqrt of the sum of the squares which is : " << 100*TMath::Sqrt(mcefferr*mcefferr+(toterr*toterr)) << endl;
402 >  toterr+=(triggereff)*(triggereff);
403 >  toterr+=(leptonseleff)*(leptonseleff);
404 >  if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown);
405 >  if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
406 >  toterr+=(resolution*resolution);
407 >  toterr+=(sysfrompeak*sysfrompeak);
408 >  dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
409 >  float systerr=TMath::Sqrt(toterr)*mceff;
410 >  toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
411 >  
412 >  dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst)   %" << endl;
413 >  dout << "     we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
414 >  
415 >  //Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
416    vector<float> res;
417    res.push_back(jzbSel);
418    res.push_back(mceff);
419    res.push_back(mcefferr);
420    res.push_back(toterr);
421    res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr)));
422 <  
422 >  if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
423 >  if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
424 >  res.push_back(fabs(resolution));
425    results.push_back(res);
426   }
427  
# Line 413 | Line 433 | vector<vector<float> > compute_systemati
433        for(int ibin=0;ibin<bins.size();ibin++) {
434          jzbSel=bins[ibin];
435          geqleq="geq";
436 <        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
436 >        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
437        }//end of bin loop
438    }//end of signal loop
439    return systematics;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines