ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.19
Committed: Wed May 23 15:13:36 2012 UTC (12 years, 11 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.18: +1 -0 lines
Log Message:
included additional met plot

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <sys/stat.h>
4
5 #include <TCut.h>
6 #include <TROOT.h>
7 #include <TCanvas.h>
8 #include <TMath.h>
9 #include <TColor.h>
10 #include <TPaveText.h>
11 #include <TRandom.h>
12 #include <TH1.h>
13 #include <TH2.h>
14 #include <TF1.h>
15 #include <TSQLResult.h>
16 #include <TProfile.h>
17 #include <TLegendEntry.h>
18
19 using namespace std;
20
21 using namespace PlottingSetup;
22
23 void todo() {
24 dout << "My to do list: " << endl;
25 dout << " - ExperimentalModule::Poisson_ratio_plot : Get the second part to work!" << endl;
26 dout << " - compare_onpeak_offpeak_signal_distributions: Implement this function ... " << endl;
27 dout << "Info : The trigger requirement is currently set to " << (const char*) passtrig << endl;
28 dout << "Info : The pt requirement is currently set to " << (const char*) passtrig << endl;
29 dout << "Info : The mll requirement is currently set to " << (const char*) cutmass << endl;
30 dout << "Info : The lepton requirement is currently set to " << (const char*) leptoncut << endl;
31 }
32
33 void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result, bool doPUreweighting = true )
34 {
35 // Temporarily switch off PU reweighting, if asked
36 TCut weightbackup=cutWeight;
37 if ( !doPUreweighting ) cutWeight="1.0";
38
39 TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
40 TH1F *rawJZBeemmMC = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
41 TH1F *rawJZBeemmData = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
42 TH1F *rawJZBemMC = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
43 TH1F *rawJZBemData = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
44 TH1F *rawttbarjzbeemmMC;
45
46 if(method==doKM) {
47 //we only need this histo for the KM fitting...
48 rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
49 MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
50 DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
51 }
52 else {
53 TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
54 TH1F *reducedData = (TH1F*)rawJZBeemmData->Clone();
55 reducedMC->Add(rawJZBemMC,-1);
56 reducedData->Add(rawJZBemData,-1);
57 //this is Kostas' way of doing it - we subtract em to get rid of some of the ttbar contribution (in reality, of flavor-symmetric contribution)
58 MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
59 DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
60
61 }
62
63 // Revert to original PU reweighting
64 if ( !doPUreweighting ) cutWeight = weightbackup;
65
66 // MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
67 // DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
68 dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
69 result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
70 dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
71 result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
72 delete tempcan;
73 }
74
75 void make_special_obs_pred_mll_plot(string mcjzb, float jzbthreshold) {
76 float min=70.0;
77 float max=115.0;
78 if(!PlottingSetup::RestrictToMassPeak) {
79 min=10;
80 max=150;
81 }
82 int nbins=int((max-min)/5);
83
84 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
85
86 stringstream largerzeroS;
87 largerzeroS << "(" << mcjzb << ">" << jzbthreshold << ")";
88 TCut largerzero(largerzeroS.str().c_str());
89
90 stringstream smallerzeroS;
91 smallerzeroS << "(" << mcjzb << "<-" << jzbthreshold << ")";
92 TCut smallerzero(smallerzeroS.str().c_str());
93
94 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,data,luminosity);
95 THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,mc,luminosity);
96 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,data,luminosity);
97 TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,data,luminosity);
98 TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,data,luminosity);
99
100 TH1F *RcorrJZBSBem;
101 TH1F *LcorrJZBSBem;
102 TH1F *RcorrJZBSBeemm;
103 TH1F *LcorrJZBSBeemm;
104
105 // TH1F *RcorrJZBeemmNoS;
106
107 if(PlottingSetup::RestrictToMassPeak) {
108 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem", "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,data, luminosity);
109 LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem", "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,data, luminosity);
110 RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,data, luminosity);
111 LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,data, luminosity);
112 }
113
114 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
115 if(PlottingSetup::RestrictToMassPeak) {
116 Bpred->Add(RcorrJZBem,1.0/3.);
117 Bpred->Add(LcorrJZBem,-1.0/3.);
118 Bpred->Add(RcorrJZBSBem,1.0/3.);
119 Bpred->Add(LcorrJZBSBem,-1.0/3.);
120 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
121 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
122 } else {
123 Bpred->Add(RcorrJZBem,1.0);
124 Bpred->Add(LcorrJZBem,-1.0);
125 }
126
127 Bpred->SetLineColor(kRed);
128
129 RcorrJZBeemm->Draw();
130 mcRcorrJZBeemm.Draw("same");
131 Bpred->Draw("histo,same");
132 RcorrJZBeemm->Draw("same");
133
134 TLegend *leg = allsamples.allbglegend();
135 leg->SetX1(0.58);
136 leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
137 leg->AddEntry(Bpred,"predicted (data)","l");
138 leg->Draw("same");
139
140 stringstream saveas;
141 saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
142 CompleteSave(ckin,saveas.str());
143
144 delete RcorrJZBeemm;
145 delete LcorrJZBeemm;
146 delete RcorrJZBem;
147 delete LcorrJZBem;
148 if(PlottingSetup::RestrictToMassPeak) {
149 delete RcorrJZBSBeemm;
150 delete LcorrJZBSBeemm;
151 delete RcorrJZBSBem;
152 delete LcorrJZBSBem;
153 }
154 delete Bpred;
155 delete ckin;
156 }
157
158 void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
159
160 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
161
162 TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
163 THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
164 TH1F *datahistoOSOF = allsamples.Draw("datahistoOSOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
165
166 if(logscale) ckin->SetLogy(1);
167 datahistoOSSF->SetMarkerSize(DataMarkerSize);
168 datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
169 datahistoOSSF->GetXaxis()->CenterTitle();
170 datahistoOSSF->GetYaxis()->SetTitle("events");
171 datahistoOSSF->GetYaxis()->CenterTitle();
172 datahistoOSOF->SetMarkerSize(DataMarkerSize);
173 datahistoOSSF->SetMarkerSize(DataMarkerSize);
174 datahistoOSSF->Draw();
175
176 mcstackOSSF.Draw("same");
177 datahistoOSSF->Draw("same");
178
179 datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
180 datahistoOSOF->SetLineColor(kRed);
181 datahistoOSOF->SetMarkerStyle(21);
182 datahistoOSOF->Draw("same");
183
184 // Try to re-arrange legend...
185 TLegend *bgleg = allsamples.allbglegend("",datahistoOSSF);
186 TLegend *kinleg = make_legend();
187 kinleg->AddEntry(datahistoOSSF,"SF (data)","p");
188 kinleg->AddEntry(datahistoOSOF,"OF (data)","p");
189 TIter next(bgleg->GetListOfPrimitives());
190 TObject* obj;
191 // Copy the nice bkgd legend skipping the "data"
192 while ( (obj = next()) )
193 if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
194 kinleg->GetListOfPrimitives()->Add(obj);
195
196 kinleg->Draw();
197 CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
198
199 delete datahistoOSOF;
200 delete datahistoOSSF;
201 delete ckin;
202 }
203
204
205 void draw_ratio_plot(TH1* hdata, THStack& hmc, float ymin=0.5, float ymax=1.5) {
206
207 // Make a histogram from stack
208 TIter next(hmc.GetHists());
209 TObject* obj;
210 TH1* hratio = NULL;
211 while ( (obj = next()) ) {
212 if ( !hratio ) {
213 hratio = (TH1*)obj->Clone();
214 hratio->SetName("hratio");
215 } else hratio->Add( (TH1*)obj );
216 }
217 hratio->Divide(hdata);
218 hratio->SetMaximum(ymax);
219 hratio->SetMinimum(ymin);
220 hratio->SetMarkerStyle(2);
221 hratio->SetLineWidth(1);
222 hratio->GetYaxis()->SetLabelSize(0.08);
223 hratio->GetXaxis()->SetLabelSize(0.0);
224
225 TPad* rpad = new TPad("rpad","",0.15,0.73,0.4,0.88);
226 rpad->SetTopMargin(0.0);
227 rpad->SetBottomMargin(0.0);
228 rpad->SetRightMargin(0.0);
229 rpad->Draw();
230 rpad->cd();
231 // hratio->GetXaxis()->SetNdivisions(0);
232 hratio->GetYaxis()->SetNdivisions(502,false);
233 hratio->Draw("e1x0");
234
235 TF1* oneline = new TF1("","1.0",0,1000);
236 oneline->SetLineColor(kBlue);
237 oneline->SetLineStyle(1);
238 oneline->SetLineWidth(1);
239 oneline->Draw("same");
240 }
241
242 float lastrange_min=0;
243 float lastrange_max=0;
244
245 void make_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
246 string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
247 // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
248 TCut ibasiccut=basiccut;
249 bool draw_separation_lines=false;
250
251 if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
252
253 if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
254
255 //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
256 if(isPF) {
257 if(variable=="mll") variable="pfmll[0]";
258 if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
259 if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
260 if(variable=="pt") variable="pfpt[0]";
261 if(variable=="pt1") variable="pfpt1[0]";
262 if(variable=="pt2") variable="pfpt2[0]";
263 if(variable=="eta1") variable="pfeta1[0]";
264 if(variable=="jzb[1]") variable="pfjzb[0]";
265 //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
266 }
267
268 //Step 2: Refine the cut
269 TCut cut;
270 cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
271 if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
272 if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
273 if(filename=="mll") {
274 cut=cutOSSF&&cutnJets&&ibasiccut;
275 draw_separation_lines=true;
276 }
277 if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
278 if(filename=="mll_osof") {
279 cut=cutOSOF&&cutnJets&&ibasiccut;
280 draw_separation_lines=true;
281 }
282 if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
283 if(Contains(filename,"mll_aboveJZB100")) cut=cutOSSF&&cutnJets&&ibasiccut;
284 if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
285 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
286 if(filename=="mll_inclusive_osof") cut=cutOSOF;
287 if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
288 if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
289 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
290 if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
291
292 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
293 ckin->SetLogy(logscale);
294 TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
295 datahisto->SetMarkerSize(DataMarkerSize);
296 THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
297 if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
298 if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
299 if(filename=="mll_inclusive") datahisto->SetMinimum(1);
300 if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
301 if(filename=="mll_osof") datahisto->SetMinimum(9);
302
303 datahisto->SetMaximum(5.3*datahisto->GetMaximum());
304 datahisto->Draw("e1");
305 ckin->Update();
306 if(loadlastminmax) {
307 datahisto->SetMinimum(lastrange_min);
308 datahisto->SetMaximum(lastrange_max);
309 if(logscale) {
310 datahisto->SetMinimum(pow(10,lastrange_min));
311 datahisto->SetMaximum(pow(10,lastrange_max));
312 }
313 }
314
315 mcstack.Draw("same");
316 datahisto->Draw("same,e1");
317 TLegend *kinleg = allsamples.allbglegend();
318 kinleg->Draw();
319 if(filename=="mll_osof") {
320 kinleg->SetHeader("Opposite flavor");
321 kinleg->SetX1(0.58);
322 }
323 if(filename=="mll") {
324 kinleg->SetHeader("Same flavor");
325 kinleg->SetX1(0.58);
326 }
327 TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
328 write_cut->Draw();
329 TText* write_variable = write_text(0.99,0.01,variable);
330 write_variable->SetTextAlign(31);
331 write_variable->SetTextSize(0.02);
332
333 TLine *lowerboundary;
334 TLine *upperboundary;
335
336 if(RestrictToMassPeak&&draw_separation_lines) {
337 Color_t linecolor=kBlue;
338 float linemin=pow(10,ckin->GetUymin());
339 if(filename=="mll_osof") linemin=pow(10,lastrange_min);
340 lowerboundary = new TLine(71,linemin,71,datahisto->GetMaximum());
341 upperboundary = new TLine(111,linemin,111,datahisto->GetMaximum());
342 lowerboundary->SetLineColor(linecolor);
343 lowerboundary->SetLineStyle(2);
344 upperboundary->SetLineColor(linecolor);
345 upperboundary->SetLineStyle(2);
346 }
347
348 lastrange_min=ckin->GetUymin();
349 lastrange_max=ckin->GetUymax();
350
351
352 if ( plotratio ) {
353 TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
354 kinpad->cd();
355 kinpad->SetLogy(logscale);
356 datahisto->Draw("e1");
357 mcstack.Draw("same");
358 datahisto->Draw("same,e1");
359 datahisto->Draw("same,axis");
360 if(RestrictToMassPeak&&draw_separation_lines) {
361 lowerboundary->Draw("same");
362 upperboundary->Draw("same");
363 }
364
365 kinleg->Draw();
366 write_cut->Draw();
367 DrawPrelim();
368 string saveas="kin/"+filename;
369 if(isPF) saveas="kin/"+filename+"__PF";
370 save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
371 // if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
372 // else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
373 // delete with_ratio;
374 } else {
375 if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
376 else CompleteSave(ckin,"kin/"+filename);
377 }
378 datahisto->Delete();
379 delete ckin;
380 }
381
382 void make_JES_plot() {
383
384 int nbins=10;
385 float min=-0.5;
386 float max = 9.5;
387 bool logscale=true;
388 string xlabel="nJets";
389 TCut cut=cutmass&&cutOSSF&&basiccut;
390
391 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
392 ckin->SetLogy(logscale);
393 TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
394 datahisto->SetMarkerSize(DataMarkerSize);
395 THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
396 TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
397 TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
398
399 datahisto->SetMinimum(1);
400 datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
401
402 float xs[nbins],ys[nbins],exs[nbins],eys[nbins];
403 for(int i=1;i<JESup->GetNbinsX();i++) {
404 float up=JESup->GetBinContent(i);
405 float dn=JESdn->GetBinContent(i);
406 xs[i]=JESup->GetBinCenter(i);
407 ys[i]=0.5*(up+dn);
408 exs[i]=0.5*JESup->GetBinWidth(i);
409 eys[i]=0.5*TMath::Abs(up-dn);
410 }
411
412 TGraphAsymmErrors *JESunc = new TGraphAsymmErrors(nbins, xs,ys,exs,exs,eys,eys);
413 JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
414 JESunc->SetFillStyle(3002);
415 datahisto->Draw("e1");
416 mcstack.Draw("same");
417 JESunc->Draw("2");
418 datahisto->Draw("same,e1");
419 TLegend *kinleg = allsamples.allbglegend();
420 kinleg->AddEntry(JESunc,"JES uncertainty","f");
421 kinleg->Draw();
422 CompleteSave(ckin,"Systematics/JES");
423 datahisto->Delete();
424 delete ckin;
425
426 }
427
428 void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
429 {
430 bool dolog=true;
431 bool nolog=false;
432 if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
433 float mll_low=50;
434 float mll_hi=160;
435 if(!PlottingSetup::RestrictToMassPeak) {
436 mll_low=20;
437 mll_hi=210;
438 }
439
440 make_kin_plot("met[4]","",40,0,200,dolog,"MET [GeV]","met",doPF,true);
441 make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
442 make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
443 make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
444 make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
445 make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
446 make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
447 make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
448 make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
449 make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
450 make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
451 make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
452 make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
453 make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
454 make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
455 make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
456 make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
457 make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
458 make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
459 make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
460 if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
461 stringstream jzbcut;
462 jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
463 make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
464 make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB100",doPF,true);
465 make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
466 make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB100",doPF,true);
467 stringstream jzbcut2;
468 jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
469 make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
470 make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB150",doPF,true);
471 stringstream jzbcut3;
472 jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
473 make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true); make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB50",doPF,true,true);
474
475 make_special_obs_pred_mll_plot(mcjzb,0);
476 make_special_obs_pred_mll_plot(mcjzb,50);
477 make_special_obs_pred_mll_plot(mcjzb,100);
478 make_special_obs_pred_mll_plot(mcjzb,150);
479 make_special_obs_pred_mll_plot(mcjzb,200);
480 make_special_obs_pred_mll_plot(mcjzb,250);
481 }
482
483 void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
484 int nbins, float xmin, float xmax, bool log,
485 float ymin=0, float ymax=0, bool leftJustified=false ) {
486 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
487
488 TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
489 if(weightbackup==TCut("1.0")||weightbackup==TCut("1")) write_warning(__FUNCTION__,"WATCH OUT THE WEIGHT HAS POSSIBLY NOT BEEN RESET!!!! PLEASE CHANGE LINE "+any2string(__LINE__));
490 if(var=="numVtx") cutWeight=TCut("1.0");
491 TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
492 TCut jzbMC[] = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
493
494 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- below: the next ~20 lines changed!
495 int nRegions=4;
496 if(!PlottingSetup::RestrictToMassPeak) {
497 nRegions=2;
498 }
499
500 string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
501 TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass, cutOSOF&&cutnJets&&cutmass,
502 cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
503
504 //find ymax
505 TH1F *Refdatahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[0]&&jzbData[0],data,luminosity);
506 ymax=int((Refdatahisto->GetMaximum()+2*TMath::Sqrt(Refdatahisto->GetMaximum()))*1.2+0.5);
507 delete Refdatahisto;
508
509 for ( int iregion=0; iregion<nRegions; ++iregion )
510 for ( int ijzb=0; ijzb<2; ++ijzb ) {
511 TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
512 ccomp->SetLogy(log);
513 TH1F *datahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
514 TH1F *lm4histo = signalsamples.Draw("lm4histo", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
515 THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb], mc, luminosity);
516 datahisto->SetMarkerSize(DataMarkerSize);
517 if (ymax>ymin) datahisto->SetMaximum(ymax);
518 lm4histo->SetLineStyle(2);
519 datahisto->Draw("e1");
520 mcstack.Draw("same");
521 datahisto->Draw("same,e1");
522 // lm4histo->Draw("hist,same");
523 TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
524 if ( leftJustified ) {
525 Float_t w = kinleg->GetX2()-kinleg->GetX1();
526 kinleg->SetX1(0.2);
527 kinleg->SetX2(0.2+w);
528 }
529 // kinleg->AddEntry(lm4histo,"LM4","l");
530 kinleg->Draw();
531 TText* write_variable = write_text(0.99,0.01,var);
532 write_variable->SetTextAlign(31);
533 write_variable->SetTextSize(0.02);
534 ccomp->RedrawAxis();
535 CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
536 delete datahisto;
537 delete ccomp;
538 delete lm4histo;
539 }
540 cutWeight=weightbackup;
541 }
542
543
544 void region_comparison_plots(string mcjzb, string datajzb, vector<float> jzb_cuts) {
545 dout << "Creating comparison plots for signal and control regions" << endl;
546 // Compare a few quantities in the signal region and all 7 control regions
547
548 switch_overunderflow(true); // switching overflow/underflow bins on
549
550
551 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
552 for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
553 float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
554 float mll_low=50;float mll_high=170;
555 if(!PlottingSetup::RestrictToMassPeak) {
556 mll_high=200;
557 mll_low=50;
558 }
559 make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,30,mll_low,mll_high,false,0,16.);
560 make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
561 make_comp_plot("pfJetGoodNum","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
562 make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
563 make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,20,0.,20.,false,0,16.);
564 make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
565 make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
566 }
567
568 switch_overunderflow(false); // switching overflow/underflow bins off
569 }
570
571
572
573 void do_kinematic_PF_plots(string mcjzb, string datajzb)
574 {
575 do_kinematic_plots(mcjzb,datajzb,true);
576 }
577
578 void signal_bg_comparison()
579 {
580 TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
581 can->SetLogy(1);
582
583 int sbg_nbins=130;
584 float sbg_min=-500; //-110;
585 float sbg_max=800; //jzbHigh;
586
587 float simulatedlumi=luminosity;//in pb please - adjust to your likings
588
589 TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
590 TH1F *JZBplotLM4;
591 if(PlottingSetup::RestrictToMassPeak) JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
592 else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
593 TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
594
595 JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
596 JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
597 JZBplotZJETs->SetLineColor(kBlack);
598 JZBplotLM4->SetLineStyle(2);
599 JZBplotZJETs->SetMaximum(JZBplotZJETs->GetMaximum()*5);
600 JZBplotZJETs->SetMinimum(1);
601
602 JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
603 JZBplotTtbar->SetMinimum(0.01);
604 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
605 JZBplotTtbar->DrawClone("histo");
606 JZBplotZJETs->Draw("histo,same");
607 JZBplotTtbar->SetFillColor(0);
608 JZBplotTtbar->DrawClone("histo,same");
609 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
610 JZBplotLM4->Draw("histo,same");
611
612
613 TLegend *signal_bg_comparison_leg2 = make_legend("",0.55,0.75,false);
614 signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
615 signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
616 if(PlottingSetup::RestrictToMassPeak) signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
617 else signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM3","f");
618 signal_bg_comparison_leg2->Draw();
619 DrawMCPrelim(simulatedlumi);
620 CompleteSave(can,"jzb_bg_vs_signal_distribution");
621
622 // Define illustrative set of SMS points
623 TCut kSMS1("MassGlu==250&&MassLSP==75");
624 TCut kSMS2("MassGlu==800&&MassLSP==200");
625 TCut kSMS3("MassGlu==1050&&MassLSP==850");
626 TCut kSMS4("MassGlu==1200&&MassLSP==100");
627
628 //If the scan samples haven't been loaded yet, this is a good point to load them (all of them!)
629 if((scansample.collection).size()<2) define_SMS_sample(false, allsamples, signalsamples, scansample, true); // loading ALL zones for the scans, not only the basic one.
630
631
632 TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS1,mc,simulatedlumi,scansample.FindSample("t"));
633 JZBplotSMS1->Scale(JZBplotLM4->Integral()/JZBplotSMS1->Integral());
634
635 TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS2,mc,simulatedlumi,scansample.FindSample("t"));
636 JZBplotSMS2->Scale(JZBplotLM4->Integral()/JZBplotSMS2->Integral());
637
638 TH1F *JZBplotSMS3 = scansample.Draw("JZBplotSMS3",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS3,mc,simulatedlumi,scansample.FindSample("t"));
639 JZBplotSMS3->Scale(JZBplotLM4->Integral()/JZBplotSMS3->Integral());
640
641 TH1F *JZBplotSMS4 = scansample.Draw("JZBplotSMS4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS4,mc,simulatedlumi,scansample.FindSample("t"));
642 JZBplotSMS4->Scale(JZBplotLM4->Integral()/JZBplotSMS4->Integral());
643
644 // Draw all plots overlaid
645 JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
646 JZBplotTtbar->SetMinimum(0.01);
647 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
648 JZBplotTtbar->DrawClone("histo");
649 JZBplotZJETs->Draw("histo,same");
650 JZBplotTtbar->SetFillColor(0);
651 JZBplotTtbar->DrawClone("histo,same");
652 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
653
654 JZBplotSMS1->SetLineColor(kRed+1);
655 JZBplotSMS2->SetLineColor(kBlue+1);
656 JZBplotSMS3->SetLineColor(kRed+1);
657 JZBplotSMS4->SetLineColor(kBlue+1);
658 JZBplotSMS3->SetLineStyle(2);
659 JZBplotSMS4->SetLineStyle(2);
660
661 JZBplotSMS1->Draw("histo,same");
662 JZBplotSMS2->Draw("histo,same");
663 JZBplotSMS3->Draw("histo,same");
664 JZBplotSMS4->Draw("histo,same");
665 JZBplotLM4->SetLineColor(kGreen);JZBplotLM4->Draw("histo,same");
666 TLegend *signal_bg_comparison_leg6 = make_legend("",0.55,0.55,false);
667 signal_bg_comparison_leg6->AddEntry(JZBplotZJETs,"Z+Jets","f");
668 signal_bg_comparison_leg6->AddEntry(JZBplotTtbar,"t#bar{t}","f");
669 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
670 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"SMS parameters","");
671 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"(250,75) [GeV]","f");
672 signal_bg_comparison_leg6->AddEntry(JZBplotSMS2,"(800,200) [GeV]","f");
673 signal_bg_comparison_leg6->AddEntry(JZBplotSMS3,"(1050,850) [GeV]","f");
674 signal_bg_comparison_leg6->AddEntry(JZBplotSMS4,"(1200,100) [GeV]","f");
675 signal_bg_comparison_leg6->AddEntry(JZBplotLM4,"LM4","f");
676 signal_bg_comparison_leg6->Draw();
677 DrawMCPrelim(simulatedlumi);
678 CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__summary");
679
680 while((scansample.collection).size() > 1) scansample.RemoveLastSample();
681
682 }
683
684 vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
685 TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
686 BpredFunc->SetParameter(0,histo->GetBinContent(1));
687 if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
688 BpredFunc->SetParameter(1,0.);
689 if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
690 else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
691 if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
692 BpredFunc->SetParameter(3,1.8);
693 BpredFunc->SetParameter(4,2.5);
694 histo->Fit(BpredFunc,"QN0");
695 BpredFunc->SetLineColor(kBlue);
696
697 TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
698 TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
699
700 BpredFuncP->SetParameters(BpredFunc->GetParameters());
701 BpredFuncP->SetLineColor(kBlue);
702 BpredFuncP->SetLineStyle(2);
703
704 BpredFuncN->SetParameters(BpredFunc->GetParameters());
705 BpredFuncN->SetLineColor(kBlue);
706 BpredFuncN->SetLineStyle(2);
707
708 vector<TF1*> functions;
709 functions.push_back(BpredFuncN);
710 functions.push_back(BpredFunc);
711 functions.push_back(BpredFuncP);
712 return functions;
713 }
714
715
716 TF1* do_logpar_fit_to_plot(TH1F *osof) {
717 TCanvas *logpar_fit_can = new TCanvas("logpar_fit_can","Fit canvas for LogPar");
718 TF1 *logparfunc = new TF1("logparfunc",LogParabola,0,300,3);
719 TF1 *logparfunc2 = new TF1("logparfunc2",LogParabola,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
720 TF1 *logparfuncN = new TF1("logparfuncN",LogParabolaN,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
721 TF1 *logparfuncP = new TF1("logparfuncP",LogParabolaP,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
722 osof->SetMinimum(0);
723 osof->Fit(logparfunc,"QR");
724 osof->Draw();
725 logparfunc->SetLineWidth(2);
726 logparfunc2->SetParameters(logparfunc->GetParameters());
727 logparfuncN->SetParameters(logparfunc->GetParameters());
728 logparfuncP->SetParameters(logparfunc->GetParameters());
729 stringstream fitinfo;
730 fitinfo << "#Chi^{2} / NDF : " << logparfunc->GetChisquare() << " / " << logparfunc->GetNDF();
731 TText *writefitinfo = write_text(0.8,0.8,fitinfo.str());
732 writefitinfo->SetTextSize(0.03);
733 DrawPrelim();
734 writefitinfo->Draw();
735 logparfunc->Draw("same");
736 logparfunc2->Draw("same");
737 logparfuncN->SetLineStyle(2);
738 logparfuncP->SetLineStyle(2);
739 logparfuncN->Draw("same");
740 logparfuncP->Draw("same");
741 CompleteSave(logpar_fit_can,"MakingOfBpredFunction/Bpred_Data_LogPar_Fit_To_TTbarPred");
742 delete logpar_fit_can;
743 return logparfunc2;
744 }
745
746 vector<TF1*> do_extended_fit_to_plot(TH1F *prediction, TH1F *Tprediction, TH1F *ossf, TH1F *osof,int isdata) {
747 /* there are mainly two background contributions: Z+Jets (a) and ttbar (b). So:
748 a) The case is clear - we take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it. We then extract the CB parameters.
749 b) For ttbar, we use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola. We then extract the LP parameters.
750 Once we have these two components, we use the combined parameters to get the final function and we're done.
751 */
752 //Step 1: take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it
753 TH1F *step1cb = (TH1F*)ossf->Clone("step1cb");
754 step1cb->Add(osof,-1);
755 vector<TF1*> functions = do_cb_fit_to_plot(step1cb,PlottingSetup::JZBPeakWidthData);
756 TF1 *zjetscrystalball = functions[1];
757
758 //Step 2: use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola
759 // TH1F *ttbarprediction=(TH1F*)prediction->Clone("ttbarprediction");
760 // ttbarprediction->Add(ossf,-1);//without the Z+Jets estimate, this is really just the ttbar estimate!
761 // the line above is not necessary anymore as we're now looking at a prediction without Z+Jets, and not multiplied with (1.0/3)
762 TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
763 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
764 if(PlottingSetup::RestrictToMassPeak) ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
765
766
767 TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
768 TF1 *ttbarlogparN = new TF1("ttbarlogparN",LogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
769
770 //and now fuse the two!
771 TF1 *kmlp = new TF1("kmlp", CrystalBallPlusLogParabola, 0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
772 TF1 *kmlpP= new TF1("kmlpP",CrystalBallPlusLogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
773 TF1 *kmlpN= new TF1("kmlpN",CrystalBallPlusLogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
774 double kmlp_pars[10];
775 for(int i=0;i<5;i++) kmlp_pars[i]=zjetscrystalball->GetParameter(i);
776 for(int i=0;i<3;i++) kmlp_pars[5+i]=ttbarlogpar->GetParameter(i);
777 ttbarlogparP->SetParameters(ttbarlogpar->GetParameters());
778 ttbarlogparN->SetParameters(ttbarlogpar->GetParameters());
779 kmlp->SetParameters(kmlp_pars);
780 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
781 /*
782 if you want to start from scratch (without the partial fitting and only fitting the whole thing, some good start values could be :
783 */
784 kmlp_pars[0]=kmlp->GetParameter(0);
785 kmlp_pars[1]=3.6198;
786 kmlp_pars[2]=16.4664;
787 kmlp_pars[3]=1.92253;
788 kmlp_pars[4]=3.56099;
789 kmlp_pars[5]=5.83;
790 kmlp_pars[6]=0.000757479;
791 kmlp_pars[7]=95.6157;
792 kmlp_pars[8]=0;
793 kmlp_pars[9]=0;
794 kmlp->SetParameters(kmlp_pars);
795 /**/
796 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
797
798 kmlpP->SetParameters(kmlp->GetParameters());
799 kmlpN->SetParameters(kmlp->GetParameters());
800
801 // now that we're done, let's save all of this so we can have a look at it afterwards.
802 TCanvas *can = new TCanvas("can","Prediction Fit Canvas");
803 can->SetLogy(1);
804 prediction->SetMarkerColor(kRed);
805 prediction->Draw();
806
807 kmlp->SetLineColor(TColor::GetColor("#04B404"));
808 kmlpP->SetLineColor(TColor::GetColor("#04B404"));
809 kmlpN->SetLineColor(TColor::GetColor("#04B404"));
810 kmlp->Draw("same");
811 kmlpN->SetLineStyle(2);
812 kmlpP->SetLineStyle(2);
813 kmlpN->Draw("same");
814 kmlpP->Draw("same");
815
816 ttbarlogpar->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
817 ttbarlogpar->Draw("same");
818 ttbarlogparP->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
819 ttbarlogparN->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
820 ttbarlogparP->SetLineStyle(2);
821 ttbarlogparN->SetLineStyle(2);
822 ttbarlogparP->Draw("same");
823 ttbarlogparN->Draw("same");
824
825 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
826
827 TLegend *analyticalBpredLEG = make_legend("",0.5,0.55);
828 analyticalBpredLEG->AddEntry(prediction,"predicted","p");
829 analyticalBpredLEG->AddEntry(functions[1],"Crystal Ball fit","l");
830 analyticalBpredLEG->AddEntry(functions[0],"1#sigma Crystal Ball fit","l");
831 analyticalBpredLEG->AddEntry(ttbarlogparN,"TTbar fit","l");
832 analyticalBpredLEG->AddEntry(ttbarlogpar,"1#sigma TTbar fit","l");
833 analyticalBpredLEG->AddEntry(kmlp,"Combined function","l");
834 analyticalBpredLEG->AddEntry(kmlpN,"1#sigma combined function","l");
835 analyticalBpredLEG->Draw("same");
836
837 if(isdata==0) CompleteSave(can,"MakingOfBpredFunction/Bpred_MC_Analytical_Function_Composition");
838 if(isdata==1) CompleteSave(can,"MakingOfBpredFunction/Bpred_data_Analytical_Function_Composition");
839 if(isdata==2) CompleteSave(can,"MakingOfBpredFunction/Bpred_MCBnS_Analytical_Function_Composition");
840 delete can;
841
842 //and finally: prep return functions
843 vector<TF1*> return_functions;
844 return_functions.push_back(kmlpN);
845 return_functions.push_back(kmlp);
846 return_functions.push_back(kmlpP);
847
848 return_functions.push_back(ttbarlogparN);
849 return_functions.push_back(ttbarlogpar);
850 return_functions.push_back(ttbarlogparP);
851
852 return_functions.push_back(functions[0]);
853 return_functions.push_back(functions[1]);
854 return_functions.push_back(functions[2]);
855
856 return return_functions;
857 }
858
859 void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false,string subdir="" )
860 {
861 // note: sigma is not used ATM
862 switch_overunderflow(true);
863 bool is_data=false;
864 bool use_signal=false;
865 if(use_data==1) is_data=true;
866 if(use_data==2) use_signal=true;
867 int nbins=50;//100;
868 if(is_data) nbins=50;
869 float low=0;
870 float hi=500;
871
872 stringstream largerzeroS;
873 largerzeroS << "("<<jzb<<">0)";
874 TCut largerzero(largerzeroS.str().c_str());
875 stringstream smallerzeroS;
876 smallerzeroS << "("<<jzb<<"<0)";
877 TCut smallerzero(smallerzeroS.str().c_str());
878
879 TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
880 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
881 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
882 TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
883 TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
884
885 blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
886 blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
887 blankback->GetXaxis()->CenterTitle();
888 blankback->GetYaxis()->CenterTitle();
889
890 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
891 TH1F *RcorrJZBSBem;
892 TH1F *LcorrJZBSBem;
893 TH1F *RcorrJZBSBeemm;
894 TH1F *LcorrJZBSBeemm;
895
896 TH1F *RcorrJZBeemmNoS;
897
898 //these are for the ratio
899
900 TH1F *JRcorrJZBeemm = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
901 TH1F *JLcorrJZBeemm = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
902 TH1F *JRcorrJZBem = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
903 TH1F *JLcorrJZBem = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
904
905 TH1F *JRcorrJZBSBem;
906 TH1F *JLcorrJZBSBem;
907 TH1F *JRcorrJZBSBeemm;
908 TH1F *JLcorrJZBSBeemm;
909
910 if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,false);
911
912
913 if(PlottingSetup::RestrictToMassPeak) {
914 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
915 LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
916 RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
917 LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
918
919 //these are for the ratio
920 JRcorrJZBSBem = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
921 JLcorrJZBSBem = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
922 JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
923 JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
924 }
925
926 TH1F *lm4RcorrJZBeemm;
927 if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,allsamples.FindSample("LM"));
928
929 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
930
931 TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
932 TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
933
934 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
935 TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
936 if(PlottingSetup::RestrictToMassPeak) {
937 Bpred->Add(RcorrJZBem,1.0/3.);
938 Bpred->Add(LcorrJZBem,-1.0/3.);
939 Bpred->Add(RcorrJZBSBem,1.0/3.);
940 Bpred->Add(LcorrJZBSBem,-1.0/3.);
941 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
942 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
943
944 TTbarpred->Scale(1.0/3);
945 Zjetspred->Add(LcorrJZBem,-1.0/3.);
946 Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
947 TTbarpred->Add(RcorrJZBSBem,1.0/3.);
948 Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
949 TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
950
951 //these are for the ratio
952 JBpred->Add(JRcorrJZBem,1.0/3.);
953 JBpred->Add(JLcorrJZBem,-1.0/3.);
954 JBpred->Add(JRcorrJZBSBem,1.0/3.);
955 JBpred->Add(JLcorrJZBSBem,-1.0/3.);
956 JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
957 JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
958 } else {
959 Bpred->Add(RcorrJZBem,1.0);
960 Bpred->Add(LcorrJZBem,-1.0);
961
962 Zjetspred->Add(LcorrJZBem,-1.0);
963
964 //these are for the ratio
965 JBpred->Add(JRcorrJZBem,1.0);
966 JBpred->Add(JLcorrJZBem,-1.0);
967 }
968
969
970
971 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
972 TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
973 Tpred->Add(LcorrJZBem,-1.0);
974 if(PlottingSetup::RestrictToMassPeak) {
975 Tpred->Add(RcorrJZBSBem,1.0);
976 Tpred->Add(LcorrJZBSBem,-1.0);
977 Tpred->Add(RcorrJZBSBeemm,1.0);
978 Tpred->Add(LcorrJZBSBeemm,-1.0);
979 }
980
981 globalcanvas->cd();
982 globalcanvas->SetLogy(1);
983
984 RcorrJZBeemm->SetMarkerStyle(20);
985 RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
986 RcorrJZBeemm->SetMinimum(0.1);
987
988 Bpred->SetLineColor(kRed);
989 Bpred->SetStats(0);
990
991 int versok=false;
992 if(gROOT->GetVersionInt()>=53000) versok=true;
993
994
995 if ( overlay_signal || use_data==2 ) lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
996 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
997
998 TLegend *legBpred = make_legend("",0.6,0.55);
999 TLegend *legBpred2 = make_legend("",0.6,0.55);
1000
1001
1002 vector<TF1*> analytical_function;
1003 TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1004 kinpad->cd();
1005 kinpad->SetLogy(1);
1006
1007 string Bpredsaveas="Bpred_Data";
1008 blankback->SetMaximum(5*RcorrJZBeemm->GetMaximum());
1009 blankback->SetMinimum(0.1);
1010 if(use_data!=1) blankback->SetMinimum(0.1);
1011 blankback->Draw();
1012 if(use_data==1)
1013 {
1014 //Bpred->SetLineWidth(3); //paper style.overruled.
1015 //lm4RcorrJZBeemm->SetLineWidth(3); //paper style.overruled.
1016 analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
1017 kinpad->cd();//necessary because the extended fit function creates its own canvas
1018 RcorrJZBeemm->Draw("e1x0,same");
1019
1020 Bpred->Draw("hist,same");
1021 //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1022 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1023 lm4RcorrJZBeemm->Draw("hist,same");
1024 legBpred->AddEntry(RcorrJZBeemm,"observed","p");
1025 legBpred->AddEntry(Bpred,"predicted","l");
1026 legBpred->AddEntry(analytical_function[1],"predicted fit","l");
1027 legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
1028 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1029 legBpred->Draw();
1030 DrawPrelim();
1031
1032 //this plot shows what the prediction is composed of
1033 TPad *predcomppad = new TPad("predcomppad","predcomppad",0,0,1,1);
1034 float CurrentBpredLineWidth=Bpred->GetLineWidth();
1035 Bpred->SetLineWidth(2);
1036 predcomppad->cd();
1037 predcomppad->SetLogy(1);
1038
1039 TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
1040 TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
1041 sidebandsemu->Add(jzbnegative,-1);
1042
1043 jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1044 jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1045 sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1046 sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1047
1048 THStack predcomposition("predcomposition","prediction composition");
1049 predcomposition.Add(sidebandsemu);
1050 predcomposition.Add(jzbnegative);
1051 blankback->Draw();
1052 RcorrJZBeemm->Draw("e1x0,same");
1053 predcomposition.Draw("histo,same");//
1054 Bpred->Draw("hist,same");
1055 // analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1056 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1057 // lm4RcorrJZBeemm->SetLineColor(kOrange+1);
1058 lm4RcorrJZBeemm->SetLineWidth(2);
1059 //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
1060 lm4RcorrJZBeemm->Draw("histo,same");
1061 DrawPrelim();
1062 TLegend *speciallegBpred = make_legend("",0.45,0.55);
1063 //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
1064 speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
1065 speciallegBpred->AddEntry(Bpred,"Total background","l");
1066 speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
1067 speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
1068 // speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
1069 speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1070 speciallegBpred->Draw();
1071 save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,use_data!=1,"data/pred");
1072
1073 TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
1074 THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
1075 blankback->Draw();
1076 kostack.Draw("same");
1077 Bpred->Draw("hist,same");
1078 analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1079 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1080 legBpred->Draw();
1081 DrawPrelim();
1082 CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
1083 Bpred->SetLineWidth((int)CurrentBpredLineWidth);
1084
1085 delete speciallegBpred;
1086 delete Zjetspred;
1087 delete TTbarpred;
1088
1089 kinpad->cd();
1090 }
1091 if(use_data==0) {
1092 RcorrJZBeemm->Draw("e1x0,same");
1093 //Bpred->SetLineWidth(3); // paper style. overruled.
1094 Bpred->Draw("hist,same");
1095 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1096 legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1097 legBpred->AddEntry(Bpred,"MC predicted","l");
1098 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
1099 if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
1100 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1101 legBpred->Draw();
1102 DrawMCPrelim();
1103 Bpredsaveas="Bpred_MC";
1104 // CompleteSave(globalcanvas,"Bpred_MC"); // done below in save_with_ratio
1105 }
1106 if(use_data==2) {
1107 RcorrJZBeemm->Draw("e1x0,same");
1108 //Bpred->SetLineWidth(3); // paper style. overruled.
1109 Bpred->Draw("hist,same");
1110 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1111 legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1112 legBpred->AddEntry(Bpred,"MC predicted","l");
1113 legBpred2->AddEntry(RcorrJZBeemm,"MC true","p");
1114 legBpred2->AddEntry(Bpred,"MC predicted","l");
1115 {
1116 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
1117 if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
1118 legBpred->Draw();
1119 DrawMCPrelim();
1120 Bpredsaveas="Bpred_MCwithS";
1121 // CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
1122 }
1123 {
1124 //lm4RcorrJZBeemm->SetLineWidth(3); //paper style. overruled.
1125 //RcorrJZBeemmNoS->SetLineWidth(3); //paper style. overruled.
1126 //lm4RcorrJZBeemm->SetLineStyle(2); //paper style. overruled.
1127 //RcorrJZBeemmNoS->SetLineStyle(3); //paper style. overruled.
1128 //lm4RcorrJZBeemm->SetLineColor(kOrange+1); //paper style. overruled.
1129
1130 RcorrJZBeemmNoS->SetLineStyle(2);
1131 legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
1132 legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
1133 legBpred2->Draw();
1134 RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
1135 RcorrJZBeemmNoS->Draw("histo,same");
1136 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1137 lm4RcorrJZBeemm->Draw("histo,same");
1138 DrawMCPrelim();
1139 Bpredsaveas="Bpred_MCwithS__plus";
1140 // CompleteSave(globalcanvas,"Bpred_MCwithS__plus"); // done below in save_with_ratio
1141 }
1142 }
1143
1144
1145 //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
1146 string ytitle("ratio");
1147 if ( use_data==1 ) ytitle = "data/pred";
1148 //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
1149 save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle);//not extending the y range anymore up to 4
1150
1151
1152 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1153 /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1154 if(PlottingSetup::RestrictToMassPeak) {
1155 TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1156 Bpredem->Add(RcorrJZBem);
1157 Bpredem->Add(LcorrJZBem,-1);
1158 TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1159 BpredSBem->Add(RcorrJZBSBem);
1160 Bpred->Add(LcorrJZBSBem,-1);
1161 TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");
1162 BpredSBeemm->Add(RcorrJZBSBeemm);
1163 BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1164 globalcanvas->cd();
1165 globalcanvas->SetLogy(1);
1166
1167 RcorrJZBeemm->SetMarkerStyle(20);
1168 RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1169 blankback->Draw();
1170 RcorrJZBeemm->Draw("e1x0,same");
1171 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1172
1173 Bpredem->SetLineColor(kRed+1);
1174 Bpredem->SetStats(0);
1175 Bpredem->Draw("hist,same");
1176
1177 BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1178 BpredSBem->SetLineStyle(2);
1179 BpredSBem->Draw("hist,same");
1180
1181 BpredSBeemm->SetLineColor(kBlue+1);
1182 BpredSBeemm->SetLineStyle(3);
1183 BpredSBeemm->Draw("hist,same");
1184 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1185
1186 TLegend *legBpredc = make_legend("",0.6,0.55);
1187 if(use_data==1)
1188 {
1189 legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1190 legBpredc->AddEntry(Bpredem,"OFZP","l");
1191 legBpredc->AddEntry(BpredSBem,"OFSB","l");
1192 legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1193 legBpredc->Draw();
1194 CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
1195 }
1196 if(use_data==0) {
1197 legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1198 legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1199 legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1200 legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1201 legBpredc->Draw();
1202 CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
1203 }
1204 if(use_data==2) {
1205 legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1206 legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1207 legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1208 legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1209 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1210 legBpredc->Draw();
1211 CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
1212 }
1213 }
1214
1215 delete RcorrJZBeemm;
1216 delete LcorrJZBeemm;
1217 delete RcorrJZBem;
1218 delete LcorrJZBem;
1219
1220 delete JRcorrJZBeemm;
1221 delete JLcorrJZBeemm;
1222 delete JRcorrJZBem;
1223 delete JLcorrJZBem;
1224
1225 delete blankback;
1226
1227 if(PlottingSetup::RestrictToMassPeak) {
1228 delete RcorrJZBSBem;
1229 delete LcorrJZBSBem;
1230 delete RcorrJZBSBeemm;
1231 delete LcorrJZBSBeemm;
1232
1233 delete JRcorrJZBSBem;
1234 delete JLcorrJZBSBem;
1235 delete JRcorrJZBSBeemm;
1236 delete JLcorrJZBSBeemm;
1237 }
1238 if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1239 switch_overunderflow(false);
1240 }
1241
1242 void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
1243 TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
1244 do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
1245 if ( !PlottingSetup::Approved ) {
1246 do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
1247 do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
1248 } else {
1249 write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
1250 }
1251 }
1252
1253 void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1254 bool do_data=0;
1255 bool dosignal=0;
1256 if(is_data==1) do_data=1;
1257 if(is_data==2) dosignal=1;
1258 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1259 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1260 TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1261 TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1262
1263 TH1F *RcorrJZBSBem;
1264 TH1F *LcorrJZBSBem;
1265 TH1F *RcorrJZBSBeemm;
1266 TH1F *LcorrJZBSbeemm;
1267
1268 if(PlottingSetup::RestrictToMassPeak) {
1269 RcorrJZBSBem = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1270 LcorrJZBSBem = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1271 RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1272 LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1273 }
1274
1275
1276
1277
1278 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1279 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1280 if(PlottingSetup::RestrictToMassPeak) {
1281 Bpred->Add(RcorrJZBem,1.0/3);
1282 Bpred->Add(LcorrJZBem,-1.0/3);
1283 Bpred->Add(RcorrJZBSBem,1.0/3);
1284 Bpred->Add(LcorrJZBSBem,-1.0/3);
1285 Bpred->Add(RcorrJZBSBeemm,1.0/3);
1286 Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1287 } else {
1288 Bpred->Add(RcorrJZBem,1.0);
1289 Bpred->Add(LcorrJZBem,-1.0);
1290 }
1291
1292 can->cd();
1293 can->SetLogy(0);
1294 Bpred->SetLineColor(kRed);
1295 Bpred->SetStats(0);
1296 if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1297 TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1298 JZBratioforfitting->Divide(Bpred);
1299 TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1300
1301
1302 JZBratio->SetTitle("");
1303 JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1304 // if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1305
1306 TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1307 TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1308 // straightline_fit->SetParameter(0,1);
1309 JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1310 pol0d->SetParameter(0,pol0->GetParameter(0));
1311
1312 JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1313 JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1314 if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1315 JZBratio->GetYaxis()->SetNdivisions(519);
1316 JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1317 JZBratio->GetYaxis()->CenterTitle();
1318 JZBratio->GetXaxis()->CenterTitle();
1319 JZBratio->SetMarkerSize(DataMarkerSize);
1320 JZBratio->Draw("AP");
1321 /////----------------------------
1322 TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1323 writeresult->SetFillStyle(4000);
1324 writeresult->SetFillColor(kWhite);
1325 writeresult->SetTextFont(42);
1326 writeresult->SetTextSize(0.03);
1327 writeresult->SetTextAlign(12);
1328 ostringstream jzb_agreement_data_text;
1329 jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) << pol0->GetParError(0);
1330 if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1331 if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1332 /* if(is_data) writeresult->AddText("Data closure test");
1333 else writeresult->AddText("MC closure test");
1334 */
1335 writeresult->AddText(jzb_agreement_data_text.str().c_str());
1336 // writeresult->Draw("same");
1337 // pol0d->Draw("same");
1338 TF1 *topline = new TF1("","1.5",0,1000);
1339 TF1 *bottomline = new TF1("","0.5",0,1000);
1340 topline->SetLineColor(kBlue);
1341 topline->SetLineStyle(2);
1342 bottomline->SetLineColor(kBlue);
1343 bottomline->SetLineStyle(2);
1344 // topline->Draw("same");
1345 // bottomline->Draw("same");
1346 TF1 *oneline = new TF1("","1.0",0,1000);
1347 oneline->SetLineColor(kBlue);
1348 oneline->SetLineStyle(1);
1349 oneline->Draw("same");
1350 TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
1351 if(is_data==1) DrawPrelim();
1352 else DrawMCPrelim();
1353 TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1354 leg->SetTextFont(42);
1355 leg->SetTextSize(0.04);
1356 // if(is_data==1) leg->SetHeader("Ratio (data)");
1357 // else leg->SetHeader("Ratio (MC)");
1358
1359 TString MCtitle("MC ");
1360 if (is_data==1) MCtitle = "";
1361
1362 leg->SetFillStyle(4000);
1363 leg->SetFillColor(kWhite);
1364 leg->SetTextFont(42);
1365 // leg->AddEntry(topline,"+20\% sys envelope","l");
1366 leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1367 leg->AddEntry(oneline,"ratio = 1","l");
1368 // leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1369 // leg->AddEntry(bottomline,"#pm50% envelope","l");
1370
1371
1372 //leg->Draw("same"); // no longer drawing legend
1373
1374 if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1375 if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1376 if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1377
1378 delete RcorrJZBeemm;
1379 delete LcorrJZBeemm;
1380 delete RcorrJZBem;
1381 delete LcorrJZBem;
1382
1383 delete RcorrJZBSBem;
1384 delete LcorrJZBSBem;
1385 delete RcorrJZBSBeemm;
1386 delete LcorrJZBSbeemm;
1387 }
1388
1389 void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1390 TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1391 globalc->SetLogy(0);
1392
1393 do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh );
1394 do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh );
1395 do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh );
1396 }
1397
1398 string give_jzb_expression(float peak, int type) {
1399 stringstream val;
1400 if(type==data) {
1401 if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
1402 if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
1403 if(peak==0) val << jzbvariabledata;
1404 }
1405 if(type==mc) {
1406 if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
1407 if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
1408 if(peak==0) val << jzbvariablemc;
1409 }
1410 return val.str();
1411 }
1412
1413
1414 void lepton_comparison_plots() {
1415 Float_t ymin = 1.e-5, ymax = 0.25;
1416 TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
1417 can->SetLogy(1);
1418 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
1419 TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
1420 eemc->SetLineColor(kBlue);
1421 mmmc->SetLineColor(kRed);
1422 eemc->SetMinimum(0.1);
1423 eemc->SetMaximum(10*eemc->GetMaximum());
1424 eemc->Draw("histo");
1425 mmmc->Draw("histo,same");
1426 TLegend *leg = make_legend();
1427 leg->AddEntry(eemc,"ZJets->ee (MC)","l");
1428 leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
1429 leg->Draw("same");
1430 CompleteSave(can, "lepton_comparison/mll_effratio_mc");
1431
1432 TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
1433 TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
1434 eed->SetLineColor(kBlue);
1435 mmd->SetLineColor(kRed);
1436 eed->SetMinimum(0.1);
1437 eed->SetMaximum(10*eed->GetMaximum());
1438 eed->Draw("histo");
1439 mmd->Draw("histo,same");
1440 TLegend *leg2 = make_legend();
1441 leg2->AddEntry(eed,"ZJets->ee (data)","l");
1442 leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
1443 leg2->Draw();
1444 CompleteSave(can, "lepton_comparison/mll_effratio_data");
1445
1446 TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
1447 TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
1448 TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
1449 dout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
1450 dout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
1451 dout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
1452 jeemmd->SetLineColor(kBlack);
1453 jeemmd->SetMarkerStyle(25);
1454 jeed->SetLineColor(kBlue);
1455 jmmd->SetLineColor(kRed);
1456 jeed->SetMinimum(0.1);
1457 jeed->SetMaximum(10*eed->GetMaximum());
1458 TH1* njeemmd = jeemmd->DrawNormalized();
1459 njeemmd->SetMinimum(ymin);
1460 njeemmd->SetMaximum(ymax);
1461
1462 jeed->DrawNormalized("histo,same");
1463 jmmd->DrawNormalized("histo,same");
1464 jeemmd->DrawNormalized("same");
1465 TLegend *jleg2 = make_legend(" ");
1466 jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
1467 jleg2->AddEntry(jeed,"ee","l");
1468 jleg2->AddEntry(jmmd,"#mu#mu","l");
1469 jleg2->Draw();
1470 CompleteSave(can,"lepton_comparison/jzb_effratio_data");
1471
1472 TPad *eemmpad = new TPad("eemmpad","eemmpad",0,0,1,1);
1473 eemmpad->cd();
1474 eemmpad->SetLogy(1);
1475 jeed->Draw("histo");
1476 jmmd->Draw("histo,same");
1477 TLegend *eemmlegend = make_legend(" ");
1478 eemmlegend->AddEntry(jeed,"ee","l");
1479 eemmlegend->AddEntry(jmmd,"#mu#mu","l");
1480 eemmlegend->Draw();
1481 DrawPrelim();
1482 save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
1483
1484 TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
1485 TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
1486 TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets, mc, luminosity,allsamples.FindSample("/DY"));
1487 dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
1488 dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
1489 dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
1490 zjeemmd->SetLineColor(kBlack);
1491 zjeemmd->SetMarkerStyle(25);
1492 zjeed->SetLineColor(kBlue);
1493 zjmmd->SetLineColor(kRed);
1494 zjeed->SetMinimum(0.1);
1495 zjeed->SetMaximum(10*eed->GetMaximum());
1496
1497 TH1* nzjeemmd = zjeemmd->DrawNormalized();
1498 nzjeemmd->SetMinimum(ymin);
1499 nzjeemmd->SetMaximum(ymax);
1500 zjeed->DrawNormalized("histo,same");
1501 zjmmd->DrawNormalized("histo,same");
1502 zjeemmd->DrawNormalized("same");
1503 TLegend *zjleg2 = make_legend("Z+jets MC");
1504 zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
1505 zjleg2->AddEntry(jeed,"ee","l");
1506 zjleg2->AddEntry(jmmd,"#mu#mu","l");
1507 zjleg2->Draw();
1508 CompleteSave(can,"lepton_comparison/jzb_effratio_ZJets");
1509
1510 TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
1511 ld->DrawNormalized("e1");
1512 eed->DrawNormalized("histo,same");
1513 mmd->DrawNormalized("histo,same");
1514 TLegend *leg3 = make_legend();
1515 leg3->AddEntry(ld,"ZJets->ll (data)","p");
1516 leg3->AddEntry(eed,"ZJets->ee (data)","l");
1517 leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
1518 leg3->Draw();
1519 CompleteSave(can,"lepton_comparison/mll_effratio_data__all_compared");
1520 /*
1521 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1522 TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1523 */
1524 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1525 TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1526 jzbld->SetMarkerColor(kBlack);
1527 jzbld->SetMarkerStyle(26);
1528 jzbemd->SetMarkerStyle(25);
1529 jzbemd->SetMarkerColor(kRed);
1530 jzbemd->SetLineColor(kRed);
1531 jzbld->SetMinimum(0.35);
1532 jzbld->Draw("e1");
1533 jzbemd->Draw("e1,same");
1534 TLegend *leg4 = make_legend();
1535 leg4->AddEntry(jzbld,"SFZP","p");
1536 leg4->AddEntry(jzbemd,"OFZP","p");
1537 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
1538 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
1539 leg4->Draw();
1540 CompleteSave(can,"lepton_comparison/jzb_eemumu_emu_data");
1541
1542 TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
1543 TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
1544 ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
1545 ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
1546 ttbarjzbld->Draw("histo");
1547 ttbarjzbemd->SetLineStyle(2);
1548 ttbarjzbemd->Draw("histo,same");
1549 TLegend *leg5 = make_legend();
1550 leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
1551 leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
1552 leg5->Draw();
1553 CompleteSave(can,"lepton_comparison/ttbar_emu_mc");
1554
1555 }
1556
1557 bool is_OF(TCut cut) {
1558 string scut = (const char*) cut;
1559 if((int)scut.find("id1!=id2")>-1) return true;
1560 if((int)scut.find("id1==id2")>-1) return false;
1561 return false;
1562 }
1563
1564 bool is_ZP(TCut cut) {
1565 string scut = (const char*) cut;
1566 if((int)scut.find("91")>-1) return true;
1567 return false;
1568 }
1569
1570
1571 void draw_pure_jzb_histo(TCut cut,string datavariable, string mcvariable, string savename, TCanvas *can,vector<float> binning) {
1572 TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
1573 jzbpad->cd();
1574 jzbpad->SetLogy(1);
1575 string xlabel="JZB [GeV]";
1576
1577 TH1F *datahisto = allsamples.Draw("datahisto",datavariable,binning, xlabel, "events",cut,data,luminosity);
1578 THStack mcstack = allsamples.DrawStack("mcstack",mcvariable,binning, xlabel, "events",cut,mc,luminosity);
1579
1580 datahisto->SetMinimum(0.1);
1581 datahisto->SetMarkerSize(DataMarkerSize);
1582 datahisto->Draw("e1");
1583 mcstack.Draw("same");
1584 datahisto->Draw("same,e1");
1585
1586 TLegend *leg;
1587 if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
1588 else if(!is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1589 else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1590 else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1591 else {
1592 std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1593 exit(-1);
1594 }
1595 leg->Draw();
1596 string write_cut = decipher_cut(cut,"");
1597 TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1598 writeline1->SetTextSize(0.035);
1599 writeline1->Draw();
1600 if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1601 else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
1602 TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
1603 jzbpad2->cd();
1604 jzbpad2->SetLogy(1);
1605 datahisto->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
1606 datahisto->SetMinimum(0.1);
1607 datahisto->SetMarkerSize(DataMarkerSize);
1608 datahisto->Draw("e1");
1609 mcstack.Draw("same");
1610 datahisto->Draw("same,e1");
1611 leg->SetHeader("");
1612 leg->Draw();
1613 writeline1->SetTextSize(0.035);
1614 writeline1->Draw();
1615 DrawPrelim();
1616 if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1617 else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
1618 datahisto->Delete();
1619 mcstack.Delete();
1620 }
1621
1622 Double_t GausR(Double_t *x, Double_t *par) {
1623 return gRandom->Gaus(x[0],par[0]);
1624 }
1625
1626 void produce_stretched_jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1627 TCanvas *dican = new TCanvas("dican","JZB Plots Canvas");
1628 float max=jzbHigh ;
1629 float min=-120;
1630 int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
1631 int coarserbins=int(nbins/2.0);
1632 int rebinnedbins=int(nbins/4.0);
1633
1634 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1635 for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1636 for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1637 for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1638
1639 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP",dican,binning);
1640 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP",dican,binning);
1641 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_SFZP",dican,binning);
1642 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
1643 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
1644 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
1645 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
1646 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
1647
1648 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
1649 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
1650 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
1651 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
1652
1653 delete dican;
1654 }
1655
1656
1657 void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1658 vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
1659
1660 if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
1661 write_error(__FUNCTION__,"Could not find any diboson samples - aborting diboson plots");
1662 return;
1663 }
1664
1665 float stretchfactor = 100.0;
1666 vector<string> labels;
1667
1668
1669 dout << "Going to increase the cross section for diboson samples ... " << endl;
1670 for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1671 float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1672 (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
1673 dout << " Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
1674 labels.push_back((allsamples.collection)[SamplesToBeModified[i]].samplename);
1675 (allsamples.collection)[SamplesToBeModified[i]].samplename=any2string(int(stretchfactor))+" x "+(allsamples.collection)[SamplesToBeModified[i]].samplename;
1676 dout << " (also renamed it to " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " )" << endl;
1677 }
1678
1679 dout << "Going to produce JZB plots" << endl;
1680 produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
1681 TCanvas *gloca = new TCanvas("gloca","gloca");
1682 float sigma=123456;
1683
1684 dout << "Going to produce prediction plots" << endl;
1685 do_prediction_plot(mcjzb, gloca, sigma, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
1686 do_prediction_plot(mcjzb, gloca, sigma, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
1687 delete gloca;
1688
1689 dout << "Going to reset the cross section for diboson samples ... " << endl;
1690 for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1691 float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1692 (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
1693 string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
1694 (allsamples.collection)[SamplesToBeModified[i]].samplename=labels[i];
1695 dout << " Reset xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " from " << Upxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ") and reset the correct name (from " << Upname << ")" << endl;
1696
1697 }
1698
1699 }
1700 void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1701 TCanvas *can = new TCanvas("can","JZB Plots Canvas");
1702 float max=jzbHigh ;
1703 float min=-120;
1704 int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
1705 int coarserbins=int(nbins/2.0);
1706 int rebinnedbins=int(nbins/4.0);
1707
1708 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1709 for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1710 for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1711 for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1712
1713 if ( !PlottingSetup::Approved ) {
1714 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
1715 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
1716 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
1717 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
1718 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
1719 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
1720 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1721 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
1722 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
1723 }
1724
1725 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1726 if ( !PlottingSetup::Approved ) {
1727 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1728 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1729 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1730 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1731 }
1732 delete can;
1733 }
1734
1735
1736 void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
1737 dout << "Calculating background yields in MC:" << endl;
1738 jzb_cuts.push_back(14000);
1739 TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
1740 float cumulative=0;
1741 for(int i=allbgs->GetNbinsX();i>=1;i--) {
1742 cumulative+=allbgs->GetBinContent(i);
1743 dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
1744 }
1745 }
1746
1747
1748 TCut give_jzb_expression(string mcjzb, float jzbcut, string posneg="pos") {
1749 stringstream res;
1750 res << "(" << mcjzb;
1751 if(posneg=="pos") res << ">";
1752 else res << "<-";
1753 res << jzbcut << ")";
1754 return TCut(res.str().c_str());
1755 }
1756
1757 string sigdig(float number, int nsigdig=3, float min=0) {
1758 //this function tries to extract n significant digits, and if the number is below (min), it returns "<min"
1759 if(number<min) return "< "+any2string(min);
1760 stringstream sol;
1761 sol << setprecision(nsigdig) << number;
1762
1763 return sol.str();
1764 }
1765
1766 string jzb_tex_command(string region, string posneg) {
1767 if(posneg=="pos") posneg="POS";
1768 else posneg="NEG";
1769 stringstream texcommand;
1770 texcommand<<"\\"<<region <<"JZB"<<posneg;
1771 return texcommand.str();
1772 }
1773 // \SFZPJZBPOS
1774 // Sample & \OFZPJZBPOS & \OFZPJZBNEG & \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS & \OFSBJZBNEG & \SFSBJZBPOS & \SFSBJZBNEG \\\hline
1775
1776 void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
1777 dout << "Calculating background yields in MC:" << endl;
1778
1779 TCanvas *yica = new TCanvas("yica","yield canvas");
1780
1781 int nRegions=4;
1782 if(!PlottingSetup::RestrictToMassPeak) nRegions=2;
1783 string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
1784 string posneg[] = {"pos","neg"};
1785 TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
1786
1787 for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
1788 TCut jzbMC[] = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
1789 dout << "_________________________________________________________" << endl;
1790 dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
1791 for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
1792 if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << " & ";
1793 else dout << "Sample & ";
1794 for(int iregion=0;iregion<nRegions;iregion++) {
1795 for(int ipos=0;ipos<2;ipos++) {
1796 if((allsamples.collection)[isample].is_data) dout << jzb_tex_command(tsRegions[iregion],posneg[ipos]) << " & ";
1797 else {
1798 vector<int> specific;specific.push_back(isample);
1799 TH1F *shisto = allsamples.Draw("shisto","mll",1,0,500,"tester","events",tkRegions[iregion]&&jzbMC[ipos],mc,luminosity,specific);
1800 dout << sigdig(shisto->Integral(),3,0.05) <<" & ";
1801 delete shisto;
1802 }
1803 }//end of ipos
1804 }//end of iregion
1805 dout << " \\\\" << endl;
1806 }//end of isample
1807 }//end of ijzb
1808 dout << " \\hline" << endl;
1809
1810 delete yica;
1811 }
1812
1813 void draw_ttbar_and_zjets_shape_for_one_configuration(string mcjzb, string datajzb, int leptontype=-1, int scenario=0,bool floating=false) {
1814 //Step 1: Establishing cuts
1815 stringstream jetcutstring;
1816 string writescenario="";
1817
1818 if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
1819 if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
1820 TCut jetcut(jetcutstring.str().c_str());
1821 string leptoncut="mll>0";
1822 if(leptontype==0||leptontype==1) {
1823 if(leptontype==0) {
1824 leptoncut="id1==0";
1825 writescenario="__ee";
1826 }
1827 else {
1828 leptoncut="id1==1";
1829 writescenario="__ee";
1830 }
1831 }
1832 TCut lepcut(leptoncut.c_str());
1833
1834 TCanvas *c5 = new TCanvas("c5","c5",1500,500);
1835 TCanvas *c6 = new TCanvas("c6","c6");
1836 c5->Divide(3,1);
1837
1838 //STEP 2: Extract Zjets shape in data
1839 c5->cd(1);
1840 c5->cd(1)->SetLogy(1);
1841 TCut massat40("mll>40");
1842 TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1843 TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1844 ossfleft->SetLineColor(kRed);
1845 ossfleft->SetMarkerColor(kRed);
1846 ossfleft->Add(osofleft,-1);
1847 vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
1848 ossfleft->SetMarkerSize(DataMarkerSize);
1849 ossfleft->Draw();
1850 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
1851 TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
1852 TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
1853 TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
1854 zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
1855 TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
1856 leg1->SetFillColor(kWhite);
1857 leg1->SetLineColor(kWhite);
1858 leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
1859 leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
1860 leg1->Draw("same");
1861 TText *titleleft = write_title("Extracting Z+Jets shape");
1862 titleleft->Draw();
1863
1864 //Step 3: Extract ttbar shape (in data or MC?)
1865 c5->cd(2);
1866 c5->cd(2)->SetLogy(1);
1867 TH1F *osof;
1868 TText *titlecenter;
1869 bool frommc=false;
1870 if(frommc) {
1871 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
1872 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
1873 }
1874 else {
1875 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1876 titlecenter = write_title("Extracting ttbar shape (from osof data)");
1877 }
1878 osof->SetMarkerSize(DataMarkerSize);
1879 osof->Draw();
1880 vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
1881 ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
1882 ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
1883 ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
1884
1885 TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
1886 leg2->SetFillColor(kWhite);
1887 leg2->SetLineColor(kWhite);
1888 if(frommc) {
1889 leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
1890 leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
1891 } else {
1892 leg2->AddEntry(osof,"OSOF","p");
1893 leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
1894 }
1895 leg2->Draw("same");
1896 titlecenter->Draw();
1897
1898 //--------------------------------------------------------------------------------------------------------------------------------
1899 //STEP 4: Present it!
1900 // actually: if we wanna let it float we need to do that first :-)
1901 c5->cd(3);
1902 c5->cd(3)->SetLogy(1);
1903 TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1904 observed->SetMarkerSize(DataMarkerSize);
1905
1906 TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
1907 TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
1908 TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
1909
1910 TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
1911 TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
1912 TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
1913
1914 TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
1915 TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
1916 TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
1917
1918 zjetsc->SetParameters(zjetsfunc->GetParameters());
1919 zjetscp->SetParameters(zjetsfunc->GetParameters());
1920 zjetscn->SetParameters(zjetsfunc->GetParameters());
1921
1922 TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1923 //blublu
1924 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1925 logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
1926 logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
1927 if(floating) {
1928 dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
1929 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1930 for(int i=0;i<10;i++) {
1931 if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
1932 if(i>=5) {
1933 if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
1934 if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
1935 }
1936 }//end of setting parameters
1937 observeda->Draw("same");
1938 ZplusJetsplusTTbar->Draw("same");
1939 observeda->Fit(ZplusJetsplusTTbar);
1940 dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
1941 ZplusJetsplusTTbar->Draw("same");
1942 ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
1943 ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
1944 dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
1945 float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
1946 dout << "FACTOR: " << factor << endl;
1947 logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1948 logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1949 logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1950 }
1951
1952 c5->cd(3);
1953 c5->cd(3)->SetLogy(1);
1954 observed->Draw();
1955 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1956 logparc->Draw("same");
1957 logparcn->Draw("same");
1958 logparcp->Draw("same");
1959
1960 TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
1961 leg3->SetFillColor(kWhite);
1962 leg3->SetLineColor(kWhite);
1963 leg3->AddEntry(observed,"OSSF,JZB>peak","p");
1964 leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
1965 leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
1966 leg3->Draw("same");
1967 TText *titleright = write_title("Summary of shapes and observed shape");
1968 titleright->Draw();
1969
1970 c6->cd()->SetLogy(1);
1971 observed->Draw();
1972 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1973 logparc->Draw("same");
1974 logparcn->Draw("same");
1975 logparcp->Draw("same");
1976 leg3->Draw("same");
1977 titleright->Draw();
1978
1979 if(scenario==0) {
1980 CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
1981 CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
1982 CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
1983 CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
1984 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
1985 } else {
1986 CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
1987 CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
1988 CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
1989 CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
1990 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
1991 }
1992 dout << "Statistics about our fits: " << endl;
1993 dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
1994 dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
1995
1996 c6->cd();
1997 TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
1998 additionallegend->SetFillColor(kWhite);
1999 additionallegend->SetLineColor(kWhite);
2000 additionallegend->AddEntry(observed,"Data","p");
2001 additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
2002 additionallegend->AddEntry(zjetsc,"Z+jets","l");
2003 additionallegend->AddEntry(logparc,"TTbar","l");
2004 observed->Draw();
2005 ZplusJetsplusTTbar->SetLineColor(kGreen);
2006 ZplusJetsplusTTbarP->SetLineColor(kGreen);
2007 ZplusJetsplusTTbarN->SetLineColor(kGreen);
2008 ZplusJetsplusTTbarP->SetLineStyle(2);
2009 ZplusJetsplusTTbarN->SetLineStyle(2);
2010 TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
2011 ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
2012 ZplusJetsplusTTbar2->SetLineColor(kGreen);
2013 ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
2014 ZplusJetsplusTTbarN->SetFillColor(kWhite);
2015 ZplusJetsplusTTbarP->Draw("fcsame");
2016 ZplusJetsplusTTbarN->Draw("fcsame");
2017 TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
2018 TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
2019 TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
2020 hZplusJetsplusTTbar->SetMarkerSize(0);
2021 hZplusJetsplusTTbarP->SetMarkerSize(0);
2022 hZplusJetsplusTTbarN->SetMarkerSize(0);
2023 for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
2024 float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
2025 hZplusJetsplusTTbar->SetBinError(i,newerror);
2026 if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
2027 }
2028 hZplusJetsplusTTbarP->SetFillColor(kGreen);
2029 hZplusJetsplusTTbarN->SetFillColor(kWhite);
2030 hZplusJetsplusTTbarN->Draw("same");
2031
2032 ZplusJetsplusTTbar2->SetMarkerSize(0);
2033 ZplusJetsplusTTbar2->Draw("same");
2034
2035 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
2036 logparc->Draw("same");
2037 logparcn->Draw("same");
2038 logparcp->Draw("same");
2039 additionallegend->Draw("same");
2040 if(scenario==0) {
2041 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
2042 } else {
2043 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
2044 }
2045 //--------------------------------------------------------------------------------------------------------------------------------
2046 }
2047
2048 void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
2049 int all_leptons=-1;
2050 int threejetswith30gev=0;
2051 /*
2052 int twojetswith50gev=1;
2053 int electrons_only=0;
2054 int mu_only=1;
2055
2056 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
2057 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
2058
2059 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
2060 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
2061
2062 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
2063 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
2064 */
2065
2066 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
2067 }
2068
2069 void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
2070 //first: colorful plots
2071 TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
2072 cancorr->SetLogz();
2073 cancorr->SetRightMargin(0.13);
2074 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2075 TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
2076 if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
2077 TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
2078 (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
2079 niceresponseplotd->SetStats(0);
2080 niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2081 niceresponseplotd->GetYaxis()->SetTitle("Response");
2082 niceresponseplotd->GetXaxis()->CenterTitle();
2083 niceresponseplotd->GetYaxis()->CenterTitle();
2084 niceresponseplotd->Draw("COLZ");
2085 TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
2086 profd->SetMarkerSize(DataMarkerSize);
2087 profd->Fit("pol0","","same,e1",100,400);
2088 DrawPrelim();
2089 TText* title = write_text(0.5,0.7,"Data");
2090 title->SetTextAlign(12);
2091 title->Draw();
2092 TF1 *datapol=(TF1*)profd->GetFunction("pol0");
2093 float datacorrection=datapol->GetParameter(0);
2094 stringstream dataresstring;
2095 dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
2096 TText* restitle = write_text(0.5,0.65,dataresstring.str());
2097 restitle->SetTextAlign(12);
2098 restitle->SetTextSize(0.03);
2099 restitle->Draw();
2100 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
2101
2102 TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
2103 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
2104 niceresponseplotm->SetStats(0);
2105 niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2106 niceresponseplotm->GetYaxis()->SetTitle("Response");
2107 niceresponseplotm->GetXaxis()->CenterTitle();
2108 niceresponseplotm->GetYaxis()->CenterTitle();
2109 niceresponseplotm->Draw("COLZ");
2110 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
2111 TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
2112 profm->SetMarkerSize(DataMarkerSize);
2113 profm->Fit("pol0","","same,e1",100,400);
2114 DrawMCPrelim();
2115 title = write_text(0.5,0.7,"MC simulation");
2116 title->SetTextAlign(12);
2117 title->Draw();
2118 TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
2119 float mccorrection=mcpol->GetParameter(0);
2120 stringstream mcresstring;
2121 mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
2122 TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
2123 mcrestitle->SetTextAlign(12);
2124 mcrestitle->SetTextSize(0.03);
2125 mcrestitle->Draw();
2126 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
2127
2128
2129 //Step 2: Getting the result
2130 // TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
2131 stringstream jzbvardatas;
2132 if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
2133 if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
2134 jzbvardata=jzbvardatas.str();
2135 stringstream jzbvarmcs;
2136 if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
2137 if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
2138 jzbvarmc=jzbvarmcs.str();
2139 dout << "JZB Z pt correction summary : " << endl;
2140 dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
2141 dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
2142 }
2143
2144 void pick_up_events(string cut) {
2145 dout << "Picking up events with cut " << cut << endl;
2146 allsamples.PickUpEvents(cut);
2147 }
2148
2149 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
2150 dout << "Saving configuration template!" << endl;
2151 ofstream configfile;
2152 configfile.open("../DistributedModelCalculations/last_configuration.C");
2153 configfile<<"#include <iostream>\n";
2154 configfile<<"#include <vector>\n";
2155 configfile<<"#ifndef SampleClassLoaded\n";
2156 configfile<<"#include \"SampleClass.C\"\n";
2157 configfile<<"#endif\n";
2158 configfile<<"#define SetupLoaded\n";
2159 configfile<<"#ifndef ResultLibraryClassLoaded\n";
2160 configfile<<"#include \"ResultLibraryClass.C\"\n";
2161 configfile<<"#endif\n";
2162
2163 configfile<<"\nusing namespace std;\n\n";
2164
2165 configfile<<"namespace PlottingSetup { \n";
2166 configfile<<"string datajzb=\"datajzb_ERROR\";\n";
2167 configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
2168 configfile<<"vector<float>jzb_cuts;\n";
2169 configfile<<"vector<float>jzb_shape_limit_bins;\n";
2170 configfile<<"float MCPeakError=-999;\n";
2171 configfile<<"float DataPeakError=-999;\n";
2172 configfile<<"}\n\n";
2173
2174 configfile<<"void read_config() {\n";
2175 configfile<<"datajzb=\""<<datajzb<<"\";\n";
2176 configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
2177 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
2178 configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
2179 for(int i=0;i<(int)jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2180 configfile<<"\n\n";
2181 for(int i=0;i<(int)Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2182 for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2183 for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2184 configfile<<"\n\n";
2185 for(int i=0;i<(int)flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2186 for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2187 for(int i=0;i<(int)flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n\n";
2188 for(int i=0;i<(int)jzb_shape_limit_bins.size();i++) configfile<<"jzb_shape_limit_bins.push_back("<<jzb_shape_limit_bins[i]<<"); // JZB shape bin boundary at " << jzb_shape_limit_bins[i] << "\n";
2189 configfile<<"\n\n";
2190 configfile<<"\n\n";
2191 configfile<<"luminosity="<<luminosity<<";\n";
2192 configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
2193
2194 configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
2195
2196 configfile.close();
2197
2198 }
2199
2200 float get_nonzero_minimum(TH1F *histo) {
2201 float min=histo->GetMaximum();
2202 for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
2203 float curcont=histo->GetBinContent(ibin);
2204 if(curcont<min&&curcont>0) min=curcont;
2205 }
2206 return min;
2207 }
2208
2209 void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
2210 can->cd();
2211 float min=1;
2212 float max=histos[0]->GetMaximum();
2213 if(manualmin>=0) min=manualmin;
2214 else {
2215 for(int i=1;i<(int)histos.size();i++) {
2216 float curmin=get_nonzero_minimum(histos[i]);
2217 float curmax=histos[i]->GetMaximum();
2218 if(curmin<min) min=curmin;
2219 if(curmax>max) max=curmax;
2220 }
2221 }
2222 histos[0]->GetYaxis()->SetRangeUser(min,4*max);
2223 histos[0]->Draw(drawoption.c_str());
2224 stringstream drawopt;
2225 drawopt << drawoption << ",same";
2226 for(int i=1;i<(int)histos.size();i++) {
2227 histos[i]->Draw(drawopt.str().c_str());
2228 }
2229 }
2230
2231 void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
2232 //in the case of the on peak analysis, we compare the 3 control regions to the real value
2233 //in the case of the OFF peak analysis, we compare our control region to the real value
2234 TCut weightbackup=cutWeight;
2235 cutWeight="1.0";
2236 float simulatedlumi = luminosity; //in pb please - adjust to your likings
2237
2238
2239 TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2240 TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2241 TH1F *TSem;
2242 TH1F *nTSem;
2243 TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2244 TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2245 TH1F *TSeemm;
2246 TH1F *nTSeemm;
2247
2248 if(PlottingSetup::RestrictToMassPeak) {
2249 TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2250 nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2251 TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2252 nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2253 }
2254
2255 TCanvas *tcan = new TCanvas("tcan","tcan");
2256
2257 tcan->SetLogy(1);
2258
2259 TZeemm->SetLineColor(kBlack);
2260 TZem->SetLineColor(kRed);
2261 TZeemm->SetMarkerColor(kBlack);
2262 TZem->SetMarkerColor(kRed);
2263
2264
2265 if(PlottingSetup::RestrictToMassPeak) {
2266 TSem->SetLineColor(TColor::GetColor("#00A616"));
2267 TSeemm->SetLineColor(kMagenta+2);
2268 TSem->SetMarkerColor(TColor::GetColor("#00A616"));
2269 TSeemm->SetMarkerColor(kMagenta+2);
2270 TSem->SetLineStyle(2);
2271 TSeemm->SetLineStyle(3);
2272 }
2273
2274 vector<TH1F*> histos;
2275 histos.push_back(TZem);
2276 histos.push_back(TZeemm);
2277 if(PlottingSetup::RestrictToMassPeak) {
2278 histos.push_back(TSem);
2279 histos.push_back(TSeemm);
2280 }
2281 draw_all_ttbar_histos(tcan,histos,"histo",0.04);
2282
2283 TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
2284 leg->AddEntry(TZeemm,"SFZP","l");
2285 leg->AddEntry(TZem,"OFZP","l");
2286 if(PlottingSetup::RestrictToMassPeak) {
2287 leg->AddEntry(TSeemm,"SFSB","l");
2288 leg->AddEntry(TSem,"OFSB","l");
2289 }
2290 leg->Draw("same");
2291 DrawMCPrelim(simulatedlumi);
2292 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
2293 cout << __LINE__ << endl;
2294 TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2295 cout << __LINE__ << endl;
2296 TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2297 cout << __LINE__ << endl;
2298 TH1F *TSeemmcopy;
2299 TH1F *TSemcopy;
2300 if(PlottingSetup::RestrictToMassPeak) {
2301 TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2302 TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2303 }
2304
2305 TZem->Divide(TZeemm);
2306 TZem->SetMarkerStyle(21);
2307 if(PlottingSetup::RestrictToMassPeak) {
2308 TSem->Divide(TZeemm);
2309 TSeemm->Divide(TZeemm);
2310 TSem->SetMarkerStyle(24);
2311 TSeemm->SetMarkerStyle(32);
2312 }
2313
2314 tcan->SetLogy(0);
2315 TZem->GetYaxis()->SetRangeUser(0,2.5);
2316 TZem->GetYaxis()->SetTitle("ratio");
2317 TZem->Draw();
2318 if(PlottingSetup::RestrictToMassPeak) {
2319 TSem->Draw("same");
2320 TSeemm->Draw("same");
2321 }
2322
2323 float linepos=0.25;
2324 if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
2325 if(!PlottingSetup::RestrictToMassPeak) linepos=0.1; //sys uncertainty for iJZB
2326 TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
2327 TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2328 TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
2329
2330 /*write_warning(__FUNCTION__,"These two lines are to be removed!");
2331 TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
2332 TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
2333 topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
2334 bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
2335 topalt->Draw("same");bottomalt->Draw("same");*/
2336
2337
2338 top->SetLineColor(kBlue);top->SetLineStyle(2);
2339 bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2340 center->SetLineColor(kBlue);
2341
2342 top->Draw("same");
2343 center->Draw("same");
2344 bottom->Draw("same");
2345
2346 TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
2347 leg2->AddEntry(TZem,"OFZP / SFZP","ple");
2348 if(PlottingSetup::RestrictToMassPeak) {
2349 leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
2350 leg2->AddEntry(TSem,"OFSB / SFZP","ple");
2351 }
2352 leg2->AddEntry(bottom,"syst. envelope","l");
2353 leg2->SetX1(0.25);leg2->SetX2(0.6);
2354 leg2->SetY1(0.65);
2355
2356 leg2->Draw("same");
2357
2358 DrawMCPrelim(simulatedlumi);
2359 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
2360
2361
2362 ///-------------- second part: only look at the quantity we actually care about!
2363 TH1F *leftsfzp = (TH1F*)nTZeemm->Clone("leftsfzp");
2364 TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
2365 rightsfzp->Add(leftsfzp,-1);
2366 TH1F *leftofzp = (TH1F*)nTZem->Clone("leftofzp");
2367 TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
2368 rightofzp->Add(leftofzp,-1);
2369 TH1F *leftofsb;
2370 TH1F *rightofsb;
2371 TH1F *leftsfsb;
2372 TH1F *rightsfsb;
2373 if(PlottingSetup::RestrictToMassPeak) {
2374 leftofsb = (TH1F*)nTSem->Clone("leftofsb");
2375 rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
2376 rightofsb->Add(leftofsb,-1);
2377 leftsfsb = (TH1F*)nTSeemm->Clone("leftsfsb");
2378 rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
2379 rightsfsb->Add(leftsfsb,-1);
2380 }
2381
2382 tcan->SetLogy(1);
2383 rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
2384 rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
2385 rightsfzp->Draw("histo");
2386 rightofzp->Draw("histo,same");
2387 if(PlottingSetup::RestrictToMassPeak) {
2388 rightofsb->Draw("histo,same");
2389 rightsfsb->Draw("histo,same");
2390 }
2391 DrawMCPrelim(simulatedlumi);
2392
2393 TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2394 legA->AddEntry(rightsfzp,"SFZP","l");
2395 legA->AddEntry(rightofzp,"OFZP","l");
2396 if(PlottingSetup::RestrictToMassPeak) {
2397 legA->AddEntry(rightofsb,"SFSB","l");
2398 legA->AddEntry(rightsfsb,"OFSB","l");
2399 }
2400 legA->Draw();
2401
2402 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
2403
2404 tcan->SetLogy(0);
2405 rightofzp->Divide(rightsfzp);
2406 rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2407 rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
2408 rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2409 rightofzp->Draw();
2410 if(PlottingSetup::RestrictToMassPeak) {
2411 rightofsb->Divide(rightsfzp);
2412 rightsfsb->Divide(rightsfzp);
2413 rightofsb->Draw("same");
2414 rightsfsb->Draw("same");
2415 }
2416
2417 TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
2418 TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
2419 TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
2420
2421 top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2422 bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2423 center2->SetLineColor(kBlue);
2424
2425 top2->Draw("same");
2426 center2->Draw("same");
2427 bottom2->Draw("same");
2428
2429 rightofzp->SetMarkerStyle(21);
2430 if(PlottingSetup::RestrictToMassPeak) {
2431 rightofsb->SetMarkerStyle(24);
2432 rightsfsb->SetMarkerStyle(32);
2433 }
2434
2435 TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2436 leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2437 if(PlottingSetup::RestrictToMassPeak) {
2438 leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2439 leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
2440 }
2441 leg3->AddEntry(bottom,"syst. envelope","l");
2442 leg3->SetX1(0.25);leg3->SetX2(0.6);
2443 leg3->SetY1(0.65);
2444
2445 leg3->Draw("same");
2446
2447 DrawMCPrelim(simulatedlumi);
2448 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
2449
2450 delete TZem;
2451 delete nTZem;
2452 delete TZeemm;
2453 delete nTZeemm;
2454 if(PlottingSetup::RestrictToMassPeak) {
2455 delete TSem;
2456 delete nTSem;
2457 delete TSeemm;
2458 delete nTSeemm;
2459 }
2460
2461 delete tcan;
2462 cutWeight=weightbackup;
2463 }
2464
2465 void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
2466 vector<float> nicer_binning;
2467 nicer_binning.push_back(-125);
2468 nicer_binning.push_back(-100);
2469 nicer_binning.push_back(-75);
2470 nicer_binning.push_back(-50);
2471 nicer_binning.push_back(-25);
2472 nicer_binning.push_back(0);
2473 nicer_binning.push_back(25);
2474 nicer_binning.push_back(50);
2475 nicer_binning.push_back(75);
2476 nicer_binning.push_back(100);
2477 nicer_binning.push_back(125);
2478 nicer_binning.push_back(150);
2479 nicer_binning.push_back(175);
2480 nicer_binning.push_back(200);
2481 nicer_binning.push_back(230);
2482 nicer_binning.push_back(280);
2483 nicer_binning.push_back(400);
2484 ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
2485 }
2486
2487
2488 void zjets_prediction_comparison() {
2489 // Do it without PU re-weighting
2490 float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2491 stringstream resultsNoPU;
2492
2493 stringstream mcjzbnoPU;
2494 find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
2495 if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
2496 else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
2497
2498 string mcjzb = mcjzbnoPU.str();
2499 dout << "The peak corrected JZB expression for MC without pileup is : " << mcjzb << endl;
2500
2501 TCut weightbackup=cutWeight;
2502 cutWeight="1.0";
2503 float sbg_min=0.;
2504 float sbg_max=100.;
2505 int sbg_nbins=5;
2506 float simulatedlumi = luminosity;//in pb please - adjust to your likings
2507
2508 TCut kPos((mcjzb+">0").c_str());
2509 TCut kNeg((mcjzb+"<0").c_str());
2510 string var( "abs("+mcjzb+")" );
2511
2512 TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
2513 TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2514 kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2515 TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2516 kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2517 hJZBpos->SetLineColor(kBlack);
2518 hJZBneg->SetLineColor(kRed);
2519
2520 TCanvas *zcan = new TCanvas("zcan","zcan");
2521 zcan->SetLogy(1);
2522
2523 hJZBpos->Draw("e1");
2524 hJZBneg->Draw("same,hist");
2525 hJZBpos->Draw("same,e1"); // So it's on top...
2526
2527 TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
2528 leg->AddEntry(hJZBpos,"Observed","pe");
2529 leg->AddEntry(hJZBneg,"Predicted","l");
2530 leg->Draw("same");
2531 DrawMCPrelim(simulatedlumi);
2532 CompleteSave(zcan,"Systematics/zjets_prediction");
2533
2534 TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
2535 hratio->Divide(hJZBneg);
2536
2537 zcan->SetLogy(0);
2538 hratio->GetYaxis()->SetRangeUser(0,2.5);
2539 hratio->GetYaxis()->SetTitle("Observed/Predicted");
2540 hratio->Draw("e1");
2541
2542 TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
2543 TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
2544 TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
2545
2546
2547 top->SetLineColor(kBlue);top->SetLineStyle(2);
2548 bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2549 center->SetLineColor(kBlue);
2550
2551 top->Draw("same");
2552 center->Draw("same");
2553 bottom->Draw("same");
2554
2555 TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
2556 leg2->AddEntry(hratio,"obs / pred","pe");
2557 leg2->AddEntry(bottom,"syst. envelope","l");
2558 leg2->Draw("same");
2559 DrawMCPrelim(simulatedlumi);
2560 CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
2561
2562 delete zcan;
2563 cutWeight=weightbackup;
2564
2565 }
2566
2567
2568
2569 void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
2570 tout << endl << endl;
2571 stringstream bordercut;
2572 bordercut << "(TMath::Abs(" << datajzb << ")<" << max << ")&&(TMath::Abs(" << datajzb << ")>" << min << ")";
2573 tout << bordercut.str().c_str() << endl;
2574 TH1F *ofsb = allsamples.Draw("ofsb",datajzb,100, 0,100, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2575 TH1F *ofzp = allsamples.Draw("ofzp",datajzb,100, 0,100, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2576 float OFSB = ofsb->Integral();
2577 float OFZP = ofzp->Integral();
2578
2579 tout << "\\begin{table}[hbtp]" << endl;
2580 tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
2581 tout << "\\begin{center}" << endl;
2582 tout << "\\caption{Total number of events observed in the auxiliary region $|JZB|>"<<min<<"\\GeV \\cup |JZB|<"<<max<<"\\GeV$ for the {\\OFZP} and {\\OFSB}.}\\label{tab:auxcounts}" << endl;
2583 tout << "\\begin{tabular}{l|cc}" << endl;
2584 tout << "\\hline" << endl;
2585 tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
2586 tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
2587 tout << "\\end{tabular}" << endl;
2588 tout << "\\end{center}" << endl;
2589 tout << "\\end{table}" << endl;
2590
2591
2592 }
2593
2594 void make_table(samplecollection &coll, string jzbexpr, bool is_data, vector<float> jzb_cuts, string subselection="none") {
2595
2596 vector<float> jzbcutprediction;
2597 vector<float> metcutprediction;
2598
2599 vector<float> jzbcutobservation;
2600 vector<float> metcutobservation;
2601
2602 TCanvas *cannie = new TCanvas("cannie","cannie");
2603
2604 for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
2605 float currcut=jzb_cuts[icut];
2606 int nbins=1;float low=currcut;
2607 vector<int> mysample;
2608 if(subselection!="none") mysample=coll.FindSample(subselection);
2609 TH1F *RcorrJZBeemm = coll.Draw("RcorrJZBeemm",jzbexpr,1,currcut,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2610 TH1F *LcorrJZBeemm = coll.Draw("LcorrJZBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2611 TH1F *RcorrJZBem = coll.Draw("RcorrJZBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2612 TH1F *LcorrJZBem = coll.Draw("LcorrJZBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2613
2614 TH1F *RcorrJZBSBem;
2615 TH1F *LcorrJZBSBem;
2616 TH1F *RcorrJZBSBeemm;
2617 TH1F *LcorrJZBSBeemm;
2618
2619 if(PlottingSetup::RestrictToMassPeak) {
2620 RcorrJZBSBem = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2621 LcorrJZBSBem = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2622 RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2623 LcorrJZBSBeemm = coll.Draw("LcorrJZBSBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2624 }
2625
2626 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2627 if(PlottingSetup::RestrictToMassPeak) {
2628 Bpred->Add(RcorrJZBem,1.0/3.);
2629 Bpred->Add(LcorrJZBem,-1.0/3.);
2630 Bpred->Add(RcorrJZBSBem,1.0/3.);
2631 Bpred->Add(LcorrJZBSBem,-1.0/3.);
2632 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2633 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2634 } else {
2635 Bpred->Add(RcorrJZBem,1.0);
2636 Bpred->Add(LcorrJZBem,-1.0);
2637 }
2638
2639 jzbcutobservation.push_back(RcorrJZBeemm->Integral());
2640 jzbcutprediction.push_back(Bpred->Integral());
2641
2642 delete RcorrJZBeemm;
2643 delete LcorrJZBeemm;
2644 delete RcorrJZBem;
2645 delete LcorrJZBem;
2646 delete RcorrJZBSBem;
2647 delete LcorrJZBSBem;
2648 delete RcorrJZBSBeemm;
2649 delete LcorrJZBSBeemm;
2650
2651 TH1F *MetObs = coll.Draw("MetObs",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2652 TH1F *MetPred = coll.Draw("MetPred",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2653
2654 metcutobservation.push_back(MetObs->Integral());
2655 metcutprediction.push_back(MetPred->Integral());
2656 delete MetObs;
2657 delete MetPred;
2658 }//end of cut loop
2659
2660 //prediction part
2661 if(is_data) cout << "Data prediction & ";
2662 if(subselection!="none") cout << subselection << " prediction &";
2663 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
2664
2665 cout << endl;
2666 //observation part
2667 if(is_data) cout << "Data observation & ";
2668 if(subselection!="none") cout << subselection << " observation &";
2669 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
2670 cout << endl;
2671 cout << "_________________________________________________________________" << endl;
2672 delete cannie;
2673 }
2674
2675 void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
2676 /*we want a table like this:
2677 __________________ 50 | 100 | ...
2678 | Data prediction | a vs b | a vs b | ...
2679 | Data observed | a vs b | a vs b | ...
2680 --------------------------------------
2681 --------------------------------------
2682 | LM4 prediction | a vs b | a vs b | ...
2683 | LM4 observed | a vs b | a vs b | ...
2684 | LM8 prediction | a vs b | a vs b | ...
2685 | LM8 observed | a vs b | a vs b | ...
2686
2687 where a is the result for a jzb cut at X, and b is the result for a met cut at X
2688 */
2689 make_table(allsamples,datajzb, true,jzb_cut,"none");
2690 make_table(signalsamples,mcjzb, false,jzb_cut,"LM4");
2691 make_table(signalsamples,mcjzb, false,jzb_cut,"LM8");
2692 }
2693
2694
2695 //________________________________________________________________________________________
2696 // JZB Efficiency plot (efficiency of passing reco. JZB cut as function of generator JZB cut)
2697 void JZBSelEff(string mcjzb, TTree* events, string informalname, vector<float> jzb_bins) {
2698
2699 float min = 0, max = 400;
2700 float xbins[] = {min,10,20,30,40,50,60,70,80,90,100,110,120,140,150,160,170,180,190,200,210,220,250,300,max,max+100};
2701 int nbins = sizeof(xbins)/sizeof(float)-1;
2702 int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
2703
2704
2705 TH1F* heff = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
2706 TH1F* hgen = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
2707 TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
2708
2709 TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
2710 TCut kreco(cutmass);
2711
2712 TF1* func = new TF1("func","0.5*[2]*(TMath::Erf((x-[1])/[0])+1)",min,max);
2713 func->SetParNames("epsilon","x_{1/2}","sigma");
2714 func->SetParameter(0,50.);
2715 func->SetParameter(1,0.);
2716 func->SetParameter(2,1.);
2717 gStyle->SetOptStat(0);
2718 gStyle->SetOptFit(0);
2719
2720 TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
2721 can->SetGridx(1);
2722 can->SetGridy(1);
2723 can->SetLeftMargin(0.16);
2724 can->SetRightMargin(0.05);
2725 TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
2726 leg->SetBorderSize(1);
2727 leg->SetLineColor(kBlack);
2728 leg->SetTextFont(62);
2729
2730 for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
2731
2732 ostringstream selection;
2733 selection << mcjzb << ">" << jzb_bins[icut];
2734 TCut ksel(selection.str().c_str());
2735 events->Draw("genJZB>>hgen", kgen&&kreco, "goff");
2736 events->Draw("genJZB>>hreco",kgen&&kreco&&ksel,"goff");
2737
2738 // Loop over steps to get efficiency curve
2739 for ( Int_t iBin = 0; iBin<nbins-1; ++iBin ) {
2740 Float_t eff = hreco->GetBinContent(iBin+1)/hgen->GetBinContent(iBin+1);
2741 heff->SetBinContent(iBin+1,eff);
2742 heff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/hgen->GetBinContent(iBin+1)));
2743 }
2744
2745 heff->GetXaxis()->SetRangeUser(min, max);
2746 // heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
2747 // heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
2748 // heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
2749 // heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
2750 heff->SetMarkerStyle(markers[icut]);
2751 heff->Fit("func","Q+","same");
2752
2753 // Print values
2754 dout << "+++ For " << selection.str() << std::endl;
2755 for ( int i=0; i<func->GetNpar(); ++i )
2756 dout << " " << func->GetParName(i) << " " << func->GetParameter(i) << " \\pm " << func->GetParError(i) << std::endl;
2757 char hname[256]; sprintf(hname,"heff%d",icut);
2758
2759 // Store plot
2760 TH1F* h = (TH1F*)heff->Clone(hname);
2761 h->SetNdivisions(505,"X");
2762 if ( icut) h->Draw("same");
2763 else h->Draw();
2764 char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
2765 leg->AddEntry(h,htitle,"p");
2766
2767 }
2768
2769 leg->Draw();
2770 DrawMCPrelim(0.0);
2771 CompleteSave(can, "Systematics/jzb_efficiency_curve"+informalname );
2772
2773 delete hgen;
2774 delete hreco;
2775 delete heff;
2776 }
2777
2778 //________________________________________________________________________________________
2779 // Calls the above function for each signal sample
2780 void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
2781 {
2782 for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
2783 dout << "JZB selection efficiency curve: " << std::endl;
2784 JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
2785 }
2786 }
2787
2788 void qcd_plots(string datajzb, string mcjzb, vector<float> bins) {
2789 // What this function aims to do:
2790 // Illustrate cut flow for QCD (requiring only one lepton, requiring etc.)
2791 // Illustrate how little QCD is left over! i.e. make some pointless JZB plot with only QCD to visualize the fact that there's not much really.
2792 TCanvas *can = new TCanvas("can","can");
2793 TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2794 kinpad->cd();
2795
2796 string jzb=mcjzb;
2797
2798 float hi=400;
2799 bool use_signal=false;
2800 bool use_data=false;
2801
2802 bool is_data=false;
2803 int nbins=50;//100;
2804 float low=0;
2805 float high=500;
2806 int versok=false;
2807 if(gROOT->GetVersionInt()>=53000) versok=true;
2808
2809 TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2810 TH1F *RcorrJZBeemm = qcdsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2811 TH1F *LcorrJZBeemm = qcdsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2812 TH1F *RcorrJZBem = qcdsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2813 TH1F *LcorrJZBem = qcdsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2814 blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2815 blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
2816 blankback->GetXaxis()->CenterTitle();
2817 blankback->GetYaxis()->CenterTitle();
2818
2819 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2820 TH1F *RcorrJZBSBem;
2821 TH1F *LcorrJZBSBem;
2822 TH1F *RcorrJZBSBeemm;
2823 TH1F *LcorrJZBSBeemm;
2824
2825 // TH1F *RcorrJZBeemmNoS;
2826
2827 //these are for the ratio
2828 TH1F *JRcorrJZBeemm = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2829 TH1F *JLcorrJZBeemm = qcdsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2830 TH1F *JRcorrJZBem = qcdsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2831 TH1F *JLcorrJZBem = qcdsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2832
2833 TH1F *JRcorrJZBSBem;
2834 TH1F *JLcorrJZBSBem;
2835 TH1F *JRcorrJZBSBeemm;
2836 TH1F *JLcorrJZBSBeemm;
2837
2838 if(PlottingSetup::RestrictToMassPeak) {
2839 RcorrJZBSBem = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2840 LcorrJZBSBem = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2841 RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2842 LcorrJZBSBeemm = qcdsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2843
2844 //these are for the ratio
2845 JRcorrJZBSBem = qcdsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2846 JLcorrJZBSBem = qcdsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2847 JRcorrJZBSBeemm = qcdsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2848 JLcorrJZBSBeemm = qcdsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2849
2850 }
2851
2852 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2853
2854 TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
2855 TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
2856
2857 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2858 TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
2859 if(PlottingSetup::RestrictToMassPeak) {
2860 Bpred->Add(RcorrJZBem,1.0/3.);
2861 Bpred->Add(LcorrJZBem,-1.0/3.);
2862 Bpred->Add(RcorrJZBSBem,1.0/3.);
2863 Bpred->Add(LcorrJZBSBem,-1.0/3.);
2864 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2865 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2866
2867 TTbarpred->Scale(1.0/3);
2868 Zjetspred->Add(LcorrJZBem,-1.0/3.);
2869 Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
2870 TTbarpred->Add(RcorrJZBSBem,1.0/3.);
2871 Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
2872 TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
2873
2874 //these are for the ratio
2875 JBpred->Add(JRcorrJZBem,1.0/3.);
2876 JBpred->Add(JLcorrJZBem,-1.0/3.);
2877 JBpred->Add(JRcorrJZBSBem,1.0/3.);
2878 JBpred->Add(JLcorrJZBSBem,-1.0/3.);
2879 JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
2880 JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
2881 } else {
2882 Bpred->Add(RcorrJZBem,1.0);
2883 Bpred->Add(LcorrJZBem,-1.0);
2884
2885 Zjetspred->Add(LcorrJZBem,-1.0);
2886
2887 //these are for the ratio
2888 JBpred->Add(JRcorrJZBem,1.0);
2889 JBpred->Add(JLcorrJZBem,-1.0);
2890 }
2891
2892
2893 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2894
2895 TLegend *legBpred = make_legend("",0.6,0.55,false);
2896 RcorrJZBeemm->Draw("e1x0,same");
2897 Bpred->Draw("hist,same");
2898 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2899 legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
2900 legBpred->AddEntry(Bpred,"MC predicted","l");
2901 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
2902 if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
2903 legBpred->Draw();
2904 DrawMCPrelim();
2905
2906 //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
2907 string ytitle("ratio");
2908 if ( use_data==1 ) ytitle = "data/pred";
2909 save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,use_data!=1,ytitle);
2910
2911 TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
2912 TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
2913 TH1F *osof = qcdsamples.Draw("osof","pfJetGoodNum",1,0,100, "internal code", "events", cutOSOF ,mc, luminosity);
2914 TH1F *njossf = qcdsamples.Draw("njossf","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSSF ,mc, luminosity);
2915 TH1F *njosof = qcdsamples.Draw("njosof","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSOF ,mc, luminosity);
2916
2917 dout << "______________________________________________" << endl;
2918 dout << "QCD contribution: " << endl;
2919 dout << "Total number of events: " << allevents->Integral() << endl;
2920 dout << "OSSF events: " << ossf->Integral() << endl;
2921 dout << "OSOF events: " << osof->Integral() << endl;
2922 dout << "OSSF events with >=3 jets:" << njossf->Integral() << endl;
2923 dout << "OSOF events with >=3 jets:" << njosof->Integral() << endl;
2924 dout << "(note that no mass requirement has been imposed)" << endl;
2925
2926 dout << "______________________________________________" << endl;
2927 dout << "How QCD shows up in the different regions: " << endl;
2928 dout << "OSSF: " << endl;
2929 if(PlottingSetup::RestrictToMassPeak) {
2930 dout << " Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
2931 dout << " sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
2932 } else {
2933 dout << " " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
2934 }
2935 dout << "OSOF: " << endl;
2936 if(PlottingSetup::RestrictToMassPeak) {
2937 dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
2938 dout << " sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
2939 } else {
2940 dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
2941 }
2942 dout << "Therefore: " << endl;
2943 if(PlottingSetup::RestrictToMassPeak) {
2944 dout << " Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
2945 dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
2946 dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
2947 dout << " = " << LcorrJZBeemm->Integral() + (1.0/3)*(RcorrJZBSBeemm->Integral() - LcorrJZBSBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() + RcorrJZBSBem->Integral() - LcorrJZBSBem->Integral()) << endl;
2948 } else {
2949 dout << " Prediction increases by : " << LcorrJZBeemm->Integral();
2950 dout << " + (" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
2951 dout << " = " << LcorrJZBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() << endl;
2952 }
2953 dout << " Observation increases by : " << RcorrJZBeemm->Integral() << endl;
2954
2955 dout << endl;
2956 for(int i=0;i<(int)bins.size();i++) {
2957 dout << " JZB > " << bins[i] << " : " << endl;
2958 dout << " Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
2959 if(PlottingSetup::RestrictToMassPeak) {
2960 dout << " Prediction increases by : " << LcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + (1.0/3)*(RcorrJZBSBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBSBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBSBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBSBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX())) << endl;
2961 } else {
2962 dout << " Prediction increases by : " << LcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
2963 }
2964 }
2965
2966 delete can;
2967 delete allevents;
2968 if(ossf) delete ossf;
2969 if(RcorrJZBem) delete RcorrJZBem;
2970 if(LcorrJZBem) delete LcorrJZBem;
2971 if(RcorrJZBeemm) delete RcorrJZBeemm;
2972 if(LcorrJZBeemm) delete LcorrJZBeemm;
2973 if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBem) delete RcorrJZBSBem;
2974 if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBem) delete LcorrJZBSBem;
2975 if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
2976 if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
2977 }
2978
2979 void check_ptsanity() {
2980 TCanvas *ptsancan = new TCanvas("ptsancan","ptsancan",600,1800);
2981 TH1F *individualpt1histos[allsamples.collection.size()];
2982 TH1F *individualpt2histos[allsamples.collection.size()];
2983 TH1F *fpt1 = new TH1F("fpt1","fpt1",50,0,50);
2984 fpt1->GetYaxis()->SetRangeUser(0,1);
2985 fpt1->GetXaxis()->SetTitle("p_{T,1}");
2986 fpt1->GetXaxis()->CenterTitle();
2987
2988 TH1F *fpt2 = new TH1F("fpt2","fpt2",50,0,50);
2989 fpt2->GetXaxis()->SetTitle("p_{T,2}");
2990 fpt2->GetXaxis()->CenterTitle();
2991
2992 ptsancan->Divide(1,3);
2993 ptsancan->cd(1);
2994 float maxpt1entry=0;
2995 float maxpt2entry=0;
2996
2997 TLegend *leg = make_legend();
2998 leg->SetX1(0.0);
2999 leg->SetY1(0.0);
3000 leg->SetX2(1.0);
3001 leg->SetY2(1.0);
3002
3003
3004 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3005 string nowname=(allsamples.collection)[isample].filename;
3006 cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
3007 individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3008 individualpt2histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt2",50,0,50, "p_{T,2}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3009 individualpt1histos[isample]->SetLineColor(isample+1);
3010 individualpt2histos[isample]->SetLineColor(isample+1);
3011 float currmaxpt1entry=individualpt1histos[isample]->GetMaximum()/individualpt1histos[isample]->Integral();
3012 float currmaxpt2entry=individualpt2histos[isample]->GetMaximum()/individualpt2histos[isample]->Integral();
3013 cout << " pt 1 histo contains; " << individualpt1histos[isample]->Integral() << endl;
3014 cout << " pt 2 histo contains; " << individualpt2histos[isample]->Integral() << endl;
3015 if(currmaxpt1entry>maxpt1entry)maxpt1entry=currmaxpt1entry;
3016 if(currmaxpt2entry>maxpt2entry)maxpt2entry=currmaxpt2entry;
3017 leg->AddEntry(individualpt2histos[isample],((allsamples.collection)[isample].filename).c_str(),"f");
3018 }
3019
3020 fpt1->GetYaxis()->SetRangeUser(0,maxpt1entry);
3021 fpt2->GetYaxis()->SetRangeUser(0,maxpt2entry);
3022
3023 ptsancan->cd(1);
3024 fpt1->Draw();
3025 ptsancan->cd(2);
3026 fpt2->Draw();
3027
3028 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3029 ptsancan->cd(1);
3030 individualpt1histos[isample]->DrawNormalized("same,histo");
3031 ptsancan->cd(2);
3032 individualpt2histos[isample]->DrawNormalized("same,histo");
3033 }
3034 ptsancan->cd(3);
3035 leg->Draw();
3036 CompleteSave(ptsancan,"PtSanityCheck");
3037
3038 delete ptsancan;
3039 }
3040
3041 void do_mlls_plot(string mcjzb) {
3042 cout << "At this point we'd plot the mll distribution" << endl;
3043 TCanvas *sigcan = new TCanvas("sigcan","sigcan");
3044 for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
3045 if(!(signalsamples.collection)[isig].events) continue;
3046 string nowname=(signalsamples.collection)[isig].filename;
3047 TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
3048 // TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
3049 mll->SetLineColor(TColor::GetColor("#04B404"));
3050 stringstream poscutS;
3051 poscutS << "((" << mcjzb <<")>50)";
3052 TCut poscut(poscutS.str().c_str());
3053 TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
3054 mllP->SetLineColor(TColor::GetColor("#0040FF"));
3055 mll->Draw("histo");
3056 mllP->Draw("histo,same");
3057 TLegend *leg = make_legend();
3058 leg->SetY1(0.8);
3059 leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
3060 leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
3061 leg->Draw();
3062 TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
3063 TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
3064 lin->Draw("same");
3065 lin2->Draw("same");
3066
3067 CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
3068 delete mll;
3069 delete mllP;
3070 }
3071 }
3072
3073 void met_vs_jzb_plots() {
3074
3075 TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
3076 canmetjzb->SetRightMargin(0.16);
3077
3078 vector<string> findme;
3079 findme.push_back("DY");
3080 findme.push_back("TTJets");
3081 findme.push_back("LM");
3082
3083 for(int ifind=0;ifind<(int)findme.size();ifind++) {
3084 vector<int> selsamples = allsamples.FindSample(findme[ifind]);
3085 TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
3086 for(int isel=0;isel<(int)selsamples.size();isel++) {
3087 cout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
3088 allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF);
3089 }
3090 metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
3091 metvsjzb->SetStats(0);
3092 metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
3093 metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
3094 metvsjzb->GetXaxis()->CenterTitle();
3095 metvsjzb->GetYaxis()->CenterTitle();
3096 metvsjzb->Draw("COLZ");
3097 TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
3098 title->SetTextAlign(12);
3099 title->Draw();
3100 CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
3101 }
3102 }
3103
3104
3105 void test() {
3106
3107 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
3108 testcanv->cd();
3109 switch_overunderflow(true);
3110 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
3111 switch_overunderflow(false);
3112 ptdistr->Draw();
3113 testcanv->SaveAs("test.png");
3114 dout << "HELLO there!" << endl;
3115
3116 }