ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.53
Committed: Mon Sep 3 17:02:53 2012 UTC (12 years, 8 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.52: +5 -3 lines
Log Message:
Made peak finding over/underflow resistant; adapted plots for high control region

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