ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.39
Committed: Mon Jul 16 04:42:37 2012 UTC (12 years, 9 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.38: +10 -5 lines
Log Message:
Removed sidebands for correction in computation of response correction for classic search (as we're not in the preselection with njets)

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