ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.15
Committed: Wed Apr 18 13:04:08 2012 UTC (13 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.14: +1 -0 lines
Log Message:
forgot a brace in an if clause when porting changed. fixed.

File Contents

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