ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.78
Committed: Wed Jan 9 09:27:00 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.77: +262 -4 lines
Log Message:
Added plots illustrating MC systematics

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