ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.90
Committed: Fri Apr 12 12:30:48 2013 UTC (12 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.89: +8 -7 lines
Log Message:
Added several nice variables for the signal region, such as tilde{S}_{T}, M_{T2} and JZB

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