ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.35
Committed: Mon Jul 9 16:26:00 2012 UTC (12 years, 9 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.34: +36 -0 lines
Log Message:
Added possibility to compare ee and mm jzb distributions

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