ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C (file contents):
Revision 1.56 by buchmann, Wed Sep 5 20:16:25 2012 UTC vs.
Revision 1.97 by buchmann, Thu May 30 07:59:33 2013 UTC

# Line 15 | Line 15
15   #include <TSQLResult.h>
16   #include <TProfile.h>
17   #include <TLegendEntry.h>
18 + #include "TMath.h"
19 + #include "Math/DistFunc.h"
20  
21   using namespace std;
22  
# Line 32 | Line 34 | void todo() {
34   }  
35  
36  
37 + namespace PeakLibrary {
38 +  bool StoreHistos=false;
39 +  vector<TH1F*> DataHistogram;
40 +  vector<TH1F*> MCHistogram;
41 + }
42 +
43  
44 < void find_one_peak_combination(TCut specialcut, float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &MCSigmaError, float &DataSigma, float& DataSigmaError, stringstream &result, bool doPUreweighting = true, string saveas="")
44 > 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="")
45   {
46    // Temporarily switch off PU reweighting, if asked
47    TCut weightbackup=cutWeight;
# Line 42 | Line 50 | void find_one_peak_combination(TCut spec
50    int nbins=100;
51    if(PlottingSetup::DoBTag) nbins=25;
52    
53 +  TCut nJetsCut(cutnJets);
54 +  if(SwitchOffNJetsCut) nJetsCut=specialcut;
55 +  
56 +  
57    TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
58 <  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,mc, luminosity);
59 <  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,data, luminosity);
60 <  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,mc, luminosity);
61 <  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,data, luminosity);
58 >  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,mc, luminosity);
59 >  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,data, luminosity);
60 >  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&nJetsCut&&specialcut,mc, luminosity);
61 >  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&nJetsCut&&specialcut,data, luminosity);
62    TH1F *rawttbarjzbeemmMC;
63  
64    if(method==doKM) {
65      //we only need this histo for the KM fitting...
66 <    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,nbins, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&specialcut,mc,luminosity,allsamples.FindSample("TTJet"));
66 >    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,nbins, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&nJetsCut&&specialcut,mc,luminosity,allsamples.FindSample("TTJet"));
67      MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,MCSigmaError,method,saveas);
68      DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,DataSigmaError,method,saveas);
69      delete rawttbarjzbeemmMC;
# Line 77 | Line 89 | void find_one_peak_combination(TCut spec
89    result << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
90    dout   << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
91    result << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
92 <  delete rawJZBeemmData;
93 <  delete rawJZBeemmMC;
92 >  
93 >  if(!PeakLibrary::StoreHistos) {
94 >    delete rawJZBeemmData;
95 >    delete rawJZBeemmMC;
96 >  } else {
97 >    rawJZBeemmMC->SetName(GetNumericHistoName().c_str());
98 >    rawJZBeemmData->SetName(GetNumericHistoName().c_str());
99 >    rawJZBeemmMC->Add(rawJZBemMC,-1);
100 >    rawJZBeemmData->Add(rawJZBemData,-1);
101 >    PeakLibrary::DataHistogram.push_back(rawJZBeemmData);
102 >    PeakLibrary::MCHistogram.push_back(rawJZBeemmMC);
103 >  }
104 >  
105 >
106 >  
107    delete rawJZBemData;
108    delete rawJZBemMC;
109    delete tempcan;
110   }
111  
112 < void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb)
112 > void Old_FindPeakPileUpCorrection() {
113 >  bool StoreResultsInSeparateFile=false;
114 >  PeakLibrary::StoreHistos=true;
115 >  
116 >  
117 >  dout << "Finding peak position as a function of PU" << endl;
118 >  float MCPeak, MCPeakError, DataPeak, DataPeakError;
119 >  stringstream result, datajzb, mcjzb;
120 >  bool doPUreweighting=true;
121 >  bool SwitchOffNJetsCut=false;
122 >  
123 >  
124 >  TCanvas *can = new TCanvas("can","can");
125 >  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
126 >  
127 >  float NumVtxBin[6] = {0,5,10,15,20,30};
128 >  
129 >  stringstream NowCut;
130 >  
131 >  TGraphErrors *gMCPeak = new TGraphErrors();
132 >  gMCPeak->SetTitle("gMCPeak");
133 >  gMCPeak->SetName("gMCPeak");
134 >  TGraphErrors *gDataPeak = new TGraphErrors();
135 >  gDataPeak->SetTitle("gDataPeak");
136 >  gDataPeak->SetName("gDataPeak");
137 >  TGraphErrors *gMCWidth = new TGraphErrors();
138 >  gMCWidth->SetTitle("gMCWidth");
139 >  gMCWidth->SetName("gMCWidth");
140 >  TGraphErrors *gDataWidth = new TGraphErrors();
141 >  gDataWidth->SetTitle("gDataWidth");
142 >  gDataWidth->SetName("gDataWidth");
143 >  
144 >  
145 >  for(int i=0;i<5;i++) {
146 >    NowCut.str("");
147 >    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
148 >    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
149 >    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
150 >    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
151 >    
152 >    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
153 >    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
154 >    
155 >    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
156 >    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
157 >    
158 >    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
159 >    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
160 >    
161 >    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
162 >    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
163 >  }
164 >  
165 >  can->cd();
166 >  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
167 >  gMCPeak->GetYaxis()->SetTitle("Peak position");
168 >  gMCPeak->GetXaxis()->CenterTitle();
169 >  gMCPeak->GetYaxis()->CenterTitle();
170 >  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
171 >  gDataPeak->GetYaxis()->SetTitle("Peak position");
172 >  gDataPeak->GetXaxis()->CenterTitle();
173 >  gDataPeak->GetYaxis()->CenterTitle();
174 >  
175 >  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
176 >  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
177 >  gDataWidth->GetXaxis()->CenterTitle();
178 >  gDataWidth->GetYaxis()->CenterTitle();
179 >  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
180 >  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
181 >  gMCWidth->GetXaxis()->CenterTitle();
182 >  gMCWidth->GetYaxis()->CenterTitle();
183 >  
184 >  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
185 >  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
186 >  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
187 >  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
188 >  
189 >  gMCPeak->Draw("A2");
190 >  DrawMCPrelim();
191 >  CompleteSave(can,"PUStudy/MCPeak");
192 >  can->cd();
193 >  gMCWidth->Draw("A2");
194 >  DrawMCPrelim();
195 >  CompleteSave(can,"PUStudy/MCWidth");
196 >  
197 >  can->cd();
198 >  gDataPeak->Draw("A2");
199 >  
200 >  DrawPrelim();
201 >  CompleteSave(can,"PUStudy/DataPeak");
202 >  can->cd();
203 >  gDataWidth->Draw("A2");
204 >  DrawPrelim();
205 >  CompleteSave(can,"PUStudy/DataWidth");
206 >  
207 >  if(StoreResultsInSeparateFile) {
208 >    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
209 >    gMCPeak->Write();
210 >    gDataPeak->Write();
211 >    gMCWidth->Write();
212 >    gDataWidth->Write();
213 >    PeakFinding->Close();
214 >  }
215 >  
216 >  gDataPeak->Fit("pol1","L");
217 >  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
218 >  gMCPeak->Fit("pol1","L");
219 >  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
220 >  
221 >  
222 >  can->cd();
223 >  gMCPeak->Draw("A2");
224 >  DrawMCPrelim();
225 >  CompleteSave(can,"PUStudy/MCPeak_WithFit");
226 >  can->cd();
227 >  
228 >  can->cd();
229 >  gDataPeak->Draw("A2");
230 >  DrawPrelim();
231 >  CompleteSave(can,"PUStudy/DataPeak_WithFit");
232 >  
233 >  
234 >  
235 >  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
236 >  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
237 >  
238 >  TLegend *leg = make_legend();
239 >  can->cd();
240 >  int j=0;
241 >  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
242 >    PeakLibrary::DataHistogram[i]->Rebin(5);
243 >    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
244 >    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
245 >    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
246 >    stringstream name;
247 >    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
248 >    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
249 >    j++;
250 >  }
251 >  
252 >  leg->Draw();
253 >  DrawPrelim();
254 >  CompleteSave(can,"PUStudy/DataOverview");
255 >  
256 >  TLegend *leg2 = make_legend();
257 >  can->cd();
258 >  j=0;
259 >  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
260 >    PeakLibrary::MCHistogram[i]->Rebin(5);
261 >    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
262 >    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
263 >    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
264 >    stringstream name;
265 >    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
266 >    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
267 >    j++;
268 >  }
269 >  
270 >  leg->Draw();
271 >  DrawPrelim();
272 >  CompleteSave(can,"PUStudy/MCOverview");
273 >  
274 >  delete can;
275 >  PeakLibrary::StoreHistos=false;
276 > }
277 >
278 > void FindPeakPileUpCorrection() {
279 >  bool StoreResultsInSeparateFile=true;
280 >  PeakLibrary::StoreHistos=true;
281 >  
282 >  
283 >  dout << "Finding peak position as a function of PU" << endl;
284 >  float MCPeak, MCPeakError, DataPeak, DataPeakError;
285 >  stringstream result, datajzb, mcjzb;
286 >  bool doPUreweighting=true;
287 >  bool SwitchOffNJetsCut=false;
288 >  
289 >  
290 >  TCanvas *can = new TCanvas("can","can");
291 >  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
292 >  
293 >  const int nbins=11;
294 >  float NumVtxBin[nbins] = {0,7,9,11,13,15,17,19,21,24,50};
295 >  
296 >  stringstream NowCut;
297 >  
298 >
299 >  Double_t mc_peak_x[nbins];
300 >  Double_t mc_peak_y[nbins];
301 >  Double_t mc_peak_dxh[nbins];
302 >  Double_t mc_peak_dxl[nbins];
303 >  Double_t mc_peak_dy[nbins];
304 >  
305 >  Double_t data_peak_x[nbins];
306 >  Double_t data_peak_y[nbins];
307 >  Double_t data_peak_dxh[nbins];
308 >  Double_t data_peak_dxl[nbins];
309 >  Double_t data_peak_dy[nbins];
310 >  
311 >  Double_t mc_width_x[nbins];
312 >  Double_t mc_width_y[nbins];
313 >  Double_t mc_width_dxh[nbins];
314 >  Double_t mc_width_dxl[nbins];
315 >  Double_t mc_width_dy[nbins];
316 >  
317 >  Double_t data_width_x[nbins];
318 >  Double_t data_width_y[nbins];
319 >  Double_t data_width_dxh[nbins];
320 >  Double_t data_width_dxl[nbins];
321 >  Double_t data_width_dy[nbins];
322 >
323 >  for(int i=0;i<nbins-1;i++) {
324 >    NowCut.str("");
325 >    NowCut << "numVtx>" << NumVtxBin[i] << "&&numVtx<=" << NumVtxBin[i+1];
326 >    cout << "NVtx cut is now : " << NowCut.str() << endl;
327 >    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
328 >    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
329 >    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
330 >    
331 >    TH1F *hDataSFNumVtx = allsamples.Draw("hDataSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
332 >    TH1F *hDataOFNumVtx = allsamples.Draw("hDataOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
333 >    TH1F *hMCSFNumVtx = allsamples.Draw("hMCSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
334 >    TH1F *hMCOFNumVtx = allsamples.Draw("hMCOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
335 >    
336 >    hDataSFNumVtx->Add(hDataOFNumVtx,-1);
337 >    hMCSFNumVtx->Add(hMCOFNumVtx,-1);
338 >    
339 >    mc_peak_x[i]=hMCSFNumVtx->GetMean();
340 >    mc_peak_y[i]=MCPeak;
341 >    mc_peak_dy[i]=MCPeakError;
342 >    
343 >    data_peak_x[i]=hDataSFNumVtx->GetMean();
344 >    data_peak_y[i]=DataPeak;
345 >    data_peak_dy[i]=DataPeakError;
346 >    
347 >    mc_width_x[i]=hMCSFNumVtx->GetMean();
348 >    mc_width_y[i]=mcSigma;
349 >    mc_width_dy[i]=mcSigmaError;
350 >    
351 >    data_width_x[i]=hDataSFNumVtx->GetMean();
352 >    data_width_y[i]=dataSigma;
353 >    data_width_dy[i]=dataSigmaError;
354 >    
355 >    delete hDataSFNumVtx;
356 >    delete hDataOFNumVtx;
357 >    delete hMCSFNumVtx;
358 >    delete hMCOFNumVtx;
359 >  }
360 >  
361 >  for(int i=0;i<nbins-1;i++) {
362 >    if(i==0) {
363 >      data_width_dxl[i]=data_width_x[i];
364 >      data_peak_dxl[i]=data_peak_x[i];
365 >      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
366 >      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
367 >      
368 >      mc_width_dxl[i]=mc_width_x[i];
369 >      mc_peak_dxl[i]=mc_peak_x[i];
370 >      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
371 >      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
372 >    } else if(i==nbins-2) {
373 >      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
374 >      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
375 >      data_width_dxh[i]=50-data_width_x[i];
376 >      data_peak_dxh[i]=50-data_peak_x[i];
377 >      
378 >      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
379 >      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
380 >      mc_width_dxh[i]=50-mc_width_x[i];
381 >      mc_peak_dxh[i]=50-mc_peak_x[i];
382 >    } else {
383 >      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
384 >      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
385 >      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
386 >      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
387 >      
388 >      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
389 >      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
390 >      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
391 >      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
392 >    }
393 >  }
394 >  
395 >  TGraphAsymmErrors *gMCPeak = new TGraphAsymmErrors(nbins-1,mc_peak_x,mc_peak_y,mc_peak_dxl,mc_peak_dxh,mc_peak_dy,mc_peak_dy);
396 >  gMCPeak->SetTitle("gMCPeak");
397 >  gMCPeak->SetName("gMCPeak");
398 >  
399 >  TGraphAsymmErrors *gDataPeak = new TGraphAsymmErrors(nbins-1,data_peak_x,data_peak_y,data_peak_dxl,data_peak_dxh,data_peak_dy,data_peak_dy);
400 >  gDataPeak->SetTitle("gDataPeak");
401 >  gDataPeak->SetName("gDataPeak");
402 >  
403 >  TGraphAsymmErrors *gMCWidth = new TGraphAsymmErrors(nbins-1,mc_width_x,mc_width_y,mc_width_dxl,mc_width_dxh,mc_width_dy,mc_width_dy);
404 >  gMCWidth->SetTitle("gMCWidth");
405 >  gMCWidth->SetName("gMCWidth");
406 >  
407 >  TGraphAsymmErrors *gDataWidth = new TGraphAsymmErrors(nbins-1,data_width_x,data_width_y,data_width_dxl,data_width_dxh,data_width_dy,data_width_dy);
408 >  gDataWidth->SetTitle("gDataWidth");
409 >  gDataWidth->SetName("gDataWidth");
410 >  
411 >  can->cd();
412 >  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
413 >  gMCPeak->GetYaxis()->SetTitle("Peak position");
414 >  gMCPeak->GetXaxis()->CenterTitle();
415 >  gMCPeak->GetYaxis()->CenterTitle();
416 >  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
417 >  gDataPeak->GetYaxis()->SetTitle("Peak position");
418 >  gDataPeak->GetXaxis()->CenterTitle();
419 >  gDataPeak->GetYaxis()->CenterTitle();
420 >  
421 >  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
422 >  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
423 >  gDataWidth->GetXaxis()->CenterTitle();
424 >  gDataWidth->GetYaxis()->CenterTitle();
425 >  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
426 >  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
427 >  gMCWidth->GetXaxis()->CenterTitle();
428 >  gMCWidth->GetYaxis()->CenterTitle();
429 >  
430 >  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
431 >  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
432 >  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
433 >  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
434 >  
435 >  gMCPeak->Draw("A2");
436 >  DrawMCPrelim();
437 >  CompleteSave(can,"PUStudy/MCPeak");
438 >  can->cd();
439 >  gMCWidth->Draw("A2");
440 >  DrawMCPrelim();
441 >  CompleteSave(can,"PUStudy/MCWidth");
442 >  
443 >  can->cd();
444 >  gDataPeak->Draw("A2");
445 >  
446 >  DrawPrelim();
447 >  CompleteSave(can,"PUStudy/DataPeak");
448 >  can->cd();
449 >  gDataWidth->Draw("A2");
450 >  DrawPrelim();
451 >  CompleteSave(can,"PUStudy/DataWidth");
452 >  
453 >  if(StoreResultsInSeparateFile) {
454 >    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
455 >    gMCPeak->Write();
456 >    gDataPeak->Write();
457 >    gMCWidth->Write();
458 >    gDataWidth->Write();
459 >    PeakFinding->Close();
460 >  }
461 >  
462 >  gDataPeak->Fit("pol1");
463 >  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
464 >  gMCPeak->Fit("pol1");
465 >  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
466 >  
467 >  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
468 >  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
469 >  
470 >  TLegend *leg = make_legend();
471 >  can->cd();
472 >  int j=0;
473 >  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
474 >    PeakLibrary::DataHistogram[i]->Rebin(5);
475 >    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
476 >    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
477 >    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
478 >    stringstream name;
479 >    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
480 >    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
481 >    j++;
482 >  }
483 >  
484 >  leg->Draw();
485 >  DrawPrelim();
486 >  CompleteSave(can,"PUStudy/DataOverview");
487 >  
488 >  TLegend *leg2 = make_legend();
489 >  can->cd();
490 >  j=0;
491 >  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
492 >    PeakLibrary::MCHistogram[i]->Rebin(5);
493 >    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
494 >    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
495 >    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
496 >    stringstream name;
497 >    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
498 >    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
499 >    j++;
500 >  }
501 >  
502 >  leg->Draw();
503 >  DrawPrelim();
504 >  CompleteSave(can,"PUStudy/MCOverview");
505 >  
506 >  delete can;
507 >  PeakLibrary::StoreHistos=false;
508 > }
509 >
510 >
511 >
512 > void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
513   {
514 +  bool overunderflowstatus=addoverunderflowbins;
515    switch_overunderflow(false);
516 <
516 >  
517 >  TCut SpecialCut("mll>=0");
518 >  if(sSpecialCut!="") SpecialCut=TCut(sSpecialCut.c_str());
519 >  
520    bool DoInvidualeemmPeaks=false;
521    
522    float mcpeak, datapeak;
# Line 102 | Line 531 | void find_peaks(float &MCPeak,float &MCP
531    float mcSigma,mcSigmaError, dataSigma, dataSigmaError;
532    
533    dout << "Finding global peak : " << endl;
534 <  find_one_peak_combination(TCut(""),mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
534 >  find_one_peak_combination(SpecialCut,SwitchOffNJetsCut,mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
535    
536    if(DoInvidualeemmPeaks) {
537      dout << "Finding peak for electrons : " << endl;
538 <    find_one_peak_combination(TCut("id1==0"),mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
538 >    find_one_peak_combination(SpecialCut&&TCut("id1==0"),SwitchOffNJetsCut,mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
539      dout << "Finding peak for muons : " << endl;
540 <    find_one_peak_combination(TCut("id1==1"),mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
540 >    find_one_peak_combination(SpecialCut&&TCut("id1==1"),SwitchOffNJetsCut,mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
541      
542      datajzb << "(" << jzbvariabledata;
543      mcjzb << "(" << jzbvariablemc;
# Line 137 | Line 566 | void find_peaks(float &MCPeak,float &MCP
566      
567    } else {
568      datajzb << "(" << jzbvariabledata;
569 <      mcjzb << "(" << jzbvariablemc;
569 >    mcjzb   << "(" << jzbvariablemc;
570      
571      if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
572      else datajzb << "+ " << TMath::Abs(datapeak) << " ";
# Line 154 | Line 583 | void find_peaks(float &MCPeak,float &MCP
583      MCPeakError=mcpeakerr;
584      DataPeak=datapeak;
585      DataPeakError=datapeakerr;
586 <    
158 <    switch_overunderflow(true);
159 <  
586 >    switch_overunderflow(overunderflowstatus);
587   }
588  
589 < void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
589 > void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth, int MCorData) {
590    float min=70.0;
591    float max=115.0;
592    if(!PlottingSetup::RestrictToMassPeak) {
# Line 168 | Line 595 | void make_special_obs_pred_mll_plot(stri
595    }
596    int nbins=int((max-min)/binWidth);
597    
598 +  string prefix="";
599 +  if(MCorData==mc) prefix="MC__";
600 +  
601 +  
602 +  if(MCorData==mc) datajzb=mcjzb;
603 +  
604    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
605    
606    stringstream largerzeroS;
# Line 183 | Line 616 | void make_special_obs_pred_mll_plot(stri
616    largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
617    TCut largerzeroM(largerzeroMS.str().c_str());
618    
619 <  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
620 <  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
621 <  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
622 <  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
623 <  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
619 >
620 >  stringstream smallerzeroMS;
621 >  smallerzeroMS << "(" << mcjzb << "<-" << jzbthreshold << ")";
622 >  TCut smallerzeroM(smallerzeroMS.str().c_str());
623 >  
624 >  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,MCorData,luminosity);
625 >  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
626 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,MCorData,luminosity);
627 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,MCorData,luminosity);
628 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,MCorData,luminosity);
629  
630    TH1F *RcorrJZBSBem;
631    TH1F *LcorrJZBSBem;
# Line 197 | Line 635 | void make_special_obs_pred_mll_plot(stri
635   //  TH1F *RcorrJZBeemmNoS;
636  
637    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
638 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
639 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
640 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
641 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
638 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,MCorData, luminosity);
639 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,MCorData, luminosity);
640 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,MCorData, luminosity);
641 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,MCorData, luminosity);
642    }
643 <  
644 <  // Separate predictions
643 >
644 >    // Separate predictions
645    TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
646    TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
647    TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
648 +  
649 +  TH1F *BpredSys = (TH1F*)SFN->Clone("BpredSys");
650 +  ClearHisto(BpredSys);
651 +  AddSquared(BpredSys,SFN,pow(PlottingSetup::zjetsestimateuncertOFFPEAK,2));
652 +
653    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
654      OFP->Scale(1.0/3.0);
655      OFP->Add(RcorrJZBSBem,1.0/3.);
# Line 214 | Line 657 | void make_special_obs_pred_mll_plot(stri
657      OFN->Scale(1.0/3.0);
658      OFN->Add(LcorrJZBSBem,1.0/3.);
659      OFN->Add(LcorrJZBSBeemm,1.0/3.);
660 <  }
660 >    AddSquared(BpredSys,RcorrJZBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
661 >    AddSquared(BpredSys,RcorrJZBSBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
662 >    AddSquared(BpredSys,RcorrJZBSBeemm,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
663 >  } else {
664 >    AddSquared(BpredSys,OFN,pow(PlottingSetup::emuncertOFFPEAK,2));  
665 >  }
666  
667 +  SQRT(BpredSys);
668 +  
669 +  TGraphErrors *BpredSysBand = new TGraphErrors();
670 + //  TH1F *BpredSysBand = (TH1F*)BpredSys->Clone("BpredSysBand");
671 +  
672 +  for(int i=1;i<=BpredSys->GetNbinsX();i++) {
673 +    /*BpredSysBand->SetBinError(i,BpredSysBand->GetBinContent(i));
674 +    BpredSysBand->SetBinContent(i,0);*/
675 +    float dx=0.5*BpredSys->GetBinWidth(i);
676 +    float dy=BpredSys->GetBinContent(i);
677 +    BpredSysBand->SetPoint(i-1,BpredSys->GetBinCenter(i),0);
678 +    BpredSysBand->SetPointError(i-1,dx,dy);
679 +  }
680 +  
681 +  delete BpredSys;
682 +  BpredSysBand->SetFillColor(TColor::GetColor("#2E9AFE"));
683 +  
684    TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
685    Bpred->Add(OFP);
686    Bpred->Add(OFN,-1);
# Line 223 | Line 688 | void make_special_obs_pred_mll_plot(stri
688    
689    RcorrJZBeemm->SetTitleOffset(1.3,"y");
690    RcorrJZBeemm->Draw();
691 <  mcRcorrJZBeemm.Draw("same");
691 >  mcRcorrJZBeemm.Draw("histo,same");
692    Bpred->Draw("histo,same");
693    RcorrJZBeemm->Draw("same");
694    
695    TLegend *leg = allsamples.allbglegend();
696    leg->SetX1(0.58);
697 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
697 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
698    leg->AddEntry(Bpred,"predicted (data)","l");
699    leg->Draw("same");
700    
701    stringstream saveas;
702 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
702 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold;
703    CompleteSave(ckin,saveas.str());
704    
705    // Draw all predictions overlayed
# Line 257 | Line 722 | void make_special_obs_pred_mll_plot(stri
722    RcorrJZBeemm->Draw("same");
723    
724    TLegend *leg2 = make_legend("",0.52,0.7);
725 <  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
726 <  leg2->AddEntry(Bpred,"predicted (data)","l");
727 <  leg2->AddEntry(SFN,  "  SF JZB<0","l");
728 <  leg2->AddEntry(OFN,  "  OF JZB<0","l");
729 <  leg2->AddEntry(OFP,  "  OF JZB>0","l");
725 >  if(MCorData==data) {
726 >    leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
727 >    leg2->AddEntry(Bpred,"predicted (data)","l");
728 >  } else {
729 >    leg2->AddEntry(RcorrJZBeemm,"true (MC)","lp");
730 >    leg2->AddEntry(Bpred,"predicted (MC)","l");
731 >  }
732 >
733 >  if(jzbthreshold>0) {
734 >    leg2->AddEntry(SFN,  ("  SF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
735 >    leg2->AddEntry(OFN,  ("  OF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
736 >  } else {
737 >    leg2->AddEntry(SFN,  "  SF JZB<0","l");
738 >    leg2->AddEntry(OFN,  "  OF JZB<0","l");
739 >  }
740 >  leg2->AddEntry(OFP,  ("  OF JZB>"+any2string(jzbthreshold)).c_str(),"l");
741    leg2->Draw("same");
742    
743    saveas.str("");
744 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
744 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc";
745 >  CompleteSave(ckin,saveas.str());
746 >  
747 >  
748 >  TH1F *diff = (TH1F*)RcorrJZBeemm->Clone("diff");
749 >  diff->Add(Bpred,-1);
750 >  
751 >  TLegend *dleg = make_legend();
752 >  if(MCorData==data) dleg->AddEntry(diff,"Obs-predicted","p");
753 >  else dleg->AddEntry(diff,"True-predicted","p");
754 >  dleg->AddEntry(BpredSysBand,"Sys. envelope","f");
755 >  dleg->SetY1(0.7);
756 >  
757 >  
758 >  diff->Draw("e1");
759 >  BpredSysBand->Draw("e2");
760 >  diff->Draw("e1,same");
761 >  dleg->Draw();
762 >  
763 >  if(MCorData==data) DrawPrelim();
764 >  else DrawMCPrelim();
765 >  
766 >  saveas.str("");
767 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc_Diff";
768    CompleteSave(ckin,saveas.str());
769 +
770 +  delete BpredSysBand;
771 +  delete diff;
772    
773    delete RcorrJZBeemm;
774    delete LcorrJZBeemm;
775    delete RcorrJZBem;
776    delete LcorrJZBem;
777 +
778    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
779      delete RcorrJZBSBeemm;
780      delete LcorrJZBSBeemm;
# Line 280 | Line 783 | void make_special_obs_pred_mll_plot(stri
783    }
784    delete Bpred;
785    delete ckin;
786 +  CleanLegends();
787   }
788  
789   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 300 | Line 804 | void make_special_mll_plot(int nbins, fl
804    datahistoOSSF->SetMarkerSize(DataMarkerSize);
805    datahistoOSSF->Draw();
806  
807 <  mcstackOSSF.Draw("same");
807 >  mcstackOSSF.Draw("histo,same");
808    datahistoOSSF->Draw("same");
809  
810    datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
# Line 326 | Line 830 | void make_special_mll_plot(int nbins, fl
830    delete datahistoOSOF;
831    delete datahistoOSSF;
832    delete ckin;
833 +  CleanLegends();
834   }
835    
836  
# Line 367 | Line 872 | void draw_ratio_plot(TH1* hdata, THStack
872   }
873  
874   float make_one_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
875 <                        string xlabel, string filename, bool plotratio=true, bool loadlastminmax=false, float legendPosition=0.55) {
875 >                        string xlabel, string filename, float legendPosition=0.55) {
876  
877    TCut ibasiccut=basiccut;
878    bool draw_separation_lines=false;
# Line 377 | Line 882 | float make_one_OFSF_plot(string variable
882    TCut cutSF;
883    TCut cutOF;
884  
885 +  cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
886    cutOF = cutOSOF&&cutnJets&&ibasiccut;
887    cutSF = cutOSSF&&cutnJets&&ibasiccut;
888 +  
889 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
890  
383  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
891    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
892    rcan->SetLogy(logscale);
893    rcan->cd();
894  
895 +  std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
896    TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
897    TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
898 <  string signal("LM3");
899 <  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
900 <  int idx = signalsamples.FindSample(signal)[0];
901 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
902 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
903 <  signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
904 <  signalhisto->SetLineStyle(2);
898 > //   string signal("LM3");
899 > //   TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
900 > //   int idx = signalsamples.FindSample(signal)[0];
901 > //   (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
902 > //   signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
903 > //   signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
904 > //   signalhisto->SetLineStyle(2);
905    datahistoSF->SetMarkerSize(DataMarkerSize);
906    datahistoOF->SetLineColor(kRed);
907 +  datahistoOF->SetLineWidth(2);
908 +  
909 +  datahistoOF->Scale(1.02); // R(SF/OF)
910  
911    if ( !logscale ) {
912      datahistoSF->SetMinimum(0); // Defaults
# Line 404 | Line 915 | float make_one_OFSF_plot(string variable
915    }
916    if (ymax<0) {
917      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
918 <    else datahistoSF->SetMaximum(1.5*datahistoSF->GetMaximum());
918 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
919    } else {
920      datahistoSF->SetMaximum(ymax);
921    }
# Line 416 | Line 927 | float make_one_OFSF_plot(string variable
927    datahistoSF->GetXaxis()->CenterTitle();
928    datahistoSF->GetYaxis()->CenterTitle();
929  
930 <  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.7,false,legendPosition+0.2);
930 >  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.6,false,legendPosition+0.2);
931    mleg->AddEntry(datahistoSF, "Same-flavor", "PL");
932    if (datahistoOF->Integral()>0) {
933 <    mleg->AddEntry(datahistoOF, "Opposite-flavor", "L");
933 >    mleg->AddEntry(datahistoOF, "OF based estimate", "L");
934    } else {
935      mleg->AddEntry((TObject*)0, "", "");
936    }
937 <  mleg->AddEntry(signalhisto, "LM3", "L");
937 >  //mleg->AddEntry(signalhisto, "LM3", "L");
938  
939    datahistoSF->Draw("E1");
940 +  
941 +  TH1F *syshisto = (TH1F*)datahistoOF->Clone("syshisto");
942 +  TGraphAsymmErrors *datahistoOFboxes = produce_ratio_graph(datahistoOF);
943 +  for(int i=0;i<datahistoOFboxes->GetN();i++) {
944 +    float ex=datahistoOFboxes->GetErrorX(i);
945 +    float ey=datahistoOFboxes->GetErrorY(i);
946 +    double x,y;
947 +    datahistoOFboxes->GetPoint(i,x,y);
948 +    float pey = sqrt(pow(y*0.07,2)+pow(datahistoOF->GetBinError(i+1),2));
949 +    datahistoOFboxes->SetPointError(ex,ex,pey,pey);
950 +    syshisto->SetBinContent(i+1,0.07);
951 +    syshisto->SetBinError(i+1,0.07);
952 +    if(y<0.01) datahistoOF->SetBinContent(i+1,0);
953 +  }
954 +  mleg->AddEntry(datahistoOFboxes,"Total uncert.","F");
955 +  datahistoOFboxes->SetFillColor(TColor::GetColor("#2E9AFE"));
956 +  
957 +  if (datahistoOF->Integral()>0) datahistoOFboxes->Draw("20");
958    if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
959 <  signalhisto->Draw("HIST,SAMES");
959 >  
960 >  datahistoSF->Draw("E1,same");
961 >  
962 >  //signalhisto->Draw("HIST,SAMES");
963    mleg->Draw();
964    DrawPrelim();
965 <  if (datahistoOF->Integral()>0) save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
966 <  else CompleteSave(ckin, "SFOF/" + filename);
965 >  if (datahistoOF->Integral()>0) {
966 > //    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
967 >    save_with_ratio_and_sys_band(0, datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF",syshisto);
968 >  } else {
969 >    CompleteSave(rcan, "SFOF/" + filename);
970 >  }
971  
972    datahistoSF->Delete();
973    datahistoOF->Delete();
974 <  signalhisto->Delete();
974 >  //signalhisto->Delete();
975 >  delete datahistoOFboxes;
976 >  delete syshisto;
977    delete mleg;
978 <  delete ckin;
979 <
978 >  delete rcan;
979 >  delete ofsf_can;
980    return ymaxSet;
443
981   }
982  
983   // Compare data to data
# Line 458 | Line 995 | float make_data_comparison_plot(string v
995  
996    TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
997    TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
998 +  data1->Scale(5.0/9.2);
999  
1000    data1->SetMarkerSize(DataMarkerSize);
1001    data2->SetLineColor(kRed);
# Line 482 | Line 1020 | float make_data_comparison_plot(string v
1020    data1->GetYaxis()->CenterTitle();
1021  
1022    TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
1023 <  mleg->AddEntry(data1, "Old 5/fb", "PL");
1024 <  mleg->AddEntry(data2, "New x/fb", "L");
1023 >  mleg->AddEntry(data1, "2012 data (scaled)", "PL");
1024 >  mleg->AddEntry(data2, "2011 data", "L");
1025  
1026    data1->Draw("E1");
1027    data2->Draw("HIST,SAMES");
1028    mleg->Draw();
1029    DrawPrelim();
1030 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "old/new" );
1030 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
1031  
1032    data1->Delete();
1033    data2->Delete();
1034    delete mleg;
1035 +  delete rcan;
1036    delete ckin;
1037  
1038   }
# Line 501 | Line 1040 | float make_data_comparison_plot(string v
1040   void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
1041                       string xlabel, string filename, float legendPosition=0.55) {
1042  
1043 <  string mllcuts[] = { "mll>20","mll>20&&mll<70", "mll>75&&mll<105", "mll>120" };
1044 <  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "75 < m_{ll} < 105 GeV", "m_{ll} > 120 GeV" };
1043 >  string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
1044 >  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
1045    string plotname[] = {"_all","_low","_peak","_high"};
1046    float ymax;
1047  
# Line 512 | Line 1051 | void make_OFSF_plots(string variable, st
1051    for ( int i=start; i<4; ++i ) {
1052      if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
1053      if ( i==start ) {
1054 <      ymax = make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, -1, logscale, xlabel,
1054 >      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
1055                           filename+plotname[i], legendPosition );
1056      } else {
1057 <      make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1057 >      make_one_OFSF_plot(variable, mllcuts[i],        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1058                           filename+plotname[i], legendPosition );
1059      }
1060      make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
# Line 526 | Line 1065 | void make_OFSF_plots(string variable, st
1065  
1066   }
1067  
1068 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
1069 +  string scut=(string)(const char*)cut;
1070 +  string acut=ReplaceAll(scut,replacethis,withthis);
1071 +  return TCut(acut.c_str());
1072 + }
1073 +
1074 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1075 +  TCut cut=addcut&&basiccut;
1076 +
1077 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1078 +  ckin->SetLogy(dolog);
1079 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
1080 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1081 +  datahisto->SetMarkerSize(DataMarkerSize);
1082 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1083 +  else datahisto->SetMinimum(0.5);
1084 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1085 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1086 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
1087 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1088 +  TH1F *MCcentral = CollapseStack(mcstack);
1089 +
1090 +  TCut bkpcut = cut;
1091 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
1092 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
1093 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1094 +
1095 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
1096 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
1097 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1098 +  
1099 +  cut=bkpcut;
1100 +  TCut bkpweight = cutWeight;
1101 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
1102 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
1103 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1104 +  
1105 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
1106 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
1107 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1108 +  cutWeight=bkpweight;
1109 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
1110 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
1111 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1112 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
1113 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
1114 +    float jes   = jesdn>jesup?jesdn:jesup;
1115 +    
1116 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
1117 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
1118 +    float pu   = PUdn>PUup?PUdn:PUup;
1119 +    
1120 +    float sys=sqrt(jes*jes+pu*pu);
1121 +    sys/=MCcentral->GetBinContent(i);
1122 +    if(MCcentral->GetBinContent(i)==0) sys=0;
1123 +    Systematic->SetBinContent(i,sys);
1124 +  }
1125 +  
1126 +  datahisto->Draw("e1");
1127 +  ckin->Update();
1128 +  mcstack.Draw("histo,same");
1129 +  
1130 +  datahisto->Draw("same,e1");
1131 +  TLegend *kinleg = allsamples.allbglegend();
1132 +  kinleg->Draw();
1133 +
1134 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1135 +  kinpad->SetLogy(dolog);
1136 +  kinpad->cd();
1137 +  datahisto->Draw("e1");
1138 +  mcstack.Draw("histo,same");
1139 +  datahisto->Draw("same,e1");
1140 +  datahisto->Draw("same,axis");
1141 +  
1142 +  kinleg->Draw("same");
1143 +  DrawPrelim();
1144 +  string saveas="kin/"+filename;
1145 +  
1146 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1147 +  save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1148 +  
1149 +  ckin->cd();
1150 +  MCcentral->SetFillColor(kWhite);
1151 +  MCcentral->SetLineColor(kBlack);
1152 +  MCcentral->SetLineWidth(2);
1153 +  MCPUdn->SetLineColor(kRed);
1154 +  MCPUup->SetLineColor(kYellow);
1155 +  MCJESdn->SetLineColor(kBlue);
1156 +  MCJESup->SetLineColor(kGreen);
1157 +  
1158 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
1159 +  legsmall->SetNColumns(5);
1160 +  legsmall->AddEntry(MCcentral,"central","L");
1161 +  legsmall->AddEntry(MCPUdn,"PU down","L");
1162 +  legsmall->AddEntry(MCPUup,"PU up","L");
1163 +  legsmall->AddEntry(MCJESdn,"JES down","L");
1164 +  legsmall->AddEntry(MCJESup,"JES up","L");
1165 +  legsmall->SetFillColor(kWhite);
1166 +  legsmall->SetBorderSize(0);
1167 +  
1168 +  datahisto->Draw("e1");
1169 +  MCcentral->Draw("histo,same");
1170 +  MCPUdn->Draw("histo,same");
1171 +  MCPUup->Draw("histo,same");
1172 +  MCJESdn->Draw("histo,same");
1173 +  MCJESup->Draw("histo,same");
1174 +  datahisto->Draw("e1,same");
1175 +  legsmall->Draw();
1176 +  CompleteSave(ckin,saveas+"___AllLines");
1177 +  
1178 +  delete datahisto;
1179 +  delete MCcentral;
1180 +  delete MCPUdn;
1181 +  delete MCPUup;
1182 +  delete MCJESdn;
1183 +  delete MCJESup;
1184 +  delete ckin;
1185 + }
1186  
1187 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1188 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1189 + }
1190 +  
1191   float lastrange_min=0;
1192   float lastrange_max=0;
1193  
# Line 535 | Line 1196 | void make_kin_plot(string variable, stri
1196   //  TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
1197    TCut ibasiccut=basiccut;
1198    bool draw_separation_lines=false;
1199 +  bool drawsignal = false;
1200    
1201    if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
1202  
# Line 556 | Line 1218 | void make_kin_plot(string variable, stri
1218    //Step 2: Refine the cut
1219    TCut cut;
1220    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
1221 <  if(filename=="nJets" || filename=="nJets_inclusive") cut=cutmass&&cutOSSF&&ibasiccut;
1222 <  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive") cut=cutmass&&cutOSOF&&ibasiccut;
1221 >  if(filename=="nJets" || filename=="nJets_inclusive" || filename=="nJets_met100" || filename=="nJets_inclusive_met100") cut=cutmass&&cutOSSF&&ibasiccut;
1222 >  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive" || filename=="nJets_osof_met100" || filename=="nJets_osof_inclusive_met100") cut=cutmass&&cutOSOF&&ibasiccut;
1223    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
1224 <  if(filename=="mll") {
1224 >  if(filename=="mll"||filename=="mll_met100") {
1225          cut=cutOSSF&&cutnJets&&ibasiccut;
1226          draw_separation_lines=true;
1227    }
1228 <  if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
1229 <  if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
1230 <  if(filename=="mll_osof") {
1228 >  if(filename=="mll_ee"||filename=="mll_ee_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
1229 >  if(filename=="mll_mm"||filename=="mll_mm_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
1230 >  if(filename=="mll_osof"||filename=="mll_osof_met100") {
1231          cut=cutOSOF&&cutnJets&&ibasiccut;
1232          draw_separation_lines=true;
1233    }
# Line 573 | Line 1235 | void make_kin_plot(string variable, stri
1235    if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
1236    if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
1237    if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
1238 <  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutmass&&cutOSSF;
1239 <  if(filename=="mll_inclusive_osof") cut=cutmass&&cutOSOF;
1240 <  if(filename=="mll_inclusive_ee") cut=cutmass&&cutOSSF&&"id1==0";
1241 <  if(filename=="mll_inclusive_mm") cut=cutmass&&cutOSSF&&"id1==1";
1238 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
1239 >  if(filename=="mll_inclusive_osof") cut=cutOSOF;
1240 >  if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
1241 >  if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
1242    if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
1243    if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
1244    if(filename=="numVtx") cut=cutmass&&ibasiccut;
# Line 597 | Line 1259 | void make_kin_plot(string variable, stri
1259    if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1260    else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1261  
1262 <  cout << "******** Cut used : " << (const char*) cut << endl;
1262 >  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
1263    if(loadlastminmax) {
1264          datahisto->SetMinimum(lastrange_min);
1265          datahisto->SetMaximum(lastrange_max);
# Line 611 | Line 1273 | void make_kin_plot(string variable, stri
1273    string signal("LM3");
1274    TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
1275    int idx = signalsamples.FindSample(signal)[0];
1276 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
1277 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
1278 <  signalhisto->SetLineColor(kOrange);
1276 >  if(drawsignal) (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
1277 >  if(drawsignal) signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
1278 >  if(drawsignal) signalhisto->SetLineColor(kOrange);
1279  
1280    THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1281    datahisto->Draw("e1");
1282    ckin->Update();
1283 <  mcstack.Draw("same");
1283 >  mcstack.Draw("histo,same");
1284    
1285    datahisto->Draw("same,e1");
1286    TLegend *kinleg = allsamples.allbglegend();
# Line 661 | Line 1323 | void make_kin_plot(string variable, stri
1323          kinpad->cd();
1324          kinpad->SetLogy(logscale);
1325          datahisto->Draw("e1");
1326 <        mcstack.Draw("same");
1327 <        signalhisto->Draw("same");
1326 >        mcstack.Draw("histo,same");
1327 >        if(drawsignal) signalhisto->Draw("same");
1328          datahisto->Draw("same,e1");
1329          datahisto->Draw("same,axis");
1330          if(RestrictToMassPeak&&draw_separation_lines) {
# Line 670 | Line 1332 | void make_kin_plot(string variable, stri
1332            upperboundary->Draw("same");
1333          }
1334            
1335 <        kinleg->AddEntry("signalhisto",signal.c_str(),"l");
1335 >        if(drawsignal) kinleg->AddEntry("signalhisto",signal.c_str(),"l");
1336          kinleg->Draw();
1337          write_cut->Draw();
1338          DrawPrelim();
1339          string saveas="kin/"+filename;
1340          if(isPF) saveas="kin/"+filename+"__PF";
1341 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1341 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1342   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
1343   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
1344   //      delete with_ratio;
# Line 685 | Line 1347 | void make_kin_plot(string variable, stri
1347          else CompleteSave(ckin,"kin/"+filename);
1348    }
1349    datahisto->Delete();
1350 +  delete signalhisto;
1351    delete ckin;
1352   }
1353  
1354 +
1355 + void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
1356 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
1357 +  TCut cut=TCut(addcut.c_str())&&basiccut;
1358 +
1359 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1360 +  ckin->SetLogy(logscale);
1361 +  TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1362 +  datahisto->SetMarkerSize(DataMarkerSize);
1363 +  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
1364 +  else datahisto->SetMinimum(0.5);
1365 +  // Custom max.
1366 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1367 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1368 +
1369 +  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
1370 +  if(loadlastminmax) {
1371 +        datahisto->SetMinimum(lastrange_min);
1372 +        datahisto->SetMaximum(lastrange_max);
1373 +        if(logscale) {
1374 +                datahisto->SetMinimum(pow(10,lastrange_min));
1375 +                datahisto->SetMaximum(pow(10,lastrange_max));
1376 +        }              
1377 +  }
1378 +
1379 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1380 +  datahisto->Draw("e1");
1381 +  ckin->Update();
1382 +  mcstack.Draw("histo,same");
1383 +  
1384 +  datahisto->Draw("same,e1");
1385 +  TLegend *kinleg = allsamples.allbglegend();
1386 +  kinleg->Draw();
1387 +
1388 +  lastrange_min=ckin->GetUymin();
1389 +  lastrange_max=ckin->GetUymax();
1390 +
1391 +  if ( plotratio ) {
1392 +        TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1393 +        kinpad->cd();
1394 +        kinpad->SetLogy(logscale);
1395 +        datahisto->Draw("e1");
1396 +        mcstack.Draw("histo,same");
1397 +        datahisto->Draw("same,e1");
1398 +        datahisto->Draw("same,axis");
1399 +          
1400 +        kinleg->Draw();
1401 +        DrawPrelim();
1402 +        string saveas="kin/"+filename;
1403 +        if(isPF) saveas="kin/"+filename+"__PF";
1404 +        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1405 +  } else {
1406 +        if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
1407 +        else CompleteSave(ckin,"kin/"+filename);
1408 +  }
1409 +  datahisto->Delete();
1410 +  delete ckin;
1411 + }
1412 +
1413 +
1414   void make_JES_plot(TCut cut, string name) {
1415  
1416    int nbins=10;
# Line 721 | Line 1444 | void make_JES_plot(TCut cut, string name
1444    JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
1445    JESunc->SetFillStyle(3002);
1446    datahisto->Draw("e1");
1447 <  mcstack.Draw("same");
1447 >  mcstack.Draw("histo,same");
1448    JESunc->Draw("2");
1449    datahisto->Draw("same,e1");
1450    TLegend *kinleg = allsamples.allbglegend();
# Line 730 | Line 1453 | void make_JES_plot(TCut cut, string name
1453    CompleteSave(ckin,"Systematics/JES"+name);
1454    datahisto->Delete();
1455    delete ckin;
1456 +  delete JESunc;
1457 +  delete JESup;
1458 +  delete JESdn;
1459 +  CleanLegends();
1460 + }
1461 +
1462 + string Cut2Str(TCut cut) {
1463 +  return ((string)(const char*)cut);
1464 + }
1465 +
1466 + void MakeElegantTwoThreeComparisons() {
1467 +    
1468 +    TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
1469 +    TCut TwoJets("pfJetGoodNum40==2");
1470 +    TCut ThreeJets("pfJetGoodNum40>=3");
1471 +    
1472 +    float min=20;
1473 +    float max=300;
1474 +    int nbins=int((max-min)/5.0);
1475 +    string xlabel="m_{ll} [GeV]";
1476 +    
1477 +    TCanvas *can2 = new TCanvas("can2","can2");
1478 +    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1479 +    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1480 +    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1481 +    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1482 +    
1483 +    can2->cd(1);
1484 +    
1485 +    TwoSF->SetFillColor(kWhite);
1486 +    TwoOF->SetFillColor(kWhite);
1487 +    ThreeSF->SetFillColor(kWhite);
1488 +    ThreeOF->SetFillColor(kWhite);
1489 +    
1490 +    TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1491 +    kin3->cd();
1492 +    TwoOF->Draw("histo");
1493 +    TwoSF->Draw("e1,same");
1494 +    TLegend *leg_SFOF_Two = make_legend();
1495 +    leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1496 +    leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1497 +    leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1498 +    leg_SFOF_Two->Draw();
1499 +    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1500 +    
1501 +    TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1502 +    kin4->cd();
1503 +    ThreeOF->Draw("histo");
1504 +    ThreeSF->Draw("e1,same");
1505 +    TLegend *leg_SFOF_Three = make_legend();
1506 +    leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1507 +    leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1508 +    leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1509 +    leg_SFOF_Three->Draw();
1510 +    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1511 +    
1512 +    
1513 +    TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1514 +    TPad *kin = new TPad("kin","kin",0,0,1,1);
1515 +    kin->cd();
1516 +    TwoSF->Draw("histo");
1517 +    ThreeSF->Draw("e1,same");
1518 +    TLegend *leg_SF_Two_Three = make_legend();
1519 +    leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1520 +    leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1521 +    leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1522 +    leg_SF_Two_Three->Draw();
1523 +    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1524 +    
1525 +    TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1526 +    TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1527 +    kin2->cd();
1528 +    TwoOF->Draw("histo");
1529 +    ThreeOF->Draw("e1,same");
1530 +    TLegend *leg_OF_Two_Three = make_legend();
1531 +    leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1532 +    leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1533 +    leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1534 +    leg_OF_Two_Three->Draw();
1535 +    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1536 +    
1537 + }
1538 +
1539 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1540 +  pad->cd();
1541 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1542 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1543 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1544 +    float error=abs(Down->GetBinContent(i)-average);
1545 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1546 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1547 +  }
1548 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1549 +  gr->GetYaxis()->SetRangeUser(0,2);
1550 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1551 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1552 +  gr->GetXaxis()->CenterTitle();
1553 +  gr->GetYaxis()->CenterTitle();
1554 +  
1555 +  gr->Draw("A2");
1556 +  central->Draw("e1,same");
1557 +  DrawMCPrelim();
1558 +  TText *rtitle = write_text(0.8,0.8,title);
1559 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1560 +  line->SetLineColor(kBlue);
1561 +  line->SetLineStyle(2);
1562 +  line->Draw("same");
1563 +  rtitle->Draw("same");
1564 + }
1565 +
1566 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1567 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1568 +  basehisto->Add(originalttbar,-1);
1569 +  basehisto->Add(httbar);
1570 +  
1571 +  string sname=httbar->GetName();
1572 +  sname="R"+sname.substr(1,sname.length());
1573 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1574 +  ratio->Divide(basehisto);
1575 +  delete basehisto;
1576 +  return ratio;
1577 + }
1578 +  
1579 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1580 +  
1581 +  TCut cut=addcut&&basiccut;
1582 +  
1583 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1584 +  ckin->SetLogy(dolog);
1585 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1586 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1587 +  datahisto->SetMarkerSize(DataMarkerSize);
1588 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1589 +  else datahisto->SetMinimum(0.5);
1590 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1591 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1592 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1593 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1594 +  TH1F *MCcentral = CollapseStack(mcstack);
1595 +
1596 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1597 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("/TT_"));
1598 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1599 +  
1600 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1601 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1602 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1603 +  
1604 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1605 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1606 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1607 +  
1608 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1609 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1610 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1611 +  
1612 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1613 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1614 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1615 +  
1616 +  datahisto->Draw("e1");
1617 +  ckin->Update();
1618 +  mcstack.Draw("histo,same");
1619 +  
1620 +  datahisto->Draw("same,e1");
1621 +  TLegend *kinleg = allsamples.allbglegend();
1622 +  kinleg->Draw();
1623 +
1624 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1625 +  kinpad->SetLogy(dolog);
1626 +  kinpad->cd();
1627 +  datahisto->Draw("e1");
1628 +  mcstack.Draw("histo,same");
1629 +  datahisto->Draw("same,e1");
1630 +  datahisto->Draw("same,axis");
1631 +  
1632 +  kinleg->Draw("same");
1633 +  DrawPrelim();
1634 +  string saveas="kin/"+filename;
1635 +  
1636 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1637 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1638 +  delete kinpad;
1639 +  
1640 +  ckin->cd();
1641 +  TCentral->SetLineColor(kBlack);
1642 +  
1643 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1644 +  TMatchingUp->SetLineStyle(2);//dashed
1645 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1646 +  TMatchingDown->SetLineStyle(3);//dotted
1647 +  
1648 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1649 +  TScaleUp->SetLineStyle(2);//dashed
1650 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1651 +  TScaleDown->SetLineStyle(3);//dotted
1652 +  
1653 +  MCcentral->SetLineStyle(3);
1654 +  MCcentral->SetLineColor(kRed);
1655 +  
1656 +  TCentral->Draw("e1,same");
1657 +  TCentral->Draw("histo,same");
1658 +  TMatchingUp->Draw("histo,same");
1659 +  TMatchingDown->Draw("histo,same");
1660 +  TScaleUp->Draw("histo,same");
1661 +  TScaleDown->Draw("histo,same");
1662 +  
1663 +  TLegend *sleg = make_legend();
1664 +  sleg->AddEntry(TCentral,"Central","L");
1665 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1666 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1667 +  sleg->AddEntry(TScaleUp,"scale up","L");
1668 +  sleg->AddEntry(TScaleDown,"scale down","L");
1669 +  sleg->Draw();
1670 +  
1671 +  CompleteSave(ckin,saveas+"___AllLines");
1672 +  ckin->cd();
1673 +  ckin->SetLogy(0);
1674 +  
1675 +  RCentral->SetLineColor(kBlack);
1676 +  
1677 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1678 +  RMatchingUp->SetLineStyle(2);//dashed
1679 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1680 +  RMatchingDown->SetLineStyle(3);//dotted
1681 +  
1682 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1683 +  RScaleUp->SetLineStyle(2);//dashed
1684 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1685 +  RScaleDown->SetLineStyle(3);//dotted
1686 +  
1687 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1688 +  RCentral->Draw("e1");
1689 +  RMatchingUp->Draw("histo,same");
1690 +  RMatchingDown->Draw("histo,same");
1691 +  RScaleUp->Draw("histo,same");
1692 +  RScaleDown->Draw("histo,same");
1693 +  
1694 +  CompleteSave(ckin,saveas+"___AllRatios");
1695 +
1696 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1697 +  multicanvas->Divide(2,1);
1698 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1699 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1700 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1701 +  
1702 +  
1703 +  delete datahisto;
1704 +  delete   TCentral;
1705 +  delete   TMatchingUp;
1706 +  delete   TMatchingDown;
1707 +  delete   TScaleUp;
1708 +  delete   TScaleDown;
1709 + //   delete   Ttmass166;
1710 + //   delete   Ttmass169;
1711 + //   delete   Ttmass175;
1712 + //   delete   Ttmass178;
1713 +  
1714 +  delete ckin;
1715 +  
1716 + }
1717 +  
1718 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1719 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1720 + }
1721 +
1722 + void ProduceJanPlots() {
1723 +  TCanvas *c1 = new TCanvas("c1","c1");
1724 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1725 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1726 +  
1727 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1728 +  rcan->cd();
1729 +
1730 +  metOF->SetLineColor(kRed);
1731 +  metSF->Draw("e1");
1732 +  metOF->Draw("histo,same");
1733 +  metSF->Draw("e1,same");
1734 +  
1735 +  TLegend *leg = make_legend();
1736 +  
1737 +  leg->AddEntry(metSF,"Data SF","p");
1738 +  leg->AddEntry(metOF,"Data OF","l");
1739 +  leg->Draw();
1740 +  
1741 +  DrawPrelim();
1742 +  
1743 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1744 +  
1745 +  delete rcan;
1746 +  delete metSF;
1747 +  delete metOF;
1748 +  delete c1;
1749 + }
1750 +
1751 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1752 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1753 +  
1754 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1755 +  if(variation!="Central") {
1756 +    TH1F *varttbar;
1757 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1758 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1759 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1760 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1761 +    assert(varttbar);
1762 +    
1763 +    TIter nextHisto(SystPlot.GetHists());
1764 +    TH1F* h;
1765 +    while ( h = (TH1F*)nextHisto() ) {
1766 +      if(Contains(h->GetName(),"t_bar_t")) {
1767 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1768 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1769 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1770 +          h->SetBinError(i,varttbar->GetBinError(i));
1771 +        }
1772 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1773 +        SystPlot.Modified();
1774 +      }
1775 +    }
1776 +    delete varttbar;
1777 +  } else {
1778 +    TIter nextHisto(SystPlot.GetHists());
1779 +    TH1F* h;
1780 +    while ( h = (TH1F*)nextHisto() ) {
1781 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1782 +    }
1783 +  }
1784 +    
1785 +  TLegend *fullleg = allsamples.allbglegend();
1786 +  fullleg->SetHeader(variation.c_str());
1787 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1788 +  kinpad->SetLogy(1);
1789 +  kinpad->cd();
1790 +  
1791 +  hdata->Draw("e1");
1792 +  SystPlot.Draw("histo,same");
1793 +  hdata->Draw("e1,same");
1794 +  fullleg->Draw();
1795 +  DrawPrelim();
1796 +  
1797 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1798 +  CleanLegends();
1799 +  
1800 +  delete kinpad;
1801 +  return SystPlot;
1802 + }
1803 +  
1804 +
1805 +
1806 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1807 +  TCanvas *ca = new TCanvas("ca","ca");
1808 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1809 +  
1810 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1811 +  
1812 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1813 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1814 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1815 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1816 +  
1817 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1818 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1819 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1820 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1821 +  
1822 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1823 +  TH1F *HCentral = CollapseStack(Central);
1824 +  
1825 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1826 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1827 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1828 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1829 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1830 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1831 +    
1832 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1833 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1834 +    
1835 +    float sys=sqrt(matching*matching+scale*scale);
1836 +    sys/=HCentral->GetBinContent(i);
1837 +    if(HCentral->GetBinContent(i)==0) sys=0;
1838 +    Systematic->SetBinContent(i,sys);
1839 +  }
1840 +  
1841 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1842 +  kinpad->SetLogy(1);
1843 +  kinpad->cd();
1844 +  if(variable=="genMET") {
1845 +    Central.Draw("histo");
1846 +  } else {
1847 +    hdata->Draw("e1");
1848 +    Central.Draw("histo,same");
1849 +    hdata->Draw("e1,same");
1850 +  }
1851 +  
1852 +  DrawPrelim();
1853 +  
1854 +  save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1855 +  
1856 +  kinpad->cd();
1857 +  tCentral->SetFillColor(kWhite);
1858 +  tCentral->SetLineColor(kBlack);
1859 +  tScaleUp->SetLineColor(kRed);
1860 +  tScaleDown->SetLineColor(kRed);
1861 +  tMatchingUp->SetLineColor(kBlue);
1862 +  tMatchingDown->SetLineColor(kBlue);
1863 +  tScaleUp->SetLineStyle(2);
1864 +  tScaleDown->SetLineStyle(3);
1865 +  tMatchingUp->SetLineStyle(2);
1866 +  tMatchingDown->SetLineStyle(3);
1867 +  
1868 +  TLegend *leg2 = make_legend();
1869 +  leg2->AddEntry(hdata,"Data","p");
1870 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1871 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1872 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1873 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1874 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1875 +  if(variable=="genMET") {
1876 +    Central.Draw("histo");
1877 +  }else {
1878 +    hdata->Draw("e1");
1879 +    Central.Draw("histo,same");
1880 +    hdata->Draw("e1,same");
1881 +  }
1882 +  tCentral->Draw("histo,same");
1883 +  tScaleUp->Draw("histo,same");
1884 +  tScaleDown->Draw("histo,same");
1885 +  tMatchingUp->Draw("histo,same");
1886 +  tMatchingDown->Draw("histo,same");
1887 +  leg2->Draw();
1888 +  
1889 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1890 +  
1891 +  gStyle->SetOptFit(0);
1892 +  
1893 +  kinpad->cd();
1894 +  kinpad->SetLogy(0);
1895 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1896 +  MatchingRatio->Divide(tMatchingDown);
1897 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1898 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1899 +  lone->SetLineStyle(2);
1900 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1901 +  ScaleRatio->Divide(tScaleDown);
1902 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1903 +  MatchingRatio->Draw("e1");
1904 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1905 +  MatchingRatio->Fit("QP1","R");
1906 +  lone->Draw();
1907 +  stringstream summary;
1908 +  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);
1909 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1910 +  TText *infobox = write_title(summary.str());
1911 +  infobox->SetX(0.75);
1912 +  infobox->SetTextSize(0.03);
1913 +  infobox->SetY(0.75);
1914 +  infobox->Draw();
1915 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1916 +  kinpad->cd();
1917 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1918 +  ScaleRatio->Draw("e1");
1919 +  ScaleRatio->Fit("QP1","R");
1920 +  summary.str("");
1921 +  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);
1922 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1923 +  TText *infobox2 = write_title(summary.str());
1924 +  infobox2->SetX(0.75);
1925 +  infobox2->SetTextSize(0.03);
1926 +  infobox2->SetY(0.75);
1927 +  infobox2->Draw();
1928 +
1929 +  lone->Draw();
1930 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1931 +  
1932 +  
1933 +  delete QP1;
1934 +  delete infobox;
1935 +  delete infobox2;
1936 +  delete MatchingRatio;
1937 +  delete ScaleRatio;
1938 +  DeleteStack(ScaleUp);
1939 +  DeleteStack(ScaleDown);
1940 +  DeleteStack(MatchingUp);
1941 +  DeleteStack(MatchingDown);
1942 +  delete leg2;
1943 +  CleanLegends();
1944 +  DeleteStack(Central);
1945 +  delete Systematic;
1946 +  delete HScaleUp;
1947 +  delete HScaleDown;
1948 +  delete HMatchingUp;
1949 +  delete HMatchingDown;
1950 +  delete hdata;
1951 +  delete HCentral;
1952 +  delete ca;
1953 + }
1954 +
1955 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1956 +  float val=0,err=0;
1957 +  vector<float> bins;
1958 +  vector<float> vals;
1959 +  vector<float> errs;
1960 +  
1961 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1962 +  int iBin=1;
1963 +  
1964 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1965 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1966 +      bins.push_back(histo->GetBinLowEdge(i));
1967 +      vals.push_back(val);val=0;
1968 +      errs.push_back(err);err=0;
1969 +      iBin++;
1970 +    }
1971 +    val+=histo->GetBinContent(i);
1972 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1973 +  }
1974 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1975 +  vals.push_back(val);val=0;
1976 +  errs.push_back(err);err=0;
1977 +  
1978 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1979 +  for(unsigned int i=0;i<vals.size();i++) {
1980 +    h->SetBinContent(i+1,vals[i]);
1981 +    h->SetBinError(i+1,errs[i]);
1982 +  }
1983 +  
1984 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1985 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1986 +  
1987 +  h->GetXaxis()->CenterTitle();
1988 +  h->GetYaxis()->CenterTitle();
1989 +
1990 +  return h;
1991 + }
1992 +
1993 +
1994 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1995 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1996 +  float val=0,err=0;
1997 +  vector<float> bins;
1998 +  vector<float> vals;
1999 +  vector<float> errs;
2000 +  
2001 +  bins.push_back(histo->GetBinLowEdge(1));
2002 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
2003 +    val+=histo->GetBinContent(i);
2004 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
2005 +    if( val/statsperbin > 0.85) {
2006 +      if(bins.size()<nbins) {
2007 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
2008 +        vals.push_back(val);val=0;
2009 +        errs.push_back(err);err=0;
2010 +      }
2011 +    }
2012 +    if(i==histo->GetNbinsX()) {
2013 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
2014 +      vals.push_back(val);val=0;
2015 +      errs.push_back(err);err=0;
2016 +    }
2017 +  }
2018 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
2019 +  
2020 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
2021 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
2022 +  
2023 +  h->GetXaxis()->CenterTitle();
2024 +  h->GetYaxis()->CenterTitle();
2025 +  
2026 +  for(unsigned int i=0;i<vals.size();i++) {
2027 +    h->SetBinContent(i+1,vals[i]);
2028 +    h->SetBinError(i+1,errs[i]);
2029 +  }
2030 +  
2031 +  return h;
2032 + }
2033 +
2034 +
2035 +  
2036 + void ShowBinning(TH1F *histo) {
2037 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
2038 +  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;
2039 + }
2040 +  
2041 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
2042 +  TCanvas *ca = new TCanvas("ca","ca");
2043 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
2044 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
2045 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
2046 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
2047 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
2048 +  
2049 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
2050 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
2051 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
2052 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
2053 +  tCentral->Scale(1.0/tCentral->Integral());
2054 +  
2055 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
2056 +  
2057 +  
2058 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
2059 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
2060 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
2061 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
2062 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
2063 +  
2064 +  float min=rtScaleUp->GetMinimum();
2065 +  float max=rtScaleUp->GetMaximum();
2066 +  
2067 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
2068 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2069 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2070 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
2071 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
2072 +  
2073 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
2074 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2075 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2076 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
2077 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
2078 +  
2079 +  rtCentral->SetMaximum(1.2*max);
2080 +  rtCentral->SetMinimum(0.8*min);
2081 +  
2082 + /*  tScaleUp->Rebin(40);
2083 +  tScaleDown->Rebin(40);
2084 +  tMatchingDown->Rebin(40);
2085 +  tMatchingUp->Rebin(40);
2086 +  tCentral->Rebin(40);*/
2087 +  
2088 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2089 +  kinpad->SetLogy(1);
2090 +  kinpad->cd();
2091 +  tCentral->SetFillColor(kWhite);
2092 +  tCentral->SetLineColor(kBlack);
2093 +  tScaleUp->SetLineColor(kRed);
2094 +  tScaleDown->SetLineColor(kRed);
2095 +  tMatchingUp->SetLineColor(kBlue);
2096 +  tMatchingDown->SetLineColor(kBlue);
2097 +  tScaleUp->SetLineStyle(2);
2098 +  tScaleDown->SetLineStyle(3);
2099 +  tMatchingUp->SetLineStyle(2);
2100 +  tMatchingDown->SetLineStyle(3);
2101 +  
2102 +  rtScaleDown->SetLineColor(kRed);
2103 +  rtMatchingUp->SetLineColor(kBlue);
2104 +  rtMatchingDown->SetLineColor(kBlue);
2105 +  rtScaleUp->SetLineStyle(2);
2106 +  rtScaleDown->SetLineStyle(3);
2107 +  rtMatchingUp->SetLineStyle(2);
2108 +  rtMatchingDown->SetLineStyle(3);
2109 +  
2110 +  TLegend *leg2 = make_legend();
2111 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
2112 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
2113 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
2114 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
2115 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
2116 +  
2117 +  tCentral->Draw("histo");
2118 +  tScaleUp->Draw("histo,same");
2119 +  tScaleDown->Draw("histo,same");
2120 +  tMatchingUp->Draw("histo,same");
2121 +  tMatchingDown->Draw("histo,same");
2122 +  leg2->Draw();
2123 +  DrawMCPrelim();
2124 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
2125 +  kinpad->cd();
2126 +  kinpad->SetLogy(0);
2127 +  rtCentral->Draw("histo");
2128 +  rtScaleUp->Draw("histo,same");
2129 +  rtScaleDown->Draw("histo,same");
2130 +  rtMatchingUp->Draw("histo,same");
2131 +  rtMatchingDown->Draw("histo,same");
2132 +  leg2->Draw();
2133 +  DrawMCPrelim();
2134 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
2135 +  
2136 +  
2137 +  gStyle->SetOptFit(0);
2138 +
2139 +  kinpad->cd();
2140 +  kinpad->SetLogy(0);
2141 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
2142 +  MatchingRatio->Divide(rtMatchingDown);
2143 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
2144 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
2145 +  lone->SetLineStyle(2);
2146 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
2147 +  ScaleRatio->Divide(rtScaleDown);
2148 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
2149 +  MatchingRatio->Draw("e1");
2150 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
2151 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
2152 +  lone->Draw();
2153 +  stringstream summary;
2154 +  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);
2155 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2156 +  TText *infobox = write_title(summary.str());
2157 +  infobox->SetX(0.75);
2158 +  infobox->SetTextSize(0.03);
2159 +  infobox->SetY(0.75);
2160 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
2161 +  DrawMCPrelim();
2162 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
2163 +  kinpad->cd();
2164 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
2165 +  ScaleRatio->Draw("e1");
2166 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
2167 +  summary.str("");
2168 +  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);
2169 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2170 +  TText *infobox2 = write_title(summary.str());
2171 +  infobox2->SetX(0.75);
2172 +  infobox2->SetTextSize(0.03);
2173 +  infobox2->SetY(0.75);
2174 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
2175 +
2176 +  lone->Draw();
2177 +  DrawMCPrelim();
2178 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
2179 +  
2180 +  kinpad->cd();
2181 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
2182 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
2183 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
2184 +  
2185 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
2186 +    float matching, scale;
2187 +    bool AssumeFactor=false;
2188 +    if(AssumeFactor) {
2189 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
2190 +      matching=0.;
2191 +      scale=0.;
2192 +    } else {
2193 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
2194 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
2195 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
2196 +    }
2197 +    
2198 +    SysMatching->SetBinContent(i,1+matching);
2199 +    SysScale->SetBinContent(i,1+scale);
2200 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
2201 +  }
2202 +  
2203 +  SysHisto->SetLineColor(kGreen);
2204 +  
2205 +  SysMatching->SetMaximum(3.0);
2206 +  SysMatching->SetMinimum(0.0);
2207 +  SysMatching->Draw("histo");
2208 +  SysScale->Draw("histo,same");
2209 +  SysHisto->Draw("histo,same");
2210 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
2211 +  
2212 +  delete SysMatching;
2213 +  delete SysScale;
2214 +  
2215 +  if(!Contains(variable,"gen")) {
2216 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
2217 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
2218 +    
2219 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
2220 +    
2221 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
2222 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
2223 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
2224 +      float sys = SysHisto->GetBinContent(iBin)-1;
2225 +      Systematic->SetBinContent(i,sys);
2226 +    }
2227 +    
2228 +    kinpad->cd();
2229 +    TLegend *leg = allsamples.allbglegend();
2230 +    hdata->Draw();
2231 +    smc.Draw("histo,same");
2232 +    hdata->Draw("same");
2233 +    leg->Draw();
2234 +    DrawPrelim();
2235 +    save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
2236 +    
2237 +    delete Systematic;
2238 +    delete hdata;
2239 +  }
2240 +  
2241 +  
2242 +  delete SysHisto;
2243 +  delete tScaleUp;
2244 +  delete tScaleDown;
2245 +  delete tCentral;
2246 +  delete tMatchingUp;
2247 +  delete tMatchingDown;
2248 +  delete rtScaleUp;
2249 +  delete rtScaleDown;
2250 +  delete rtCentral;
2251 +  delete rtMatchingUp;
2252 +  delete rtMatchingDown;
2253 +  delete QP1;
2254 +  delete infobox;
2255 +  delete infobox2;
2256 +  delete MatchingRatio;
2257 +  delete ScaleRatio;
2258 +  delete leg2;
2259 +  CleanLegends();
2260 +  delete ca;
2261 + }
2262 +
2263 + void ProduceMCSystematicPlots() {
2264 +  cout << "Getting ready to produce systematic plots " << endl;
2265 +  TCut cutweightBKP = cutWeight;
2266 +  
2267 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
2268 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
2269 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
2270 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
2271 +  
2272 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
2273 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
2274 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
2275 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
2276 +  
2277 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
2278 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
2279 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
2280 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
2281 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
2282 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
2283 +  
2284 +  
2285 +  
2286 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2287 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2288 +  cutWeight="1.0";
2289 +  
2290 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2291 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
2292 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2293 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2294 +  
2295 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2296 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
2297 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2298 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2299 +  
2300 +  
2301 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
2302 +  
2303 +  /*
2304 +  cutWeight=cutweightBKP;
2305 +  TCut essentialcutBKP = essentialcut;
2306 +  cout << (const char*) essentialcut << endl;
2307 +  
2308 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
2309 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2310 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2311 +  
2312 +  TCut cutnJetsBKP = cutnJets;
2313 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
2314 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
2315 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2316 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2317 +  
2318 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
2319 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
2320 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
2321 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
2322 +  
2323 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
2324 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
2325 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2326 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
2327 +  
2328 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
2329 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
2330 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2331 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
2332 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
2333 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
2334 +  
2335 +  
2336 +  
2337 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2338 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2339 +  cutWeight="1.0";
2340 +  
2341 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2342 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
2343 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2344 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2345 +  
2346 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2347 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
2348 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2349 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2350 +  
2351 +  cutnJets  = cutnJetsBKP;
2352 +  cutWeight = cutweightBKP;
2353 +  essentialcut = essentialcutBKP;
2354 +  */
2355 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
2356 + }
2357 +
2358 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
2359 +  TCut cut=pcut&&basiccut;
2360 +  string variable="mll";
2361 +  string xlabel="m_{ll} [GeV]";
2362 +  int nbins=40;
2363 +  float min=0;
2364 +  float max=200;
2365 +
2366 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
2367 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
2368 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
2369 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2370 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2371 +  datahistoSF->SetMarkerSize(DataMarkerSize);
2372 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
2373 +  datahistoOF->SetMarkerSize(DataMarkerSize);
2374 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
2375 +
2376 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
2377 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
2378 +  datahistoSF->Draw("e1");
2379 +  ckin->Update();
2380 +  mcstackSF.Draw("histo,same");
2381 +  
2382 +  datahistoSF->Draw("same,e1");
2383 +  TLegend *kinleg = allsamples.allbglegend();
2384 +  kinleg->Draw();
2385 +  
2386 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2387 +  kinpad->cd();
2388 +  datahistoSF->Draw("e1");
2389 +  mcstackSF.Draw("histo,same");
2390 +  datahistoSF->Draw("same,e1");
2391 +  datahistoSF->Draw("same,axis");
2392 +  kinleg->Draw();
2393 +  DrawPrelim();
2394 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
2395 +  
2396 +  kinpad->cd();
2397 +  datahistoOF->Draw("e1");
2398 +  mcstackOF.Draw("histo,same");
2399 +  datahistoOF->Draw("same,e1");
2400 +  datahistoOF->Draw("same,axis");
2401 +  kinleg->Draw();
2402 +  DrawPrelim();
2403 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
2404 +  
2405 +  kinpad->cd();
2406 +  tauSF->Draw("e1");
2407 +  tauOF->Draw("histo,same");
2408 +  tauSF->Draw("e1,same");
2409 +  TLegend *legtau = make_legend();
2410 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
2411 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
2412 +  legtau->Draw();
2413 +  DrawPrelim();
2414 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
2415 +  
2416 +  delete datahistoSF;
2417 +  delete datahistoOF;
2418 +  delete tauSF;
2419 +  delete tauOF;
2420 +  delete kinpad;
2421 +  delete ckin;
2422 +  CleanLegends();
2423 + }
2424 +  
2425  
2426 + void TauQuestion() {
2427 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2428 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2429 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2430 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2431 + }
2432 +
2433 + void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2434 +  string BaseMetCut="met[4]>100";
2435 +  string Prefix="ETH/";
2436 +  if(isAachen) {
2437 +    BaseMetCut="met[4]>150";
2438 +    Prefix="Aachen/";
2439 +  }
2440 +  
2441 +      make_OFSF_plots("met[4]",  BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET");
2442 +      make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 5, -0.5, 4.5, true, "N_{b-jets}", Prefix+"nbjets");
2443 +      make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "#tilde{S}_{T}", Prefix+"FrankT");
2444 +      make_OFSF_plots("pt1+pt2+met[4]+Sum$(pfJetGoodPt)", BaseMetCut, 20, 0, 2000., false, "#tilde{S}_{T}", Prefix+"POOR_FrankT");
2445 + /*      make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2446 +
2447 +      make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2448 +      make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2449 +      make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2450 +  
2451 +      make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2452 +      make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2453 +      make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2454 +      make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2455 +      */
2456 +      make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2457 +      make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2458 +
2459 +      make_OFSF_plots("pfJetGoodNum40", BaseMetCut,                        7, 3, 10, true, "#(jets)", Prefix+"njets");
2460 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2461 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2462 +
2463 +      make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2464 +      make_OFSF_plots("pfJetGoodPt",  BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2465 +
2466 + //      make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2467 + //      make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2468 +      make_OFSF_plots("pt",  BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2469 +      make_OFSF_plots("pt1",  BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2470 +      make_OFSF_plots("pt2",  BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2471 + //      make_OFSF_plots("eta1", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{1}", Prefix+"eta1", 0.15);
2472 + //      make_OFSF_plots("eta2", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{2}", Prefix+"eta2", 0.15);
2473 + //      make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", 0.2);
2474 + //      make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", 0.2);
2475 + //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", 0.2);
2476 + //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", 0.2);
2477 +    
2478 + //      make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", 0.2);
2479 + //      make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", 0.2);
2480 + //      make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", 0.2);
2481 + //      make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2482 + //      make_OFSF_plots("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", Prefix+"dphijc");
2483 + //      make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(l,MET)|)", Prefix+"dphilco");
2484 + //      make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(jet,MET)|)", Prefix+"dphijco");
2485 +      
2486   }
2487  
2488 + void ProduceOFSFPlots(string mcjzb, string datajzb) {
2489 +  
2490 +  
2491 +  //FIRST : ETH SELECTION
2492 +  ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2493 +  
2494 +  string backup_cutnJets = (const char*)cutnJets;
2495 +  cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2496 +  cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2497 +  
2498 +  string backup_basiccut = (const char*)basiccut;
2499 +  basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2500 +  
2501 +  string backup_essential = (const char*) essentialcut;
2502 +  essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2503 +  
2504 +  ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2505 +  
2506 +  cutnJets     = TCut(backup_cutnJets.c_str());
2507 +  basiccut     = TCut(backup_basiccut.c_str());
2508 +  essentialcut = TCut(backup_essential.c_str());
2509 + }
2510 +  
2511 +
2512   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2513   {
2514 + //  switch_overunderflow(true);
2515    bool dolog=true;
2516    bool nolog=false;
2517  
2518 <  bool doOFSF = false;
2518 >  bool doOFSF = true;
2519    bool doKin  = false;
2520 <  bool doDataComp = true;
2520 >  bool doDataComp = false;
2521 >  bool MakeTwoThreeJetComparison = false;
2522    
2523  
2524    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
# Line 750 | Line 2528 | void do_kinematic_plots(string mcjzb, st
2528          mll_low=20;
2529          mll_hi=320;
2530    }
2531 +  
2532 +  if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2533 +  
2534 +  //TauQuestion();
2535  
2536 <  if ( doOFSF ) {
2537 <    make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2538 <
2539 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100", 7, 3, 10, true, "#(jets)", "njets");
2540 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2541 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30>0", 7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
760 <
761 <    make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
762 <    make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
763 <    make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
764 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
765 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
766 <    make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
767 <    make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
768 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
769 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
770 <    //  make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
771 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
772 <    make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
773 <    //  make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
774 <    //  make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
775 <    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");
776 <    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");
777 <    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");
778 <    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");
779 <  }
2536 >  //ProduceJanPlots();
2537 >  //ProduceMCSystematicPlots();
2538 >  //assert(0);
2539 > //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2540 >  
2541 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2542  
2543 <  if ( doDataComp && !PlottingSetup::openBox ) {
2543 >  if ( doDataComp) {
2544      TCut mllCut("");
2545 <    if ( !PlottingSetup::openBox ) mllCut = "mll>120";
2545 >    float massmin = 15.;
2546 >    float massmax = 315;
2547 >    int massnbins = 60;
2548 > /*    if ( !PlottingSetup::openBox ) {
2549 >      mllCut = "mll>70";
2550 >      massmin = 120;
2551 >      massmax = 360;
2552 >      massnbins = 14;
2553 >    }*/
2554  
2555      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2556 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig");
2557 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee");
2558 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm");
2559 <
2560 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2561 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_btagVeto");
2562 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_btagVeto");
2563 <
2564 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2565 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_AtLeastOneBJet");
2566 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_AtLeastOneBJet");
2556 >    
2557 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2558 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2559 >    
2560 >    
2561 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2562 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2563 >    make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2564 >    make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2565 >    make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2566 >    
2567 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2568 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2569 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2570 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2571 >
2572 >  
2573 >    string basiccutsaved = (const char*)basiccut;
2574 >    
2575 >    string newbasiccut=basiccutsaved;
2576 >    
2577 >    size_t found;
2578 >    found = newbasiccut.find( "pt2>20" );
2579 >    while (found!=string::npos){
2580 >      newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2581 >      found = newbasiccut.find( "pt2>20" );
2582 >    }
2583 >    basiccut=TCut(newbasiccut.c_str());
2584 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2585 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2586 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2587 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2588 >    basiccut=TCut(basiccutsaved.c_str());
2589 >    
2590 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2591 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2592 >    
2593 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2594 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2595 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2596 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2597 >
2598 >    
2599 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2600 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2601 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2602 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2603 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2604 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2605 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2606 >    make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2607 >
2608 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2609 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2610 >    
2611 >    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");
2612 >    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");
2613 >    
2614 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2615 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2616 >    
2617 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2618 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2619 >
2620 >
2621 >    make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2622 >    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");
2623 >    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");
2624 >
2625 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2626 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2627 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2628 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2629  
798    make_data_comparison_plot("mll", cutOSOF&&cutSignal, 60, 20., 320.,-1., false, "m_{ll}", "mll_OF_sig");
799    make_data_comparison_plot("mll", cutmass&&"met[4]>100&&met[4]<150&&pfJetGoodNum40<3", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_CR");
2630    }
2631  
2632  
2633    if ( doKin ) {
2634      string mllCut("");
2635 <    if ( !PlottingSetup::openBox ) mllCut = "&&mll>120";
2636 <
2635 >    /*
2636 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2637 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2638 >
2639 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2640 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2641 >
2642 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2643 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2644 >    
2645 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2646 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2647 >    
2648 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2649 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2650 >    
2651 >    make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2652 >    make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2653 >    
2654 >    make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2655 >    make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2656 >    
2657 >    
2658 >    assert(0);
2659 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2660 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2661 >  
2662 >    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);
2663 >    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);
2664 >    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);
2665 >    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);
2666 >
2667 >    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);
2668 >    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);
2669 >    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);
2670 >    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);
2671 >
2672 >
2673 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2674 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2675 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2676 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2677 >
2678 >    
2679 >    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);
2680 >    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);
2681 >    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);
2682 >    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);
2683 >
2684 >    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);
2685 >    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);
2686 >    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);
2687 >    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);
2688 >
2689 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2690 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2691 >    
2692 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2693 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2694 >    
2695 >    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);
2696 >    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);
2697 >    
2698 >    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);
2699 >    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);
2700 >
2701 >    
2702 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2703 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2704      // Plots in signal region
2705 <    make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2706 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2707 <    make_kin_plot("mll","mll>20&&met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2708 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2709 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2705 >    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2706 >
2707 >
2708 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2709 >    
2710 >    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");
2711 >    /*
2712 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2713 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2714 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2715 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2716 >
2717 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2718 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2719 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2720 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2721 >
2722 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2723 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2724 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2725 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2726 >
2727 >    
2728 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2729 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2730 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2731 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2732 >
2733 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2734 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2735 >
2736 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2737 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2738 >    
2739 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2740 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2741 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2742 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2743 >
2744 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2745 >    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);
2746 >    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);
2747 >    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);
2748 >    
2749 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2750 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2751 >    
2752 >    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);
2753 >    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);
2754 >    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);
2755 >    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);
2756      
2757 <    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2758 <    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2757 >    
2758 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2759 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2760  
2761      // Further inclusive invariant mass plots
2762 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2762 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2763      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2764      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2765 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2765 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2766      
2767 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2767 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2768      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2769      
826    //make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
827    //make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2770      
2771      // Number of jets
2772      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2773      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2774 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2774 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2775      
2776      // Others
2777      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 861 | Line 2803 | void do_kinematic_plots(string mcjzb, st
2803      
2804      //   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);
2805      //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);
2806 <    //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);
2806 >    //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);*/
2807    }
2808      
2809 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2810 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2811 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2812 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2813 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2814 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2815 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2816 <
2817 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2818 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2819 <
2809 >   int jzbcuts[7]={0,50,80,100,150,200,250};
2810 >   int MCorData[2]={data,mc};
2811 >  
2812 >   for(int d=0;d<2;d++) {
2813 >     for(int j=0;j<7;j++) {
2814 >       make_special_obs_pred_mll_plot(datajzb,mcjzb,jzbcuts[j],5.0,MCorData[d]); // 5.0 is the binwidth
2815 >     }
2816 >   }
2817 >  
2818 > /*
2819 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2820 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2821 > */
2822 >  switch_overunderflow(false);
2823   }
2824  
2825   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
# Line 895 | Line 2840 | void make_comp_plot( string var, string
2840    }
2841    
2842    string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
2843 +  if(!RestrictToMassPeak) {
2844 +    sRegions[0]="SF";
2845 +    sRegions[1]="OF";
2846 +  }
2847    TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass,     cutOSOF&&cutnJets&&cutmass,
2848                        cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
2849    
# Line 914 | Line 2863 | void make_comp_plot( string var, string
2863        if (ymax>ymin) datahisto->SetMaximum(ymax);
2864        lm3histo->SetLineStyle(2);
2865        datahisto->Draw("e1");
2866 <      mcstack.Draw("same");
2866 >      mcstack.Draw("histo,same");
2867        datahisto->Draw("same,e1");
2868        lm3histo->Draw("hist,same");
2869        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
# Line 944 | Line 2893 | void region_comparison_plots(string mcjz
2893  
2894   //  switch_overunderflow(true);  // switching overflow/underflow bins on
2895      
2896 <  
2896 >  switch_overunderflow(true);
2897      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2898    for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2899      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
# Line 957 | Line 2906 | void region_comparison_plots(string mcjz
2906      make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2907  
2908      make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2909 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2909 >    make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2910      make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2911      make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2912      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
# Line 989 | Line 2938 | void signal_bg_comparison()
2938    
2939    float simulatedlumi=luminosity;//in pb please - adjust to your likings
2940    
2941 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
2941 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2942    TH1F *JZBplotLM4;
2943    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"));
2944    else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2945 <  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
2945 >  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TT_"));
2946    
2947    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
2948    JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
# Line 1004 | Line 2953 | void signal_bg_comparison()
2953  
2954    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2955    JZBplotTtbar->SetMinimum(0.01);
2956 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2956 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2957    JZBplotTtbar->DrawClone("histo");
2958    JZBplotZJETs->Draw("histo,same");
2959    JZBplotTtbar->SetFillColor(0);
2960    JZBplotTtbar->DrawClone("histo,same");
2961 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2961 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2962    JZBplotLM4->Draw("histo,same");
2963  
2964  
# Line 1047 | Line 2996 | void signal_bg_comparison()
2996    // Draw all plots overlaid
2997    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2998    JZBplotTtbar->SetMinimum(0.01);
2999 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2999 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
3000    JZBplotTtbar->DrawClone("histo");
3001    JZBplotZJETs->Draw("histo,same");
3002    JZBplotTtbar->SetFillColor(0);
3003    JZBplotTtbar->DrawClone("histo,same");
3004 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
3004 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
3005  
3006    JZBplotSMS1->SetLineColor(kRed+1);
3007    JZBplotSMS2->SetLineColor(kBlue+1);
# Line 1259 | Line 3208 | if you want to start from scratch (witho
3208    return return_functions;
3209   }
3210  
3211 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3211 > void do_prediction_plot(TCut addcut, string Cname, string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3212   {
3213 < //  switch_overunderflow(true);
3213 >  
3214    bool is_data=false;
3215    bool use_signal=false;
3216    if(use_data==1) is_data=true;
3217    if(use_data==2) use_signal=true;
3218 <  int nbins=50;//100;
3219 <  if(is_data) nbins=50;
3218 >  int nbins=int(high/10);//100;
3219 >  if(is_data) nbins=int(high/10);
3220    float low=0;
3221 <  float hi=500;
3221 >  float hi=high;
3222 >  
3223 >  stringstream cutpositiveS;
3224 >  cutpositiveS << "(" << jzb << ">0)";
3225 >  TCut cutpositive(cutpositiveS.str().c_str());
3226 >  stringstream cutnegativeS;
3227 >  cutnegativeS << "(" << jzb << "<0)";
3228 >  TCut cutnegative(cutnegativeS.str().c_str());
3229 >  
3230    
3231    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3232 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3233 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3234 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3235 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3232 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3233 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3234 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3235 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3236  
3237    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3238    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1290 | Line 3247 | void do_prediction_plot(string jzb, TCan
3247    
3248    TH1F *RcorrJZBeemmNoS;
3249  
3250 <    //these are for the ratio
3251 <  
3252 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3253 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3254 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1298 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3250 >  //these are for the ratio
3251 >  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3252 >  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3253 >  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3254 >  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3255    
3256    TH1F *JRcorrJZBSBem;
3257    TH1F *JLcorrJZBSBem;
3258    TH1F *JRcorrJZBSBeemm;
3259    TH1F *JLcorrJZBSBeemm;
3260    
3261 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
3261 >  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
3262  
3263    
3264    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3265 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3266 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3267 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3268 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3265 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3266 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3267 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3268 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3269      
3270      //these are for the ratio
3271 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3272 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3273 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3274 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3271 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3272 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3273 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3274 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3275    }
3276    
3277    TH1F *lm4RcorrJZBeemm;
3278 <  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
3278 >  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
3279    
3280    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3281    
# Line 1383 | Line 3339 | void do_prediction_plot(string jzb, TCan
3339    SQRT(BpredSys);
3340    BpredSys->Divide(JBpred);
3341  
1386  
3342    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
3343    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
3344    Tpred->Add(LcorrJZBem,-1.0);
# Line 1436 | Line 3391 | void do_prediction_plot(string jzb, TCan
3391      Bpred->Draw("hist,same");
3392      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3393      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3394 <    lm4RcorrJZBeemm->Draw("hist,same");
3394 >    //lm4RcorrJZBeemm->Draw("hist,same");
3395      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
3396      legBpred->AddEntry(Bpred,"predicted","l");
3397   //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
3398   //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
3399 <    legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
3399 > //     legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
3400      legBpred->Draw();
3401      DrawPrelim();
3402  
# Line 1451 | Line 3406 | void do_prediction_plot(string jzb, TCan
3406      Bpred->SetLineWidth(2);
3407      predcomppad->cd();
3408      predcomppad->SetLogy(1);
1454    
3409      TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
3410      TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
3411      sidebandsemu->Add(jzbnegative,-1);
3412      
3413      jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3414      jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3415 <    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3416 <    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3415 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3416 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3417      
3418      THStack predcomposition("predcomposition","prediction composition");
3419      predcomposition.Add(sidebandsemu);
# Line 1473 | Line 3427 | void do_prediction_plot(string jzb, TCan
3427   //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
3428      lm4RcorrJZBeemm->SetLineWidth(2);
3429      //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
3430 <    lm4RcorrJZBeemm->Draw("histo,same");
3430 > //     lm4RcorrJZBeemm->Draw("histo,same");
3431      DrawPrelim();
3432      TLegend *speciallegBpred = make_legend("",0.45,0.55);
3433      //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
# Line 1483 | Line 3437 | void do_prediction_plot(string jzb, TCan
3437      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
3438      else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
3439   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3440 <    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3440 > //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3441      speciallegBpred->Draw();
3442 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3442 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition"+Cname,true,true,"data/pred",BpredSys);
3443 >    delete predcomppad;
3444      
3445      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3446      specialcanv->SetLogy(1);
3447   //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
3448      blankback->Draw();
3449   //    kostack.Draw("same");
3450 <    predcomposition.Draw();
3450 >    predcomposition.Draw("hist");
3451      Bpred->Draw("hist,same");
3452      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3453      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
# Line 1519 | Line 3474 | void do_prediction_plot(string jzb, TCan
3474      legBpred->AddEntry(Bpred,"MC predicted","l");    
3475      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
3476      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
3477 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3477 > //     if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3478      legBpred->Draw();
3479      DrawMCPrelim();
3480      Bpredsaveas="Bpred_MC";
# Line 1564 | Line 3519 | void do_prediction_plot(string jzb, TCan
3519    }
3520  
3521  
3522 +  Bpredsaveas+="_"+Cname+"_";
3523    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3524    string ytitle("ratio");
3525    if ( use_data==1 ) ytitle = "data/pred";
3526    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3527 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3527 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3528 >  
3529 >  delete kinpad;
3530 >
3531  
3532    
3533    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
# Line 1609 | Line 3568 | void do_prediction_plot(string jzb, TCan
3568      if(use_data==1)
3569      {
3570        legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3571 <      legBpredc->AddEntry(Bpredem,"OFZP","l");
3572 <      legBpredc->AddEntry(BpredSBem,"OFSB","l");
3573 <      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3571 >      if(RestrictToMassPeak) {
3572 >        legBpredc->AddEntry(Bpredem,"OFZP","l");
3573 >        legBpredc->AddEntry(BpredSBem,"OFSB","l");
3574 >        legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3575 >      } else legBpredc->AddEntry(Bpredem,"OF","l");
3576 >        
3577 >        
3578        legBpredc->Draw();
3579        CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3580      }
3581      if(use_data==0) {
3582        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3583 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3584 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3585 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3583 >      if(RestrictToMassPeak) {
3584 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3585 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3586 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3587 >      } else legBpredc->AddEntry(Bpredem,"MC OF","l");
3588 >        
3589        legBpredc->Draw();
3590        CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3591      }
3592      if(use_data==2) {
3593        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3594 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3595 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3596 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3597 <      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3594 >      if(RestrictToMassPeak) {
3595 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3596 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3597 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3598 >      } else {
3599 >        legBpredc->AddEntry(Bpredem,"MC OF","l");
3600 >      }
3601 > //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3602        legBpredc->Draw();
3603        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3604      }
3605    }
3606    
1637  TFile *f = new TFile("tester.root","RECREATE");
1638  RcorrJZBeemm->Write();
1639  Bpred->Write();
1640  f->Close();
1641  
3607    delete RcorrJZBeemm;
3608    delete LcorrJZBeemm;
3609    delete RcorrJZBem;
# Line 1664 | Line 3629 | void do_prediction_plot(string jzb, TCan
3629      delete JLcorrJZBSBeemm;
3630    }
3631    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1667  switch_overunderflow(false);
3632   }
3633  
3634   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3635 <  TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
1672 <  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
1673 <  if ( !PlottingSetup::Approved ) {
1674 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
1675 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
1676 <  } else {
1677 <    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
1678 <  }
1679 < }
1680 <
1681 < void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1682 <  bool do_data=0;
1683 <  bool dosignal=0;
1684 <  if(is_data==1) do_data=1;
1685 <  if(is_data==2) dosignal=1;
1686 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1687 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1688 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1689 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
3635 >  switch_overunderflow(true);
3636    
3637 <  TH1F *RcorrJZBSBem;
3638 <  TH1F *LcorrJZBSBem;
1693 <  TH1F *RcorrJZBSBeemm;
1694 <  TH1F *LcorrJZBSbeemm;
3637 >  TCut cuts[3] = {TCut("mll>0"),Restrmasscut,TCut("mll>20&&mll<70")};
3638 >  string cutnames[3] = {"NoMassCut","ZWindow","LowMassRegion2070"};
3639    
3640 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3641 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
3642 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
3643 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
3644 <    LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
3645 <  }
3646 <  
3647 <
3648 <
1705 <
1706 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1707 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1708 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
1709 <    Bpred->Add(RcorrJZBem,1.0/3);
1710 <    Bpred->Add(LcorrJZBem,-1.0/3);
1711 <    Bpred->Add(RcorrJZBSBem,1.0/3);
1712 <    Bpred->Add(LcorrJZBSBem,-1.0/3);
1713 <    Bpred->Add(RcorrJZBSBeemm,1.0/3);
1714 <    Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1715 <  } else {
1716 <    Bpred->Add(RcorrJZBem,1.0);
1717 <    Bpred->Add(LcorrJZBem,-1.0);
3640 >  TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3641 >  for(int i=0;i<3;i++) {
3642 >    do_prediction_plot(cuts[i],cutnames[i],datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3643 >    if ( !PlottingSetup::Approved ) {
3644 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3645 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3646 >    } else {
3647 >      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3648 >    }
3649    }
1719
1720  can->cd();
1721  can->SetLogy(0);
1722  Bpred->SetLineColor(kRed);
1723  Bpred->SetStats(0);
1724  if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1725  TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1726  JZBratioforfitting->Divide(Bpred);
1727  TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1728  
1729  
1730  JZBratio->SetTitle("");
1731  JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1732 //  if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1733  
1734  TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1735  TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1736 //  straightline_fit->SetParameter(0,1);
1737  JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1738  pol0d->SetParameter(0,pol0->GetParameter(0));
1739  
1740  JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1741  JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1742  if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1743  JZBratio->GetYaxis()->SetNdivisions(519);
1744  JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1745  JZBratio->GetYaxis()->CenterTitle();
1746  JZBratio->GetXaxis()->CenterTitle();
1747  JZBratio->SetMarkerSize(DataMarkerSize);
1748  JZBratio->Draw("AP");
1749  /////----------------------------
1750  TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1751  writeresult->SetFillStyle(4000);
1752  writeresult->SetFillColor(kWhite);
1753  writeresult->SetTextFont(42);
1754  writeresult->SetTextSize(0.03);
1755  writeresult->SetTextAlign(12);
1756  ostringstream jzb_agreement_data_text;
1757  jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) <<  pol0->GetParError(0);
1758  if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1759  if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1760 /*  if(is_data) writeresult->AddText("Data closure test");
1761  else writeresult->AddText("MC closure test");
1762  */
1763  writeresult->AddText(jzb_agreement_data_text.str().c_str());
1764 //  writeresult->Draw("same");
1765 //  pol0d->Draw("same");
1766  TF1 *topline =  new TF1("","1.5",0,1000);
1767  TF1 *bottomline =  new TF1("","0.5",0,1000);
1768  topline->SetLineColor(kBlue);
1769  topline->SetLineStyle(2);
1770  bottomline->SetLineColor(kBlue);
1771  bottomline->SetLineStyle(2);
1772 //  topline->Draw("same");
1773 //  bottomline->Draw("same");
1774  TF1 *oneline = new TF1("","1.0",0,1000);
1775  oneline->SetLineColor(kBlue);
1776  oneline->SetLineStyle(1);
1777  oneline->Draw("same");
1778  TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
1779  if(is_data==1) DrawPrelim();
1780  else DrawMCPrelim();
1781  TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1782  leg->SetTextFont(42);
1783  leg->SetTextSize(0.04);
1784 //   if(is_data==1) leg->SetHeader("Ratio (data)");
1785 //   else leg->SetHeader("Ratio (MC)");
1786
1787  TString MCtitle("MC ");
1788  if (is_data==1) MCtitle = "";
1789
1790  leg->SetFillStyle(4000);
1791  leg->SetFillColor(kWhite);
1792  leg->SetTextFont(42);
1793 //  leg->AddEntry(topline,"+20\% sys envelope","l");
1794  leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1795  leg->AddEntry(oneline,"ratio = 1","l");
1796 //  leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1797 //  leg->AddEntry(bottomline,"#pm50% envelope","l");
1798
1799
1800  //leg->Draw("same"); // no longer drawing legend
1801
1802  if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1803  if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1804  if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
3650    
3651 <  delete RcorrJZBeemm;
3652 <  delete LcorrJZBeemm;
1808 <  delete RcorrJZBem;
1809 <  delete LcorrJZBem;
1810 <  
1811 <  delete RcorrJZBSBem;
1812 <  delete LcorrJZBSBem;
1813 <  delete RcorrJZBSBeemm;
1814 <  delete LcorrJZBSbeemm;
1815 < }
1816 <
1817 < void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1818 <  TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1819 <  globalc->SetLogy(0);
1820 <  
1821 <  do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh  );
1822 <  do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh  );
1823 <  do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh  );
3651 >  delete globalcanvas;
3652 >  switch_overunderflow(false);
3653   }
3654  
3655   string give_jzb_expression(float peak, int type) {
# Line 1843 | Line 3672 | void lepton_comparison_plots() {
3672    Float_t ymin = 1.e-5, ymax = 0.25;
3673    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3674    can->SetLogy(1);
3675 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
3676 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
3675 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3676 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3677    eemc->SetLineColor(kBlue);
3678    mmmc->SetLineColor(kRed);
3679    eemc->SetMinimum(0.1);
# Line 1907 | Line 3736 | void lepton_comparison_plots() {
3736    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3737    eemmlegend->Draw();
3738    DrawPrelim();
3739 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3739 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3740    
3741 <  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"));
3742 <  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"));
3743 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
3741 >  TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3742 >  TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3743 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3744    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3745    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3746    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 2008 | Line 3837 | void draw_pure_jzb_histo(TCut cut,string
3837    datahisto->SetMinimum(0.1);
3838    datahisto->SetMarkerSize(DataMarkerSize);
3839    datahisto->Draw("e1");
3840 <  mcstack.Draw("same");
3840 >  mcstack.Draw("histo,same");
3841    datahisto->Draw("same,e1");
3842    
3843    TLegend *leg;
# Line 2030 | Line 3859 | void draw_pure_jzb_histo(TCut cut,string
3859    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3860    writeline1->SetTextSize(0.035);
3861    writeline1->Draw();
3862 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3863 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3862 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3863 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3864    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3865    jzbpad2->cd();
3866    jzbpad2->SetLogy(1);
# Line 2039 | Line 3868 | void draw_pure_jzb_histo(TCut cut,string
3868    datahisto->SetMinimum(0.1);
3869    datahisto->SetMarkerSize(DataMarkerSize);
3870    datahisto->Draw("e1");
3871 <  mcstack.Draw("same");
3871 >  mcstack.Draw("histo,same");
3872    datahisto->Draw("same,e1");
3873    leg->SetHeader("");
3874    leg->Draw();
3875    writeline1->SetTextSize(0.035);
3876    writeline1->Draw();
3877    DrawPrelim();
3878 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3879 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3878 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3879 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3880    datahisto->Delete();
3881    mcstack.Delete();
3882   }
# Line 2088 | Line 3917 | void produce_stretched_jzb_plots(string
3917    
3918  
3919   void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3920 +  switch_overunderflow(true);
3921    vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3922    
3923    if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
# Line 2114 | Line 3944 | void diboson_plots(string mcjzb, string
3944    TCanvas *gloca = new TCanvas("gloca","gloca");
3945    
3946    dout << "Going to produce prediction plots" << endl;
3947 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3948 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3947 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3948 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3949    delete gloca;
3950  
3951    dout << "Going to reset the cross section for diboson samples ... " << endl;
# Line 2127 | Line 3957 | void diboson_plots(string mcjzb, string
3957      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;
3958      
3959    }
3960 <  
3960 > //   switch_overunderflow(false);
3961   }
3962  
3963  
# Line 2154 | Line 3984 | void draw_normalized_data_vs_data_histo(
3984    leg->AddEntry(datahisto2,legentry2.c_str());
3985    leg->Draw();
3986    
3987 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3987 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3988    
3989    datahisto1->Delete();
3990    datahisto2->Delete();
# Line 2162 | Line 3992 | void draw_normalized_data_vs_data_histo(
3992  
3993  
3994   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3995 +  switch_overunderflow(true);
3996    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3997    float max=jzbHigh ;
3998    float min=-120;
# Line 2198 | Line 4029 | void jzb_plots(string mcjzb, string data
4029      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
4030    }
4031    delete can;
4032 +  switch_overunderflow(false);
4033   }
4034  
4035  
# Line 2241 | Line 4073 | string jzb_tex_command(string region, st
4073   //  \SFZPJZBPOS
4074   //  Sample &  \OFZPJZBPOS  & \OFZPJZBNEG &  \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS  & \OFSBJZBNEG  & \SFSBJZBPOS  & \SFSBJZBNEG  \\\hline
4075    
4076 +  
4077 + void compute_Improved_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4078 +  dout << "Calculating background yields in MC:" << endl;
4079 +  
4080 +  TCanvas *yica = new TCanvas("yica","yield canvas");
4081 +  
4082 +  int nRegions=2;
4083 +  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
4084 +  string tsRegions[] = {"SFZP","OFZP"};
4085 +  string posneg[] = {"pos","neg"};
4086 +  TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass};
4087 +
4088 +  
4089 +  
4090 +  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
4091 +    TCut posJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos");
4092 +    TCut negJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg");
4093 +    
4094 +    dout << "_________________________________________________________" << endl;
4095 +    dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
4096 +    
4097 +    
4098 +    THStack *spstack = new THStack(allsamples.DrawStack("spstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4099 +    THStack *snstack = new THStack(allsamples.DrawStack("snstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4100 +    THStack *opstack = new THStack(allsamples.DrawStack("opstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4101 +    THStack *onstack = new THStack(allsamples.DrawStack("onstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4102 +    
4103 +    
4104 +    vector<pair<string,Value> > obs_yields     = WriteYield(spstack, -10, 10, true);
4105 +    vector<pair<string,Value> > neg_sf_yields  = WriteYield(snstack, -10, 10, true);
4106 +    vector<pair<string,Value> > pos_of_yields  = WriteYield(opstack, -10, 10, true);
4107 +    vector<pair<string,Value> > neg_of_yields  = WriteYield(onstack, -10, 10, true);
4108 +    
4109 +    Value TotObs=Value(0,0);
4110 +    Value TotPred=Value(0,0);
4111 +    
4112 +    for(int ientry=0;ientry<obs_yields.size();ientry++) {
4113 +      if(Contains(obs_yields[ientry].first,"t_bar_t")) continue; // ttbar
4114 +      if(Contains(obs_yields[ientry].first,"W_Jets")) continue; // W+Jets
4115 +      if(Contains(obs_yields[ientry].first,"WW_")) continue; // WW (fully flavor symmetric)
4116 +      if(Contains(obs_yields[ientry].first,"Single_top")) continue; // Single Top
4117 +      if(Contains(obs_yields[ientry].first,"ee_mumu")) continue; // DY
4118 +      if(Contains(obs_yields[ientry].first,"tau_tau")) continue; // DY
4119 +      Value pred = neg_sf_yields[ientry].second + pos_of_yields[ientry].second - neg_of_yields[ientry].second;
4120 +      Value obs=obs_yields[ientry].second;
4121 +      Value diff=obs-pred;
4122 +      dout << obs_yields[ientry].first << "\t & \t " << obs << " \t & \t " << pred << "\t & \t " << diff << endl;
4123 +      TotObs=TotObs+obs_yields[ientry].second;
4124 +      TotPred=TotPred+pred;
4125 +    }
4126 +    
4127 +    float Systematic=sqrt(pow(TotPred.getValue(),2)*0.5*0.5 + pow(TotObs.getValue(),2)*0.5*0.5);
4128 +
4129 +        
4130 +  }
4131 +  
4132 +  delete yica;
4133 + }
4134 +      
4135   void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4136    dout << "Calculating background yields in MC:" << endl;
4137    
# Line 2336 | Line 4227 | void draw_ttbar_and_zjets_shape_for_one_
4227    TText *titlecenter;
4228    bool frommc=false;
4229    if(frommc) {
4230 <    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
4230 >    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TT_"));
4231      titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
4232    }
4233    else {
# Line 2553 | Line 4444 | float find_one_correction_factor(string
4444      (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
4445      (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
4446    }
4447 +  
4448    niceresponseplotd->Add(emuResponse,-1);
4449    
4450 +  //TF1 *resp_func = new TF1("resp_func","[0]+[1]/x + [2]/pow(x,2)",10,600);
4451 +  
4452    niceresponseplotd->SetStats(0);
4453    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
4454    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 2564 | Line 4458 | float find_one_correction_factor(string
4458    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
4459    profd->Rebin(2);
4460    profd->SetMarkerSize(DataMarkerSize);
4461 +  //profd->Fit(resp_func,"","same,e1",10,400);
4462    profd->Fit("pol0","","same,e1",100,400);
4463 +  //resp_func->SetLineColor(kBlue);
4464    DrawPrelim();
4465    string stitle="Data";
4466    if(!Contains(FindKeyword,"Data")) stitle="MC";
4467    TText* title = write_text(0.5,0.7,stitle.c_str());
4468    title->SetTextAlign(12);
4469    title->Draw();
4470 + //  TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4471    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4472    float correction=datapol->GetParameter(0);
4473 +  
4474 + //  float correction=resp_func->GetParameter(0);
4475    stringstream resstring;
4476    resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
4477    TText* restitle = write_text(0.5,0.65,resstring.str());
# Line 2593 | Line 4492 | void find_correction_factors(string &jzb
4492    float datacorrection=find_one_correction_factor("Data",true,"","Data");
4493    float mccorrection=find_one_correction_factor("DY",false,"","MC");
4494    
4495 <  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4495 > /*  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4496    float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
4497    
4498    float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
4499    float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
4500 <  
4500 >  */
4501    cout << "Corrections : " << endl;
4502    cout << "   Data : " << datacorrection << endl;
4503 <  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4503 > //   cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4504    cout << "   MC : " << mccorrection << endl;
4505 <  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4505 > //   cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4506    
4507    //Step 2: Processing the result and making it into something useful :-)
4508    stringstream jzbvardatas;
4509 +  /*
4510    jzbvardatas << "(";
4511    
4512    if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
# Line 2622 | Line 4522 | void find_correction_factors(string &jzb
4522    
4523    jzbvardatas << ")";
4524    jzbvardata=jzbvardatas.str();
4525 <  
4525 >  */
4526    stringstream jzbvarmcs;
4527 +  /*
4528    jzbvarmcs << "(";
4529 <  
4529 >
4530    if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4531    if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4532    
# Line 2639 | Line 4540 | void find_correction_factors(string &jzb
4540    
4541    jzbvarmcs << ")";
4542    jzbvarmc=jzbvarmcs.str();
4543 <
4543 >  */
4544 >  
4545 >  if(datacorrection>=1) jzbvardatas<<"(jzb[1]-" << datacorrection-1 << "*pt)";
4546 >  if(datacorrection<1)  jzbvardatas<<"(jzb[1]+" << 1-datacorrection << "*pt)";
4547 >  
4548 >  if(mccorrection>=1) jzbvarmcs<<"(jzb[1]-" << mccorrection-1 << "*pt)";
4549 >  if(mccorrection<1)  jzbvarmcs<<"(jzb[1]+" << 1-mccorrection << "*pt)";
4550 >  
4551 >  jzbvardata = jzbvardatas.str();
4552 >  jzbvarmc = jzbvarmcs.str();
4553 >  
4554    dout << "JZB Z pt correction summary : " << endl;
4555    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
4556    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
4557    
4558   }
4559  
4560 < void pick_up_events(string cut) {
4561 <  dout << "Picking up events with cut " << cut << endl;
2651 <  allsamples.PickUpEvents(cut);
4560 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
4561 >  allsamples.PickUpEvents(cut,filename,QuietMode);
4562   }
4563  
4564   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2734 | Line 4644 | void draw_all_ttbar_histos(TCanvas *can,
4644    }
4645   }
4646  
4647 < void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
4647 > void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring, TCut cut) {
4648    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4649    //in the case of the OFF peak analysis, we compare our control region to the real value
4650    TCut weightbackup=cutWeight;
4651 +  switch_overunderflow(true);
4652    
4653 <  bool doPURW=false;
4653 >  bool doPURW=true;
4654    
4655    
4656    if(!doPURW) {
# Line 2759 | Line 4670 | void ttbar_sidebands_comparison(string m
4670        
4671    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4672  
4673 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4674 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4673 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4674 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4675    TH1F *TSem;
4676    TH1F *nTSem;
4677 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4678 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4677 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4678 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4679    TH1F *TSeemm;
4680    TH1F *nTSeemm;
4681    
4682    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4683 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4684 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4685 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4686 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4683 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4684 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4685 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4686 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4687    }
4688  
4689    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 2804 | Line 4715 | void ttbar_sidebands_comparison(string m
4715      histos.push_back(TSem);
4716      histos.push_back(TSeemm);
4717    }
4718 <  draw_all_ttbar_histos(tcan,histos,"histo",1);
4718 >  draw_all_ttbar_histos(tcan,histos,"histo",8);
4719    
4720    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4721    leg->AddEntry(TZeemm,"SFZP","l");
# Line 2816 | Line 4727 | void ttbar_sidebands_comparison(string m
4727    leg->Draw("same");
4728    DrawMCPrelim(simulatedlumi);
4729    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
4730 +  
4731    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
4732    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
4733    TH1F *TSeemmcopy;
# Line 2881 | Line 4793 | void ttbar_sidebands_comparison(string m
4793    DrawMCPrelim(simulatedlumi);
4794    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4795    
4796 +  
4797    if (0) { // Turn this off: we don't need this
4798  
4799      ///-------------- second part: only look at the quantity we actually care about!
# Line 2986 | Line 4899 | void ttbar_sidebands_comparison(string m
4899  
4900    delete tcan;
4901    cutWeight=weightbackup;
4902 +  switch_overunderflow(false);
4903   }
4904  
4905   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
# Line 3020 | Line 4934 | void ttbar_sidebands_comparison(string m
4934    nicer_binning.push_back(150);
4935    //nicer_binning.push_back(175);
4936    nicer_binning.push_back(200);
4937 <  nicer_binning.push_back(250);
4938 <  nicer_binning.push_back(300);
4939 <  nicer_binning.push_back(400);
4937 > //  nicer_binning.push_back(250);
4938 > //  nicer_binning.push_back(300);
4939 > //  nicer_binning.push_back(400);
4940 >  
4941 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/",TCut("mll>0"));
4942 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/CutAt20",TCut("mll>20"));
4943 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/LowMassRegion2070",TCut("mll>20&&mll<70"));
4944 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/ZWindow",Restrmasscut);
4945    
3027  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4946   }
4947  
4948  
4949 < void zjets_prediction_comparison(string mcjzbWithPUa) {
4949 > void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4950 >  cout << "****************************************************************************************************************************************************************" << endl;
4951    TCanvas *zcan = new TCanvas("zcan","zcan");  
3033 //  zcan->SetLogy(1);
4952    TCut weightbackup=cutWeight;
4953    
4954 <  bool UsePURW=false;
4954 >  bool UsePURW=true;
4955    
4956    
4957    string mcjzb;
4958    if(UsePURW) {
4959      mcjzb=mcjzbWithPUa;
4960 +    cout << "Using PURW peak positions" << endl;
4961    } else {
4962      // Do it without PU re-weighting
4963 +    cutWeight="1.0";
4964      float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4965      stringstream resultsNoPU;
4966      stringstream noPUdatajzb;
# Line 3051 | Line 4971 | void zjets_prediction_comparison(string
4971      
4972      mcjzb = noPUmcjzb.str();
4973      
3054    cutWeight="1.0";
4974    }
4975  
4976    
4977 +  
4978    vector<float> binning;
4979    binning.push_back(0);
4980    binning.push_back(10);
4981 <  binning.push_back(20);
4982 <  binning.push_back(40);
4983 <  binning.push_back(60);
4984 < //   binning.push_back(50);
4981 >  binning.push_back(30);
4982 > //  binning.push_back(40);
4983 > //  binning.push_back(60);
4984 >   binning.push_back(50);
4985   //   binning.push_back(60);
4986   //   binning.push_back(70);
4987   //   binning.push_back(80);
# Line 3072 | Line 4992 | void zjets_prediction_comparison(string
4992    
4993    TCut kPos((mcjzb+">0").c_str());
4994    TCut kNeg((mcjzb+"<0").c_str());
4995 +  TCut reducedNJets(cutnJets);
4996    string var( "abs("+mcjzb+")" );
4997    
3077  TCut notTau("abs(genMID1)!=15");
3078  TCut ONLYTau("mll>20");
4998    
4999 <
5000 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
5001 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4999 >  TCut notTau("!EventZToTaus");
5000 >  TCut ee_mm_tautau("mll>0");
5001 >  
5002 >  TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5003 >  TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5004    
5005    hJZBpos->SetLineColor(kBlack);
5006    hJZBneg->SetLineColor(kRed);
# Line 3094 | Line 5015 | void zjets_prediction_comparison(string
5015    leg->AddEntry(hJZBneg,"Predicted","l");
5016    leg->Draw("same");
5017    DrawMCPrelim(simulatedlumi);
5018 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
5018 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
5019    
5020    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
5021    hratio->Divide(hJZBneg);
5022    
5023    for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
5024 <    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
5024 >    cout << "Positive: " << hJZBpos->GetBinContent(i) << " +/- " << hJZBpos->GetBinError(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << " +/- " << hJZBneg->GetBinError(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << " +/- " << (hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i)) * sqrt(pow(hJZBpos->GetBinError(i)/hJZBpos->GetBinContent(i),2) + pow(hJZBneg->GetBinError(i)/hJZBneg->GetBinContent(i),2)) << ")" << endl;
5025    }
5026    
5027 <  zcan->SetLogy(0);
5028 <  hratio->GetYaxis()->SetRangeUser(0,2.0);
5027 > //  zcan->SetLogy(0);
5028 >  hratio->GetYaxis()->SetRangeUser(0,2.5);
5029    hratio->GetYaxis()->SetTitle("Observed/Predicted");
5030    hratio->Draw("e1");
5031    
5032 <  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
5032 >  TLine *top = new TLine(binning[0],1.2,binning[binning.size()-1],1.2);
5033    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5034 <  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
5034 >  TLine *bottom = new TLine(binning[0],0.8,binning[binning.size()-1],0.8);
5035    
5036  
5037    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 3126 | Line 5047 | void zjets_prediction_comparison(string
5047    leg2->AddEntry(bottom,"syst. envelope","l");
5048    leg2->Draw("same");
5049    DrawMCPrelim(simulatedlumi);
5050 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
3130 <  
3131 <  TCut reducedNJets(cutnJets);
5050 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
5051    
5052 <  TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
5053 <  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
5054 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
5055 <  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
5052 >  TH1F *TAUhJZBpos       = allsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5053 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5054 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5055 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5056  
5057    TH1F *RcorrJZBSBem;
5058    TH1F *LcorrJZBSBem;
# Line 3141 | Line 5060 | void zjets_prediction_comparison(string
5060    TH1F *LcorrJZBSBeemm;
5061  
5062    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5063 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
5064 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
5065 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
5066 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
5063 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5064 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5065 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5066 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5067    }
5068    
5069    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3175 | Line 5094 | void zjets_prediction_comparison(string
5094    TAUleg->AddEntry(Bpred,"Predicted","l");
5095    TAUleg->Draw("same");
5096    DrawMCPrelim(simulatedlumi);
5097 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
5097 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
5098    
5099    TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
5100    TAUhratio->Divide(Bpred);
5101    
5102    for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
5103 <    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
5103 >    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << " +/- " << TAUhJZBpos->GetBinError(i) << "   vs    Negative : " << Bpred->GetBinContent(i) << " +/- " << Bpred->GetBinError(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << " +/- " << (TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i)) * sqrt(pow(TAUhJZBpos->GetBinError(i)/TAUhJZBpos->GetBinContent(i),2) + pow(Bpred->GetBinError(i)/Bpred->GetBinContent(i),2)) << ")" << endl;
5104 >    
5105 >    
5106    }
5107    
5108    zcan->SetLogy(0);
# Line 3193 | Line 5114 | void zjets_prediction_comparison(string
5114    center->Draw("same");
5115    bottom->Draw("same");
5116    
5117 <  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
5117 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
5118    TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
5119    TAUleg2->AddEntry(bottom,"syst. envelope","l");
5120    TAUleg2->Draw("same");
5121    DrawMCPrelim(simulatedlumi);
5122 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
5122 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
5123    
5124    delete Bpred;
5125    delete TAUhJZBpos;
5126    delete LcorrJZBeemm;
5127    delete RcorrJZBem;
5128    delete LcorrJZBem;
5129 +  delete hJZBpos;
5130 +  delete hJZBneg;
5131    
5132    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5133      delete RcorrJZBSBem;
# Line 3213 | Line 5136 | void zjets_prediction_comparison(string
5136      delete LcorrJZBSBeemm;
5137    }
5138    
5139 +  //***************************************************************************************************
5140 +  
5141 +  string jzbvar=var;
5142 +  /*
5143 +  for(int i=0;i<60;i+=10) {
5144 +    stringstream sSpecialJZBCut;
5145 +    sSpecialJZBCut << jzbvar << ">" << i;
5146 +  TCut SpecialJZBCut(sSpecialJZBCut.str().c_str());
5147 +  
5148 +  var="mll";
5149 +  
5150 +  TH1F *FullJZBhJZBpos       = allsamples.Draw("FullJZBhJZBpos",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5151 +  TH1F *LcorrJZBPluseemm     = allsamples.Draw("LcorrJZBPluseemm",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5152 +  TH1F *RcorrJZBPlusem       = allsamples.Draw("RcorrJZBPlusem",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5153 +  TH1F *LcorrJZBPlusem       = allsamples.Draw("LcorrJZBPlusem",var,10,0,200, "m_{ll} [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5154 +
5155 +  TH1F *RcorrJZBPlusSBem;
5156 +  TH1F *LcorrJZBPlusSBem;
5157 +  TH1F *RcorrJZBPlusSBeemm;
5158 +  TH1F *LcorrJZBPlusSBeemm;
5159 +
5160 +  
5161 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5162 +    RcorrJZBPlusSBem   = allsamples.Draw("RcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5163 +    LcorrJZBPlusSBem   = allsamples.Draw("LcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5164 +    RcorrJZBPlusSBeemm = allsamples.Draw("RcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5165 +    LcorrJZBPlusSBeemm = allsamples.Draw("LcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5166 +  }
5167 +  
5168 +  TH1F *BpredPrime = (TH1F*)LcorrJZBPluseemm->Clone("BpredPrime");
5169 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5170 +    BpredPrime->Add(RcorrJZBPlusem,1.0/3.);
5171 +    BpredPrime->Add(LcorrJZBPlusem,-1.0/3.);
5172 +    BpredPrime->Add(RcorrJZBPlusSBem,1.0/3.);
5173 +    BpredPrime->Add(LcorrJZBPlusSBem,-1.0/3.);
5174 +    BpredPrime->Add(RcorrJZBPlusSBeemm,1.0/3.);
5175 +    BpredPrime->Add(LcorrJZBPlusSBeemm,-1.0/3.);
5176 +  } else {
5177 +    BpredPrime->Add(RcorrJZBPlusem,1.0);
5178 +    BpredPrime->Add(LcorrJZBPlusem,-1.0);
5179 +  }
5180 +  
5181 +  BpredPrime->SetLineColor(kRed);
5182 +
5183 +  FullJZBhJZBpos->SetLineColor(kBlack);
5184 +  BpredPrime->SetLineColor(kRed);
5185 +  
5186 +  FullJZBhJZBpos->SetMinimum(1.0);
5187 +  FullJZBhJZBpos->Draw("e1");
5188 +  BpredPrime->Draw("same,hist");
5189 +  FullJZBhJZBpos->Draw("same,e1");
5190 +  
5191 +  TLegend *FullJZBleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
5192 +  FullJZBleg->AddEntry(FullJZBhJZBpos,"Observed","pe");
5193 +  FullJZBleg->AddEntry(BpredPrime,"Predicted","l");
5194 +  FullJZBleg->Draw("same");
5195 +  DrawMCPrelim(simulatedlumi);
5196 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"_zjets_eemumu_prediction__"+any2string(massregionname));
5197 +  
5198 +  TH1F* FullJZBhratio = (TH1F*)FullJZBhJZBpos->Clone("FullJZBhratio");
5199 +  FullJZBhratio->Divide(BpredPrime);
5200    
5201 +  zcan->SetLogy(0);
5202 +  FullJZBhratio->GetYaxis()->SetRangeUser(0,2.5);
5203 +  FullJZBhratio->GetYaxis()->SetTitle("Observed/Predicted");
5204 +  FullJZBhratio->Draw("e1");
5205 +  
5206 +  TLine *atop = new TLine(0,1.2,200,1.2);
5207 +  TLine *acenter = new TLine(0,1.0,200,1.0);
5208 +  TLine *abottom = new TLine(0,0.8,200,0.8);
5209 +  
5210 +  atop->SetLineColor(kBlue);
5211 +  atop->SetLineStyle(2);
5212 +  acenter->SetLineColor(kBlue);
5213 +  abottom->SetLineColor(kBlue);
5214 +  abottom->SetLineStyle(2);
5215 +  
5216 +  atop->Draw("same");
5217 +  acenter->Draw("same");
5218 +  abottom->Draw("same");
5219 +  
5220 +  TLegend *FullJZBleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
5221 +  FullJZBleg2->AddEntry(FullJZBhratio,"obs / pred","pe");
5222 +  FullJZBleg2->AddEntry(abottom,"syst. envelope","l");
5223 +  FullJZBleg2->Draw("same");
5224 +  DrawMCPrelim(simulatedlumi);
5225 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"zjets_eemumu_prediction_ratio"+any2string(massregionname));
5226 +  
5227 +  
5228 +  delete BpredPrime;
5229 +  delete FullJZBhJZBpos;
5230 +  delete LcorrJZBPluseemm;
5231 +  delete RcorrJZBPlusem;
5232 +  delete LcorrJZBPlusem;
5233 + //  delete FullJZBhJZBpos;
5234 +  
5235 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5236 +    delete RcorrJZBPlusSBem;
5237 +    delete LcorrJZBPlusSBem;
5238 +    delete RcorrJZBPlusSBeemm;
5239 +    delete LcorrJZBPlusSBeemm;
5240 +  }
5241 +  
5242 +  }
5243 +  //***************************************************************************************************
5244 +  */
5245    delete zcan;
5246    cutWeight=weightbackup;
3219
5247   }
5248  
5249  
5250 <
5250 > void zjets_prediction_comparison(string mcjzbWithPUa) {
5251 >   zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20"), "nomasscut");
5252 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<10"), "Zwindow_10");
5253 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
5254 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)>10&&mll>20"), "Outside_Zwindow_10");
5255 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5256 > }
5257 >  
5258   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
5259    tout << endl << endl;
5260    stringstream bordercut;
# Line 3328 | Line 5362 | void make_table(samplecollection &coll,
5362   }
5363  
5364   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
5365 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
5366 +  assert(0);
5367    /*we want a table like this:
5368      __________________     50   |   100  | ...
5369      | Data prediction |  a vs b | a vs b | ...
# Line 3561 | Line 5597 | void qcd_plots(string datajzb, string mc
5597    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
5598    string ytitle("ratio");
5599    if ( use_data==1 ) ytitle = "data/pred";
5600 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5600 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5601 >  delete kinpad;
5602    
5603    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
5604    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3732 | Line 5769 | void met_vs_jzb_plots(string datajzb, st
5769    
5770    vector<string> findme;
5771    findme.push_back("DY");
5772 <  findme.push_back("TTJets");
5772 >  findme.push_back("TT_");
5773    findme.push_back("LM");
5774    /*
5775    for(int ifind=0;ifind<(int)findme.size();ifind++) {
# Line 3769 | Line 5806 | void met_vs_jzb_plots(string datajzb, st
5806    sRIGHT << "((" << mcjzb << ")>0)";
5807    TCut RIGHT(sRIGHT.str().c_str());
5808    
5809 <  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5810 <  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5811 <  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5812 <  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5809 >  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5810 >  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5811 >  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5812 >  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5813    
5814    
5815    TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
# Line 3798 | Line 5835 | void met_vs_jzb_plots(string datajzb, st
5835    lg->SetHeader("DY");
5836    
5837    lg->Draw();
5838 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5838 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5839    
5840    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5841    metpad3->cd();
# Line 3816 | Line 5853 | void met_vs_jzb_plots(string datajzb, st
5853  
5854    lg2->Draw();
5855    
5856 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5856 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5857    
5858    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5859    metpad2->cd();
5860    metpad2->SetLogy(1);
5861    
5862 <  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5863 <  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5864 <  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5865 <  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5862 >  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5863 >  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5864 >  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5865 >  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5866    
5867    metlefta->Add(metleftOa,-1);
5868    metrighta->Add(metrightOa,-1);
# Line 3835 | Line 5872 | void met_vs_jzb_plots(string datajzb, st
5872    metlefta->Draw("histo");
5873    metrighta->Draw("same");
5874    lg->Draw();
5875 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5875 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5876    
5877    delete Bpred;
5878    delete obs;
# Line 3844 | Line 5881 | void met_vs_jzb_plots(string datajzb, st
5881    int newNBins=30;
5882    
5883    TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5884 <  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5885 <  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5886 <  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5887 <  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5884 >  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5885 >  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5886 >  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5887 >  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5888    
5889    TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5890    aBpred->Add(AmetleftO,-1);
# Line 3862 | Line 5899 | void met_vs_jzb_plots(string datajzb, st
5899    aobs->Draw("same");
5900    lg->SetHeader("All MC");
5901    lg->Draw();
5902 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5902 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5903    
5904    
5905    delete lg;
# Line 3872 | Line 5909 | void met_vs_jzb_plots(string datajzb, st
5909    delete metright;
5910    delete metrightO;
5911   }
5912 +
5913 +
5914 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5915 +  
5916 +  if(PlottingSetup::RestrictToMassPeak) {
5917 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5918 +    assert(!PlottingSetup::RestrictToMassPeak);
5919 +  }
5920 +  
5921 +  vector<float> binning;
5922 +  
5923 +  binning.push_back(-200);
5924 +  binning.push_back(-150);
5925 +  binning.push_back(-125);
5926 +  binning.push_back(-100);
5927 +  binning.push_back(-75);
5928 +  binning.push_back(-50);
5929 +  binning.push_back(-25);
5930 +  binning.push_back(0);
5931 +  binning.push_back(25);
5932 +  binning.push_back(50);
5933 +  binning.push_back(75);
5934 +  binning.push_back(100);
5935 +  binning.push_back(125);
5936 +  binning.push_back(150);
5937 +  binning.push_back(200);
5938 +  
5939 +  switch_overunderflow(true);
5940 +  
5941 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5942 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5943 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5944 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5945 +  
5946 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5947 +  tcan->SetLogy(1);
5948 +  
5949 +  TZeemm->SetLineColor(kBlack);
5950 +  TZem->SetLineColor(kRed);
5951 +  TZeemm->SetMarkerColor(kBlack);
5952 +  TZem->SetMarkerColor(kRed);
5953 +  
5954 +  vector<TH1F*> histos;
5955 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5956 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5957 +  histos.push_back(TZem);
5958 +  histos.push_back(TZeemm);
5959 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5960 +  
5961 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5962 +  leg->AddEntry(TZeemm,"SFZP","l");
5963 +  leg->AddEntry(TZem,"OFZP","l");
5964 +  leg->Draw("same");
5965 +  DrawMCPrelim();
5966 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5967 +  
5968 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5969 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5970 +  TH1F *TSeemmcopy;
5971 +  TH1F *TSemcopy;
5972 +  
5973 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5974 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5975 +  
5976 +  vector<float> posbinning;
5977 +  for(unsigned int i=0;i<binning.size();i++) {
5978 +    if(binning[i]<0) continue;
5979 +    posbinning.push_back(binning[i]);
5980 +  }
5981 +  
5982 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5983 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5984 +  
5985 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5986 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5987 +    if(TZem->GetBinCenter(i)<0) {
5988 +      //we're on the left: subtract em!
5989 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5990 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5991 +      //we're on the left: add eemm!
5992 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5993 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5994 +    } else {
5995 +      //we're on the right: add em!
5996 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5997 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5998 +      //we're on the left: add eemm!
5999 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
6000 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
6001 +    }
6002 +  }
6003 +  
6004 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
6005 +  ratio2->Divide(obs2);
6006 +
6007 +  TZem->Divide(TZeemm);
6008 +  TZem->SetMarkerStyle(21);
6009 +
6010 +  TZem->SetTitle("OF / SF");
6011 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
6012 +  
6013 +  tcan->SetLogy(0);
6014 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
6015 +  TZem->GetYaxis()->SetTitle("ratio");
6016 +  TZem->Draw();
6017 +  
6018 +  float linepos=emuncertOFFPEAK;
6019 +  
6020 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
6021 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
6022 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
6023 +  
6024 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
6025 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
6026 +  center->SetLineColor(kBlue);
6027 +  
6028 +  top->Draw("same");
6029 +  center->Draw("same");
6030 +  bottom->Draw("same");
6031 +  
6032 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
6033 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
6034 +  leg2->AddEntry(bottom,"syst. envelope","l");
6035 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
6036 +  leg2->SetY1(0.65);
6037 +  
6038 +  leg2->Draw("same");
6039 +  
6040 +  DrawMCPrelim();
6041 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
6042 +  
6043 +  ratio2->SetLineColor(TZem->GetLineColor());
6044 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
6045 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
6046 +  ratio2->GetYaxis()->SetTitle("ratio");
6047 +  ratio2->Draw();
6048 +  
6049 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
6050 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
6051 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
6052 +  
6053 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
6054 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
6055 +  center2->SetLineColor(kBlue);
6056 +  
6057 +  top2->Draw("same");
6058 +  center2->Draw("same");
6059 +  bottom2->Draw("same");
6060 +  
6061 +  leg2->Draw("same");
6062 +  
6063 +  DrawMCPrelim();
6064 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
6065 +  
6066 +  delete TZem;
6067 +  delete nTZem;
6068 +  delete TZeemm;
6069 +  delete nTZeemm;
6070 +  delete obs2;
6071 +  delete pred2;
6072 +  delete tcan;
6073 +  switch_overunderflow(false);
6074 + }
6075 +
6076 + 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) {
6077      
6078 +  
6079 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
6080 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6081 +  vanilla_ratio->SetFillColor(kGreen);
6082 +  vanilla_ratio->SetLineColor(kGreen);
6083 +  vanilla_ratio->SetMarkerColor(kGreen);
6084 +  vanilla_ratio->SetFillStyle(3001);
6085 +  vanilla_ratio->Draw("e3");
6086 +  
6087 +  response_only_up_ratio->SetFillColor(kRed);
6088 +  response_only_up_ratio->SetMarkerColor(kRed);
6089 +  response_only_up_ratio->SetLineColor(kRed);
6090 +  response_only_up_ratio->SetFillStyle(3003);
6091 +  response_only_up_ratio->Draw("e3,same");
6092 +  
6093 +  response_only_down_ratio->SetFillColor(kOrange);
6094 +  response_only_down_ratio->SetMarkerColor(kOrange);
6095 +  response_only_down_ratio->SetLineColor(kOrange);
6096 +  response_only_down_ratio->SetFillStyle(3004);
6097 +  response_only_down_ratio->Draw("e3,same");
6098 +  
6099 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
6100 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
6101 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
6102 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
6103 +  reponse_plus_peak_up_ratio->Draw("e3,same");
6104 +  
6105 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
6106 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
6107 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
6108 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
6109 +  reponse_plus_peak_down_ratio->Draw("e3,same");
6110 +  
6111 +  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);
6112 +  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);
6113 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
6114 +  
6115 +  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);
6116 +  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);
6117 +  
6118 +  lhiA->SetLineColor(kRed);
6119 +  lhiA->SetLineStyle(2);
6120 +  llowA->SetLineColor(kRed);
6121 +  llowA->SetLineStyle(2);
6122 +  
6123 +  llow->SetLineColor(kBlue);
6124 +  llow->SetLineStyle(2);
6125 +  lhi->SetLineColor(kBlue);
6126 +  lhi->SetLineStyle(2);
6127 +  lOne->SetLineColor(kBlue);
6128 +  
6129 +  llow->Draw();
6130 +  lhi->Draw();
6131 +  lOne->Draw();
6132 +  
6133 +  llowA->Draw();
6134 +  lhiA->Draw();
6135 +  
6136 +  TLegend *leg = make_legend();
6137 +  leg->SetX1(0.15);
6138 +  leg->SetY1(0.7);
6139 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
6140 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
6141 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6142 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6143 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6144 +  leg->AddEntry(lhi,"Systematic envelope","l");
6145 + //  leg->SetNColumns(2);
6146 +  leg->Draw();
6147 +  
6148 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
6149 +  
6150 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6151 +  vanilla_ratio->Draw("e3");
6152 +  response_only_up_ratio->Draw("e3 same");
6153 +  response_only_down_ratio->Draw("e3 same");
6154 +  TLegend *leg2 = make_legend();
6155 +  leg2->SetX1(0.15);
6156 +  leg2->SetY1(0.7);
6157 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
6158 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
6159 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6160 +  leg2->AddEntry(lhi,"Systematic envelope","l");
6161 +  leg2->Draw();
6162 +  llow->Draw();
6163 +  lOne->Draw();
6164 +  llowA->Draw();
6165 +  lhiA->Draw();
6166 +  
6167 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
6168 +  
6169 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6170 +  response_only_up_ratio->Draw("e3");
6171 +  reponse_plus_peak_up_ratio->Draw("e3 same");
6172 +  reponse_plus_peak_down_ratio->Draw("e3 same");
6173 +  TLegend *leg3 = make_legend();
6174 +  leg3->SetX1(0.15);
6175 +  leg3->SetY1(0.7);
6176 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
6177 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6178 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6179 +  leg3->AddEntry(lhi,"Systematic envelope","l");
6180 +  leg3->Draw();
6181 +  llow->Draw();
6182 +  lOne->Draw();
6183 +  llowA->Draw();
6184 +  lhiA->Draw();
6185 +  
6186 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
6187 +  
6188 +  delete ttcan2;
6189 + }
6190 +
6191 + void ttbar_correction_tests() {
6192 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
6193 +    
6194 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
6195 +  
6196 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
6197 +  
6198 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
6199 +  
6200 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
6201 +  
6202 +  string vanilla="jzb[1]";
6203 +  string response_only_up="((jzb[1]+0.034665*pt))";
6204 +  string response_only_down="((jzb[1]-0.034665*pt))";
6205 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
6206 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
6207 +
6208 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
6209 +  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");
6210 +  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");
6211 +  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");
6212 +  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");
6213 +  
6214 +  ttcan->cd();
6215 +  
6216 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
6217 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
6218 +  
6219 +  delete vanilla_observed;
6220 +  delete response_only_up_observed;
6221 +  delete response_only_down_observed;
6222 +  delete reponse_plus_peak_up_observed;
6223 +  delete reponse_plus_peak_down_observed;
6224 +  
6225 +  delete vanilla_predicted;
6226 +  delete response_only_up_predicted;
6227 +  delete response_only_down_predicted;
6228 +  delete reponse_plus_peak_up_predicted;
6229 +  delete reponse_plus_peak_down_predicted;
6230 +  
6231 +  delete vanilla_ratio;
6232 +  delete response_only_up_ratio;
6233 +  delete response_only_down_ratio;
6234 +  delete reponse_plus_peak_up_ratio;
6235 +  delete reponse_plus_peak_down_ratio;
6236 +  
6237 +  delete ttcan;
6238 + }
6239 +
6240 + void ttbar_region_search(string mcjzb) {
6241 +  cout << "Looking for a nice control region" << endl;
6242 +  TCanvas *can = new TCanvas("can","can",1200,1200);
6243 +  can->Divide(2,2);
6244 +  can->cd(1);
6245 +  can->cd(1)->SetLogy(1);
6246 +  
6247 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6248 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6249 +  
6250 +  JZBdistSF.Draw("histo");
6251 +  JZBdistSF.SetMaximum(1000);
6252 +  JZBdistSF.SetMinimum(0.1);
6253 +  JZBdistSF.Draw("histo");
6254 +  DrawMCPrelim();
6255 +  
6256 +  can->cd(2);
6257 +  can->cd(2)->SetLogy(1);
6258 +  JZBdistOF.Draw("histo");
6259 +  JZBdistOF.SetMaximum(1000);
6260 +  JZBdistOF.SetMinimum(0.1);
6261 +  JZBdistOF.Draw("histo");
6262 +  DrawMCPrelim();
6263 +  
6264 +  can->cd(3);
6265 +  
6266 +  
6267 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
6268 +  
6269 +  DrawMCPrelim();
6270 +  
6271 +  /*
6272 +  THStack *Subtracted = new THStack();
6273 +  
6274 +  TIter nextSF(JZBdistSF.GetHists());
6275 +  TIter nextOF(JZBdistOF.GetHists());
6276 +  TObject* SFobj;
6277 +  TObject* OFobj;
6278 +  
6279 +  TH1* sfh = NULL;
6280 +  TH1* ofh = NULL;
6281 +  
6282 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
6283 +    TH1F *sfstart = (TH1*)SFobj->Clone();
6284 +    TH1F *ofstart = (TH1*)OFobj->Clone();
6285 +    TH1F *obs, *pred;
6286 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
6287 +    
6288 +    if ( !hratio ) {
6289 +      hratio = (TH1*)obj->Clone();
6290 +      hratio->SetName("hratio");
6291 +    } else hratio->Add( (TH1*)obj );
6292 +    
6293 +  }
6294 +  hratio->Divide(hdata);
6295 +  */
6296 +  
6297 +  
6298 +  can->cd(4);
6299 +  JZBdistOF.Draw("histo");
6300 +  DrawMCPrelim();
6301 +  
6302 +  
6303 +  
6304 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
6305 +  
6306 +  CleanLegends();
6307 +  delete can;
6308 + }
6309 +
6310 + void ttbar_tests(string mcjzb) {
6311 +  //ttbar_correction_tests();
6312 +  ttbar_region_search(mcjzb);
6313 + }
6314 +
6315 + Value GetYieldBetween(TH1F *h, float low, float high) {
6316 +  float Yield=0;
6317 +  float YieldErr=0;
6318 +  for(int i=1;i<=h->GetNbinsX()+1;i++) {
6319 +    if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
6320 +    if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
6321 +    Yield+=h->GetBinContent(i);
6322 +    YieldErr=sqrt(YieldErr*YieldErr+h->GetBinError(i)*h->GetBinError(i));
6323 +  }
6324 +  
6325 +  Value a(Yield,YieldErr);
6326 +  return a;
6327 + }
6328 +
6329 +
6330 + void make_SF_over_OF_plot(string datajzb, string mcjzb, TCut cut, string variable, int nbins, float xmin, float ymin, string varname, string filename) {
6331 +  TCanvas *SFoOF_can = new TCanvas("SFoOF_can","SFoOF_can");
6332 +  TH1F *data_sf = allsamples.Draw("data_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,data,luminosity);
6333 +  TH1F *data_of = allsamples.Draw("data_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,data,luminosity);
6334 +  
6335 +  TH1F *mc_sf = allsamples.Draw("mc_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6336 +  TH1F *mc_of = allsamples.Draw("mc_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6337 +  
6338 +  TH1F *mc_ratio = (TH1F*)mc_sf->Clone("mc_ratio");
6339 +  mc_ratio->Divide(mc_of);
6340 +  
6341 +  TH1F *data_ratio = (TH1F*)data_sf->Clone("data_ratio");
6342 +  data_ratio->Divide(data_of);
6343 +  
6344 +  mc_ratio->SetFillColor(TColor::GetColor("#00ADE1"));
6345 +  mc_ratio->SetMarkerColor(TColor::GetColor("#00ADE1"));
6346 +  mc_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6347 +  
6348 +  mc_ratio->GetYaxis()->SetTitle("R(SF / OF)");
6349 +  
6350 +  
6351 +  Value R_sf_of_low_mass = GetYieldBetween(data_sf,20,70)/GetYieldBetween(data_of,20,70);
6352 +  Value R_sf_of_high_mass = GetYieldBetween(data_sf,120,200)/GetYieldBetween(data_of,120,200);
6353 +  
6354 +  Value R_sf_of_low_mass_mc = GetYieldBetween(mc_sf,20,70)/GetYieldBetween(mc_of,20,70);
6355 +  Value R_sf_of_high_mass_mc = GetYieldBetween(mc_sf,120,200)/GetYieldBetween(mc_of,120,200);
6356 +  
6357 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6358 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6359 +  
6360 +  TGraphAsymmErrors *gra = produce_ratio_graph(mc_ratio);
6361 +  gra->Draw();
6362 +  mc_ratio->Draw();
6363 +  gra->Draw("e20");
6364 +  gra->SetFillColor(TColor::GetColor("#00ADE1"));
6365 +  gra->SetMarkerColor(TColor::GetColor("#00ADE1"));
6366 +  data_ratio->Draw("e1,same");
6367 +  
6368 +  TLegend *leg = new TLegend(0.17,0.16,0.53,0.31);
6369 + //   leg->SetHeader("R( SF / OF )");
6370 +  leg->SetFillColor(kWhite);
6371 +  leg->SetBorderSize(0);
6372 +  leg->AddEntry(data_ratio,"Data","p");
6373 +  leg->AddEntry(gra,"MC","fp");
6374 +  leg->Draw();
6375 +  
6376 +  TLine *g = new TLine(0,1.01,200,1.01);
6377 +  g->SetLineColor(kBlue);
6378 +  g->Draw();
6379 +  
6380 +  TLine *l = new TLine(70,0.5,70,1.5);
6381 +  l->SetLineStyle(2);
6382 +  l->SetLineColor(TColor::GetColor("#00ADE1"));
6383 +  TLine *m = new TLine(120,0.5,120,1.5);
6384 +  m->SetLineStyle(2);
6385 +  m->SetLineColor(TColor::GetColor("#00ADE1"));
6386 +  l->Draw();
6387 +  m->Draw();
6388 +  
6389 +  
6390 +  DrawPrelim();
6391 +  
6392 +  CompleteSave(SFoOF_can,"iTTbar/"+filename+"SF_vs_OF");
6393 +  
6394 +  delete leg;
6395 +  delete mc_sf;
6396 +  delete mc_of;
6397 +  delete mc_ratio;
6398 +  delete data_sf;
6399 +  delete data_of;
6400 +  delete data_ratio;
6401 +  delete SFoOF_can;
6402 + }  
6403 +
6404 + void make_iTTbar_JZB_plot(string datajzb, string mcjzb, TCut cut) {
6405 +  TCanvas *can = new TCanvas("can","can");
6406 +  vector<float> binning;
6407 +  binning.push_back(-100);
6408 +  binning.push_back(-50);
6409 +  binning.push_back(-20);
6410 +  binning.push_back(0);
6411 + //  binning.push_back(10);
6412 +  binning.push_back(20);
6413 + //  binning.push_back(30);
6414 +  binning.push_back(50);
6415 +  binning.push_back(100);
6416 +  binning.push_back(300);
6417 +  
6418 +  TH1F *hdata   = allsamples.Draw("hdata",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6419 +  TH1F *hodata  = allsamples.Draw("hodata", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6420 +  TH1F *hndata  = allsamples.Draw("hndata", "-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6421 +  TH1F *hnodata = allsamples.Draw("hnodata","-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6422 +  
6423 +  TH1F *hmc   = allsamples.Draw("hmc",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6424 +  TH1F *homc  = allsamples.Draw("homc", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6425 +  
6426 +  hodata->SetLineColor(kRed);
6427 +  hmc->SetLineColor(kRed);
6428 + //  hodata->Add(hndata);
6429 + //  hodata->Add(hnodata,-1);
6430 +  
6431 +  if(hdata->GetMaximum()>hodata->GetMaximum()) {
6432 +    hdata->SetMinimum(1.0);
6433 +    hdata->Draw();
6434 +    hodata->Draw("histo,same");
6435 +    hdata->Draw("same");
6436 +  } else {
6437 +    hodata->SetMinimum(1.0);
6438 +    hodata->Draw("histo");
6439 +    hdata->Draw("same");
6440 +  }
6441 +  
6442 +  CompleteSave(can,"iTTbar/JZB_plot");
6443 +  TH1F *ratio = (TH1F*)hdata->Clone("ratio");
6444 +  ratio->Divide(hodata);
6445 +  ratio->GetYaxis()->SetTitle("obs/pred");
6446 +  ratio->GetYaxis()->SetRangeUser(0,2);
6447 +  
6448 +  ratio->Draw();
6449 +  TLine *l = new TLine(-100,1.0,300,1.0);
6450 +  l->SetLineColor(kBlue);
6451 +  l->SetLineStyle(2);
6452 +  l->Draw();
6453 +  TLine *llow = new TLine(-100,1.0-0.07,300,1.0-0.07);
6454 +  TLine *lhi = new TLine(-100,1.0+0.07,300,1.0+0.07);
6455 +  llow->SetLineColor(kBlue);
6456 +  llow->SetLineStyle(2);
6457 +  llow->Draw();
6458 +  lhi->SetLineColor(kBlue);
6459 +  lhi->SetLineStyle(2);
6460 +  lhi->Draw();
6461 +  
6462 +  CompleteSave(can,"iTTbar/JZB_plot_ratio");
6463 +  
6464 +  delete hdata;
6465 +  delete hodata;
6466 +  delete ratio;
6467 +  delete can;
6468 + //  THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity));
6469 + //  THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity));
6470 + }
6471 +
6472 +  
6473 +  
6474 + void MakeSpecialiTTbarClosurePlot(TCut fullcut, string datajzb, string mcjzb, string MassRegion) {
6475 +  TCanvas *iTTbarClosureTestCanvas = new TCanvas("iTTbarClosureTestCanvas","iTTbarClosureTestCanvas");
6476 +  
6477 +  vector<float> binning;
6478 + /*
6479 +  binning.push_back(0);
6480 +  binning.push_back(20);
6481 +  binning.push_back(50);
6482 +  binning.push_back(100);
6483 + //  binning.push_back(200);
6484 + */
6485 +  binning.push_back(0);
6486 +  binning.push_back(10);
6487 +  binning.push_back(30);
6488 +  binning.push_back(50);
6489 +  binning.push_back(100);
6490 + //  binning.push_back(200);
6491 +  
6492 +  
6493 +  TH1F *hdata  = allsamples.Draw("hdata", datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),data,luminosity);
6494 +  TH1F *hodata = allsamples.Draw("hodata",datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),data,luminosity);
6495 +  TH1F *hmc    = allsamples.Draw("hmc",   mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),mc,luminosity);
6496 +  TH1F *homc   = allsamples.Draw("homc",  mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),mc,luminosity);
6497 +  
6498 +  hdata->SetLineColor(kBlack);
6499 +  hmc->SetLineColor(kBlack);
6500 +  hodata->SetLineColor(kRed);
6501 +  homc->SetLineColor(kRed);
6502 +  hodata->SetMarkerColor(kRed);
6503 +  
6504 +  hdata->GetYaxis()->SetTitle("events");
6505 +  
6506 +  float maximum=hdata->GetMaximum()+1.2*sqrt(hdata->GetMaximum());
6507 +  float minimum=hdata->GetMinimum()-1.2*sqrt(hdata->GetMinimum());
6508 +  if(hmc->GetMinimum()<minimum) minimum=hmc->GetMinimum()-1.2*sqrt(hmc->GetMinimum());
6509 +  if(hmc->GetMaximum()>maximum) maximum=hmc->GetMaximum()+1.2*sqrt(hmc->GetMaximum());
6510 +  if(homc->GetMinimum()<minimum) minimum=homc->GetMinimum()-1.2*sqrt(homc->GetMinimum());
6511 +  if(homc->GetMaximum()>maximum) maximum=homc->GetMaximum()+1.2*sqrt(homc->GetMaximum());
6512 +  if(hodata->GetMinimum()<minimum) minimum=hodata->GetMinimum()-1.2*sqrt(hodata->GetMinimum());
6513 +  if(hodata->GetMaximum()>maximum) maximum=hodata->GetMaximum()+1.2*sqrt(hodata->GetMaximum());
6514 +  
6515 +  hdata->SetMaximum(maximum);
6516 +  hdata->SetMinimum(minimum);
6517 +  
6518 +  
6519 +  hdata->Draw();
6520 +  hmc->Draw("same,histo");
6521 +  homc->Draw("same,histo");
6522 +  hdata->Draw("same");
6523 +  hodata->Draw("same");
6524 +  
6525 +  TLegend *leg = make_legend();
6526 +  leg->AddEntry(hdata,"SF data","pe");
6527 +  leg->AddEntry(hodata,"OF data","pe");
6528 +  leg->AddEntry(hmc,"SF MC","l");
6529 +  leg->AddEntry(homc,"OF MC","l");
6530 +  leg->Draw();
6531 +  
6532 +  DrawPrelim();
6533 +  
6534 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_"+MassRegion);
6535 +  
6536 +  TH1F *ratio_data = (TH1F*)hdata->Clone("ratio_data");
6537 +  ratio_data->Divide(hodata);
6538 +  TH1F *ratio_mc = (TH1F*)hmc->Clone("ratio_mc");
6539 +  ratio_mc->Divide(homc);
6540 +  
6541 +  ratio_mc->SetFillColor(kBlue);
6542 +  ratio_mc->SetMarkerSize(0);
6543 +  
6544 +  TGraphAsymmErrors *eratio = produce_ratio_graph(ratio_mc);
6545 +  
6546 +  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
6547 +  ratio_data->GetYaxis()->SetRangeUser(0.5,1.5);
6548 +  ratio_data->Draw("e1");
6549 +  eratio->Draw("20");
6550 +  ratio_data->Draw("e1,same");
6551 +  
6552 +  TLegend *leg2 = make_legend();
6553 +  leg2->AddEntry(ratio_data,"R(SF/OF) in #bar{t}t CR, data","pe");
6554 +  leg2->AddEntry(eratio    ,"R(SF/OF) in #bar{t}t CR, MC"  ,"f");
6555 +  leg2->SetY1(0.8);
6556 +  leg2->SetX1(0.45);
6557 +  leg2->Draw();
6558 +  
6559 +  DrawPrelim();
6560 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_Ratio_"+MassRegion);
6561 +  
6562 +  TFile *f = new TFile("fout.root","RECREATE");
6563 +  eratio->Write();
6564 +  ratio_data->Write();
6565 +  leg2->Write();
6566 +  f->Close();
6567 +  
6568 +  
6569 +  delete leg;
6570 +  delete leg2;
6571 +  delete ratio_data;
6572 +  delete ratio_mc;
6573 +  delete hdata;
6574 +  delete hmc;
6575 +  delete hodata;
6576 +  delete iTTbarClosureTestCanvas;
6577 + }
6578 +  
6579 +  
6580 +  
6581 + void make_ijzb_ttbar_closure_test(string datajzb, string mcjzb) {
6582 +  TCut tt_nJets("pfJetGoodNum40==2");
6583 +  TCut tt_bJet("pfJetGoodNumBtag40==2 && met[4]>10");
6584 +  TCut tt_LowMass("mll>20&&mll<70");
6585 +  TCut tt_HighMass("mll>120&&mll<200");
6586 +  TCut tt_noZ(tt_LowMass || tt_HighMass);
6587 +  
6588 +  /*
6589 +  make_iTTbar_JZB_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ);
6590 + */
6591 +  TCanvas *can = new TCanvas("can","can");
6592 +
6593 +  TH1F *hdata  =                allsamples.Draw(        "hdata", "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,data,luminosity);
6594 +  THStack *hmc = new THStack(   allsamples.DrawStack(   "hmc",   "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,mc,  luminosity));
6595 +  TH1F *hodata =                allsamples.Draw(        "hodata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,data,luminosity);
6596 +  THStack *homc = new THStack(  allsamples.DrawStack(   "homc",  "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,mc,  luminosity));
6597 +  
6598 +  TH1F *coll_hmc = CollapseStack(hmc);
6599 +  TH1F *coll_homc = CollapseStack(homc);
6600 +  
6601 +  bool dolog=true;
6602 +  bool nolog=false;
6603 +  
6604 +  dout << " SF: " << endl;
6605 +  dout << "   Data : " << hdata->Integral() << endl;
6606 +  WriteYield(hmc, 0, 10000);
6607 +  dout << " OF: " << endl;
6608 +  dout << "   Data : " << hodata->Integral() << endl;
6609 +  WriteYield(homc, 0, 10000);
6610 +  hodata->SetLineColor(kRed);
6611 +  hdata->Draw();
6612 +  hmc->Draw("histo,same");
6613 +  hodata->Draw("histo,same");
6614 +  hdata->Draw("e1,same");
6615 +  DrawPrelim();
6616 +  CompleteSave(can,"TestingPrediction");
6617 +  
6618 +  dout << "We get an expected ratio of " << coll_hmc->Integral()/coll_homc->Integral() << endl;
6619 +  dout << "In data we find  " << hdata->Integral()/hodata->Integral() << endl;
6620 +  
6621 +  Value R_sf_of_low_mass = GetYieldBetween(hdata,20,70)/GetYieldBetween(hodata,20,70);
6622 +  Value R_sf_of_high_mass = GetYieldBetween(hdata,120,200)/GetYieldBetween(hodata,120,200);
6623 +  
6624 +  Value R_sf_of_low_mass_mc = GetYieldBetween(coll_hmc,20,70)/GetYieldBetween(coll_homc,20,70);
6625 +  Value R_sf_of_high_mass_mc = GetYieldBetween(coll_hmc,120,200)/GetYieldBetween(coll_homc,120,200);
6626 +  
6627 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6628 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6629 +  
6630 +  dout << "Composition at low mass : " << endl;
6631 +  dout << "Same flavor: " << endl;
6632 +  ProduceYields(20, 70, hdata, hmc);
6633 +  dout << "Opposite flavor: " << endl;
6634 +  ProduceYields(20, 70, hodata, homc);
6635 +  
6636 +  dout << endl << endl;
6637 +  
6638 +  dout << "Composition at high mass : " << endl;
6639 +  dout << "Same flavor: " << endl;
6640 +  ProduceYields(120, 200, hdata, hmc);
6641 +  dout << "Opposite flavor: " << endl;
6642 +  ProduceYields(120, 200, hodata, homc);
6643 +  
6644 +  
6645 +
6646 +  
6647 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),20,-200,200,dolog,"JZB","iTTbar/JZB_SF",false,true);
6648 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),20,-200,200,dolog,"JZB","iTTbar/JZB_OF",false,true);
6649 +
6650 +  make_plain_kin_plot("mll",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),40,0,200,nolog,"m_{ll} [GeV]","iTTbar/mll_SF",false,true);
6651 +  make_plain_kin_plot("mll",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),40,0,200,nolog,"m_{ll} [GeV]","iTTbar/mll_OF",false,true);
6652 +  
6653 +  make_SF_over_OF_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ,"mll",20,0,200,"m_{ll} [GeV]","mll");
6654 +  
6655 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_LowMass),datajzb,mcjzb,"LowMassRegion2070");
6656 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_HighMass),datajzb,mcjzb,"HighMassRegion");
6657 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_noZ),datajzb,mcjzb,"NoZ");
6658 +  
6659 + //   make_plain_kin_plot("pfJetGoodNum40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),10,-0.5,9.5,dolog,"n_{jets}","iTTbar/nJets_SF",false,true);
6660 + //   make_plain_kin_plot("pfJetGoodNum40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),10,-0.5,9.5,dolog,"n_{jets}","iTTbar/nJets_OF",false,true);
6661 + //  
6662 + //   make_plain_kin_plot("pfJetGoodNumBtag40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),10,-0.5,9.5,dolog,"n_{btags}","iTTbar/nBtags_SF",false,true);
6663 + //   make_plain_kin_plot("pfJetGoodNumBtag40",(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),10,-0.5,9.5,dolog,"n_{btags}","iTTbar/nBtags_OF",false,true);
6664 +  
6665 +  
6666 +  delete coll_hmc;
6667 +  delete coll_homc;
6668 +  delete hmc;
6669 +  delete homc;
6670 +  delete hdata;
6671 +  delete hodata;
6672 +  delete can;
6673 + }
6674 +
6675 + void compute_global_significance(float local_significance) {
6676 +    float global_sigificance = ROOT::Math::normal_quantile_c(ROOT::Math::normal_cdf_c(local_significance,1)*4,1);
6677 +    dout << "local significance  : " << local_significance << endl;
6678 +    dout << "global significance : " << global_sigificance << endl;
6679 + }
6680 +  
6681  
6682   void test() {
6683    
6684 +  
6685 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
6686 +  stringstream result, datajzb, mcjzb;
6687 +  bool doPUreweighting=true;
6688 +  bool SwitchOffNJetsCut=false;
6689 +  
6690 +  
6691 +  TCanvas *can = new TCanvas("can","can");
6692 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
6693 +  
6694 +  float NumVtxBin[6] = {0,5,10,15,20,30};
6695 +  
6696 +  stringstream NowCut;
6697 +  
6698 +  TGraphErrors *gMCPeak = new TGraphErrors();
6699 +  gMCPeak->SetTitle("gMCPeak");
6700 +  gMCPeak->SetName("gMCPeak");
6701 +  TGraphErrors *gDataPeak = new TGraphErrors();
6702 +  gDataPeak->SetTitle("gDataPeak");
6703 +  gDataPeak->SetName("gDataPeak");
6704 +  TGraphErrors *gMCWidth = new TGraphErrors();
6705 +  gMCWidth->SetTitle("gMCWidth");
6706 +  gMCWidth->SetName("gMCWidth");
6707 +  TGraphErrors *gDataWidth = new TGraphErrors();
6708 +  gDataWidth->SetTitle("gDataWidth");
6709 +  gDataWidth->SetName("gDataWidth");
6710 +  
6711 +  float AllMCPeaks[200];
6712 +  float AllMCPeaksErrors[200];
6713 +  
6714 +  for(int i=10;i<180;i+=20) {
6715 +    NowCut.str("");
6716 +    NowCut << "mll>=" << i << "&&mll<" << i+20;
6717 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
6718 +    AllMCPeaks[i]=MCPeak;
6719 +    AllMCPeaksErrors[i]=MCPeakError;
6720 +  }
6721 +  
6722 +  dout << "Summary : " << endl;
6723 +  for(int i=10;i<180;i+=20) {
6724 +    dout << "For the slice at [" << i << " , " << i+20 << "] we get a peak at " << AllMCPeaks[i] << " +/- " << AllMCPeaksErrors[i] << endl;
6725 +  }
6726 +  /*
6727    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
6728    testcanv->cd();
6729   //  switch_overunderflow(true);
6730 <  TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
6731 <  switch_overunderflow(false);
6732 <  ptdistr->Draw();
6733 <  testcanv->SaveAs("test.png");
3886 <  dout << "HELLO there!" << endl;
6730 >  TH1F *histo1 = new TH1F("histo","histo",100,0,1);
6731 >  histo1->Sumw2();
6732 >  TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
6733 >  histo2->Sumw2();
6734    
6735 +  for(int i=0;i<100;i++) {
6736 +    histo1->Fill(1.0/i,i);
6737 +    histo2->Fill(1.0/(i*i),i);
6738 +  }
6739 +
6740 +  histo1->Draw();
6741 +  histo2->Draw("e1,same");
6742 +  
6743 +  Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
6744 +  
6745 +  
6746 +  dout << "HELLO there!" << endl;
6747 +  */
6748   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines