ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.29
Committed: Mon Jun 18 16:26:07 2012 UTC (12 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.28: +1 -1 lines
Log Message:
using mc specific jzb variable for constructing corrected mc expression

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