ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Systematics.C
Revision: 1.8
Committed: Thu Jul 21 08:26:12 2011 UTC (13 years, 9 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.7: +34 -24 lines
Log Message:
Added option for systematics to require a Z explicitly

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4    
5     #include <TMath.h>
6     #include <TColor.h>
7     #include <TPaveText.h>
8     #include <TRandom.h>
9     #include <TF1.h>
10    
11     #ifndef SampleClassLoaded
12     #include "ActiveSamples.C"
13     #endif
14    
15     #ifndef Verbosity
16     #define Verbosity 0
17     #endif
18    
19     #include <TFile.h>
20     #include <TTree.h>
21     #include <TH1.h>
22     #include <TCut.h>
23     #include <TMath.h>
24     #include <TLine.h>
25     #include <TCanvas.h>
26     #include <TProfile.h>
27     #include <TF1.h>
28    
29    
30    
31     Int_t nBins = 100;
32     Float_t jzbMin = -207;
33     Float_t jzbMax = 243;
34     Float_t jzbSel = 100;
35     int iplot=0;
36     int verbose=0;
37 buchmann 1.2 string geqleq;
38     string mcjzbexpression;
39 buchmann 1.4 bool automatized=false;//if we're running this fully automatized we don't want each function to flood the screen
40 buchmann 1.2
41     TString geq_or_leq() {
42     if(geqleq=="geq") return TString(">=");
43     if(geqleq=="leq") return TString("<=");
44     return TString("GEQ_OR_LEQ_ERROR");
45     }
46 buchmann 1.1
47 buchmann 1.6 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 buchmann 1.1 //______________________________________________________________________________
54     Double_t Interpolate(Double_t x, TH1 *histo)
55     {
56     // Given a point x, approximates the value via linear interpolation
57     // based on the two nearest bin centers
58     // Andy Mastbaum 10/21/08
59     // in newer ROOT versions but not in the one I have so I had to work around that ...
60    
61     Int_t xbin = histo->FindBin(x);
62     Double_t x0,x1,y0,y1;
63    
64     if(x<=histo->GetBinCenter(1)) {
65     return histo->GetBinContent(1);
66     } else if(x>=histo->GetBinCenter(histo->GetNbinsX())) {
67     return histo->GetBinContent(histo->GetNbinsX());
68     } else {
69     if(x<=histo->GetBinCenter(xbin)) {
70     y0 = histo->GetBinContent(xbin-1);
71     x0 = histo->GetBinCenter(xbin-1);
72     y1 = histo->GetBinContent(xbin);
73     x1 = histo->GetBinCenter(xbin);
74     } else {
75     y0 = histo->GetBinContent(xbin);
76     x0 = histo->GetBinCenter(xbin);
77     y1 = histo->GetBinContent(xbin+1);
78     x1 = histo->GetBinCenter(xbin+1);
79     }
80     return y0 + (x-x0)*((y1-y0)/(x1-x0));
81     }
82     }
83    
84 buchmann 1.7 //____________________________________________________________________________________
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 buchmann 1.1
127     //____________________________________________________________________________________
128     // Efficiency plot
129     TH1F* plotEff(TTree* events, TCut kbase, TString informalname) {
130     iplot++;
131     int count=iplot;
132     // Define new histogram
133     char hname[30]; sprintf(hname,"hJzbEff%d",count);
134     TH1F* hJzbEff = new TH1F(hname,"JZB selection efficiency ; JZB (GeV/c); Efficiency",
135     nBins,jzbMin,jzbMax);
136     Float_t step = (jzbMax-jzbMin)/static_cast<Float_t>(nBins);
137    
138 buchmann 1.6 events->Draw(mcjzbexpression.c_str(),"genJZB>-400"&&kbase,"goff");
139 buchmann 1.1 Float_t maxEff = events->GetSelectedRows();
140 buchmann 1.5 if(verbose>0) dout << hname << " (" << informalname <<") " << maxEff << std::endl;
141 buchmann 1.1
142 buchmann 1.5 if(verbose>0) dout << "JZB max = " << jzbMax << std::endl;
143 buchmann 1.1 // Loop over steps to get efficiency curve
144     char cut[256];
145     for ( Int_t iBin = 0; iBin<nBins; ++iBin ) {
146 buchmann 1.6 sprintf(cut,"genJZB>%3f",jzbMin+iBin*step);
147 buchmann 1.2 events->Draw(mcjzbexpression.c_str(),TCut(cut)&&kbase,"goff");
148 buchmann 1.1 Float_t eff = static_cast<Float_t>(events->GetSelectedRows())/maxEff;
149 buchmann 1.5 // dout << "COUCOU " << __LINE__ << std::endl;
150 buchmann 1.1 hJzbEff->SetBinContent(iBin+1,eff);
151     hJzbEff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/maxEff));
152     }
153     return hJzbEff;
154    
155    
156     }
157    
158    
159     //________________________________________________________________________________________
160     // Pile-up efficiency
161 buchmann 1.8 float pileup(TTree *events, bool requireZ, string informalname, Float_t myJzbMax = 140. ) {
162 buchmann 1.1 nBins = 16;
163     jzbMax = myJzbMax;
164    
165     // Acceptance cuts
166 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
167 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
168 buchmann 1.1 TH1F* hLM4 = plotEff(events,kbase,informalname);
169     hLM4->SetMinimum(0.);
170    
171     // Nominal function
172     TF1* func = new TF1("func","0.5*TMath::Erfc([0]*x-[1])",jzbMin,jzbMax);
173     func->SetParameter(0,0.03);
174     func->SetParameter(1,0.);
175     hLM4->Fit(func,"Q");
176    
177     // Pimped-up function
178     TF1* funcUp = (TF1*)func->Clone();
179     funcUp->SetParameter( 0., func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
180 buchmann 1.5 if(!automatized) dout << " PU: " << funcUp->Eval(jzbSel) << " " << func->Eval(jzbSel)
181 buchmann 1.1 << "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl;
182    
183     return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100.;
184    
185     }
186    
187     //____________________________________________________________________________________
188 buchmann 1.6 // Effect of peak shifting
189     void PeakError(TTree *events,float &result, string mcjzb, float peakerr) {
190     TString peakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
191     TString peakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
192     TString peakcentral("("+TString(mcjzb)+")"+geq_or_leq()+TString(any2string(jzbSel)));
193     TString npeakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
194     TString npeakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
195     TString npeakcentral("("+TString(mcjzb)+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
196    
197     nBins = 1;
198     string informalname="PeakErrorCalculation";
199     float resup,resdown,rescent;
200     for(int i=0;i<3;i++) {
201     string poscut,negcut;
202     if(i==0) {
203     poscut=peakcentral;
204     negcut=npeakcentral;
205     } else if(i==1) {
206     poscut=peakdown;
207     negcut=npeakdown;
208     } else if(i==2) {
209     poscut=peakup;
210     negcut=npeakup;
211     }
212 buchmann 1.7 float res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str());
213     if(i==0) rescent=res;
214     else if(i==1) resdown=res;
215     else if(i==2) resup=res;
216 buchmann 1.6 }
217 buchmann 1.7 if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/rescent)*100;
218 buchmann 1.6 else result=(TMath::Abs(rescent-resdown)/rescent)*100;
219     }
220    
221     //____________________________________________________________________________________
222 buchmann 1.1 // Total selection efficiency (MC)
223 buchmann 1.8 void MCefficiency(TTree *events,float &result, float &resulterr,string mcjzb,bool requireZ) {
224 buchmann 1.1
225     char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
226     // All acceptance cuts at gen. level
227 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&genJZB"+geq_or_leq()+TString(jzbSelStr)+"&&genId1==-genId2");
228 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
229 buchmann 1.1 // Corresponding reco. cuts
230 buchmann 1.2 TCut ksel("abs(mll-91.2)<20&&id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
231 buchmann 1.1
232 buchmann 1.2 events->Draw(mcjzbexpression.c_str(),kbase&&ksel,"goff");
233 buchmann 1.1 Float_t sel = events->GetSelectedRows();
234 buchmann 1.2 events->Draw(mcjzbexpression.c_str(),kbase,"goff");
235 buchmann 1.1 Float_t tot = events->GetSelectedRows();
236    
237 buchmann 1.4 result=sel/tot;
238     resulterr=TMath::Sqrt(sel/tot*(1-sel/tot)/tot);
239 buchmann 1.5 if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << std::endl;
240 buchmann 1.1 }
241    
242 buchmann 1.8 void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, bool requireZ) {
243 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genNjets>2&&genZPt>0&&abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
244 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
245 buchmann 1.1 TH1F* hLM4 = plotEff(events,kbase,informalname);
246     Int_t bin = hLM4->FindBin(jzbSel); // To get the error
247 buchmann 1.8 jzbeff=Interpolate(jzbSel,hLM4);
248     jzbefferr=hLM4->GetBinError(bin);
249 buchmann 1.5 if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
250 buchmann 1.8 if(!automatized) dout << " " << jzbeff << "+-" << jzbefferr << std::endl;
251 buchmann 1.1 }
252    
253     //________________________________________________________________________
254     // Effect of energy scale on efficiency
255 buchmann 1.8 void JZBjetScale(TTree *events, float &jesdown, float &jesup, string informalname,bool requireZ,float syst=0.1, Float_t jzbSelection=-1, TString plotName = "" ) {
256 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genZPt>0");
257 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
258    
259 buchmann 1.1 TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
260     TCut nJets("pfJetGoodNum>2");
261     stringstream down,up;
262     down << "pfJetGoodNum"<<30*(1-syst)<<">=3";
263     up << "pfJetGoodNum"<<30*(1+syst)<<">=3";
264    
265     TCut nJetsP(up.str().c_str());
266     TCut nJetsM(down.str().c_str());
267    
268     if ( !(plotName.Length()>1) ) plotName = informalname;
269    
270     nBins = 1; jzbMin = jzbSel*0.95; jzbMax = jzbSel*1.05;
271     TH1F* hist = plotEff(events,(kbase&&ksel&&nJets),informalname);
272    
273     TH1F* histp = plotEff(events,(kbase&&ksel&&nJetsP),informalname);
274    
275     TH1F* histm = plotEff(events,(kbase&&ksel&&nJetsM),informalname);
276    
277     // Dump some information
278     Float_t eff = Interpolate(jzbSel,hist);
279     Float_t effp = Interpolate(jzbSel,histp);
280     Float_t effm = Interpolate(jzbSel,histm);
281 buchmann 1.5 if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
282     if(!automatized) dout << " JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
283     if(!automatized) dout << " central: " << eff << std::endl;
284     if(!automatized) dout << " JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
285 buchmann 1.1 jesup=(effp-eff)/eff*100.;
286     jesdown=(effm-eff)/eff*100.;
287     }
288    
289     //________________________________________________________________________
290     // Effect of energy scale on JZB efficiency
291 buchmann 1.8 void doJZBscale(TTree *events, float &down, float &up, float &syst, float systematic, string informalname, bool requireZ) {
292 buchmann 1.1
293 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
294 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
295 buchmann 1.1 TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
296    
297     nBins = 50;
298     jzbMin = 0.5*jzbSel;
299     jzbMax = 2.0*jzbSel;
300    
301     TH1F* hist = plotEff(events,kbase&&ksel,informalname);
302    
303     // Dump some information
304     Float_t eff = Interpolate(jzbSel,hist);
305     Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
306     Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
307 buchmann 1.5 if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<syst*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl;
308     if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl;
309     if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<syst*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl;
310 buchmann 1.1 up=((effp-eff)/eff)*100;
311     down=((effm-eff)/eff)*100;
312     }
313    
314     //________________________________________________________________________
315     // JZB response (true/reco. vs. true)
316 buchmann 1.8 void JZBresponse(TTree *events, bool requireZ, float &resp, float &resperr, bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
317 buchmann 1.1
318     jzbMin = 20;
319 buchmann 1.6 TCut kbase("abs(genMll-91.2)<20&&genZPt>0&&genNjets>2");
320 buchmann 1.8 if(requireZ) kbase=kbase&&"TMath::Abs(genMID)==23";
321 buchmann 1.1 TCut ksel("abs(mll-91.2)<20&&((id1+1)*(id2+1)*ch1*ch2)!=-2");
322    
323 buchmann 1.8 TProfile* hJzbResp = new TProfile("hJzbResp","JZB response ; JZB true (GeV/c); JZB reco. / JZB true", nPeriods, jzbMin, myJzbMax, "" );
324 buchmann 1.1
325 buchmann 1.6 if (!isMET) events->Project("hJzbResp","("+TString(mcjzbexpression)+")/genJZB:genJZB",kbase&&ksel);
326 buchmann 1.1 else events->Project("hJzbResp","met[4]/genMET:genMET",kbase&&ksel);
327    
328     hJzbResp->SetMaximum(1.2);
329     hJzbResp->SetMinimum(0.2);
330     hJzbResp->Fit("pol0","Q");
331     TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
332 buchmann 1.8 resp=fittedfunction->GetParameter(0);
333     resperr=fittedfunction->GetParError(0);
334     if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl;
335 buchmann 1.5 delete hJzbResp;
336 buchmann 1.1 }
337    
338    
339 buchmann 1.8 void do_systematics_for_one_file(TTree *events,string informalname, vector<vector<float> > &results,string mcjzb,string datajzb,float peakerror,bool requireZ=false) {
340 buchmann 1.1
341     float JetEnergyScaleUncert=0.1;
342     float JZBScaleUncert=0.1;
343 buchmann 1.2 mcjzbexpression=mcjzb;
344 buchmann 1.1
345     float triggereff=4;//percent!
346 buchmann 1.5 dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl;
347 buchmann 1.1 float leptonseleff=2;//percent!
348 buchmann 1.5 dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl;
349 buchmann 1.1
350 buchmann 1.8 float mceff,mcefferr,jzbeff,jzbefferr;
351 buchmann 1.5 if(!automatized) dout << "MC efficiencies:" << endl;
352 buchmann 1.8 MCefficiency(events,mceff,mcefferr,mcjzb,requireZ);
353     JZBefficiency(events,informalname,jzbeff,jzbefferr,requireZ);
354     if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
355 buchmann 1.1
356 buchmann 1.6 if(!automatized) dout << "Error from Peak position:" << endl;
357     float sysfrompeak=0;
358     PeakError(events,sysfrompeak,mcjzb,peakerror);
359    
360 buchmann 1.5 if(!automatized) dout << "Jet energy scale: " << std::endl;
361 buchmann 1.1 float jesup,jesdown;
362 buchmann 1.8 JZBjetScale(events,jesdown,jesup,informalname,JetEnergyScaleUncert,requireZ);
363 buchmann 1.1
364 buchmann 1.5 if(!automatized) dout << "JZB scale: " << std::endl;
365 buchmann 1.1 float scaleup,scaledown,scalesyst;
366 buchmann 1.8 doJZBscale(events,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,requireZ);
367 buchmann 1.1
368 buchmann 1.5 if(!automatized) dout << "JZB response: " << std::endl;
369 buchmann 1.8 float resp,resperr;
370     JZBresponse(events,requireZ,resp,resperr);
371 buchmann 1.1
372 buchmann 1.5 if(!automatized) dout << "Pileup: " << std::endl;
373 buchmann 1.8 float resolution=pileup(events,requireZ,informalname);
374 buchmann 1.1
375 buchmann 1.5 dout << "_______________________________________________" << endl;
376 buchmann 1.6 dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) " << endl;
377     dout << "MC efficiency: " << 100*mceff << "+/-" << 100*mcefferr << endl;
378 buchmann 1.5 dout << "Trigger efficiency: " << triggereff << endl;
379     dout << "Lepton Sel Eff: " << leptonseleff << endl;
380 buchmann 1.6 dout << "Jet energy scale: " << jesup << " " << jesdown << endl;
381     dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl;
382 buchmann 1.5 dout << "Resolution : " << resolution << endl;
383 buchmann 1.6 dout << "From peak : " << sysfrompeak << endl;
384 buchmann 1.8 dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl;
385     dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl;
386 buchmann 1.1
387 buchmann 1.4 float toterr=0;
388     toterr+=(triggereff/100)*(triggereff/100);
389     toterr+=(leptonseleff/100)*(leptonseleff/100);
390     if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup/100)*(jesup/100); else toterr+=(jesdown/100)*(jesdown/100);
391     if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup/100)*(scaleup/100); else toterr+=(scaledown/100)*(scaledown/100);
392     toterr+=(resolution/100)*(resolution/100);
393 buchmann 1.7 toterr+=(sysfrompeak/100)*(sysfrompeak/100);
394 buchmann 1.4 toterr=TMath::Sqrt(toterr);
395 buchmann 1.6 dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*toterr << " (syst) %" << endl;
396 buchmann 1.5 dout << " we thus use the sqrt of the sum of the squares which is : " << 100*TMath::Sqrt(mcefferr*mcefferr+(toterr*toterr)) << endl;
397 buchmann 1.4 vector<float> res;
398     res.push_back(jzbSel);
399     res.push_back(mceff);
400     res.push_back(mcefferr);
401     res.push_back(toterr);
402     res.push_back(TMath::Sqrt((mcefferr)*(mcefferr)+(toterr*toterr)));
403    
404     results.push_back(res);
405 buchmann 1.1 }
406    
407 buchmann 1.8 vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
408 buchmann 1.4 automatized=true;
409     vector< vector<float> > systematics;
410 buchmann 1.1 for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
411 buchmann 1.5 dout << "Looking at signal " << (signalsamples.collection)[isignal].filename << endl;
412 buchmann 1.1 for(int ibin=0;ibin<bins.size();ibin++) {
413     jzbSel=bins[ibin];
414 buchmann 1.2 geqleq="geq";
415 buchmann 1.8 do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,systematics,mcjzb,datajzb,mcpeakerror,requireZ);
416 buchmann 1.1 }//end of bin loop
417     }//end of signal loop
418 buchmann 1.4 return systematics;
419 buchmann 1.1 }