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.2 by buchmann, Tue Jul 19 07:04:41 2011 UTC vs.
Revision 1.21 by buchmann, Mon Aug 29 06:30:21 2011 UTC

# Line 36 | Line 36 | int iplot=0;
36   int verbose=0;
37   string geqleq;
38   string mcjzbexpression;
39 + bool automatized=false;//if we're running this fully automatized we don't want each function to flood the screen
40  
41   TString geq_or_leq() {
42    if(geqleq=="geq") return TString(">=");
# Line 43 | Line 44 | TString geq_or_leq() {
44    return TString("GEQ_OR_LEQ_ERROR");
45   }
46  
47 + TString ngeq_or_leq() {
48 +  if(geqleq=="geq") return TString("<=");
49 +  if(geqleq=="leq") return TString(">=");
50 +  return TString("NGEQ_OR_LEQ_ERROR");
51 + }
52 +
53   //______________________________________________________________________________
54   Double_t Interpolate(Double_t x, TH1 *histo)
55   {
# Line 74 | Line 81 | Double_t Interpolate(Double_t x, TH1 *hi
81     }
82   }
83  
84 + //____________________________________________________________________________________
85 + // Plotting with all contributions, i.e. sidebands, peak, osof,ossf ... (for a systematic)
86 + float allcontributionsplot(TTree* events, TCut kBaseCut, TCut kMassCut, TCut kSidebandCut, TCut JZBPosCut, TCut JZBNegCut) {
87 +        iplot++;
88 +        int count=iplot;
89 +        // Define new histogram
90 +        string hname=GetNumericHistoName();
91 +        TH1F* hossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
92 +        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSSF,"goff");
93 +        hname=GetNumericHistoName();
94 +        TH1F* hossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
95 +        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSSF,"goff");
96 +
97 +        hname=GetNumericHistoName();
98 +        TH1F* hosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
99 +        events->Draw(TString(mcjzbexpression)+">>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSOF,"goff");
100 +        hname=GetNumericHistoName();
101 +        TH1F* hosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
102 +        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");
117 +        
118 +        float obs = hossfp->Integral();
119 +        float pred= hossfn->Integral() + (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
120 +        
121 +        delete hossfp,hossfn,hosofp,hosofn;
122 +        delete sbhossfp,sbhossfn,sbhosofp,sbhosofn;
123 +        return obs-pred;
124 + }
125 +
126  
127   //____________________________________________________________________________________
128   // Efficiency plot
# Line 86 | Line 135 | TH1F* plotEff(TTree* events, TCut kbase,
135                                                           nBins,jzbMin,jzbMax);
136          Float_t step = (jzbMax-jzbMin)/static_cast<Float_t>(nBins);
137          
138 <        events->Draw(mcjzbexpression.c_str(),"genJZBSel>-400"&&kbase,"goff");
138 >        events->Draw(mcjzbexpression.c_str(),"genJZB>-400"&&kbase,"goff");
139          Float_t maxEff = events->GetSelectedRows();
140 <        if(verbose>0) std::cout << hname << " (" << informalname <<") " << maxEff <<  std::endl;
140 >        if(verbose>0) dout << hname << " (" << informalname <<") " << maxEff <<  std::endl;
141          
142 <        if(verbose>0) std::cout <<  "JZB max = " << jzbMax << std::endl;
142 >        if(verbose>0) dout <<  "JZB max = " << jzbMax << std::endl;
143          // Loop over steps to get efficiency curve
144          char cut[256];
145          for ( Int_t iBin = 0; iBin<nBins; ++iBin ) {
146 <                sprintf(cut,"genJZBSel>%3f",jzbMin+iBin*step);
146 >                sprintf(cut,"genJZB>%3f",jzbMin+iBin*step);
147                  events->Draw(mcjzbexpression.c_str(),TCut(cut)&&kbase,"goff");
148                  Float_t eff = static_cast<Float_t>(events->GetSelectedRows())/maxEff;
149 <                //     std::cout << "COUCOU " << __LINE__ << std::endl;
149 >                //     dout << "COUCOU " << __LINE__ << std::endl;
150                  hJzbEff->SetBinContent(iBin+1,eff);
151                  hJzbEff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/maxEff));
152          }
# Line 109 | Line 158 | TH1F* plotEff(TTree* events, TCut kbase,
158  
159   //________________________________________________________________________________________
160   // Pile-up efficiency
161 < float pileup(TTree *events, 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(genMllSel-91.2)<20&&pfJetGoodNum>2&&genZPtSel>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
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.);
172          
# Line 128 | Line 179 | float pileup(TTree *events, string infor
179          // Pimped-up function
180          TF1* funcUp = (TF1*)func->Clone();
181          funcUp->SetParameter( 0., func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
182 <        std::cout << "  PU: " << funcUp->Eval(jzbSel) << " " <<  func->Eval(jzbSel)
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,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)));
195 +        TString npeakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
196 +        TString npeakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
197 +        TString npeakcentral("("+TString(mcjzb)+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
198 +        
199 +        nBins = 1;
200 +        string informalname="PeakErrorCalculation";
201 +        float resup,resdown,rescent;
202 +        for(int i=0;i<3;i++) {
203 +          string poscut,negcut;
204 +          if(i==0) {
205 +            poscut=peakcentral;
206 +            negcut=npeakcentral;
207 +          } else if(i==1) {
208 +            poscut=peakdown;
209 +            negcut=npeakdown;
210 +          } else if(i==2) {
211 +            poscut=peakup;
212 +            negcut=npeakup;
213 +          }
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);
222 +        else result=(TMath::Abs(rescent-resdown)/rescent);
223 + }
224 +
225 + //____________________________________________________________________________________
226   // Total selection efficiency (MC)
227 < void MCefficiency(TTree *events,float &res, float &reserr,string mcjzb) {
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(genMllSel-91.2)<20&&pfJetGoodNum>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();
242 <        
243 <        res=sel/tot;
244 <        reserr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot);
245 <        std::cout << "  MC efficiency: " << res << "+-" << reserr << std::endl;
240 >        Float_t nsel=0;
241 >        if(ConsiderSignalContaminationForLimits) {
242 >          events->Draw(mcjzbexpression.c_str(),kbase&&ksel2,"goff");
243 >          nsel = events->GetSelectedRows();
244 >        }
245 > //      events->Draw(mcjzbexpression.c_str(),kbase,"goff");
246 > //      Float_t tot = events->GetSelectedRows();
247 >        Float_t tot = Neventsinfile;
248 >        
249 >        if(ConsiderSignalContaminationForLimits) {
250 >          result=(sel-nsel)/tot;
251 >          resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
252 >        } else {//no signal contamination considered:
253 >          result=(sel)/tot;
254 >          resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
255 >        }
256 >        if(!automatized) dout << "  MC efficiency: " << result << "+-" << resulterr << "  ( JZB>" << jzbSel << " : " << sel << " , JZB<-" << jzbSel << " : " << nsel << " and nevents=" << tot << ")" << std::endl;
257   }
258  
259 < float JZBefficiency(TTree *events, string informalname) {
260 <        TCut kbase("abs(genMllSel-91.2)<20&&pfJetGoodNum>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
259 > void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ, string addcut="") {
260 >        TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
261 >        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
262 >        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
263          TH1F* hLM4 = plotEff(events,kbase,informalname);
264          Int_t bin = hLM4->FindBin(jzbSel); // To get the error
265 <        std::cout << "  Efficiency at JZB==" << jzbSel  << std::endl;
266 <        std::cout << "    " << Interpolate(jzbSel,hLM4) << "+-" << hLM4->GetBinError(bin)  << std::endl;
267 <        return -1;
265 >        jzbeff=Interpolate(jzbSel,hLM4);
266 >        jzbefferr=hLM4->GetBinError(bin);
267 >        if(!automatized) dout << "  Efficiency at JZB==" << jzbSel  << std::endl;
268 >        if(!automatized) dout << "    " << jzbeff << "+-" << jzbefferr  << std::endl;
269   }
270  
271   //________________________________________________________________________
272   // Effect of energy scale on efficiency
273 < void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname="",float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
274 <        TCut kbase("abs(genMllSel-91.2)<20&&genZPt>0");
273 > void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,string addcut="",float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
274 >        TCut kbase("abs(genMll-91.2)<20&&genZPt>0");
275 >        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
276 >        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
277 >
278          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
279          TCut nJets("pfJetGoodNum>2");
280          stringstream down,up;
# Line 177 | Line 284 | void JZBjetScale(TTree *events, float &j
284          TCut nJetsP(up.str().c_str());
285          TCut nJetsM(down.str().c_str());
286          
180        if ( jzbSelection>0 ) jzbSel = jzbSelection;
181        
287          if ( !(plotName.Length()>1) ) plotName = informalname;
288          
289          nBins = 1; jzbMin = jzbSel*0.95; jzbMax = jzbSel*1.05;
# Line 192 | Line 297 | void JZBjetScale(TTree *events, float &j
297          Float_t eff  = Interpolate(jzbSel,hist);
298          Float_t effp = Interpolate(jzbSel,histp);
299          Float_t effm = Interpolate(jzbSel,histm);
300 <        std::cout << "  Efficiency at JZB==" << jzbSel  << std::endl;
301 <        std::cout << "    JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
302 <        std::cout << "    central:  " << eff << std::endl;
303 <        std::cout << "    JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
304 <        jesup=(effp-eff)/eff*100.;
305 <        jesdown=(effm-eff)/eff*100.;
300 >        if(!automatized) dout << "  Efficiency at JZB==" << jzbSel  << std::endl;
301 >        if(!automatized) dout << "    JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
302 >        if(!automatized) dout << "    central:  " << eff << std::endl;
303 >        if(!automatized) dout << "    JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
304 >        jesup=(effp-eff)/eff;
305 >        jesdown=(effm-eff)/eff;
306   }
307  
308   //________________________________________________________________________
309   // Effect of energy scale on JZB efficiency
310 < void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname) {
310 > void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ, string addcut) {
311          
312 <        TCut kbase("abs(genMllSel-91.2)<20&&genZPt>0&&pfJetGoodNum>2");
312 >        TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
313 >        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
314 >        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
315          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
316          
317          nBins =    50;
# Line 217 | Line 324 | void doJZBscale(TTree *events, float &do
324          Float_t eff  = Interpolate(jzbSel,hist);
325          Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
326          Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
327 <        std::cout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
328 <        std::cout << "  efficiency at JZB==" << jzbSel  << ": " << eff << std::endl;
329 <        std::cout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
330 <        up=((effp-eff)/eff)*100;
331 <        down=((effm-eff)/eff)*100;
327 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.+systematic)  << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)"  << std::endl;
328 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel  << ": " << eff << std::endl;
329 >        if(!automatized) dout << "  efficiency at JZB==" << jzbSel*(1.-systematic)  << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)"  << std::endl;
330 >        up=((effp-eff)/eff);
331 >        down=((effm-eff)/eff);
332   }
333  
334   //________________________________________________________________________
335   // JZB response (true/reco. vs. true)
336 < void JZBresponse(TTree *events, bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
336 > void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, string addcut="",bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
337          
338          jzbMin = 20;
339 <        TCut kbase("abs(genMllSel-91.2)<20&&genZPtSel>0&&pfJetGoodNum>2");
339 >        TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
340 >        if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
341 >        if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
342          TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
343          
344 <        TProfile* hJzbResp = new TProfile("hJzbResp","JZB response  ; JZB true (GeV/c); JZB reco. / JZB true",
236 <                                                                          nPeriods, jzbMin, myJzbMax, "" );
344 >        TProfile* hJzbResp = new TProfile("hJzbResp","JZB response  ; JZB true (GeV/c); JZB reco. / JZB true", nPeriods, jzbMin, myJzbMax, "" );
345          
346 <        if (!isMET) events->Project("hJzbResp","("+TString(mcjzbexpression)+")/genJZBSel:genJZBSel",kbase&&ksel);
346 >        if (!isMET) events->Project("hJzbResp","("+TString(mcjzbexpression)+")/genJZB:genJZB",kbase&&ksel);
347          else events->Project("hJzbResp","met[4]/genMET:genMET",kbase&&ksel);
348          
349          hJzbResp->SetMaximum(1.2);
350          hJzbResp->SetMinimum(0.2);
351          hJzbResp->Fit("pol0","Q");
352          TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
353 <        cout << "  Response: " << fittedfunction->GetParameter(0) << " +/- " << fittedfunction->GetParError(0) << endl;
353 >        resp=fittedfunction->GetParameter(0);
354 >        resperr=fittedfunction->GetParError(0);
355 >        if(!automatized) dout << "  Response: " << resp << " +/- " << resperr << endl;
356 >        delete hJzbResp;
357   }
358  
359  
360 < void do_systematics_for_one_file(TTree *events,string informalname, vector<vector<float> > &uncertainties,string mcjzb,string datajzb) {
360 > 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="") {
361    
362    float JetEnergyScaleUncert=0.1;
363    float JZBScaleUncert=0.1;
364    mcjzbexpression=mcjzb;
365 +  float triggereff=4.0/100;// in range [0,1]
366 +  dout << "Trigger efficiency not implemented in this script  yet, still using external one" << endl;
367 +  float leptonseleff=2.0/100;// in range [0,1]
368 +  dout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
369    
370 <  float triggereff=4;//percent!
371 <  cout << "Trigger efficiency not implemented in this script  yet, still using external one" << endl;
372 <  float leptonseleff=2;//percent!
373 <  cout << "Lepton selection efficiency not implemented in this script  yet, still using external one" << endl;
374 <  
260 <  float mceff,mcefferr;
261 <  cout << "MC efficiencies:" << endl;
262 <  MCefficiency(events,mceff,mcefferr,mcjzb);
263 <  JZBefficiency(events,informalname);
370 >  float mceff,mcefferr,jzbeff,jzbefferr;
371 >  if(!automatized) dout << "MC efficiencies:" << endl;
372 >  MCefficiency(events,mceff,mcefferr,mcjzb,requireZ,Neventsinfile,addcut);
373 >  JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ,addcut);
374 >  if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
375    
376 <  std::cout << "Jet energy scale: " << std::endl;
376 >  if(!automatized) dout << "Error from Peak position:" << endl;
377 >  float sysfrompeak=0;
378 >  PeakError(events,sysfrompeak,mcjzb,peakerror,addcut);
379 >    
380 >  if(!automatized) dout << "Jet energy scale: " << std::endl;
381    float jesup,jesdown;
382 <  JZBjetScale(events,jesdown,jesup,informalname,JetEnergyScaleUncert);
382 >  JZBjetScale(events,jesdown,jesup,informalname,requireZ,addcut,JetEnergyScaleUncert);
383    
384 <  std::cout << "JZB scale: " << std::endl;
384 >  if(!automatized) dout << "JZB scale: " << std::endl;
385    float scaleup,scaledown,scalesyst;
386 <  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname);
386 >  doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ,addcut);
387    
388 <  std::cout << "JZB response: " << std::endl;
389 <  JZBresponse(events);
388 >  if(!automatized) dout << "JZB response: " << std::endl;
389 >  float resp,resperr;
390 >  JZBresponse(events,requireZ,resp,resperr,addcut);
391  
392 <  std::cout << "Pileup: " << std::endl;
393 <  float resolution=pileup(events,informalname);
392 >  if(!automatized) dout << "Pileup: " << std::endl;
393 >  float resolution=pileup(events,requireZ,informalname,addcut);
394    
395 <  cout << "_______________________________________________" << endl;
396 <  cout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << endl;
397 <  cout << "Trigger efficiency: " << triggereff << endl;
398 <  cout << "Lepton Sel Eff: " << leptonseleff << endl;
399 <  cout << "For JZB>" << jzbSel << endl;
400 <  cout << "Jet energy scale: " << jesup << " " << jesdown << " --> suggesting: " << Round(0.5*(fabs(jesup)+fabs(jesdown)),1) << endl;
401 <  cout << "JZB Scale Uncert: " << scaledown << " " << scaleup << " --> suggesting: " << Round(0.5*(fabs(scaledown)+fabs(scaleup)),1) << endl;
402 <  cout << "Resolution : " << resolution << endl;
395 >  dout << "_______________________________________________" << endl;
396 >  dout << "                 SUMMARY FOR " << informalname << " with JZB>" << jzbSel << "  (all in %) ";
397 >  if(addcut!="") dout << "With additional cut: " << addcut;
398 >  dout << endl;
399 >  dout << "MC efficiency: " << mceff << "+/-" << mcefferr << endl; // in range [0,1]
400 >  dout << "Trigger efficiency: " << triggereff << endl; // in range [0,1]
401 >  dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1]
402 >  dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1]
403 >  dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
404 >  dout << "Resolution : " << resolution << endl; // in range [0,1]
405 >  dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
406 >  dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
407 >  dout << "JZB response  : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
408    
409 <  vector<float> uncert;
410 <  uncert.push_back(jzbSel);
411 <  uncert.push_back(triggereff);
412 <  uncert.push_back(leptonseleff);
413 <  uncert.push_back(0.5*(fabs(jesup)+fabs(jesdown)));
414 <  uncert.push_back(0.5*(fabs(scaledown)+fabs(scaleup)));
415 <  uncert.push_back(resolution);
409 >  float toterr=0;
410 >  toterr+=(triggereff)*(triggereff);
411 >  toterr+=(leptonseleff)*(leptonseleff);
412 >  if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown);
413 >  if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
414 >  toterr+=(resolution*resolution);
415 >  toterr+=(sysfrompeak*sysfrompeak);
416 >  dout << "TOTAL SYSTEMATICS: " << TMath::Sqrt(toterr) << " --> " << TMath::Sqrt(toterr)*mceff << endl;
417 >  float systerr=TMath::Sqrt(toterr)*mceff;
418 >  toterr=TMath::Sqrt(toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
419    
420 <  uncertainties.push_back(uncert);
421 < }
422 <
423 < vector<vector<float> > compute_systematics(string mcjzb, string datajzb, samplecollection &signalsamples, vector<float> bins) {
424 <  vector< vector<float> > uncertainties;
420 >  dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst)   %" << endl;
421 >  dout << "     we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
422 >  
423 >  //Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
424 >  vector<float> res;
425 >  res.push_back(jzbSel);
426 >  res.push_back(mceff);
427 >  res.push_back(mcefferr);
428 >  res.push_back(toterr);
429 >  res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr)));
430 >  if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
431 >  if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
432 >  res.push_back(fabs(resolution));
433 >  results.push_back(res);
434 > }
435 >
436 > vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
437 >  automatized=true;
438 >  vector< vector<float> > systematics;
439    for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
440 <      cout << "Looking at signal " << (signalsamples.collection)[isignal].filename << endl;
440 >      dout << "Looking at signal " << (signalsamples.collection)[isignal].filename << endl;
441        for(int ibin=0;ibin<bins.size();ibin++) {
442          jzbSel=bins[ibin];
443          geqleq="geq";
444 <        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,uncertainties,mcjzb,datajzb);
444 >        do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
445        }//end of bin loop
446    }//end of signal loop
447 <  return uncertainties;
447 >  return systematics;
448   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines