ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.93
Committed: Sun May 12 20:20:58 2013 UTC (11 years, 11 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.92: +334 -69 lines
Log Message:
Adapted JZB closure tests for new ttbar closure (with new ttbar samples); added several new plots for ttbar systematic tests; improved compatibility with different top pair production sample names

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.86 void DoPeakVsPU() {
91     cout << "Trying to find peak position as a function of PU" << endl;
92     float MCPeak, MCPeakError, DataPeak, DataPeakError;
93     stringstream result, datajzb, mcjzb;
94     bool doPUreweighting=true;
95     bool SwitchOffNJetsCut=false;
96    
97 buchmann 1.87
98     TCanvas *can = new TCanvas("can","can");
99 buchmann 1.86 float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
100    
101 buchmann 1.87 float NumVtxBin[6] = {0,5,10,15,20,30};
102 buchmann 1.86
103     stringstream NowCut;
104    
105     TGraphErrors *gMCPeak = new TGraphErrors();
106     gMCPeak->SetTitle("gMCPeak");
107 buchmann 1.87 gMCPeak->SetName("gMCPeak");
108 buchmann 1.86 TGraphErrors *gDataPeak = new TGraphErrors();
109     gDataPeak->SetTitle("gDataPeak");
110 buchmann 1.87 gDataPeak->SetName("gDataPeak");
111 buchmann 1.86 TGraphErrors *gMCWidth = new TGraphErrors();
112     gMCWidth->SetTitle("gMCWidth");
113 buchmann 1.87 gMCWidth->SetName("gMCWidth");
114 buchmann 1.86 TGraphErrors *gDataWidth = new TGraphErrors();
115     gDataWidth->SetTitle("gDataWidth");
116 buchmann 1.87 gDataWidth->SetName("gDataWidth");
117 buchmann 1.86
118     for(int i=0;i<5;i++) {
119     NowCut.str("");
120     NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
121     find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
122     cout << " " << MCPeak << " +/- " << MCPeakError << endl;
123     cout << " " << DataPeak << " +/- " << DataPeakError << endl;
124    
125     gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
126     gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
127    
128     gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
129     gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
130    
131     gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
132     gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
133    
134     gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
135     gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
136     }
137    
138 buchmann 1.87 can->cd();
139     gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
140     gMCPeak->GetYaxis()->SetTitle("Peak position");
141     gMCPeak->GetXaxis()->CenterTitle();
142     gMCPeak->GetYaxis()->CenterTitle();
143     gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
144     gDataPeak->GetYaxis()->SetTitle("Peak position");
145     gDataPeak->GetXaxis()->CenterTitle();
146     gDataPeak->GetYaxis()->CenterTitle();
147    
148     gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
149     gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
150     gDataWidth->GetXaxis()->CenterTitle();
151     gDataWidth->GetYaxis()->CenterTitle();
152     gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
153     gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
154     gMCWidth->GetXaxis()->CenterTitle();
155     gMCWidth->GetYaxis()->CenterTitle();
156    
157     gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
158     gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
159     gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
160     gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
161    
162     gMCPeak->Draw("A2");
163     DrawMCPrelim();
164     CompleteSave(can,"PUStudy/MCPeak");
165     can->cd();
166     gMCWidth->Draw("A2");
167     DrawMCPrelim();
168     CompleteSave(can,"PUStudy/MCWidth");
169     can->cd();
170    
171     gDataPeak->Draw("A2");
172     DrawPrelim();
173     CompleteSave(can,"PUStudy/DataPeak");
174     can->cd();
175     gDataWidth->Draw("A2");
176     DrawPrelim();
177     CompleteSave(can,"PUStudy/DataWidth");
178    
179    
180    
181     delete can;
182 buchmann 1.86
183     }
184    
185 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)
186 buchmann 1.28 {
187 buchmann 1.66 bool overunderflowstatus=addoverunderflowbins;
188 buchmann 1.53 switch_overunderflow(false);
189 buchmann 1.57
190     TCut SpecialCut("mll>=0");
191     if(sSpecialCut!="") SpecialCut=TCut(sSpecialCut.c_str());
192    
193 buchmann 1.31 bool DoInvidualeemmPeaks=false;
194    
195 buchmann 1.28 float mcpeak, datapeak;
196     float mcpeakerr, datapeakerr;
197    
198     float mceepeak,mcmmpeak;
199     float mceepeakerr,mcmmpeakerr;
200    
201     float datammpeak,dataeepeak;
202     float datammpeakerr,dataeepeakerr;
203    
204 fronga 1.40 float mcSigma,mcSigmaError, dataSigma, dataSigmaError;
205 buchmann 1.28
206     dout << "Finding global peak : " << endl;
207 buchmann 1.57 find_one_peak_combination(SpecialCut,SwitchOffNJetsCut,mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
208 buchmann 1.30
209 buchmann 1.31 if(DoInvidualeemmPeaks) {
210     dout << "Finding peak for electrons : " << endl;
211 buchmann 1.57 find_one_peak_combination(SpecialCut&&TCut("id1==0"),SwitchOffNJetsCut,mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
212 buchmann 1.31 dout << "Finding peak for muons : " << endl;
213 buchmann 1.57 find_one_peak_combination(SpecialCut&&TCut("id1==1"),SwitchOffNJetsCut,mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
214 buchmann 1.31
215     datajzb << "(" << jzbvariabledata;
216     mcjzb << "(" << jzbvariablemc;
217    
218     if(dataeepeak>0) datajzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
219     else datajzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
220    
221     if(datammpeak>0) datajzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
222     else datajzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
223    
224     if(datapeak>0) datajzb << "- (id1!=id2)*" << TMath::Abs(datapeak) << " ";
225     else datajzb << "+ (id1!=id2)*" << TMath::Abs(datapeak) << " ";
226    
227     datajzb << ")";
228    
229     if(mceepeak>0) mcjzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
230     else mcjzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
231    
232     if(mcmmpeak>0) mcjzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
233     else mcjzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
234    
235     if(mcpeak>0) mcjzb << "- (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
236     else mcjzb << "+ (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
237    
238     mcjzb << ")";
239 buchmann 1.56
240 buchmann 1.31 } else {
241     datajzb << "(" << jzbvariabledata;
242 buchmann 1.93 mcjzb << "(" << jzbvariablemc;
243 buchmann 1.31
244     if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
245     else datajzb << "+ " << TMath::Abs(datapeak) << " ";
246    
247     datajzb << ")";
248    
249     if(mcpeak>0) mcjzb << "- " << TMath::Abs(mcpeak) << " ";
250     else mcjzb << "+ " << TMath::Abs(mcpeak) << " ";
251    
252     mcjzb << ")";
253     }
254 buchmann 1.36
255 buchmann 1.56 MCPeak=mcpeak;
256     MCPeakError=mcpeakerr;
257     DataPeak=datapeak;
258     DataPeakError=datapeakerr;
259 buchmann 1.66 switch_overunderflow(overunderflowstatus);
260 buchmann 1.28 }
261    
262 fronga 1.40 void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
263 buchmann 1.11 float min=70.0;
264     float max=115.0;
265     if(!PlottingSetup::RestrictToMassPeak) {
266 buchmann 1.34 min=20;
267 fronga 1.40 max=300;
268 buchmann 1.11 }
269 fronga 1.40 int nbins=int((max-min)/binWidth);
270 buchmann 1.11
271     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
272    
273 buchmann 1.34 stringstream largerzeroS;
274     largerzeroS << "(" << datajzb << ">" << jzbthreshold << ")";
275     TCut largerzeroD(largerzeroS.str().c_str());
276 buchmann 1.11
277     stringstream smallerzeroS;
278 buchmann 1.34 smallerzeroS << "(" << datajzb << "<-" << jzbthreshold << ")";
279     TCut smallerzeroD(smallerzeroS.str().c_str());
280    
281    
282     stringstream largerzeroMS;
283     largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
284     TCut largerzeroM(largerzeroMS.str().c_str());
285    
286     TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
287 buchmann 1.93 THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
288 buchmann 1.34 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
289     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
290     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem", "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
291 buchmann 1.11
292     TH1F *RcorrJZBSBem;
293     TH1F *LcorrJZBSBem;
294     TH1F *RcorrJZBSBeemm;
295     TH1F *LcorrJZBSBeemm;
296    
297 buchmann 1.16 // TH1F *RcorrJZBeemmNoS;
298 buchmann 1.11
299 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
300 buchmann 1.34 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem", "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
301     LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem", "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
302     RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
303     LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
304 buchmann 1.11 }
305    
306 fronga 1.40 // Separate predictions
307 fronga 1.43 TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
308     TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
309     TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
310 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
311 fronga 1.43 OFP->Scale(1.0/3.0);
312     OFP->Add(RcorrJZBSBem,1.0/3.);
313     OFP->Add(RcorrJZBSBeemm,1.0/3.);
314     OFN->Scale(1.0/3.0);
315     OFN->Add(LcorrJZBSBem,1.0/3.);
316     OFN->Add(LcorrJZBSBeemm,1.0/3.);
317     }
318    
319     TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
320     Bpred->Add(OFP);
321     Bpred->Add(OFN,-1);
322 buchmann 1.11 Bpred->SetLineColor(kRed);
323    
324 fronga 1.40 RcorrJZBeemm->SetTitleOffset(1.3,"y");
325 buchmann 1.11 RcorrJZBeemm->Draw();
326 buchmann 1.77 mcRcorrJZBeemm.Draw("histo,same");
327 buchmann 1.11 Bpred->Draw("histo,same");
328     RcorrJZBeemm->Draw("same");
329    
330     TLegend *leg = allsamples.allbglegend();
331     leg->SetX1(0.58);
332 buchmann 1.88 // leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
333 buchmann 1.11 leg->AddEntry(Bpred,"predicted (data)","l");
334     leg->Draw("same");
335    
336     stringstream saveas;
337     saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
338     CompleteSave(ckin,saveas.str());
339 buchmann 1.34
340 fronga 1.40 // Draw all predictions overlayed
341 fronga 1.43 unsigned int w = gStyle->GetHistLineWidth()+1; // Make line a bit wider, since we dash it
342     SFN->SetLineColor(kGreen+2);
343     SFN->SetLineStyle(2);
344     SFN->SetLineWidth(w);
345     OFP->SetLineColor(kBlue+2);
346     OFP->SetLineStyle(2);
347     OFP->SetLineWidth(w);
348     OFN->SetLineColor(kMagenta+2);
349     OFN->SetLineStyle(3);
350     OFN->SetLineWidth(w);
351 buchmann 1.34
352     RcorrJZBeemm->Draw();
353 fronga 1.43 SFN->Draw("histo,same");
354     OFP->Draw("histo,same");
355     OFN->Draw("histo,same");
356 buchmann 1.34 Bpred->Draw("histo,same");
357     RcorrJZBeemm->Draw("same");
358    
359 fronga 1.40 TLegend *leg2 = make_legend("",0.52,0.7);
360 buchmann 1.88 // leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
361 buchmann 1.34 leg2->AddEntry(Bpred,"predicted (data)","l");
362 fronga 1.43 leg2->AddEntry(SFN, " SF JZB<0","l");
363     leg2->AddEntry(OFN, " OF JZB<0","l");
364     leg2->AddEntry(OFP, " OF JZB>0","l");
365 buchmann 1.34 leg2->Draw("same");
366    
367     saveas.str("");
368     saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
369     CompleteSave(ckin,saveas.str());
370    
371 buchmann 1.11 delete RcorrJZBeemm;
372     delete LcorrJZBeemm;
373     delete RcorrJZBem;
374     delete LcorrJZBem;
375 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
376 buchmann 1.11 delete RcorrJZBSBeemm;
377     delete LcorrJZBSBeemm;
378     delete RcorrJZBSBem;
379     delete LcorrJZBSBem;
380     }
381     delete Bpred;
382     delete ckin;
383 buchmann 1.85 CleanLegends();
384 buchmann 1.11 }
385    
386 buchmann 1.1 void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
387    
388     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
389    
390     TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
391     THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
392     TH1F *datahistoOSOF = allsamples.Draw("datahistoOSOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
393    
394     if(logscale) ckin->SetLogy(1);
395     datahistoOSSF->SetMarkerSize(DataMarkerSize);
396     datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
397     datahistoOSSF->GetXaxis()->CenterTitle();
398     datahistoOSSF->GetYaxis()->SetTitle("events");
399     datahistoOSSF->GetYaxis()->CenterTitle();
400     datahistoOSOF->SetMarkerSize(DataMarkerSize);
401     datahistoOSSF->SetMarkerSize(DataMarkerSize);
402     datahistoOSSF->Draw();
403    
404 buchmann 1.73 mcstackOSSF.Draw("histo,same");
405 buchmann 1.1 datahistoOSSF->Draw("same");
406    
407     datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
408     datahistoOSOF->SetLineColor(kRed);
409     datahistoOSOF->SetMarkerStyle(21);
410     datahistoOSOF->Draw("same");
411    
412     // Try to re-arrange legend...
413     TLegend *bgleg = allsamples.allbglegend("",datahistoOSSF);
414     TLegend *kinleg = make_legend();
415     kinleg->AddEntry(datahistoOSSF,"SF (data)","p");
416     kinleg->AddEntry(datahistoOSOF,"OF (data)","p");
417     TIter next(bgleg->GetListOfPrimitives());
418     TObject* obj;
419     // Copy the nice bkgd legend skipping the "data"
420 buchmann 1.16 while ( (obj = next()) )
421 buchmann 1.1 if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
422     kinleg->GetListOfPrimitives()->Add(obj);
423    
424     kinleg->Draw();
425     CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
426    
427     delete datahistoOSOF;
428     delete datahistoOSSF;
429     delete ckin;
430 buchmann 1.85 CleanLegends();
431 buchmann 1.1 }
432    
433    
434     void draw_ratio_plot(TH1* hdata, THStack& hmc, float ymin=0.5, float ymax=1.5) {
435    
436     // Make a histogram from stack
437     TIter next(hmc.GetHists());
438     TObject* obj;
439     TH1* hratio = NULL;
440 buchmann 1.16 while ( (obj = next()) ) {
441 buchmann 1.1 if ( !hratio ) {
442     hratio = (TH1*)obj->Clone();
443     hratio->SetName("hratio");
444     } else hratio->Add( (TH1*)obj );
445     }
446     hratio->Divide(hdata);
447     hratio->SetMaximum(ymax);
448     hratio->SetMinimum(ymin);
449     hratio->SetMarkerStyle(2);
450     hratio->SetLineWidth(1);
451     hratio->GetYaxis()->SetLabelSize(0.08);
452     hratio->GetXaxis()->SetLabelSize(0.0);
453    
454     TPad* rpad = new TPad("rpad","",0.15,0.73,0.4,0.88);
455     rpad->SetTopMargin(0.0);
456     rpad->SetBottomMargin(0.0);
457     rpad->SetRightMargin(0.0);
458     rpad->Draw();
459     rpad->cd();
460     // hratio->GetXaxis()->SetNdivisions(0);
461     hratio->GetYaxis()->SetNdivisions(502,false);
462     hratio->Draw("e1x0");
463    
464     TF1* oneline = new TF1("","1.0",0,1000);
465     oneline->SetLineColor(kBlue);
466     oneline->SetLineStyle(1);
467     oneline->SetLineWidth(1);
468     oneline->Draw("same");
469     }
470 fronga 1.55
471 buchmann 1.51 float make_one_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
472 fronga 1.58 string xlabel, string filename, float legendPosition=0.55) {
473 pablom 1.46
474     TCut ibasiccut=basiccut;
475     bool draw_separation_lines=false;
476    
477     if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
478    
479     TCut cutSF;
480     TCut cutOF;
481    
482 buchmann 1.91 cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
483 buchmann 1.51 cutOF = cutOSOF&&cutnJets&&ibasiccut;
484     cutSF = cutOSSF&&cutnJets&&ibasiccut;
485 buchmann 1.81
486     TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
487 pablom 1.46
488 fronga 1.54 TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
489     rcan->SetLogy(logscale);
490     rcan->cd();
491    
492 fronga 1.58 std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
493 pablom 1.46 TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
494     TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
495 fronga 1.58 // string signal("LM3");
496     // TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
497     // int idx = signalsamples.FindSample(signal)[0];
498     // (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
499     // signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
500     // signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
501     // signalhisto->SetLineStyle(2);
502 pablom 1.46 datahistoSF->SetMarkerSize(DataMarkerSize);
503     datahistoOF->SetLineColor(kRed);
504    
505     if ( !logscale ) {
506     datahistoSF->SetMinimum(0); // Defaults
507     } else {
508     datahistoSF->SetMinimum(0.5);
509     }
510 buchmann 1.51 if (ymax<0) {
511     if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
512 buchmann 1.81 else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
513 pablom 1.46 } else {
514 buchmann 1.51 datahistoSF->SetMaximum(ymax);
515 pablom 1.46 }
516    
517 buchmann 1.51 float ymaxSet = datahistoSF->GetMaximum();
518    
519 pablom 1.46 datahistoSF->GetXaxis()->SetTitle(xlabel.c_str());
520 buchmann 1.51 datahistoSF->GetYaxis()->SetTitle("Events");
521 pablom 1.46 datahistoSF->GetXaxis()->CenterTitle();
522     datahistoSF->GetYaxis()->CenterTitle();
523    
524 buchmann 1.51 TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.7,false,legendPosition+0.2);
525     mleg->AddEntry(datahistoSF, "Same-flavor", "PL");
526     if (datahistoOF->Integral()>0) {
527     mleg->AddEntry(datahistoOF, "Opposite-flavor", "L");
528     } else {
529     mleg->AddEntry((TObject*)0, "", "");
530     }
531 fronga 1.58 //mleg->AddEntry(signalhisto, "LM3", "L");
532 pablom 1.46
533     datahistoSF->Draw("E1");
534 buchmann 1.51 if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
535 fronga 1.58 //signalhisto->Draw("HIST,SAMES");
536 pablom 1.46 mleg->Draw();
537     DrawPrelim();
538 fronga 1.58 if (datahistoOF->Integral()>0) {
539 buchmann 1.79 Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
540 fronga 1.58 } else {
541     CompleteSave(rcan, "SFOF/" + filename);
542     }
543 pablom 1.46
544     datahistoSF->Delete();
545     datahistoOF->Delete();
546 fronga 1.58 //signalhisto->Delete();
547 pablom 1.46 delete mleg;
548 buchmann 1.79 delete rcan;
549 buchmann 1.81 delete ofsf_can;
550 pablom 1.46
551 buchmann 1.51 return ymaxSet;
552    
553 pablom 1.46 }
554    
555 fronga 1.55 // Compare data to data
556     float make_data_comparison_plot(string variable, TCut cut, int nbins, float min, float max, float ymax, bool logscale,
557     string xlabel, string filename, float legendPosition=0.55) {
558    
559     TCut ibasiccut=basiccut&&cut;
560    
561     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
562     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
563     rcan->SetLogy(logscale);
564     rcan->cd();
565    
566     std::cout << "Data comparison: variable = " << variable << ", cut = " << ibasiccut.GetTitle() << std::endl;
567    
568     TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
569     TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
570 buchmann 1.71 data1->Scale(5.0/9.2);
571 fronga 1.55
572     data1->SetMarkerSize(DataMarkerSize);
573     data2->SetLineColor(kRed);
574    
575     if ( !logscale ) {
576     data1->SetMinimum(0); // Defaults
577     } else {
578     data1->SetMinimum(0.5);
579     }
580     if (ymax<0) {
581     if ( logscale ) data1->SetMaximum(5.3*data1->GetMaximum());
582     else data1->SetMaximum(1.5*data1->GetMaximum());
583     } else {
584     data1->SetMaximum(ymax);
585     }
586    
587     float ymaxSet = data1->GetMaximum();
588    
589     data1->GetXaxis()->SetTitle(xlabel.c_str());
590     data1->GetYaxis()->SetTitle("Events");
591     data1->GetXaxis()->CenterTitle();
592     data1->GetYaxis()->CenterTitle();
593    
594     TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
595 buchmann 1.71 mleg->AddEntry(data1, "2012 data (scaled)", "PL");
596     mleg->AddEntry(data2, "2011 data", "L");
597 fronga 1.55
598     data1->Draw("E1");
599     data2->Draw("HIST,SAMES");
600     mleg->Draw();
601     DrawPrelim();
602 buchmann 1.79 Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
603 fronga 1.55
604     data1->Delete();
605     data2->Delete();
606     delete mleg;
607 buchmann 1.79 delete rcan;
608 fronga 1.55 delete ckin;
609    
610     }
611    
612     void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
613     string xlabel, string filename, float legendPosition=0.55) {
614 buchmann 1.51
615 buchmann 1.68 string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
616     string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
617 buchmann 1.51 string plotname[] = {"_all","_low","_peak","_high"};
618     float ymax;
619 fronga 1.54
620     int start = 0;
621     if ( !PlottingSetup::openBox ) start = 3;
622    
623     for ( int i=start; i<4; ++i ) {
624 buchmann 1.51 if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
625 fronga 1.54 if ( i==start ) {
626 fronga 1.58 ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
627 fronga 1.55 filename+plotname[i], legendPosition );
628 buchmann 1.51 } else {
629 fronga 1.58 make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
630 fronga 1.55 filename+plotname[i], legendPosition );
631 buchmann 1.51 }
632     make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
633 fronga 1.55 filename+plotname[i]+"_mm", legendPosition );
634 buchmann 1.51 make_one_OFSF_plot(variable, "id1==0&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
635 fronga 1.55 filename+plotname[i]+"_ee", legendPosition );
636 buchmann 1.51 }
637    
638     }
639 pablom 1.46
640 buchmann 1.76 TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
641     string scut=(string)(const char*)cut;
642     string acut=ReplaceAll(scut,replacethis,withthis);
643     return TCut(acut.c_str());
644     }
645    
646 buchmann 1.77 void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
647 buchmann 1.76 TCut cut=addcut&&basiccut;
648    
649     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
650     ckin->SetLogy(dolog);
651     cout << "\r Creating " << filename << " : data (1/6)" << std::flush;
652 buchmann 1.77 TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
653 buchmann 1.76 datahisto->SetMarkerSize(DataMarkerSize);
654     if ( !dolog ) datahisto->SetMinimum(0); // Defaults
655     else datahisto->SetMinimum(0.5);
656     if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
657     else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
658     cout << "\r Creating " << filename << " : MC central (2/6)" << std::flush;
659 buchmann 1.77 THStack mcstack = allsamples.DrawStack("mcstack", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
660 buchmann 1.76 TH1F *MCcentral = CollapseStack(mcstack);
661    
662     TCut bkpcut = cut;
663     cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
664     cout << "\r Creating " << filename << " : MC JES up (3/6)" << std::flush;
665 buchmann 1.77 TH1F *MCJESup = allsamples.Draw("MCJESup", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
666 buchmann 1.76
667     cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
668     cout << "\r Creating " << filename << " : MC JES down (4/6)" << std::flush;
669 buchmann 1.77 TH1F *MCJESdn = allsamples.Draw("MCJESdn", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
670 buchmann 1.76
671     cut=bkpcut;
672     TCut bkpweight = cutWeight;
673     cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
674     cout << "\r Creating " << filename << " : MC PU up (5/6)" << std::flush;
675 buchmann 1.77 TH1F *MCPUup = allsamples.Draw("MCPUup", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
676 buchmann 1.76
677     cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
678     cout << "\r Creating " << filename << " : MC PU down (6/6)" << std::flush;
679 buchmann 1.77 TH1F *MCPUdn = allsamples.Draw("MCPUdn", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
680 buchmann 1.76 cutWeight=bkpweight;
681     cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
682     TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
683     for(int i=1;i<=Systematic->GetNbinsX();i++) {
684     float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
685     float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
686     float jes = jesdn>jesup?jesdn:jesup;
687    
688     float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
689     float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
690     float pu = PUdn>PUup?PUdn:PUup;
691    
692     float sys=sqrt(jes*jes+pu*pu);
693     sys/=MCcentral->GetBinContent(i);
694     if(MCcentral->GetBinContent(i)==0) sys=0;
695     Systematic->SetBinContent(i,sys);
696     }
697    
698     datahisto->Draw("e1");
699     ckin->Update();
700     mcstack.Draw("histo,same");
701    
702     datahisto->Draw("same,e1");
703     TLegend *kinleg = allsamples.allbglegend();
704     kinleg->Draw();
705    
706     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
707 buchmann 1.77 kinpad->SetLogy(dolog);
708 buchmann 1.76 kinpad->cd();
709     datahisto->Draw("e1");
710     mcstack.Draw("histo,same");
711     datahisto->Draw("same,e1");
712     datahisto->Draw("same,axis");
713    
714     kinleg->Draw("same");
715     DrawPrelim();
716     string saveas="kin/"+filename;
717    
718     cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
719 buchmann 1.90 save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
720 buchmann 1.76
721     ckin->cd();
722     MCcentral->SetFillColor(kWhite);
723     MCcentral->SetLineColor(kBlack);
724 buchmann 1.77 MCcentral->SetLineWidth(2);
725 buchmann 1.76 MCPUdn->SetLineColor(kRed);
726     MCPUup->SetLineColor(kYellow);
727     MCJESdn->SetLineColor(kBlue);
728     MCJESup->SetLineColor(kGreen);
729    
730 buchmann 1.77 TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
731     legsmall->SetNColumns(5);
732 buchmann 1.76 legsmall->AddEntry(MCcentral,"central","L");
733     legsmall->AddEntry(MCPUdn,"PU down","L");
734     legsmall->AddEntry(MCPUup,"PU up","L");
735     legsmall->AddEntry(MCJESdn,"JES down","L");
736     legsmall->AddEntry(MCJESup,"JES up","L");
737 buchmann 1.77 legsmall->SetFillColor(kWhite);
738     legsmall->SetBorderSize(0);
739 buchmann 1.76
740 buchmann 1.77 datahisto->Draw("e1");
741     MCcentral->Draw("histo,same");
742 buchmann 1.76 MCPUdn->Draw("histo,same");
743     MCPUup->Draw("histo,same");
744     MCJESdn->Draw("histo,same");
745     MCJESup->Draw("histo,same");
746     datahisto->Draw("e1,same");
747     legsmall->Draw();
748 buchmann 1.77 CompleteSave(ckin,saveas+"___AllLines");
749 buchmann 1.76
750 buchmann 1.77 delete datahisto;
751     delete MCcentral;
752     delete MCPUdn;
753     delete MCPUup;
754     delete MCJESdn;
755     delete MCJESup;
756 buchmann 1.76 delete ckin;
757     }
758    
759 buchmann 1.77 void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
760     DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
761     }
762    
763 buchmann 1.1 float lastrange_min=0;
764     float lastrange_max=0;
765    
766     void make_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
767     string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
768     // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
769     TCut ibasiccut=basiccut;
770     bool draw_separation_lines=false;
771 buchmann 1.67 bool drawsignal = false;
772 buchmann 1.1
773     if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
774    
775     if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
776    
777     //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
778     if(isPF) {
779     if(variable=="mll") variable="pfmll[0]";
780     if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
781     if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
782     if(variable=="pt") variable="pfpt[0]";
783     if(variable=="pt1") variable="pfpt1[0]";
784     if(variable=="pt2") variable="pfpt2[0]";
785     if(variable=="eta1") variable="pfeta1[0]";
786     if(variable=="jzb[1]") variable="pfjzb[0]";
787     //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
788     }
789    
790     //Step 2: Refine the cut
791     TCut cut;
792     cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
793 buchmann 1.66 if(filename=="nJets" || filename=="nJets_inclusive" || filename=="nJets_met100" || filename=="nJets_inclusive_met100") cut=cutmass&&cutOSSF&&ibasiccut;
794     if(filename=="nJets_osof" || filename=="nJets_osof_inclusive" || filename=="nJets_osof_met100" || filename=="nJets_osof_inclusive_met100") cut=cutmass&&cutOSOF&&ibasiccut;
795 buchmann 1.1 if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
796 buchmann 1.66 if(filename=="mll"||filename=="mll_met100") {
797 buchmann 1.1 cut=cutOSSF&&cutnJets&&ibasiccut;
798     draw_separation_lines=true;
799     }
800 buchmann 1.66 if(filename=="mll_ee"||filename=="mll_ee_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
801     if(filename=="mll_mm"||filename=="mll_mm_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
802     if(filename=="mll_osof"||filename=="mll_osof_met100") {
803 buchmann 1.1 cut=cutOSOF&&cutnJets&&ibasiccut;
804     draw_separation_lines=true;
805     }
806 buchmann 1.34 if(Contains(filename,"aboveJZB")) cut=cutOSSF&&cutnJets&&ibasiccut;
807     if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
808     if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
809 buchmann 1.11 if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
810 buchmann 1.66 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
811     if(filename=="mll_inclusive_osof") cut=cutOSOF;
812     if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
813     if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
814 buchmann 1.1 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
815     if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
816 fronga 1.54 if(filename=="numVtx") cut=cutmass&&ibasiccut;
817 buchmann 1.1
818     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
819     ckin->SetLogy(logscale);
820     TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
821     datahisto->SetMarkerSize(DataMarkerSize);
822 fronga 1.40 if ( !logscale ) datahisto->SetMinimum(0); // Defaults
823     else datahisto->SetMinimum(0.5);
824     // Custom max.
825     if(variable=="TMath::Abs(pfJetDphiMet[0])") datahisto->SetMaximum(1.5*datahisto->GetMaximum());
826 buchmann 1.1 if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
827     if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
828 buchmann 1.22 if(filename=="mll_inclusive"||filename=="mll_inclusive_mm"||filename=="mll_inclusive_ee") datahisto->SetMinimum(1);
829 buchmann 1.1 if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
830     if(filename=="mll_osof") datahisto->SetMinimum(9);
831 fronga 1.40 if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
832     else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
833    
834 buchmann 1.66 cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
835 buchmann 1.1 if(loadlastminmax) {
836     datahisto->SetMinimum(lastrange_min);
837     datahisto->SetMaximum(lastrange_max);
838     if(logscale) {
839     datahisto->SetMinimum(pow(10,lastrange_min));
840     datahisto->SetMaximum(pow(10,lastrange_max));
841     }
842     }
843    
844 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!)
845     string signal("LM3");
846     TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
847     int idx = signalsamples.FindSample(signal)[0];
848 buchmann 1.67 if(drawsignal) (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
849     if(drawsignal) signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
850     if(drawsignal) signalhisto->SetLineColor(kOrange);
851 fronga 1.40
852     THStack mcstack = allsamples.DrawStack("mcstack", variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
853     datahisto->Draw("e1");
854     ckin->Update();
855 buchmann 1.73 mcstack.Draw("histo,same");
856 fronga 1.40
857 buchmann 1.1 datahisto->Draw("same,e1");
858     TLegend *kinleg = allsamples.allbglegend();
859     kinleg->Draw();
860     if(filename=="mll_osof") {
861     kinleg->SetHeader("Opposite flavor");
862     kinleg->SetX1(0.58);
863     }
864     if(filename=="mll") {
865     kinleg->SetHeader("Same flavor");
866     kinleg->SetX1(0.58);
867     }
868     TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
869     write_cut->Draw();
870     TText* write_variable = write_text(0.99,0.01,variable);
871     write_variable->SetTextAlign(31);
872     write_variable->SetTextSize(0.02);
873    
874     TLine *lowerboundary;
875     TLine *upperboundary;
876    
877     if(RestrictToMassPeak&&draw_separation_lines) {
878     Color_t linecolor=kBlue;
879     float linemin=pow(10,ckin->GetUymin());
880     if(filename=="mll_osof") linemin=pow(10,lastrange_min);
881     lowerboundary = new TLine(71,linemin,71,datahisto->GetMaximum());
882     upperboundary = new TLine(111,linemin,111,datahisto->GetMaximum());
883     lowerboundary->SetLineColor(linecolor);
884     lowerboundary->SetLineStyle(2);
885     upperboundary->SetLineColor(linecolor);
886     upperboundary->SetLineStyle(2);
887     }
888    
889     lastrange_min=ckin->GetUymin();
890     lastrange_max=ckin->GetUymax();
891    
892    
893     if ( plotratio ) {
894     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
895     kinpad->cd();
896     kinpad->SetLogy(logscale);
897     datahisto->Draw("e1");
898 buchmann 1.73 mcstack.Draw("histo,same");
899 buchmann 1.67 if(drawsignal) signalhisto->Draw("same");
900 buchmann 1.1 datahisto->Draw("same,e1");
901     datahisto->Draw("same,axis");
902     if(RestrictToMassPeak&&draw_separation_lines) {
903     lowerboundary->Draw("same");
904     upperboundary->Draw("same");
905     }
906    
907 buchmann 1.67 if(drawsignal) kinleg->AddEntry("signalhisto",signal.c_str(),"l");
908 buchmann 1.1 kinleg->Draw();
909     write_cut->Draw();
910     DrawPrelim();
911     string saveas="kin/"+filename;
912     if(isPF) saveas="kin/"+filename+"__PF";
913 buchmann 1.79 Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
914 buchmann 1.1 // if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
915     // else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
916     // delete with_ratio;
917     } else {
918     if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
919     else CompleteSave(ckin,"kin/"+filename);
920     }
921     datahisto->Delete();
922 buchmann 1.66 delete signalhisto;
923 buchmann 1.1 delete ckin;
924     }
925    
926 buchmann 1.72
927     void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
928     string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
929     TCut cut=TCut(addcut.c_str())&&basiccut;
930    
931     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
932     ckin->SetLogy(logscale);
933     TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
934     datahisto->SetMarkerSize(DataMarkerSize);
935     if ( !logscale ) datahisto->SetMinimum(0); // Defaults
936     else datahisto->SetMinimum(0.5);
937     // Custom max.
938     if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
939     else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
940    
941     cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
942     if(loadlastminmax) {
943     datahisto->SetMinimum(lastrange_min);
944     datahisto->SetMaximum(lastrange_max);
945     if(logscale) {
946     datahisto->SetMinimum(pow(10,lastrange_min));
947     datahisto->SetMaximum(pow(10,lastrange_max));
948     }
949     }
950    
951     THStack mcstack = allsamples.DrawStack("mcstack", variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
952     datahisto->Draw("e1");
953     ckin->Update();
954 buchmann 1.73 mcstack.Draw("histo,same");
955 buchmann 1.72
956     datahisto->Draw("same,e1");
957     TLegend *kinleg = allsamples.allbglegend();
958     kinleg->Draw();
959    
960     lastrange_min=ckin->GetUymin();
961     lastrange_max=ckin->GetUymax();
962    
963     if ( plotratio ) {
964     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
965     kinpad->cd();
966     kinpad->SetLogy(logscale);
967     datahisto->Draw("e1");
968 buchmann 1.73 mcstack.Draw("histo,same");
969 buchmann 1.72 datahisto->Draw("same,e1");
970     datahisto->Draw("same,axis");
971    
972     kinleg->Draw();
973     DrawPrelim();
974     string saveas="kin/"+filename;
975     if(isPF) saveas="kin/"+filename+"__PF";
976 buchmann 1.79 Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
977 buchmann 1.72 } else {
978     if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
979     else CompleteSave(ckin,"kin/"+filename);
980     }
981     datahisto->Delete();
982     delete ckin;
983     }
984    
985    
986 fronga 1.40 void make_JES_plot(TCut cut, string name) {
987 buchmann 1.1
988     int nbins=10;
989     float min=-0.5;
990     float max = 9.5;
991     bool logscale=true;
992     string xlabel="nJets";
993    
994     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
995     ckin->SetLogy(logscale);
996 fronga 1.40 TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,data,luminosity);
997 buchmann 1.1 datahisto->SetMarkerSize(DataMarkerSize);
998 fronga 1.40 THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,mc,luminosity);
999     TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum40p1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1000     TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum40n1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1001 buchmann 1.1
1002     datahisto->SetMinimum(1);
1003     datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
1004    
1005     float xs[nbins],ys[nbins],exs[nbins],eys[nbins];
1006     for(int i=1;i<JESup->GetNbinsX();i++) {
1007     float up=JESup->GetBinContent(i);
1008     float dn=JESdn->GetBinContent(i);
1009     xs[i]=JESup->GetBinCenter(i);
1010     ys[i]=0.5*(up+dn);
1011     exs[i]=0.5*JESup->GetBinWidth(i);
1012     eys[i]=0.5*TMath::Abs(up-dn);
1013     }
1014    
1015     TGraphAsymmErrors *JESunc = new TGraphAsymmErrors(nbins, xs,ys,exs,exs,eys,eys);
1016     JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
1017     JESunc->SetFillStyle(3002);
1018     datahisto->Draw("e1");
1019 buchmann 1.73 mcstack.Draw("histo,same");
1020 buchmann 1.1 JESunc->Draw("2");
1021     datahisto->Draw("same,e1");
1022     TLegend *kinleg = allsamples.allbglegend();
1023     kinleg->AddEntry(JESunc,"JES uncertainty","f");
1024     kinleg->Draw();
1025 fronga 1.40 CompleteSave(ckin,"Systematics/JES"+name);
1026 buchmann 1.1 datahisto->Delete();
1027     delete ckin;
1028 buchmann 1.85 delete JESunc;
1029     delete JESup;
1030     delete JESdn;
1031     CleanLegends();
1032 buchmann 1.1 }
1033    
1034 buchmann 1.72 string Cut2Str(TCut cut) {
1035     return ((string)(const char*)cut);
1036     }
1037    
1038     void MakeElegantTwoThreeComparisons() {
1039    
1040 buchmann 1.73 TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
1041 buchmann 1.72 TCut TwoJets("pfJetGoodNum40==2");
1042     TCut ThreeJets("pfJetGoodNum40>=3");
1043    
1044 buchmann 1.73 float min=20;
1045     float max=300;
1046     int nbins=int((max-min)/5.0);
1047     string xlabel="m_{ll} [GeV]";
1048 buchmann 1.72
1049     TCanvas *can2 = new TCanvas("can2","can2");
1050 buchmann 1.93 TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1051     TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1052     TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1053     TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1054 buchmann 1.72
1055     can2->cd(1);
1056    
1057     TwoSF->SetFillColor(kWhite);
1058     TwoOF->SetFillColor(kWhite);
1059     ThreeSF->SetFillColor(kWhite);
1060     ThreeOF->SetFillColor(kWhite);
1061    
1062     TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1063     kin3->cd();
1064     TwoOF->Draw("histo");
1065     TwoSF->Draw("e1,same");
1066     TLegend *leg_SFOF_Two = make_legend();
1067     leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1068     leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1069     leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1070     leg_SFOF_Two->Draw();
1071 buchmann 1.79 Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1072 buchmann 1.72
1073     TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1074     kin4->cd();
1075     ThreeOF->Draw("histo");
1076     ThreeSF->Draw("e1,same");
1077     TLegend *leg_SFOF_Three = make_legend();
1078     leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1079     leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1080     leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1081     leg_SFOF_Three->Draw();
1082 buchmann 1.79 Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1083 buchmann 1.72
1084 buchmann 1.73
1085     TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1086     TPad *kin = new TPad("kin","kin",0,0,1,1);
1087     kin->cd();
1088     TwoSF->Draw("histo");
1089     ThreeSF->Draw("e1,same");
1090     TLegend *leg_SF_Two_Three = make_legend();
1091     leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1092     leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1093     leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1094     leg_SF_Two_Three->Draw();
1095 buchmann 1.79 Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1096 buchmann 1.73
1097     TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1098     TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1099     kin2->cd();
1100     TwoOF->Draw("histo");
1101     ThreeOF->Draw("e1,same");
1102     TLegend *leg_OF_Two_Three = make_legend();
1103     leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1104     leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1105     leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1106     leg_OF_Two_Three->Draw();
1107 buchmann 1.79 Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1108 buchmann 1.73
1109 buchmann 1.72 }
1110    
1111 buchmann 1.78 void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1112     pad->cd();
1113     TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1114     for(int i=1;i<=Down->GetNbinsX();i++) {
1115     float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1116     float error=abs(Down->GetBinContent(i)-average);
1117     gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1118     gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1119     }
1120     gr->SetFillColor(TColor::GetColor("#F79F81"));
1121     gr->GetYaxis()->SetRangeUser(0,2);
1122     gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1123     gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1124     gr->GetXaxis()->CenterTitle();
1125     gr->GetYaxis()->CenterTitle();
1126    
1127     gr->Draw("A2");
1128     central->Draw("e1,same");
1129     DrawMCPrelim();
1130     TText *rtitle = write_text(0.8,0.8,title);
1131     TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1132     line->SetLineColor(kBlue);
1133     line->SetLineStyle(2);
1134     line->Draw("same");
1135     rtitle->Draw("same");
1136     }
1137    
1138     TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1139     TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1140     basehisto->Add(originalttbar,-1);
1141     basehisto->Add(httbar);
1142    
1143     string sname=httbar->GetName();
1144     sname="R"+sname.substr(1,sname.length());
1145     TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1146     ratio->Divide(basehisto);
1147     delete basehisto;
1148     return ratio;
1149     }
1150    
1151     void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1152    
1153     TCut cut=addcut&&basiccut;
1154    
1155     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1156     ckin->SetLogy(dolog);
1157 buchmann 1.86 cout << "\r Creating " << filename << " : data (1/7)" << std::flush;
1158 buchmann 1.78 TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1159     datahisto->SetMarkerSize(DataMarkerSize);
1160     if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1161     else datahisto->SetMinimum(0.5);
1162     if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1163     else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1164 buchmann 1.86 cout << "\r Creating " << filename << " : MC central (stack) (2/7)" << std::flush;
1165 buchmann 1.78 THStack mcstack = allsamples.DrawStack("mcstack", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1166     TH1F *MCcentral = CollapseStack(mcstack);
1167    
1168 buchmann 1.86 cout << "\r Creating " << filename << " : MC central (histo) (3/7)" << std::flush;
1169 buchmann 1.93 TH1F *TCentral = allsamples.Draw ("TCentral", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("/TT_"));
1170 buchmann 1.78 TH1F *RCentral = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1171    
1172 buchmann 1.86 cout << "\r Creating " << filename << " : MC Matching up (4/7)" << std::flush;
1173 buchmann 1.78 TH1F *TMatchingUp = systsamples.Draw("TMatchingUp", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1174     TH1F *RMatchingUp = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1175    
1176 buchmann 1.86 cout << "\r Creating " << filename << " : MC Matching down (5/7)" << std::flush;
1177 buchmann 1.78 TH1F *TMatchingDown = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1178     TH1F *RMatchingDown = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1179    
1180 buchmann 1.86 cout << "\r Creating " << filename << " : MC Scale up (6/7)" << std::flush;
1181 buchmann 1.78 TH1F *TScaleUp = systsamples.Draw("TScaleUp", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1182     TH1F *RScaleUp = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1183    
1184 buchmann 1.86 cout << "\r Creating " << filename << " : MC Scale down (7/7)" << std::flush;
1185 buchmann 1.78 TH1F *TScaleDown = systsamples.Draw("TScaleDown", mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1186     TH1F *RScaleDown = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1187    
1188     datahisto->Draw("e1");
1189     ckin->Update();
1190     mcstack.Draw("histo,same");
1191    
1192     datahisto->Draw("same,e1");
1193     TLegend *kinleg = allsamples.allbglegend();
1194     kinleg->Draw();
1195    
1196     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1197     kinpad->SetLogy(dolog);
1198     kinpad->cd();
1199     datahisto->Draw("e1");
1200     mcstack.Draw("histo,same");
1201     datahisto->Draw("same,e1");
1202     datahisto->Draw("same,axis");
1203    
1204     kinleg->Draw("same");
1205     DrawPrelim();
1206     string saveas="kin/"+filename;
1207    
1208     cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1209 buchmann 1.79 Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1210     delete kinpad;
1211 buchmann 1.78
1212     ckin->cd();
1213     TCentral->SetLineColor(kBlack);
1214    
1215     TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1216     TMatchingUp->SetLineStyle(2);//dashed
1217     TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1218     TMatchingDown->SetLineStyle(3);//dotted
1219    
1220     TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1221     TScaleUp->SetLineStyle(2);//dashed
1222     TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1223     TScaleDown->SetLineStyle(3);//dotted
1224    
1225     MCcentral->SetLineStyle(3);
1226     MCcentral->SetLineColor(kRed);
1227    
1228     TCentral->Draw("e1,same");
1229     TCentral->Draw("histo,same");
1230     TMatchingUp->Draw("histo,same");
1231     TMatchingDown->Draw("histo,same");
1232     TScaleUp->Draw("histo,same");
1233     TScaleDown->Draw("histo,same");
1234    
1235     TLegend *sleg = make_legend();
1236     sleg->AddEntry(TCentral,"Central","L");
1237     sleg->AddEntry(TMatchingUp,"matching up","L");
1238     sleg->AddEntry(TMatchingDown,"matching down","L");
1239     sleg->AddEntry(TScaleUp,"scale up","L");
1240     sleg->AddEntry(TScaleDown,"scale down","L");
1241     sleg->Draw();
1242    
1243     CompleteSave(ckin,saveas+"___AllLines");
1244     ckin->cd();
1245     ckin->SetLogy(0);
1246    
1247     RCentral->SetLineColor(kBlack);
1248    
1249     RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1250     RMatchingUp->SetLineStyle(2);//dashed
1251     RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1252     RMatchingDown->SetLineStyle(3);//dotted
1253    
1254     RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1255     RScaleUp->SetLineStyle(2);//dashed
1256     RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1257     RScaleDown->SetLineStyle(3);//dotted
1258    
1259     RCentral->GetYaxis()->SetRangeUser(0,2);
1260     RCentral->Draw("e1");
1261     RMatchingUp->Draw("histo,same");
1262     RMatchingDown->Draw("histo,same");
1263     RScaleUp->Draw("histo,same");
1264     RScaleDown->Draw("histo,same");
1265    
1266     CompleteSave(ckin,saveas+"___AllRatios");
1267    
1268 buchmann 1.85 TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1269     multicanvas->Divide(2,1);
1270 buchmann 1.78 PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1271     PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1272     CompleteSave(multicanvas,saveas+"___RangeIllustration");
1273    
1274    
1275     delete datahisto;
1276     delete TCentral;
1277     delete TMatchingUp;
1278     delete TMatchingDown;
1279     delete TScaleUp;
1280     delete TScaleDown;
1281 buchmann 1.85 // delete Ttmass166;
1282     // delete Ttmass169;
1283     // delete Ttmass175;
1284     // delete Ttmass178;
1285 buchmann 1.78
1286     delete ckin;
1287    
1288     }
1289    
1290     void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1291     make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1292     }
1293 buchmann 1.72
1294 buchmann 1.79 void ProduceJanPlots() {
1295     TCanvas *c1 = new TCanvas("c1","c1");
1296     TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1297     TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1298    
1299     TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1300     rcan->cd();
1301    
1302     metOF->SetLineColor(kRed);
1303     metSF->Draw("e1");
1304     metOF->Draw("histo,same");
1305     metSF->Draw("e1,same");
1306    
1307     TLegend *leg = make_legend();
1308    
1309     leg->AddEntry(metSF,"Data SF","p");
1310     leg->AddEntry(metOF,"Data OF","l");
1311     leg->Draw();
1312    
1313     DrawPrelim();
1314    
1315     Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1316    
1317     delete rcan;
1318     delete metSF;
1319     delete metOF;
1320     delete c1;
1321     }
1322    
1323 buchmann 1.81 THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1324 buchmann 1.79 THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1325    
1326     //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1327     if(variation!="Central") {
1328     TH1F *varttbar;
1329     if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1330     if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1331     if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1332     if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1333     assert(varttbar);
1334    
1335     TIter nextHisto(SystPlot.GetHists());
1336     TH1F* h;
1337     while ( h = (TH1F*)nextHisto() ) {
1338     if(Contains(h->GetName(),"t_bar_t")) {
1339     varttbar->Scale(h->Integral()/varttbar->Integral());
1340     for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1341     h->SetBinContent(i,varttbar->GetBinContent(i));
1342     h->SetBinError(i,varttbar->GetBinError(i));
1343     }
1344 buchmann 1.81 thisto=(TH1F*)varttbar->Clone(variation.c_str());
1345 buchmann 1.79 SystPlot.Modified();
1346     }
1347     }
1348     delete varttbar;
1349 buchmann 1.81 } else {
1350     TIter nextHisto(SystPlot.GetHists());
1351     TH1F* h;
1352     while ( h = (TH1F*)nextHisto() ) {
1353     if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1354     }
1355 buchmann 1.79 }
1356 buchmann 1.81
1357 buchmann 1.79 TLegend *fullleg = allsamples.allbglegend();
1358     fullleg->SetHeader(variation.c_str());
1359     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1360     kinpad->SetLogy(1);
1361     kinpad->cd();
1362    
1363     hdata->Draw("e1");
1364     SystPlot.Draw("histo,same");
1365     hdata->Draw("e1,same");
1366     fullleg->Draw();
1367     DrawPrelim();
1368    
1369     Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1370     CleanLegends();
1371    
1372     delete kinpad;
1373     return SystPlot;
1374     }
1375    
1376    
1377    
1378     void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1379     TCanvas *ca = new TCanvas("ca","ca");
1380     TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1381    
1382 buchmann 1.81 TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1383    
1384     THStack ScaleUp = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1385     THStack ScaleDown = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1386     THStack MatchingUp = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1387     THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1388 buchmann 1.79
1389     TH1F *HScaleUp = CollapseStack(ScaleUp);
1390     TH1F *HScaleDown = CollapseStack(ScaleDown);
1391     TH1F *HMatchingUp = CollapseStack(MatchingUp);
1392     TH1F *HMatchingDown = CollapseStack(MatchingDown);
1393    
1394 buchmann 1.81 THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1395 buchmann 1.79 TH1F *HCentral = CollapseStack(Central);
1396    
1397     TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1398     for(int i=1;i<=Systematic->GetNbinsX();i++) {
1399     float matchingup = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1400     float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1401     float scaleup = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1402     float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1403    
1404     float matching = matchingup>matchingdown?matchingup:matchingdown;
1405     float scale = scaleup>scaledown?scaleup:scaledown;
1406    
1407     float sys=sqrt(matching*matching+scale*scale);
1408     sys/=HCentral->GetBinContent(i);
1409     if(HCentral->GetBinContent(i)==0) sys=0;
1410     Systematic->SetBinContent(i,sys);
1411     }
1412    
1413     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1414     kinpad->SetLogy(1);
1415     kinpad->cd();
1416 buchmann 1.81 if(variable=="genMET") {
1417     Central.Draw("histo");
1418     } else {
1419     hdata->Draw("e1");
1420     Central.Draw("histo,same");
1421     hdata->Draw("e1,same");
1422     }
1423    
1424 buchmann 1.79 DrawPrelim();
1425 buchmann 1.81
1426 buchmann 1.90 save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1427 buchmann 1.79
1428 buchmann 1.81 kinpad->cd();
1429     tCentral->SetFillColor(kWhite);
1430     tCentral->SetLineColor(kBlack);
1431     tScaleUp->SetLineColor(kRed);
1432     tScaleDown->SetLineColor(kRed);
1433     tMatchingUp->SetLineColor(kBlue);
1434     tMatchingDown->SetLineColor(kBlue);
1435     tScaleUp->SetLineStyle(2);
1436     tScaleDown->SetLineStyle(3);
1437     tMatchingUp->SetLineStyle(2);
1438     tMatchingDown->SetLineStyle(3);
1439    
1440     TLegend *leg2 = make_legend();
1441     leg2->AddEntry(hdata,"Data","p");
1442     leg2->AddEntry(tCentral,"Central (ttbar)","l");
1443     leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1444     leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1445     leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1446     leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1447     if(variable=="genMET") {
1448     Central.Draw("histo");
1449     }else {
1450     hdata->Draw("e1");
1451     Central.Draw("histo,same");
1452     hdata->Draw("e1,same");
1453     }
1454     tCentral->Draw("histo,same");
1455     tScaleUp->Draw("histo,same");
1456     tScaleDown->Draw("histo,same");
1457     tMatchingUp->Draw("histo,same");
1458     tMatchingDown->Draw("histo,same");
1459     leg2->Draw();
1460    
1461     CompleteSave(kinpad,saveas+"__TTbarComparison");
1462    
1463     gStyle->SetOptFit(0);
1464    
1465     kinpad->cd();
1466     kinpad->SetLogy(0);
1467     TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1468     MatchingRatio->Divide(tMatchingDown);
1469     TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1470     lone->SetLineColor(TColor::GetColor("#01DF01"));
1471     lone->SetLineStyle(2);
1472     TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1473     ScaleRatio->Divide(tScaleDown);
1474     MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1475     MatchingRatio->Draw("e1");
1476     TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1477     MatchingRatio->Fit("QP1","R");
1478     lone->Draw();
1479     stringstream summary;
1480     summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1481     summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1482     TText *infobox = write_title(summary.str());
1483     infobox->SetX(0.75);
1484     infobox->SetTextSize(0.03);
1485     infobox->SetY(0.75);
1486     infobox->Draw();
1487     CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1488     kinpad->cd();
1489     ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1490     ScaleRatio->Draw("e1");
1491     ScaleRatio->Fit("QP1","R");
1492     summary.str("");
1493     summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1494     summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1495     TText *infobox2 = write_title(summary.str());
1496     infobox2->SetX(0.75);
1497     infobox2->SetTextSize(0.03);
1498     infobox2->SetY(0.75);
1499     infobox2->Draw();
1500    
1501     lone->Draw();
1502     CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1503    
1504    
1505     delete QP1;
1506     delete infobox;
1507     delete infobox2;
1508     delete MatchingRatio;
1509     delete ScaleRatio;
1510     DeleteStack(ScaleUp);
1511     DeleteStack(ScaleDown);
1512     DeleteStack(MatchingUp);
1513     DeleteStack(MatchingDown);
1514     delete leg2;
1515 buchmann 1.79 CleanLegends();
1516     DeleteStack(Central);
1517     delete Systematic;
1518     delete HScaleUp;
1519     delete HScaleDown;
1520     delete HMatchingUp;
1521     delete HMatchingDown;
1522     delete hdata;
1523     delete HCentral;
1524     delete ca;
1525     }
1526    
1527 buchmann 1.86 TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1528     float val=0,err=0;
1529     vector<float> bins;
1530     vector<float> vals;
1531     vector<float> errs;
1532    
1533     bins.push_back(binninghisto->GetBinLowEdge(1));
1534     int iBin=1;
1535    
1536     for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1537     if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1538     bins.push_back(histo->GetBinLowEdge(i));
1539     vals.push_back(val);val=0;
1540     errs.push_back(err);err=0;
1541     iBin++;
1542     }
1543     val+=histo->GetBinContent(i);
1544     err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1545     }
1546     bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1547     vals.push_back(val);val=0;
1548     errs.push_back(err);err=0;
1549    
1550     TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1551     for(unsigned int i=0;i<vals.size();i++) {
1552     h->SetBinContent(i+1,vals[i]);
1553     h->SetBinError(i+1,errs[i]);
1554     }
1555    
1556     h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1557     h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1558    
1559     h->GetXaxis()->CenterTitle();
1560     h->GetYaxis()->CenterTitle();
1561    
1562     return h;
1563     }
1564    
1565    
1566     TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1567     float statsperbin = (1/(float)nbins) * histo->Integral();
1568     float val=0,err=0;
1569     vector<float> bins;
1570     vector<float> vals;
1571     vector<float> errs;
1572    
1573     bins.push_back(histo->GetBinLowEdge(1));
1574     for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1575     val+=histo->GetBinContent(i);
1576     err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1577     if( val/statsperbin > 0.85) {
1578     if(bins.size()<nbins) {
1579     bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1580     vals.push_back(val);val=0;
1581     errs.push_back(err);err=0;
1582     }
1583     }
1584     if(i==histo->GetNbinsX()) {
1585     bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1586     vals.push_back(val);val=0;
1587     errs.push_back(err);err=0;
1588     }
1589     }
1590     TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1591    
1592     h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1593     h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1594    
1595     h->GetXaxis()->CenterTitle();
1596     h->GetYaxis()->CenterTitle();
1597    
1598     for(unsigned int i=0;i<vals.size();i++) {
1599     h->SetBinContent(i+1,vals[i]);
1600     h->SetBinError(i+1,errs[i]);
1601     }
1602    
1603     return h;
1604     }
1605    
1606    
1607    
1608     void ShowBinning(TH1F *histo) {
1609     cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1610     for(unsigned int i=1;i<=histo->GetNbinsX();i++) cout << " Bin " << i << " : " << histo->GetBinLowEdge(i) << " , " << histo->GetBinLowEdge(i) + histo->GetBinWidth(i) << " : " << histo->GetBinContent(i) << endl;
1611     }
1612    
1613 buchmann 1.81 void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1614     TCanvas *ca = new TCanvas("ca","ca");
1615     TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1616     TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1617     TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1618     TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1619     TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1620    
1621     tScaleUp->Scale(1.0/tScaleUp->Integral());
1622     tScaleDown->Scale(1.0/tScaleDown->Integral());
1623     tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1624     tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1625 buchmann 1.86 tCentral->Scale(1.0/tCentral->Integral());
1626    
1627     cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1628    
1629    
1630     TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1631     TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1632     TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1633     TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
1634     TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
1635    
1636     float min=rtScaleUp->GetMinimum();
1637     float max=rtScaleUp->GetMaximum();
1638    
1639     if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
1640     if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1641     if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1642     if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
1643     if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
1644    
1645     if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
1646     if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1647     if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1648     if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
1649     if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
1650    
1651     rtCentral->SetMaximum(1.2*max);
1652     rtCentral->SetMinimum(0.8*min);
1653    
1654     /* tScaleUp->Rebin(40);
1655     tScaleDown->Rebin(40);
1656     tMatchingDown->Rebin(40);
1657     tMatchingUp->Rebin(40);
1658     tCentral->Rebin(40);*/
1659 buchmann 1.81
1660     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1661     kinpad->SetLogy(1);
1662     kinpad->cd();
1663     tCentral->SetFillColor(kWhite);
1664     tCentral->SetLineColor(kBlack);
1665     tScaleUp->SetLineColor(kRed);
1666     tScaleDown->SetLineColor(kRed);
1667     tMatchingUp->SetLineColor(kBlue);
1668     tMatchingDown->SetLineColor(kBlue);
1669     tScaleUp->SetLineStyle(2);
1670     tScaleDown->SetLineStyle(3);
1671     tMatchingUp->SetLineStyle(2);
1672     tMatchingDown->SetLineStyle(3);
1673    
1674 buchmann 1.86 rtScaleDown->SetLineColor(kRed);
1675     rtMatchingUp->SetLineColor(kBlue);
1676     rtMatchingDown->SetLineColor(kBlue);
1677     rtScaleUp->SetLineStyle(2);
1678     rtScaleDown->SetLineStyle(3);
1679     rtMatchingUp->SetLineStyle(2);
1680     rtMatchingDown->SetLineStyle(3);
1681    
1682 buchmann 1.81 TLegend *leg2 = make_legend();
1683     leg2->AddEntry(tCentral,"Central (ttbar)","l");
1684     leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1685     leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1686     leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1687     leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1688    
1689     tCentral->Draw("histo");
1690     tScaleUp->Draw("histo,same");
1691     tScaleDown->Draw("histo,same");
1692     tMatchingUp->Draw("histo,same");
1693     tMatchingDown->Draw("histo,same");
1694     leg2->Draw();
1695 buchmann 1.86 DrawMCPrelim();
1696     CompleteSave(kinpad,saveas+"__TTbarComparison");
1697     kinpad->cd();
1698     kinpad->SetLogy(0);
1699     rtCentral->Draw("histo");
1700     rtScaleUp->Draw("histo,same");
1701     rtScaleDown->Draw("histo,same");
1702     rtMatchingUp->Draw("histo,same");
1703     rtMatchingDown->Draw("histo,same");
1704     leg2->Draw();
1705     DrawMCPrelim();
1706     CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
1707 buchmann 1.81
1708    
1709     gStyle->SetOptFit(0);
1710 buchmann 1.86
1711 buchmann 1.81 kinpad->cd();
1712     kinpad->SetLogy(0);
1713 buchmann 1.86 TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
1714     MatchingRatio->Divide(rtMatchingDown);
1715 buchmann 1.81 TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1716     lone->SetLineColor(TColor::GetColor("#01DF01"));
1717     lone->SetLineStyle(2);
1718 buchmann 1.86 TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
1719     ScaleRatio->Divide(rtScaleDown);
1720 buchmann 1.81 MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1721     MatchingRatio->Draw("e1");
1722     TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1723 buchmann 1.86 if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
1724 buchmann 1.81 lone->Draw();
1725     stringstream summary;
1726     summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1727     summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1728     TText *infobox = write_title(summary.str());
1729     infobox->SetX(0.75);
1730     infobox->SetTextSize(0.03);
1731     infobox->SetY(0.75);
1732 buchmann 1.86 if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
1733     DrawMCPrelim();
1734 buchmann 1.81 CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1735     kinpad->cd();
1736     ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1737     ScaleRatio->Draw("e1");
1738 buchmann 1.86 if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
1739 buchmann 1.81 summary.str("");
1740     summary << " #splitline{Fit result for f(x) = a+bx :}{#splitline{a=" << DigitsAfterComma(QP1->GetParameter(0),4) << " +/- " << DigitsAfterComma(QP1->GetParError(0),4) << "}{b=" << DigitsAfterComma(QP1->GetParameter(1),4);
1741     summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1742     TText *infobox2 = write_title(summary.str());
1743     infobox2->SetX(0.75);
1744     infobox2->SetTextSize(0.03);
1745     infobox2->SetY(0.75);
1746 buchmann 1.86 if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
1747 buchmann 1.81
1748     lone->Draw();
1749 buchmann 1.86 DrawMCPrelim();
1750 buchmann 1.81 CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1751    
1752 buchmann 1.86 kinpad->cd();
1753     TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
1754     TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
1755     TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
1756    
1757     for(int i=1;i<=SysScale->GetNbinsX();i++) {
1758     float matching, scale;
1759     bool AssumeFactor=false;
1760     if(AssumeFactor) {
1761     // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
1762     matching=0.;
1763     scale=0.;
1764     } else {
1765     // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
1766     matching = fabs( ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
1767     scale = fabs( ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
1768     }
1769    
1770     SysMatching->SetBinContent(i,1+matching);
1771     SysScale->SetBinContent(i,1+scale);
1772     SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
1773     }
1774    
1775     SysHisto->SetLineColor(kGreen);
1776    
1777     SysMatching->SetMaximum(3.0);
1778     SysMatching->SetMinimum(0.0);
1779     SysMatching->Draw("histo");
1780     SysScale->Draw("histo,same");
1781     SysHisto->Draw("histo,same");
1782     CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
1783    
1784     delete SysMatching;
1785     delete SysScale;
1786    
1787     if(!Contains(variable,"gen")) {
1788     TH1F *hdata = allsamples.Draw("hdata", variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1789     THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
1790    
1791     TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1792    
1793     for(int i=1;i<=Systematic->GetNbinsX();i++) {
1794     int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
1795     if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
1796     float sys = SysHisto->GetBinContent(iBin)-1;
1797     Systematic->SetBinContent(i,sys);
1798     }
1799    
1800     kinpad->cd();
1801     TLegend *leg = allsamples.allbglegend();
1802     hdata->Draw();
1803     smc.Draw("histo,same");
1804     hdata->Draw("same");
1805     leg->Draw();
1806     DrawPrelim();
1807 buchmann 1.90 save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
1808 buchmann 1.86
1809     delete Systematic;
1810     delete hdata;
1811     }
1812    
1813    
1814     delete SysHisto;
1815 buchmann 1.81 delete tScaleUp;
1816     delete tScaleDown;
1817     delete tCentral;
1818     delete tMatchingUp;
1819     delete tMatchingDown;
1820 buchmann 1.86 delete rtScaleUp;
1821     delete rtScaleDown;
1822     delete rtCentral;
1823     delete rtMatchingUp;
1824     delete rtMatchingDown;
1825 buchmann 1.81 delete QP1;
1826     delete infobox;
1827     delete infobox2;
1828     delete MatchingRatio;
1829     delete ScaleRatio;
1830     delete leg2;
1831     CleanLegends();
1832     delete ca;
1833     }
1834    
1835 buchmann 1.79 void ProduceMCSystematicPlots() {
1836 buchmann 1.81 cout << "Getting ready to produce systematic plots " << endl;
1837 buchmann 1.79 TCut cutweightBKP = cutWeight;
1838    
1839 buchmann 1.89 QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1840     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1841     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1842     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1843    
1844     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1845     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");
1846     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1847     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1848    
1849     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1850     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1851     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1852     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1853 buchmann 1.82 QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
1854     QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
1855 buchmann 1.81
1856    
1857 buchmann 1.79
1858 buchmann 1.81 cout << "Kicking cutWeight " << (const char*) cutWeight << endl;
1859     cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1860     cutWeight="1.0";
1861    
1862 buchmann 1.89 QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1863     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1864     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1865     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1866    
1867     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1868     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1869     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1870     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1871 buchmann 1.84
1872 buchmann 1.81
1873 buchmann 1.82 // -------------------------------------- ***** AACHEN ***** --------------------------------------
1874    
1875 buchmann 1.86 /*
1876 buchmann 1.82 cutWeight=cutweightBKP;
1877     TCut essentialcutBKP = essentialcut;
1878     cout << (const char*) essentialcut << endl;
1879    
1880     essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
1881     essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1882     essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1883    
1884 buchmann 1.79 TCut cutnJetsBKP = cutnJets;
1885     cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
1886     cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
1887     cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1888     cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1889    
1890 buchmann 1.89 QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1891     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");
1892     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1893     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1894    
1895     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1896     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");
1897     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1898     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1899    
1900     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1901     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1902     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1903     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1904 buchmann 1.82 QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
1905     QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
1906    
1907    
1908    
1909     cout << "Kicking cutWeight " << (const char*) cutWeight << endl;
1910     cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1911     cutWeight="1.0";
1912    
1913 buchmann 1.89 QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1914     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1915     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1916     QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1917    
1918     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1919     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1920     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1921     QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1922 buchmann 1.82
1923 buchmann 1.79 cutnJets = cutnJetsBKP;
1924     cutWeight = cutweightBKP;
1925 buchmann 1.82 essentialcut = essentialcutBKP;
1926 buchmann 1.86 */
1927 buchmann 1.83 write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
1928 buchmann 1.81 }
1929    
1930     void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
1931     TCut cut=pcut&&basiccut;
1932     string variable="mll";
1933     string xlabel="m_{ll} [GeV]";
1934     int nbins=40;
1935     float min=0;
1936     float max=200;
1937    
1938     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1939     TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
1940     TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
1941     TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1942     TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1943     datahistoSF->SetMarkerSize(DataMarkerSize);
1944     datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
1945     datahistoOF->SetMarkerSize(DataMarkerSize);
1946     datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
1947    
1948     THStack mcstackSF = allsamples.DrawStack("mcstackSF", variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
1949     THStack mcstackOF = allsamples.DrawStack("mcstackOF", variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
1950     datahistoSF->Draw("e1");
1951     ckin->Update();
1952     mcstackSF.Draw("histo,same");
1953    
1954     datahistoSF->Draw("same,e1");
1955     TLegend *kinleg = allsamples.allbglegend();
1956     kinleg->Draw();
1957    
1958     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1959     kinpad->cd();
1960     datahistoSF->Draw("e1");
1961     mcstackSF.Draw("histo,same");
1962     datahistoSF->Draw("same,e1");
1963     datahistoSF->Draw("same,axis");
1964     kinleg->Draw();
1965     DrawPrelim();
1966     Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
1967    
1968     kinpad->cd();
1969     datahistoOF->Draw("e1");
1970     mcstackOF.Draw("histo,same");
1971     datahistoOF->Draw("same,e1");
1972     datahistoOF->Draw("same,axis");
1973     kinleg->Draw();
1974     DrawPrelim();
1975     Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
1976    
1977     kinpad->cd();
1978     tauSF->Draw("e1");
1979     tauOF->Draw("histo,same");
1980     tauSF->Draw("e1,same");
1981     TLegend *legtau = make_legend();
1982     legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
1983     legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
1984     legtau->Draw();
1985     DrawPrelim();
1986     Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
1987    
1988     delete datahistoSF;
1989     delete datahistoOF;
1990     delete tauSF;
1991     delete tauOF;
1992     delete kinpad;
1993     delete ckin;
1994     CleanLegends();
1995     }
1996    
1997    
1998     void TauQuestion() {
1999     // MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2000     // MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2001     // MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2002     MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2003 buchmann 1.79 }
2004    
2005 buchmann 1.91 void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2006     string BaseMetCut="met[4]>100";
2007     string Prefix="ETH/";
2008     if(isAachen) {
2009     BaseMetCut="met[4]>150";
2010     Prefix="Aachen/";
2011     }
2012     // make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "S_{T}", Prefix+"FrankT");
2013     make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2014    
2015     make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2016     make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2017     make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2018    
2019     // make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2020     make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2021     make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2022     make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2023    
2024     // make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2025     // make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2026    
2027     // make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 7, 3, 10, true, "#(jets)", Prefix+"njets");
2028     // make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2029     // make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0", 7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2030    
2031     // make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 5, -0.5, 4.5, true, "N_{b-jets}", Prefix+"nbjets");
2032     // make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2033     // make_OFSF_plots("pfJetGoodPt", BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2034    
2035     // make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2036     // make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2037     make_OFSF_plots("pt", BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2038     make_OFSF_plots("pt1", BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2039     make_OFSF_plots("pt2", BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2040     // make_OFSF_plots("eta1", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{1}", Prefix+"eta1", 0.15);
2041     // make_OFSF_plots("eta2", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{2}", Prefix+"eta2", 0.15);
2042     // make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", 0.2);
2043     // make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", 0.2);
2044     // make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", 0.2);
2045     // make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", 0.2);
2046    
2047     // make_OFSF_plots("met[4]", BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET");
2048     // make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", 0.2);
2049     // make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", 0.2);
2050     // make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", 0.2);
2051     // make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2052     // make_OFSF_plots("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", Prefix+"dphijc");
2053     // make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(l,MET)|)", Prefix+"dphilco");
2054     // 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]))))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(jet,MET)|)", Prefix+"dphijco");
2055    
2056     }
2057    
2058     void ProduceOFSFPlots(string mcjzb, string datajzb) {
2059    
2060    
2061     //FIRST : ETH SELECTION
2062     ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2063    
2064    
2065    
2066     string backup_cutnJets = (const char*)cutnJets;
2067     cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2068     cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2069    
2070     string backup_basiccut = (const char*)basiccut;
2071     basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2072    
2073     string backup_essential = (const char*) essentialcut;
2074     essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2075    
2076     ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2077    
2078     cutnJets = TCut(backup_cutnJets.c_str());
2079     basiccut = TCut(backup_basiccut.c_str());
2080     essentialcut = TCut(backup_essential.c_str());
2081     }
2082    
2083    
2084 buchmann 1.1 void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2085     {
2086 buchmann 1.66 // switch_overunderflow(true);
2087 buchmann 1.1 bool dolog=true;
2088     bool nolog=false;
2089 fronga 1.54
2090 buchmann 1.88 bool doOFSF = true;
2091     bool doKin = false;
2092 buchmann 1.81 bool doDataComp = false;
2093     bool MakeTwoThreeJetComparison = false;
2094 fronga 1.55
2095 fronga 1.54
2096 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!");
2097 buchmann 1.17 float mll_low=50;
2098 buchmann 1.2 float mll_hi=160;
2099     if(!PlottingSetup::RestrictToMassPeak) {
2100 buchmann 1.26 mll_low=20;
2101 fronga 1.54 mll_hi=320;
2102 buchmann 1.2 }
2103 buchmann 1.72
2104 buchmann 1.73 if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2105 buchmann 1.81
2106     //TauQuestion();
2107 fronga 1.54
2108 buchmann 1.79 //ProduceJanPlots();
2109 buchmann 1.88 //ProduceMCSystematicPlots();
2110     //assert(0);
2111 buchmann 1.81 // make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2112 buchmann 1.79
2113 buchmann 1.91 if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2114     assert(0);
2115 fronga 1.55
2116 buchmann 1.70 if ( doDataComp) {
2117 fronga 1.55 TCut mllCut("");
2118 fronga 1.62 float massmin = 15.;
2119     float massmax = 315;
2120     int massnbins = 60;
2121 buchmann 1.70 /* if ( !PlottingSetup::openBox ) {
2122 buchmann 1.69 mllCut = "mll>70";
2123 fronga 1.62 massmin = 120;
2124     massmax = 360;
2125     massnbins = 14;
2126 buchmann 1.70 }*/
2127 fronga 1.55
2128     TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2129 buchmann 1.70
2130 buchmann 1.80 make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2131 buchmann 1.71 make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2132    
2133    
2134     make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2135     make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2136 buchmann 1.70 make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2137     make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2138     make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2139    
2140     make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2141 buchmann 1.80 make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2142 buchmann 1.70 make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2143 buchmann 1.80 make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2144    
2145 buchmann 1.70
2146     string basiccutsaved = (const char*)basiccut;
2147    
2148     string newbasiccut=basiccutsaved;
2149    
2150     size_t found;
2151     found = newbasiccut.find( "pt2>20" );
2152     while (found!=string::npos){
2153     newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2154     found = newbasiccut.find( "pt2>20" );
2155     }
2156 buchmann 1.80 basiccut=TCut(newbasiccut.c_str());
2157     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2158     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2159     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2160     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2161     basiccut=TCut(basiccutsaved.c_str());
2162    
2163     make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2164     make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2165    
2166     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2167     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2168     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2169     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2170    
2171    
2172     make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2173     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2174     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2175     make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2176 buchmann 1.70 make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2177     make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2178     make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2179     make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2180 buchmann 1.80
2181 fronga 1.62 make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2182 buchmann 1.71 make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2183    
2184     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");
2185     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");
2186    
2187 fronga 1.62 make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2188 buchmann 1.71 make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2189    
2190 fronga 1.62 make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2191 buchmann 1.71 make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2192 fronga 1.55
2193 buchmann 1.80
2194 fronga 1.62 make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2195 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");
2196     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");
2197 fronga 1.60
2198     make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2199     make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2200     make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2201     make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2202 buchmann 1.80
2203 fronga 1.54 }
2204    
2205 fronga 1.55
2206 fronga 1.54 if ( doKin ) {
2207 fronga 1.55 string mllCut("");
2208 buchmann 1.84
2209 buchmann 1.91 make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2210     make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2211    
2212     make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2213     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2214    
2215     make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2216     make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2217    
2218     make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2219     make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2220    
2221     make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2222     make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2223    
2224     make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2225     make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2226    
2227     make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2228     make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2229    
2230    
2231     assert(0);
2232 buchmann 1.88 make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2233     make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2234 buchmann 1.80
2235 buchmann 1.73 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);
2236     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);
2237     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);
2238     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);
2239    
2240     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);
2241     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);
2242     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);
2243     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);
2244 buchmann 1.77
2245 buchmann 1.74
2246 buchmann 1.75 make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2247     make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2248     make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2249     make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2250 buchmann 1.74
2251 buchmann 1.73
2252     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);
2253     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);
2254     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);
2255     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);
2256    
2257     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);
2258     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);
2259     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);
2260     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);
2261 fronga 1.55
2262 buchmann 1.80 make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2263     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2264 buchmann 1.72
2265 buchmann 1.80 make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2266     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2267 buchmann 1.72
2268 buchmann 1.80 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);
2269     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);
2270 buchmann 1.72
2271 buchmann 1.80 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);
2272     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);
2273    
2274 buchmann 1.72
2275 buchmann 1.80 make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2276     make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2277 buchmann 1.77 // Plots in signal region
2278 buchmann 1.89 make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2279 buchmann 1.77
2280 buchmann 1.78
2281 buchmann 1.80 make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2282 buchmann 1.78
2283 buchmann 1.80 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");
2284 buchmann 1.84 /*
2285 buchmann 1.80 DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2286     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2287     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2288     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2289    
2290 buchmann 1.81 DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2291     DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2292     DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2293     DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2294    
2295 buchmann 1.80 DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2296     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2297     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2298     DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2299    
2300    
2301     DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2302     DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2303     DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2304     DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2305 buchmann 1.78
2306 buchmann 1.80 DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2307     DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2308 buchmann 1.77
2309 buchmann 1.80 DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2310     DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2311 buchmann 1.72
2312 buchmann 1.80 DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2313     DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2314     DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2315     DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2316    
2317     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2318     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);
2319     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);
2320     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);
2321    
2322     make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2323     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2324    
2325     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);
2326     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);
2327     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);
2328     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);
2329 fronga 1.54
2330 buchmann 1.69
2331 buchmann 1.80 make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2332     make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2333 fronga 1.54
2334     // Further inclusive invariant mass plots
2335 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);
2336 buchmann 1.80 make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2337     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2338 buchmann 1.70 make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2339 fronga 1.54
2340 buchmann 1.80 make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2341 fronga 1.54 //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2342    
2343    
2344     // Number of jets
2345     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2346     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2347 buchmann 1.80 make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2348 fronga 1.54
2349     // Others
2350     make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
2351     // make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
2352     // make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
2353     make_kin_plot("pt","",50,0,500,dolog,"Z p_{T} [GeV]","Zpt",doPF);
2354     make_kin_plot("pt1","",50,0,200,nolog,"p_{T} [GeV]","pt1",doPF);
2355     make_kin_plot("pt2","",50,0,200,nolog,"p_{T} [GeV]","pt2",doPF);
2356     make_kin_plot("eta1","",40,-3,3,nolog,"#eta_{l}","eta",doPF);
2357     make_kin_plot("jzb[1]","",100,-150,200,dolog,"JZB [GeV]","jzb_ossf",doPF);
2358     // stringstream jzbcut;
2359     // jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
2360     // make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2361     // 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);
2362     // 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);
2363     // 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);
2364     // stringstream jzbcut2;
2365     // jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
2366     // make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
2367     // 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);
2368     // 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);
2369     // 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);
2370     // stringstream jzbcut3;
2371     // jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
2372     // make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);
2373     // 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);
2374     // 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);
2375     // 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);
2376    
2377     // 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);
2378     //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);
2379 buchmann 1.84 //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);*/
2380 fronga 1.54 }
2381 buchmann 1.88
2382 buchmann 1.80 make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2383     make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2384     make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2385 buchmann 1.67 make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2386 buchmann 1.80 make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2387     make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2388     make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2389 buchmann 1.88 /*
2390 buchmann 1.80 make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2391     make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2392 buchmann 1.84 */
2393 buchmann 1.65 switch_overunderflow(false);
2394 buchmann 1.1 }
2395    
2396     void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
2397     int nbins, float xmin, float xmax, bool log,
2398     float ymin=0, float ymax=0, bool leftJustified=false ) {
2399 fronga 1.40 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
2400 buchmann 1.1
2401     TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
2402     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__));
2403 fronga 1.40 //if(var=="numVtx") cutWeight=TCut("1.0");
2404 buchmann 1.1 TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
2405     TCut jzbMC[] = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
2406    
2407     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- below: the next ~20 lines changed!
2408     int nRegions=4;
2409 buchmann 1.50 if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
2410 buchmann 1.1 nRegions=2;
2411     }
2412    
2413     string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
2414     TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass, cutOSOF&&cutnJets&&cutmass,
2415     cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
2416    
2417     //find ymax
2418     TH1F *Refdatahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[0]&&jzbData[0],data,luminosity);
2419     ymax=int((Refdatahisto->GetMaximum()+2*TMath::Sqrt(Refdatahisto->GetMaximum()))*1.2+0.5);
2420     delete Refdatahisto;
2421    
2422     for ( int iregion=0; iregion<nRegions; ++iregion )
2423     for ( int ijzb=0; ijzb<2; ++ijzb ) {
2424     TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
2425     ccomp->SetLogy(log);
2426     TH1F *datahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
2427 fronga 1.40 TH1F *lm3histo = signalsamples.Draw("lm3histo", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],data,luminosity,signalsamples.FindSample("LM3"));
2428 buchmann 1.1 THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb], mc, luminosity);
2429     datahisto->SetMarkerSize(DataMarkerSize);
2430     if (ymax>ymin) datahisto->SetMaximum(ymax);
2431 fronga 1.40 lm3histo->SetLineStyle(2);
2432 buchmann 1.1 datahisto->Draw("e1");
2433 buchmann 1.73 mcstack.Draw("histo,same");
2434 buchmann 1.1 datahisto->Draw("same,e1");
2435 fronga 1.40 lm3histo->Draw("hist,same");
2436 buchmann 1.1 TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
2437     if ( leftJustified ) {
2438     Float_t w = kinleg->GetX2()-kinleg->GetX1();
2439     kinleg->SetX1(0.2);
2440     kinleg->SetX2(0.2+w);
2441     }
2442 fronga 1.40 kinleg->AddEntry(lm3histo,"LM3","l");
2443 buchmann 1.1 kinleg->Draw();
2444     TText* write_variable = write_text(0.99,0.01,var);
2445     write_variable->SetTextAlign(31);
2446     write_variable->SetTextSize(0.02);
2447     ccomp->RedrawAxis();
2448     CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
2449     delete datahisto;
2450     delete ccomp;
2451 fronga 1.40 delete lm3histo;
2452 buchmann 1.1 }
2453     cutWeight=weightbackup;
2454     }
2455    
2456    
2457     void region_comparison_plots(string mcjzb, string datajzb, vector<float> jzb_cuts) {
2458     dout << "Creating comparison plots for signal and control regions" << endl;
2459     // Compare a few quantities in the signal region and all 7 control regions
2460    
2461 buchmann 1.33 // switch_overunderflow(true); // switching overflow/underflow bins on
2462 buchmann 1.1
2463 buchmann 1.65 switch_overunderflow(true);
2464 buchmann 1.1 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2465 buchmann 1.16 for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2466 buchmann 1.1 float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
2467     float mll_low=50;float mll_high=170;
2468     if(!PlottingSetup::RestrictToMassPeak) {
2469 fronga 1.40 mll_high=300;
2470     mll_low=20;
2471 buchmann 1.1 }
2472 fronga 1.40 make_comp_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",jzbcut,mcjzb,datajzb,100,0,10,true);
2473     make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2474    
2475     make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2476 buchmann 1.91 make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2477 fronga 1.40 make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2478     make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2479 buchmann 1.1 make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
2480 fronga 1.40 make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,40,0.,40.,false,0,16.);
2481 buchmann 1.1 make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2482     make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2483 fronga 1.40 make_comp_plot("eta1","#eta_1","eta1",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2484     make_comp_plot("eta2","#eta_2","eta2",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2485 buchmann 1.1 }
2486    
2487     switch_overunderflow(false); // switching overflow/underflow bins off
2488     }
2489    
2490    
2491    
2492     void do_kinematic_PF_plots(string mcjzb, string datajzb)
2493     {
2494     do_kinematic_plots(mcjzb,datajzb,true);
2495     }
2496    
2497     void signal_bg_comparison()
2498     {
2499     TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
2500     can->SetLogy(1);
2501    
2502     int sbg_nbins=130;
2503     float sbg_min=-500; //-110;
2504     float sbg_max=800; //jzbHigh;
2505    
2506     float simulatedlumi=luminosity;//in pb please - adjust to your likings
2507    
2508 buchmann 1.92 TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2509 buchmann 1.7 TH1F *JZBplotLM4;
2510     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"));
2511     else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2512 buchmann 1.93 TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TT_"));
2513 buchmann 1.1
2514     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
2515     JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
2516     JZBplotZJETs->SetLineColor(kBlack);
2517     JZBplotLM4->SetLineStyle(2);
2518     JZBplotZJETs->SetMaximum(JZBplotZJETs->GetMaximum()*5);
2519     JZBplotZJETs->SetMinimum(1);
2520    
2521     JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2522     JZBplotTtbar->SetMinimum(0.01);
2523     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2524     JZBplotTtbar->DrawClone("histo");
2525     JZBplotZJETs->Draw("histo,same");
2526     JZBplotTtbar->SetFillColor(0);
2527     JZBplotTtbar->DrawClone("histo,same");
2528     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2529     JZBplotLM4->Draw("histo,same");
2530    
2531    
2532     TLegend *signal_bg_comparison_leg2 = make_legend("",0.55,0.75,false);
2533     signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
2534     signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
2535 buchmann 1.7 if(PlottingSetup::RestrictToMassPeak) signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
2536     else signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM3","f");
2537 buchmann 1.1 signal_bg_comparison_leg2->Draw();
2538     DrawMCPrelim(simulatedlumi);
2539     CompleteSave(can,"jzb_bg_vs_signal_distribution");
2540    
2541     // Define illustrative set of SMS points
2542     TCut kSMS1("MassGlu==250&&MassLSP==75");
2543     TCut kSMS2("MassGlu==800&&MassLSP==200");
2544     TCut kSMS3("MassGlu==1050&&MassLSP==850");
2545     TCut kSMS4("MassGlu==1200&&MassLSP==100");
2546    
2547     //If the scan samples haven't been loaded yet, this is a good point to load them (all of them!)
2548     if((scansample.collection).size()<2) define_SMS_sample(false, allsamples, signalsamples, scansample, true); // loading ALL zones for the scans, not only the basic one.
2549    
2550    
2551     TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS1,mc,simulatedlumi,scansample.FindSample("t"));
2552     JZBplotSMS1->Scale(JZBplotLM4->Integral()/JZBplotSMS1->Integral());
2553    
2554     TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS2,mc,simulatedlumi,scansample.FindSample("t"));
2555     JZBplotSMS2->Scale(JZBplotLM4->Integral()/JZBplotSMS2->Integral());
2556    
2557     TH1F *JZBplotSMS3 = scansample.Draw("JZBplotSMS3",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS3,mc,simulatedlumi,scansample.FindSample("t"));
2558     JZBplotSMS3->Scale(JZBplotLM4->Integral()/JZBplotSMS3->Integral());
2559    
2560     TH1F *JZBplotSMS4 = scansample.Draw("JZBplotSMS4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS4,mc,simulatedlumi,scansample.FindSample("t"));
2561     JZBplotSMS4->Scale(JZBplotLM4->Integral()/JZBplotSMS4->Integral());
2562    
2563     // Draw all plots overlaid
2564     JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2565     JZBplotTtbar->SetMinimum(0.01);
2566     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2567     JZBplotTtbar->DrawClone("histo");
2568     JZBplotZJETs->Draw("histo,same");
2569     JZBplotTtbar->SetFillColor(0);
2570     JZBplotTtbar->DrawClone("histo,same");
2571     JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2572    
2573     JZBplotSMS1->SetLineColor(kRed+1);
2574     JZBplotSMS2->SetLineColor(kBlue+1);
2575     JZBplotSMS3->SetLineColor(kRed+1);
2576     JZBplotSMS4->SetLineColor(kBlue+1);
2577     JZBplotSMS3->SetLineStyle(2);
2578     JZBplotSMS4->SetLineStyle(2);
2579    
2580     JZBplotSMS1->Draw("histo,same");
2581     JZBplotSMS2->Draw("histo,same");
2582     JZBplotSMS3->Draw("histo,same");
2583     JZBplotSMS4->Draw("histo,same");
2584     JZBplotLM4->SetLineColor(kGreen);JZBplotLM4->Draw("histo,same");
2585     TLegend *signal_bg_comparison_leg6 = make_legend("",0.55,0.55,false);
2586     signal_bg_comparison_leg6->AddEntry(JZBplotZJETs,"Z+Jets","f");
2587     signal_bg_comparison_leg6->AddEntry(JZBplotTtbar,"t#bar{t}","f");
2588     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
2589     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"SMS parameters","");
2590     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"(250,75) [GeV]","f");
2591     signal_bg_comparison_leg6->AddEntry(JZBplotSMS2,"(800,200) [GeV]","f");
2592     signal_bg_comparison_leg6->AddEntry(JZBplotSMS3,"(1050,850) [GeV]","f");
2593     signal_bg_comparison_leg6->AddEntry(JZBplotSMS4,"(1200,100) [GeV]","f");
2594     signal_bg_comparison_leg6->AddEntry(JZBplotLM4,"LM4","f");
2595     signal_bg_comparison_leg6->Draw();
2596     DrawMCPrelim(simulatedlumi);
2597     CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__summary");
2598    
2599     while((scansample.collection).size() > 1) scansample.RemoveLastSample();
2600    
2601     }
2602    
2603     vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
2604     TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
2605     BpredFunc->SetParameter(0,histo->GetBinContent(1));
2606     if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
2607     BpredFunc->SetParameter(1,0.);
2608     if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
2609     else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
2610     if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
2611     BpredFunc->SetParameter(3,1.8);
2612     BpredFunc->SetParameter(4,2.5);
2613     histo->Fit(BpredFunc,"QN0");
2614     BpredFunc->SetLineColor(kBlue);
2615    
2616     TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
2617     TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
2618    
2619     BpredFuncP->SetParameters(BpredFunc->GetParameters());
2620     BpredFuncP->SetLineColor(kBlue);
2621     BpredFuncP->SetLineStyle(2);
2622    
2623     BpredFuncN->SetParameters(BpredFunc->GetParameters());
2624     BpredFuncN->SetLineColor(kBlue);
2625     BpredFuncN->SetLineStyle(2);
2626    
2627     vector<TF1*> functions;
2628     functions.push_back(BpredFuncN);
2629     functions.push_back(BpredFunc);
2630     functions.push_back(BpredFuncP);
2631     return functions;
2632     }
2633    
2634    
2635     TF1* do_logpar_fit_to_plot(TH1F *osof) {
2636     TCanvas *logpar_fit_can = new TCanvas("logpar_fit_can","Fit canvas for LogPar");
2637     TF1 *logparfunc = new TF1("logparfunc",LogParabola,0,300,3);
2638     TF1 *logparfunc2 = new TF1("logparfunc2",LogParabola,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
2639     TF1 *logparfuncN = new TF1("logparfuncN",LogParabolaN,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
2640     TF1 *logparfuncP = new TF1("logparfuncP",LogParabolaP,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
2641     osof->SetMinimum(0);
2642     osof->Fit(logparfunc,"QR");
2643     osof->Draw();
2644     logparfunc->SetLineWidth(2);
2645     logparfunc2->SetParameters(logparfunc->GetParameters());
2646     logparfuncN->SetParameters(logparfunc->GetParameters());
2647     logparfuncP->SetParameters(logparfunc->GetParameters());
2648     stringstream fitinfo;
2649     fitinfo << "#Chi^{2} / NDF : " << logparfunc->GetChisquare() << " / " << logparfunc->GetNDF();
2650     TText *writefitinfo = write_text(0.8,0.8,fitinfo.str());
2651     writefitinfo->SetTextSize(0.03);
2652     DrawPrelim();
2653     writefitinfo->Draw();
2654     logparfunc->Draw("same");
2655     logparfunc2->Draw("same");
2656     logparfuncN->SetLineStyle(2);
2657     logparfuncP->SetLineStyle(2);
2658     logparfuncN->Draw("same");
2659     logparfuncP->Draw("same");
2660     CompleteSave(logpar_fit_can,"MakingOfBpredFunction/Bpred_Data_LogPar_Fit_To_TTbarPred");
2661     delete logpar_fit_can;
2662     return logparfunc2;
2663     }
2664    
2665     vector<TF1*> do_extended_fit_to_plot(TH1F *prediction, TH1F *Tprediction, TH1F *ossf, TH1F *osof,int isdata) {
2666     /* there are mainly two background contributions: Z+Jets (a) and ttbar (b). So:
2667     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.
2668     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.
2669     Once we have these two components, we use the combined parameters to get the final function and we're done.
2670     */
2671     //Step 1: take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it
2672     TH1F *step1cb = (TH1F*)ossf->Clone("step1cb");
2673     step1cb->Add(osof,-1);
2674     vector<TF1*> functions = do_cb_fit_to_plot(step1cb,PlottingSetup::JZBPeakWidthData);
2675     TF1 *zjetscrystalball = functions[1];
2676    
2677     //Step 2: use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola
2678     // TH1F *ttbarprediction=(TH1F*)prediction->Clone("ttbarprediction");
2679     // ttbarprediction->Add(ossf,-1);//without the Z+Jets estimate, this is really just the ttbar estimate!
2680     // 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)
2681     TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
2682     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2683 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);
2684 buchmann 1.1
2685    
2686     TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
2687     TF1 *ttbarlogparN = new TF1("ttbarlogparN",LogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
2688    
2689     //and now fuse the two!
2690     TF1 *kmlp = new TF1("kmlp", CrystalBallPlusLogParabola, 0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
2691     TF1 *kmlpP= new TF1("kmlpP",CrystalBallPlusLogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
2692     TF1 *kmlpN= new TF1("kmlpN",CrystalBallPlusLogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
2693     double kmlp_pars[10];
2694     for(int i=0;i<5;i++) kmlp_pars[i]=zjetscrystalball->GetParameter(i);
2695     for(int i=0;i<3;i++) kmlp_pars[5+i]=ttbarlogpar->GetParameter(i);
2696     ttbarlogparP->SetParameters(ttbarlogpar->GetParameters());
2697     ttbarlogparN->SetParameters(ttbarlogpar->GetParameters());
2698     kmlp->SetParameters(kmlp_pars);
2699     prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
2700     /*
2701     if you want to start from scratch (without the partial fitting and only fitting the whole thing, some good start values could be :
2702     */
2703     kmlp_pars[0]=kmlp->GetParameter(0);
2704     kmlp_pars[1]=3.6198;
2705     kmlp_pars[2]=16.4664;
2706     kmlp_pars[3]=1.92253;
2707     kmlp_pars[4]=3.56099;
2708     kmlp_pars[5]=5.83;
2709     kmlp_pars[6]=0.000757479;
2710     kmlp_pars[7]=95.6157;
2711     kmlp_pars[8]=0;
2712     kmlp_pars[9]=0;
2713     kmlp->SetParameters(kmlp_pars);
2714     /**/
2715     prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
2716    
2717     kmlpP->SetParameters(kmlp->GetParameters());
2718     kmlpN->SetParameters(kmlp->GetParameters());
2719    
2720     // now that we're done, let's save all of this so we can have a look at it afterwards.
2721     TCanvas *can = new TCanvas("can","Prediction Fit Canvas");
2722     can->SetLogy(1);
2723     prediction->SetMarkerColor(kRed);
2724     prediction->Draw();
2725    
2726     kmlp->SetLineColor(TColor::GetColor("#04B404"));
2727     kmlpP->SetLineColor(TColor::GetColor("#04B404"));
2728     kmlpN->SetLineColor(TColor::GetColor("#04B404"));
2729     kmlp->Draw("same");
2730     kmlpN->SetLineStyle(2);
2731     kmlpP->SetLineStyle(2);
2732     kmlpN->Draw("same");
2733     kmlpP->Draw("same");
2734    
2735     ttbarlogpar->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
2736     ttbarlogpar->Draw("same");
2737     ttbarlogparP->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
2738     ttbarlogparN->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
2739     ttbarlogparP->SetLineStyle(2);
2740     ttbarlogparN->SetLineStyle(2);
2741     ttbarlogparP->Draw("same");
2742     ttbarlogparN->Draw("same");
2743    
2744     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
2745    
2746     TLegend *analyticalBpredLEG = make_legend("",0.5,0.55);
2747     analyticalBpredLEG->AddEntry(prediction,"predicted","p");
2748     analyticalBpredLEG->AddEntry(functions[1],"Crystal Ball fit","l");
2749     analyticalBpredLEG->AddEntry(functions[0],"1#sigma Crystal Ball fit","l");
2750     analyticalBpredLEG->AddEntry(ttbarlogparN,"TTbar fit","l");
2751     analyticalBpredLEG->AddEntry(ttbarlogpar,"1#sigma TTbar fit","l");
2752     analyticalBpredLEG->AddEntry(kmlp,"Combined function","l");
2753     analyticalBpredLEG->AddEntry(kmlpN,"1#sigma combined function","l");
2754     analyticalBpredLEG->Draw("same");
2755    
2756     if(isdata==0) CompleteSave(can,"MakingOfBpredFunction/Bpred_MC_Analytical_Function_Composition");
2757     if(isdata==1) CompleteSave(can,"MakingOfBpredFunction/Bpred_data_Analytical_Function_Composition");
2758     if(isdata==2) CompleteSave(can,"MakingOfBpredFunction/Bpred_MCBnS_Analytical_Function_Composition");
2759     delete can;
2760    
2761     //and finally: prep return functions
2762     vector<TF1*> return_functions;
2763     return_functions.push_back(kmlpN);
2764     return_functions.push_back(kmlp);
2765     return_functions.push_back(kmlpP);
2766    
2767     return_functions.push_back(ttbarlogparN);
2768     return_functions.push_back(ttbarlogpar);
2769     return_functions.push_back(ttbarlogparP);
2770    
2771     return_functions.push_back(functions[0]);
2772     return_functions.push_back(functions[1]);
2773     return_functions.push_back(functions[2]);
2774    
2775     return return_functions;
2776     }
2777    
2778 buchmann 1.93 void do_prediction_plot(TCut addcut, string Cname, string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
2779 buchmann 1.1 {
2780 buchmann 1.65
2781 buchmann 1.1 bool is_data=false;
2782     bool use_signal=false;
2783     if(use_data==1) is_data=true;
2784     if(use_data==2) use_signal=true;
2785 buchmann 1.65 int nbins=int(high/10);//100;
2786     if(is_data) nbins=int(high/10);
2787 buchmann 1.1 float low=0;
2788 buchmann 1.65 float hi=high;
2789    
2790     stringstream cutpositiveS;
2791     cutpositiveS << "(" << jzb << ">0)";
2792     TCut cutpositive(cutpositiveS.str().c_str());
2793     stringstream cutnegativeS;
2794     cutnegativeS << "(" << jzb << "<0)";
2795     TCut cutnegative(cutnegativeS.str().c_str());
2796    
2797 buchmann 1.10
2798 buchmann 1.1 TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2799 buchmann 1.93 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2800     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2801     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2802     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2803 buchmann 1.10
2804 buchmann 1.1 blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2805     blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
2806     blankback->GetXaxis()->CenterTitle();
2807     blankback->GetYaxis()->CenterTitle();
2808    
2809     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2810     TH1F *RcorrJZBSBem;
2811     TH1F *LcorrJZBSBem;
2812     TH1F *RcorrJZBSBeemm;
2813     TH1F *LcorrJZBSBeemm;
2814    
2815     TH1F *RcorrJZBeemmNoS;
2816    
2817 buchmann 1.65 //these are for the ratio
2818 buchmann 1.93 TH1F *JRcorrJZBeemm = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2819     TH1F *JLcorrJZBeemm = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2820     TH1F *JRcorrJZBem = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2821     TH1F *JLcorrJZBem = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2822 buchmann 1.1
2823     TH1F *JRcorrJZBSBem;
2824     TH1F *JLcorrJZBSBem;
2825     TH1F *JRcorrJZBSBeemm;
2826     TH1F *JLcorrJZBSBeemm;
2827    
2828 buchmann 1.93 if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
2829 buchmann 1.1
2830    
2831 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2832 buchmann 1.93 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2833     LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2834     RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2835     LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2836 buchmann 1.10
2837 buchmann 1.1 //these are for the ratio
2838 buchmann 1.93 JRcorrJZBSBem = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2839     JLcorrJZBSBem = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2840     JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2841     JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2842 buchmann 1.1 }
2843    
2844     TH1F *lm4RcorrJZBeemm;
2845 buchmann 1.93 if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
2846 buchmann 1.1
2847     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2848    
2849     TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
2850     TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
2851    
2852     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2853     TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
2854 buchmann 1.23
2855 buchmann 1.26 TH1F *BpredSys = new TH1F("Bpredsys","Bpredsys",PlottingSetup::global_ratio_binning.size()-1,&PlottingSetup::global_ratio_binning[0]);
2856 buchmann 1.23 ClearHisto(BpredSys);
2857    
2858 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2859 buchmann 1.1 Bpred->Add(RcorrJZBem,1.0/3.);
2860     Bpred->Add(LcorrJZBem,-1.0/3.);
2861     Bpred->Add(RcorrJZBSBem,1.0/3.);
2862     Bpred->Add(LcorrJZBSBem,-1.0/3.);
2863     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2864     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2865    
2866     TTbarpred->Scale(1.0/3);
2867     Zjetspred->Add(LcorrJZBem,-1.0/3.);
2868     Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
2869     TTbarpred->Add(RcorrJZBSBem,1.0/3.);
2870     Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
2871     TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
2872    
2873     //these are for the ratio
2874     JBpred->Add(JRcorrJZBem,1.0/3.);
2875     JBpred->Add(JLcorrJZBem,-1.0/3.);
2876     JBpred->Add(JRcorrJZBSBem,1.0/3.);
2877     JBpred->Add(JLcorrJZBSBem,-1.0/3.);
2878     JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
2879     JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
2880 buchmann 1.23
2881     //Systematics:
2882 buchmann 1.26 AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertONPEAK*zjetsestimateuncertONPEAK);
2883     AddSquared(BpredSys,JRcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2884     AddSquared(BpredSys,JLcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2885     AddSquared(BpredSys,JRcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2886     AddSquared(BpredSys,JLcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2887     AddSquared(BpredSys,JRcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2888     AddSquared(BpredSys,JLcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2889 buchmann 1.1 } else {
2890     Bpred->Add(RcorrJZBem,1.0);
2891     Bpred->Add(LcorrJZBem,-1.0);
2892    
2893     Zjetspred->Add(LcorrJZBem,-1.0);
2894    
2895     //these are for the ratio
2896     JBpred->Add(JRcorrJZBem,1.0);
2897     JBpred->Add(JLcorrJZBem,-1.0);
2898 buchmann 1.23
2899     //Systematics
2900 buchmann 1.26 AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertOFFPEAK*zjetsestimateuncertOFFPEAK);
2901     AddSquared(BpredSys,JRcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2902     AddSquared(BpredSys,JLcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2903 buchmann 1.23
2904 buchmann 1.1 }
2905    
2906 buchmann 1.23 SQRT(BpredSys);
2907 buchmann 1.26 BpredSys->Divide(JBpred);
2908 buchmann 1.23
2909 buchmann 1.1 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2910     TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
2911     Tpred->Add(LcorrJZBem,-1.0);
2912 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2913 buchmann 1.1 Tpred->Add(RcorrJZBSBem,1.0);
2914     Tpred->Add(LcorrJZBSBem,-1.0);
2915     Tpred->Add(RcorrJZBSBeemm,1.0);
2916     Tpred->Add(LcorrJZBSBeemm,-1.0);
2917     }
2918    
2919     globalcanvas->cd();
2920     globalcanvas->SetLogy(1);
2921    
2922     RcorrJZBeemm->SetMarkerStyle(20);
2923     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
2924     RcorrJZBeemm->SetMinimum(0.1);
2925    
2926     Bpred->SetLineColor(kRed);
2927     Bpred->SetStats(0);
2928    
2929     int versok=false;
2930     if(gROOT->GetVersionInt()>=53000) versok=true;
2931    
2932    
2933     if ( overlay_signal || use_data==2 ) lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
2934     RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
2935    
2936     TLegend *legBpred = make_legend("",0.6,0.55);
2937     TLegend *legBpred2 = make_legend("",0.6,0.55);
2938    
2939    
2940     vector<TF1*> analytical_function;
2941     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2942     kinpad->cd();
2943     kinpad->SetLogy(1);
2944    
2945     string Bpredsaveas="Bpred_Data";
2946     blankback->SetMaximum(5*RcorrJZBeemm->GetMaximum());
2947     blankback->SetMinimum(0.1);
2948     if(use_data!=1) blankback->SetMinimum(0.1);
2949     blankback->Draw();
2950     if(use_data==1)
2951     {
2952 buchmann 1.14 //Bpred->SetLineWidth(3); //paper style.overruled.
2953     //lm4RcorrJZBeemm->SetLineWidth(3); //paper style.overruled.
2954 buchmann 1.1 analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
2955     kinpad->cd();//necessary because the extended fit function creates its own canvas
2956     RcorrJZBeemm->Draw("e1x0,same");
2957    
2958     Bpred->Draw("hist,same");
2959 buchmann 1.14 //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2960 buchmann 1.1 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2961 buchmann 1.66 //lm4RcorrJZBeemm->Draw("hist,same");
2962 buchmann 1.1 legBpred->AddEntry(RcorrJZBeemm,"observed","p");
2963     legBpred->AddEntry(Bpred,"predicted","l");
2964 buchmann 1.24 // legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2965     // legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2966 buchmann 1.66 // legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2967 buchmann 1.1 legBpred->Draw();
2968     DrawPrelim();
2969    
2970     //this plot shows what the prediction is composed of
2971 buchmann 1.10 TPad *predcomppad = new TPad("predcomppad","predcomppad",0,0,1,1);
2972     float CurrentBpredLineWidth=Bpred->GetLineWidth();
2973     Bpred->SetLineWidth(2);
2974     predcomppad->cd();
2975     predcomppad->SetLogy(1);
2976     TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
2977     TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
2978     sidebandsemu->Add(jzbnegative,-1);
2979    
2980     jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
2981     jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
2982     sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2983     sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2984    
2985 buchmann 1.1 THStack predcomposition("predcomposition","prediction composition");
2986 buchmann 1.10 predcomposition.Add(sidebandsemu);
2987     predcomposition.Add(jzbnegative);
2988 buchmann 1.1 blankback->Draw();
2989     RcorrJZBeemm->Draw("e1x0,same");
2990     predcomposition.Draw("histo,same");//
2991     Bpred->Draw("hist,same");
2992 buchmann 1.10 // analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2993 buchmann 1.1 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2994 buchmann 1.14 // lm4RcorrJZBeemm->SetLineColor(kOrange+1);
2995 buchmann 1.10 lm4RcorrJZBeemm->SetLineWidth(2);
2996 buchmann 1.14 //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
2997 buchmann 1.66 // lm4RcorrJZBeemm->Draw("histo,same");
2998 buchmann 1.1 DrawPrelim();
2999 buchmann 1.10 TLegend *speciallegBpred = make_legend("",0.45,0.55);
3000 buchmann 1.14 //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
3001 buchmann 1.10 speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
3002     speciallegBpred->AddEntry(Bpred,"Total background","l");
3003     speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
3004 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
3005 buchmann 1.30 else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
3006 buchmann 1.10 // speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3007 buchmann 1.66 // speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3008 buchmann 1.10 speciallegBpred->Draw();
3009 buchmann 1.79 Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3010     delete predcomppad;
3011 buchmann 1.10
3012     TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3013 buchmann 1.30 specialcanv->SetLogy(1);
3014     // THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
3015 buchmann 1.1 blankback->Draw();
3016 buchmann 1.30 // kostack.Draw("same");
3017 buchmann 1.73 predcomposition.Draw("hist");
3018 buchmann 1.1 Bpred->Draw("hist,same");
3019 buchmann 1.30 //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3020 buchmann 1.1 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3021     legBpred->Draw();
3022     DrawPrelim();
3023 buchmann 1.12 CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
3024 buchmann 1.10 Bpred->SetLineWidth((int)CurrentBpredLineWidth);
3025 buchmann 1.1
3026 buchmann 1.34
3027     //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;
3028    
3029 buchmann 1.10 delete speciallegBpred;
3030 buchmann 1.1 delete Zjetspred;
3031     delete TTbarpred;
3032    
3033     kinpad->cd();
3034     }
3035     if(use_data==0) {
3036     RcorrJZBeemm->Draw("e1x0,same");
3037 buchmann 1.14 //Bpred->SetLineWidth(3); // paper style. overruled.
3038 buchmann 1.1 Bpred->Draw("hist,same");
3039     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3040 buchmann 1.10 legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
3041 buchmann 1.18 legBpred->AddEntry(Bpred,"MC predicted","l");
3042 buchmann 1.1 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
3043     if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
3044 buchmann 1.66 // if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3045 buchmann 1.1 legBpred->Draw();
3046     DrawMCPrelim();
3047     Bpredsaveas="Bpred_MC";
3048     // CompleteSave(globalcanvas,"Bpred_MC"); // done below in save_with_ratio
3049     }
3050     if(use_data==2) {
3051     RcorrJZBeemm->Draw("e1x0,same");
3052 buchmann 1.14 //Bpred->SetLineWidth(3); // paper style. overruled.
3053 buchmann 1.1 Bpred->Draw("hist,same");
3054     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3055 buchmann 1.10 legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
3056 buchmann 1.1 legBpred->AddEntry(Bpred,"MC predicted","l");
3057 buchmann 1.10 legBpred2->AddEntry(RcorrJZBeemm,"MC true","p");
3058 buchmann 1.1 legBpred2->AddEntry(Bpred,"MC predicted","l");
3059     {
3060     if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
3061     if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
3062     legBpred->Draw();
3063     DrawMCPrelim();
3064     Bpredsaveas="Bpred_MCwithS";
3065     // CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
3066     }
3067     {
3068 buchmann 1.14 //lm4RcorrJZBeemm->SetLineWidth(3); //paper style. overruled.
3069     //RcorrJZBeemmNoS->SetLineWidth(3); //paper style. overruled.
3070     //lm4RcorrJZBeemm->SetLineStyle(2); //paper style. overruled.
3071     //RcorrJZBeemmNoS->SetLineStyle(3); //paper style. overruled.
3072     //lm4RcorrJZBeemm->SetLineColor(kOrange+1); //paper style. overruled.
3073    
3074 buchmann 1.1 RcorrJZBeemmNoS->SetLineStyle(2);
3075     legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3076 buchmann 1.66 // legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3077 buchmann 1.1 legBpred2->Draw();
3078     RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3079     RcorrJZBeemmNoS->Draw("histo,same");
3080     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3081     lm4RcorrJZBeemm->Draw("histo,same");
3082     DrawMCPrelim();
3083     Bpredsaveas="Bpred_MCwithS__plus";
3084     // CompleteSave(globalcanvas,"Bpred_MCwithS__plus"); // done below in save_with_ratio
3085     }
3086     }
3087    
3088    
3089 buchmann 1.93 Bpredsaveas+="_"+Cname+"_";
3090 buchmann 1.1 //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3091     string ytitle("ratio");
3092     if ( use_data==1 ) ytitle = "data/pred";
3093 buchmann 1.8 //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3094 buchmann 1.79 Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3095    
3096     delete kinpad;
3097 buchmann 1.1
3098 buchmann 1.65
3099 buchmann 1.1
3100     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3101 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!)
3102 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3103 buchmann 1.11 TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
3104     Bpredem->Add(RcorrJZBem);
3105     Bpredem->Add(LcorrJZBem,-1);
3106     TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
3107     BpredSBem->Add(RcorrJZBSBem);
3108     Bpred->Add(LcorrJZBSBem,-1);
3109     TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");
3110     BpredSBeemm->Add(RcorrJZBSBeemm);
3111     BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
3112     globalcanvas->cd();
3113     globalcanvas->SetLogy(1);
3114    
3115     RcorrJZBeemm->SetMarkerStyle(20);
3116     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
3117     blankback->Draw();
3118     RcorrJZBeemm->Draw("e1x0,same");
3119     RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
3120    
3121     Bpredem->SetLineColor(kRed+1);
3122     Bpredem->SetStats(0);
3123     Bpredem->Draw("hist,same");
3124    
3125     BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
3126     BpredSBem->SetLineStyle(2);
3127     BpredSBem->Draw("hist,same");
3128    
3129     BpredSBeemm->SetLineColor(kBlue+1);
3130     BpredSBeemm->SetLineStyle(3);
3131     BpredSBeemm->Draw("hist,same");
3132     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3133    
3134     TLegend *legBpredc = make_legend("",0.6,0.55);
3135     if(use_data==1)
3136     {
3137     legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3138     legBpredc->AddEntry(Bpredem,"OFZP","l");
3139     legBpredc->AddEntry(BpredSBem,"OFSB","l");
3140     legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3141     legBpredc->Draw();
3142 buchmann 1.12 CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3143 buchmann 1.11 }
3144     if(use_data==0) {
3145     legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3146     legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3147     legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3148     legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3149     legBpredc->Draw();
3150 buchmann 1.12 CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3151 buchmann 1.11 }
3152     if(use_data==2) {
3153     legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3154     legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3155     legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3156     legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3157 buchmann 1.66 // if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3158 buchmann 1.11 legBpredc->Draw();
3159 buchmann 1.12 CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3160 buchmann 1.11 }
3161     }
3162 buchmann 1.1
3163 buchmann 1.31 TFile *f = new TFile("tester.root","RECREATE");
3164     RcorrJZBeemm->Write();
3165     Bpred->Write();
3166     f->Close();
3167    
3168 buchmann 1.1 delete RcorrJZBeemm;
3169     delete LcorrJZBeemm;
3170     delete RcorrJZBem;
3171     delete LcorrJZBem;
3172    
3173     delete JRcorrJZBeemm;
3174     delete JLcorrJZBeemm;
3175     delete JRcorrJZBem;
3176     delete JLcorrJZBem;
3177    
3178     delete blankback;
3179    
3180 buchmann 1.30 delete BpredSys;
3181 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3182 buchmann 1.1 delete RcorrJZBSBem;
3183     delete LcorrJZBSBem;
3184     delete RcorrJZBSBeemm;
3185     delete LcorrJZBSBeemm;
3186    
3187     delete JRcorrJZBSBem;
3188     delete JLcorrJZBSBem;
3189     delete JRcorrJZBSBeemm;
3190     delete JLcorrJZBSBeemm;
3191     }
3192     if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
3193     }
3194    
3195     void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3196 buchmann 1.65 switch_overunderflow(true);
3197 buchmann 1.93
3198     TCut cuts[3] = {TCut("mll>0"),Restrmasscut,TCut("mll>20&&mll<70")};
3199     string cutnames[3] = {"NoMassCut","ZWindow","LowMassRegion2070"};
3200    
3201 buchmann 1.1 TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3202 buchmann 1.93 for(int i=0;i<3;i++) {
3203     do_prediction_plot(cuts[i],cutnames[i],datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3204     if ( !PlottingSetup::Approved ) {
3205     do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3206     do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3207     } else {
3208     write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3209     }
3210 buchmann 1.15 }
3211 buchmann 1.93
3212 buchmann 1.65 delete globalcanvas;
3213     switch_overunderflow(false);
3214 buchmann 1.1 }
3215    
3216     string give_jzb_expression(float peak, int type) {
3217     stringstream val;
3218     if(type==data) {
3219     if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
3220     if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
3221     if(peak==0) val << jzbvariabledata;
3222     }
3223     if(type==mc) {
3224     if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
3225     if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
3226     if(peak==0) val << jzbvariablemc;
3227     }
3228     return val.str();
3229     }
3230    
3231    
3232     void lepton_comparison_plots() {
3233     Float_t ymin = 1.e-5, ymax = 0.25;
3234     TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3235     can->SetLogy(1);
3236 buchmann 1.92 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3237     TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3238 buchmann 1.1 eemc->SetLineColor(kBlue);
3239     mmmc->SetLineColor(kRed);
3240     eemc->SetMinimum(0.1);
3241     eemc->SetMaximum(10*eemc->GetMaximum());
3242     eemc->Draw("histo");
3243     mmmc->Draw("histo,same");
3244     TLegend *leg = make_legend();
3245     leg->AddEntry(eemc,"ZJets->ee (MC)","l");
3246     leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
3247     leg->Draw("same");
3248     CompleteSave(can, "lepton_comparison/mll_effratio_mc");
3249    
3250     TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
3251     TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
3252     eed->SetLineColor(kBlue);
3253     mmd->SetLineColor(kRed);
3254     eed->SetMinimum(0.1);
3255     eed->SetMaximum(10*eed->GetMaximum());
3256     eed->Draw("histo");
3257     mmd->Draw("histo,same");
3258     TLegend *leg2 = make_legend();
3259     leg2->AddEntry(eed,"ZJets->ee (data)","l");
3260     leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
3261     leg2->Draw();
3262     CompleteSave(can, "lepton_comparison/mll_effratio_data");
3263    
3264     TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
3265     TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
3266     TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
3267     dout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
3268     dout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
3269     dout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
3270     jeemmd->SetLineColor(kBlack);
3271     jeemmd->SetMarkerStyle(25);
3272     jeed->SetLineColor(kBlue);
3273     jmmd->SetLineColor(kRed);
3274     jeed->SetMinimum(0.1);
3275     jeed->SetMaximum(10*eed->GetMaximum());
3276     TH1* njeemmd = jeemmd->DrawNormalized();
3277     njeemmd->SetMinimum(ymin);
3278     njeemmd->SetMaximum(ymax);
3279    
3280     jeed->DrawNormalized("histo,same");
3281     jmmd->DrawNormalized("histo,same");
3282     jeemmd->DrawNormalized("same");
3283     TLegend *jleg2 = make_legend(" ");
3284     jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
3285     jleg2->AddEntry(jeed,"ee","l");
3286     jleg2->AddEntry(jmmd,"#mu#mu","l");
3287     jleg2->Draw();
3288     CompleteSave(can,"lepton_comparison/jzb_effratio_data");
3289    
3290     TPad *eemmpad = new TPad("eemmpad","eemmpad",0,0,1,1);
3291     eemmpad->cd();
3292     eemmpad->SetLogy(1);
3293     jeed->Draw("histo");
3294     jmmd->Draw("histo,same");
3295     TLegend *eemmlegend = make_legend(" ");
3296     eemmlegend->AddEntry(jeed,"ee","l");
3297     eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3298     eemmlegend->Draw();
3299     DrawPrelim();
3300 buchmann 1.79 Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3301 buchmann 1.1
3302 buchmann 1.92 TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3303     TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3304     TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets, mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3305 buchmann 1.1 dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3306     dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3307     dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
3308     zjeemmd->SetLineColor(kBlack);
3309     zjeemmd->SetMarkerStyle(25);
3310     zjeed->SetLineColor(kBlue);
3311     zjmmd->SetLineColor(kRed);
3312     zjeed->SetMinimum(0.1);
3313     zjeed->SetMaximum(10*eed->GetMaximum());
3314    
3315     TH1* nzjeemmd = zjeemmd->DrawNormalized();
3316     nzjeemmd->SetMinimum(ymin);
3317     nzjeemmd->SetMaximum(ymax);
3318     zjeed->DrawNormalized("histo,same");
3319     zjmmd->DrawNormalized("histo,same");
3320     zjeemmd->DrawNormalized("same");
3321     TLegend *zjleg2 = make_legend("Z+jets MC");
3322     zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
3323     zjleg2->AddEntry(jeed,"ee","l");
3324     zjleg2->AddEntry(jmmd,"#mu#mu","l");
3325     zjleg2->Draw();
3326     CompleteSave(can,"lepton_comparison/jzb_effratio_ZJets");
3327    
3328     TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
3329     ld->DrawNormalized("e1");
3330     eed->DrawNormalized("histo,same");
3331     mmd->DrawNormalized("histo,same");
3332     TLegend *leg3 = make_legend();
3333     leg3->AddEntry(ld,"ZJets->ll (data)","p");
3334     leg3->AddEntry(eed,"ZJets->ee (data)","l");
3335     leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
3336     leg3->Draw();
3337     CompleteSave(can,"lepton_comparison/mll_effratio_data__all_compared");
3338     /*
3339     TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
3340     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
3341     */
3342     TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
3343     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
3344     jzbld->SetMarkerColor(kBlack);
3345     jzbld->SetMarkerStyle(26);
3346     jzbemd->SetMarkerStyle(25);
3347     jzbemd->SetMarkerColor(kRed);
3348     jzbemd->SetLineColor(kRed);
3349     jzbld->SetMinimum(0.35);
3350     jzbld->Draw("e1");
3351     jzbemd->Draw("e1,same");
3352     TLegend *leg4 = make_legend();
3353     leg4->AddEntry(jzbld,"SFZP","p");
3354     leg4->AddEntry(jzbemd,"OFZP","p");
3355     leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
3356     leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
3357     leg4->Draw();
3358     CompleteSave(can,"lepton_comparison/jzb_eemumu_emu_data");
3359    
3360     TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
3361     TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
3362     ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
3363     ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
3364     ttbarjzbld->Draw("histo");
3365     ttbarjzbemd->SetLineStyle(2);
3366     ttbarjzbemd->Draw("histo,same");
3367     TLegend *leg5 = make_legend();
3368     leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
3369     leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
3370     leg5->Draw();
3371     CompleteSave(can,"lepton_comparison/ttbar_emu_mc");
3372    
3373     }
3374    
3375     bool is_OF(TCut cut) {
3376     string scut = (const char*) cut;
3377     if((int)scut.find("id1!=id2")>-1) return true;
3378     if((int)scut.find("id1==id2")>-1) return false;
3379     return false;
3380     }
3381    
3382     bool is_ZP(TCut cut) {
3383     string scut = (const char*) cut;
3384     if((int)scut.find("91")>-1) return true;
3385     return false;
3386     }
3387    
3388    
3389     void draw_pure_jzb_histo(TCut cut,string datavariable, string mcvariable, string savename, TCanvas *can,vector<float> binning) {
3390     TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
3391     jzbpad->cd();
3392     jzbpad->SetLogy(1);
3393     string xlabel="JZB [GeV]";
3394    
3395     TH1F *datahisto = allsamples.Draw("datahisto",datavariable,binning, xlabel, "events",cut,data,luminosity);
3396     THStack mcstack = allsamples.DrawStack("mcstack",mcvariable,binning, xlabel, "events",cut,mc,luminosity);
3397    
3398     datahisto->SetMinimum(0.1);
3399     datahisto->SetMarkerSize(DataMarkerSize);
3400     datahisto->Draw("e1");
3401 buchmann 1.73 mcstack.Draw("histo,same");
3402 buchmann 1.1 datahisto->Draw("same,e1");
3403    
3404     TLegend *leg;
3405 buchmann 1.50 if (!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
3406 fronga 1.41 if(is_OF(cut)) leg = allsamples.allbglegend("Opposite flavor",datahisto);
3407     else leg = allsamples.allbglegend("Same flavor",datahisto);
3408     } else {
3409     if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
3410     else if(!is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
3411     else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
3412     else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
3413     else {
3414     std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
3415     exit(-1);
3416     }
3417     }
3418 buchmann 1.1 leg->Draw();
3419     string write_cut = decipher_cut(cut,"");
3420     TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3421     writeline1->SetTextSize(0.035);
3422     writeline1->Draw();
3423 buchmann 1.79 if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3424     else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3425 buchmann 1.1 TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3426     jzbpad2->cd();
3427     jzbpad2->SetLogy(1);
3428     datahisto->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
3429     datahisto->SetMinimum(0.1);
3430     datahisto->SetMarkerSize(DataMarkerSize);
3431     datahisto->Draw("e1");
3432 buchmann 1.73 mcstack.Draw("histo,same");
3433 buchmann 1.1 datahisto->Draw("same,e1");
3434     leg->SetHeader("");
3435     leg->Draw();
3436     writeline1->SetTextSize(0.035);
3437     writeline1->Draw();
3438     DrawPrelim();
3439 buchmann 1.79 if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3440     else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3441 buchmann 1.1 datahisto->Delete();
3442     mcstack.Delete();
3443     }
3444    
3445     Double_t GausR(Double_t *x, Double_t *par) {
3446     return gRandom->Gaus(x[0],par[0]);
3447     }
3448 buchmann 1.12
3449     void produce_stretched_jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3450     TCanvas *dican = new TCanvas("dican","JZB Plots Canvas");
3451     float max=jzbHigh ;
3452     float min=-120;
3453     int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
3454     int coarserbins=int(nbins/2.0);
3455     int rebinnedbins=int(nbins/4.0);
3456 buchmann 1.1
3457 buchmann 1.12 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
3458     for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
3459     for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
3460     for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
3461    
3462     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP",dican,binning);
3463     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP",dican,binning);
3464     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_SFZP",dican,binning);
3465     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
3466     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
3467     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
3468 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
3469     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
3470 buchmann 1.12
3471     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
3472     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
3473 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);
3474     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
3475 buchmann 1.12
3476     delete dican;
3477     }
3478    
3479    
3480     void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3481 buchmann 1.65 switch_overunderflow(true);
3482 buchmann 1.12 vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3483    
3484     if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
3485     write_error(__FUNCTION__,"Could not find any diboson samples - aborting diboson plots");
3486     return;
3487     }
3488    
3489     float stretchfactor = 100.0;
3490     vector<string> labels;
3491    
3492    
3493     dout << "Going to increase the cross section for diboson samples ... " << endl;
3494 buchmann 1.16 for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3495 buchmann 1.12 float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3496     (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
3497     dout << " Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
3498     labels.push_back((allsamples.collection)[SamplesToBeModified[i]].samplename);
3499     (allsamples.collection)[SamplesToBeModified[i]].samplename=any2string(int(stretchfactor))+" x "+(allsamples.collection)[SamplesToBeModified[i]].samplename;
3500     dout << " (also renamed it to " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " )" << endl;
3501     }
3502    
3503     dout << "Going to produce JZB plots" << endl;
3504 buchmann 1.13 produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
3505 buchmann 1.12 TCanvas *gloca = new TCanvas("gloca","gloca");
3506    
3507     dout << "Going to produce prediction plots" << endl;
3508 buchmann 1.93 do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3509     do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3510 buchmann 1.12 delete gloca;
3511    
3512     dout << "Going to reset the cross section for diboson samples ... " << endl;
3513 buchmann 1.16 for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3514 buchmann 1.12 float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3515     (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
3516     string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
3517     (allsamples.collection)[SamplesToBeModified[i]].samplename=labels[i];
3518     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;
3519    
3520     }
3521 buchmann 1.65 // switch_overunderflow(false);
3522 buchmann 1.12 }
3523 buchmann 1.35
3524    
3525     void draw_normalized_data_vs_data_histo(TCut cut1, TCut cut2, string variable, string legentry1, string legentry2, string savename, TCanvas *can,vector<float> binning) {
3526     TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
3527     jzbpad->cd();
3528     jzbpad->SetLogy(1);
3529     string xlabel="JZB [GeV]";
3530    
3531     TH1F *datahisto1 = allsamples.Draw("datahisto1",variable,binning, xlabel, "events",cut1,data,luminosity);
3532     datahisto1->SetLineColor(kRed);
3533     datahisto1->SetMarkerColor(kRed);
3534     TH1F *datahisto2 = allsamples.Draw("datahisto2",variable,binning, xlabel, "events",cut2,data,luminosity);
3535     datahisto2->SetLineColor(kBlue);
3536     datahisto2->SetMarkerColor(kBlue);
3537    
3538     datahisto2->SetMarkerSize(DataMarkerSize);
3539     datahisto1->DrawNormalized("e1");
3540     datahisto2->DrawNormalized("histo,same");
3541     datahisto1->DrawNormalized("same,e1");
3542    
3543     TLegend *leg = make_legend();
3544     leg->AddEntry(datahisto1,legentry1.c_str());
3545     leg->AddEntry(datahisto2,legentry2.c_str());
3546     leg->Draw();
3547    
3548 buchmann 1.79 Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3549 buchmann 1.35
3550     datahisto1->Delete();
3551     datahisto2->Delete();
3552     }
3553    
3554    
3555 buchmann 1.1 void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3556 buchmann 1.65 switch_overunderflow(true);
3557 buchmann 1.1 TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3558     float max=jzbHigh ;
3559     float min=-120;
3560     int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
3561     int coarserbins=int(nbins/2.0);
3562     int rebinnedbins=int(nbins/4.0);
3563    
3564     vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
3565     for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
3566     for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
3567     for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
3568    
3569 buchmann 1.14 if ( !PlottingSetup::Approved ) {
3570     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
3571     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
3572     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
3573     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
3574     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
3575     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
3576     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3577 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
3578     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
3579 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);
3580     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);
3581 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);
3582 buchmann 1.35
3583 buchmann 1.14 }
3584 buchmann 1.1
3585     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
3586 buchmann 1.14 if ( !PlottingSetup::Approved ) {
3587     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
3588     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3589 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
3590     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3591 buchmann 1.14 }
3592 buchmann 1.12 delete can;
3593 buchmann 1.65 switch_overunderflow(false);
3594 buchmann 1.1 }
3595    
3596    
3597     void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
3598     dout << "Calculating background yields in MC:" << endl;
3599     jzb_cuts.push_back(14000);
3600     TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
3601     float cumulative=0;
3602     for(int i=allbgs->GetNbinsX();i>=1;i--) {
3603     cumulative+=allbgs->GetBinContent(i);
3604     dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
3605     }
3606     }
3607    
3608    
3609     TCut give_jzb_expression(string mcjzb, float jzbcut, string posneg="pos") {
3610     stringstream res;
3611     res << "(" << mcjzb;
3612     if(posneg=="pos") res << ">";
3613     else res << "<-";
3614     res << jzbcut << ")";
3615     return TCut(res.str().c_str());
3616     }
3617    
3618     string sigdig(float number, int nsigdig=3, float min=0) {
3619     //this function tries to extract n significant digits, and if the number is below (min), it returns "<min"
3620     if(number<min) return "< "+any2string(min);
3621     stringstream sol;
3622     sol << setprecision(nsigdig) << number;
3623    
3624     return sol.str();
3625     }
3626    
3627     string jzb_tex_command(string region, string posneg) {
3628     if(posneg=="pos") posneg="POS";
3629     else posneg="NEG";
3630     stringstream texcommand;
3631     texcommand<<"\\"<<region <<"JZB"<<posneg;
3632     return texcommand.str();
3633     }
3634     // \SFZPJZBPOS
3635     // Sample & \OFZPJZBPOS & \OFZPJZBNEG & \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS & \OFSBJZBNEG & \SFSBJZBPOS & \SFSBJZBNEG \\\hline
3636    
3637     void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
3638     dout << "Calculating background yields in MC:" << endl;
3639    
3640     TCanvas *yica = new TCanvas("yica","yield canvas");
3641    
3642     int nRegions=4;
3643 buchmann 1.50 if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
3644 buchmann 1.1 string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
3645     string posneg[] = {"pos","neg"};
3646     TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
3647    
3648 buchmann 1.16 for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
3649 buchmann 1.1 TCut jzbMC[] = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
3650     dout << "_________________________________________________________" << endl;
3651     dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
3652 buchmann 1.16 for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
3653 buchmann 1.1 if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << " & ";
3654     else dout << "Sample & ";
3655     for(int iregion=0;iregion<nRegions;iregion++) {
3656     for(int ipos=0;ipos<2;ipos++) {
3657     if((allsamples.collection)[isample].is_data) dout << jzb_tex_command(tsRegions[iregion],posneg[ipos]) << " & ";
3658     else {
3659     vector<int> specific;specific.push_back(isample);
3660     TH1F *shisto = allsamples.Draw("shisto","mll",1,0,500,"tester","events",tkRegions[iregion]&&jzbMC[ipos],mc,luminosity,specific);
3661     dout << sigdig(shisto->Integral(),3,0.05) <<" & ";
3662     delete shisto;
3663     }
3664     }//end of ipos
3665     }//end of iregion
3666     dout << " \\\\" << endl;
3667     }//end of isample
3668     }//end of ijzb
3669     dout << " \\hline" << endl;
3670    
3671     delete yica;
3672     }
3673    
3674     void draw_ttbar_and_zjets_shape_for_one_configuration(string mcjzb, string datajzb, int leptontype=-1, int scenario=0,bool floating=false) {
3675     //Step 1: Establishing cuts
3676     stringstream jetcutstring;
3677     string writescenario="";
3678    
3679     if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
3680     if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
3681     TCut jetcut(jetcutstring.str().c_str());
3682     string leptoncut="mll>0";
3683     if(leptontype==0||leptontype==1) {
3684     if(leptontype==0) {
3685     leptoncut="id1==0";
3686     writescenario="__ee";
3687     }
3688     else {
3689     leptoncut="id1==1";
3690     writescenario="__ee";
3691     }
3692     }
3693     TCut lepcut(leptoncut.c_str());
3694    
3695     TCanvas *c5 = new TCanvas("c5","c5",1500,500);
3696     TCanvas *c6 = new TCanvas("c6","c6");
3697     c5->Divide(3,1);
3698    
3699     //STEP 2: Extract Zjets shape in data
3700     c5->cd(1);
3701     c5->cd(1)->SetLogy(1);
3702     TCut massat40("mll>40");
3703     TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
3704     TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
3705     ossfleft->SetLineColor(kRed);
3706     ossfleft->SetMarkerColor(kRed);
3707     ossfleft->Add(osofleft,-1);
3708     vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
3709     ossfleft->SetMarkerSize(DataMarkerSize);
3710     ossfleft->Draw();
3711     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
3712     TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
3713     TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
3714     TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
3715     zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
3716     TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
3717     leg1->SetFillColor(kWhite);
3718     leg1->SetLineColor(kWhite);
3719     leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
3720     leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
3721     leg1->Draw("same");
3722     TText *titleleft = write_title("Extracting Z+Jets shape");
3723     titleleft->Draw();
3724    
3725     //Step 3: Extract ttbar shape (in data or MC?)
3726     c5->cd(2);
3727     c5->cd(2)->SetLogy(1);
3728     TH1F *osof;
3729     TText *titlecenter;
3730     bool frommc=false;
3731     if(frommc) {
3732 buchmann 1.93 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TT_"));
3733 buchmann 1.1 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
3734     }
3735     else {
3736     osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
3737     titlecenter = write_title("Extracting ttbar shape (from osof data)");
3738     }
3739     osof->SetMarkerSize(DataMarkerSize);
3740     osof->Draw();
3741     vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
3742     ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
3743     ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
3744     ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
3745    
3746     TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
3747     leg2->SetFillColor(kWhite);
3748     leg2->SetLineColor(kWhite);
3749     if(frommc) {
3750     leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
3751     leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
3752     } else {
3753     leg2->AddEntry(osof,"OSOF","p");
3754     leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
3755     }
3756     leg2->Draw("same");
3757     titlecenter->Draw();
3758    
3759     //--------------------------------------------------------------------------------------------------------------------------------
3760     //STEP 4: Present it!
3761     // actually: if we wanna let it float we need to do that first :-)
3762     c5->cd(3);
3763     c5->cd(3)->SetLogy(1);
3764     TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
3765     observed->SetMarkerSize(DataMarkerSize);
3766    
3767     TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
3768     TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
3769     TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
3770    
3771     TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
3772     TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
3773     TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
3774    
3775     TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
3776     TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
3777     TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
3778    
3779     zjetsc->SetParameters(zjetsfunc->GetParameters());
3780     zjetscp->SetParameters(zjetsfunc->GetParameters());
3781     zjetscn->SetParameters(zjetsfunc->GetParameters());
3782    
3783     TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
3784     //blublu
3785     logparc->SetParameters(ttbarfunctions[1]->GetParameters());
3786     logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
3787     logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
3788     if(floating) {
3789     dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
3790     logparc->SetParameters(ttbarfunctions[1]->GetParameters());
3791     for(int i=0;i<10;i++) {
3792     if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
3793     if(i>=5) {
3794     if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
3795     if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
3796     }
3797     }//end of setting parameters
3798     observeda->Draw("same");
3799     ZplusJetsplusTTbar->Draw("same");
3800     observeda->Fit(ZplusJetsplusTTbar);
3801     dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
3802     ZplusJetsplusTTbar->Draw("same");
3803     ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
3804     ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
3805     dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
3806     float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
3807     dout << "FACTOR: " << factor << endl;
3808     logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
3809     logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
3810     logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
3811     }
3812    
3813     c5->cd(3);
3814     c5->cd(3)->SetLogy(1);
3815     observed->Draw();
3816     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
3817     logparc->Draw("same");
3818     logparcn->Draw("same");
3819     logparcp->Draw("same");
3820    
3821     TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
3822     leg3->SetFillColor(kWhite);
3823     leg3->SetLineColor(kWhite);
3824     leg3->AddEntry(observed,"OSSF,JZB>peak","p");
3825     leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
3826     leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
3827     leg3->Draw("same");
3828     TText *titleright = write_title("Summary of shapes and observed shape");
3829     titleright->Draw();
3830    
3831     c6->cd()->SetLogy(1);
3832     observed->Draw();
3833     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
3834     logparc->Draw("same");
3835     logparcn->Draw("same");
3836     logparcp->Draw("same");
3837     leg3->Draw("same");
3838     titleright->Draw();
3839    
3840     if(scenario==0) {
3841     CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
3842     CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
3843     CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
3844     CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
3845     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
3846     } else {
3847     CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
3848     CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
3849     CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
3850     CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
3851     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
3852     }
3853     dout << "Statistics about our fits: " << endl;
3854     dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
3855     dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
3856    
3857     c6->cd();
3858     TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
3859     additionallegend->SetFillColor(kWhite);
3860     additionallegend->SetLineColor(kWhite);
3861     additionallegend->AddEntry(observed,"Data","p");
3862     additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
3863     additionallegend->AddEntry(zjetsc,"Z+jets","l");
3864     additionallegend->AddEntry(logparc,"TTbar","l");
3865     observed->Draw();
3866     ZplusJetsplusTTbar->SetLineColor(kGreen);
3867     ZplusJetsplusTTbarP->SetLineColor(kGreen);
3868     ZplusJetsplusTTbarN->SetLineColor(kGreen);
3869     ZplusJetsplusTTbarP->SetLineStyle(2);
3870     ZplusJetsplusTTbarN->SetLineStyle(2);
3871     TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
3872     ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
3873     ZplusJetsplusTTbar2->SetLineColor(kGreen);
3874     ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
3875     ZplusJetsplusTTbarN->SetFillColor(kWhite);
3876     ZplusJetsplusTTbarP->Draw("fcsame");
3877     ZplusJetsplusTTbarN->Draw("fcsame");
3878     TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
3879     TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
3880     TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
3881     hZplusJetsplusTTbar->SetMarkerSize(0);
3882     hZplusJetsplusTTbarP->SetMarkerSize(0);
3883     hZplusJetsplusTTbarN->SetMarkerSize(0);
3884     for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
3885     float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
3886     hZplusJetsplusTTbar->SetBinError(i,newerror);
3887     if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
3888     }
3889     hZplusJetsplusTTbarP->SetFillColor(kGreen);
3890     hZplusJetsplusTTbarN->SetFillColor(kWhite);
3891     hZplusJetsplusTTbarN->Draw("same");
3892    
3893     ZplusJetsplusTTbar2->SetMarkerSize(0);
3894     ZplusJetsplusTTbar2->Draw("same");
3895    
3896     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
3897     logparc->Draw("same");
3898     logparcn->Draw("same");
3899     logparcp->Draw("same");
3900     additionallegend->Draw("same");
3901     if(scenario==0) {
3902     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
3903     } else {
3904     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
3905     }
3906     //--------------------------------------------------------------------------------------------------------------------------------
3907     }
3908    
3909     void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
3910     int all_leptons=-1;
3911 buchmann 1.16 int threejetswith30gev=0;
3912     /*
3913     int twojetswith50gev=1;
3914 buchmann 1.1 int electrons_only=0;
3915     int mu_only=1;
3916 buchmann 1.16
3917 buchmann 1.1 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
3918     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
3919    
3920     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
3921     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
3922    
3923     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
3924     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
3925     */
3926    
3927     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
3928     }
3929    
3930 buchmann 1.32 float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
3931 buchmann 1.1 TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
3932     cancorr->SetLogz();
3933     cancorr->SetRightMargin(0.13);
3934 buchmann 1.45 TCut zptforresponsepresentation(Restrmasscut&&SpecialCut&&passtrig);
3935 fronga 1.40
3936     if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
3937     TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
3938     niceresponseplotd->Sumw2();
3939     TH2F* emuResponse = (TH2F*)niceresponseplotd->Clone("emuResponse");
3940 buchmann 1.27 vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
3941 buchmann 1.33 for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
3942 buchmann 1.32 if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
3943     if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
3944    
3945 buchmann 1.30 dout << " Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
3946 fronga 1.40 (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
3947     (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
3948 buchmann 1.27 }
3949 fronga 1.40 niceresponseplotd->Add(emuResponse,-1);
3950    
3951 buchmann 1.1 niceresponseplotd->SetStats(0);
3952     niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
3953     niceresponseplotd->GetYaxis()->SetTitle("Response");
3954     niceresponseplotd->GetXaxis()->CenterTitle();
3955     niceresponseplotd->GetYaxis()->CenterTitle();
3956     niceresponseplotd->Draw("COLZ");
3957     TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
3958 fronga 1.40 profd->Rebin(2);
3959 buchmann 1.1 profd->SetMarkerSize(DataMarkerSize);
3960 fronga 1.40 profd->Fit("pol0","","same,e1",100,400);
3961 buchmann 1.1 DrawPrelim();
3962 buchmann 1.27 string stitle="Data";
3963     if(!Contains(FindKeyword,"Data")) stitle="MC";
3964     TText* title = write_text(0.5,0.7,stitle.c_str());
3965 buchmann 1.1 title->SetTextAlign(12);
3966     title->Draw();
3967     TF1 *datapol=(TF1*)profd->GetFunction("pol0");
3968 buchmann 1.27 float correction=datapol->GetParameter(0);
3969     stringstream resstring;
3970     resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
3971     TText* restitle = write_text(0.5,0.65,resstring.str());
3972 buchmann 1.1 restitle->SetTextAlign(12);
3973     restitle->SetTextSize(0.03);
3974     restitle->Draw();
3975 buchmann 1.27 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
3976     delete cancorr;
3977     delete niceresponseplotd;
3978 fronga 1.40 delete profd;
3979 buchmann 1.27 return correction;
3980     }
3981    
3982     void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
3983    
3984 buchmann 1.30 dout << "Computing response corrections: " << endl;
3985 buchmann 1.27 //Step 1 : Get results
3986 buchmann 1.32 float datacorrection=find_one_correction_factor("Data",true,"","Data");
3987     float mccorrection=find_one_correction_factor("DY",false,"","MC");
3988 buchmann 1.1
3989 buchmann 1.93 /* float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
3990 buchmann 1.32 float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
3991 buchmann 1.27
3992 buchmann 1.32 float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
3993     float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
3994 buchmann 1.93 */
3995 buchmann 1.27 cout << "Corrections : " << endl;
3996     cout << " Data : " << datacorrection << endl;
3997 buchmann 1.93 // cout << " ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
3998 buchmann 1.27 cout << " MC : " << mccorrection << endl;
3999 buchmann 1.93 // cout << " ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4000 buchmann 1.27
4001     //Step 2: Processing the result and making it into something useful :-)
4002 buchmann 1.1 stringstream jzbvardatas;
4003 buchmann 1.27 jzbvardatas << "(";
4004    
4005 buchmann 1.93 /*
4006 buchmann 1.27 if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
4007     if(dataEEcorrection<1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
4008    
4009     if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
4010     if(dataMMcorrection<1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
4011    
4012     float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
4013    
4014 buchmann 1.30 if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
4015     if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
4016 buchmann 1.27
4017     jzbvardatas << ")";
4018 buchmann 1.1 jzbvardata=jzbvardatas.str();
4019 buchmann 1.93 */
4020 buchmann 1.1 stringstream jzbvarmcs;
4021 buchmann 1.27 jzbvarmcs << "(";
4022 buchmann 1.93 /*
4023 buchmann 1.27 if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4024     if(mcEEcorrection<1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4025    
4026     if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
4027     if(mcMMcorrection<1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
4028    
4029     float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
4030    
4031 buchmann 1.30 if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
4032     if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
4033 buchmann 1.27
4034     jzbvarmcs << ")";
4035 buchmann 1.1 jzbvarmc=jzbvarmcs.str();
4036 buchmann 1.93 */
4037    
4038     if(datacorrection>=1) jzbvardatas<<"(jzb[1]-" << datacorrection-1 << "*pt)";
4039     if(datacorrection<1) jzbvardatas<<"(jzb[1]+" << 1-datacorrection << "*pt)";
4040    
4041     if(mccorrection>=1) jzbvarmcs<<"(jzb[1]-" << mccorrection-1 << "*pt)";
4042     if(mccorrection<1) jzbvarmcs<<"(jzb[1]+" << 1-mccorrection << "*pt)";
4043    
4044     jzbvardata = jzbvardatas.str();
4045     jzbvarmc = jzbvarmcs.str();
4046    
4047 buchmann 1.1 dout << "JZB Z pt correction summary : " << endl;
4048     dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
4049     dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
4050 buchmann 1.27
4051 buchmann 1.1 }
4052    
4053 buchmann 1.88 void pick_up_events(string cut, string filename, bool QuietMode=false) {
4054     allsamples.PickUpEvents(cut,filename,QuietMode);
4055 buchmann 1.1 }
4056    
4057 buchmann 1.18 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
4058 buchmann 1.1 dout << "Saving configuration template!" << endl;
4059     ofstream configfile;
4060     configfile.open("../DistributedModelCalculations/last_configuration.C");
4061     configfile<<"#include <iostream>\n";
4062     configfile<<"#include <vector>\n";
4063     configfile<<"#ifndef SampleClassLoaded\n";
4064     configfile<<"#include \"SampleClass.C\"\n";
4065     configfile<<"#endif\n";
4066     configfile<<"#define SetupLoaded\n";
4067     configfile<<"#ifndef ResultLibraryClassLoaded\n";
4068     configfile<<"#include \"ResultLibraryClass.C\"\n";
4069     configfile<<"#endif\n";
4070    
4071     configfile<<"\nusing namespace std;\n\n";
4072    
4073     configfile<<"namespace PlottingSetup { \n";
4074     configfile<<"string datajzb=\"datajzb_ERROR\";\n";
4075     configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
4076     configfile<<"vector<float>jzb_cuts;\n";
4077 buchmann 1.18 configfile<<"vector<float>jzb_shape_limit_bins;\n";
4078 buchmann 1.1 configfile<<"float MCPeakError=-999;\n";
4079 buchmann 1.11 configfile<<"float DataPeakError=-999;\n";
4080 buchmann 1.1 configfile<<"}\n\n";
4081    
4082     configfile<<"void read_config() {\n";
4083     configfile<<"datajzb=\""<<datajzb<<"\";\n";
4084     configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
4085 buchmann 1.11 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
4086     configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
4087 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";
4088 buchmann 1.1 configfile<<"\n\n";
4089 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";
4090     for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4091     for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4092 buchmann 1.1 configfile<<"\n\n";
4093 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";
4094     for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4095 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";
4096 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";
4097     configfile<<"\n\n";
4098 buchmann 1.1 configfile<<"\n\n";
4099     configfile<<"luminosity="<<luminosity<<";\n";
4100 buchmann 1.5 configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
4101 buchmann 1.52 configfile<<"UseSidebandsForcJZB="<<UseSidebandsForcJZB<<";//tells us whether to use the sidebands or not\n";
4102 buchmann 1.1
4103     configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
4104    
4105     configfile.close();
4106    
4107     }
4108    
4109     float get_nonzero_minimum(TH1F *histo) {
4110     float min=histo->GetMaximum();
4111     for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
4112     float curcont=histo->GetBinContent(ibin);
4113     if(curcont<min&&curcont>0) min=curcont;
4114     }
4115     return min;
4116     }
4117    
4118     void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
4119     can->cd();
4120     float min=1;
4121     float max=histos[0]->GetMaximum();
4122     if(manualmin>=0) min=manualmin;
4123     else {
4124 buchmann 1.16 for(int i=1;i<(int)histos.size();i++) {
4125 buchmann 1.1 float curmin=get_nonzero_minimum(histos[i]);
4126     float curmax=histos[i]->GetMaximum();
4127     if(curmin<min) min=curmin;
4128     if(curmax>max) max=curmax;
4129     }
4130     }
4131     histos[0]->GetYaxis()->SetRangeUser(min,4*max);
4132     histos[0]->Draw(drawoption.c_str());
4133     stringstream drawopt;
4134     drawopt << drawoption << ",same";
4135 buchmann 1.16 for(int i=1;i<(int)histos.size();i++) {
4136 buchmann 1.1 histos[i]->Draw(drawopt.str().c_str());
4137     }
4138     }
4139    
4140 buchmann 1.93 void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring, TCut cut) {
4141 buchmann 1.1 //in the case of the on peak analysis, we compare the 3 control regions to the real value
4142     //in the case of the OFF peak analysis, we compare our control region to the real value
4143     TCut weightbackup=cutWeight;
4144 buchmann 1.65 switch_overunderflow(true);
4145 buchmann 1.34
4146 buchmann 1.93 bool doPURW=true;
4147 buchmann 1.34
4148    
4149     if(!doPURW) {
4150 fronga 1.40 dout << "Not doing PU reweighting for ttbar closure test" << endl;
4151 buchmann 1.34 cutWeight="1.0";
4152     // Do it without PU re-weighting
4153     float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4154     stringstream resultsNoPU;
4155     stringstream noPUdatajzb;
4156     stringstream noPUmcjzb;
4157    
4158     stringstream mcjzbnoPU;
4159     find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
4160 buchmann 1.36 mcjzb = noPUmcjzb.str();
4161 buchmann 1.34 }
4162    
4163 fronga 1.40
4164 buchmann 1.1 float simulatedlumi = luminosity; //in pb please - adjust to your likings
4165    
4166 buchmann 1.93 TH1F *TZem = allsamples.Draw("TZem", mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4167     TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4168 buchmann 1.1 TH1F *TSem;
4169     TH1F *nTSem;
4170 buchmann 1.93 TH1F *TZeemm = allsamples.Draw("TZeemm", mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4171     TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4172 buchmann 1.1 TH1F *TSeemm;
4173     TH1F *nTSeemm;
4174    
4175 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4176 buchmann 1.93 TSem = allsamples.Draw("TSem", mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4177     nTSem = allsamples.Draw("nTSem", "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4178     TSeemm = allsamples.Draw("TSeemm", mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4179     nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4180 buchmann 1.1 }
4181    
4182     TCanvas *tcan = new TCanvas("tcan","tcan");
4183     tcan->SetLogy(1);
4184    
4185     TZeemm->SetLineColor(kBlack);
4186     TZem->SetLineColor(kRed);
4187     TZeemm->SetMarkerColor(kBlack);
4188     TZem->SetMarkerColor(kRed);
4189    
4190    
4191 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4192 buchmann 1.1 TSem->SetLineColor(TColor::GetColor("#00A616"));
4193     TSeemm->SetLineColor(kMagenta+2);
4194     TSem->SetMarkerColor(TColor::GetColor("#00A616"));
4195     TSeemm->SetMarkerColor(kMagenta+2);
4196     TSem->SetLineStyle(2);
4197     TSeemm->SetLineStyle(3);
4198     }
4199    
4200     vector<TH1F*> histos;
4201 buchmann 1.31 TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4202     TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4203 buchmann 1.1 histos.push_back(TZem);
4204     histos.push_back(TZeemm);
4205 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4206 buchmann 1.31 TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4207     TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4208 buchmann 1.1 histos.push_back(TSem);
4209     histos.push_back(TSeemm);
4210     }
4211 buchmann 1.67 draw_all_ttbar_histos(tcan,histos,"histo",8);
4212 buchmann 1.1
4213     TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4214     leg->AddEntry(TZeemm,"SFZP","l");
4215     leg->AddEntry(TZem,"OFZP","l");
4216 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4217 buchmann 1.1 leg->AddEntry(TSeemm,"SFSB","l");
4218     leg->AddEntry(TSem,"OFSB","l");
4219     }
4220     leg->Draw("same");
4221     DrawMCPrelim(simulatedlumi);
4222     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
4223 buchmann 1.66
4224 buchmann 1.1 TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
4225     TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
4226 buchmann 1.11 TH1F *TSeemmcopy;
4227     TH1F *TSemcopy;
4228 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4229 buchmann 1.11 TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
4230     TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
4231     }
4232 buchmann 1.1
4233     TZem->Divide(TZeemm);
4234     TZem->SetMarkerStyle(21);
4235 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4236 buchmann 1.1 TSem->Divide(TZeemm);
4237     TSeemm->Divide(TZeemm);
4238     TSem->SetMarkerStyle(24);
4239     TSeemm->SetMarkerStyle(32);
4240 fronga 1.40 }
4241 buchmann 1.1
4242     tcan->SetLogy(0);
4243     TZem->GetYaxis()->SetRangeUser(0,2.5);
4244     TZem->GetYaxis()->SetTitle("ratio");
4245     TZem->Draw();
4246 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4247 buchmann 1.1 TSem->Draw("same");
4248     TSeemm->Draw("same");
4249     }
4250    
4251 buchmann 1.33 float linepos=emuncertONPEAK;
4252 buchmann 1.51 if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
4253 buchmann 1.33
4254 buchmann 1.1 TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
4255     TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4256     TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
4257    
4258 buchmann 1.11 /*write_warning(__FUNCTION__,"These two lines are to be removed!");
4259     TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
4260     TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
4261     topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
4262     bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
4263     topalt->Draw("same");bottomalt->Draw("same");*/
4264    
4265    
4266 buchmann 1.1 top->SetLineColor(kBlue);top->SetLineStyle(2);
4267     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
4268     center->SetLineColor(kBlue);
4269    
4270     top->Draw("same");
4271     center->Draw("same");
4272     bottom->Draw("same");
4273    
4274     TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
4275     leg2->AddEntry(TZem,"OFZP / SFZP","ple");
4276 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4277 buchmann 1.1 leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
4278     leg2->AddEntry(TSem,"OFSB / SFZP","ple");
4279     }
4280     leg2->AddEntry(bottom,"syst. envelope","l");
4281     leg2->SetX1(0.25);leg2->SetX2(0.6);
4282     leg2->SetY1(0.65);
4283    
4284     leg2->Draw("same");
4285    
4286     DrawMCPrelim(simulatedlumi);
4287     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4288    
4289 buchmann 1.66
4290 fronga 1.40 if (0) { // Turn this off: we don't need this
4291    
4292     ///-------------- second part: only look at the quantity we actually care about!
4293     TH1F *leftsfzp = (TH1F*)nTZeemm->Clone("leftsfzp");
4294     TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
4295     rightsfzp->Add(leftsfzp,-1);
4296     TH1F *leftofzp = (TH1F*)nTZem->Clone("leftofzp");
4297     TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
4298     rightofzp->Add(leftofzp,-1);
4299     TH1F *leftofsb;
4300     TH1F *rightofsb;
4301     TH1F *leftsfsb;
4302     TH1F *rightsfsb;
4303 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4304 fronga 1.40 leftofsb = (TH1F*)nTSem->Clone("leftofsb");
4305     rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
4306     rightofsb->Add(leftofsb,-1);
4307     leftsfsb = (TH1F*)nTSeemm->Clone("leftsfsb");
4308     rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
4309     rightsfsb->Add(leftsfsb,-1);
4310     }
4311 buchmann 1.1
4312 fronga 1.40 tcan->SetLogy(1);
4313     rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
4314     rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
4315     rightsfzp->Draw("histo");
4316     rightofzp->Draw("histo,same");
4317 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4318 fronga 1.40 rightofsb->Draw("histo,same");
4319     rightsfsb->Draw("histo,same");
4320     }
4321     DrawMCPrelim(simulatedlumi);
4322    
4323     TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
4324     legA->AddEntry(rightsfzp,"SFZP","l");
4325     legA->AddEntry(rightofzp,"OFZP","l");
4326 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4327 fronga 1.40 legA->AddEntry(rightofsb,"SFSB","l");
4328     legA->AddEntry(rightsfsb,"OFSB","l");
4329     }
4330     legA->Draw();
4331 buchmann 1.1
4332 fronga 1.40 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
4333 buchmann 1.1
4334 fronga 1.40 tcan->SetLogy(0);
4335     rightofzp->Divide(rightsfzp);
4336     rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
4337     rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
4338     rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
4339     rightofzp->Draw();
4340 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4341 fronga 1.40 rightofsb->Divide(rightsfzp);
4342     rightsfsb->Divide(rightsfzp);
4343     rightofsb->Draw("same");
4344     rightsfsb->Draw("same");
4345     }
4346 buchmann 1.1
4347 fronga 1.40 TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
4348     TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
4349     TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
4350    
4351     top2->SetLineColor(kBlue);top2->SetLineStyle(2);
4352     bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
4353     center2->SetLineColor(kBlue);
4354    
4355     top2->Draw("same");
4356     center2->Draw("same");
4357     bottom2->Draw("same");
4358 buchmann 1.1
4359 fronga 1.40 rightofzp->SetMarkerStyle(21);
4360 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4361 fronga 1.40 rightofsb->SetMarkerStyle(24);
4362     rightsfsb->SetMarkerStyle(32);
4363     }
4364 buchmann 1.1
4365 fronga 1.40 TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
4366     leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
4367 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4368 fronga 1.40 leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
4369     leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
4370     }
4371     leg3->AddEntry(bottom,"syst. envelope","l");
4372     leg3->SetX1(0.25);leg3->SetX2(0.6);
4373     leg3->SetY1(0.65);
4374 buchmann 1.1
4375 fronga 1.40 leg3->Draw("same");
4376 buchmann 1.1
4377 fronga 1.40 DrawMCPrelim(simulatedlumi);
4378     CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
4379 buchmann 1.1
4380     }
4381    
4382     delete TZem;
4383     delete nTZem;
4384     delete TZeemm;
4385     delete nTZeemm;
4386 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4387 buchmann 1.1 delete TSem;
4388     delete nTSem;
4389     delete TSeemm;
4390     delete nTSeemm;
4391     }
4392    
4393     delete tcan;
4394     cutWeight=weightbackup;
4395 buchmann 1.65 switch_overunderflow(false);
4396 buchmann 1.1 }
4397    
4398     void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
4399     vector<float> nicer_binning;
4400 buchmann 1.32
4401 buchmann 1.33 /* nicer_binning.push_back(-400);
4402 buchmann 1.31 nicer_binning.push_back(-250);
4403     nicer_binning.push_back(-200);
4404     nicer_binning.push_back(-150);
4405     nicer_binning.push_back(-100);
4406     nicer_binning.push_back(-50);
4407     nicer_binning.push_back(-20);
4408    
4409     nicer_binning.push_back(0);
4410     nicer_binning.push_back(20);
4411     nicer_binning.push_back(50);
4412     nicer_binning.push_back(100);
4413     nicer_binning.push_back(150);
4414     nicer_binning.push_back(200);
4415     nicer_binning.push_back(250);
4416 buchmann 1.33 nicer_binning.push_back(400);*/
4417    
4418 buchmann 1.1 nicer_binning.push_back(-100);
4419     nicer_binning.push_back(-50);
4420     nicer_binning.push_back(-25);
4421     nicer_binning.push_back(0);
4422     nicer_binning.push_back(25);
4423     nicer_binning.push_back(50);
4424     nicer_binning.push_back(75);
4425     nicer_binning.push_back(100);
4426     nicer_binning.push_back(125);
4427     nicer_binning.push_back(150);
4428 fronga 1.40 //nicer_binning.push_back(175);
4429 buchmann 1.1 nicer_binning.push_back(200);
4430 buchmann 1.66 // nicer_binning.push_back(250);
4431     // nicer_binning.push_back(300);
4432     // nicer_binning.push_back(400);
4433 buchmann 1.33
4434 buchmann 1.93 ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/",TCut("mll>0"));
4435     ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/LowMassRegion2070",TCut("mll>20&&mll<70"));
4436     ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/ZWindow",Restrmasscut);
4437    
4438 buchmann 1.1 }
4439    
4440    
4441 buchmann 1.70 void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4442 buchmann 1.66 cout << "****************************************************************************************************************************************************************" << endl;
4443 buchmann 1.20 TCanvas *zcan = new TCanvas("zcan","zcan");
4444     TCut weightbackup=cutWeight;
4445 buchmann 1.36
4446 buchmann 1.66 bool UsePURW=true;
4447 buchmann 1.36
4448    
4449     string mcjzb;
4450     if(UsePURW) {
4451     mcjzb=mcjzbWithPUa;
4452 buchmann 1.66 cout << "Using PURW peak positions" << endl;
4453 buchmann 1.36 } else {
4454     // Do it without PU re-weighting
4455 buchmann 1.66 cutWeight="1.0";
4456 buchmann 1.36 float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4457     stringstream resultsNoPU;
4458     stringstream noPUdatajzb;
4459     stringstream noPUmcjzb;
4460    
4461     find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
4462     dout << "The peak corrected JZB expression for MC without pileup is : " << noPUmcjzb.str() << endl;
4463    
4464     mcjzb = noPUmcjzb.str();
4465    
4466     }
4467 buchmann 1.34
4468 buchmann 1.25
4469 buchmann 1.92
4470 buchmann 1.25 vector<float> binning;
4471     binning.push_back(0);
4472 buchmann 1.33 binning.push_back(10);
4473 buchmann 1.93 binning.push_back(30);
4474     // binning.push_back(40);
4475     // binning.push_back(60);
4476     binning.push_back(50);
4477 buchmann 1.36 // binning.push_back(60);
4478     // binning.push_back(70);
4479     // binning.push_back(80);
4480     // binning.push_back(90);
4481 buchmann 1.25 binning.push_back(100);
4482 buchmann 1.36
4483 buchmann 1.1 float simulatedlumi = luminosity;//in pb please - adjust to your likings
4484    
4485     TCut kPos((mcjzb+">0").c_str());
4486     TCut kNeg((mcjzb+"<0").c_str());
4487 buchmann 1.92 TCut reducedNJets(cutnJets);
4488 buchmann 1.1 string var( "abs("+mcjzb+")" );
4489 buchmann 1.36
4490 buchmann 1.92
4491 buchmann 1.93 TCut notTau("!EventZToTaus");
4492 buchmann 1.66 TCut ee_mm_tautau("mll>0");
4493 buchmann 1.36
4494 buchmann 1.92 TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4495     TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4496 buchmann 1.36
4497 buchmann 1.1 hJZBpos->SetLineColor(kBlack);
4498     hJZBneg->SetLineColor(kRed);
4499    
4500 buchmann 1.25 hJZBpos->SetMinimum(1.0);
4501 buchmann 1.1 hJZBpos->Draw("e1");
4502     hJZBneg->Draw("same,hist");
4503     hJZBpos->Draw("same,e1"); // So it's on top...
4504    
4505 buchmann 1.36 TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
4506 buchmann 1.1 leg->AddEntry(hJZBpos,"Observed","pe");
4507     leg->AddEntry(hJZBneg,"Predicted","l");
4508     leg->Draw("same");
4509     DrawMCPrelim(simulatedlumi);
4510 buchmann 1.70 CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
4511 buchmann 1.1
4512     TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
4513     hratio->Divide(hJZBneg);
4514    
4515 buchmann 1.30 for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
4516 buchmann 1.93 cout << "Positive: " << hJZBpos->GetBinContent(i) << " +/- " << hJZBpos->GetBinError(i) << " vs Negative : " << hJZBneg->GetBinContent(i) << " +/- " << hJZBneg->GetBinError(i) << " (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << " +/- " << (hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i)) * sqrt(pow(hJZBpos->GetBinError(i)/hJZBpos->GetBinContent(i),2) + pow(hJZBneg->GetBinError(i)/hJZBneg->GetBinContent(i),2)) << ")" << endl;
4517 buchmann 1.30 }
4518    
4519 buchmann 1.70 // zcan->SetLogy(0);
4520 buchmann 1.66 hratio->GetYaxis()->SetRangeUser(0,2.5);
4521 buchmann 1.1 hratio->GetYaxis()->SetTitle("Observed/Predicted");
4522     hratio->Draw("e1");
4523    
4524 buchmann 1.92 TLine *top = new TLine(binning[0],1.2,binning[binning.size()-1],1.2);
4525 buchmann 1.25 TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4526 buchmann 1.92 TLine *bottom = new TLine(binning[0],0.8,binning[binning.size()-1],0.8);
4527 buchmann 1.1
4528    
4529     top->SetLineColor(kBlue);top->SetLineStyle(2);
4530     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
4531     center->SetLineColor(kBlue);
4532    
4533     top->Draw("same");
4534     center->Draw("same");
4535     bottom->Draw("same");
4536    
4537 buchmann 1.36 TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4538 buchmann 1.1 leg2->AddEntry(hratio,"obs / pred","pe");
4539     leg2->AddEntry(bottom,"syst. envelope","l");
4540     leg2->Draw("same");
4541     DrawMCPrelim(simulatedlumi);
4542 buchmann 1.70 CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4543 buchmann 1.36
4544 buchmann 1.92 TH1F *TAUhJZBpos = allsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4545     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4546     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4547     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4548 buchmann 1.36
4549     TH1F *RcorrJZBSBem;
4550     TH1F *LcorrJZBSBem;
4551     TH1F *RcorrJZBSBeemm;
4552     TH1F *LcorrJZBSBeemm;
4553    
4554 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4555 buchmann 1.92 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4556     LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4557     RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4558     LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4559 buchmann 1.36 }
4560    
4561     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4562 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4563 buchmann 1.36 Bpred->Add(RcorrJZBem,1.0/3.);
4564     Bpred->Add(LcorrJZBem,-1.0/3.);
4565     Bpred->Add(RcorrJZBSBem,1.0/3.);
4566     Bpred->Add(LcorrJZBSBem,-1.0/3.);
4567     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
4568     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
4569     } else {
4570     Bpred->Add(RcorrJZBem,1.0);
4571     Bpred->Add(LcorrJZBem,-1.0);
4572     }
4573    
4574     Bpred->SetLineColor(kRed);
4575    
4576     TAUhJZBpos->SetLineColor(kBlack);
4577     Bpred->SetLineColor(kRed);
4578    
4579     TAUhJZBpos->SetMinimum(1.0);
4580     TAUhJZBpos->Draw("e1");
4581     Bpred->Draw("same,hist");
4582     TAUhJZBpos->Draw("same,e1");
4583    
4584     TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
4585     TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
4586     TAUleg->AddEntry(Bpred,"Predicted","l");
4587     TAUleg->Draw("same");
4588     DrawMCPrelim(simulatedlumi);
4589 buchmann 1.70 CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
4590 buchmann 1.36
4591     TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
4592     TAUhratio->Divide(Bpred);
4593    
4594     for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
4595     cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << " vs predicted : " << Bpred->GetBinContent(i) << " (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
4596     }
4597    
4598     zcan->SetLogy(0);
4599     TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
4600     TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
4601     TAUhratio->Draw("e1");
4602    
4603     top->Draw("same");
4604     center->Draw("same");
4605     bottom->Draw("same");
4606    
4607 buchmann 1.66 TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4608 buchmann 1.36 TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
4609     TAUleg2->AddEntry(bottom,"syst. envelope","l");
4610     TAUleg2->Draw("same");
4611     DrawMCPrelim(simulatedlumi);
4612 buchmann 1.70 CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
4613 buchmann 1.36
4614     delete Bpred;
4615     delete TAUhJZBpos;
4616     delete LcorrJZBeemm;
4617     delete RcorrJZBem;
4618     delete LcorrJZBem;
4619 buchmann 1.70 delete hJZBpos;
4620     delete hJZBneg;
4621 buchmann 1.36
4622 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4623 buchmann 1.36 delete RcorrJZBSBem;
4624     delete LcorrJZBSBem;
4625     delete RcorrJZBSBeemm;
4626     delete LcorrJZBSBeemm;
4627     }
4628    
4629 buchmann 1.92 //***************************************************************************************************
4630    
4631     string jzbvar=var;
4632 buchmann 1.93 /*
4633 buchmann 1.92 for(int i=0;i<60;i+=10) {
4634     stringstream sSpecialJZBCut;
4635     sSpecialJZBCut << jzbvar << ">" << i;
4636     TCut SpecialJZBCut(sSpecialJZBCut.str().c_str());
4637    
4638     var="mll";
4639    
4640     TH1F *FullJZBhJZBpos = allsamples.Draw("FullJZBhJZBpos",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4641     TH1F *LcorrJZBPluseemm = allsamples.Draw("LcorrJZBPluseemm",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4642     TH1F *RcorrJZBPlusem = allsamples.Draw("RcorrJZBPlusem",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4643     TH1F *LcorrJZBPlusem = allsamples.Draw("LcorrJZBPlusem",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4644    
4645     TH1F *RcorrJZBPlusSBem;
4646     TH1F *LcorrJZBPlusSBem;
4647     TH1F *RcorrJZBPlusSBeemm;
4648     TH1F *LcorrJZBPlusSBeemm;
4649    
4650    
4651     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4652     RcorrJZBPlusSBem = allsamples.Draw("RcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4653     LcorrJZBPlusSBem = allsamples.Draw("LcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4654     RcorrJZBPlusSBeemm = allsamples.Draw("RcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4655     LcorrJZBPlusSBeemm = allsamples.Draw("LcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4656     }
4657    
4658     TH1F *BpredPrime = (TH1F*)LcorrJZBPluseemm->Clone("BpredPrime");
4659     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4660     BpredPrime->Add(RcorrJZBPlusem,1.0/3.);
4661     BpredPrime->Add(LcorrJZBPlusem,-1.0/3.);
4662     BpredPrime->Add(RcorrJZBPlusSBem,1.0/3.);
4663     BpredPrime->Add(LcorrJZBPlusSBem,-1.0/3.);
4664     BpredPrime->Add(RcorrJZBPlusSBeemm,1.0/3.);
4665     BpredPrime->Add(LcorrJZBPlusSBeemm,-1.0/3.);
4666     } else {
4667     BpredPrime->Add(RcorrJZBPlusem,1.0);
4668     BpredPrime->Add(LcorrJZBPlusem,-1.0);
4669     }
4670    
4671     BpredPrime->SetLineColor(kRed);
4672    
4673     FullJZBhJZBpos->SetLineColor(kBlack);
4674     BpredPrime->SetLineColor(kRed);
4675    
4676     FullJZBhJZBpos->SetMinimum(1.0);
4677     FullJZBhJZBpos->Draw("e1");
4678     BpredPrime->Draw("same,hist");
4679     FullJZBhJZBpos->Draw("same,e1");
4680    
4681     TLegend *FullJZBleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
4682     FullJZBleg->AddEntry(FullJZBhJZBpos,"Observed","pe");
4683     FullJZBleg->AddEntry(BpredPrime,"Predicted","l");
4684     FullJZBleg->Draw("same");
4685     DrawMCPrelim(simulatedlumi);
4686     CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"_zjets_eemumu_prediction__"+any2string(massregionname));
4687    
4688     TH1F* FullJZBhratio = (TH1F*)FullJZBhJZBpos->Clone("FullJZBhratio");
4689     FullJZBhratio->Divide(BpredPrime);
4690    
4691     zcan->SetLogy(0);
4692     FullJZBhratio->GetYaxis()->SetRangeUser(0,2.5);
4693     FullJZBhratio->GetYaxis()->SetTitle("Observed/Predicted");
4694     FullJZBhratio->Draw("e1");
4695    
4696     TLine *atop = new TLine(0,1.2,200,1.2);
4697     TLine *acenter = new TLine(0,1.0,200,1.0);
4698     TLine *abottom = new TLine(0,0.8,200,0.8);
4699    
4700     atop->SetLineColor(kBlue);
4701     atop->SetLineStyle(2);
4702     acenter->SetLineColor(kBlue);
4703     abottom->SetLineColor(kBlue);
4704     abottom->SetLineStyle(2);
4705    
4706     atop->Draw("same");
4707     acenter->Draw("same");
4708     abottom->Draw("same");
4709    
4710     TLegend *FullJZBleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4711     FullJZBleg2->AddEntry(FullJZBhratio,"obs / pred","pe");
4712     FullJZBleg2->AddEntry(abottom,"syst. envelope","l");
4713     FullJZBleg2->Draw("same");
4714     DrawMCPrelim(simulatedlumi);
4715     CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"zjets_eemumu_prediction_ratio"+any2string(massregionname));
4716    
4717    
4718     delete BpredPrime;
4719     delete FullJZBhJZBpos;
4720     delete LcorrJZBPluseemm;
4721     delete RcorrJZBPlusem;
4722     delete LcorrJZBPlusem;
4723     // delete FullJZBhJZBpos;
4724    
4725     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4726     delete RcorrJZBPlusSBem;
4727     delete LcorrJZBPlusSBem;
4728     delete RcorrJZBPlusSBeemm;
4729     delete LcorrJZBPlusSBeemm;
4730     }
4731    
4732     }
4733     //***************************************************************************************************
4734 buchmann 1.93 */
4735 buchmann 1.1 delete zcan;
4736     cutWeight=weightbackup;
4737     }
4738    
4739    
4740 buchmann 1.70 void zjets_prediction_comparison(string mcjzbWithPUa) {
4741 buchmann 1.93 zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20"), "nomasscut");
4742 buchmann 1.92 zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<10"), "Zwindow_10");
4743 buchmann 1.70 zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
4744 buchmann 1.93 // zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)>10&&mll>20"), "Outside_Zwindow_10");
4745     // zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
4746 buchmann 1.70 }
4747    
4748 buchmann 1.1 void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
4749     tout << endl << endl;
4750     stringstream bordercut;
4751     bordercut << "(TMath::Abs(" << datajzb << ")<" << max << ")&&(TMath::Abs(" << datajzb << ")>" << min << ")";
4752     tout << bordercut.str().c_str() << endl;
4753     TH1F *ofsb = allsamples.Draw("ofsb",datajzb,100, 0,100, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
4754     TH1F *ofzp = allsamples.Draw("ofzp",datajzb,100, 0,100, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
4755     float OFSB = ofsb->Integral();
4756     float OFZP = ofzp->Integral();
4757    
4758     tout << "\\begin{table}[hbtp]" << endl;
4759     tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
4760     tout << "\\begin{center}" << endl;
4761     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;
4762     tout << "\\begin{tabular}{l|cc}" << endl;
4763     tout << "\\hline" << endl;
4764     tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
4765 buchmann 1.25 tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
4766 buchmann 1.1 tout << "\\end{tabular}" << endl;
4767     tout << "\\end{center}" << endl;
4768     tout << "\\end{table}" << endl;
4769    
4770    
4771     }
4772    
4773     void make_table(samplecollection &coll, string jzbexpr, bool is_data, vector<float> jzb_cuts, string subselection="none") {
4774    
4775     vector<float> jzbcutprediction;
4776     vector<float> metcutprediction;
4777    
4778     vector<float> jzbcutobservation;
4779     vector<float> metcutobservation;
4780    
4781     TCanvas *cannie = new TCanvas("cannie","cannie");
4782    
4783 buchmann 1.16 for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
4784 buchmann 1.1 float currcut=jzb_cuts[icut];
4785     int nbins=1;float low=currcut;
4786     vector<int> mysample;
4787     if(subselection!="none") mysample=coll.FindSample(subselection);
4788     TH1F *RcorrJZBeemm = coll.Draw("RcorrJZBeemm",jzbexpr,1,currcut,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
4789     TH1F *LcorrJZBeemm = coll.Draw("LcorrJZBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
4790     TH1F *RcorrJZBem = coll.Draw("RcorrJZBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4791     TH1F *LcorrJZBem = coll.Draw("LcorrJZBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4792    
4793     TH1F *RcorrJZBSBem;
4794     TH1F *LcorrJZBSBem;
4795     TH1F *RcorrJZBSBeemm;
4796     TH1F *LcorrJZBSBeemm;
4797    
4798 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4799 buchmann 1.1 RcorrJZBSBem = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4800     LcorrJZBSBem = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4801     RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
4802     LcorrJZBSBeemm = coll.Draw("LcorrJZBSBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
4803     }
4804    
4805     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4806 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4807 buchmann 1.1 Bpred->Add(RcorrJZBem,1.0/3.);
4808     Bpred->Add(LcorrJZBem,-1.0/3.);
4809     Bpred->Add(RcorrJZBSBem,1.0/3.);
4810     Bpred->Add(LcorrJZBSBem,-1.0/3.);
4811     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
4812     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
4813     } else {
4814     Bpred->Add(RcorrJZBem,1.0);
4815     Bpred->Add(LcorrJZBem,-1.0);
4816     }
4817    
4818     jzbcutobservation.push_back(RcorrJZBeemm->Integral());
4819     jzbcutprediction.push_back(Bpred->Integral());
4820    
4821     delete RcorrJZBeemm;
4822     delete LcorrJZBeemm;
4823     delete RcorrJZBem;
4824     delete LcorrJZBem;
4825     delete RcorrJZBSBem;
4826     delete LcorrJZBSBem;
4827     delete RcorrJZBSBeemm;
4828     delete LcorrJZBSBeemm;
4829    
4830     TH1F *MetObs = coll.Draw("MetObs",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
4831     TH1F *MetPred = coll.Draw("MetPred",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4832    
4833     metcutobservation.push_back(MetObs->Integral());
4834     metcutprediction.push_back(MetPred->Integral());
4835     delete MetObs;
4836     delete MetPred;
4837     }//end of cut loop
4838    
4839     //prediction part
4840     if(is_data) cout << "Data prediction & ";
4841     if(subselection!="none") cout << subselection << " prediction &";
4842 buchmann 1.16 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
4843 buchmann 1.1
4844     cout << endl;
4845     //observation part
4846     if(is_data) cout << "Data observation & ";
4847     if(subselection!="none") cout << subselection << " observation &";
4848 buchmann 1.16 for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
4849 buchmann 1.1 cout << endl;
4850     cout << "_________________________________________________________________" << endl;
4851     delete cannie;
4852     }
4853    
4854     void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4855 buchmann 1.79 cout << "You probably don't want --met, you want --metplots ... " << endl;
4856     assert(0);
4857 buchmann 1.1 /*we want a table like this:
4858     __________________ 50 | 100 | ...
4859     | Data prediction | a vs b | a vs b | ...
4860     | Data observed | a vs b | a vs b | ...
4861     --------------------------------------
4862     --------------------------------------
4863     | LM4 prediction | a vs b | a vs b | ...
4864     | LM4 observed | a vs b | a vs b | ...
4865     | LM8 prediction | a vs b | a vs b | ...
4866     | LM8 observed | a vs b | a vs b | ...
4867    
4868     where a is the result for a jzb cut at X, and b is the result for a met cut at X
4869     */
4870     make_table(allsamples,datajzb, true,jzb_cut,"none");
4871     make_table(signalsamples,mcjzb, false,jzb_cut,"LM4");
4872     make_table(signalsamples,mcjzb, false,jzb_cut,"LM8");
4873     }
4874    
4875    
4876     //________________________________________________________________________________________
4877     // JZB Efficiency plot (efficiency of passing reco. JZB cut as function of generator JZB cut)
4878     void JZBSelEff(string mcjzb, TTree* events, string informalname, vector<float> jzb_bins) {
4879    
4880     float min = 0, max = 400;
4881     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};
4882     int nbins = sizeof(xbins)/sizeof(float)-1;
4883     int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
4884    
4885 buchmann 1.14
4886     TH1F* heff = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
4887     TH1F* hgen = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
4888     TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
4889 buchmann 1.1
4890     TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
4891     TCut kreco(cutmass);
4892    
4893     TF1* func = new TF1("func","0.5*[2]*(TMath::Erf((x-[1])/[0])+1)",min,max);
4894     func->SetParNames("epsilon","x_{1/2}","sigma");
4895     func->SetParameter(0,50.);
4896     func->SetParameter(1,0.);
4897     func->SetParameter(2,1.);
4898     gStyle->SetOptStat(0);
4899     gStyle->SetOptFit(0);
4900    
4901     TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
4902     can->SetGridx(1);
4903     can->SetGridy(1);
4904 buchmann 1.14 can->SetLeftMargin(0.16);
4905     can->SetRightMargin(0.05);
4906 buchmann 1.1 TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
4907 buchmann 1.14 leg->SetBorderSize(1);
4908     leg->SetLineColor(kBlack);
4909     leg->SetTextFont(62);
4910 buchmann 1.1
4911 buchmann 1.16 for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
4912 buchmann 1.1
4913     ostringstream selection;
4914     selection << mcjzb << ">" << jzb_bins[icut];
4915     TCut ksel(selection.str().c_str());
4916     events->Draw("genJZB>>hgen", kgen&&kreco, "goff");
4917     events->Draw("genJZB>>hreco",kgen&&kreco&&ksel,"goff");
4918    
4919     // Loop over steps to get efficiency curve
4920     for ( Int_t iBin = 0; iBin<nbins-1; ++iBin ) {
4921     Float_t eff = hreco->GetBinContent(iBin+1)/hgen->GetBinContent(iBin+1);
4922     heff->SetBinContent(iBin+1,eff);
4923     heff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/hgen->GetBinContent(iBin+1)));
4924     }
4925    
4926     heff->GetXaxis()->SetRangeUser(min, max);
4927 buchmann 1.14 // heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
4928     // heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
4929     // heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
4930     // heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
4931 buchmann 1.1 heff->SetMarkerStyle(markers[icut]);
4932     heff->Fit("func","Q+","same");
4933    
4934     // Print values
4935     dout << "+++ For " << selection.str() << std::endl;
4936     for ( int i=0; i<func->GetNpar(); ++i )
4937     dout << " " << func->GetParName(i) << " " << func->GetParameter(i) << " \\pm " << func->GetParError(i) << std::endl;
4938     char hname[256]; sprintf(hname,"heff%d",icut);
4939    
4940     // Store plot
4941     TH1F* h = (TH1F*)heff->Clone(hname);
4942 buchmann 1.14 h->SetNdivisions(505,"X");
4943 buchmann 1.1 if ( icut) h->Draw("same");
4944     else h->Draw();
4945     char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
4946     leg->AddEntry(h,htitle,"p");
4947    
4948     }
4949    
4950     leg->Draw();
4951     DrawMCPrelim(0.0);
4952     CompleteSave(can, "Systematics/jzb_efficiency_curve"+informalname );
4953    
4954     delete hgen;
4955     delete hreco;
4956     delete heff;
4957     }
4958    
4959     //________________________________________________________________________________________
4960     // Calls the above function for each signal sample
4961     void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
4962     {
4963 buchmann 1.16 for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
4964 buchmann 1.1 dout << "JZB selection efficiency curve: " << std::endl;
4965     JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
4966     }
4967     }
4968 buchmann 1.3
4969     void qcd_plots(string datajzb, string mcjzb, vector<float> bins) {
4970     // What this function aims to do:
4971     // Illustrate cut flow for QCD (requiring only one lepton, requiring etc.)
4972     // 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.
4973     TCanvas *can = new TCanvas("can","can");
4974     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
4975     kinpad->cd();
4976    
4977     string jzb=mcjzb;
4978    
4979     float hi=400;
4980     bool use_signal=false;
4981     bool use_data=false;
4982    
4983     bool is_data=false;
4984     int nbins=50;//100;
4985     float low=0;
4986     float high=500;
4987     int versok=false;
4988     if(gROOT->GetVersionInt()>=53000) versok=true;
4989    
4990     TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
4991     TH1F *RcorrJZBeemm = qcdsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4992     TH1F *LcorrJZBeemm = qcdsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4993     TH1F *RcorrJZBem = qcdsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4994     TH1F *LcorrJZBem = qcdsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4995     blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
4996     blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
4997     blankback->GetXaxis()->CenterTitle();
4998     blankback->GetYaxis()->CenterTitle();
4999    
5000     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
5001     TH1F *RcorrJZBSBem;
5002     TH1F *LcorrJZBSBem;
5003     TH1F *RcorrJZBSBeemm;
5004     TH1F *LcorrJZBSBeemm;
5005    
5006 buchmann 1.16 // TH1F *RcorrJZBeemmNoS;
5007 buchmann 1.3
5008     //these are for the ratio
5009     TH1F *JRcorrJZBeemm = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5010     TH1F *JLcorrJZBeemm = qcdsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5011     TH1F *JRcorrJZBem = qcdsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5012     TH1F *JLcorrJZBem = qcdsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5013    
5014     TH1F *JRcorrJZBSBem;
5015     TH1F *JLcorrJZBSBem;
5016     TH1F *JRcorrJZBSBeemm;
5017     TH1F *JLcorrJZBSBeemm;
5018    
5019 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5020 buchmann 1.3 RcorrJZBSBem = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5021     LcorrJZBSBem = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5022     RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5023     LcorrJZBSBeemm = qcdsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5024    
5025     //these are for the ratio
5026     JRcorrJZBSBem = qcdsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5027     JLcorrJZBSBem = qcdsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
5028     JRcorrJZBSBeemm = qcdsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5029     JLcorrJZBSBeemm = qcdsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
5030    
5031     }
5032    
5033     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
5034    
5035     TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
5036     TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
5037    
5038     TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
5039     TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
5040 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5041 buchmann 1.3 Bpred->Add(RcorrJZBem,1.0/3.);
5042     Bpred->Add(LcorrJZBem,-1.0/3.);
5043     Bpred->Add(RcorrJZBSBem,1.0/3.);
5044     Bpred->Add(LcorrJZBSBem,-1.0/3.);
5045     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
5046     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
5047    
5048     TTbarpred->Scale(1.0/3);
5049     Zjetspred->Add(LcorrJZBem,-1.0/3.);
5050     Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
5051     TTbarpred->Add(RcorrJZBSBem,1.0/3.);
5052     Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
5053     TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
5054    
5055     //these are for the ratio
5056     JBpred->Add(JRcorrJZBem,1.0/3.);
5057     JBpred->Add(JLcorrJZBem,-1.0/3.);
5058     JBpred->Add(JRcorrJZBSBem,1.0/3.);
5059     JBpred->Add(JLcorrJZBSBem,-1.0/3.);
5060     JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
5061     JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
5062     } else {
5063     Bpred->Add(RcorrJZBem,1.0);
5064     Bpred->Add(LcorrJZBem,-1.0);
5065    
5066     Zjetspred->Add(LcorrJZBem,-1.0);
5067    
5068     //these are for the ratio
5069     JBpred->Add(JRcorrJZBem,1.0);
5070     JBpred->Add(JLcorrJZBem,-1.0);
5071     }
5072    
5073    
5074     flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
5075 buchmann 1.1
5076 buchmann 1.3 TLegend *legBpred = make_legend("",0.6,0.55,false);
5077     RcorrJZBeemm->Draw("e1x0,same");
5078     Bpred->Draw("hist,same");
5079     RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
5080     legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
5081     legBpred->AddEntry(Bpred,"MC predicted","l");
5082     if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
5083     if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
5084     legBpred->Draw();
5085     DrawMCPrelim();
5086    
5087     //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
5088     string ytitle("ratio");
5089     if ( use_data==1 ) ytitle = "data/pred";
5090 buchmann 1.79 Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5091     delete kinpad;
5092 buchmann 1.3
5093     TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
5094     TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
5095     TH1F *osof = qcdsamples.Draw("osof","pfJetGoodNum",1,0,100, "internal code", "events", cutOSOF ,mc, luminosity);
5096     TH1F *njossf = qcdsamples.Draw("njossf","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSSF ,mc, luminosity);
5097     TH1F *njosof = qcdsamples.Draw("njosof","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSOF ,mc, luminosity);
5098    
5099     dout << "______________________________________________" << endl;
5100     dout << "QCD contribution: " << endl;
5101     dout << "Total number of events: " << allevents->Integral() << endl;
5102     dout << "OSSF events: " << ossf->Integral() << endl;
5103     dout << "OSOF events: " << osof->Integral() << endl;
5104     dout << "OSSF events with >=3 jets:" << njossf->Integral() << endl;
5105     dout << "OSOF events with >=3 jets:" << njosof->Integral() << endl;
5106     dout << "(note that no mass requirement has been imposed)" << endl;
5107    
5108     dout << "______________________________________________" << endl;
5109     dout << "How QCD shows up in the different regions: " << endl;
5110     dout << "OSSF: " << endl;
5111 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5112 buchmann 1.3 dout << " Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
5113     dout << " sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
5114     } else {
5115     dout << " " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
5116     }
5117     dout << "OSOF: " << endl;
5118 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5119 buchmann 1.3 dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
5120     dout << " sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
5121     } else {
5122     dout << " Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
5123     }
5124     dout << "Therefore: " << endl;
5125 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5126 buchmann 1.3 dout << " Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
5127     dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
5128     dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
5129     dout << " = " << LcorrJZBeemm->Integral() + (1.0/3)*(RcorrJZBSBeemm->Integral() - LcorrJZBSBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() + RcorrJZBSBem->Integral() - LcorrJZBSBem->Integral()) << endl;
5130     } else {
5131     dout << " Prediction increases by : " << LcorrJZBeemm->Integral();
5132     dout << " + (" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
5133     dout << " = " << LcorrJZBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() << endl;
5134     }
5135     dout << " Observation increases by : " << RcorrJZBeemm->Integral() << endl;
5136    
5137     dout << endl;
5138 buchmann 1.16 for(int i=0;i<(int)bins.size();i++) {
5139 buchmann 1.3 dout << " JZB > " << bins[i] << " : " << endl;
5140     dout << " Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
5141 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5142 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;
5143     } else {
5144     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;
5145     }
5146     }
5147    
5148     delete can;
5149     delete allevents;
5150     if(ossf) delete ossf;
5151     if(RcorrJZBem) delete RcorrJZBem;
5152     if(LcorrJZBem) delete LcorrJZBem;
5153     if(RcorrJZBeemm) delete RcorrJZBeemm;
5154     if(LcorrJZBeemm) delete LcorrJZBeemm;
5155 buchmann 1.50 if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBem) delete RcorrJZBSBem;
5156     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBem) delete LcorrJZBSBem;
5157     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
5158     if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
5159 buchmann 1.3 }
5160 buchmann 1.1
5161 buchmann 1.4 void check_ptsanity() {
5162     TCanvas *ptsancan = new TCanvas("ptsancan","ptsancan",600,1800);
5163     TH1F *individualpt1histos[allsamples.collection.size()];
5164     TH1F *individualpt2histos[allsamples.collection.size()];
5165     TH1F *fpt1 = new TH1F("fpt1","fpt1",50,0,50);
5166     fpt1->GetYaxis()->SetRangeUser(0,1);
5167     fpt1->GetXaxis()->SetTitle("p_{T,1}");
5168     fpt1->GetXaxis()->CenterTitle();
5169    
5170     TH1F *fpt2 = new TH1F("fpt2","fpt2",50,0,50);
5171     fpt2->GetXaxis()->SetTitle("p_{T,2}");
5172     fpt2->GetXaxis()->CenterTitle();
5173    
5174     ptsancan->Divide(1,3);
5175     ptsancan->cd(1);
5176     float maxpt1entry=0;
5177     float maxpt2entry=0;
5178    
5179     TLegend *leg = make_legend();
5180     leg->SetX1(0.0);
5181     leg->SetY1(0.0);
5182     leg->SetX2(1.0);
5183     leg->SetY2(1.0);
5184    
5185    
5186 buchmann 1.16 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
5187 buchmann 1.4 string nowname=(allsamples.collection)[isample].filename;
5188     cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
5189     individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
5190     individualpt2histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt2",50,0,50, "p_{T,2}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
5191     individualpt1histos[isample]->SetLineColor(isample+1);
5192     individualpt2histos[isample]->SetLineColor(isample+1);
5193     float currmaxpt1entry=individualpt1histos[isample]->GetMaximum()/individualpt1histos[isample]->Integral();
5194     float currmaxpt2entry=individualpt2histos[isample]->GetMaximum()/individualpt2histos[isample]->Integral();
5195     cout << " pt 1 histo contains; " << individualpt1histos[isample]->Integral() << endl;
5196     cout << " pt 2 histo contains; " << individualpt2histos[isample]->Integral() << endl;
5197     if(currmaxpt1entry>maxpt1entry)maxpt1entry=currmaxpt1entry;
5198     if(currmaxpt2entry>maxpt2entry)maxpt2entry=currmaxpt2entry;
5199     leg->AddEntry(individualpt2histos[isample],((allsamples.collection)[isample].filename).c_str(),"f");
5200     }
5201    
5202     fpt1->GetYaxis()->SetRangeUser(0,maxpt1entry);
5203     fpt2->GetYaxis()->SetRangeUser(0,maxpt2entry);
5204    
5205     ptsancan->cd(1);
5206     fpt1->Draw();
5207     ptsancan->cd(2);
5208     fpt2->Draw();
5209    
5210 buchmann 1.16 for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
5211 buchmann 1.4 ptsancan->cd(1);
5212     individualpt1histos[isample]->DrawNormalized("same,histo");
5213     ptsancan->cd(2);
5214     individualpt2histos[isample]->DrawNormalized("same,histo");
5215     }
5216     ptsancan->cd(3);
5217     leg->Draw();
5218     CompleteSave(ptsancan,"PtSanityCheck");
5219    
5220     delete ptsancan;
5221     }
5222    
5223 buchmann 1.6 void do_mlls_plot(string mcjzb) {
5224     cout << "At this point we'd plot the mll distribution" << endl;
5225     TCanvas *sigcan = new TCanvas("sigcan","sigcan");
5226 buchmann 1.16 for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
5227 buchmann 1.6 if(!(signalsamples.collection)[isig].events) continue;
5228     string nowname=(signalsamples.collection)[isig].filename;
5229     TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
5230     // TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
5231     mll->SetLineColor(TColor::GetColor("#04B404"));
5232     stringstream poscutS;
5233     poscutS << "((" << mcjzb <<")>50)";
5234     TCut poscut(poscutS.str().c_str());
5235     TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
5236     mllP->SetLineColor(TColor::GetColor("#0040FF"));
5237     mll->Draw("histo");
5238     mllP->Draw("histo,same");
5239     TLegend *leg = make_legend();
5240     leg->SetY1(0.8);
5241     leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
5242     leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
5243     leg->Draw();
5244     TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
5245     TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
5246     lin->Draw("same");
5247     lin2->Draw("same");
5248    
5249     CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
5250     delete mll;
5251     delete mllP;
5252     }
5253     }
5254    
5255 buchmann 1.47 void met_vs_jzb_plots(string datajzb, string mcjzb) {
5256 buchmann 1.9
5257     TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
5258     canmetjzb->SetRightMargin(0.16);
5259    
5260     vector<string> findme;
5261     findme.push_back("DY");
5262 buchmann 1.93 findme.push_back("TT_");
5263 buchmann 1.9 findme.push_back("LM");
5264 buchmann 1.48 /*
5265 buchmann 1.16 for(int ifind=0;ifind<(int)findme.size();ifind++) {
5266 buchmann 1.9 vector<int> selsamples = allsamples.FindSample(findme[ifind]);
5267     TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
5268 buchmann 1.16 for(int isel=0;isel<(int)selsamples.size();isel++) {
5269 buchmann 1.47 dout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
5270     allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF&&cutnJets);
5271 buchmann 1.9 }
5272     metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
5273     metvsjzb->SetStats(0);
5274     metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
5275     metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
5276     metvsjzb->GetXaxis()->CenterTitle();
5277     metvsjzb->GetYaxis()->CenterTitle();
5278     metvsjzb->Draw("COLZ");
5279     TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
5280     title->SetTextAlign(12);
5281     title->Draw();
5282     CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
5283     }
5284 buchmann 1.48 */
5285 buchmann 1.47
5286     dout << "About to produce MET plot for DY split up by JZB" << endl;
5287    
5288     int nbins=14;
5289     float low=0;
5290     float high=140;
5291    
5292     stringstream sLEFT;
5293     sLEFT << "((" << mcjzb << ")<0)";
5294     TCut LEFT(sLEFT.str().c_str());
5295     stringstream sRIGHT;
5296     sRIGHT << "((" << mcjzb << ")>0)";
5297     TCut RIGHT(sRIGHT.str().c_str());
5298    
5299 buchmann 1.89 TH1F *metleft = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5300     TH1F *metleftO = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5301     TH1F *metright = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5302     TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5303 buchmann 1.47
5304 buchmann 1.48
5305     TH1F *Bpred = (TH1F*)metleft->Clone("Bpred");
5306     Bpred->Add(metleftO,-1);
5307     Bpred->Add(metrightO);
5308     TH1F *obs = (TH1F*)metright->Clone("obs");
5309    
5310 buchmann 1.47 metleft->Add(metleftO,-1);
5311     metright->Add(metrightO,-1);
5312    
5313     metleft->SetLineColor(kRed);
5314     metright->SetLineColor(kBlack);
5315     TPad *metpad = new TPad("metpad","metpad",0,0,1,1);
5316     metpad->cd();
5317     metpad->SetLogy(1);
5318     metleft->Draw("histo");
5319     metright->Draw("same");
5320     TLegend *lg = make_legend();
5321     lg->SetX1(0.5);
5322 buchmann 1.48 lg->SetY1(0.7);
5323 buchmann 1.47 lg->AddEntry(metright,"JZB>0 (OSOF corrected)","P");
5324     lg->AddEntry(metleft,"JZB<0 (OSOF corrected)","L");
5325 buchmann 1.48 lg->SetHeader("DY");
5326    
5327 buchmann 1.47 lg->Draw();
5328 buchmann 1.79 Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5329 buchmann 1.48
5330     TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5331     metpad3->cd();
5332     metpad3->SetLogy(1);
5333     Bpred->SetLineColor(kRed);
5334     Bpred->Draw("histo");
5335     obs->SetLineColor(kBlack);
5336     obs->Draw("same");
5337     TLegend *lg2 = make_legend();
5338     lg2->SetX1(0.5);
5339     lg2->SetY1(0.7);
5340     lg2->AddEntry(obs,"observed","P");
5341     lg2->AddEntry(Bpred,"predicted","L");
5342     lg2->SetHeader("DY");
5343    
5344     lg2->Draw();
5345    
5346 buchmann 1.79 Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5347 buchmann 1.48
5348 buchmann 1.47 TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5349 buchmann 1.48 metpad2->cd();
5350     metpad2->SetLogy(1);
5351 buchmann 1.47
5352 buchmann 1.89 TH1F *metlefta = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5353     TH1F *metleftOa = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5354     TH1F *metrighta = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5355     TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5356 buchmann 1.47
5357     metlefta->Add(metleftOa,-1);
5358     metrighta->Add(metrightOa,-1);
5359    
5360     metlefta->SetLineColor(kRed);
5361     metpad2->cd();
5362     metlefta->Draw("histo");
5363     metrighta->Draw("same");
5364     lg->Draw();
5365 buchmann 1.79 Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5366 buchmann 1.47
5367 buchmann 1.48 delete Bpred;
5368     delete obs;
5369    
5370     float newhigh=300;
5371     int newNBins=30;
5372    
5373     TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5374 buchmann 1.89 TH1F *Ametleft = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5375     TH1F *AmetleftO = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5376     TH1F *Ametright = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5377     TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5378 buchmann 1.48
5379     TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5380     aBpred->Add(AmetleftO,-1);
5381     aBpred->Add(AmetrightO);
5382     aBpred->SetLineColor(kRed);
5383    
5384     TH1F *aobs = (TH1F*)Ametright->Clone("aobs");
5385     metpad4->cd();
5386     metpad4->SetLogy(1);
5387     aobs->Draw();
5388     aBpred->Draw("histo,same");
5389     aobs->Draw("same");
5390     lg->SetHeader("All MC");
5391     lg->Draw();
5392 buchmann 1.79 Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5393 buchmann 1.48
5394 buchmann 1.47
5395     delete lg;
5396     delete canmetjzb;
5397     delete metleft;
5398     delete metleftO;
5399     delete metright;
5400     delete metrightO;
5401 buchmann 1.9 }
5402 buchmann 1.88
5403    
5404     void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5405    
5406     if(PlottingSetup::RestrictToMassPeak) {
5407     write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5408     assert(!PlottingSetup::RestrictToMassPeak);
5409     }
5410    
5411     vector<float> binning;
5412    
5413     binning.push_back(-200);
5414     binning.push_back(-150);
5415     binning.push_back(-125);
5416     binning.push_back(-100);
5417     binning.push_back(-75);
5418     binning.push_back(-50);
5419     binning.push_back(-25);
5420     binning.push_back(0);
5421     binning.push_back(25);
5422     binning.push_back(50);
5423     binning.push_back(75);
5424     binning.push_back(100);
5425     binning.push_back(125);
5426     binning.push_back(150);
5427     binning.push_back(200);
5428    
5429     switch_overunderflow(true);
5430    
5431     TH1F *TZem = allsamples.Draw("TZem", mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5432     TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5433     TH1F *TZeemm = allsamples.Draw("TZeemm", mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5434     TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5435    
5436     TCanvas *tcan = new TCanvas("tcan","tcan");
5437     tcan->SetLogy(1);
5438    
5439     TZeemm->SetLineColor(kBlack);
5440     TZem->SetLineColor(kRed);
5441     TZeemm->SetMarkerColor(kBlack);
5442     TZem->SetMarkerColor(kRed);
5443    
5444     vector<TH1F*> histos;
5445     // TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5446     // TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5447     histos.push_back(TZem);
5448     histos.push_back(TZeemm);
5449     draw_all_ttbar_histos(tcan,histos,"histo",8);
5450    
5451     TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5452     leg->AddEntry(TZeemm,"SFZP","l");
5453     leg->AddEntry(TZem,"OFZP","l");
5454     leg->Draw("same");
5455     DrawMCPrelim();
5456     CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5457    
5458     TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5459     TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5460     TH1F *TSeemmcopy;
5461     TH1F *TSemcopy;
5462    
5463     predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5464     observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5465    
5466     vector<float> posbinning;
5467     for(unsigned int i=0;i<binning.size();i++) {
5468     if(binning[i]<0) continue;
5469     posbinning.push_back(binning[i]);
5470     }
5471    
5472     TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5473     TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5474    
5475     for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5476     int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5477     if(TZem->GetBinCenter(i)<0) {
5478     //we're on the left: subtract em!
5479     pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5480     pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5481     //we're on the left: add eemm!
5482     pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5483     pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5484     } else {
5485     //we're on the right: add em!
5486     pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5487     pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5488     //we're on the left: add eemm!
5489     obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5490     obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5491     }
5492     }
5493    
5494     ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5495     ratio2->Divide(obs2);
5496    
5497     TZem->Divide(TZeemm);
5498     TZem->SetMarkerStyle(21);
5499    
5500     TZem->SetTitle("OF / SF");
5501     ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5502    
5503     tcan->SetLogy(0);
5504     TZem->GetYaxis()->SetRangeUser(0,2.5);
5505     TZem->GetYaxis()->SetTitle("ratio");
5506     TZem->Draw();
5507    
5508     float linepos=emuncertOFFPEAK;
5509    
5510     TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5511     TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5512     TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5513    
5514     top->SetLineColor(kBlue);top->SetLineStyle(2);
5515     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5516     center->SetLineColor(kBlue);
5517    
5518     top->Draw("same");
5519     center->Draw("same");
5520     bottom->Draw("same");
5521    
5522     TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
5523     leg2->AddEntry(TZem,"OFZP / SFZP","ple");
5524     leg2->AddEntry(bottom,"syst. envelope","l");
5525     leg2->SetX1(0.25);leg2->SetX2(0.6);
5526     leg2->SetY1(0.65);
5527    
5528     leg2->Draw("same");
5529    
5530     DrawMCPrelim();
5531     CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
5532    
5533     ratio2->SetLineColor(TZem->GetLineColor());
5534     ratio2->SetMarkerColor(TZem->GetMarkerColor());
5535     ratio2->GetYaxis()->SetRangeUser(0,2.5);
5536     ratio2->GetYaxis()->SetTitle("ratio");
5537     ratio2->Draw();
5538    
5539     TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
5540     TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
5541     TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
5542    
5543     top2->SetLineColor(kBlue);top->SetLineStyle(2);
5544     bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
5545     center2->SetLineColor(kBlue);
5546    
5547     top2->Draw("same");
5548     center2->Draw("same");
5549     bottom2->Draw("same");
5550    
5551     leg2->Draw("same");
5552    
5553     DrawMCPrelim();
5554     CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
5555    
5556     delete TZem;
5557     delete nTZem;
5558     delete TZeemm;
5559     delete nTZeemm;
5560     delete obs2;
5561     delete pred2;
5562     delete tcan;
5563     switch_overunderflow(false);
5564     }
5565    
5566     void IllustrateVariation(TH1F *vanilla_ratio, TH1F *response_only_up_ratio, TH1F *response_only_down_ratio, TH1F *reponse_plus_peak_up_ratio, TH1F *reponse_plus_peak_down_ratio, string PostString) {
5567    
5568    
5569     TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
5570 buchmann 1.93 vanilla_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
5571 buchmann 1.88 vanilla_ratio->SetFillColor(kGreen);
5572     vanilla_ratio->SetLineColor(kGreen);
5573     vanilla_ratio->SetMarkerColor(kGreen);
5574     vanilla_ratio->SetFillStyle(3001);
5575     vanilla_ratio->Draw("e3");
5576    
5577     response_only_up_ratio->SetFillColor(kRed);
5578     response_only_up_ratio->SetMarkerColor(kRed);
5579     response_only_up_ratio->SetLineColor(kRed);
5580     response_only_up_ratio->SetFillStyle(3003);
5581     response_only_up_ratio->Draw("e3,same");
5582    
5583     response_only_down_ratio->SetFillColor(kOrange);
5584     response_only_down_ratio->SetMarkerColor(kOrange);
5585     response_only_down_ratio->SetLineColor(kOrange);
5586     response_only_down_ratio->SetFillStyle(3004);
5587     response_only_down_ratio->Draw("e3,same");
5588    
5589     reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
5590     reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
5591     reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
5592     reponse_plus_peak_up_ratio->SetFillStyle(3005);
5593     reponse_plus_peak_up_ratio->Draw("e3,same");
5594    
5595     reponse_plus_peak_down_ratio->SetFillColor(kBlue);
5596     reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
5597     reponse_plus_peak_down_ratio->SetLineColor(kBlue);
5598     reponse_plus_peak_down_ratio->SetFillStyle(3006);
5599     reponse_plus_peak_down_ratio->Draw("e3,same");
5600    
5601     TLine *llow = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-emuncertOFFPEAK);
5602     TLine *lhi = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+emuncertOFFPEAK);
5603     TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
5604    
5605     TLine *llowA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-0.07);
5606     TLine *lhiA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+0.07);
5607    
5608     lhiA->SetLineColor(kRed);
5609     lhiA->SetLineStyle(2);
5610     llowA->SetLineColor(kRed);
5611     llowA->SetLineStyle(2);
5612    
5613     llow->SetLineColor(kBlue);
5614     llow->SetLineStyle(2);
5615     lhi->SetLineColor(kBlue);
5616     lhi->SetLineStyle(2);
5617     lOne->SetLineColor(kBlue);
5618    
5619     llow->Draw();
5620     lhi->Draw();
5621     lOne->Draw();
5622    
5623     llowA->Draw();
5624     lhiA->Draw();
5625    
5626     TLegend *leg = make_legend();
5627     leg->SetX1(0.15);
5628     leg->SetY1(0.7);
5629     leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
5630     leg->AddEntry(response_only_up_ratio,"With response correction","pf");
5631     leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5632     leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5633     leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5634     leg->AddEntry(lhi,"Systematic envelope","l");
5635     // leg->SetNColumns(2);
5636     leg->Draw();
5637    
5638     CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
5639    
5640     vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5641     vanilla_ratio->Draw("e3");
5642     response_only_up_ratio->Draw("e3 same");
5643     response_only_down_ratio->Draw("e3 same");
5644     TLegend *leg2 = make_legend();
5645     leg2->SetX1(0.15);
5646     leg2->SetY1(0.7);
5647     leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
5648     leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
5649     leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5650     leg2->AddEntry(lhi,"Systematic envelope","l");
5651     leg2->Draw();
5652     llow->Draw();
5653     lOne->Draw();
5654     llowA->Draw();
5655     lhiA->Draw();
5656    
5657     CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
5658    
5659     response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5660     response_only_up_ratio->Draw("e3");
5661     reponse_plus_peak_up_ratio->Draw("e3 same");
5662     reponse_plus_peak_down_ratio->Draw("e3 same");
5663     TLegend *leg3 = make_legend();
5664     leg3->SetX1(0.15);
5665     leg3->SetY1(0.7);
5666     leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
5667     leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5668     leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5669     leg3->AddEntry(lhi,"Systematic envelope","l");
5670     leg3->Draw();
5671     llow->Draw();
5672     lOne->Draw();
5673     llowA->Draw();
5674     lhiA->Draw();
5675    
5676     CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
5677    
5678     delete ttcan2;
5679     }
5680    
5681     void ttbar_correction_tests() {
5682     TCanvas *ttcan = new TCanvas("ttcan","ttcan");
5683    
5684     TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
5685    
5686     TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
5687    
5688     TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
5689    
5690     TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
5691    
5692     string vanilla="jzb[1]";
5693     string response_only_up="((jzb[1]+0.034665*pt))";
5694     string response_only_down="((jzb[1]-0.034665*pt))";
5695     string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
5696     string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
5697    
5698     do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
5699     do_one_ttbar_test(response_only_up_observed,response_only_up_predicted,response_only_up_ratio,response_only_up_ratio2,response_only_up,"response_only_up");
5700     do_one_ttbar_test(response_only_down_observed,response_only_down_predicted,response_only_down_ratio,response_only_down_ratio2,response_only_down,"response_only_down");
5701     do_one_ttbar_test(reponse_plus_peak_up_observed,reponse_plus_peak_up_predicted,reponse_plus_peak_up_ratio,reponse_plus_peak_up_ratio2,reponse_plus_peak_up,"reponse_plus_peak_up");
5702     do_one_ttbar_test(reponse_plus_peak_down_observed,reponse_plus_peak_down_predicted,reponse_plus_peak_down_ratio,reponse_plus_peak_down_ratio2,reponse_plus_peak_down,"reponse_plus_peak_down");
5703    
5704     ttcan->cd();
5705    
5706     IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
5707     IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
5708    
5709     delete vanilla_observed;
5710     delete response_only_up_observed;
5711     delete response_only_down_observed;
5712     delete reponse_plus_peak_up_observed;
5713     delete reponse_plus_peak_down_observed;
5714    
5715     delete vanilla_predicted;
5716     delete response_only_up_predicted;
5717     delete response_only_down_predicted;
5718     delete reponse_plus_peak_up_predicted;
5719     delete reponse_plus_peak_down_predicted;
5720    
5721     delete vanilla_ratio;
5722     delete response_only_up_ratio;
5723     delete response_only_down_ratio;
5724     delete reponse_plus_peak_up_ratio;
5725     delete reponse_plus_peak_down_ratio;
5726    
5727     delete ttcan;
5728     }
5729    
5730     void ttbar_region_search(string mcjzb) {
5731     cout << "Looking for a nice control region" << endl;
5732     TCanvas *can = new TCanvas("can","can",1200,1200);
5733     can->Divide(2,2);
5734     can->cd(1);
5735     can->cd(1)->SetLogy(1);
5736    
5737     THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5738     THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5739    
5740     JZBdistSF.Draw("histo");
5741     JZBdistSF.SetMaximum(1000);
5742     JZBdistSF.SetMinimum(0.1);
5743     JZBdistSF.Draw("histo");
5744     DrawMCPrelim();
5745    
5746     can->cd(2);
5747     can->cd(2)->SetLogy(1);
5748     JZBdistOF.Draw("histo");
5749     JZBdistOF.SetMaximum(1000);
5750     JZBdistOF.SetMinimum(0.1);
5751     JZBdistOF.Draw("histo");
5752     DrawMCPrelim();
5753    
5754     can->cd(3);
5755    
5756    
5757     write_warning(__FUNCTION__,"Missing negative JZB subtraction ");
5758    
5759     DrawMCPrelim();
5760    
5761     /*
5762     THStack *Subtracted = new THStack();
5763    
5764     TIter nextSF(JZBdistSF.GetHists());
5765     TIter nextOF(JZBdistOF.GetHists());
5766     TObject* SFobj;
5767     TObject* OFobj;
5768    
5769     TH1* sfh = NULL;
5770     TH1* ofh = NULL;
5771    
5772     while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
5773     TH1F *sfstart = (TH1*)SFobj->Clone();
5774     TH1F *ofstart = (TH1*)OFobj->Clone();
5775     TH1F *obs, *pred;
5776     MakeObservationPrediction(obs,pred,sfstart,ofstart);
5777    
5778     if ( !hratio ) {
5779     hratio = (TH1*)obj->Clone();
5780     hratio->SetName("hratio");
5781     } else hratio->Add( (TH1*)obj );
5782 buchmann 1.9
5783 buchmann 1.88 }
5784     hratio->Divide(hdata);
5785     */
5786    
5787    
5788     can->cd(4);
5789     JZBdistOF.Draw("histo");
5790     DrawMCPrelim();
5791    
5792    
5793    
5794     CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
5795    
5796     CleanLegends();
5797     delete can;
5798     }
5799    
5800     void ttbar_tests(string mcjzb) {
5801     //ttbar_correction_tests();
5802     ttbar_region_search(mcjzb);
5803     }
5804 buchmann 1.9
5805 buchmann 1.93 Value GetYieldBetween(TH1F *h, float low, float high) {
5806     float Yield=0;
5807     float YieldErr=0;
5808     for(int i=1;i<=h->GetNbinsX()+1;i++) {
5809     if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
5810     if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
5811     Yield+=h->GetBinContent(i);
5812     YieldErr=sqrt(YieldErr*YieldErr+h->GetBinError(i)*h->GetBinError(i));
5813     }
5814    
5815     Value a(Yield,YieldErr);
5816     return a;
5817     }
5818    
5819    
5820     void make_SF_over_OF_plot(string datajzb, string mcjzb, TCut cut, string variable, int nbins, float xmin, float ymin, string varname, string filename) {
5821     TCanvas *SFoOF_can = new TCanvas("SFoOF_can","SFoOF_can");
5822     TH1F *data_sf = allsamples.Draw("data_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,data,luminosity);
5823     TH1F *data_of = allsamples.Draw("data_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,data,luminosity);
5824    
5825     TH1F *mc_sf = allsamples.Draw("mc_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity);
5826     TH1F *mc_of = allsamples.Draw("mc_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity);
5827    
5828     TH1F *mc_ratio = (TH1F*)mc_sf->Clone("mc_ratio");
5829     mc_ratio->Divide(mc_of);
5830    
5831     TH1F *data_ratio = (TH1F*)data_sf->Clone("data_ratio");
5832     data_ratio->Divide(data_of);
5833    
5834     mc_ratio->SetFillColor(TColor::GetColor("#00ADE1"));
5835     mc_ratio->SetMarkerColor(TColor::GetColor("#00ADE1"));
5836     mc_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
5837    
5838     mc_ratio->GetYaxis()->SetTitle("R(SF / OF)");
5839    
5840    
5841     Value R_sf_of_low_mass = GetYieldBetween(data_sf,20,70)/GetYieldBetween(data_of,20,70);
5842     Value R_sf_of_high_mass = GetYieldBetween(data_sf,120,200)/GetYieldBetween(data_of,120,200);
5843    
5844     Value R_sf_of_low_mass_mc = GetYieldBetween(mc_sf,20,70)/GetYieldBetween(mc_of,20,70);
5845     Value R_sf_of_high_mass_mc = GetYieldBetween(mc_sf,120,200)/GetYieldBetween(mc_of,120,200);
5846    
5847     dout << "Ratio at low mass : " << R_sf_of_low_mass << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
5848     dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
5849    
5850     TGraphAsymmErrors *gra = produce_ratio_graph(mc_ratio);
5851     gra->Draw();
5852     mc_ratio->Draw();
5853     gra->Draw("e20");
5854     gra->SetFillColor(TColor::GetColor("#00ADE1"));
5855     gra->SetMarkerColor(TColor::GetColor("#00ADE1"));
5856     data_ratio->Draw("e1,same");
5857    
5858     TLegend *leg = new TLegend(0.17,0.16,0.53,0.31);
5859     // leg->SetHeader("R( SF / OF )");
5860     leg->SetFillColor(kWhite);
5861     leg->SetBorderSize(0);
5862     leg->AddEntry(data_ratio,"Data","p");
5863     leg->AddEntry(gra,"MC","fp");
5864     leg->Draw();
5865    
5866     TLine *g = new TLine(0,R_sf_of_low_mass.getValue(),200,R_sf_of_low_mass.getValue());
5867     g->SetLineColor(kBlue);
5868     g->Draw();
5869    
5870     TLine *l = new TLine(70,0.5,70,1.5);
5871     l->SetLineStyle(2);
5872     l->SetLineColor(TColor::GetColor("#00ADE1"));
5873     TLine *m = new TLine(70,0.5,70,1.5);
5874     m->SetLineStyle(2);
5875     m->SetLineColor(TColor::GetColor("#00ADE1"));
5876     l->Draw();
5877     m->Draw();
5878    
5879    
5880     DrawPrelim();
5881    
5882     CompleteSave(SFoOF_can,"iTTbar/"+filename+"SF_vs_OF");
5883    
5884     delete leg;
5885     delete mc_sf;
5886     delete mc_of;
5887     delete mc_ratio;
5888     delete data_sf;
5889     delete data_of;
5890     delete data_ratio;
5891     delete SFoOF_can;
5892     }
5893    
5894     void make_iTTbar_JZB_plot(string datajzb, string mcjzb, TCut cut) {
5895     TCanvas *can = new TCanvas("can","can");
5896     vector<float> binning;
5897     binning.push_back(-100);
5898     binning.push_back(-50);
5899     binning.push_back(-20);
5900     binning.push_back(0);
5901     // binning.push_back(10);
5902     binning.push_back(20);
5903     // binning.push_back(30);
5904     binning.push_back(50);
5905     binning.push_back(100);
5906     binning.push_back(300);
5907    
5908     TH1F *hdata = allsamples.Draw("hdata", datajzb, binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
5909     TH1F *hodata = allsamples.Draw("hodata", datajzb, binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
5910     TH1F *hndata = allsamples.Draw("hndata", "-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
5911     TH1F *hnodata = allsamples.Draw("hnodata","-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
5912    
5913     TH1F *hmc = allsamples.Draw("hmc", datajzb, binning, "JZB [GeV]", "events", cut&&cutOSSF,mc,luminosity);
5914     TH1F *homc = allsamples.Draw("homc", datajzb, binning, "JZB [GeV]", "events", cut&&cutOSOF,mc,luminosity);
5915    
5916     hodata->SetLineColor(kRed);
5917     hmc->SetLineColor(kRed);
5918     // hodata->Add(hndata);
5919     // hodata->Add(hnodata,-1);
5920    
5921     if(hdata->GetMaximum()>hodata->GetMaximum()) {
5922     hdata->SetMinimum(1.0);
5923     hdata->Draw();
5924     hodata->Draw("histo,same");
5925     hdata->Draw("same");
5926     } else {
5927     hodata->SetMinimum(1.0);
5928     hodata->Draw("histo");
5929     hdata->Draw("same");
5930     }
5931    
5932     CompleteSave(can,"iTTbar/JZB_plot");
5933     TH1F *ratio = (TH1F*)hdata->Clone("ratio");
5934     ratio->Divide(hodata);
5935     ratio->GetYaxis()->SetTitle("obs/pred");
5936     ratio->GetYaxis()->SetRangeUser(0,2);
5937    
5938     ratio->Draw();
5939     TLine *l = new TLine(-100,1.0,300,1.0);
5940     l->SetLineColor(kBlue);
5941     l->SetLineStyle(2);
5942     l->Draw();
5943     TLine *llow = new TLine(-100,1.0-0.07,300,1.0-0.07);
5944     TLine *lhi = new TLine(-100,1.0+0.07,300,1.0+0.07);
5945     llow->SetLineColor(kBlue);
5946     llow->SetLineStyle(2);
5947     llow->Draw();
5948     lhi->SetLineColor(kBlue);
5949     lhi->SetLineStyle(2);
5950     lhi->Draw();
5951    
5952     CompleteSave(can,"iTTbar/JZB_plot_ratio");
5953    
5954     delete hdata;
5955     delete hodata;
5956     delete ratio;
5957     delete can;
5958     // THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity));
5959     // THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity));
5960     }
5961    
5962     void make_ijzb_ttbar_closure_test(string datajzb, string mcjzb) {
5963     TCut tt_nJets("pfJetGoodNum40==2");
5964     TCut tt_bJet("pfJetGoodNumBtag40==2");
5965     TCut tt_noZ("(mll>20 && mll<70)||(mll>120&&mll<200)");
5966    
5967    
5968     make_iTTbar_JZB_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ);
5969    
5970     TCanvas *can = new TCanvas("can","can");
5971    
5972     TH1F *hdata = allsamples.Draw("hdata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,data,luminosity);
5973     TH1F *hodata = allsamples.Draw("hodata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,data,luminosity);
5974     THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,mc,luminosity));
5975     THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,mc,luminosity));
5976    
5977     TH1F *coll_hmc = CollapseStack(hmc);
5978     TH1F *coll_homc = CollapseStack(homc);
5979    
5980     bool dolog=true;
5981     bool nolog=false;
5982    
5983     dout << "Data : " << hdata->Integral() << endl;
5984     dout << " SF: " << endl;
5985     WriteYield(hmc, 0, 10000);
5986     dout << " OF: " << endl;
5987     WriteYield(homc, 0, 10000);
5988     hodata->SetLineColor(kRed);
5989     hdata->Draw();
5990     hmc->Draw("histo,same");
5991     hodata->Draw("histo,same");
5992     hdata->Draw("e1,same");
5993     DrawPrelim();
5994     CompleteSave(can,"TestingPrediction");
5995    
5996     dout << "We get an expected ratio of " << coll_hmc->Integral()/coll_homc->Integral() << endl;
5997     dout << "In data we find " << hdata->Integral()/hodata->Integral() << endl;
5998    
5999     Value R_sf_of_low_mass = GetYieldBetween(hdata,20,70)/GetYieldBetween(hodata,20,70);
6000     Value R_sf_of_high_mass = GetYieldBetween(hdata,120,200)/GetYieldBetween(hodata,120,200);
6001    
6002     Value R_sf_of_low_mass_mc = GetYieldBetween(coll_hmc,20,70)/GetYieldBetween(coll_homc,20,70);
6003     Value R_sf_of_high_mass_mc = GetYieldBetween(coll_hmc,120,200)/GetYieldBetween(coll_homc,120,200);
6004    
6005     dout << "Ratio at low mass : " << R_sf_of_low_mass << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6006     dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6007    
6008     dout << "Composition at low mass : " << endl;
6009     dout << "Same flavor: " << endl;
6010     ProduceYields(20, 70, hdata, hmc);
6011     dout << "Opposite flavor: " << endl;
6012     ProduceYields(20, 70, hodata, homc);
6013    
6014     dout << endl << endl;
6015    
6016     dout << "Composition at high mass : " << endl;
6017     dout << "Same flavor: " << endl;
6018     ProduceYields(120, 200, hdata, hmc);
6019     dout << "Opposite flavor: " << endl;
6020     ProduceYields(120, 200, hodata, homc);
6021    
6022    
6023    
6024    
6025     make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),20,-200,200,dolog,"JZB","iTTbar/JZB_SF",false,true);
6026     make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),20,-200,200,dolog,"JZB","iTTbar/JZB_OF",false,true);
6027    
6028     make_plain_kin_plot("mll",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),40,0,200,nolog,"m_{ll} [GeV]","iTTbar/mll_SF",false,true);
6029     make_plain_kin_plot("mll",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),40,0,200,nolog,"m_{ll} [GeV]","iTTbar/mll_OF",false,true);
6030    
6031     make_SF_over_OF_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ,"mll",20,0,200,"m_{ll} [GeV]","mll");
6032    
6033     // make_plain_kin_plot("pfJetGoodNum40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),10,-0.5,9.5,dolog,"n_{jets}","iTTbar/nJets_SF",false,true);
6034     // make_plain_kin_plot("pfJetGoodNum40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),10,-0.5,9.5,dolog,"n_{jets}","iTTbar/nJets_OF",false,true);
6035     //
6036     // make_plain_kin_plot("pfJetGoodNumBtag40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),10,-0.5,9.5,dolog,"n_{btags}","iTTbar/nBtags_SF",false,true);
6037     // make_plain_kin_plot("pfJetGoodNumBtag40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),10,-0.5,9.5,dolog,"n_{btags}","iTTbar/nBtags_OF",false,true);
6038    
6039    
6040     delete coll_hmc;
6041     delete coll_homc;
6042     delete hmc;
6043     delete homc;
6044     delete hdata;
6045     delete hodata;
6046     delete can;
6047     }
6048    
6049    
6050 buchmann 1.1 void test() {
6051    
6052 buchmann 1.92
6053     float MCPeak, MCPeakError, DataPeak, DataPeakError;
6054     stringstream result, datajzb, mcjzb;
6055     bool doPUreweighting=true;
6056     bool SwitchOffNJetsCut=false;
6057    
6058    
6059     TCanvas *can = new TCanvas("can","can");
6060     float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
6061    
6062     float NumVtxBin[6] = {0,5,10,15,20,30};
6063    
6064     stringstream NowCut;
6065    
6066     TGraphErrors *gMCPeak = new TGraphErrors();
6067     gMCPeak->SetTitle("gMCPeak");
6068     gMCPeak->SetName("gMCPeak");
6069     TGraphErrors *gDataPeak = new TGraphErrors();
6070     gDataPeak->SetTitle("gDataPeak");
6071     gDataPeak->SetName("gDataPeak");
6072     TGraphErrors *gMCWidth = new TGraphErrors();
6073     gMCWidth->SetTitle("gMCWidth");
6074     gMCWidth->SetName("gMCWidth");
6075     TGraphErrors *gDataWidth = new TGraphErrors();
6076     gDataWidth->SetTitle("gDataWidth");
6077     gDataWidth->SetName("gDataWidth");
6078    
6079     float AllMCPeaks[200];
6080     float AllMCPeaksErrors[200];
6081    
6082     for(int i=10;i<180;i+=20) {
6083     NowCut.str("");
6084     NowCut << "mll>=" << i << "&&mll<" << i+20;
6085     find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
6086     AllMCPeaks[i]=MCPeak;
6087     AllMCPeaksErrors[i]=MCPeakError;
6088     }
6089    
6090     dout << "Summary : " << endl;
6091     for(int i=10;i<180;i+=20) {
6092     dout << "For the slice at [" << i << " , " << i+20 << "] we get a peak at " << AllMCPeaks[i] << " +/- " << AllMCPeaksErrors[i] << endl;
6093     }
6094     /*
6095 buchmann 1.1 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
6096     testcanv->cd();
6097 buchmann 1.33 // switch_overunderflow(true);
6098 buchmann 1.91 TH1F *histo1 = new TH1F("histo","histo",100,0,1);
6099     histo1->Sumw2();
6100     TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
6101     histo2->Sumw2();
6102    
6103     for(int i=0;i<100;i++) {
6104     histo1->Fill(1.0/i,i);
6105     histo2->Fill(1.0/(i*i),i);
6106     }
6107    
6108     histo1->Draw();
6109     histo2->Draw("e1,same");
6110    
6111     Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
6112    
6113    
6114 buchmann 1.1 dout << "HELLO there!" << endl;
6115 buchmann 1.92 */
6116 buchmann 1.1 }