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.52 by buchmann, Mon Nov 21 19:04:28 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 83 | Line 85 | Double_t Interpolate(Double_t x, TH1 *hi
85  
86   //____________________________________________________________________________________
87   // Plotting with all contributions, i.e. sidebands, peak, osof,ossf ... (for a systematic)
88 < float allcontributionsplot(TTree* events, TCut kBaseCut, TCut kMassCut, TCut kSidebandCut, TCut JZBPosCut, TCut JZBNegCut) {
88 > float allcontributionsplot(TTree* events, TCut kBaseCut, TCut kMassCut, TCut kSidebandCut, TCut JZBPosCut, TCut JZBNegCut, int flipped) {
89          iplot++;
90          int count=iplot;
91 +        string locmcjzbexpression=mcjzbexpression;
92          // Define new histogram
93          string hname=GetNumericHistoName();
94          TH1F* hossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
95 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSSF,"goff");
95 >        events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSSF,"goff");
96          hname=GetNumericHistoName();
97          TH1F* hossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
98 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSSF,"goff");
98 >        events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSSF,"goff");
99  
100          hname=GetNumericHistoName();
101          TH1F* hosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
102 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSOF,"goff");
102 >        events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSOF,"goff");
103          hname=GetNumericHistoName();
104          TH1F* hosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
105 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSOF,"goff");
103 <
104 <        hname=GetNumericHistoName();
105 <        TH1F* sbhossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
106 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSSF,"goff");
107 <        hname=GetNumericHistoName();
108 <        TH1F* sbhossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
109 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSSF,"goff");
110 <
111 <        hname=GetNumericHistoName();
112 <        TH1F* sbhosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
113 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSOF,"goff");
114 <        hname=GetNumericHistoName();
115 <        TH1F* sbhosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
116 <        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSOF,"goff");
105 >        events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSOF,"goff");
106          
107 <        float obs = hossfp->Integral();
108 <        float pred= hossfn->Integral() + (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
107 >        float obs=0;
108 >        float pred=0;
109 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
110 >        if(PlottingSetup::RestrictToMassPeak) {
111 >          hname=GetNumericHistoName();
112 >          TH1F* sbhossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
113 >          events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSSF,"goff");
114 >          hname=GetNumericHistoName();
115 >          TH1F* sbhossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
116 >          events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSSF,"goff");
117 >          
118 >          hname=GetNumericHistoName();
119 >          TH1F* sbhosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
120 >          events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSOF,"goff");
121 >          hname=GetNumericHistoName();
122 >          TH1F* sbhosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
123 >          events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSOF,"goff");
124 >          
125 >          obs = hossfp->Integral();
126 >          pred= hossfn->Integral() + (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
127 >
128 >          if(flipped>0) {
129 >                obs = hossfn->Integral();
130 >                pred= hossfp->Integral() - (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
131 >          }
132 >          delete sbhossfp,sbhossfn,sbhosofp,sbhosofn;
133 >        } else {
134 >          obs = hossfp->Integral();
135 >          pred= hossfn->Integral() + (hosofp->Integral() - hosofn->Integral());
136 >          if(flipped>0) {
137 >                obs = hossfn->Integral();
138 >                pred= hossfp->Integral() - (hosofp->Integral() - hosofn->Integral());;
139 >          }
140 >        }
141          
142          delete hossfp,hossfn,hosofp,hosofn;
122        delete sbhossfp,sbhossfn,sbhosofp,sbhosofn;
143          return obs-pred;
144   }
145  
146  
147   //____________________________________________________________________________________
148   // Efficiency plot
149 < TH1F* plotEff(TTree* events, TCut kbase, TString informalname) {
149 > TH1F* plotEff(TTree* events, TCut kbase, TString informalname, int flipped) {
150          iplot++;
151          int count=iplot;
152 +        iplot++;
153 +        int count2=iplot;
154          // Define new histogram
155          char hname[30]; sprintf(hname,"hJzbEff%d",count);
156 <        TH1F* hJzbEff = new TH1F(hname,"JZB selection efficiency ; JZB (GeV/c); Efficiency",
157 <                                                         nBins,jzbMin,jzbMax);
156 >        char hname2[30]; sprintf(hname2,"hJzbEff%d",count2);
157 >        TH1F* hJzbEff = new TH1F(hname,"JZB selection efficiency ; JZB (GeV/c); Efficiency",nBins,jzbMin,jzbMax);
158 >        TH1F* hJzbEff2= new TH1F(hname2,"JZB selection efficiency ; JZB (GeV/c); Efficiency",1,-14000,14000);
159          Float_t step = (jzbMax-jzbMin)/static_cast<Float_t>(nBins);
160 <        
161 <        events->Draw(mcjzbexpression.c_str(),"genJZB>-400"&&kbase,"goff");
162 <        Float_t maxEff = events->GetSelectedRows();
160 >
161 >        if(flipped==0) events->Draw((mcjzbexpression+">>"+(string)hname2).c_str(),("genJZB>-400"&&kbase),"goff");
162 >        else events->Draw(("(-"+mcjzbexpression+")>>"+(string)hname2).c_str(),("genJZB>-400"&&kbase),"goff");
163 >        Float_t maxEff = hJzbEff2->Integral();
164          if(verbose>0) dout << hname << " (" << informalname <<") " << maxEff <<  std::endl;
165          
166          if(verbose>0) dout <<  "JZB max = " << jzbMax << std::endl;
# Line 144 | Line 168 | TH1F* plotEff(TTree* events, TCut kbase,
168          char cut[256];
169          for ( Int_t iBin = 0; iBin<nBins; ++iBin ) {
170                  sprintf(cut,"genJZB>%3f",jzbMin+iBin*step);
171 <                events->Draw(mcjzbexpression.c_str(),TCut(cut)&&kbase,"goff");
172 <                Float_t eff = static_cast<Float_t>(events->GetSelectedRows())/maxEff;
173 <                //     dout << "COUCOU " << __LINE__ << std::endl;
171 >                if(flipped==0) events->Draw((mcjzbexpression+">>"+(string)hname2).c_str(),(TCut(cut)&&kbase),"goff");
172 >                if(flipped>0) events->Draw(("(-"+mcjzbexpression+")>>"+(string)hname2).c_str(),(TCut(cut)&&kbase),"goff");
173 >                Float_t eff = static_cast<Float_t>(hJzbEff2->Integral())/maxEff;
174                  hJzbEff->SetBinContent(iBin+1,eff);
175                  hJzbEff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/maxEff));
176          }
177 +        delete hJzbEff2;
178          return hJzbEff;
154        
155        
179   }
180  
181  
182   //________________________________________________________________________________________
183 + // Master Formula
184 + void master_formula(std::vector<float> eff, float &errHi, float &errLo) {
185 +
186 +  float x0 = eff[0];
187 +  float deltaPos = 0, deltaNeg = 0;
188 +  for(int k = 0; k < (eff.size()-1)/2; k++) {
189 +    float xneg = eff[2*k+2];
190 +    float xpos = eff[2*k+1];
191 +    if(xpos-x0>0 || xneg-x0>0) {
192 +      if(xpos-x0 > xneg-x0) {
193 +        deltaPos += (xpos-x0)*(xpos-x0);
194 +      } else {
195 +        deltaPos += (xneg-x0)*(xneg-x0);
196 +      }
197 +    }
198 +    if(x0-xpos>0 || x0-xneg>0) {
199 +      if(x0-xpos > x0-xneg) {
200 +        deltaNeg += (xpos-x0)*(xpos-x0);
201 +      } else {
202 +        deltaNeg += (xneg-x0)*(xneg-x0);
203 +      }
204 +    }
205 +  }
206 +  errHi = sqrt(deltaPos);
207 +  errLo = sqrt(deltaNeg);
208 +
209 + }
210 +
211 +
212 + //________________________________________________________________________________________
213 + // Get normalization factor for the PDFs
214 + float get_norm_pdf_factor(TTree *events, int k, string addcut) {
215 +
216 +  TH1F *haux = new TH1F("haux", "", 10000, 0, 5);
217 +  char nameVar[20];
218 +  sprintf(nameVar, "pdfW[%d]", k);
219 +  events->Project("haux", nameVar, addcut.c_str());
220 +  float thisW = haux->Integral();
221 +  events->Project("haux", "pdfW[0]");
222 +  float normW = haux->Integral();
223 +
224 +  float factor=thisW/normW;
225 +
226 +  delete haux;
227 +
228 +  return factor;
229 +
230 + }
231 +
232 +
233 +
234 + //________________________________________________________________________________________
235   // Pile-up efficiency
236 < float pileup(TTree *events, bool requireZ, string informalname, string addcut="",Float_t myJzbMax = 140. ) {
236 > float pileup(TTree *events, bool requireZ, string informalname, int flipped, string addcut="",Float_t myJzbMax = 140. ) {
237          nBins = 16;
238          jzbMax = myJzbMax;
239          
240          // Acceptance cuts
241 <        TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
241 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
242 >        TCut kbase(PlottingSetup::genMassCut&&"genNjets>2&&genZPt>0"&&cutmass&&cutOSSF);
243          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
244          
245 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
246 <        TH1F* hLM4 = plotEff(events,kbase,informalname);
245 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
246 >        TH1F* hLM4 = plotEff(events,kbase,informalname,flipped);
247          hLM4->SetMinimum(0.);
248          
249          // Nominal function
# Line 178 | Line 254 | float pileup(TTree *events, bool require
254          
255          // Pimped-up function
256          TF1* funcUp = (TF1*)func->Clone();
257 <        funcUp->SetParameter( 0., func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
257 >        funcUp->SetParameter( 0, func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
258          if(!automatized) dout << "  PU: " << funcUp->Eval(jzbSel) << " " <<  func->Eval(jzbSel)
259          << "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl;
260          
# Line 188 | Line 264 | float pileup(TTree *events, bool require
264  
265   //____________________________________________________________________________________
266   // Effect of peak shifting
267 < void PeakError(TTree *events,float &result, string mcjzb, float peakerr,string addcut="") {
267 > void PeakError(TTree *events,float &result, string mcjzb, float peakerr,int flipped,string addcut="") {
268 >    //Note: the cut used here is something like (JZBEXPRESSION+(peakerr)>50) without all the other cuts, to increase statistics (particularly for scans)
269          TString peakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
270          TString peakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
271          TString peakcentral("("+TString(mcjzb)+")"+geq_or_leq()+TString(any2string(jzbSel)));
272          TString npeakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
273          TString npeakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
274          TString npeakcentral("("+TString(mcjzb)+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
198        
275          nBins = 1;
276          string informalname="PeakErrorCalculation";
277          float resup,resdown,rescent;
# Line 212 | Line 288 | void PeakError(TTree *events,float &resu
288              negcut=npeakup;
289            }
290            float res;
291 <          if(addcut=="") res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
292 <          else res=allcontributionsplot(events,cutnJets&&addcut.c_str(),cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
291 >          if(addcut=="") res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str(),flipped);
292 >          else res=allcontributionsplot(events,cutnJets&&addcut.c_str(),cutmass,sidebandcut,poscut.c_str(),negcut.c_str(),flipped);
293            if(i==0) rescent=res;
294            else if(i==1) resdown=res;
295            else if(i==2) resup=res;
296          }
297 <        if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent);
298 <        else result=(TMath::Abs(rescent-resdown)/rescent);
297 >        if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/(float)rescent);
298 >        else result=(TMath::Abs(rescent-resdown)/(float)rescent);
299 >        cout << "    " << result << endl;
300 > }
301 >
302 >
303 > void  MCPartialefficiency(TTree *events,float &result, float &resulterr,int flipped, string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0, int type = 0) {
304 >   if(!events) {
305 >      write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
306 >      result=0;resulterr=0;
307 >      return;
308 >   }
309 >  
310 >   char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
311 >   // All acceptance cuts at gen. level
312 >   //TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
313 >   TCut kbase("");
314 >   if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
315 >   if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
316 >   // Corresponding reco. cuts
317 >  
318 >   TCut acceptance("genPt2 != 0");
319 >   TCut massId(cutmass&&cutOSSF);
320 >   TCut njets(cutnJets);
321 >   TCut jzbp;
322 >   TCut jzbn;
323 >   if(flipped==0) {
324 >        jzbp=TCut((TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
325 >        jzbn=TCut((TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
326 >   } else {
327 >        jzbp=TCut(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
328 >        jzbn=TCut(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
329 >   }
330 >   float ntotal = events->Draw("pt1", kbase, "goff");
331 >   TCut theCut;
332 >   switch(type) {
333 >     case 1:
334 >       theCut = kbase+acceptance;
335 >       break;
336 >     case 2:
337 >       theCut = kbase+massId;
338 >       break;
339 >     case 3:
340 >       theCut = kbase+massId+njets;
341 >       break;
342 >     case 4:
343 >       theCut = kbase+massId+njets+jzbn;
344 >       break;
345 >     default:
346 >       theCut = kbase+massId+njets+jzbn;
347 >       break;
348 >   }  
349 >      
350 >   string stheCut(theCut);
351 >   char var[20];
352 >   sprintf(var, "pdfW[%d]", k);
353 >
354 >   string svar(var);
355 >   string newtheCut;
356 >   if(k>0) newtheCut = "(" + stheCut + ")*" + svar;
357 >   else newtheCut = "(" + stheCut + ")"; // for k==0 or even k==-1 we don't need to evaluate PDFs
358 >
359 >   TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
360 >   if(k>=0) events->Draw((mcjzbexpression+">>effh").c_str(), newtheCut.c_str(),"goff");
361 >   else events->Draw((mcjzbexpression+">>effh").c_str(), theCut,"goff");
362 >   Float_t sel = effh->Integral();
363 >   Float_t nsel=0;
364 >   //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.
365 >   float normFactor = 1;
366 >   if(k>=0) get_norm_pdf_factor(events, k, addcut);
367 >   sel = sel/normFactor;
368 >
369 >   result=(sel)/ntotal;
370 >   resulterr=TMath::Sqrt(sel/ntotal*(1+sel/ntotal)/ntotal);
371 >
372 >   delete effh;
373   }
374  
375   //____________________________________________________________________________________
376   // Total selection efficiency (MC)
377 < void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ,int Neventsinfile, string addcut="") {
377 > //returns the efficiency WITHOUT signal contamination, and the result and resulterr contain the result and the corresponding error
378 > Value MCefficiency(TTree *events,float &result, float &resulterr, int flipped, string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0) {
379 >        if(!events) {
380 >          write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
381 >          result=0;
382 >          resulterr=0;
383 >          return Value(0,0);
384 >        }
385          
386          char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
387          // All acceptance cuts at gen. level
388          //TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
389          TCut kbase("");
390 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
390 >        
391 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
392 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
393          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
394          // Corresponding reco. cuts
395 <        TCut ksel("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
396 <        TCut ksel2("pfJetGoodNum>2&&abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
397 <        events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff");
398 <        Float_t sel = events->GetSelectedRows();
399 <        events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff");
400 <        Float_t nsel = events->GetSelectedRows();
401 < //      events->Draw(mcjzbexpression.c_str(),kbase,"goff");
402 < //      Float_t tot = events->GetSelectedRows();
395 >        
396 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
397 >        TCut ksel;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
398 >        TCut ksel2;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
399 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
400 >        if(PlottingSetup::RestrictToMassPeak||!ConsiderSignalContaminationForLimits) {
401 >          ksel=TCut("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
402 >          ksel2=TCut("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
403 >          if(flipped>0) {
404 >                ksel=TCut("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
405 >                ksel2=TCut("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
406 >          }
407 >        } else {
408 >          //for off peak analysis we don't use the OSSF condition here yet so we can recycle these two cuts for the em condition!
409 >          ksel=TCut("pfJetGoodNum>2"&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
410 >          ksel2=TCut("pfJetGoodNum>2"&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
411 >          if(flipped>0) {
412 >                ksel=TCut("pfJetGoodNum>2"&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
413 >                ksel2=TCut("pfJetGoodNum>2"&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
414 >          }
415 >        }
416 >            
417 >        TCut posSide = kbase&&ksel;
418 >        TCut negSide = kbase&&ksel2;
419 >        string sposSide(posSide);
420 >        string snegSide(negSide);
421 >        char var[20];
422 >        sprintf(var, "pdfW[%d]", k);
423 >        if(k==-1) sprintf(var,"1.0");//case in which we don't want to evaluate PDFs
424 >        string svar(var);
425 >        string newPosSide = "((id1==id2)&&(" + sposSide + "))*" + svar;
426 >        string newNegSide = "((id1==id2)&&(" + snegSide + "))*" + svar;
427 >        string emnewPosSide = "((id1!=id2)&&(" + sposSide + "))*" + svar; // only used for off peak analysis
428 >        string emnewNegSide = "((id1!=id2)&&(" + snegSide + "))*" + svar; // only used for off peak analysis
429 >
430 >        TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
431 >        if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), TCut(newPosSide.c_str())*PlottingSetup::Weight,"goff");
432 >        else events->Draw((mcjzbexpression+">>effh").c_str(), TCut((sposSide+"&&(id1==id2)").c_str())*PlottingSetup::Weight,"goff");//the OSSF condition is added for the offpeak analysis, in onpeak case it's there already but doesn't change anything.
433 >
434 >        Float_t sel = effh->Integral();
435 >        Float_t nsel=0;
436 >        
437 >        ///----------------------------------------------- THIS PART REQUIRES STUDYING! -------------------------
438 >        
439 >        if(ConsiderSignalContaminationForLimits) {
440 >          flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
441 >          if(PlottingSetup::RestrictToMassPeak) {
442 >            events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(newNegSide.c_str()))*PlottingSetup::Weight,"goff");
443 >            nsel += effh->Integral();
444 >          } else {
445 >            events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(newNegSide.c_str()))*PlottingSetup::Weight,"goff");
446 >            nsel += effh->Integral();
447 >            events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(emnewPosSide.c_str()))*PlottingSetup::Weight,"goff");
448 >            nsel += effh->Integral();
449 >            events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(emnewNegSide.c_str()))*PlottingSetup::Weight,"goff");
450 >            nsel -= effh->Integral();
451 >          }
452 >        }
453 >
454 >        //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.
455 >        float normFactor = 1;
456 >        if(k>=0) get_norm_pdf_factor(events, k, addcut);
457 >        sel = sel/normFactor;
458 >        nsel = nsel/normFactor;
459 >
460          Float_t tot = Neventsinfile;
461          
462 <        result=(sel-nsel)/tot;
463 <        resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot);
464 <        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
462 >        Value result_wo_signalcont;
463 >
464 >        if(ConsiderSignalContaminationForLimits) {
465 >          result=(sel-nsel)/tot;
466 >          resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
467 >          result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot));
468 >        } else {//no signal contamination considered:
469 >          result=(sel)/tot;
470 >          resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
471 >          result_wo_signalcont=Value(result,resulterr);
472 >        }
473 >        if(!automatized && k>0 ) dout << "PDF assessment [" << k << "] : ";
474 >        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , signal contamination : " << nsel << " and nevents=" << tot << ") with normFact=" << normFactor << std::endl;
475 >        delete effh;
476 >        return result_wo_signalcont;
477   }
478  
479 < void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
480 <        TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
479 >
480 >
481 > //____________________________________________________________________________________
482 > // Selection efficiency for one process (MC)
483 > // not in use anymore.
484 > /*
485 > vector<float> processMCefficiency(TTree *events,int flipped, string mcjzb,bool requireZ,int Neventsinfile, string addcut) {
486 >  vector<float> process_efficiencies;
487 >  for(int iprocess=0;iprocess<=10;iprocess++) {
488 >    float this_process_efficiency,efferr;
489 >    stringstream addcutplus;
490 >    addcutplus<<addcut<<"&&(process=="<<iprocess<<")";
491 >    MCefficiency(events,this_process_efficiency, efferr,flipped,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1);
492 >    process_efficiencies.push_back(this_process_efficiency);
493 >  }
494 >  return process_efficiencies;
495 > }
496 > */      
497 >
498 > void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, int flipped, bool requireZ, string addcut="") {
499 >        TCut kbase(genMassCut&&"genNjets>2&&genZPt>0"&&cutmass&&cutOSSF);
500          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
501 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
502 <        TH1F* hLM4 = plotEff(events,kbase,informalname);
501 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
502 >        TH1F* hLM4 = plotEff(events,kbase,informalname,flipped);
503          Int_t bin = hLM4->FindBin(jzbSel); // To get the error
504          jzbeff=Interpolate(jzbSel,hLM4);
505          jzbefferr=hLM4->GetBinError(bin);
# Line 262 | Line 509 | void JZBefficiency(TTree *events, string
509  
510   //________________________________________________________________________
511   // Effect of energy scale on efficiency
512 < void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,string addcut="",float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
513 <        TCut kbase("abs(genMll-91.2)<20&&genZPt>0");
512 > void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname, int flipped, bool requireZ,string addcut="",Float_t jzbSelection=-1, TString plotName = "" ) {
513 >        TCut kbase(genMassCut&&"genZPt>0");
514          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
515 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
515 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
516 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
517  
518 <        TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
518 >        TCut ksel(cutmass&&cutOSSF);
519          TCut nJets("pfJetGoodNum>2");
520          stringstream down,up;
521 <        down << "pfJetGoodNum"<<30*(1-syst)<<">=3";
522 <        up << "pfJetGoodNum"<<30*(1+syst)<<">=3";
521 >        down << "pfJetGoodNumn1sigma>=3";
522 >        up << "pfJetGoodNump1sigma>=3";
523          
524          TCut nJetsP(up.str().c_str());
525          TCut nJetsM(down.str().c_str());
# Line 279 | Line 527 | void JZBjetScale(TTree *events, float &j
527          if ( !(plotName.Length()>1) ) plotName = informalname;
528          
529          nBins = 1; jzbMin = jzbSel*0.95; jzbMax = jzbSel*1.05;
530 <        TH1F* hist = plotEff(events,(kbase&&ksel&&nJets),informalname);
531 <        
532 <        TH1F* histp = plotEff(events,(kbase&&ksel&&nJetsP),informalname);
285 <        
286 <        TH1F* histm = plotEff(events,(kbase&&ksel&&nJetsM),informalname);
530 >        TH1F* hist  = plotEff(events,(kbase&&ksel&&nJets),informalname,flipped);
531 >        TH1F* histp = plotEff(events,(kbase&&ksel&&nJetsP),informalname,flipped);
532 >        TH1F* histm = plotEff(events,(kbase&&ksel&&nJetsM),informalname,flipped);
533          
534          // Dump some information
535          Float_t eff  = Interpolate(jzbSel,hist);
# Line 299 | Line 545 | void JZBjetScale(TTree *events, float &j
545  
546   //________________________________________________________________________
547   // Effect of energy scale on JZB efficiency
548 < void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ, string addcut) {
548 > void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, int flipped, bool requireZ, string addcut) {
549          
550 <        TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
550 >        TCut kbase(genMassCut&&"genZPt>0&&genNjets>2");
551          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
552 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
553 <        TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
552 >        flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
553 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
554 >        TCut ksel(cutmass&&cutOSSF);
555          
556          nBins =    50;
557          jzbMin =   0.5*jzbSel;
558          jzbMax =   2.0*jzbSel;
559          
560 <        TH1F* hist = plotEff(events,kbase&&ksel,informalname);
560 >        TH1F* hist = plotEff(events,kbase&&ksel,informalname,flipped);
561          
562          // Dump some information
563          Float_t eff  = Interpolate(jzbSel,hist);
564          Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
565          Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
566 <        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
566 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
567          if(!automatized) dout << "  efficiency at JZB==" << jzbSel  << ": " << eff << std::endl;
568 <        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
568 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
569          up=((effp-eff)/eff);
570          down=((effm-eff)/eff);
571   }
572  
573   //________________________________________________________________________
574   // JZB response (true/reco. vs. true)
575 < void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, string addcut="",bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
575 > void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, int flipped, string addcut="", bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
576          
577          jzbMin = 20;
578 <        TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
578 >        flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
579 >        TCut kbase(genMassCut&&"genZPt>0&&genNjets>2");
580          if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
581 <        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
582 <        TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
581 >        flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
582 >        if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
583 >        flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
584 >        TCut ksel(cutmass&&cutOSSF);
585          
586          TProfile* hJzbResp = new TProfile("hJzbResp","JZB response  ; JZB true (GeV/c); JZB reco. / JZB true", nPeriods, jzbMin, myJzbMax, "" );
587          
588 <        if (!isMET) events->Project("hJzbResp","("+TString(mcjzbexpression)+")/genJZB:genJZB",kbase&&ksel);
588 >        string locmcjzbexpression=mcjzbexpression;
589 >        if(flipped>0) locmcjzbexpression="-"+locmcjzbexpression;
590 >        string possibleminus="";
591 >        if(flipped>0) possibleminus="-";
592 >        if (!isMET) events->Project("hJzbResp","("+TString(locmcjzbexpression)+")/("+possibleminus+"genJZB):("+possibleminus+"genJZB)",kbase&&ksel);
593          else events->Project("hJzbResp","met[4]/genMET:genMET",kbase&&ksel);
594          
595          hJzbResp->SetMaximum(1.2);
596          hJzbResp->SetMinimum(0.2);
597          hJzbResp->Fit("pol0","Q");
598          TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
599 <        resp=fittedfunction->GetParameter(0);
600 <        resperr=fittedfunction->GetParError(0);
601 <        if(!automatized) dout << "  Response: " << resp << " +/- " << resperr << endl;
599 >        if(!fittedfunction) {
600 >                // in case there are not enough points passing our selection
601 >                cout << "OOPS response function invalid, assuming 100% error !!!!" << endl;
602 >                resp=1;
603 >                resperr=1;
604 >        } else {
605 >                resp=fittedfunction->GetParameter(0);
606 >                resperr=fittedfunction->GetParError(0);
607 >                if(!automatized) dout << "  Response: " << resp << " +/- " << resperr << endl;
608 >        }
609          delete hJzbResp;
610   }
611  
612  
613 < 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="") {
613 > //________________________________________________________________________________________
614 > // PDF uncertainty  
615 > float get_pdf_uncertainty(TTree *events, int flipped, string mcjzb, bool requireZ, int Neventsinfile, int NPdfs, string addcut="") {
616 >  std::vector<float> efficiency;
617 >  for(int k = 1; k < NPdfs; k++) {
618 >    float result, resulterr;
619 >    Value flipval;
620 >    MCefficiency(events, result, resulterr, flipped, mcjzb, requireZ, Neventsinfile, addcut, k);
621 >    efficiency.push_back(result);
622 >  }
623 >  float errHi, errLow,err;
624 >  master_formula(efficiency, errHi, errLow);
625 >  err=errLow;
626 >  if(errHi>errLow) err=errHi;
627 >  if(!automatized) dout << "  Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl;
628 >  return err;
629 >
630 > }
631 >
632 > int get_npdfs(TTree *events) {
633 >  int NPDFs;
634 >  events->SetBranchAddress("NPdfs",&NPDFs);
635 >  events->GetEntry(1);
636 >  return NPDFs;
637 > }
638    
639 <  float JetEnergyScaleUncert=0.1;
640 <  float JZBScaleUncert=0.1;
639 >
640 > void do_systematics_for_one_file(TTree *events,int Neventsinfile,string informalname, vector<vector<float> > &results,int flipped, string mcjzb,string datajzb,float peakerror,bool requireZ=false, string addcut="", bool ismSUGRA=false) {
641 >  float JZBScaleUncert=0.05;
642    mcjzbexpression=mcjzb;
643 <  float triggereff=4.0/100;// in range [0,1]
643 >  float triggereff=2.0/100;// in range [0,1]
644    dout << "Trigger efficiency not implemented in this script  yet, still using external one" << endl;
645    float leptonseleff=2.0/100;// in range [0,1]
646 +  leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton
647    dout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
648    
649 +  int NPdfs=0;
650 +  if(ismSUGRA) NPdfs = get_npdfs(events);
651 +  
652    float mceff,mcefferr,jzbeff,jzbefferr;
653    if(!automatized) dout << "MC efficiencies:" << endl;
654 <  MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut);
655 <  JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
654 >  Value flipefficiency;
655 >  Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,flipped,mcjzb,requireZ,Neventsinfile,addcut,-1);
656 >  if(!automatized) cout << "   Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl;
657 >
658 >  if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,flipped,requireZ,addcut);
659    if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
660    
661 <  if(!automatized) dout << "Error from Peak position:" << endl;
661 >  if(!automatized) dout << "Error from Peak position:";
662    float sysfrompeak=0;
663 <  PeakError(events,sysfrompeak,mcjzb,peakerror,addcut);
663 >  PeakError(events,sysfrompeak,mcjzb,peakerror,flipped,addcut);
664      
665 <  if(!automatized) dout << "Jet energy scale: " << std::endl;
665 >  if(!automatized) dout << "Jet energy scale (JES): " << std::endl;
666    float jesup,jesdown;
667 <  JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert);
667 >  JZBjetScale(events,jesdown,jesup,informalname,flipped,requireZ,addcut);
668    
669    if(!automatized) dout << "JZB scale: " << std::endl;
670    float scaleup,scaledown,scalesyst;
671 <  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut);
671 >  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,flipped,requireZ,addcut);
672    
673    if(!automatized) dout << "JZB response: " << std::endl;
674    float resp,resperr;
675 <  JZBresponse(events,requireZ,resp,resperr,addcut);
675 >  if(PlottingSetup::computeJZBresponse) {
676 >        if(!automatized) dout << "JZB response: " << std::endl;
677 >        if(!ismSUGRA) JZBresponse(events,requireZ,resp,resperr,flipped,addcut);
678 >  }
679  
680    if(!automatized) dout << "Pileup: " << std::endl;
681 <  float resolution=pileup(events,requireZ,informalname,addcut);
682 <  
681 > //  float resolution;
682 >  //resolution=pileup(events,requireZ,informalname,flipped,addcut);
683 >
684 >  float PDFuncert=0;
685 >  if(!automatized) dout << "Assessing PDF uncertainty: " << std::endl;
686 >  if(ismSUGRA) PDFuncert = get_pdf_uncertainty(events, flipped, mcjzb, requireZ, Neventsinfile, NPdfs, addcut);
687 >
688    dout << "_______________________________________________" << endl;
689    dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
690    if(addcut!="") dout << "With additional cut: " << addcut;
# Line 393 | Line 694 | void do_systematics_for_one_file(TTree *
694    dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1]
695    dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1]
696    dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
697 <  dout << "Resolution : " << resolution << endl; // in range [0,1]
697 > //  dout << "Resolution : " << resolution << endl; // in range [0,1]
698    dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
699 <  dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
700 <  dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
699 >  if(ismSUGRA) dout << "PDF uncertainty  : " << PDFuncert << endl; // in range [0,1]
700 >  if(PlottingSetup::computeJZBefficiency) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
701 >  if(PlottingSetup::computeJZBresponse)dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
702    
703    float toterr=0;
704    toterr+=(triggereff)*(triggereff);
705    toterr+=(leptonseleff)*(leptonseleff);
706    if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown);
707    if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
708 <  toterr+=(resolution*resolution);
708 > //  toterr+=(resolution*resolution);
709    toterr+=(sysfrompeak*sysfrompeak);
710 +  if(ismSUGRA) toterr+=(PDFuncert*PDFuncert);
711    dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
712    float systerr=TMath::Sqrt(toterr)*mceff;
713    toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
714    
715    dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst)   %" << endl;
716    dout << "     we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
717 +  dout << "_______________________________________________" << endl;
718    
719    //Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
720    vector<float> res;
# Line 421 | Line 725 | void do_systematics_for_one_file(TTree *
725    res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr)));
726    if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
727    if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
728 <  res.push_back(fabs(resolution));
728 > //  res.push_back(fabs(resolution));
729 >  res.push_back(0.0);
730 >  res.push_back(mceff_nosigcont.getValue());
731 >  res.push_back(mceff_nosigcont.getError());
732 >  if(ismSUGRA) res.push_back(PDFuncert);
733    results.push_back(res);
734   }
735  
736 < vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
736 > vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, int flipped, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
737    automatized=true;
738    vector< vector<float> > systematics;
739    for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
# Line 433 | Line 741 | vector<vector<float> > compute_systemati
741        for(int ibin=0;ibin<bins.size();ibin++) {
742          jzbSel=bins[ibin];
743          geqleq="geq";
744 <        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
744 >        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,flipped,mcjzb,datajzb,mcpeakerror,requireZ);
745        }//end of bin loop
746    }//end of signal loop
747    return systematics;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines