ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.23
Committed: Thu Jun 7 08:16:28 2012 UTC (12 years, 11 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.22: +22 -1 lines
Log Message:
Added systematic error histo to prediction plot (but not drawing it yet)

File Contents

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