ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.36
Committed: Thu Jul 12 12:55:02 2012 UTC (12 years, 9 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.35: +132 -39 lines
Log Message:
Updated Z+Jets systematic uncert plot: First doing a Z->ee,mm plot only (vetoing taus) with flipping, followed by ee,mm,tautau plot with all control regions

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 buchmann 1.36
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 buchmann 1.36 /*
1884 buchmann 1.14 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
1885     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
1886     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
1887     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
1888     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
1889     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
1890     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1891     if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
1892     if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
1893 buchmann 1.36 */
1894 buchmann 1.35 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);
1895     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);
1896 buchmann 1.36 draw_normalized_data_vs_data_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,"ee","mm","jzb_ee_vs_mm_coarsest",can,coarsest_binning);
1897 buchmann 1.35
1898 buchmann 1.14 }
1899 buchmann 1.1
1900     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1901 buchmann 1.14 if ( !PlottingSetup::Approved ) {
1902     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1903     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1904     if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1905     if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1906     }
1907 buchmann 1.12 delete can;
1908 buchmann 1.1 }
1909    
1910    
1911     void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
1912     dout << "Calculating background yields in MC:" << endl;
1913     jzb_cuts.push_back(14000);
1914     TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
1915     float cumulative=0;
1916     for(int i=allbgs->GetNbinsX();i>=1;i--) {
1917     cumulative+=allbgs->GetBinContent(i);
1918     dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
1919     }
1920     }
1921    
1922    
1923     TCut give_jzb_expression(string mcjzb, float jzbcut, string posneg="pos") {
1924     stringstream res;
1925     res << "(" << mcjzb;
1926     if(posneg=="pos") res << ">";
1927     else res << "<-";
1928     res << jzbcut << ")";
1929     return TCut(res.str().c_str());
1930     }
1931    
1932     string sigdig(float number, int nsigdig=3, float min=0) {
1933     //this function tries to extract n significant digits, and if the number is below (min), it returns "<min"
1934     if(number<min) return "< "+any2string(min);
1935     stringstream sol;
1936     sol << setprecision(nsigdig) << number;
1937    
1938     return sol.str();
1939     }
1940    
1941     string jzb_tex_command(string region, string posneg) {
1942     if(posneg=="pos") posneg="POS";
1943     else posneg="NEG";
1944     stringstream texcommand;
1945     texcommand<<"\\"<<region <<"JZB"<<posneg;
1946     return texcommand.str();
1947     }
1948     // \SFZPJZBPOS
1949     // Sample & \OFZPJZBPOS & \OFZPJZBNEG & \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS & \OFSBJZBNEG & \SFSBJZBPOS & \SFSBJZBNEG \\\hline
1950    
1951     void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
1952     dout << "Calculating background yields in MC:" << endl;
1953    
1954     TCanvas *yica = new TCanvas("yica","yield canvas");
1955    
1956     int nRegions=4;
1957     if(!PlottingSetup::RestrictToMassPeak) nRegions=2;
1958     string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
1959     string posneg[] = {"pos","neg"};
1960     TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
1961    
1962 buchmann 1.16 for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
1963 buchmann 1.1 TCut jzbMC[] = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
1964     dout << "_________________________________________________________" << endl;
1965     dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
1966 buchmann 1.16 for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
1967 buchmann 1.1 if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << " & ";
1968     else dout << "Sample & ";
1969     for(int iregion=0;iregion<nRegions;iregion++) {
1970     for(int ipos=0;ipos<2;ipos++) {
1971     if((allsamples.collection)[isample].is_data) dout << jzb_tex_command(tsRegions[iregion],posneg[ipos]) << " & ";
1972     else {
1973     vector<int> specific;specific.push_back(isample);
1974     TH1F *shisto = allsamples.Draw("shisto","mll",1,0,500,"tester","events",tkRegions[iregion]&&jzbMC[ipos],mc,luminosity,specific);
1975     dout << sigdig(shisto->Integral(),3,0.05) <<" & ";
1976     delete shisto;
1977     }
1978     }//end of ipos
1979     }//end of iregion
1980     dout << " \\\\" << endl;
1981     }//end of isample
1982     }//end of ijzb
1983     dout << " \\hline" << endl;
1984    
1985     delete yica;
1986     }
1987    
1988     void draw_ttbar_and_zjets_shape_for_one_configuration(string mcjzb, string datajzb, int leptontype=-1, int scenario=0,bool floating=false) {
1989     //Step 1: Establishing cuts
1990     stringstream jetcutstring;
1991     string writescenario="";
1992    
1993     if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
1994     if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
1995     TCut jetcut(jetcutstring.str().c_str());
1996     string leptoncut="mll>0";
1997     if(leptontype==0||leptontype==1) {
1998     if(leptontype==0) {
1999     leptoncut="id1==0";
2000     writescenario="__ee";
2001     }
2002     else {
2003     leptoncut="id1==1";
2004     writescenario="__ee";
2005     }
2006     }
2007     TCut lepcut(leptoncut.c_str());
2008    
2009     TCanvas *c5 = new TCanvas("c5","c5",1500,500);
2010     TCanvas *c6 = new TCanvas("c6","c6");
2011     c5->Divide(3,1);
2012    
2013     //STEP 2: Extract Zjets shape in data
2014     c5->cd(1);
2015     c5->cd(1)->SetLogy(1);
2016     TCut massat40("mll>40");
2017     TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
2018     TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
2019     ossfleft->SetLineColor(kRed);
2020     ossfleft->SetMarkerColor(kRed);
2021     ossfleft->Add(osofleft,-1);
2022     vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
2023     ossfleft->SetMarkerSize(DataMarkerSize);
2024     ossfleft->Draw();
2025     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
2026     TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
2027     TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
2028     TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
2029     zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
2030     TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
2031     leg1->SetFillColor(kWhite);
2032     leg1->SetLineColor(kWhite);
2033     leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
2034     leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
2035     leg1->Draw("same");
2036     TText *titleleft = write_title("Extracting Z+Jets shape");
2037     titleleft->Draw();
2038    
2039     //Step 3: Extract ttbar shape (in data or MC?)
2040     c5->cd(2);
2041     c5->cd(2)->SetLogy(1);
2042     TH1F *osof;
2043     TText *titlecenter;
2044     bool frommc=false;
2045     if(frommc) {
2046     osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
2047     titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
2048     }
2049     else {
2050     osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
2051     titlecenter = write_title("Extracting ttbar shape (from osof data)");
2052     }
2053     osof->SetMarkerSize(DataMarkerSize);
2054     osof->Draw();
2055     vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
2056     ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
2057     ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
2058     ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
2059    
2060     TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
2061     leg2->SetFillColor(kWhite);
2062     leg2->SetLineColor(kWhite);
2063     if(frommc) {
2064     leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
2065     leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
2066     } else {
2067     leg2->AddEntry(osof,"OSOF","p");
2068     leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
2069     }
2070     leg2->Draw("same");
2071     titlecenter->Draw();
2072    
2073     //--------------------------------------------------------------------------------------------------------------------------------
2074     //STEP 4: Present it!
2075     // actually: if we wanna let it float we need to do that first :-)
2076     c5->cd(3);
2077     c5->cd(3)->SetLogy(1);
2078     TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
2079     observed->SetMarkerSize(DataMarkerSize);
2080    
2081     TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
2082     TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
2083     TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
2084    
2085     TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
2086     TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
2087     TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
2088    
2089     TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
2090     TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
2091     TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
2092    
2093     zjetsc->SetParameters(zjetsfunc->GetParameters());
2094     zjetscp->SetParameters(zjetsfunc->GetParameters());
2095     zjetscn->SetParameters(zjetsfunc->GetParameters());
2096    
2097     TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
2098     //blublu
2099     logparc->SetParameters(ttbarfunctions[1]->GetParameters());
2100     logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
2101     logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
2102     if(floating) {
2103     dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
2104     logparc->SetParameters(ttbarfunctions[1]->GetParameters());
2105     for(int i=0;i<10;i++) {
2106     if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
2107     if(i>=5) {
2108     if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
2109     if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
2110     }
2111     }//end of setting parameters
2112     observeda->Draw("same");
2113     ZplusJetsplusTTbar->Draw("same");
2114     observeda->Fit(ZplusJetsplusTTbar);
2115     dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
2116     ZplusJetsplusTTbar->Draw("same");
2117     ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
2118     ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
2119     dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
2120     float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
2121     dout << "FACTOR: " << factor << endl;
2122     logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
2123     logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
2124     logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
2125     }
2126    
2127     c5->cd(3);
2128     c5->cd(3)->SetLogy(1);
2129     observed->Draw();
2130     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
2131     logparc->Draw("same");
2132     logparcn->Draw("same");
2133     logparcp->Draw("same");
2134    
2135     TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
2136     leg3->SetFillColor(kWhite);
2137     leg3->SetLineColor(kWhite);
2138     leg3->AddEntry(observed,"OSSF,JZB>peak","p");
2139     leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
2140     leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
2141     leg3->Draw("same");
2142     TText *titleright = write_title("Summary of shapes and observed shape");
2143     titleright->Draw();
2144    
2145     c6->cd()->SetLogy(1);
2146     observed->Draw();
2147     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
2148     logparc->Draw("same");
2149     logparcn->Draw("same");
2150     logparcp->Draw("same");
2151     leg3->Draw("same");
2152     titleright->Draw();
2153    
2154     if(scenario==0) {
2155     CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
2156     CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
2157     CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
2158     CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
2159     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
2160     } else {
2161     CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
2162     CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
2163     CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
2164     CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
2165     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
2166     }
2167     dout << "Statistics about our fits: " << endl;
2168     dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
2169     dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
2170    
2171     c6->cd();
2172     TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
2173     additionallegend->SetFillColor(kWhite);
2174     additionallegend->SetLineColor(kWhite);
2175     additionallegend->AddEntry(observed,"Data","p");
2176     additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
2177     additionallegend->AddEntry(zjetsc,"Z+jets","l");
2178     additionallegend->AddEntry(logparc,"TTbar","l");
2179     observed->Draw();
2180     ZplusJetsplusTTbar->SetLineColor(kGreen);
2181     ZplusJetsplusTTbarP->SetLineColor(kGreen);
2182     ZplusJetsplusTTbarN->SetLineColor(kGreen);
2183     ZplusJetsplusTTbarP->SetLineStyle(2);
2184     ZplusJetsplusTTbarN->SetLineStyle(2);
2185     TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
2186     ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
2187     ZplusJetsplusTTbar2->SetLineColor(kGreen);
2188     ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
2189     ZplusJetsplusTTbarN->SetFillColor(kWhite);
2190     ZplusJetsplusTTbarP->Draw("fcsame");
2191     ZplusJetsplusTTbarN->Draw("fcsame");
2192     TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
2193     TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
2194     TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
2195     hZplusJetsplusTTbar->SetMarkerSize(0);
2196     hZplusJetsplusTTbarP->SetMarkerSize(0);
2197     hZplusJetsplusTTbarN->SetMarkerSize(0);
2198     for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
2199     float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
2200     hZplusJetsplusTTbar->SetBinError(i,newerror);
2201     if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
2202     }
2203     hZplusJetsplusTTbarP->SetFillColor(kGreen);
2204     hZplusJetsplusTTbarN->SetFillColor(kWhite);
2205     hZplusJetsplusTTbarN->Draw("same");
2206    
2207     ZplusJetsplusTTbar2->SetMarkerSize(0);
2208     ZplusJetsplusTTbar2->Draw("same");
2209    
2210     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
2211     logparc->Draw("same");
2212     logparcn->Draw("same");
2213     logparcp->Draw("same");
2214     additionallegend->Draw("same");
2215     if(scenario==0) {
2216     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
2217     } else {
2218     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
2219     }
2220     //--------------------------------------------------------------------------------------------------------------------------------
2221     }
2222    
2223     void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
2224     int all_leptons=-1;
2225 buchmann 1.16 int threejetswith30gev=0;
2226     /*
2227     int twojetswith50gev=1;
2228 buchmann 1.1 int electrons_only=0;
2229     int mu_only=1;
2230 buchmann 1.16
2231 buchmann 1.1 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
2232     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
2233    
2234     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
2235     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
2236    
2237     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
2238     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
2239     */
2240    
2241     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
2242     }
2243    
2244 buchmann 1.32 float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
2245 buchmann 1.1 TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
2246     cancorr->SetLogz();
2247     cancorr->SetRightMargin(0.13);
2248 buchmann 1.30 TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)"&&SpecialCut&&passtrig);
2249 buchmann 1.18 if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
2250 buchmann 1.1 TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
2251 buchmann 1.27 vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
2252 buchmann 1.33 for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
2253 buchmann 1.32 if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
2254     if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
2255    
2256 buchmann 1.30 dout << " Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
2257 buchmann 1.27 (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",zptforresponsepresentation*cutWeight);
2258     }
2259    
2260 buchmann 1.1 niceresponseplotd->SetStats(0);
2261     niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2262     niceresponseplotd->GetYaxis()->SetTitle("Response");
2263     niceresponseplotd->GetXaxis()->CenterTitle();
2264     niceresponseplotd->GetYaxis()->CenterTitle();
2265     niceresponseplotd->Draw("COLZ");
2266     TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
2267     profd->SetMarkerSize(DataMarkerSize);
2268 buchmann 1.18 profd->Fit("pol0","","same,e1",100,400);
2269 buchmann 1.1 DrawPrelim();
2270 buchmann 1.27 string stitle="Data";
2271     if(!Contains(FindKeyword,"Data")) stitle="MC";
2272     TText* title = write_text(0.5,0.7,stitle.c_str());
2273 buchmann 1.1 title->SetTextAlign(12);
2274     title->Draw();
2275     TF1 *datapol=(TF1*)profd->GetFunction("pol0");
2276 buchmann 1.27 float correction=datapol->GetParameter(0);
2277     stringstream resstring;
2278     resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
2279     TText* restitle = write_text(0.5,0.65,resstring.str());
2280 buchmann 1.1 restitle->SetTextAlign(12);
2281     restitle->SetTextSize(0.03);
2282     restitle->Draw();
2283 buchmann 1.27 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
2284     delete cancorr;
2285     delete niceresponseplotd;
2286     return correction;
2287     }
2288    
2289     void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
2290    
2291 buchmann 1.30 dout << "Computing response corrections: " << endl;
2292 buchmann 1.27 //Step 1 : Get results
2293 buchmann 1.32 float datacorrection=find_one_correction_factor("Data",true,"","Data");
2294     float mccorrection=find_one_correction_factor("DY",false,"","MC");
2295 buchmann 1.1
2296 buchmann 1.32 float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
2297     float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
2298 buchmann 1.27
2299 buchmann 1.32 float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
2300     float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
2301 buchmann 1.27
2302     cout << "Corrections : " << endl;
2303     cout << " Data : " << datacorrection << endl;
2304     cout << " ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
2305     cout << " MC : " << mccorrection << endl;
2306     cout << " ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
2307    
2308     //Step 2: Processing the result and making it into something useful :-)
2309 buchmann 1.1 stringstream jzbvardatas;
2310 buchmann 1.27 jzbvardatas << "(";
2311    
2312     if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
2313     if(dataEEcorrection<1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
2314    
2315     if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
2316     if(dataMMcorrection<1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
2317    
2318     float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
2319    
2320 buchmann 1.30 if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
2321     if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
2322 buchmann 1.27
2323     jzbvardatas << ")";
2324 buchmann 1.1 jzbvardata=jzbvardatas.str();
2325 buchmann 1.27
2326 buchmann 1.1 stringstream jzbvarmcs;
2327 buchmann 1.27 jzbvarmcs << "(";
2328    
2329     if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
2330     if(mcEEcorrection<1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
2331    
2332     if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
2333     if(mcMMcorrection<1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
2334    
2335     float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
2336    
2337 buchmann 1.30 if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
2338     if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
2339 buchmann 1.27
2340     jzbvarmcs << ")";
2341 buchmann 1.1 jzbvarmc=jzbvarmcs.str();
2342 buchmann 1.27
2343 buchmann 1.1 dout << "JZB Z pt correction summary : " << endl;
2344     dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
2345     dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
2346 buchmann 1.27
2347 buchmann 1.1 }
2348    
2349     void pick_up_events(string cut) {
2350     dout << "Picking up events with cut " << cut << endl;
2351     allsamples.PickUpEvents(cut);
2352     }
2353    
2354 buchmann 1.18 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
2355 buchmann 1.1 dout << "Saving configuration template!" << endl;
2356     ofstream configfile;
2357     configfile.open("../DistributedModelCalculations/last_configuration.C");
2358     configfile<<"#include <iostream>\n";
2359     configfile<<"#include <vector>\n";
2360     configfile<<"#ifndef SampleClassLoaded\n";
2361     configfile<<"#include \"SampleClass.C\"\n";
2362     configfile<<"#endif\n";
2363     configfile<<"#define SetupLoaded\n";
2364     configfile<<"#ifndef ResultLibraryClassLoaded\n";
2365     configfile<<"#include \"ResultLibraryClass.C\"\n";
2366     configfile<<"#endif\n";
2367    
2368     configfile<<"\nusing namespace std;\n\n";
2369    
2370     configfile<<"namespace PlottingSetup { \n";
2371     configfile<<"string datajzb=\"datajzb_ERROR\";\n";
2372     configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
2373     configfile<<"vector<float>jzb_cuts;\n";
2374 buchmann 1.18 configfile<<"vector<float>jzb_shape_limit_bins;\n";
2375 buchmann 1.1 configfile<<"float MCPeakError=-999;\n";
2376 buchmann 1.11 configfile<<"float DataPeakError=-999;\n";
2377 buchmann 1.1 configfile<<"}\n\n";
2378    
2379     configfile<<"void read_config() {\n";
2380     configfile<<"datajzb=\""<<datajzb<<"\";\n";
2381     configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
2382 buchmann 1.11 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
2383     configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
2384 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";
2385 buchmann 1.1 configfile<<"\n\n";
2386 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";
2387     for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2388     for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2389 buchmann 1.1 configfile<<"\n\n";
2390 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";
2391     for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2392 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";
2393 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";
2394     configfile<<"\n\n";
2395 buchmann 1.1 configfile<<"\n\n";
2396     configfile<<"luminosity="<<luminosity<<";\n";
2397 buchmann 1.5 configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
2398 buchmann 1.1
2399     configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
2400    
2401     configfile.close();
2402    
2403     }
2404    
2405     float get_nonzero_minimum(TH1F *histo) {
2406     float min=histo->GetMaximum();
2407     for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
2408     float curcont=histo->GetBinContent(ibin);
2409     if(curcont<min&&curcont>0) min=curcont;
2410     }
2411     return min;
2412     }
2413    
2414     void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
2415     can->cd();
2416     float min=1;
2417     float max=histos[0]->GetMaximum();
2418     if(manualmin>=0) min=manualmin;
2419     else {
2420 buchmann 1.16 for(int i=1;i<(int)histos.size();i++) {
2421 buchmann 1.1 float curmin=get_nonzero_minimum(histos[i]);
2422     float curmax=histos[i]->GetMaximum();
2423     if(curmin<min) min=curmin;
2424     if(curmax>max) max=curmax;
2425     }
2426     }
2427     histos[0]->GetYaxis()->SetRangeUser(min,4*max);
2428     histos[0]->Draw(drawoption.c_str());
2429     stringstream drawopt;
2430     drawopt << drawoption << ",same";
2431 buchmann 1.16 for(int i=1;i<(int)histos.size();i++) {
2432 buchmann 1.1 histos[i]->Draw(drawopt.str().c_str());
2433     }
2434     }
2435    
2436     void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
2437     //in the case of the on peak analysis, we compare the 3 control regions to the real value
2438     //in the case of the OFF peak analysis, we compare our control region to the real value
2439     TCut weightbackup=cutWeight;
2440 buchmann 1.34
2441     bool doPURW=false;
2442    
2443    
2444     if(!doPURW) {
2445     cutWeight="1.0";
2446     // Do it without PU re-weighting
2447     float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2448     stringstream resultsNoPU;
2449     stringstream noPUdatajzb;
2450     stringstream noPUmcjzb;
2451    
2452     stringstream mcjzbnoPU;
2453     find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
2454 buchmann 1.36 mcjzb = noPUmcjzb.str();
2455 buchmann 1.34 }
2456    
2457    
2458    
2459    
2460    
2461    
2462 buchmann 1.1 float simulatedlumi = luminosity; //in pb please - adjust to your likings
2463    
2464     TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2465     TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2466     TH1F *TSem;
2467     TH1F *nTSem;
2468     TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2469     TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2470     TH1F *TSeemm;
2471     TH1F *nTSeemm;
2472    
2473     if(PlottingSetup::RestrictToMassPeak) {
2474     TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2475     nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2476     TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2477     nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2478     }
2479    
2480     TCanvas *tcan = new TCanvas("tcan","tcan");
2481    
2482     tcan->SetLogy(1);
2483    
2484     TZeemm->SetLineColor(kBlack);
2485     TZem->SetLineColor(kRed);
2486     TZeemm->SetMarkerColor(kBlack);
2487     TZem->SetMarkerColor(kRed);
2488    
2489    
2490     if(PlottingSetup::RestrictToMassPeak) {
2491     TSem->SetLineColor(TColor::GetColor("#00A616"));
2492     TSeemm->SetLineColor(kMagenta+2);
2493     TSem->SetMarkerColor(TColor::GetColor("#00A616"));
2494     TSeemm->SetMarkerColor(kMagenta+2);
2495     TSem->SetLineStyle(2);
2496     TSeemm->SetLineStyle(3);
2497     }
2498    
2499     vector<TH1F*> histos;
2500 buchmann 1.31 TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2501     TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2502 buchmann 1.1 histos.push_back(TZem);
2503     histos.push_back(TZeemm);
2504     if(PlottingSetup::RestrictToMassPeak) {
2505 buchmann 1.31 TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2506     TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2507 buchmann 1.1 histos.push_back(TSem);
2508     histos.push_back(TSeemm);
2509     }
2510     draw_all_ttbar_histos(tcan,histos,"histo",0.04);
2511    
2512     TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
2513     leg->AddEntry(TZeemm,"SFZP","l");
2514     leg->AddEntry(TZem,"OFZP","l");
2515     if(PlottingSetup::RestrictToMassPeak) {
2516     leg->AddEntry(TSeemm,"SFSB","l");
2517     leg->AddEntry(TSem,"OFSB","l");
2518     }
2519     leg->Draw("same");
2520     DrawMCPrelim(simulatedlumi);
2521     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
2522     TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2523     TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2524 buchmann 1.11 TH1F *TSeemmcopy;
2525     TH1F *TSemcopy;
2526     if(PlottingSetup::RestrictToMassPeak) {
2527     TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2528     TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2529     }
2530 buchmann 1.1
2531     TZem->Divide(TZeemm);
2532     TZem->SetMarkerStyle(21);
2533     if(PlottingSetup::RestrictToMassPeak) {
2534     TSem->Divide(TZeemm);
2535     TSeemm->Divide(TZeemm);
2536     TSem->SetMarkerStyle(24);
2537     TSeemm->SetMarkerStyle(32);
2538     }
2539    
2540     tcan->SetLogy(0);
2541     TZem->GetYaxis()->SetRangeUser(0,2.5);
2542     TZem->GetYaxis()->SetTitle("ratio");
2543     TZem->Draw();
2544     if(PlottingSetup::RestrictToMassPeak) {
2545     TSem->Draw("same");
2546     TSeemm->Draw("same");
2547     }
2548    
2549 buchmann 1.33 float linepos=emuncertONPEAK;
2550     if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
2551    
2552 buchmann 1.1 TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
2553     TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2554     TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
2555    
2556 buchmann 1.11 /*write_warning(__FUNCTION__,"These two lines are to be removed!");
2557     TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
2558     TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
2559     topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
2560     bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
2561     topalt->Draw("same");bottomalt->Draw("same");*/
2562    
2563    
2564 buchmann 1.1 top->SetLineColor(kBlue);top->SetLineStyle(2);
2565     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2566     center->SetLineColor(kBlue);
2567    
2568     top->Draw("same");
2569     center->Draw("same");
2570     bottom->Draw("same");
2571    
2572     TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
2573     leg2->AddEntry(TZem,"OFZP / SFZP","ple");
2574     if(PlottingSetup::RestrictToMassPeak) {
2575     leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
2576     leg2->AddEntry(TSem,"OFSB / SFZP","ple");
2577     }
2578     leg2->AddEntry(bottom,"syst. envelope","l");
2579     leg2->SetX1(0.25);leg2->SetX2(0.6);
2580     leg2->SetY1(0.65);
2581    
2582     leg2->Draw("same");
2583    
2584     DrawMCPrelim(simulatedlumi);
2585     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
2586    
2587    
2588     ///-------------- second part: only look at the quantity we actually care about!
2589     TH1F *leftsfzp = (TH1F*)nTZeemm->Clone("leftsfzp");
2590     TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
2591     rightsfzp->Add(leftsfzp,-1);
2592     TH1F *leftofzp = (TH1F*)nTZem->Clone("leftofzp");
2593     TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
2594     rightofzp->Add(leftofzp,-1);
2595     TH1F *leftofsb;
2596     TH1F *rightofsb;
2597     TH1F *leftsfsb;
2598     TH1F *rightsfsb;
2599     if(PlottingSetup::RestrictToMassPeak) {
2600     leftofsb = (TH1F*)nTSem->Clone("leftofsb");
2601     rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
2602     rightofsb->Add(leftofsb,-1);
2603     leftsfsb = (TH1F*)nTSeemm->Clone("leftsfsb");
2604     rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
2605     rightsfsb->Add(leftsfsb,-1);
2606     }
2607    
2608     tcan->SetLogy(1);
2609     rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
2610     rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
2611     rightsfzp->Draw("histo");
2612     rightofzp->Draw("histo,same");
2613     if(PlottingSetup::RestrictToMassPeak) {
2614     rightofsb->Draw("histo,same");
2615     rightsfsb->Draw("histo,same");
2616     }
2617     DrawMCPrelim(simulatedlumi);
2618    
2619     TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2620     legA->AddEntry(rightsfzp,"SFZP","l");
2621     legA->AddEntry(rightofzp,"OFZP","l");
2622     if(PlottingSetup::RestrictToMassPeak) {
2623     legA->AddEntry(rightofsb,"SFSB","l");
2624     legA->AddEntry(rightsfsb,"OFSB","l");
2625     }
2626     legA->Draw();
2627    
2628     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
2629    
2630     tcan->SetLogy(0);
2631     rightofzp->Divide(rightsfzp);
2632     rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2633 buchmann 1.30 rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
2634 buchmann 1.1 rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2635     rightofzp->Draw();
2636     if(PlottingSetup::RestrictToMassPeak) {
2637     rightofsb->Divide(rightsfzp);
2638     rightsfsb->Divide(rightsfzp);
2639     rightofsb->Draw("same");
2640     rightsfsb->Draw("same");
2641     }
2642    
2643     TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
2644     TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
2645     TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
2646    
2647     top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2648     bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2649     center2->SetLineColor(kBlue);
2650    
2651     top2->Draw("same");
2652     center2->Draw("same");
2653     bottom2->Draw("same");
2654    
2655     rightofzp->SetMarkerStyle(21);
2656     if(PlottingSetup::RestrictToMassPeak) {
2657     rightofsb->SetMarkerStyle(24);
2658     rightsfsb->SetMarkerStyle(32);
2659     }
2660    
2661     TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2662     leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2663     if(PlottingSetup::RestrictToMassPeak) {
2664     leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2665     leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
2666     }
2667     leg3->AddEntry(bottom,"syst. envelope","l");
2668     leg3->SetX1(0.25);leg3->SetX2(0.6);
2669     leg3->SetY1(0.65);
2670    
2671     leg3->Draw("same");
2672    
2673     DrawMCPrelim(simulatedlumi);
2674     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
2675    
2676     delete TZem;
2677     delete nTZem;
2678     delete TZeemm;
2679     delete nTZeemm;
2680     if(PlottingSetup::RestrictToMassPeak) {
2681     delete TSem;
2682     delete nTSem;
2683     delete TSeemm;
2684     delete nTSeemm;
2685     }
2686    
2687     delete tcan;
2688     cutWeight=weightbackup;
2689     }
2690    
2691     void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
2692     vector<float> nicer_binning;
2693 buchmann 1.32
2694 buchmann 1.33 /* nicer_binning.push_back(-400);
2695 buchmann 1.31 nicer_binning.push_back(-250);
2696     nicer_binning.push_back(-200);
2697     nicer_binning.push_back(-150);
2698     nicer_binning.push_back(-100);
2699     nicer_binning.push_back(-50);
2700     nicer_binning.push_back(-20);
2701    
2702     nicer_binning.push_back(0);
2703     nicer_binning.push_back(20);
2704     nicer_binning.push_back(50);
2705     nicer_binning.push_back(100);
2706     nicer_binning.push_back(150);
2707     nicer_binning.push_back(200);
2708     nicer_binning.push_back(250);
2709 buchmann 1.33 nicer_binning.push_back(400);*/
2710    
2711 buchmann 1.1 nicer_binning.push_back(-100);
2712     nicer_binning.push_back(-50);
2713     nicer_binning.push_back(-25);
2714     nicer_binning.push_back(0);
2715     nicer_binning.push_back(25);
2716     nicer_binning.push_back(50);
2717     nicer_binning.push_back(75);
2718     nicer_binning.push_back(100);
2719     nicer_binning.push_back(125);
2720     nicer_binning.push_back(150);
2721     nicer_binning.push_back(175);
2722     nicer_binning.push_back(200);
2723     nicer_binning.push_back(230);
2724     nicer_binning.push_back(280);
2725     nicer_binning.push_back(400);
2726 buchmann 1.33
2727 buchmann 1.1 ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
2728     }
2729    
2730    
2731 buchmann 1.34 void zjets_prediction_comparison(string mcjzbWithPUa) {
2732 buchmann 1.20 TCanvas *zcan = new TCanvas("zcan","zcan");
2733 buchmann 1.36 // zcan->SetLogy(1);
2734 buchmann 1.20 TCut weightbackup=cutWeight;
2735 buchmann 1.36
2736     bool UsePURW=false;
2737    
2738    
2739     string mcjzb;
2740     if(UsePURW) {
2741     mcjzb=mcjzbWithPUa;
2742     } else {
2743     // Do it without PU re-weighting
2744     float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2745     stringstream resultsNoPU;
2746     stringstream noPUdatajzb;
2747     stringstream noPUmcjzb;
2748    
2749     find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
2750     dout << "The peak corrected JZB expression for MC without pileup is : " << noPUmcjzb.str() << endl;
2751    
2752     mcjzb = noPUmcjzb.str();
2753    
2754     cutWeight="1.0";
2755     }
2756 buchmann 1.34
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 buchmann 1.36 // binning.push_back(30);
2763 buchmann 1.34 binning.push_back(40);
2764 buchmann 1.36 // binning.push_back(50);
2765     // binning.push_back(60);
2766     // binning.push_back(70);
2767     // binning.push_back(80);
2768     // binning.push_back(90);
2769 buchmann 1.25 binning.push_back(100);
2770 buchmann 1.36
2771 buchmann 1.1 float simulatedlumi = luminosity;//in pb please - adjust to your likings
2772    
2773     TCut kPos((mcjzb+">0").c_str());
2774     TCut kNeg((mcjzb+"<0").c_str());
2775     string var( "abs("+mcjzb+")" );
2776 buchmann 1.36
2777     TCut notTau("abs(genMID1)!=15");
2778     TCut ONLYTau("mll>20");
2779    
2780 buchmann 1.1
2781 buchmann 1.36 TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2782     TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2783    
2784 buchmann 1.1 hJZBpos->SetLineColor(kBlack);
2785     hJZBneg->SetLineColor(kRed);
2786    
2787 buchmann 1.25 hJZBpos->SetMinimum(1.0);
2788 buchmann 1.1 hJZBpos->Draw("e1");
2789     hJZBneg->Draw("same,hist");
2790     hJZBpos->Draw("same,e1"); // So it's on top...
2791    
2792 buchmann 1.36 TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
2793 buchmann 1.1 leg->AddEntry(hJZBpos,"Observed","pe");
2794     leg->AddEntry(hJZBneg,"Predicted","l");
2795     leg->Draw("same");
2796     DrawMCPrelim(simulatedlumi);
2797 buchmann 1.36 CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
2798 buchmann 1.1
2799     TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
2800     hratio->Divide(hJZBneg);
2801    
2802 buchmann 1.30 for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
2803 buchmann 1.36 cout << "Positive: " << hJZBpos->GetBinContent(i) << " vs Negative : " << hJZBneg->GetBinContent(i) << " (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
2804 buchmann 1.30 }
2805    
2806 buchmann 1.1 zcan->SetLogy(0);
2807     hratio->GetYaxis()->SetRangeUser(0,2.5);
2808     hratio->GetYaxis()->SetTitle("Observed/Predicted");
2809     hratio->Draw("e1");
2810    
2811 buchmann 1.25 TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
2812     TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2813     TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
2814 buchmann 1.1
2815    
2816     top->SetLineColor(kBlue);top->SetLineStyle(2);
2817     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2818     center->SetLineColor(kBlue);
2819    
2820     top->Draw("same");
2821     center->Draw("same");
2822     bottom->Draw("same");
2823    
2824 buchmann 1.36 TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
2825 buchmann 1.1 leg2->AddEntry(hratio,"obs / pred","pe");
2826     leg2->AddEntry(bottom,"syst. envelope","l");
2827     leg2->Draw("same");
2828     DrawMCPrelim(simulatedlumi);
2829 buchmann 1.36 CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
2830    
2831     TCut reducedNJets(cutnJets);
2832    
2833     TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2834     TH1F *LcorrJZBeemm = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2835     TH1F *RcorrJZBem = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2836     TH1F *LcorrJZBem = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2837    
2838     TH1F *RcorrJZBSBem;
2839     TH1F *LcorrJZBSBem;
2840     TH1F *RcorrJZBSBeemm;
2841     TH1F *LcorrJZBSBeemm;
2842    
2843     if(PlottingSetup::RestrictToMassPeak) {
2844     RcorrJZBSBem = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2845     LcorrJZBSBem = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2846     RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2847     LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2848     }
2849    
2850     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2851     if(PlottingSetup::RestrictToMassPeak) {
2852     Bpred->Add(RcorrJZBem,1.0/3.);
2853     Bpred->Add(LcorrJZBem,-1.0/3.);
2854     Bpred->Add(RcorrJZBSBem,1.0/3.);
2855     Bpred->Add(LcorrJZBSBem,-1.0/3.);
2856     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2857     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2858     } else {
2859     Bpred->Add(RcorrJZBem,1.0);
2860     Bpred->Add(LcorrJZBem,-1.0);
2861     }
2862    
2863     Bpred->SetLineColor(kRed);
2864    
2865     TAUhJZBpos->SetLineColor(kBlack);
2866     Bpred->SetLineColor(kRed);
2867    
2868     TAUhJZBpos->SetMinimum(1.0);
2869     TAUhJZBpos->Draw("e1");
2870     Bpred->Draw("same,hist");
2871     TAUhJZBpos->Draw("same,e1");
2872    
2873     TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
2874     TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
2875     TAUleg->AddEntry(Bpred,"Predicted","l");
2876     TAUleg->Draw("same");
2877     DrawMCPrelim(simulatedlumi);
2878     CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
2879    
2880     TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
2881     TAUhratio->Divide(Bpred);
2882    
2883     for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
2884     cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << " vs predicted : " << Bpred->GetBinContent(i) << " (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
2885     }
2886    
2887     zcan->SetLogy(0);
2888     TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
2889     TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
2890     TAUhratio->Draw("e1");
2891    
2892     top->Draw("same");
2893     center->Draw("same");
2894     bottom->Draw("same");
2895    
2896     TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
2897     TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
2898     TAUleg2->AddEntry(bottom,"syst. envelope","l");
2899     TAUleg2->Draw("same");
2900     DrawMCPrelim(simulatedlumi);
2901     CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
2902    
2903     delete Bpred;
2904     delete TAUhJZBpos;
2905     delete LcorrJZBeemm;
2906     delete RcorrJZBem;
2907     delete LcorrJZBem;
2908    
2909     if(PlottingSetup::RestrictToMassPeak) {
2910     delete RcorrJZBSBem;
2911     delete LcorrJZBSBem;
2912     delete RcorrJZBSBeemm;
2913     delete LcorrJZBSBeemm;
2914     }
2915    
2916 buchmann 1.1
2917     delete zcan;
2918     cutWeight=weightbackup;
2919    
2920     }
2921    
2922    
2923    
2924     void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
2925     tout << endl << endl;
2926     stringstream bordercut;
2927     bordercut << "(TMath::Abs(" << datajzb << ")<" << max << ")&&(TMath::Abs(" << datajzb << ")>" << min << ")";
2928     tout << bordercut.str().c_str() << endl;
2929     TH1F *ofsb = allsamples.Draw("ofsb",datajzb,100, 0,100, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2930     TH1F *ofzp = allsamples.Draw("ofzp",datajzb,100, 0,100, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2931     float OFSB = ofsb->Integral();
2932     float OFZP = ofzp->Integral();
2933    
2934     tout << "\\begin{table}[hbtp]" << endl;
2935     tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
2936     tout << "\\begin{center}" << endl;
2937     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;
2938     tout << "\\begin{tabular}{l|cc}" << endl;
2939     tout << "\\hline" << endl;
2940     tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
2941 buchmann 1.25 tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
2942 buchmann 1.1 tout << "\\end{tabular}" << endl;
2943     tout << "\\end{center}" << endl;
2944     tout << "\\end{table}" << endl;
2945    
2946    
2947     }
2948    
2949     void make_table(samplecollection &coll, string jzbexpr, bool is_data, vector<float> jzb_cuts, string subselection="none") {
2950    
2951     vector<float> jzbcutprediction;
2952     vector<float> metcutprediction;
2953    
2954     vector<float> jzbcutobservation;
2955     vector<float> metcutobservation;
2956    
2957     TCanvas *cannie = new TCanvas("cannie","cannie");
2958    
2959 buchmann 1.16 for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
2960 buchmann 1.1 float currcut=jzb_cuts[icut];
2961     int nbins=1;float low=currcut;
2962     vector<int> mysample;
2963     if(subselection!="none") mysample=coll.FindSample(subselection);
2964     TH1F *RcorrJZBeemm = coll.Draw("RcorrJZBeemm",jzbexpr,1,currcut,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2965     TH1F *LcorrJZBeemm = coll.Draw("LcorrJZBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2966     TH1F *RcorrJZBem = coll.Draw("RcorrJZBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2967     TH1F *LcorrJZBem = coll.Draw("LcorrJZBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2968    
2969     TH1F *RcorrJZBSBem;
2970     TH1F *LcorrJZBSBem;
2971     TH1F *RcorrJZBSBeemm;
2972     TH1F *LcorrJZBSBeemm;
2973    
2974     if(PlottingSetup::RestrictToMassPeak) {
2975     RcorrJZBSBem = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2976     LcorrJZBSBem = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2977     RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2978     LcorrJZBSBeemm = coll.Draw("LcorrJZBSBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2979     }
2980    
2981     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2982     if(PlottingSetup::RestrictToMassPeak) {
2983     Bpred->Add(RcorrJZBem,1.0/3.);
2984     Bpred->Add(LcorrJZBem,-1.0/3.);
2985     Bpred->Add(RcorrJZBSBem,1.0/3.);
2986     Bpred->Add(LcorrJZBSBem,-1.0/3.);
2987     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2988     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2989     } else {
2990     Bpred->Add(RcorrJZBem,1.0);
2991     Bpred->Add(LcorrJZBem,-1.0);
2992     }
2993    
2994     jzbcutobservation.push_back(RcorrJZBeemm->Integral());
2995     jzbcutprediction.push_back(Bpred->Integral());
2996    
2997     delete RcorrJZBeemm;
2998     delete LcorrJZBeemm;
2999     delete RcorrJZBem;
3000     delete LcorrJZBem;
3001     delete RcorrJZBSBem;
3002     delete LcorrJZBSBem;
3003     delete RcorrJZBSBeemm;
3004     delete LcorrJZBSBeemm;
3005    
3006     TH1F *MetObs = coll.Draw("MetObs",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
3007     TH1F *MetPred = coll.Draw("MetPred",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
3008    
3009     metcutobservation.push_back(MetObs->Integral());
3010     metcutprediction.push_back(MetPred->Integral());
3011     delete MetObs;
3012     delete MetPred;
3013     }//end of cut loop
3014    
3015     //prediction part
3016     if(is_data) cout << "Data prediction & ";
3017     if(subselection!="none") cout << subselection << " prediction &";
3018 buchmann 1.16 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
3019 buchmann 1.1
3020     cout << endl;
3021     //observation part
3022     if(is_data) cout << "Data observation & ";
3023     if(subselection!="none") cout << subselection << " observation &";
3024 buchmann 1.16 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
3025 buchmann 1.1 cout << endl;
3026     cout << "_________________________________________________________________" << endl;
3027     delete cannie;
3028     }
3029    
3030     void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
3031     /*we want a table like this:
3032     __________________ 50 | 100 | ...
3033     | Data prediction | a vs b | a vs b | ...
3034     | Data observed | a vs b | a vs b | ...
3035     --------------------------------------
3036     --------------------------------------
3037     | LM4 prediction | a vs b | a vs b | ...
3038     | LM4 observed | a vs b | a vs b | ...
3039     | LM8 prediction | a vs b | a vs b | ...
3040     | LM8 observed | a vs b | a vs b | ...
3041    
3042     where a is the result for a jzb cut at X, and b is the result for a met cut at X
3043     */
3044     make_table(allsamples,datajzb, true,jzb_cut,"none");
3045     make_table(signalsamples,mcjzb, false,jzb_cut,"LM4");
3046     make_table(signalsamples,mcjzb, false,jzb_cut,"LM8");
3047     }
3048    
3049    
3050     //________________________________________________________________________________________
3051     // JZB Efficiency plot (efficiency of passing reco. JZB cut as function of generator JZB cut)
3052     void JZBSelEff(string mcjzb, TTree* events, string informalname, vector<float> jzb_bins) {
3053    
3054     float min = 0, max = 400;
3055     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};
3056     int nbins = sizeof(xbins)/sizeof(float)-1;
3057     int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
3058    
3059 buchmann 1.14
3060     TH1F* heff = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
3061     TH1F* hgen = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
3062     TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
3063 buchmann 1.1
3064     TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
3065     TCut kreco(cutmass);
3066    
3067     TF1* func = new TF1("func","0.5*[2]*(TMath::Erf((x-[1])/[0])+1)",min,max);
3068     func->SetParNames("epsilon","x_{1/2}","sigma");
3069     func->SetParameter(0,50.);
3070     func->SetParameter(1,0.);
3071     func->SetParameter(2,1.);
3072     gStyle->SetOptStat(0);
3073     gStyle->SetOptFit(0);
3074    
3075     TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
3076     can->SetGridx(1);
3077     can->SetGridy(1);
3078 buchmann 1.14 can->SetLeftMargin(0.16);
3079     can->SetRightMargin(0.05);
3080 buchmann 1.1 TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
3081 buchmann 1.14 leg->SetBorderSize(1);
3082     leg->SetLineColor(kBlack);
3083     leg->SetTextFont(62);
3084 buchmann 1.1
3085 buchmann 1.16 for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
3086 buchmann 1.1
3087     ostringstream selection;
3088     selection << mcjzb << ">" << jzb_bins[icut];
3089     TCut ksel(selection.str().c_str());
3090     events->Draw("genJZB>>hgen", kgen&&kreco, "goff");
3091     events->Draw("genJZB>>hreco",kgen&&kreco&&ksel,"goff");
3092    
3093     // Loop over steps to get efficiency curve
3094     for ( Int_t iBin = 0; iBin<nbins-1; ++iBin ) {
3095     Float_t eff = hreco->GetBinContent(iBin+1)/hgen->GetBinContent(iBin+1);
3096     heff->SetBinContent(iBin+1,eff);
3097     heff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/hgen->GetBinContent(iBin+1)));
3098     }
3099    
3100     heff->GetXaxis()->SetRangeUser(min, max);
3101 buchmann 1.14 // heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
3102     // heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
3103     // heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
3104     // heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
3105 buchmann 1.1 heff->SetMarkerStyle(markers[icut]);
3106     heff->Fit("func","Q+","same");
3107    
3108     // Print values
3109     dout << "+++ For " << selection.str() << std::endl;
3110     for ( int i=0; i<func->GetNpar(); ++i )
3111     dout << " " << func->GetParName(i) << " " << func->GetParameter(i) << " \\pm " << func->GetParError(i) << std::endl;
3112     char hname[256]; sprintf(hname,"heff%d",icut);
3113    
3114     // Store plot
3115     TH1F* h = (TH1F*)heff->Clone(hname);
3116 buchmann 1.14 h->SetNdivisions(505,"X");
3117 buchmann 1.1 if ( icut) h->Draw("same");
3118     else h->Draw();
3119     char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
3120     leg->AddEntry(h,htitle,"p");
3121    
3122     }
3123    
3124     leg->Draw();
3125     DrawMCPrelim(0.0);
3126     CompleteSave(can, "Systematics/jzb_efficiency_curve"+informalname );
3127    
3128     delete hgen;
3129     delete hreco;
3130     delete heff;
3131     }
3132    
3133     //________________________________________________________________________________________
3134     // Calls the above function for each signal sample
3135     void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
3136     {
3137 buchmann 1.16 for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
3138 buchmann 1.1 dout << "JZB selection efficiency curve: " << std::endl;
3139     JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
3140     }
3141     }
3142 buchmann 1.3
3143     void qcd_plots(string datajzb, string mcjzb, vector<float> bins) {
3144     // What this function aims to do:
3145     // Illustrate cut flow for QCD (requiring only one lepton, requiring etc.)
3146     // 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.
3147     TCanvas *can = new TCanvas("can","can");
3148     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
3149     kinpad->cd();
3150    
3151     string jzb=mcjzb;
3152    
3153     float hi=400;
3154     bool use_signal=false;
3155     bool use_data=false;
3156    
3157     bool is_data=false;
3158     int nbins=50;//100;
3159     float low=0;
3160     float high=500;
3161     int versok=false;
3162     if(gROOT->GetVersionInt()>=53000) versok=true;
3163    
3164     TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3165     TH1F *RcorrJZBeemm = qcdsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3166     TH1F *LcorrJZBeemm = qcdsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3167     TH1F *RcorrJZBem = qcdsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3168     TH1F *LcorrJZBem = qcdsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3169     blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3170     blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
3171     blankback->GetXaxis()->CenterTitle();
3172     blankback->GetYaxis()->CenterTitle();
3173    
3174     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3175     TH1F *RcorrJZBSBem;
3176     TH1F *LcorrJZBSBem;
3177     TH1F *RcorrJZBSBeemm;
3178     TH1F *LcorrJZBSBeemm;
3179    
3180 buchmann 1.16 // TH1F *RcorrJZBeemmNoS;
3181 buchmann 1.3
3182     //these are for the ratio
3183     TH1F *JRcorrJZBeemm = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3184     TH1F *JLcorrJZBeemm = qcdsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3185     TH1F *JRcorrJZBem = qcdsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3186     TH1F *JLcorrJZBem = qcdsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3187    
3188     TH1F *JRcorrJZBSBem;
3189     TH1F *JLcorrJZBSBem;
3190     TH1F *JRcorrJZBSBeemm;
3191     TH1F *JLcorrJZBSBeemm;
3192    
3193     if(PlottingSetup::RestrictToMassPeak) {
3194     RcorrJZBSBem = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3195     LcorrJZBSBem = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3196     RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3197     LcorrJZBSBeemm = qcdsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3198    
3199     //these are for the ratio
3200     JRcorrJZBSBem = qcdsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3201     JLcorrJZBSBem = qcdsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3202     JRcorrJZBSBeemm = qcdsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3203     JLcorrJZBSBeemm = qcdsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3204    
3205     }
3206    
3207     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3208    
3209     TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
3210     TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
3211    
3212     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
3213     TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
3214     if(PlottingSetup::RestrictToMassPeak) {
3215     Bpred->Add(RcorrJZBem,1.0/3.);
3216     Bpred->Add(LcorrJZBem,-1.0/3.);
3217     Bpred->Add(RcorrJZBSBem,1.0/3.);
3218     Bpred->Add(LcorrJZBSBem,-1.0/3.);
3219     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
3220     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
3221    
3222     TTbarpred->Scale(1.0/3);
3223     Zjetspred->Add(LcorrJZBem,-1.0/3.);
3224     Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
3225     TTbarpred->Add(RcorrJZBSBem,1.0/3.);
3226     Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
3227     TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
3228    
3229     //these are for the ratio
3230     JBpred->Add(JRcorrJZBem,1.0/3.);
3231     JBpred->Add(JLcorrJZBem,-1.0/3.);
3232     JBpred->Add(JRcorrJZBSBem,1.0/3.);
3233     JBpred->Add(JLcorrJZBSBem,-1.0/3.);
3234     JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
3235     JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
3236     } else {
3237     Bpred->Add(RcorrJZBem,1.0);
3238     Bpred->Add(LcorrJZBem,-1.0);
3239    
3240     Zjetspred->Add(LcorrJZBem,-1.0);
3241    
3242     //these are for the ratio
3243     JBpred->Add(JRcorrJZBem,1.0);
3244     JBpred->Add(JLcorrJZBem,-1.0);
3245     }
3246    
3247    
3248     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
3249 buchmann 1.1
3250 buchmann 1.3 TLegend *legBpred = make_legend("",0.6,0.55,false);
3251     RcorrJZBeemm->Draw("e1x0,same");
3252     Bpred->Draw("hist,same");
3253     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3254     legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
3255     legBpred->AddEntry(Bpred,"MC predicted","l");
3256     if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
3257     if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
3258     legBpred->Draw();
3259     DrawMCPrelim();
3260    
3261     //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3262     string ytitle("ratio");
3263     if ( use_data==1 ) ytitle = "data/pred";
3264 buchmann 1.25 save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
3265 buchmann 1.3
3266     TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
3267     TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
3268     TH1F *osof = qcdsamples.Draw("osof","pfJetGoodNum",1,0,100, "internal code", "events", cutOSOF ,mc, luminosity);
3269     TH1F *njossf = qcdsamples.Draw("njossf","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSSF ,mc, luminosity);
3270     TH1F *njosof = qcdsamples.Draw("njosof","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSOF ,mc, luminosity);
3271    
3272     dout << "______________________________________________" << endl;
3273     dout << "QCD contribution: " << endl;
3274     dout << "Total number of events: " << allevents->Integral() << endl;
3275     dout << "OSSF events: " << ossf->Integral() << endl;
3276     dout << "OSOF events: " << osof->Integral() << endl;
3277     dout << "OSSF events with >=3 jets:" << njossf->Integral() << endl;
3278     dout << "OSOF events with >=3 jets:" << njosof->Integral() << endl;
3279     dout << "(note that no mass requirement has been imposed)" << endl;
3280    
3281     dout << "______________________________________________" << endl;
3282     dout << "How QCD shows up in the different regions: " << endl;
3283     dout << "OSSF: " << endl;
3284     if(PlottingSetup::RestrictToMassPeak) {
3285     dout << " Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
3286     dout << " sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
3287     } else {
3288     dout << " " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
3289     }
3290     dout << "OSOF: " << endl;
3291     if(PlottingSetup::RestrictToMassPeak) {
3292     dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
3293     dout << " sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
3294     } else {
3295     dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
3296     }
3297     dout << "Therefore: " << endl;
3298     if(PlottingSetup::RestrictToMassPeak) {
3299     dout << " Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
3300     dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
3301     dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
3302     dout << " = " << LcorrJZBeemm->Integral() + (1.0/3)*(RcorrJZBSBeemm->Integral() - LcorrJZBSBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() + RcorrJZBSBem->Integral() - LcorrJZBSBem->Integral()) << endl;
3303     } else {
3304     dout << " Prediction increases by : " << LcorrJZBeemm->Integral();
3305     dout << " + (" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
3306     dout << " = " << LcorrJZBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() << endl;
3307     }
3308     dout << " Observation increases by : " << RcorrJZBeemm->Integral() << endl;
3309    
3310     dout << endl;
3311 buchmann 1.16 for(int i=0;i<(int)bins.size();i++) {
3312 buchmann 1.3 dout << " JZB > " << bins[i] << " : " << endl;
3313     dout << " Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
3314     if(PlottingSetup::RestrictToMassPeak) {
3315     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;
3316     } else {
3317     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;
3318     }
3319     }
3320    
3321     delete can;
3322     delete allevents;
3323     if(ossf) delete ossf;
3324     if(RcorrJZBem) delete RcorrJZBem;
3325     if(LcorrJZBem) delete LcorrJZBem;
3326     if(RcorrJZBeemm) delete RcorrJZBeemm;
3327     if(LcorrJZBeemm) delete LcorrJZBeemm;
3328     if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBem) delete RcorrJZBSBem;
3329     if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBem) delete LcorrJZBSBem;
3330     if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
3331     if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
3332     }
3333 buchmann 1.1
3334 buchmann 1.4 void check_ptsanity() {
3335     TCanvas *ptsancan = new TCanvas("ptsancan","ptsancan",600,1800);
3336     TH1F *individualpt1histos[allsamples.collection.size()];
3337     TH1F *individualpt2histos[allsamples.collection.size()];
3338     TH1F *fpt1 = new TH1F("fpt1","fpt1",50,0,50);
3339     fpt1->GetYaxis()->SetRangeUser(0,1);
3340     fpt1->GetXaxis()->SetTitle("p_{T,1}");
3341     fpt1->GetXaxis()->CenterTitle();
3342    
3343     TH1F *fpt2 = new TH1F("fpt2","fpt2",50,0,50);
3344     fpt2->GetXaxis()->SetTitle("p_{T,2}");
3345     fpt2->GetXaxis()->CenterTitle();
3346    
3347     ptsancan->Divide(1,3);
3348     ptsancan->cd(1);
3349     float maxpt1entry=0;
3350     float maxpt2entry=0;
3351    
3352     TLegend *leg = make_legend();
3353     leg->SetX1(0.0);
3354     leg->SetY1(0.0);
3355     leg->SetX2(1.0);
3356     leg->SetY2(1.0);
3357    
3358    
3359 buchmann 1.16 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3360 buchmann 1.4 string nowname=(allsamples.collection)[isample].filename;
3361     cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
3362     individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3363     individualpt2histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt2",50,0,50, "p_{T,2}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3364     individualpt1histos[isample]->SetLineColor(isample+1);
3365     individualpt2histos[isample]->SetLineColor(isample+1);
3366     float currmaxpt1entry=individualpt1histos[isample]->GetMaximum()/individualpt1histos[isample]->Integral();
3367     float currmaxpt2entry=individualpt2histos[isample]->GetMaximum()/individualpt2histos[isample]->Integral();
3368     cout << " pt 1 histo contains; " << individualpt1histos[isample]->Integral() << endl;
3369     cout << " pt 2 histo contains; " << individualpt2histos[isample]->Integral() << endl;
3370     if(currmaxpt1entry>maxpt1entry)maxpt1entry=currmaxpt1entry;
3371     if(currmaxpt2entry>maxpt2entry)maxpt2entry=currmaxpt2entry;
3372     leg->AddEntry(individualpt2histos[isample],((allsamples.collection)[isample].filename).c_str(),"f");
3373     }
3374    
3375     fpt1->GetYaxis()->SetRangeUser(0,maxpt1entry);
3376     fpt2->GetYaxis()->SetRangeUser(0,maxpt2entry);
3377    
3378     ptsancan->cd(1);
3379     fpt1->Draw();
3380     ptsancan->cd(2);
3381     fpt2->Draw();
3382    
3383 buchmann 1.16 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3384 buchmann 1.4 ptsancan->cd(1);
3385     individualpt1histos[isample]->DrawNormalized("same,histo");
3386     ptsancan->cd(2);
3387     individualpt2histos[isample]->DrawNormalized("same,histo");
3388     }
3389     ptsancan->cd(3);
3390     leg->Draw();
3391     CompleteSave(ptsancan,"PtSanityCheck");
3392    
3393     delete ptsancan;
3394     }
3395    
3396 buchmann 1.6 void do_mlls_plot(string mcjzb) {
3397     cout << "At this point we'd plot the mll distribution" << endl;
3398     TCanvas *sigcan = new TCanvas("sigcan","sigcan");
3399 buchmann 1.16 for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
3400 buchmann 1.6 if(!(signalsamples.collection)[isig].events) continue;
3401     string nowname=(signalsamples.collection)[isig].filename;
3402     TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
3403     // TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
3404     mll->SetLineColor(TColor::GetColor("#04B404"));
3405     stringstream poscutS;
3406     poscutS << "((" << mcjzb <<")>50)";
3407     TCut poscut(poscutS.str().c_str());
3408     TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
3409     mllP->SetLineColor(TColor::GetColor("#0040FF"));
3410     mll->Draw("histo");
3411     mllP->Draw("histo,same");
3412     TLegend *leg = make_legend();
3413     leg->SetY1(0.8);
3414     leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
3415     leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
3416     leg->Draw();
3417     TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
3418     TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
3419     lin->Draw("same");
3420     lin2->Draw("same");
3421    
3422     CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
3423     delete mll;
3424     delete mllP;
3425     }
3426     }
3427    
3428 buchmann 1.9 void met_vs_jzb_plots() {
3429    
3430     TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
3431     canmetjzb->SetRightMargin(0.16);
3432    
3433     vector<string> findme;
3434     findme.push_back("DY");
3435     findme.push_back("TTJets");
3436     findme.push_back("LM");
3437    
3438 buchmann 1.16 for(int ifind=0;ifind<(int)findme.size();ifind++) {
3439 buchmann 1.9 vector<int> selsamples = allsamples.FindSample(findme[ifind]);
3440     TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
3441 buchmann 1.16 for(int isel=0;isel<(int)selsamples.size();isel++) {
3442 buchmann 1.9 cout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
3443     allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF);
3444     }
3445     metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
3446     metvsjzb->SetStats(0);
3447     metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
3448     metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
3449     metvsjzb->GetXaxis()->CenterTitle();
3450     metvsjzb->GetYaxis()->CenterTitle();
3451     metvsjzb->Draw("COLZ");
3452     TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
3453     title->SetTextAlign(12);
3454     title->Draw();
3455     CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
3456     }
3457     }
3458    
3459    
3460 buchmann 1.1 void test() {
3461    
3462     TCanvas *testcanv = new TCanvas("testcanv","testcanv");
3463     testcanv->cd();
3464 buchmann 1.33 // switch_overunderflow(true);
3465 buchmann 1.1 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
3466     switch_overunderflow(false);
3467     ptdistr->Draw();
3468     testcanv->SaveAs("test.png");
3469     dout << "HELLO there!" << endl;
3470    
3471     }