ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Systematics.C
Revision: 1.9
Committed: Wed Sep 19 09:16:24 2012 UTC (12 years, 7 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +1 -5 lines
Error occurred while calculating annotation data.
Log Message:
Updated window to 10 GeV around 91 GeV

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <assert.h>
4 #include <sys/stat.h>
5 #include <algorithm>
6 #include <cmath>
7
8 #include <TMath.h>
9 #include <TColor.h>
10 #include <TPaveText.h>
11 #include <TRandom.h>
12 #include <TF1.h>
13
14 #ifndef SampleClassLoaded
15 #include "SampleClass.C"
16 #endif
17
18 /*#ifndef CrossSectionReaderLoaded
19 #include "CrossSectionReader.C"
20 #endif*/
21
22 #ifndef Verbosity
23 #define Verbosity 0
24 #endif
25
26 #include <TFile.h>
27 #include <TTree.h>
28 #include <TH1.h>
29 #include <TCut.h>
30 #include <TMath.h>
31 #include <TLine.h>
32 #include <TCanvas.h>
33 #include <TProfile.h>
34 #include <TF1.h>
35
36
37
38 Int_t nBins = 100;
39 Float_t jzbMin = -207;
40 Float_t jzbMax = 243;
41 Float_t jzbSel = 100;
42 int iplot=0;
43 int verbose=0;
44 string geqleq;
45 string mcjzbexpression;
46 bool automatized=false;//if we're running this fully automatized we don't want each function to flood the screen
47
48 TString geq_or_leq() {
49 if(geqleq=="geq") return TString(">=");
50 if(geqleq=="leq") return TString("<=");
51 return TString("GEQ_OR_LEQ_ERROR");
52 }
53
54 TString ngeq_or_leq() {
55 if(geqleq=="geq") return TString("<=");
56 if(geqleq=="leq") return TString(">=");
57 return TString("NGEQ_OR_LEQ_ERROR");
58 }
59
60 //______________________________________________________________________________
61 Double_t Interpolate(Double_t x, TH1 *histo)
62 {
63 // Given a point x, approximates the value via linear interpolation
64 // based on the two nearest bin centers
65 // Andy Mastbaum 10/21/08
66 // in newer ROOT versions but not in the one I have so I had to work around that ...
67
68 Int_t xbin = histo->FindBin(x);
69 Double_t x0,x1,y0,y1;
70
71 if(x<=histo->GetBinCenter(1)) {
72 return histo->GetBinContent(1);
73 } else if(x>=histo->GetBinCenter(histo->GetNbinsX())) {
74 return histo->GetBinContent(histo->GetNbinsX());
75 } else {
76 if(x<=histo->GetBinCenter(xbin)) {
77 y0 = histo->GetBinContent(xbin-1);
78 x0 = histo->GetBinCenter(xbin-1);
79 y1 = histo->GetBinContent(xbin);
80 x1 = histo->GetBinCenter(xbin);
81 } else {
82 y0 = histo->GetBinContent(xbin);
83 x0 = histo->GetBinCenter(xbin);
84 y1 = histo->GetBinContent(xbin+1);
85 x1 = histo->GetBinCenter(xbin+1);
86 }
87 return y0 + (x-x0)*((y1-y0)/(x1-x0));
88 }
89 }
90
91 //____________________________________________________________________________________
92 // Plotting with all contributions, i.e. sidebands, peak, osof,ossf ... (for a systematic)
93 float allcontributionsplot(TTree* events, TCut kBaseCut, TCut kMassCut, TCut kSidebandCut, TCut JZBPosCut, TCut JZBNegCut, int flipped) {
94 iplot++;
95 string locmcjzbexpression=mcjzbexpression;
96 // Define new histogram
97 string hname=GetNumericHistoName();
98 TH1F* hossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
99 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSSF,"goff");
100 hname=GetNumericHistoName();
101 TH1F* hossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
102 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSSF,"goff");
103
104 hname=GetNumericHistoName();
105 TH1F* hosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
106 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBPosCut&&cutOSOF,"goff");
107 hname=GetNumericHistoName();
108 TH1F* hosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
109 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kMassCut&&JZBNegCut&&cutOSOF,"goff");
110
111 float obs=0;
112 float pred=0;
113 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
114 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
115 hname=GetNumericHistoName();
116 TH1F* sbhossfp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
117 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSSF,"goff");
118 hname=GetNumericHistoName();
119 TH1F* sbhossfn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
120 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSSF,"goff");
121
122 hname=GetNumericHistoName();
123 TH1F* sbhosofp = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
124 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBPosCut&&cutOSOF,"goff");
125 hname=GetNumericHistoName();
126 TH1F* sbhosofn = new TH1F(hname.c_str(),hname.c_str(),1,-14000,14000);
127 events->Draw("("+TString(locmcjzbexpression)+")>>"+TString(hname),kBaseCut&&kSidebandCut&&JZBNegCut&&cutOSOF,"goff");
128
129 obs = hossfp->Integral();
130 pred= hossfn->Integral() + (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
131
132 if(flipped>0) {
133 obs = hossfn->Integral();
134 pred= hossfp->Integral() - (1.0/3)*( hosofp->Integral() - hosofn->Integral() + sbhossfp->Integral() - sbhossfn->Integral() + sbhosofp->Integral() - sbhosofn->Integral());
135 }
136 delete sbhossfp;
137 delete sbhossfn;
138 delete sbhosofp;
139 delete sbhosofn;
140 } else {
141 obs = hossfp->Integral();
142 pred= hossfn->Integral() + (hosofp->Integral() - hosofn->Integral());
143 if(flipped>0) {
144 obs = hossfn->Integral();
145 pred= hossfp->Integral() - (hosofp->Integral() - hosofn->Integral());;
146 }
147 }
148
149 delete hossfp;
150 delete hossfn;
151 delete hosofp;
152 delete hosofn;
153
154 return obs-pred;
155 }
156
157
158 //____________________________________________________________________________________
159 // Efficiency plot
160 TH1F* plotEff(TTree* events, TCut kbase, TString informalname, int flipped) {
161 iplot++;
162 int count=iplot;
163 iplot++;
164 int count2=iplot;
165 // Define new histogram
166 char hname[30]; sprintf(hname,"hJzbEff%d",count);
167 char hname2[30]; sprintf(hname2,"hJzbEff%d",count2);
168 TH1F* hJzbEff = new TH1F(hname,"JZB selection efficiency ; JZB [GeV]; Efficiency",nBins,jzbMin,jzbMax);
169 TH1F* hJzbEff2= new TH1F(hname2,"JZB selection efficiency ; JZB [GeV]; Efficiency",1,-14000,14000);
170 Float_t step = (jzbMax-jzbMin)/static_cast<Float_t>(nBins);
171
172 if(flipped==0) events->Draw((mcjzbexpression+">>"+(string)hname2).c_str(),("genJZB>-400"&&kbase),"goff");
173 else events->Draw(("(-"+mcjzbexpression+")>>"+(string)hname2).c_str(),("genJZB>-400"&&kbase),"goff");
174 Float_t maxEff = hJzbEff2->Integral();
175 if(verbose>0) dout << hname << " (" << informalname <<") " << maxEff << std::endl;
176
177 if(verbose>0) dout << "JZB max = " << jzbMax << std::endl;
178 // Loop over steps to get efficiency curve
179 char cut[256];
180 for ( Int_t iBin = 0; iBin<nBins; ++iBin ) {
181 sprintf(cut,"genJZB>%3f",jzbMin+iBin*step);
182 if(flipped==0) events->Draw((mcjzbexpression+">>"+(string)hname2).c_str(),(TCut(cut)&&kbase),"goff");
183 if(flipped>0) events->Draw(("(-"+mcjzbexpression+")>>"+(string)hname2).c_str(),(TCut(cut)&&kbase),"goff");
184 Float_t eff = static_cast<Float_t>(hJzbEff2->Integral())/maxEff;
185 hJzbEff->SetBinContent(iBin+1,eff);
186 hJzbEff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/maxEff));
187 }
188 delete hJzbEff2;
189 return hJzbEff;
190 }
191
192
193
194 //________________________________________________________________________________________
195 // Master Formula
196 void master_formula(std::vector<float> eff, float &errHi, float &errLo) {
197
198 float x0 = eff[0];
199 float deltaPos = 0, deltaNeg = 0;
200 for(int k = 0; k < ((int)eff.size()-1)/2; k++) {
201 float xneg = eff[2*k+2];
202 float xpos = eff[2*k+1];
203 if(xpos-x0>0 || xneg-x0>0) {
204 if(xpos-x0 > xneg-x0) {
205 deltaPos += (xpos-x0)*(xpos-x0);
206 } else {
207 deltaPos += (xneg-x0)*(xneg-x0);
208 }
209 }
210 if(x0-xpos>0 || x0-xneg>0) {
211 if(x0-xpos > x0-xneg) {
212 deltaNeg += (xpos-x0)*(xpos-x0);
213 } else {
214 deltaNeg += (xneg-x0)*(xneg-x0);
215 }
216 }
217 }
218 errHi = sqrt(deltaPos);
219 errLo = sqrt(deltaNeg);
220
221 }
222
223
224 //________________________________________________________________________________________
225 // Get normalization factor for the PDFs
226 float get_norm_pdf_factor(TTree *events, int k, string addcut) {
227
228 TH1F *haux = new TH1F("haux", "", 10000, 0, 5);
229 char nameVar[20];
230 sprintf(nameVar, "pdfW[%d]", k);
231 events->Project("haux", nameVar, addcut.c_str());
232 float thisW = haux->Integral();
233 events->Project("haux", "pdfW[0]");
234 float normW = haux->Integral();
235
236 float factor=thisW/normW;
237
238 delete haux;
239
240 return factor;
241
242 }
243
244
245
246 //________________________________________________________________________________________
247 // Pile-up efficiency
248 float pileup(TTree *events, bool requireZ, string informalname, int flipped, string addcut="",Float_t myJzbMax = 140. ) {
249 nBins = 16;
250 jzbMax = myJzbMax;
251
252 // Acceptance cuts
253 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
254 TCut kbase(PlottingSetup::genMassCut&&"genNjets>2&&genZPt>0"&&cutmass&&cutOSSF);
255 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
256
257 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
258 TH1F* hLM4 = plotEff(events,kbase,informalname,flipped);
259 hLM4->SetMinimum(0.);
260
261 // Nominal function
262 TF1* func = new TF1("func","0.5*TMath::Erfc([0]*x-[1])",jzbMin,jzbMax);
263 func->SetParameter(0,0.03);
264 func->SetParameter(1,0.);
265 hLM4->Fit(func,"Q");
266
267 // Pimped-up function
268 TF1* funcUp = (TF1*)func->Clone();
269 funcUp->SetParameter( 0, func->GetParameter(0)/1.1); // 10% systematic error (up in sigma => 0.1 in erfc)
270 if(!automatized) dout << " PU: " << funcUp->Eval(jzbSel) << " " << func->Eval(jzbSel)
271 << "(" << (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel)*100. << "%)" << std::endl;
272
273 return (funcUp->Eval(jzbSel)-func->Eval(jzbSel))/func->Eval(jzbSel);
274
275 }
276
277 //____________________________________________________________________________________
278 // Effect of peak shifting
279 void PeakError(TTree *events,float &result, string mcjzb, float peakerr,int flipped,string addcut="") {
280 //Note: the cut used here is something like (JZBEXPRESSION+(peakerr)>50) without all the other cuts, to increase statistics (particularly for scans)
281 TString peakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
282 TString peakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+geq_or_leq()+TString(any2string(jzbSel)));
283 TString peakcentral("("+TString(mcjzb)+")"+geq_or_leq()+TString(any2string(jzbSel)));
284 TString npeakup("("+TString(mcjzb)+"+"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
285 TString npeakdown("("+TString(mcjzb)+"-"+TString(any2string(TMath::Abs(peakerr)))+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
286 TString npeakcentral("("+TString(mcjzb)+")"+ngeq_or_leq()+"-"+TString(any2string(jzbSel)));
287 nBins = 1;
288 string informalname="PeakErrorCalculation";
289 float resup,resdown,rescent;
290 for(int i=0;i<3;i++) {
291 string poscut,negcut;
292 if(i==0) {
293 poscut=peakcentral;
294 negcut=npeakcentral;
295 } else if(i==1) {
296 poscut=peakdown;
297 negcut=npeakdown;
298 } else if(i==2) {
299 poscut=peakup;
300 negcut=npeakup;
301 }
302 float res;
303 if(addcut=="") res=allcontributionsplot(events,cutnJets,cutmass,sidebandcut,poscut.c_str(),negcut.c_str(),flipped);
304 else res=allcontributionsplot(events,cutnJets&&addcut.c_str(),cutmass,sidebandcut,poscut.c_str(),negcut.c_str(),flipped);
305 if(i==0) rescent=res;
306 else if(i==1) resdown=res;
307 else if(i==2) resup=res;
308 }
309 if(TMath::Abs(rescent-resup)>TMath::Abs(rescent-resdown)) result=(TMath::Abs(rescent-resup)/(float)rescent);
310 else result=(TMath::Abs(rescent-resdown)/(float)rescent);
311 if(!automatized) cout << " " << result << endl;
312 // if(rescent==0) result=0;
313 }
314
315
316 void MCPartialefficiency(TTree *events,float &result, float &resulterr,int flipped, string mcjzb,bool requireZ,int Neventsinfile, string addcut="", int k = 0, int type = 0) {
317 if(!events) {
318 write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
319 result=0;resulterr=0;
320 return;
321 }
322
323 char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
324 char metSel[256]; sprintf(metSel, "met[4] > %f", jzbSel);
325 string metSelection(metSel);
326 TCut kbase("");
327 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
328 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
329 // Corresponding reco. cuts
330
331 TCut acceptance("genPt2 != 0");
332 TCut massId(cutmass&&cutOSSF);
333 TCut njets(cutnJets);
334 TCut jzbp;
335 TCut jzbn;
336 TCut met(("pfJetGoodNum > 1 && abs(mll-91) < 10.0 && id1 == id2 &&" + metSelection).c_str());
337 if(flipped==0) {
338 jzbp=TCut((TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
339 jzbn=TCut((TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
340 } else {
341 jzbp=TCut(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
342 jzbn=TCut(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
343 }
344 float ntotal = events->Draw("pt1", addcut.c_str(), "goff");
345 TCut theCut;
346 switch(type) {
347 case 1:
348 theCut = kbase+acceptance;
349 break;
350 case 2:
351 theCut = kbase+massId;
352 break;
353 case 3:
354 theCut = kbase+massId+njets;
355 break;
356 case 4:
357 theCut = kbase+massId+njets+jzbn;
358 break;
359 case 5:
360 theCut = kbase + met;
361 break;
362 default:
363 theCut = kbase+massId+njets+jzbn;
364 break;
365 }
366
367 string stheCut(theCut);
368 char var[20];
369 sprintf(var, "pdfW[%d]", k);
370
371 string svar(var);
372 string newtheCut;
373 if(k>0) newtheCut = "(" + stheCut + ")*" + svar;
374 else newtheCut = "(" + stheCut + ")"; // for k==0 or even k==-1 we don't need to evaluate PDFs
375
376 TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
377 if(k>=0) events->Draw((mcjzbexpression+">>effh").c_str(), newtheCut.c_str(),"goff");
378 else events->Draw((mcjzbexpression+">>effh").c_str(), theCut,"goff");
379 Float_t sel = effh->Integral();
380 //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.
381 float normFactor = 1;
382 if(k>=0) get_norm_pdf_factor(events, k, addcut);
383 sel = sel/normFactor;
384
385 result=(sel)/ntotal;
386 resulterr=TMath::Sqrt(sel/ntotal*(1+sel/ntotal)/ntotal);
387
388 delete effh;
389 }
390
391
392
393 float XSForProcessViaAddCutWrapper(string addcut, map < pair<float, float>, map<string, float> > xsec, int i) {
394 int position = addcut.find("Abs(M0-");
395 string M0string=addcut.substr(position+7,4);
396 position=M0string.find(")");
397 if(position>0&&position<5) M0string=M0string.substr(0,position);
398 position = addcut.find("Abs(M12-");
399 string M12string=addcut.substr(position+8,4);
400 position=M0string.find(")");
401 if(position>0&&position<5) M12string=M12string.substr(0,position);
402 float m0=atof(M0string.c_str());
403 float m12=atof(M12string.c_str());
404 return GetXSecForPointAndChannel(m0,m12,xsec,i);
405 }
406
407 float sum(vector<float> v) {
408 float sum=0;
409 for(int i=0;i<(int)v.size();i++) sum+=v[i];
410 return sum;
411 }
412 Value mSUGRAefficiency(TTree *events,float &result, float &resulterr, int flipped, string mcjzb,bool requireZ,int Neventsinfile, int scantype, map < pair<float, float>, map<string, float> > xsec, string addcut="", int kwrong = -2) {
413 if(kwrong>0) {
414 write_error(__FUNCTION__,"Watch out, evaluation of PDF uncerts is done differently now .... asserting this and exiting, so long!");
415 assert(kwrong<=0);
416 }
417
418 if(!events) {
419 write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
420 result=0;
421 resulterr=0;
422 return Value(0,0);
423 }
424 char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
425 // All acceptance cuts at gen. level
426 TCut kbase(basiccut&&leptoncut);
427
428 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
429 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
430 TCut ksel;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
431
432 TCut ksel2;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
433 if(PlottingSetup::RestrictToMassPeak||!ConsiderSignalContaminationForLimits) {
434 ksel=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
435 ksel2=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
436 if(flipped>0) {
437 ksel=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
438 ksel2=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
439 }
440 }else {
441 //for off peak analysis we don't use the OSSF condition here yet so we can recycle these two cuts for the em condition!
442 ksel=TCut(cutnJets&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
443 ksel2=TCut(cutnJets&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
444 if(flipped>0) {
445 ksel=TCut(cutnJets&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
446 ksel2=TCut(cutnJets&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
447 }
448 }
449
450 TCut posSide = kbase&&ksel;
451 TCut negSide = kbase&&ksel2;
452 string sposSide(posSide);
453 string snegSide(negSide);
454 string newPosSide = "((id1==id2)&&(" + sposSide + "))";
455 string newNegSide = "((id1==id2)&&(" + snegSide + "))";
456 string emnewPosSide = "((id1!=id2)&&(" + sposSide + "))"; // only used for off peak analysis
457 string emnewNegSide = "((id1!=id2)&&(" + snegSide + "))"; // only used for off peak analysis
458
459 TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
460 vector<float> sel;
461 vector<float> nsel;
462 vector<float> Nproc;
463
464 for(int i=0;i<11;i++) {
465 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(((string)sposSide+"&&(id1==id2)&&process=="+any2string(i)).c_str()))*cutWeight,"goff");//the OSSF condition is added for the offpeak analysis, in onpeak case it's there already but doesn't change anything.
466 sel.push_back(effh->Integral());
467 events->Draw(("id1>>effh"), (addcut+"&&process=="+any2string(i)).c_str(),"goff");
468 Nproc.push_back(effh->Integral());
469 }
470
471
472 ///----------------------------------------------- THIS PART REQUIRES STUDYING! -------------------------
473
474 if(ConsiderSignalContaminationForLimits) {
475 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
476 if(PlottingSetup::RestrictToMassPeak) {
477 for(int i=0;i<11;i++) {
478 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut((newNegSide+"&&process=="+any2string(i)).c_str()))*cutWeight,"goff");
479 nsel.push_back(effh->Integral());
480 }
481 } else {
482 for(int i=0;i<11;i++) {
483 float nselproc=0;
484 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut((newNegSide+"&&process=="+any2string(i)).c_str()))*cutWeight,"goff");
485 nselproc += effh->Integral();
486 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut((emnewPosSide+"&&process=="+any2string(i)).c_str()))*cutWeight,"goff");
487 nselproc += effh->Integral();
488 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut((emnewNegSide+"&&process=="+any2string(i)).c_str()))*cutWeight,"goff");
489 nselproc -= effh->Integral();
490 nsel.push_back(nselproc);
491 }
492 }
493 }
494
495 Value result_wo_signalcont;
496
497 float resultwosigcont;
498 float resultwosigconterr;
499 if(ConsiderSignalContaminationForLimits) {
500 result=0;
501 resulterr=0;
502 float totalXS=0;
503 resultwosigcont=0;
504 resultwosigconterr=0;
505 for(int i=0;i<11;i++) {
506 float xsi=XSForProcessViaAddCutWrapper(addcut,xsec,i);
507 if(Nproc[i]<1) continue;
508 result+=((sel[i]-nsel[i])/Nproc[i])*xsi;
509 totalXS+=xsi;
510 resulterr+=xsi*(sel[i]+nsel[i]+(sel[i]-nsel[i])*(sel[i]-nsel[i])/Nproc[i])/(Nproc[i]*Nproc[i]);
511 resultwosigcont+=(sel[i]/Nproc[i])*xsi;
512 resultwosigconterr+=xsi*(sel[i]+(sel[i]*sel[i])/Nproc[i])/(Nproc[i]*Nproc[i]);
513 }
514 result=result/totalXS;
515 resulterr=TMath::Sqrt((1/totalXS)*resulterr);
516 resultwosigcont=resultwosigcont/totalXS;
517 resultwosigconterr=TMath::Sqrt((1/totalXS)*resultwosigconterr);
518 result_wo_signalcont=Value(resultwosigcont,resultwosigconterr);
519 } else {//no signal contamination considered:
520 result=0;
521 resulterr=0;
522 float totalXS=0;
523 for(int i=0;i<11;i++) {
524 float xsi=XSForProcessViaAddCutWrapper(addcut,xsec,i);
525 result+=((sel[i])/Nproc[i])*xsi;
526 totalXS+=xsi;
527 resulterr+=xsi*(sel[i]+(sel[i]*sel[i])/Nproc[i])/(Nproc[i]*Nproc[i]);
528 }
529 result=result/totalXS;
530 resulterr=TMath::Sqrt((1/totalXS)*resulterr);
531 result_wo_signalcont=Value(result,resulterr);
532 }
533
534
535 if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sum(sel) << " , signal contamination : " << sum(nsel) << " and nevents=" << sum(Nproc) << ") " << std::endl;
536 delete effh;
537 return result_wo_signalcont;
538
539 }
540
541
542 //____________________________________________________________________________________
543 // Total selection efficiency (MC)
544 //returns the efficiency WITHOUT signal contamination, and the result and resulterr contain the result and the corresponding error
545 Value MCefficiency(TTree *events,float &result, float &resulterr, int flipped, string mcjzb,bool requireZ,int Neventsinfile, int scantype, map < pair<float, float>, map<string, float> > xsec, string addcut="", int k = 0) {
546 if(scantype==mSUGRA) {
547 write_warning(__FUNCTION__,"Need to check the efficiency algorithm for mSUGRA!");
548 //return mSUGRAefficiency(events,result,resulterr,flipped,mcjzb,requireZ,Neventsinfile,scantype,xsec,addcut,k);
549 }
550 if(!events) {
551 write_error(__FUNCTION__,"Tree passed for efficiency calculation is invalid!");
552 result=0;
553 resulterr=0;
554 return Value(0,0);
555 }
556
557 char jzbSelStr[256]; sprintf(jzbSelStr,"%f",jzbSel);
558 // All acceptance cuts at gen. level
559 TCut kbase(basiccut&&leptoncut);
560
561 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
562 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
563 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
564 // Corresponding reco. cuts
565 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
566 TCut ksel;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
567 TCut ksel2;//("pfJetGoodNum>2"&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
568 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
569 if(PlottingSetup::RestrictToMassPeak||!ConsiderSignalContaminationForLimits) {
570 ksel=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
571 ksel2=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
572 if(flipped>0) {
573 ksel=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr));
574 ksel2=TCut(cutnJets&&cutmass&&"id1==id2&&"+TString(mcjzb)+geq_or_leq()+TString(jzbSelStr));
575 }
576 } else {
577 //for off peak analysis we don't use the OSSF condition here yet so we can recycle these two cuts for the em condition!
578 ksel=TCut(cutnJets&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
579 ksel2=TCut(cutnJets&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
580 if(flipped>0) {
581 ksel=TCut(cutnJets&&cutmass&&(TString(mcjzb)+ngeq_or_leq()+TString("-")+TString(jzbSelStr)));
582 ksel2=TCut(cutnJets&&cutmass&&(TString(mcjzb)+geq_or_leq()+TString(jzbSelStr)));
583 }
584 }
585
586 TCut posSide = kbase&&ksel;
587 TCut negSide = kbase&&ksel2;
588 string sposSide(posSide);
589 string snegSide(negSide);
590 char var[20];
591 sprintf(var, "pdfW[%d]", k);
592 if(k==-1) sprintf(var,"1.0");//case in which we don't want to evaluate PDFs
593 string svar(var);
594 string newPosSide = "((id1==id2)&&(" + sposSide + "))*" + svar;
595 string newNegSide = "((id1==id2)&&(" + snegSide + "))*" + svar;
596 string emnewPosSide = "((id1!=id2)&&(" + sposSide + "))*" + svar; // only used for off peak analysis
597 string emnewNegSide = "((id1!=id2)&&(" + snegSide + "))*" + svar; // only used for off peak analysis
598
599 TH1F *effh= new TH1F("effh","effh",1,-14000,14000);
600
601 events->Draw(("1>>effh"), cutWeight,"goff");
602 float averageweight=effh->Integral()/effh->GetEntries();
603 if(averageweight<=0) averageweight=1;
604 if(k>=0)events->Draw((mcjzbexpression+">>effh").c_str(), TCut(newPosSide.c_str())*cutWeight*((string)"(1.0/"+any2string(averageweight)+")").c_str(),"goff");
605 else events->Draw((mcjzbexpression+">>effh").c_str(), TCut((sposSide+"&&(id1==id2)").c_str())*cutWeight*((string)"(1.0/"+any2string(averageweight)+")").c_str(),"goff");//the OSSF condition is added for the offpeak analysis, in onpeak case it's there already but doesn't change anything.
606 Float_t sel = effh->Integral();
607 Float_t nsel=0;
608
609 ///----------------------------------------------- THIS PART REQUIRES STUDYING! -------------------------
610
611 if(ConsiderSignalContaminationForLimits) {
612 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
613 if(PlottingSetup::RestrictToMassPeak) {
614 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(newNegSide.c_str()))*cutWeight,"goff");
615 nsel += effh->Integral();
616 cout << __FUNCTION__ << " :: Drawn with " << (TCut(newNegSide.c_str()))*cutWeight << endl;
617 } else {
618 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(newNegSide.c_str()))*cutWeight,"goff");
619
620 nsel += effh->Integral();
621 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(emnewPosSide.c_str()))*cutWeight,"goff");
622 nsel += effh->Integral();
623 events->Draw((mcjzbexpression+">>effh").c_str(), (TCut(emnewNegSide.c_str()))*cutWeight,"goff");
624 nsel -= effh->Integral();
625 }
626 }
627
628 //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.
629 float normFactor = 1;
630 if(k>=0) get_norm_pdf_factor(events, k, addcut);
631 sel = sel/normFactor;
632 nsel = nsel/normFactor;
633
634 Float_t tot = Neventsinfile;
635
636 Value result_wo_signalcont;
637
638 if(ConsiderSignalContaminationForLimits) {
639 result=(sel-nsel)/tot;
640 resulterr=(1.0/tot)*TMath::Sqrt(sel+nsel+(sel-nsel)*(sel-nsel)/tot);
641 result_wo_signalcont=Value(sel/tot,TMath::Sqrt(sel/tot*(1+sel/tot)/tot));
642 } else {//no signal contamination considered:
643 result=(sel)/tot;
644 resulterr=TMath::Sqrt(sel/tot*(1+sel/tot)/tot);
645 result_wo_signalcont=Value(result,resulterr);
646 }
647 if(!automatized && k>0 ) dout << "PDF assessment [" << k << "] : ";
648 if(!automatized) dout << " MC efficiency: " << result << "+-" << resulterr << " ( JZB>" << jzbSel << " : " << sel << " , signal contamination : " << nsel << " raw MC events out of " << tot << ") raw MC events with PDF normalization factor " << normFactor << std::endl;
649 delete effh;
650 return result_wo_signalcont;
651 }
652
653
654
655 //____________________________________________________________________________________
656 // Selection efficiency for one process (MC)
657 // not in use anymore.
658 /*
659 vector<float> processMCefficiency(TTree *events,int flipped, string mcjzb,bool requireZ,int Neventsinfile, string addcut) {
660 vector<float> process_efficiencies;
661 for(int iprocess=0;iprocess<=10;iprocess++) {
662 float this_process_efficiency,efferr;
663 stringstream addcutplus;
664 addcutplus<<addcut<<"&&(process=="<<iprocess<<")";
665 MCefficiency(events,this_process_efficiency, efferr,flipped,mcjzb,requireZ,Neventsinfile, addcutplus.str(),-1);
666 process_efficiencies.push_back(this_process_efficiency);
667 }
668 return process_efficiencies;
669 }
670 */
671
672 void JZBefficiency(TTree *events, string informalname, float &jzbeff, float &jzbefferr, int flipped, bool requireZ, string addcut="") {
673 TCut kbase(genMassCut&&"genNjets>2&&genZPt>0"&&cutmass&&cutOSSF);
674 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
675 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
676 TH1F* hLM4 = plotEff(events,kbase,informalname,flipped);
677 Int_t bin = hLM4->FindBin(jzbSel); // To get the error
678 jzbeff=Interpolate(jzbSel,hLM4);
679 jzbefferr=hLM4->GetBinError(bin);
680 if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
681 if(!automatized) dout << " " << jzbeff << "+-" << jzbefferr << std::endl;
682 }
683
684 //________________________________________________________________________
685 // Effect of energy scale on efficiency
686 void JZBjetScale(TTree *events, bool domSUGRA, map < pair<float, float>, map<string, float> > xsec, float &jesdown, float &jesup, string informalname, int flipped, bool requireZ,string addcut="",Float_t jzbSelection=-1, TString plotName = "" ) {
687 TCut kbase(genMassCut&&"genZPt>0");
688 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
689 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
690 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
691
692 TCut ksel(cutmass&&cutOSSF);
693
694 if ( !(plotName.Length()>1) ) plotName = informalname;
695
696 TCut susyweight("1.0");
697 if(domSUGRA) {
698 stringstream susyweightS;
699 float sumweights=0;
700 susyweightS << "((";
701 for(int i=0;i<11;i++) {
702 if(i==0) susyweightS << "(";
703 if(i>0) susyweightS << " + ";
704 susyweightS << "(process==" << i << ")*";
705 float thisxsec=XSForProcessViaAddCutWrapper(addcut,xsec,i);
706 susyweightS << thisxsec;
707 sumweights+=thisxsec;
708 if(i==10) susyweightS << ")";
709 }
710 susyweightS << ")/" << sumweights << ")";
711 susyweight=TCut(susyweightS.str().c_str());
712 }
713
714 nBins = 1; jzbMin = jzbSel*0.95; jzbMax = jzbSel*1.05;
715 TH1F* hist = plotEff(events,((kbase&&ksel&&cutnJets)*susyweight),informalname,flipped);
716 TH1F* histp = plotEff(events,((kbase&&ksel&&cutnJetsJESup)*susyweight),informalname,flipped);
717 TH1F* histm = plotEff(events,((kbase&&ksel&&cutnJetsJESdown)*susyweight),informalname,flipped);
718
719 // Dump some information
720 Float_t eff = Interpolate(jzbSel,hist);
721 Float_t effp = Interpolate(jzbSel,histp);
722 Float_t effm = Interpolate(jzbSel,histm);
723 if(!automatized) dout << " Efficiency at JZB==" << jzbSel << std::endl;
724 if(!automatized) dout << " JESup: " << effp << " (" << (effp-eff)/eff*100. << "%)" << std::endl;
725 if(!automatized) dout << " central: " << eff << std::endl;
726 if(!automatized) dout << " JESdown: " << effm << " (" << (effm-eff)/eff*100. << "%)" << std::endl;
727 jesup=(effp-eff)/eff;
728 jesdown=(effm-eff)/eff;
729 if(eff==0) {
730 jesup=1;
731 jesdown=1;
732 }
733 }
734
735 //________________________________________________________________________
736 // Effect of energy scale on JZB efficiency
737 void doJZBscale(TTree *events, bool domSUGRA, map < pair<float, float>, map<string, float> > xsec, float &down, float &up, float &syst, float systematic, string informalname, int flipped, bool requireZ, string addcut) {
738
739 TCut kbase(genMassCut&&"genZPt>0&&genNjets>2");
740 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
741 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
742 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
743 TCut ksel(cutmass&&cutOSSF);
744
745 nBins = 50;
746 jzbMin = 0.5*jzbSel;
747 jzbMax = 2.0*jzbSel;
748
749 TCut susyweight("1.0");
750 if(domSUGRA) {
751 stringstream susyweightS;
752 float sumweights=0;
753 susyweightS << "((";
754 for(int i=0;i<11;i++) {
755 if(i==0) susyweightS << "(";
756 if(i>0) susyweightS << " + ";
757 susyweightS << "(process==" << i << ")*";
758 float thisxsec=XSForProcessViaAddCutWrapper(addcut,xsec,i);
759 susyweightS << thisxsec;
760 sumweights+=thisxsec;
761 if(i==10) susyweightS << ")";
762 }
763 susyweightS << ")/" << sumweights << ")";
764 susyweight=TCut(susyweightS.str().c_str());
765 }
766
767
768
769 TH1F* hist = plotEff(events,((kbase&&ksel)*susyweight),informalname,flipped);
770
771 // Dump some information
772 Float_t eff = Interpolate(jzbSel,hist);
773 Float_t effp = Interpolate(jzbSel*(1.+systematic),hist);
774 Float_t effm = Interpolate(jzbSel*(1.-systematic),hist);
775 if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.+systematic) << "(-"<<systematic*100<<"%) : " << effp << " (" << ((effp-eff)/eff)*100. << "%)" << std::endl;
776 if(!automatized) dout << " efficiency at JZB==" << jzbSel << ": " << eff << std::endl;
777 if(!automatized) dout << " efficiency at JZB==" << jzbSel*(1.-systematic) << "(-"<<systematic*100<<"%) : " << effm << " (" << ((effm-eff)/eff)*100. << "%)" << std::endl;
778 up=((effp-eff)/eff);
779 down=((effm-eff)/eff);
780 if(eff==0) {
781 up=1;
782 down=1;
783 }
784 }
785
786 //________________________________________________________________________
787 // JZB response (true/reco. vs. true)
788 void JZBresponse(TTree *events, string name, bool requireZ, float &resp, float &resperr, int flipped, string addcut="", bool isMET = kFALSE, Float_t myJzbMax = 200., Int_t nPeriods = 9 ) {
789
790 jzbMin = 20;
791 flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
792 TCut kbase(genMassCut&&"genZPt>0&&genNjets>2");
793 if(addcut!="") kbase=kbase&&addcut.c_str();//this is mostly for SUSY scans (adding requirements on masses)
794 flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
795 if(requireZ&&PlottingSetup::RestrictToMassPeak) kbase=kbase&&"TMath::Abs(genMID)==23";
796 flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
797 TCut ksel(cutmass&&cutOSSF);
798
799 TProfile* hJzbResp = new TProfile("hJzbResp","JZB response ; JZB true (GeV/c); JZB reco. / JZB true", nPeriods, jzbMin, myJzbMax, "" );
800
801 string locmcjzbexpression=mcjzbexpression;
802 if(flipped>0) locmcjzbexpression="-"+locmcjzbexpression;
803 string possibleminus="";
804 if(flipped>0) possibleminus="-";
805 if (!isMET) events->Project("hJzbResp","("+TString(locmcjzbexpression)+")/("+possibleminus+"genJZB):("+possibleminus+"genJZB)",kbase&&ksel);
806 else events->Project("hJzbResp","met[4]/genMET:genMET",kbase&&ksel);
807
808 hJzbResp->SetMaximum(1.2);
809 hJzbResp->SetMinimum(0.2);
810 hJzbResp->Fit("pol0","Q");
811 TF1 *fittedfunction = hJzbResp->GetFunction("pol0");
812 if(!fittedfunction) {
813 // in case there are not enough points passing our selection
814 cout << "OOPS response function invalid, assuming 100% error !!!!" << endl;
815 resp=1;
816 resperr=1;
817 } else {
818 resp=fittedfunction->GetParameter(0);
819 resperr=fittedfunction->GetParError(0);
820 if(!automatized) dout << " Response: " << resp << " +/- " << resperr << endl;
821 }
822 delete hJzbResp;
823 }
824
825
826 //________________________________________________________________________________________
827 // PDF uncertainty
828 float get_pdf_uncertainty(TTree *events, int flipped, string mcjzb, bool requireZ, int Neventsinfile, int scantype, map < pair<float, float>, map<string, float> > xsec, int NPdfs, string addcut="") {
829 std::vector<float> efficiency;
830 for(int k = 1; k < NPdfs; k++) {
831 float result, resulterr;
832 Value flipval;
833 MCefficiency(events, result, resulterr, flipped, mcjzb, requireZ, Neventsinfile, scantype, xsec, addcut, k);
834 efficiency.push_back(result);
835 }
836 float errHi, errLow,err;
837 master_formula(efficiency, errHi, errLow);
838 err=errLow;
839 if(errHi>errLow) err=errHi;
840 if(!automatized) dout << " Uncertainty from PDF: " << errLow << " (low) and " << errHi << "(high) ---> Picked " << err << endl;
841 return err;
842
843 }
844
845 int get_npdfs(TTree *events) {
846 int NPDFs;
847 events->SetBranchAddress("NPdfs",&NPDFs);
848 events->GetEntry(1);
849 return NPDFs;
850 }
851
852
853 void do_systematics_for_one_file(TTree *events,int Neventsinfile,string informalname, vector<vector<float> > &results,int flipped, map < pair<float, float>, map<string, float> > xsec, string mcjzb,string datajzb,float peakerror,bool requireZ=false, string addcut="", bool isscan=false,int scantype=-1) {
854 float JZBScaleUncert=0.05; //if you modify this value please also adapt it in ShapeLimit.C not only here in Systematics.C
855 mcjzbexpression=mcjzb;
856 float triggereff=2.0/100;// in range [0,1]
857 dout << "Trigger efficiency not implemented in this script yet, still using external one" << endl;
858 float leptonseleff=2.0/100;// in range [0,1]
859 leptonseleff=TMath::Sqrt(leptonseleff*leptonseleff+leptonseleff*leptonseleff); // because the 2% is per lepton
860 dout << "Lepton selection efficiency not implemented in this script yet, still using external one" << endl;
861
862 int NPdfs=0;
863 if(isscan) NPdfs = get_npdfs(events);
864
865 float mceff,mcefferr,jzbeff,jzbefferr;
866 if(!automatized) dout << "MC efficiencies:" << endl;
867 Value flipefficiency;
868 Value mceff_nosigcont = MCefficiency(events,mceff,mcefferr,flipped,mcjzb,requireZ,Neventsinfile,scantype,xsec,addcut,-1);
869 if(!automatized) cout << " Without signal contamination, we find an efficiency of " << mceff_nosigcont << endl;
870
871 if(PlottingSetup::computeJZBefficiency) JZBefficiency(events,informalname,jzbeff,jzbefferr,flipped,requireZ,addcut);
872 if(!automatized) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << endl;
873
874 if(!automatized) dout << "Error from Peak position:";
875 float sysfrompeak=0;
876 PeakError(events,sysfrompeak,mcjzb,peakerror,flipped,addcut);
877
878 bool docomplicatedmSUGRAxsreweighting=false; //if you modify this value please also adapt it in ShapeLimit.C not only here in Systematics.C
879
880 if(!automatized) dout << "Jet energy scale (JES): " << std::endl;
881 float jesup,jesdown;
882 JZBjetScale(events,scantype==mSUGRA&&docomplicatedmSUGRAxsreweighting,xsec,jesdown,jesup,informalname,flipped,requireZ,addcut);
883
884 if(!automatized) dout << "JZB scale: " << std::endl;
885 float scaleup,scaledown,scalesyst;
886 doJZBscale(events,scantype==mSUGRA&&docomplicatedmSUGRAxsreweighting,xsec,scaledown,scaleup,scalesyst,JZBScaleUncert,informalname,flipped,requireZ,addcut);
887
888 if(!automatized) dout << "JZB response: " << std::endl;
889 float resp,resperr;
890 if(PlottingSetup::computeJZBresponse) {
891 if(!automatized) dout << "JZB response: " << std::endl;
892 if(!isscan) JZBresponse(events,informalname,requireZ,resp,resperr,flipped,addcut);
893 }
894
895 if(!automatized) dout << "Pileup: " << std::endl;
896 // float resolution;
897 //resolution=pileup(events,requireZ,informalname,flipped,addcut);
898
899 float PDFuncert=0;
900 if(!automatized) dout << "Assessing PDF uncertainty: " << std::endl;
901 if(isscan&&scantype!=mSUGRA) PDFuncert = get_pdf_uncertainty(events, flipped, mcjzb, requireZ, Neventsinfile, scantype, xsec, NPdfs, addcut);//for mSUGRA this is done differently!
902
903 dout << "_______________________________________________" << endl;
904 dout << " SUMMARY FOR " << informalname << " with JZB>" << jzbSel << " (all in %) ";
905 if(addcut!="") dout << "With additional cut: " << addcut;
906 dout << endl;
907 dout << "MC efficiency: " << mceff << "+/-" << mcefferr << endl; // in range [0,1]
908 dout << "Trigger efficiency: " << triggereff << endl; // in range [0,1]
909 dout << "Lepton Sel Eff: " << leptonseleff << endl; // in range [0,1]
910 dout << "Jet energy scale: " << jesup << " " << jesdown << endl; // in range [0,1]
911 dout << "JZB Scale Uncert: " << scaledown << " " << scaleup << endl; // in range [0,1]
912 // dout << "Resolution : " << resolution << endl; // in range [0,1]
913 dout << "From peak : " << sysfrompeak << endl; // in range [0,1]
914 if(isscan) dout << "PDF uncertainty : " << PDFuncert << endl; // in range [0,1]
915 if(PlottingSetup::computeJZBefficiency) dout << "JZB efficiency: " << jzbeff << "+/-" << jzbefferr << " (not yet included below) " << endl; // in range [0,1]
916 if(PlottingSetup::computeJZBresponse)dout << "JZB response : " << resp << " +/-" << resperr << " (not yet included below) " << endl; // in range [0,1]
917
918 float toterr=0;
919 toterr+=(triggereff)*(triggereff);
920 toterr+=(leptonseleff)*(leptonseleff);
921 if(fabs(jesup)>fabs(jesdown)) toterr+=(jesup*jesup); else toterr+=(jesdown*jesdown);
922 if(fabs(scaleup)>fabs(scaledown)) toterr+=(scaleup*scaleup); else toterr+=(scaledown*scaledown);
923 // toterr+=(resolution*resolution);
924 toterr+=(sysfrompeak*sysfrompeak);
925 if(isscan) toterr+=(PDFuncert*PDFuncert);
926 toterr=TMath::Sqrt(toterr);
927 dout << "TOTAL SYSTEMATICS: " << toterr << " --> " << toterr*mceff << endl;
928 float systerr=toterr*mceff;
929 toterr=TMath::Sqrt(toterr*toterr*mceff*mceff+mcefferr*mcefferr);//also includes stat err!
930
931 dout << "FINAL RESULT : " << 100*mceff << " +/- "<< 100*mcefferr << " (stat) +/- " << 100*systerr << " (syst) %" << endl;
932 dout << " we thus use the sqrt of the sum of the squares of the stat & syst err, which is : " << 100*toterr << endl;
933 dout << "_______________________________________________" << endl;
934
935 //Do not modify the lines below or mess with the order; this order is expected by all limit calculating functions!
936 vector<float> res;
937 res.push_back(jzbSel);
938 res.push_back(mceff);
939 res.push_back(mcefferr);
940 res.push_back(systerr);
941 res.push_back(toterr);
942 if(fabs(jesup)>fabs(jesdown)) res.push_back(fabs(jesup)); else res.push_back(fabs(jesdown));
943 if(fabs(scaleup)>fabs(scaledown)) res.push_back(fabs(scaleup)); else res.push_back(fabs(scaledown));
944 // res.push_back(fabs(resolution));
945 res.push_back(0.0);
946 res.push_back(mceff_nosigcont.getValue());
947 res.push_back(mceff_nosigcont.getError());
948 if(isscan) res.push_back(PDFuncert);
949 results.push_back(res);
950 }
951
952 vector<vector<float> > compute_systematics(string mcjzb, float mcpeakerror, int flipped, string datajzb, samplecollection &signalsamples, vector<float> bins, bool requireZ=false) {
953 automatized=true;
954 vector< vector<float> > systematics;
955 map < pair<float, float>, map<string, float> > xsec; // only needed for mSUGRA, and in that case this funciton isn't called
956
957 for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
958 dout << "Looking at signal " << (signalsamples.collection)[isignal].filename << endl;
959 for(int ibin=0;ibin<(int)bins.size();ibin++) {
960 jzbSel=bins[ibin];
961 geqleq="geq";
962 do_systematics_for_one_file((signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].Nentries,(signalsamples.collection)[isignal].samplename,systematics,flipped,xsec,mcjzb,datajzb,mcpeakerror,requireZ);
963 }//end of bin loop
964 }//end of signal loop
965 return systematics;
966 }