ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.54
Committed: Wed Sep 5 14:11:02 2012 UTC (12 years, 8 months ago) by fronga
Content type: text/plain
Branch: MAIN
Changes since 1.53: +118 -123 lines
Log Message:
Added protection against signal region. Prepared consistent list of plots. Also save ratio in SF/OF comparison

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