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.70 by buchmann, Thu Oct 11 09:00:41 2012 UTC vs.
Revision 1.99 by buchmann, Fri Jun 28 15:03:02 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, 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   {
# Line 45 | Line 53 | void find_one_peak_combination(TCut spec
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&&nJetsCut&&specialcut,mc, luminosity);
59    TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,data, luminosity);
# Line 80 | 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 +
113 + void FindPeakPileUpCorrection() {
114 +  bool StoreResultsInSeparateFile=true;
115 +  PeakLibrary::StoreHistos=true;
116 +  
117 +  
118 +  dout << "Finding peak position as a function of PU" << endl;
119 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
120 +  stringstream result, datajzb, mcjzb;
121 +  bool doPUreweighting=true;
122 +  bool SwitchOffNJetsCut=false;
123 +  
124 +  
125 +  TCanvas *can = new TCanvas("can","can");
126 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
127 +  
128 +  const int nbins=10;
129 +  float NumVtxBin[nbins] = {0,7,9,11,13,15,17,19,21,30};
130 +  
131 +  stringstream NowCut;
132 +  
133 +
134 +  Double_t mc_peak_x[nbins];
135 +  Double_t mc_peak_y[nbins];
136 +  Double_t mc_peak_dxh[nbins];
137 +  Double_t mc_peak_dxl[nbins];
138 +  Double_t mc_peak_dy[nbins];
139 +  
140 +  Double_t data_peak_x[nbins];
141 +  Double_t data_peak_y[nbins];
142 +  Double_t data_peak_dxh[nbins];
143 +  Double_t data_peak_dxl[nbins];
144 +  Double_t data_peak_dy[nbins];
145 +  
146 +  Double_t mc_width_x[nbins];
147 +  Double_t mc_width_y[nbins];
148 +  Double_t mc_width_dxh[nbins];
149 +  Double_t mc_width_dxl[nbins];
150 +  Double_t mc_width_dy[nbins];
151 +  
152 +  Double_t data_width_x[nbins];
153 +  Double_t data_width_y[nbins];
154 +  Double_t data_width_dxh[nbins];
155 +  Double_t data_width_dxl[nbins];
156 +  Double_t data_width_dy[nbins];
157 +
158 +  for(int i=0;i<nbins-1;i++) {
159 +    NowCut.str("");
160 +    NowCut << "numVtx>" << NumVtxBin[i] << "&&numVtx<=" << NumVtxBin[i+1];
161 +    cout << "NVtx cut is now : " << NowCut.str() << endl;
162 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
163 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
164 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
165 +    
166 +    TH1F *hDataSFNumVtx = allsamples.Draw("hDataSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
167 +    TH1F *hDataOFNumVtx = allsamples.Draw("hDataOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
168 +    TH1F *hMCSFNumVtx = allsamples.Draw("hMCSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
169 +    TH1F *hMCOFNumVtx = allsamples.Draw("hMCOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
170 +    
171 +    hDataSFNumVtx->Add(hDataOFNumVtx,-1);
172 +    hMCSFNumVtx->Add(hMCOFNumVtx,-1);
173 +    
174 +    mc_peak_x[i]=hMCSFNumVtx->GetMean();
175 +    mc_peak_y[i]=MCPeak;
176 +    mc_peak_dy[i]=MCPeakError;
177 +    
178 +    data_peak_x[i]=hDataSFNumVtx->GetMean();
179 +    data_peak_y[i]=DataPeak;
180 +    data_peak_dy[i]=DataPeakError;
181 +    
182 +    mc_width_x[i]=hMCSFNumVtx->GetMean();
183 +    mc_width_y[i]=mcSigma;
184 +    mc_width_dy[i]=mcSigmaError;
185 +    
186 +    data_width_x[i]=hDataSFNumVtx->GetMean();
187 +    data_width_y[i]=dataSigma;
188 +    data_width_dy[i]=dataSigmaError;
189 +    
190 +    delete hDataSFNumVtx;
191 +    delete hDataOFNumVtx;
192 +    delete hMCSFNumVtx;
193 +    delete hMCOFNumVtx;
194 +  }
195 +  
196 +  for(int i=0;i<nbins-1;i++) {
197 +    if(i==0) {
198 +      data_width_dxl[i]=data_width_x[i];
199 +      data_peak_dxl[i]=data_peak_x[i];
200 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
201 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
202 +      
203 +      mc_width_dxl[i]=mc_width_x[i];
204 +      mc_peak_dxl[i]=mc_peak_x[i];
205 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
206 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
207 +    } else if(i==nbins-2) {
208 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
209 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
210 +      data_width_dxh[i]=30-data_width_x[i];
211 +      data_peak_dxh[i]=30-data_peak_x[i];
212 +      
213 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
214 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
215 +      mc_width_dxh[i]=30-mc_width_x[i];
216 +      mc_peak_dxh[i]=30-mc_peak_x[i];
217 +    } else {
218 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
219 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
220 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
221 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
222 +      
223 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
224 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
225 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
226 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
227 +    }
228 +  }
229 +  
230 +  TGraphAsymmErrors *gMCPeak = new TGraphAsymmErrors(nbins-1,mc_peak_x,mc_peak_y,mc_peak_dxl,mc_peak_dxh,mc_peak_dy,mc_peak_dy);
231 +  gMCPeak->SetTitle("gMCPeak");
232 +  gMCPeak->SetName("gMCPeak");
233 +  
234 +  TGraphAsymmErrors *gDataPeak = new TGraphAsymmErrors(nbins-1,data_peak_x,data_peak_y,data_peak_dxl,data_peak_dxh,data_peak_dy,data_peak_dy);
235 +  gDataPeak->SetTitle("gDataPeak");
236 +  gDataPeak->SetName("gDataPeak");
237 +  
238 +  TGraphAsymmErrors *gMCWidth = new TGraphAsymmErrors(nbins-1,mc_width_x,mc_width_y,mc_width_dxl,mc_width_dxh,mc_width_dy,mc_width_dy);
239 +  gMCWidth->SetTitle("gMCWidth");
240 +  gMCWidth->SetName("gMCWidth");
241 +  
242 +  TGraphAsymmErrors *gDataWidth = new TGraphAsymmErrors(nbins-1,data_width_x,data_width_y,data_width_dxl,data_width_dxh,data_width_dy,data_width_dy);
243 +  gDataWidth->SetTitle("gDataWidth");
244 +  gDataWidth->SetName("gDataWidth");
245 +  
246 +  can->cd();
247 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
248 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
249 +  gMCPeak->GetXaxis()->CenterTitle();
250 +  gMCPeak->GetYaxis()->CenterTitle();
251 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
252 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
253 +  gDataPeak->GetXaxis()->CenterTitle();
254 +  gDataPeak->GetYaxis()->CenterTitle();
255 +  
256 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
257 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
258 +  gDataWidth->GetXaxis()->CenterTitle();
259 +  gDataWidth->GetYaxis()->CenterTitle();
260 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
261 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
262 +  gMCWidth->GetXaxis()->CenterTitle();
263 +  gMCWidth->GetYaxis()->CenterTitle();
264 +  
265 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
266 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
267 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
268 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
269 +  
270 +  can->cd();
271 +  gMCPeak->Draw("A2");
272 +  DrawMCPrelim();
273 +  CompleteSave(can,"PUStudy/MCPeak");
274 +  
275 +  can->cd();
276 +  gStyle->SetOptFit(0);
277 +  gMCPeak->Fit("pol1");
278 +  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
279 +  
280 +  gMCPeak->Draw("A2");
281 +  MCFit->SetLineColor(kBlue);
282 +  MCFit->SetLineWidth(2);
283 +  MCFit->Draw("same");
284 +  stringstream mresult;
285 +  mresult << "Slope: " << DigitsAfterComma(MCFit->GetParameter(1),2) << " +/- " << DigitsAfterComma(MCFit->GetParError(1),2);
286 +  TText* mrestitle = write_text(0.7,0.2,mresult.str());
287 +  mrestitle->Draw();
288 +  DrawMCPrelim();
289 +  CompleteSave(can,"PUStudy/MCPeak_Fit");
290 +  
291 +  gMCWidth->Draw("A2");
292 +  DrawMCPrelim();
293 +  CompleteSave(can,"PUStudy/MCWidth");
294 +  
295 +  
296 +  can->cd();
297 +  gDataPeak->Draw("A2");
298 +  DrawPrelim();
299 +  CompleteSave(can,"PUStudy/DataPeak");
300 +  
301 +  can->cd();
302 +  gStyle->SetOptFit(0);
303 +  gDataPeak->Fit("pol1");
304 +  
305 +  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
306 +  DataFit->SetLineColor(kBlue);
307 +  DataFit->SetLineWidth(2);
308 +  DataFit->Draw("same");
309 +  stringstream dresult;
310 +  dresult << "Slope: " << DigitsAfterComma(DataFit->GetParameter(1),2) << " +/- " << DigitsAfterComma(DataFit->GetParError(1),2);
311 +  TText* drestitle = write_text(0.7,0.2,dresult.str());
312 +  drestitle->Draw();
313 +  DrawPrelim();
314 +  CompleteSave(can,"PUStudy/DataPeak_Fit");
315 +  
316 +  can->cd();
317 +  gDataWidth->Draw("A2");
318 +  DrawPrelim();
319 +  CompleteSave(can,"PUStudy/DataWidth");
320 +  
321 +  if(StoreResultsInSeparateFile) {
322 +    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
323 +    gMCPeak->Write();
324 +    gDataPeak->Write();
325 +    gMCWidth->Write();
326 +    gDataWidth->Write();
327 +    PeakFinding->Close();
328 +  }
329 +  
330 +  
331 +  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
332 +  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
333 +  
334 +  dout << "Suggested variables : " << endl;
335 +  dout << "   jzbvariabledata=\"( " << jzbvariabledata << " - numVtx * " << DataFit->GetParameter(1) << " - " << DataFit->GetParameter(0)   << " )\";" << endl;
336 +  dout << "   jzbvariablemc=  \"( " <<   jzbvariablemc   << " - numVtx * " << MCFit->GetParameter(1)   << " - " << MCFit->GetParameter(0)   << " )\";" << endl;
337 +  
338 +  TLegend *leg = make_legend();
339 +  can->cd();
340 +  int j=0;
341 +  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
342 +    PeakLibrary::DataHistogram[i]->Rebin(5);
343 +    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
344 +    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
345 +    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
346 +    stringstream name;
347 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
348 +    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
349 +    j++;
350 +  }
351 +  
352 +  leg->Draw();
353 +  DrawPrelim();
354 +  CompleteSave(can,"PUStudy/DataOverview");
355 +  
356 +  TLegend *leg2 = make_legend();
357 +  can->cd();
358 +  j=0;
359 +  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
360 +    PeakLibrary::MCHistogram[i]->Rebin(5);
361 +    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
362 +    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
363 +    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
364 +    stringstream name;
365 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
366 +    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
367 +    j++;
368 +  }
369 +  
370 +  leg->Draw();
371 +  DrawPrelim();
372 +  CompleteSave(can,"PUStudy/MCOverview");
373 +  
374 +  delete can;
375 +  PeakLibrary::StoreHistos=false;
376 + }
377 +
378 +
379 +
380   void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
381   {
382    bool overunderflowstatus=addoverunderflowbins;
# Line 144 | Line 434 | void find_peaks(float &MCPeak,float &MCP
434      
435    } else {
436      datajzb << "(" << jzbvariabledata;
437 <      mcjzb << "(" << jzbvariablemc;
437 >    mcjzb   << "(" << jzbvariablemc;
438      
439      if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
440      else datajzb << "+ " << TMath::Abs(datapeak) << " ";
# Line 164 | Line 454 | void find_peaks(float &MCPeak,float &MCP
454      switch_overunderflow(overunderflowstatus);
455   }
456  
457 < void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
457 > void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth, int MCorData) {
458    float min=70.0;
459    float max=115.0;
460    if(!PlottingSetup::RestrictToMassPeak) {
# Line 173 | Line 463 | void make_special_obs_pred_mll_plot(stri
463    }
464    int nbins=int((max-min)/binWidth);
465    
466 +  string prefix="";
467 +  if(MCorData==mc) prefix="MC__";
468 +  
469 +  
470 +  if(MCorData==mc) datajzb=mcjzb;
471 +  
472    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
473    
474    stringstream largerzeroS;
# Line 188 | Line 484 | void make_special_obs_pred_mll_plot(stri
484    largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
485    TCut largerzeroM(largerzeroMS.str().c_str());
486    
487 <  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
488 <  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
489 <  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
490 <  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
491 <  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
487 >
488 >  stringstream smallerzeroMS;
489 >  smallerzeroMS << "(" << mcjzb << "<-" << jzbthreshold << ")";
490 >  TCut smallerzeroM(smallerzeroMS.str().c_str());
491 >  
492 >  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,MCorData,luminosity);
493 >  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
494 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,MCorData,luminosity);
495 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,MCorData,luminosity);
496 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,MCorData,luminosity);
497  
498    TH1F *RcorrJZBSBem;
499    TH1F *LcorrJZBSBem;
# Line 202 | Line 503 | void make_special_obs_pred_mll_plot(stri
503   //  TH1F *RcorrJZBeemmNoS;
504  
505    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
506 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
507 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
508 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
509 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
506 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,MCorData, luminosity);
507 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,MCorData, luminosity);
508 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,MCorData, luminosity);
509 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,MCorData, luminosity);
510    }
511 <  
512 <  // Separate predictions
511 >
512 >    // Separate predictions
513    TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
514    TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
515    TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
516 +  
517 +  TH1F *BpredSys = (TH1F*)SFN->Clone("BpredSys");
518 +  ClearHisto(BpredSys);
519 +  AddSquared(BpredSys,SFN,pow(PlottingSetup::zjetsestimateuncertOFFPEAK,2));
520 +
521    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
522      OFP->Scale(1.0/3.0);
523      OFP->Add(RcorrJZBSBem,1.0/3.);
# Line 219 | Line 525 | void make_special_obs_pred_mll_plot(stri
525      OFN->Scale(1.0/3.0);
526      OFN->Add(LcorrJZBSBem,1.0/3.);
527      OFN->Add(LcorrJZBSBeemm,1.0/3.);
528 <  }
528 >    AddSquared(BpredSys,RcorrJZBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
529 >    AddSquared(BpredSys,RcorrJZBSBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
530 >    AddSquared(BpredSys,RcorrJZBSBeemm,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
531 >  } else {
532 >    AddSquared(BpredSys,OFN,pow(PlottingSetup::emuncertOFFPEAK,2));  
533 >  }
534  
535 +  SQRT(BpredSys);
536 +  
537 +  TGraphErrors *BpredSysBand = new TGraphErrors();
538 + //  TH1F *BpredSysBand = (TH1F*)BpredSys->Clone("BpredSysBand");
539 +  
540 +  for(int i=1;i<=BpredSys->GetNbinsX();i++) {
541 +    /*BpredSysBand->SetBinError(i,BpredSysBand->GetBinContent(i));
542 +    BpredSysBand->SetBinContent(i,0);*/
543 +    float dx=0.5*BpredSys->GetBinWidth(i);
544 +    float dy=BpredSys->GetBinContent(i);
545 +    BpredSysBand->SetPoint(i-1,BpredSys->GetBinCenter(i),0);
546 +    BpredSysBand->SetPointError(i-1,dx,dy);
547 +  }
548 +  
549 +  delete BpredSys;
550 +  BpredSysBand->SetFillColor(TColor::GetColor("#2E9AFE"));
551 +  
552    TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
553 <  Bpred->Add(OFP);
554 <  Bpred->Add(OFN,-1);
553 >  Bpred->Add(OFP,1.02);
554 >  Bpred->Add(OFN,-1.02);
555    Bpred->SetLineColor(kRed);
556    
557    RcorrJZBeemm->SetTitleOffset(1.3,"y");
558    RcorrJZBeemm->Draw();
559 <  mcRcorrJZBeemm.Draw("same");
559 >  mcRcorrJZBeemm.Draw("histo,same");
560    Bpred->Draw("histo,same");
561    RcorrJZBeemm->Draw("same");
562    
563    TLegend *leg = allsamples.allbglegend();
564    leg->SetX1(0.58);
565 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
565 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
566    leg->AddEntry(Bpred,"predicted (data)","l");
567    leg->Draw("same");
568    
569    stringstream saveas;
570 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
570 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold;
571    CompleteSave(ckin,saveas.str());
572    
573    // Draw all predictions overlayed
# Line 262 | Line 590 | void make_special_obs_pred_mll_plot(stri
590    RcorrJZBeemm->Draw("same");
591    
592    TLegend *leg2 = make_legend("",0.52,0.7);
593 <  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
594 <  leg2->AddEntry(Bpred,"predicted (data)","l");
595 <  leg2->AddEntry(SFN,  "  SF JZB<0","l");
596 <  leg2->AddEntry(OFN,  "  OF JZB<0","l");
597 <  leg2->AddEntry(OFP,  "  OF JZB>0","l");
593 >  if(MCorData==data) {
594 >    leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
595 >    leg2->AddEntry(Bpred,"predicted (data)","l");
596 >  } else {
597 >    leg2->AddEntry(RcorrJZBeemm,"true (MC)","lp");
598 >    leg2->AddEntry(Bpred,"predicted (MC)","l");
599 >  }
600 >
601 >  if(jzbthreshold>0) {
602 >    leg2->AddEntry(SFN,  ("  SF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
603 >    leg2->AddEntry(OFN,  ("  OF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
604 >  } else {
605 >    leg2->AddEntry(SFN,  "  SF JZB<0","l");
606 >    leg2->AddEntry(OFN,  "  OF JZB<0","l");
607 >  }
608 >  leg2->AddEntry(OFP,  ("  OF JZB>"+any2string(jzbthreshold)).c_str(),"l");
609    leg2->Draw("same");
610    
611    saveas.str("");
612 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
612 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc";
613    CompleteSave(ckin,saveas.str());
614    
615 +  
616 +  TH1F *diff = (TH1F*)RcorrJZBeemm->Clone("diff");
617 +  diff->Add(Bpred,-1);
618 +  
619 +  TLegend *dleg = make_legend();
620 +  if(MCorData==data) dleg->AddEntry(diff,"Obs-predicted","p");
621 +  else dleg->AddEntry(diff,"True-predicted","p");
622 +  dleg->AddEntry(BpredSysBand,"Sys. envelope","f");
623 +  dleg->SetY1(0.7);
624 +  
625 +  
626 +  diff->GetYaxis()->SetTitle("true - predicted");
627 +  if(MCorData==data) diff->GetYaxis()->SetTitle("observed - predicted");
628 +  diff->Draw("e1");
629 +  BpredSysBand->Draw("e2");
630 +  diff->Draw("e1,same");
631 +  dleg->Draw();
632 +  
633 +  if(MCorData==data) DrawPrelim();
634 +  else DrawMCPrelim();
635 +  
636 +  saveas.str("");
637 +  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc_Diff";
638 +  CompleteSave(ckin,saveas.str());
639 +
640 +  delete BpredSysBand;
641 +  delete diff;
642 +  
643    delete RcorrJZBeemm;
644    delete LcorrJZBeemm;
645    delete RcorrJZBem;
646    delete LcorrJZBem;
647 +
648    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
649      delete RcorrJZBSBeemm;
650      delete LcorrJZBSBeemm;
# Line 285 | Line 653 | void make_special_obs_pred_mll_plot(stri
653    }
654    delete Bpred;
655    delete ckin;
656 +  CleanLegends();
657   }
658  
659   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 305 | Line 674 | void make_special_mll_plot(int nbins, fl
674    datahistoOSSF->SetMarkerSize(DataMarkerSize);
675    datahistoOSSF->Draw();
676  
677 <  mcstackOSSF.Draw("same");
677 >  mcstackOSSF.Draw("histo,same");
678    datahistoOSSF->Draw("same");
679  
680    datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
# Line 331 | Line 700 | void make_special_mll_plot(int nbins, fl
700    delete datahistoOSOF;
701    delete datahistoOSSF;
702    delete ckin;
703 +  CleanLegends();
704   }
705    
706  
# Line 372 | Line 742 | void draw_ratio_plot(TH1* hdata, THStack
742   }
743  
744   float make_one_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
745 <                        string xlabel, string filename, float legendPosition=0.55) {
745 >                        string xlabel, string filename, float legendPosition=0.55, int dataormc=data) {
746  
747    TCut ibasiccut=basiccut;
748    bool draw_separation_lines=false;
# Line 382 | Line 752 | float make_one_OFSF_plot(string variable
752    TCut cutSF;
753    TCut cutOF;
754  
755 +  cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
756    cutOF = cutOSOF&&cutnJets&&ibasiccut;
757    cutSF = cutOSSF&&cutnJets&&ibasiccut;
758 +  
759 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
760  
388  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
761    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
762    rcan->SetLogy(logscale);
763    rcan->cd();
764  
765    std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
766 <  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
767 <  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
766 >    TH1F *datahistoOF,*datahistoSF;
767 >    if(dataormc==data || dataormc==mc) {
768 >        datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,dataormc,luminosity);
769 >        datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,dataormc,luminosity);
770 >    } else {
771 >        datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,mc,luminosity,allsamples.FindSample("/TTJets"));
772 >        datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,mc,luminosity,allsamples.FindSample("/TTJets"));
773 >    }
774   //   string signal("LM3");
775   //   TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
776   //   int idx = signalsamples.FindSample(signal)[0];
# Line 402 | Line 780 | float make_one_OFSF_plot(string variable
780   //   signalhisto->SetLineStyle(2);
781    datahistoSF->SetMarkerSize(DataMarkerSize);
782    datahistoOF->SetLineColor(kRed);
783 +  datahistoOF->SetLineWidth(2);
784 +  
785 +  datahistoOF->Scale(1.02); // R(SF/OF)
786  
787    if ( !logscale ) {
788      datahistoSF->SetMinimum(0); // Defaults
# Line 410 | Line 791 | float make_one_OFSF_plot(string variable
791    }
792    if (ymax<0) {
793      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
794 <    else datahistoSF->SetMaximum(1.8*datahistoSF->GetMaximum());
794 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
795    } else {
796      datahistoSF->SetMaximum(ymax);
797    }
# Line 422 | Line 803 | float make_one_OFSF_plot(string variable
803    datahistoSF->GetXaxis()->CenterTitle();
804    datahistoSF->GetYaxis()->CenterTitle();
805  
806 <  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.7,false,legendPosition+0.2);
806 >  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.6,false,legendPosition+0.2);
807 >  if(dataormc!=data && dataormc!=mc) mleg->SetHeader("t#bar{t} MC only");
808    mleg->AddEntry(datahistoSF, "Same-flavor", "PL");
809    if (datahistoOF->Integral()>0) {
810 <    mleg->AddEntry(datahistoOF, "Opposite-flavor", "L");
810 >    mleg->AddEntry(datahistoOF, "OF based estimate", "L");
811    } else {
812      mleg->AddEntry((TObject*)0, "", "");
813    }
814    //mleg->AddEntry(signalhisto, "LM3", "L");
815  
816    datahistoSF->Draw("E1");
817 +  
818 +  TH1F *syshisto = (TH1F*)datahistoOF->Clone("syshisto");
819 +  TGraphAsymmErrors *datahistoOFboxes = produce_ratio_graph(datahistoOF);
820 +  for(int i=0;i<datahistoOFboxes->GetN();i++) {
821 +    float ex=datahistoOFboxes->GetErrorX(i);
822 +    float ey=datahistoOFboxes->GetErrorY(i);
823 +    double x,y;
824 +    datahistoOFboxes->GetPoint(i,x,y);
825 +    float pey = sqrt(pow(y*0.07,2)+pow(datahistoOF->GetBinError(i+1),2));
826 +    datahistoOFboxes->SetPointError(ex,ex,pey,pey);
827 +    syshisto->SetBinContent(i+1,0.07);
828 +    syshisto->SetBinError(i+1,0.07);
829 +    if(y<0.01) datahistoOF->SetBinContent(i+1,0);
830 +  }
831 +  mleg->AddEntry(datahistoOFboxes,"Total uncert.","F");
832 +  datahistoOFboxes->SetFillColor(TColor::GetColor("#2E9AFE"));
833 +  
834 +  if (datahistoOF->Integral()>0) datahistoOFboxes->Draw("20");
835    if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
836 +  
837 +  datahistoSF->Draw("E1,same");
838 +  
839    //signalhisto->Draw("HIST,SAMES");
840    mleg->Draw();
841 <  DrawPrelim();
841 >  if(dataormc==data) DrawPrelim();
842 >  else DrawMCPrelim();
843    if (datahistoOF->Integral()>0) {
844 <    save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
844 > //    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
845 >    save_with_ratio_and_sys_band(0, datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF",syshisto);
846    } else {
847      CompleteSave(rcan, "SFOF/" + filename);
443    delete rcan;
848    }
849  
850    datahistoSF->Delete();
851    datahistoOF->Delete();
852    //signalhisto->Delete();
853 +  delete datahistoOFboxes;
854 +  delete syshisto;
855    delete mleg;
856 <  delete ckin;
857 <
856 >  delete rcan;
857 >  delete ofsf_can;
858    return ymaxSet;
859 + }
860 +
861 + void make_one_OFSF_plot_DataMC(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
862 +                        string xlabel, string filename, float legendPosition=0.55, int dataormc=data) {
863 +
864 +  TCut ibasiccut=basiccut;
865 +  bool draw_separation_lines=false;
866 +
867 +  if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
868 +
869 +  TCut ThisCut;
870 +
871 +  cout << "Going to use cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
872 +  ThisCut = cutnJets&&ibasiccut;
873 +  
874 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
875 +
876 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
877 +  rcan->SetLogy(logscale);
878 +  rcan->cd();
879 +
880 +  std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << ThisCut.GetTitle() << std::endl;
881 +  TH1F *datahisto    = allsamples.Draw("datahisto",  variable,nbins,min,max, xlabel, "events",ThisCut,data,luminosity);
882 +  TH1F *signalhisto  = allsamples.Draw("signalhisto",variable,nbins,min,max, xlabel, "events",ThisCut,mc,luminosity,allsamples.FindSample("SUSY_ETH_Edge"));
883 +  signalhisto->SetLineColor(TColor::GetColor("#FF8000"));
884 +  
885 +  THStack *mchisto   = new THStack(allsamples.DrawStack("mchisto",  variable,nbins,min,max, xlabel, "events",ThisCut,mc,luminosity));
886 +    
887 +  datahisto->SetMarkerSize(DataMarkerSize);
888 +
889 +  if ( !logscale ) {
890 +    datahisto->SetMinimum(0); // Defaults
891 +  } else {
892 +    datahisto->SetMinimum(0.5);
893 +  }
894 +  if (ymax<0) {
895 +    if ( logscale ) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
896 +    else datahisto->SetMaximum(0.8*datahisto->GetMaximum());
897 +  } else {
898 +    datahisto->SetMaximum(ymax);
899 +  }
900 +
901 +  float ymaxSet = datahisto->GetMaximum();
902 +
903 +  datahisto->GetXaxis()->SetTitle(xlabel.c_str());
904 +  datahisto->GetYaxis()->SetTitle("Events");
905 +  datahisto->GetXaxis()->CenterTitle();
906 +  datahisto->GetYaxis()->CenterTitle();
907 +  
908 +  TH1F *CollapsedStack = CollapseStack(mchisto);
909 +  signalhisto->Scale((1.0/signalhisto->GetBinContent(signalhisto->FindBin(1.0))) * ( datahisto->GetBinContent(datahisto->FindBin(1.0)) - CollapsedStack->GetBinContent(CollapsedStack->FindBin(1.0))));
910 +  mchisto->Add(signalhisto);
911 +  CollapsedStack = CollapseStack(mchisto);
912 +  
913  
914 +  TLegend *mleg = allsamples.allbglegend(legendTitle.c_str(),datahisto, legendPosition,0.6);
915 +  mleg->AddEntry(signalhisto,"Sample signal","f");
916 +  datahisto->Draw("E1");
917 +  mchisto->Draw("HIST,SAMES");
918 +  datahisto->Draw("E1,same");
919 + //  signalhisto->Draw("histo,same");
920 +  mleg->Draw();
921 +  
922 +  DrawPrelim();
923 +  
924 +  Save_With_Ratio(datahisto, CollapsedStack, rcan, "SFOF/" + filename+"_dataMC", false, false);
925 +  
926 +  THStack *tempstack = new THStack();
927 +  tempstack->Add(datahisto);
928 +
929 +  write_info(__FUNCTION__,"0 btag bin : ");
930 +  WriteYield(tempstack, 0.1, 0.5);
931 +  WriteYield(mchisto, 0.1, 0.5);
932 +  write_info(__FUNCTION__,">=1 btag bin : ");
933 +  WriteYield(tempstack, 1.0, 1000);
934 +  WriteYield(mchisto, 1.0, 1000);
935 +  datahisto->Delete();
936 +  mchisto->Delete();
937 +  
938 +  delete signalhisto;
939 +  delete tempstack;
940 +  delete CollapsedStack;
941 +  delete mleg;
942 +  delete rcan;
943 +  delete ofsf_can;
944   }
945  
946   // Compare data to data
# Line 468 | Line 958 | float make_data_comparison_plot(string v
958  
959    TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
960    TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
961 <  data2->Scale(4.1/5.2);
961 >  data1->Scale(5.0/9.2);
962  
963    data1->SetMarkerSize(DataMarkerSize);
964    data2->SetLineColor(kRed);
# Line 493 | Line 983 | float make_data_comparison_plot(string v
983    data1->GetYaxis()->CenterTitle();
984  
985    TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
986 <  mleg->AddEntry(data1, "New 4.1 fb^{-1}", "PL");
987 <  mleg->AddEntry(data2, "Old 5.1 fb^{-1} (scaled) ", "L");
986 >  mleg->AddEntry(data1, "2012 data (scaled)", "PL");
987 >  mleg->AddEntry(data2, "2011 data", "L");
988  
989    data1->Draw("E1");
990    data2->Draw("HIST,SAMES");
991    mleg->Draw();
992    DrawPrelim();
993 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
993 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
994  
995    data1->Delete();
996    data2->Delete();
997    delete mleg;
998 +  delete rcan;
999    delete ckin;
1000  
1001   }
1002  
1003 < void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
1004 <                     string xlabel, string filename, float legendPosition=0.55) {
1003 > void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
1004 >                     string xlabel, string filename, float tymax=-1, float legendPosition=0.55, int dataormc=data) {
1005  
1006 <  string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
1006 >  string mllcuts[] = { "mll>20","mll>20&&mll<70", "mll>75&&mll<105", "mll>120" };
1007    string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
1008    string plotname[] = {"_all","_low","_peak","_high"};
1009    float ymax;
1010 +  if(tymax>0) ymax=tymax;
1011  
1012    int start = 0;
1013 +  write_info(__FUNCTION__,"Taking a short cut on line 916 or so");start=1;
1014    if ( !PlottingSetup::openBox ) start = 3;
1015  
1016 <  for ( int i=start; i<4; ++i ) {
1016 >  for ( int i=start; i<2; ++i ) {
1017 >    if(i==2) continue;
1018      if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
1019 <    if ( i==start ) {
1020 <      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
1021 <                         filename+plotname[i], legendPosition );
1019 >    if ( i==start && !(tymax>0) ) {
1020 >      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
1021 >                         filename+plotname[i], legendPosition,dataormc );
1022 >
1023      } else {
1024        make_one_OFSF_plot(variable, mllcuts[i],        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1025 <                         filename+plotname[i], legendPosition );
1025 >                         filename+plotname[i], legendPosition , dataormc);
1026 >    }
1027 >    if(dataormc==data) {
1028 >      make_one_OFSF_plot_DataMC(variable, mllcuts[i]+"&&id1==id2",        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1029 >                         filename+plotname[i]+"_SF", legendPosition , dataormc);
1030 >      make_one_OFSF_plot_DataMC(variable, mllcuts[i]+"&&id1!=id2",        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1031 >                         filename+plotname[i]+"_OF", legendPosition , dataormc);
1032      }
1033 <    make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1033 > /*    make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1034                         filename+plotname[i]+"_mm", legendPosition );
1035      make_one_OFSF_plot(variable, "id1==0&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
1036 <                       filename+plotname[i]+"_ee", legendPosition );
1036 >                       filename+plotname[i]+"_ee", legendPosition );*/
1037    }
1038  
1039   }
1040  
1041 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
1042 +  string scut=(string)(const char*)cut;
1043 +  string acut=ReplaceAll(scut,replacethis,withthis);
1044 +  return TCut(acut.c_str());
1045 + }
1046 +
1047 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1048 +  TCut cut=addcut&&basiccut;
1049 +
1050 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1051 +  ckin->SetLogy(dolog);
1052 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
1053 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1054 +  datahisto->SetMarkerSize(DataMarkerSize);
1055 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1056 +  else datahisto->SetMinimum(0.5);
1057 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1058 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1059 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
1060 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1061 +  TH1F *MCcentral = CollapseStack(mcstack);
1062 +
1063 +  TCut bkpcut = cut;
1064 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
1065 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
1066 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1067 +
1068 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
1069 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
1070 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1071 +  
1072 +  cut=bkpcut;
1073 +  TCut bkpweight = cutWeight;
1074 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
1075 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
1076 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1077 +  
1078 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
1079 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
1080 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1081 +  cutWeight=bkpweight;
1082 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
1083 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
1084 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1085 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
1086 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
1087 +    float jes   = jesdn>jesup?jesdn:jesup;
1088 +    
1089 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
1090 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
1091 +    float pu   = PUdn>PUup?PUdn:PUup;
1092 +    
1093 +    float sys=sqrt(jes*jes+pu*pu);
1094 +    sys/=MCcentral->GetBinContent(i);
1095 +    if(MCcentral->GetBinContent(i)==0) sys=0;
1096 +    Systematic->SetBinContent(i,sys);
1097 +  }
1098 +  
1099 +  datahisto->Draw("e1");
1100 +  ckin->Update();
1101 +  mcstack.Draw("histo,same");
1102 +  
1103 +  datahisto->Draw("same,e1");
1104 +  TLegend *kinleg = allsamples.allbglegend();
1105 +  kinleg->Draw();
1106 +
1107 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1108 +  kinpad->SetLogy(dolog);
1109 +  kinpad->cd();
1110 +  datahisto->Draw("e1");
1111 +  mcstack.Draw("histo,same");
1112 +  datahisto->Draw("same,e1");
1113 +  datahisto->Draw("same,axis");
1114 +  
1115 +  kinleg->Draw("same");
1116 +  DrawPrelim();
1117 +  string saveas="kin/"+filename;
1118 +  
1119 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1120 +  save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1121 +  
1122 +  ckin->cd();
1123 +  MCcentral->SetFillColor(kWhite);
1124 +  MCcentral->SetLineColor(kBlack);
1125 +  MCcentral->SetLineWidth(2);
1126 +  MCPUdn->SetLineColor(kRed);
1127 +  MCPUup->SetLineColor(kYellow);
1128 +  MCJESdn->SetLineColor(kBlue);
1129 +  MCJESup->SetLineColor(kGreen);
1130 +  
1131 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
1132 +  legsmall->SetNColumns(5);
1133 +  legsmall->AddEntry(MCcentral,"central","L");
1134 +  legsmall->AddEntry(MCPUdn,"PU down","L");
1135 +  legsmall->AddEntry(MCPUup,"PU up","L");
1136 +  legsmall->AddEntry(MCJESdn,"JES down","L");
1137 +  legsmall->AddEntry(MCJESup,"JES up","L");
1138 +  legsmall->SetFillColor(kWhite);
1139 +  legsmall->SetBorderSize(0);
1140 +  
1141 +  datahisto->Draw("e1");
1142 +  MCcentral->Draw("histo,same");
1143 +  MCPUdn->Draw("histo,same");
1144 +  MCPUup->Draw("histo,same");
1145 +  MCJESdn->Draw("histo,same");
1146 +  MCJESup->Draw("histo,same");
1147 +  datahisto->Draw("e1,same");
1148 +  legsmall->Draw();
1149 +  CompleteSave(ckin,saveas+"___AllLines");
1150 +  
1151 +  delete datahisto;
1152 +  delete MCcentral;
1153 +  delete MCPUdn;
1154 +  delete MCPUup;
1155 +  delete MCJESdn;
1156 +  delete MCJESup;
1157 +  delete ckin;
1158 + }
1159  
1160 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1161 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1162 + }
1163 +  
1164   float lastrange_min=0;
1165   float lastrange_max=0;
1166  
# Line 630 | Line 1253 | void make_kin_plot(string variable, stri
1253    THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1254    datahisto->Draw("e1");
1255    ckin->Update();
1256 <  mcstack.Draw("same");
1256 >  mcstack.Draw("histo,same");
1257    
1258    datahisto->Draw("same,e1");
1259    TLegend *kinleg = allsamples.allbglegend();
# Line 673 | Line 1296 | void make_kin_plot(string variable, stri
1296          kinpad->cd();
1297          kinpad->SetLogy(logscale);
1298          datahisto->Draw("e1");
1299 <        mcstack.Draw("same");
1299 >        mcstack.Draw("histo,same");
1300          if(drawsignal) signalhisto->Draw("same");
1301          datahisto->Draw("same,e1");
1302          datahisto->Draw("same,axis");
# Line 688 | Line 1311 | void make_kin_plot(string variable, stri
1311          DrawPrelim();
1312          string saveas="kin/"+filename;
1313          if(isPF) saveas="kin/"+filename+"__PF";
1314 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1314 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1315   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
1316   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
1317   //      delete with_ratio;
# Line 701 | Line 1324 | void make_kin_plot(string variable, stri
1324    delete ckin;
1325   }
1326  
1327 +
1328 + void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
1329 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
1330 +  TCut cut=TCut(addcut.c_str())&&basiccut;
1331 +
1332 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1333 +  ckin->SetLogy(logscale);
1334 +  TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1335 +  datahisto->SetMarkerSize(DataMarkerSize);
1336 +  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
1337 +  else datahisto->SetMinimum(0.5);
1338 +  // Custom max.
1339 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1340 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1341 +
1342 +  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
1343 +  if(loadlastminmax) {
1344 +        datahisto->SetMinimum(lastrange_min);
1345 +        datahisto->SetMaximum(lastrange_max);
1346 +        if(logscale) {
1347 +                datahisto->SetMinimum(pow(10,lastrange_min));
1348 +                datahisto->SetMaximum(pow(10,lastrange_max));
1349 +        }              
1350 +  }
1351 +
1352 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1353 +  datahisto->Draw("e1");
1354 +  ckin->Update();
1355 +  mcstack.Draw("histo,same");
1356 +  
1357 +  datahisto->Draw("same,e1");
1358 +  TLegend *kinleg = allsamples.allbglegend();
1359 +  kinleg->Draw();
1360 +
1361 +  lastrange_min=ckin->GetUymin();
1362 +  lastrange_max=ckin->GetUymax();
1363 +
1364 +  if ( plotratio ) {
1365 +        TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1366 +        kinpad->cd();
1367 +        kinpad->SetLogy(logscale);
1368 +        datahisto->Draw("e1");
1369 +        mcstack.Draw("histo,same");
1370 +        datahisto->Draw("same,e1");
1371 +        datahisto->Draw("same,axis");
1372 +          
1373 +        kinleg->Draw();
1374 +        DrawPrelim();
1375 +        string saveas="kin/"+filename;
1376 +        if(isPF) saveas="kin/"+filename+"__PF";
1377 +        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1378 +  } else {
1379 +        if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
1380 +        else CompleteSave(ckin,"kin/"+filename);
1381 +  }
1382 +  datahisto->Delete();
1383 +  delete ckin;
1384 + }
1385 +
1386 +
1387   void make_JES_plot(TCut cut, string name) {
1388  
1389    int nbins=10;
# Line 734 | Line 1417 | void make_JES_plot(TCut cut, string name
1417    JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
1418    JESunc->SetFillStyle(3002);
1419    datahisto->Draw("e1");
1420 <  mcstack.Draw("same");
1420 >  mcstack.Draw("histo,same");
1421    JESunc->Draw("2");
1422    datahisto->Draw("same,e1");
1423    TLegend *kinleg = allsamples.allbglegend();
# Line 743 | Line 1426 | void make_JES_plot(TCut cut, string name
1426    CompleteSave(ckin,"Systematics/JES"+name);
1427    datahisto->Delete();
1428    delete ckin;
1429 +  delete JESunc;
1430 +  delete JESup;
1431 +  delete JESdn;
1432 +  CleanLegends();
1433 + }
1434 +
1435 + string Cut2Str(TCut cut) {
1436 +  return ((string)(const char*)cut);
1437 + }
1438 +
1439 + void MakeElegantTwoThreeComparisons() {
1440 +    
1441 +    TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
1442 +    TCut TwoJets("pfJetGoodNum40==2");
1443 +    TCut ThreeJets("pfJetGoodNum40>=3");
1444 +    
1445 +    float min=20;
1446 +    float max=300;
1447 +    int nbins=int((max-min)/5.0);
1448 +    string xlabel="m_{ll} [GeV]";
1449 +    
1450 +    TCanvas *can2 = new TCanvas("can2","can2");
1451 +    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1452 +    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1453 +    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1454 +    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1455 +    
1456 +    can2->cd(1);
1457 +    
1458 +    TwoSF->SetFillColor(kWhite);
1459 +    TwoOF->SetFillColor(kWhite);
1460 +    ThreeSF->SetFillColor(kWhite);
1461 +    ThreeOF->SetFillColor(kWhite);
1462 +    
1463 +    TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1464 +    kin3->cd();
1465 +    TwoOF->Draw("histo");
1466 +    TwoSF->Draw("e1,same");
1467 +    TLegend *leg_SFOF_Two = make_legend();
1468 +    leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1469 +    leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1470 +    leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1471 +    leg_SFOF_Two->Draw();
1472 +    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1473 +    
1474 +    TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1475 +    kin4->cd();
1476 +    ThreeOF->Draw("histo");
1477 +    ThreeSF->Draw("e1,same");
1478 +    TLegend *leg_SFOF_Three = make_legend();
1479 +    leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1480 +    leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1481 +    leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1482 +    leg_SFOF_Three->Draw();
1483 +    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1484 +    
1485 +    
1486 +    TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1487 +    TPad *kin = new TPad("kin","kin",0,0,1,1);
1488 +    kin->cd();
1489 +    TwoSF->Draw("histo");
1490 +    ThreeSF->Draw("e1,same");
1491 +    TLegend *leg_SF_Two_Three = make_legend();
1492 +    leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1493 +    leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1494 +    leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1495 +    leg_SF_Two_Three->Draw();
1496 +    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1497 +    
1498 +    TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1499 +    TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1500 +    kin2->cd();
1501 +    TwoOF->Draw("histo");
1502 +    ThreeOF->Draw("e1,same");
1503 +    TLegend *leg_OF_Two_Three = make_legend();
1504 +    leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1505 +    leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1506 +    leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1507 +    leg_OF_Two_Three->Draw();
1508 +    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1509 +    
1510 + }
1511 +
1512 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1513 +  pad->cd();
1514 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1515 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1516 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1517 +    float error=abs(Down->GetBinContent(i)-average);
1518 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1519 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1520 +  }
1521 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1522 +  gr->GetYaxis()->SetRangeUser(0,2);
1523 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1524 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1525 +  gr->GetXaxis()->CenterTitle();
1526 +  gr->GetYaxis()->CenterTitle();
1527 +  
1528 +  gr->Draw("A2");
1529 +  central->Draw("e1,same");
1530 +  DrawMCPrelim();
1531 +  TText *rtitle = write_text(0.8,0.8,title);
1532 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1533 +  line->SetLineColor(kBlue);
1534 +  line->SetLineStyle(2);
1535 +  line->Draw("same");
1536 +  rtitle->Draw("same");
1537 + }
1538 +
1539 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1540 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1541 +  basehisto->Add(originalttbar,-1);
1542 +  basehisto->Add(httbar);
1543 +  
1544 +  string sname=httbar->GetName();
1545 +  sname="R"+sname.substr(1,sname.length());
1546 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1547 +  ratio->Divide(basehisto);
1548 +  delete basehisto;
1549 +  return ratio;
1550 + }
1551 +  
1552 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1553 +  
1554 +  TCut cut=addcut&&basiccut;
1555 +  
1556 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1557 +  ckin->SetLogy(dolog);
1558 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1559 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1560 +  datahisto->SetMarkerSize(DataMarkerSize);
1561 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1562 +  else datahisto->SetMinimum(0.5);
1563 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1564 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1565 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1566 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1567 +  TH1F *MCcentral = CollapseStack(mcstack);
1568 +
1569 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1570 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("/TT_"));
1571 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1572 +  
1573 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1574 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1575 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1576 +  
1577 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1578 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1579 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1580 +  
1581 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1582 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1583 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1584 +  
1585 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1586 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1587 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1588 +  
1589 +  datahisto->Draw("e1");
1590 +  ckin->Update();
1591 +  mcstack.Draw("histo,same");
1592 +  
1593 +  datahisto->Draw("same,e1");
1594 +  TLegend *kinleg = allsamples.allbglegend();
1595 +  kinleg->Draw();
1596 +
1597 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1598 +  kinpad->SetLogy(dolog);
1599 +  kinpad->cd();
1600 +  datahisto->Draw("e1");
1601 +  mcstack.Draw("histo,same");
1602 +  datahisto->Draw("same,e1");
1603 +  datahisto->Draw("same,axis");
1604 +  
1605 +  kinleg->Draw("same");
1606 +  DrawPrelim();
1607 +  string saveas="kin/"+filename;
1608 +  
1609 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1610 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1611 +  delete kinpad;
1612 +  
1613 +  ckin->cd();
1614 +  TCentral->SetLineColor(kBlack);
1615 +  
1616 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1617 +  TMatchingUp->SetLineStyle(2);//dashed
1618 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1619 +  TMatchingDown->SetLineStyle(3);//dotted
1620 +  
1621 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1622 +  TScaleUp->SetLineStyle(2);//dashed
1623 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1624 +  TScaleDown->SetLineStyle(3);//dotted
1625 +  
1626 +  MCcentral->SetLineStyle(3);
1627 +  MCcentral->SetLineColor(kRed);
1628 +  
1629 +  TCentral->Draw("e1,same");
1630 +  TCentral->Draw("histo,same");
1631 +  TMatchingUp->Draw("histo,same");
1632 +  TMatchingDown->Draw("histo,same");
1633 +  TScaleUp->Draw("histo,same");
1634 +  TScaleDown->Draw("histo,same");
1635 +  
1636 +  TLegend *sleg = make_legend();
1637 +  sleg->AddEntry(TCentral,"Central","L");
1638 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1639 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1640 +  sleg->AddEntry(TScaleUp,"scale up","L");
1641 +  sleg->AddEntry(TScaleDown,"scale down","L");
1642 +  sleg->Draw();
1643 +  
1644 +  CompleteSave(ckin,saveas+"___AllLines");
1645 +  ckin->cd();
1646 +  ckin->SetLogy(0);
1647 +  
1648 +  RCentral->SetLineColor(kBlack);
1649 +  
1650 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1651 +  RMatchingUp->SetLineStyle(2);//dashed
1652 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1653 +  RMatchingDown->SetLineStyle(3);//dotted
1654 +  
1655 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1656 +  RScaleUp->SetLineStyle(2);//dashed
1657 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1658 +  RScaleDown->SetLineStyle(3);//dotted
1659 +  
1660 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1661 +  RCentral->Draw("e1");
1662 +  RMatchingUp->Draw("histo,same");
1663 +  RMatchingDown->Draw("histo,same");
1664 +  RScaleUp->Draw("histo,same");
1665 +  RScaleDown->Draw("histo,same");
1666 +  
1667 +  CompleteSave(ckin,saveas+"___AllRatios");
1668 +
1669 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1670 +  multicanvas->Divide(2,1);
1671 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1672 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1673 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1674 +  
1675 +  
1676 +  delete datahisto;
1677 +  delete   TCentral;
1678 +  delete   TMatchingUp;
1679 +  delete   TMatchingDown;
1680 +  delete   TScaleUp;
1681 +  delete   TScaleDown;
1682 + //   delete   Ttmass166;
1683 + //   delete   Ttmass169;
1684 + //   delete   Ttmass175;
1685 + //   delete   Ttmass178;
1686 +  
1687 +  delete ckin;
1688 +  
1689 + }
1690 +  
1691 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1692 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1693 + }
1694 +
1695 + void ProduceJanPlots() {
1696 +  TCanvas *c1 = new TCanvas("c1","c1");
1697 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1698 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1699 +  
1700 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1701 +  rcan->cd();
1702 +
1703 +  metOF->SetLineColor(kRed);
1704 +  metSF->Draw("e1");
1705 +  metOF->Draw("histo,same");
1706 +  metSF->Draw("e1,same");
1707 +  
1708 +  TLegend *leg = make_legend();
1709 +  
1710 +  leg->AddEntry(metSF,"Data SF","p");
1711 +  leg->AddEntry(metOF,"Data OF","l");
1712 +  leg->Draw();
1713 +  
1714 +  DrawPrelim();
1715 +  
1716 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1717 +  
1718 +  delete rcan;
1719 +  delete metSF;
1720 +  delete metOF;
1721 +  delete c1;
1722 + }
1723 +
1724 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1725 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1726 +  
1727 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1728 +  if(variation!="Central") {
1729 +    TH1F *varttbar;
1730 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1731 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1732 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1733 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1734 +    assert(varttbar);
1735 +    
1736 +    TIter nextHisto(SystPlot.GetHists());
1737 +    TH1F* h;
1738 +    while ( h = (TH1F*)nextHisto() ) {
1739 +      if(Contains(h->GetName(),"t_bar_t")) {
1740 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1741 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1742 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1743 +          h->SetBinError(i,varttbar->GetBinError(i));
1744 +        }
1745 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1746 +        SystPlot.Modified();
1747 +      }
1748 +    }
1749 +    delete varttbar;
1750 +  } else {
1751 +    TIter nextHisto(SystPlot.GetHists());
1752 +    TH1F* h;
1753 +    while ( h = (TH1F*)nextHisto() ) {
1754 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1755 +    }
1756 +  }
1757 +    
1758 +  TLegend *fullleg = allsamples.allbglegend();
1759 +  fullleg->SetHeader(variation.c_str());
1760 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1761 +  kinpad->SetLogy(1);
1762 +  kinpad->cd();
1763 +  
1764 +  hdata->Draw("e1");
1765 +  SystPlot.Draw("histo,same");
1766 +  hdata->Draw("e1,same");
1767 +  fullleg->Draw();
1768 +  DrawPrelim();
1769 +  
1770 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1771 +  CleanLegends();
1772 +  
1773 +  delete kinpad;
1774 +  return SystPlot;
1775 + }
1776 +  
1777 +
1778 +
1779 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1780 +  TCanvas *ca = new TCanvas("ca","ca");
1781 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1782 +  
1783 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1784 +  
1785 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1786 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1787 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1788 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1789 +  
1790 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1791 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1792 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1793 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1794 +  
1795 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1796 +  TH1F *HCentral = CollapseStack(Central);
1797 +  
1798 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1799 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1800 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1801 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1802 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1803 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1804 +    
1805 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1806 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1807 +    
1808 +    float sys=sqrt(matching*matching+scale*scale);
1809 +    sys/=HCentral->GetBinContent(i);
1810 +    if(HCentral->GetBinContent(i)==0) sys=0;
1811 +    Systematic->SetBinContent(i,sys);
1812 +  }
1813 +  
1814 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1815 +  kinpad->SetLogy(1);
1816 +  kinpad->cd();
1817 +  if(variable=="genMET") {
1818 +    Central.Draw("histo");
1819 +  } else {
1820 +    hdata->Draw("e1");
1821 +    Central.Draw("histo,same");
1822 +    hdata->Draw("e1,same");
1823 +  }
1824 +  
1825 +  DrawPrelim();
1826 +  
1827 +  save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1828 +  
1829 +  kinpad->cd();
1830 +  tCentral->SetFillColor(kWhite);
1831 +  tCentral->SetLineColor(kBlack);
1832 +  tScaleUp->SetLineColor(kRed);
1833 +  tScaleDown->SetLineColor(kRed);
1834 +  tMatchingUp->SetLineColor(kBlue);
1835 +  tMatchingDown->SetLineColor(kBlue);
1836 +  tScaleUp->SetLineStyle(2);
1837 +  tScaleDown->SetLineStyle(3);
1838 +  tMatchingUp->SetLineStyle(2);
1839 +  tMatchingDown->SetLineStyle(3);
1840 +  
1841 +  TLegend *leg2 = make_legend();
1842 +  leg2->AddEntry(hdata,"Data","p");
1843 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1844 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1845 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1846 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1847 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1848 +  if(variable=="genMET") {
1849 +    Central.Draw("histo");
1850 +  }else {
1851 +    hdata->Draw("e1");
1852 +    Central.Draw("histo,same");
1853 +    hdata->Draw("e1,same");
1854 +  }
1855 +  tCentral->Draw("histo,same");
1856 +  tScaleUp->Draw("histo,same");
1857 +  tScaleDown->Draw("histo,same");
1858 +  tMatchingUp->Draw("histo,same");
1859 +  tMatchingDown->Draw("histo,same");
1860 +  leg2->Draw();
1861 +  
1862 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1863 +  
1864 +  gStyle->SetOptFit(0);
1865 +  
1866 +  kinpad->cd();
1867 +  kinpad->SetLogy(0);
1868 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1869 +  MatchingRatio->Divide(tMatchingDown);
1870 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1871 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1872 +  lone->SetLineStyle(2);
1873 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1874 +  ScaleRatio->Divide(tScaleDown);
1875 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1876 +  MatchingRatio->Draw("e1");
1877 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1878 +  MatchingRatio->Fit("QP1","R");
1879 +  lone->Draw();
1880 +  stringstream summary;
1881 +  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);
1882 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1883 +  TText *infobox = write_title(summary.str());
1884 +  infobox->SetX(0.75);
1885 +  infobox->SetTextSize(0.03);
1886 +  infobox->SetY(0.75);
1887 +  infobox->Draw();
1888 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1889 +  kinpad->cd();
1890 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1891 +  ScaleRatio->Draw("e1");
1892 +  ScaleRatio->Fit("QP1","R");
1893 +  summary.str("");
1894 +  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);
1895 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1896 +  TText *infobox2 = write_title(summary.str());
1897 +  infobox2->SetX(0.75);
1898 +  infobox2->SetTextSize(0.03);
1899 +  infobox2->SetY(0.75);
1900 +  infobox2->Draw();
1901 +
1902 +  lone->Draw();
1903 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1904 +  
1905 +  
1906 +  delete QP1;
1907 +  delete infobox;
1908 +  delete infobox2;
1909 +  delete MatchingRatio;
1910 +  delete ScaleRatio;
1911 +  DeleteStack(ScaleUp);
1912 +  DeleteStack(ScaleDown);
1913 +  DeleteStack(MatchingUp);
1914 +  DeleteStack(MatchingDown);
1915 +  delete leg2;
1916 +  CleanLegends();
1917 +  DeleteStack(Central);
1918 +  delete Systematic;
1919 +  delete HScaleUp;
1920 +  delete HScaleDown;
1921 +  delete HMatchingUp;
1922 +  delete HMatchingDown;
1923 +  delete hdata;
1924 +  delete HCentral;
1925 +  delete ca;
1926 + }
1927 +
1928 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1929 +  float val=0,err=0;
1930 +  vector<float> bins;
1931 +  vector<float> vals;
1932 +  vector<float> errs;
1933 +  
1934 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1935 +  int iBin=1;
1936 +  
1937 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1938 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1939 +      bins.push_back(histo->GetBinLowEdge(i));
1940 +      vals.push_back(val);val=0;
1941 +      errs.push_back(err);err=0;
1942 +      iBin++;
1943 +    }
1944 +    val+=histo->GetBinContent(i);
1945 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1946 +  }
1947 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1948 +  vals.push_back(val);val=0;
1949 +  errs.push_back(err);err=0;
1950 +  
1951 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1952 +  for(unsigned int i=0;i<vals.size();i++) {
1953 +    h->SetBinContent(i+1,vals[i]);
1954 +    h->SetBinError(i+1,errs[i]);
1955 +  }
1956 +  
1957 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1958 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1959 +  
1960 +  h->GetXaxis()->CenterTitle();
1961 +  h->GetYaxis()->CenterTitle();
1962 +
1963 +  return h;
1964 + }
1965 +
1966 +
1967 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1968 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1969 +  float val=0,err=0;
1970 +  vector<float> bins;
1971 +  vector<float> vals;
1972 +  vector<float> errs;
1973 +  
1974 +  bins.push_back(histo->GetBinLowEdge(1));
1975 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1976 +    val+=histo->GetBinContent(i);
1977 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1978 +    if( val/statsperbin > 0.85) {
1979 +      if(bins.size()<nbins) {
1980 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1981 +        vals.push_back(val);val=0;
1982 +        errs.push_back(err);err=0;
1983 +      }
1984 +    }
1985 +    if(i==histo->GetNbinsX()) {
1986 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1987 +      vals.push_back(val);val=0;
1988 +      errs.push_back(err);err=0;
1989 +    }
1990 +  }
1991 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1992 +  
1993 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1994 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1995 +  
1996 +  h->GetXaxis()->CenterTitle();
1997 +  h->GetYaxis()->CenterTitle();
1998 +  
1999 +  for(unsigned int i=0;i<vals.size();i++) {
2000 +    h->SetBinContent(i+1,vals[i]);
2001 +    h->SetBinError(i+1,errs[i]);
2002 +  }
2003 +  
2004 +  return h;
2005 + }
2006 +
2007 +
2008 +  
2009 + void ShowBinning(TH1F *histo) {
2010 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
2011 +  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;
2012 + }
2013 +  
2014 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
2015 +  TCanvas *ca = new TCanvas("ca","ca");
2016 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
2017 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
2018 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
2019 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
2020 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
2021 +  
2022 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
2023 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
2024 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
2025 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
2026 +  tCentral->Scale(1.0/tCentral->Integral());
2027 +  
2028 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
2029 +  
2030 +  
2031 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
2032 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
2033 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
2034 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
2035 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
2036 +  
2037 +  float min=rtScaleUp->GetMinimum();
2038 +  float max=rtScaleUp->GetMaximum();
2039 +  
2040 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
2041 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2042 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2043 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
2044 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
2045 +  
2046 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
2047 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2048 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2049 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
2050 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
2051 +  
2052 +  rtCentral->SetMaximum(1.2*max);
2053 +  rtCentral->SetMinimum(0.8*min);
2054 +  
2055 + /*  tScaleUp->Rebin(40);
2056 +  tScaleDown->Rebin(40);
2057 +  tMatchingDown->Rebin(40);
2058 +  tMatchingUp->Rebin(40);
2059 +  tCentral->Rebin(40);*/
2060 +  
2061 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2062 +  kinpad->SetLogy(1);
2063 +  kinpad->cd();
2064 +  tCentral->SetFillColor(kWhite);
2065 +  tCentral->SetLineColor(kBlack);
2066 +  tScaleUp->SetLineColor(kRed);
2067 +  tScaleDown->SetLineColor(kRed);
2068 +  tMatchingUp->SetLineColor(kBlue);
2069 +  tMatchingDown->SetLineColor(kBlue);
2070 +  tScaleUp->SetLineStyle(2);
2071 +  tScaleDown->SetLineStyle(3);
2072 +  tMatchingUp->SetLineStyle(2);
2073 +  tMatchingDown->SetLineStyle(3);
2074 +  
2075 +  rtScaleDown->SetLineColor(kRed);
2076 +  rtMatchingUp->SetLineColor(kBlue);
2077 +  rtMatchingDown->SetLineColor(kBlue);
2078 +  rtScaleUp->SetLineStyle(2);
2079 +  rtScaleDown->SetLineStyle(3);
2080 +  rtMatchingUp->SetLineStyle(2);
2081 +  rtMatchingDown->SetLineStyle(3);
2082 +  
2083 +  TLegend *leg2 = make_legend();
2084 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
2085 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
2086 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
2087 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
2088 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
2089 +  
2090 +  tCentral->Draw("histo");
2091 +  tScaleUp->Draw("histo,same");
2092 +  tScaleDown->Draw("histo,same");
2093 +  tMatchingUp->Draw("histo,same");
2094 +  tMatchingDown->Draw("histo,same");
2095 +  leg2->Draw();
2096 +  DrawMCPrelim();
2097 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
2098 +  kinpad->cd();
2099 +  kinpad->SetLogy(0);
2100 +  rtCentral->Draw("histo");
2101 +  rtScaleUp->Draw("histo,same");
2102 +  rtScaleDown->Draw("histo,same");
2103 +  rtMatchingUp->Draw("histo,same");
2104 +  rtMatchingDown->Draw("histo,same");
2105 +  leg2->Draw();
2106 +  DrawMCPrelim();
2107 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
2108 +  
2109 +  
2110 +  gStyle->SetOptFit(0);
2111 +
2112 +  kinpad->cd();
2113 +  kinpad->SetLogy(0);
2114 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
2115 +  MatchingRatio->Divide(rtMatchingDown);
2116 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
2117 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
2118 +  lone->SetLineStyle(2);
2119 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
2120 +  ScaleRatio->Divide(rtScaleDown);
2121 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
2122 +  MatchingRatio->Draw("e1");
2123 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
2124 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
2125 +  lone->Draw();
2126 +  stringstream summary;
2127 +  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);
2128 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2129 +  TText *infobox = write_title(summary.str());
2130 +  infobox->SetX(0.75);
2131 +  infobox->SetTextSize(0.03);
2132 +  infobox->SetY(0.75);
2133 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
2134 +  DrawMCPrelim();
2135 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
2136 +  kinpad->cd();
2137 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
2138 +  ScaleRatio->Draw("e1");
2139 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
2140 +  summary.str("");
2141 +  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);
2142 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2143 +  TText *infobox2 = write_title(summary.str());
2144 +  infobox2->SetX(0.75);
2145 +  infobox2->SetTextSize(0.03);
2146 +  infobox2->SetY(0.75);
2147 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
2148  
2149 +  lone->Draw();
2150 +  DrawMCPrelim();
2151 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
2152 +  
2153 +  kinpad->cd();
2154 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
2155 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
2156 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
2157 +  
2158 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
2159 +    float matching, scale;
2160 +    bool AssumeFactor=false;
2161 +    if(AssumeFactor) {
2162 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
2163 +      matching=0.;
2164 +      scale=0.;
2165 +    } else {
2166 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
2167 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
2168 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
2169 +    }
2170 +    
2171 +    SysMatching->SetBinContent(i,1+matching);
2172 +    SysScale->SetBinContent(i,1+scale);
2173 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
2174 +  }
2175 +  
2176 +  SysHisto->SetLineColor(kGreen);
2177 +  
2178 +  SysMatching->SetMaximum(3.0);
2179 +  SysMatching->SetMinimum(0.0);
2180 +  SysMatching->Draw("histo");
2181 +  SysScale->Draw("histo,same");
2182 +  SysHisto->Draw("histo,same");
2183 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
2184 +  
2185 +  delete SysMatching;
2186 +  delete SysScale;
2187 +  
2188 +  if(!Contains(variable,"gen")) {
2189 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
2190 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
2191 +    
2192 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
2193 +    
2194 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
2195 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
2196 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
2197 +      float sys = SysHisto->GetBinContent(iBin)-1;
2198 +      Systematic->SetBinContent(i,sys);
2199 +    }
2200 +    
2201 +    kinpad->cd();
2202 +    TLegend *leg = allsamples.allbglegend();
2203 +    hdata->Draw();
2204 +    smc.Draw("histo,same");
2205 +    hdata->Draw("same");
2206 +    leg->Draw();
2207 +    DrawPrelim();
2208 +    save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
2209 +    
2210 +    delete Systematic;
2211 +    delete hdata;
2212 +  }
2213 +  
2214 +  
2215 +  delete SysHisto;
2216 +  delete tScaleUp;
2217 +  delete tScaleDown;
2218 +  delete tCentral;
2219 +  delete tMatchingUp;
2220 +  delete tMatchingDown;
2221 +  delete rtScaleUp;
2222 +  delete rtScaleDown;
2223 +  delete rtCentral;
2224 +  delete rtMatchingUp;
2225 +  delete rtMatchingDown;
2226 +  delete QP1;
2227 +  delete infobox;
2228 +  delete infobox2;
2229 +  delete MatchingRatio;
2230 +  delete ScaleRatio;
2231 +  delete leg2;
2232 +  CleanLegends();
2233 +  delete ca;
2234 + }
2235 +
2236 + void ProduceMCSystematicPlots() {
2237 +  cout << "Getting ready to produce systematic plots " << endl;
2238 +  TCut cutweightBKP = cutWeight;
2239 +  
2240 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
2241 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
2242 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
2243 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
2244 +  
2245 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
2246 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
2247 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
2248 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
2249 +  
2250 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
2251 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
2252 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
2253 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
2254 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
2255 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
2256 +  
2257 +  
2258 +  
2259 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2260 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2261 +  cutWeight="1.0";
2262 +  
2263 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2264 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
2265 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2266 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2267 +  
2268 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2269 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
2270 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2271 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2272 +  
2273 +  
2274 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
2275 +  
2276 +  /*
2277 +  cutWeight=cutweightBKP;
2278 +  TCut essentialcutBKP = essentialcut;
2279 +  cout << (const char*) essentialcut << endl;
2280 +  
2281 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
2282 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2283 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2284 +  
2285 +  TCut cutnJetsBKP = cutnJets;
2286 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
2287 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
2288 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2289 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2290 +  
2291 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
2292 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
2293 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
2294 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
2295 +  
2296 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
2297 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
2298 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2299 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
2300 +  
2301 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
2302 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
2303 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2304 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
2305 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
2306 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
2307 +  
2308 +  
2309 +  
2310 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2311 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2312 +  cutWeight="1.0";
2313 +  
2314 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2315 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
2316 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2317 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2318 +  
2319 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2320 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
2321 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2322 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2323 +  
2324 +  cutnJets  = cutnJetsBKP;
2325 +  cutWeight = cutweightBKP;
2326 +  essentialcut = essentialcutBKP;
2327 +  */
2328 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
2329 + }
2330 +
2331 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
2332 +  TCut cut=pcut&&basiccut;
2333 +  string variable="mll";
2334 +  string xlabel="m_{ll} [GeV]";
2335 +  int nbins=40;
2336 +  float min=0;
2337 +  float max=200;
2338 +
2339 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
2340 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
2341 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
2342 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2343 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2344 +  datahistoSF->SetMarkerSize(DataMarkerSize);
2345 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
2346 +  datahistoOF->SetMarkerSize(DataMarkerSize);
2347 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
2348 +
2349 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
2350 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
2351 +  datahistoSF->Draw("e1");
2352 +  ckin->Update();
2353 +  mcstackSF.Draw("histo,same");
2354 +  
2355 +  datahistoSF->Draw("same,e1");
2356 +  TLegend *kinleg = allsamples.allbglegend();
2357 +  kinleg->Draw();
2358 +  
2359 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2360 +  kinpad->cd();
2361 +  datahistoSF->Draw("e1");
2362 +  mcstackSF.Draw("histo,same");
2363 +  datahistoSF->Draw("same,e1");
2364 +  datahistoSF->Draw("same,axis");
2365 +  kinleg->Draw();
2366 +  DrawPrelim();
2367 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
2368 +  
2369 +  kinpad->cd();
2370 +  datahistoOF->Draw("e1");
2371 +  mcstackOF.Draw("histo,same");
2372 +  datahistoOF->Draw("same,e1");
2373 +  datahistoOF->Draw("same,axis");
2374 +  kinleg->Draw();
2375 +  DrawPrelim();
2376 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
2377 +  
2378 +  kinpad->cd();
2379 +  tauSF->Draw("e1");
2380 +  tauOF->Draw("histo,same");
2381 +  tauSF->Draw("e1,same");
2382 +  TLegend *legtau = make_legend();
2383 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
2384 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
2385 +  legtau->Draw();
2386 +  DrawPrelim();
2387 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
2388 +  
2389 +  delete datahistoSF;
2390 +  delete datahistoOF;
2391 +  delete tauSF;
2392 +  delete tauOF;
2393 +  delete kinpad;
2394 +  delete ckin;
2395 +  CleanLegends();
2396 + }
2397 +  
2398 +
2399 + void TauQuestion() {
2400 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2401 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2402 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2403 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2404 + }
2405 +
2406 + void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2407 +  string BaseMetCut="met[4]>100";
2408 +  string Prefix="ETH/";
2409 +  if(isAachen) {
2410 +    BaseMetCut="met[4]>150";
2411 +    Prefix="Aachen/";
2412 +  }
2413 +  
2414 + //    make_OFSF_plots("met[4]",  BaseMetCut, 20, 100., 300., true, "E_{T}^{miss}", Prefix+"MET_allmc",1500,0.55,mc);
2415 + //    make_OFSF_plots("pfTightHT",  BaseMetCut, 20, 0., 800., true, "H_{T}", Prefix+"HT_allmc",1500,0.55,mc);
2416 +    
2417 + //    make_OFSF_plots("met[4]",  BaseMetCut, 20, 100., 300., true, "E_{T}^{miss}", Prefix+"MET_onlyttbar",1500,0.55,123);
2418 + //    make_OFSF_plots("pfTightHT",  BaseMetCut, 20, 0., 800., true, "H_{T}", Prefix+"HT_onlyttbar",1500,0.55,123);
2419 +    
2420 + //    make_OFSF_plots("mll",  BaseMetCut, 36, 20., 200., false, "m_{ll}", Prefix+"Mll_onlyttbar",120,0.55,123);
2421 + //     make_OFSF_plots("mll",  BaseMetCut, 36, 20., 200., false, "m_{ll}", Prefix+"Mll_allmc",120,0.55,mc);
2422 +    
2423 + //     make_OFSF_plots("pfTightHT",  BaseMetCut, 20, 0., 800., true, "H_{T}", Prefix+"HT",1500);
2424 + //       make_OFSF_plots("met[4]",  BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET",1500);
2425 +      make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 6, -0.5, 5.5, true, "N_{b-jets}", Prefix+"nbjets",5000);
2426 +    return;
2427 + //      make_OFSF_plots("max(abs(eta1),abs(eta2))", BaseMetCut, 14, 0.0, 3.5, true, "max(|#eta_{l1}|,|#eta_{l2}|)", Prefix+"MaxAbsEta",-1);
2428 + //      make_OFSF_plots("min(abs(eta1),abs(eta2))", BaseMetCut, 14, 0.0, 3.5, true, "min(|#eta_{l1}|,|#eta_{l2}|)", Prefix+"MinAbsEta",-1);
2429 + //       make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "#tilde{S}_{T}", Prefix+"FrankT",120);
2430 + //       make_OFSF_plots("pt1+pt2+met[4]+Sum$(pfJetGoodPt)", BaseMetCut, 20, 0, 2000., false, "#tilde{S}_{T}", Prefix+"POOR_FrankT",120);
2431 +      
2432 +      
2433 + //       make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2434 + //
2435 + //       make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2436 + //       make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2437 + //       make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2438 + //  
2439 + //       make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2440 + //        make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2441 + //        make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2442 + //        make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2443 + //      
2444 + //       make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2445 + //       make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2446 + //
2447 + //       make_OFSF_plots("pfJetGoodNum40", BaseMetCut,                        7, 3, 10, true, "#(jets)", Prefix+"njets");
2448 + //       make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2449 + //       make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2450 + //
2451 + //       make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2452 + //        make_OFSF_plots("pfJetGoodPt",  BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2453 + //
2454 + //       make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2455 + //       make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2456 + //        make_OFSF_plots("pt",  BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2457 + //        make_OFSF_plots("pt1",  BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2458 + //        make_OFSF_plots("pt2",  BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2459 +       make_OFSF_plots("abs(eta1)", BaseMetCut, 10, 0, 3.5, false, "#eta_{1}", Prefix+"eta1", 200);
2460 +       make_OFSF_plots("abs(eta2)", BaseMetCut, 10, 0, 3.5, false, "#eta_{2}", Prefix+"eta2", 200);
2461 + return;
2462 + //      make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", -1, 0.2);
2463 + //      make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", -1, 0.2);
2464 + //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", -1, 0.2);
2465 + //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", -1, 0.2);
2466 +    
2467 + //      make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", -1, 0.2);
2468 + //      make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", -1, 0.2);
2469 + //      make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", -1, 0.2);
2470 + //      make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2471 + //      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");
2472 + //      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");
2473 + //      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");
2474 +      
2475 + }
2476 +
2477 + void ProduceOFSFPlots(string mcjzb, string datajzb) {
2478 +  
2479 +  
2480 +  //FIRST : ETH SELECTION
2481 +  ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2482 +  
2483 +  string backup_cutnJets = (const char*)cutnJets;
2484 +  cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2485 +  cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2486 +  
2487 +  string backup_basiccut = (const char*)basiccut;
2488 +  basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2489 +  
2490 +  string backup_essential = (const char*) essentialcut;
2491 +  essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2492 +  
2493 +  ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2494 +  
2495 +  cutnJets     = TCut(backup_cutnJets.c_str());
2496 +  basiccut     = TCut(backup_basiccut.c_str());
2497 +  essentialcut = TCut(backup_essential.c_str());
2498 + }
2499 +  
2500 + void produce_OF_SF_ZlineShapePlot() {
2501 +    TCut cut=TCut("pfJetGoodNum40==2 && met[4]<100 && pt1>20 && pt2>20");
2502 +    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
2503 +    ckin->SetLogy(1);
2504 +    TH1F *datahistoSF = allsamples.Draw("datahistoSF","mll",37,15,200, "m_{ll}", "events",cut&&cutOSSF,data,luminosity);
2505 +    TH1F *datahistoOF = allsamples.Draw("datahistoOF","mll",37,15,200, "m_{ll}", "events",cut&&cutOSOF,data,luminosity);
2506 +    
2507 +    
2508 +    float min=25;
2509 +    datahistoSF->SetMinimum(min);
2510 +    float max = datahistoSF->GetMaximum()*10;
2511 +    datahistoSF->SetMaximum(max);
2512 +    datahistoSF->Draw("e1");
2513 +    datahistoOF->SetLineColor(TColor::GetColor("#2E9AFE"));
2514 +    datahistoOF->SetFillColor(TColor::GetColor("#2E9AFE"));
2515 +    datahistoOF->Draw("histo,same");
2516 +    datahistoSF->Draw("same,e1");
2517 +    
2518 +    TLegend *leg = make_legend();
2519 +    leg->AddEntry(datahistoSF,"SF events","p");
2520 +    leg->AddEntry(datahistoOF,"OF events","f");
2521 +    leg->Draw();
2522 +    
2523 +    TLine *k = new TLine(20,min,20,max);
2524 +    k->Draw();
2525 +    TLine *l = new TLine(70,min,70,max);
2526 +    l->Draw();
2527 +    TLine *m = new TLine(81,min,81,max);
2528 +    m->SetLineColor(TColor::GetColor("#FE642E"));
2529 +    m->Draw();
2530 +    TLine *n = new TLine(101,min,101,max);
2531 +    n->SetLineColor(TColor::GetColor("#FE642E"));
2532 +    n->Draw();
2533 +    
2534 +    CompleteSave(ckin,"ZLineShape_SF_OF");
2535 +    
2536 +    delete leg;
2537 +    delete ckin;
2538 +    delete datahistoSF;
2539 +    delete datahistoOF;
2540   }
2541  
2542   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2543   {
2544   //  switch_overunderflow(true);
2545 +    
2546 +  produce_OF_SF_ZlineShapePlot();
2547 +    
2548    bool dolog=true;
2549    bool nolog=false;
2550  
2551    bool doOFSF = false;
2552    bool doKin  = false;
2553 <  bool doDataComp = true;
2553 >  bool doDataComp = false;
2554 >  bool MakeTwoThreeJetComparison = false;
2555    
2556  
2557    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 764 | Line 2561 | void do_kinematic_plots(string mcjzb, st
2561          mll_low=20;
2562          mll_hi=320;
2563    }
2564 +  
2565 +  if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2566 +  
2567 +  //TauQuestion();
2568  
2569 <  if ( doOFSF ) {
2570 <     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2571 <
2572 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2573 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2574 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
774 <
775 < //      make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
776 < //      make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
777 <
778 < //     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
779 < //     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
780 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
781 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
782 < //     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
783 < //     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
784 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
785 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
786 < //     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
787 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
788 < //    make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
789 < //    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
790 < //    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
791 < //    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");
792 < //    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");
793 < //    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");
794 < //    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");
795 <  }
796 <
2569 >  //ProduceJanPlots();
2570 >  //ProduceMCSystematicPlots();
2571 >  //assert(0);
2572 > //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2573 >  
2574 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2575    if ( doDataComp) {
2576      TCut mllCut("");
2577 <    float massmin = 15.;
2578 <    float massmax = 315;
2577 >    float massmin = 20.;
2578 >    float massmax = 320;
2579      int massnbins = 60;
2580   /*    if ( !PlottingSetup::openBox ) {
2581        mllCut = "mll>70";
# Line 808 | Line 2586 | void do_kinematic_plots(string mcjzb, st
2586  
2587      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2588      
2589 < /*    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2589 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2590 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2591 >    
2592 >    
2593 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2594 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2595      make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2596      make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2597      make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
# Line 817 | Line 2600 | void do_kinematic_plots(string mcjzb, st
2600      make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2601      make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2602      make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2603 +
2604    
821  */  
2605      string basiccutsaved = (const char*)basiccut;
2606      
2607      string newbasiccut=basiccutsaved;
# Line 829 | Line 2612 | void do_kinematic_plots(string mcjzb, st
2612        newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2613        found = newbasiccut.find( "pt2>20" );
2614      }
2615 < //    basiccut=TCut(newbasiccut.c_str());
2616 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2617 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2618 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2619 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2620 < //    basiccut=TCut(basiccutsaved.c_str());
2621 <    
2622 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2623 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2624 <    
2625 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2626 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2627 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2628 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2629 <
2630 <    
2631 < //     make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2632 < //     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2633 < //     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2634 < //     make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2615 >    basiccut=TCut(newbasiccut.c_str());
2616 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2617 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2618 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2619 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2620 >    basiccut=TCut(basiccutsaved.c_str());
2621 >    
2622 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2623 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2624 >    
2625 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2626 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2627 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2628 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2629 >
2630 >    
2631 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2632 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2633 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2634 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2635      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2636      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2637      make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2638      make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2639 < /*
2639 >
2640      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2641 +    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2642 +    
2643 +    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");
2644 +    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");
2645 +    
2646      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2647 +    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2648 +    
2649      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2650 +    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2651 +
2652  
2653      make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2654      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");
# Line 866 | Line 2658 | void do_kinematic_plots(string mcjzb, st
2658      make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2659      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2660      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2661 <  */  
2661 >
2662    }
2663  
2664  
2665    if ( doKin ) {
2666      string mllCut("");
2667 <
2668 <     make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2669 <     make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2667 >    
2668 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2669 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20&&id1==0")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF_ee",doPF,true);
2670 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20&&id1==1")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF_mm",doPF,true);
2671 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2672 >      
2673 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2674 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20&&id1==0")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF_ee",doPF,true);
2675 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20&&id1==1")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF_mm",doPF,true);
2676 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2677 >      
2678 >      assert(0);
2679 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2680 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2681 >
2682 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2683 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2684 >    
2685 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2686 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2687 >    
2688 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2689 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2690 >    
2691 >    make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2692 >    make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2693 >    
2694 >    make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2695 >    make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2696 >    
2697 >    
2698 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2699 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2700 >  
2701 >    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);
2702 >    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);
2703 >    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);
2704 >    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);
2705 >
2706 >    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);
2707 >    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);
2708 >    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);
2709 >    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);
2710 >
2711 >
2712 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2713 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2714 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2715 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2716 >
2717 >    
2718 >    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);
2719 >    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);
2720 >    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);
2721 >    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);
2722 >
2723 >    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);
2724 >    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);
2725 >    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);
2726 >    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);
2727 >
2728 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2729 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2730 >    
2731 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2732 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2733 >    
2734 >    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);
2735 >    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);
2736 >    
2737 >    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);
2738 >    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);
2739 >
2740 >    
2741 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2742 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2743      // Plots in signal region
2744 < //     make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2745 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2746 <     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);
2747 <     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);
2748 <     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);
2749 <    
2750 <     make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2751 <     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2752 <    
2753 < //     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);
2754 < //     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);
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_ee_met100",doPF,true);
2756 < //     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);
2744 >    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2745 >
2746 >
2747 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2748 >    
2749 >    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");
2750 >    
2751 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2752 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2753 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2754 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2755 >
2756 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2757 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2758 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2759 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2760 >
2761 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2762 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2763 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2764 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2765 >
2766      
2767 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2768 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2769 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2770 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2771 +
2772 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2773 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2774 +
2775 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2776 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2777 +    
2778 +    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2779 +    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2780 +    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2781 +    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2782 +
2783 +    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2784 +    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);
2785 +    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);
2786 +    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);
2787 +    
2788 +    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2789 +    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2790      
2791 < //     make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2792 < //     make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2791 >    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);
2792 >    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);
2793 >    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);
2794 >    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);
2795 >    
2796 >    
2797 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2798 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2799  
2800      // Further inclusive invariant mass plots
2801      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2802 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2803 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2802 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2803 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2804      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2805      
2806 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2806 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2807      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2808      
2809      
2810      // Number of jets
2811      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2812      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2813 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2813 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2814      
2815      // Others
2816      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 939 | Line 2842 | void do_kinematic_plots(string mcjzb, st
2842      
2843      //   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);
2844      //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);
2845 <    //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);
2845 >    //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);*/
2846    }
2847      
2848 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2849 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2850 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2851 <   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2852 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2853 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2854 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2855 <
2856 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2857 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2858 <
2848 >   int jzbcuts[7]={0,50,80,100,150,200,250};
2849 >   int MCorData[2]={data,mc};
2850 >  
2851 >   for(int d=0;d<2;d++) {
2852 >     for(int j=0;j<7;j++) {
2853 >       make_special_obs_pred_mll_plot(datajzb,mcjzb,jzbcuts[j],5.0,MCorData[d]); // 5.0 is the binwidth
2854 >     }
2855 >   }
2856 >  
2857 > /*
2858 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2859 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2860 > */
2861    switch_overunderflow(false);
2862   }
2863  
# Line 974 | Line 2879 | void make_comp_plot( string var, string
2879    }
2880    
2881    string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
2882 +  if(!RestrictToMassPeak) {
2883 +    sRegions[0]="SF";
2884 +    sRegions[1]="OF";
2885 +  }
2886    TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass,     cutOSOF&&cutnJets&&cutmass,
2887                        cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
2888    
# Line 993 | Line 2902 | void make_comp_plot( string var, string
2902        if (ymax>ymin) datahisto->SetMaximum(ymax);
2903        lm3histo->SetLineStyle(2);
2904        datahisto->Draw("e1");
2905 <      mcstack.Draw("same");
2905 >      mcstack.Draw("histo,same");
2906        datahisto->Draw("same,e1");
2907        lm3histo->Draw("hist,same");
2908        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
# Line 1036 | Line 2945 | void region_comparison_plots(string mcjz
2945      make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2946  
2947      make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2948 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2948 >    make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2949      make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2950      make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2951      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
# Line 1068 | Line 2977 | void signal_bg_comparison()
2977    
2978    float simulatedlumi=luminosity;//in pb please - adjust to your likings
2979    
2980 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
2980 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2981    TH1F *JZBplotLM4;
2982    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"));
2983    else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2984 <  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
2984 >  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TT_"));
2985    
2986    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
2987    JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
# Line 1083 | Line 2992 | void signal_bg_comparison()
2992  
2993    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2994    JZBplotTtbar->SetMinimum(0.01);
2995 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2995 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2996    JZBplotTtbar->DrawClone("histo");
2997    JZBplotZJETs->Draw("histo,same");
2998    JZBplotTtbar->SetFillColor(0);
2999    JZBplotTtbar->DrawClone("histo,same");
3000 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
3000 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
3001    JZBplotLM4->Draw("histo,same");
3002  
3003  
# Line 1126 | Line 3035 | void signal_bg_comparison()
3035    // Draw all plots overlaid
3036    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
3037    JZBplotTtbar->SetMinimum(0.01);
3038 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
3038 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
3039    JZBplotTtbar->DrawClone("histo");
3040    JZBplotZJETs->Draw("histo,same");
3041    JZBplotTtbar->SetFillColor(0);
3042    JZBplotTtbar->DrawClone("histo,same");
3043 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
3043 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
3044  
3045    JZBplotSMS1->SetLineColor(kRed+1);
3046    JZBplotSMS2->SetLineColor(kBlue+1);
# Line 1338 | Line 3247 | if you want to start from scratch (witho
3247    return return_functions;
3248   }
3249  
3250 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3250 > void do_prediction_plot(TCut addcut, string Cname, string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3251   {
3252    
3253    bool is_data=false;
# Line 1359 | Line 3268 | void do_prediction_plot(string jzb, TCan
3268    
3269    
3270    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3271 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3272 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3273 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3274 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3271 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3272 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3273 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3274 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3275  
3276    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3277    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1378 | Line 3287 | void do_prediction_plot(string jzb, TCan
3287    TH1F *RcorrJZBeemmNoS;
3288  
3289    //these are for the ratio
3290 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3291 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3292 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3293 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3290 >  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);
3291 >  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);
3292 >  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);
3293 >  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);
3294    
3295    TH1F *JRcorrJZBSBem;
3296    TH1F *JLcorrJZBSBem;
3297    TH1F *JRcorrJZBSBeemm;
3298    TH1F *JLcorrJZBSBeemm;
3299    
3300 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
3300 >  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);
3301  
3302    
3303    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3304 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3305 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3306 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3307 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3304 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3305 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3306 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3307 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3308      
3309      //these are for the ratio
3310 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3311 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3312 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3313 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3310 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3311 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3312 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3313 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3314    }
3315    
3316    TH1F *lm4RcorrJZBeemm;
3317 <  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
3317 >  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"));
3318    
3319    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3320    
# Line 1542 | Line 3451 | void do_prediction_plot(string jzb, TCan
3451      
3452      jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3453      jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3454 <    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3455 <    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3454 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3455 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3456      
3457      THStack predcomposition("predcomposition","prediction composition");
3458      predcomposition.Add(sidebandsemu);
# Line 1569 | Line 3478 | void do_prediction_plot(string jzb, TCan
3478   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3479   //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3480      speciallegBpred->Draw();
3481 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3481 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition"+Cname,true,true,"data/pred",BpredSys);
3482 >    delete predcomppad;
3483      
3484      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3485      specialcanv->SetLogy(1);
3486   //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
3487      blankback->Draw();
3488   //    kostack.Draw("same");
3489 <    predcomposition.Draw();
3489 >    predcomposition.Draw("hist");
3490      Bpred->Draw("hist,same");
3491      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3492      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
# Line 1635 | Line 3545 | void do_prediction_plot(string jzb, TCan
3545        
3546        RcorrJZBeemmNoS->SetLineStyle(2);
3547        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3548 < //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3548 >      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3549        legBpred2->Draw();
3550        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3551        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1648 | Line 3558 | void do_prediction_plot(string jzb, TCan
3558    }
3559  
3560  
3561 +  Bpredsaveas+="_"+Cname+"_";
3562    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3563    string ytitle("ratio");
3564    if ( use_data==1 ) ytitle = "data/pred";
3565    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3566 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3566 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3567 >  
3568 >  delete kinpad;
3569  
3570  
3571    
# Line 1694 | Line 3607 | void do_prediction_plot(string jzb, TCan
3607      if(use_data==1)
3608      {
3609        legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3610 <      legBpredc->AddEntry(Bpredem,"OFZP","l");
3611 <      legBpredc->AddEntry(BpredSBem,"OFSB","l");
3612 <      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3610 >      if(RestrictToMassPeak) {
3611 >        legBpredc->AddEntry(Bpredem,"OFZP","l");
3612 >        legBpredc->AddEntry(BpredSBem,"OFSB","l");
3613 >        legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3614 >      } else legBpredc->AddEntry(Bpredem,"OF","l");
3615 >        
3616 >        
3617        legBpredc->Draw();
3618        CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3619      }
3620      if(use_data==0) {
3621        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3622 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3623 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3624 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3622 >      if(RestrictToMassPeak) {
3623 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3624 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3625 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3626 >      } else legBpredc->AddEntry(Bpredem,"MC OF","l");
3627 >        
3628        legBpredc->Draw();
3629        CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3630      }
3631      if(use_data==2) {
3632        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3633 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3634 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3635 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3633 >      if(RestrictToMassPeak) {
3634 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3635 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3636 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3637 >      } else {
3638 >        legBpredc->AddEntry(Bpredem,"MC OF","l");
3639 >      }
3640   //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3641        legBpredc->Draw();
3642        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3643      }
3644    }
3645    
1722  TFile *f = new TFile("tester.root","RECREATE");
1723  RcorrJZBeemm->Write();
1724  Bpred->Write();
1725  f->Close();
1726  
3646    delete RcorrJZBeemm;
3647    delete LcorrJZBeemm;
3648    delete RcorrJZBem;
# Line 1753 | Line 3672 | void do_prediction_plot(string jzb, TCan
3672  
3673   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3674    switch_overunderflow(true);
3675 +  
3676 +  TCut cuts[3] = {TCut("mll>0"),Restrmasscut,TCut("mll>20&&mll<70")};
3677 +  string cutnames[3] = {"NoMassCut","ZWindow","LowMassRegion2070"};
3678 +  
3679    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3680 <  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3681 <  if ( !PlottingSetup::Approved ) {
3682 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3683 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3684 <  } else {
3685 <    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3680 >  for(int i=0;i<3;i++) {
3681 >    do_prediction_plot(cuts[i],cutnames[i],datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3682 >    if ( !PlottingSetup::Approved ) {
3683 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3684 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3685 >    } else {
3686 >      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3687 >    }
3688    }
3689 +  
3690    delete globalcanvas;
3691    switch_overunderflow(false);
3692   }
# Line 1785 | Line 3711 | void lepton_comparison_plots() {
3711    Float_t ymin = 1.e-5, ymax = 0.25;
3712    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3713    can->SetLogy(1);
3714 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
3715 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
3714 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3715 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3716    eemc->SetLineColor(kBlue);
3717    mmmc->SetLineColor(kRed);
3718    eemc->SetMinimum(0.1);
# Line 1849 | Line 3775 | void lepton_comparison_plots() {
3775    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3776    eemmlegend->Draw();
3777    DrawPrelim();
3778 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3778 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3779    
3780 <  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"));
3781 <  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"));
3782 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
3780 >  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"));
3781 >  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"));
3782 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3783    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3784    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3785    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 1950 | Line 3876 | void draw_pure_jzb_histo(TCut cut,string
3876    datahisto->SetMinimum(0.1);
3877    datahisto->SetMarkerSize(DataMarkerSize);
3878    datahisto->Draw("e1");
3879 <  mcstack.Draw("same");
3879 >  mcstack.Draw("histo,same");
3880    datahisto->Draw("same,e1");
3881    
3882    TLegend *leg;
# Line 1972 | Line 3898 | void draw_pure_jzb_histo(TCut cut,string
3898    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3899    writeline1->SetTextSize(0.035);
3900    writeline1->Draw();
3901 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3902 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3901 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3902 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3903    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3904    jzbpad2->cd();
3905    jzbpad2->SetLogy(1);
# Line 1981 | Line 3907 | void draw_pure_jzb_histo(TCut cut,string
3907    datahisto->SetMinimum(0.1);
3908    datahisto->SetMarkerSize(DataMarkerSize);
3909    datahisto->Draw("e1");
3910 <  mcstack.Draw("same");
3910 >  mcstack.Draw("histo,same");
3911    datahisto->Draw("same,e1");
3912    leg->SetHeader("");
3913    leg->Draw();
3914    writeline1->SetTextSize(0.035);
3915    writeline1->Draw();
3916    DrawPrelim();
3917 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3918 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3917 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3918 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3919    datahisto->Delete();
3920    mcstack.Delete();
3921   }
# Line 2057 | Line 3983 | void diboson_plots(string mcjzb, string
3983    TCanvas *gloca = new TCanvas("gloca","gloca");
3984    
3985    dout << "Going to produce prediction plots" << endl;
3986 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3987 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3986 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3987 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3988    delete gloca;
3989  
3990    dout << "Going to reset the cross section for diboson samples ... " << endl;
# Line 2097 | Line 4023 | void draw_normalized_data_vs_data_histo(
4023    leg->AddEntry(datahisto2,legentry2.c_str());
4024    leg->Draw();
4025    
4026 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
4026 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
4027    
4028    datahisto1->Delete();
4029    datahisto2->Delete();
# Line 2186 | Line 4112 | string jzb_tex_command(string region, st
4112   //  \SFZPJZBPOS
4113   //  Sample &  \OFZPJZBPOS  & \OFZPJZBNEG &  \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS  & \OFSBJZBNEG  & \SFSBJZBPOS  & \SFSBJZBNEG  \\\hline
4114    
4115 +  
4116 + void compute_Improved_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4117 +  dout << "Calculating background yields in MC:" << endl;
4118 +  
4119 +  TCanvas *yica = new TCanvas("yica","yield canvas");
4120 +  
4121 +  int nRegions=2;
4122 +  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
4123 +  string tsRegions[] = {"SFZP","OFZP"};
4124 +  string posneg[] = {"pos","neg"};
4125 +  TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass};
4126 +
4127 +  
4128 +  
4129 +  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
4130 +    TCut posJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos");
4131 +    TCut negJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg");
4132 +    
4133 +    dout << "_________________________________________________________" << endl;
4134 +    dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
4135 +    
4136 +    
4137 +    THStack *spstack = new THStack(allsamples.DrawStack("spstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4138 +    THStack *snstack = new THStack(allsamples.DrawStack("snstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4139 +    THStack *opstack = new THStack(allsamples.DrawStack("opstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4140 +    THStack *onstack = new THStack(allsamples.DrawStack("onstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4141 +    
4142 +    
4143 +    vector<pair<string,Value> > obs_yields     = WriteYield(spstack, -10, 10, true);
4144 +    vector<pair<string,Value> > neg_sf_yields  = WriteYield(snstack, -10, 10, true);
4145 +    vector<pair<string,Value> > pos_of_yields  = WriteYield(opstack, -10, 10, true);
4146 +    vector<pair<string,Value> > neg_of_yields  = WriteYield(onstack, -10, 10, true);
4147 +    
4148 +    Value TotObs=Value(0,0);
4149 +    Value TotPred=Value(0,0);
4150 +    
4151 +    for(int ientry=0;ientry<obs_yields.size();ientry++) {
4152 +      if(Contains(obs_yields[ientry].first,"t_bar_t")) continue; // ttbar
4153 +      if(Contains(obs_yields[ientry].first,"W_Jets")) continue; // W+Jets
4154 +      if(Contains(obs_yields[ientry].first,"WW_")) continue; // WW (fully flavor symmetric)
4155 +      if(Contains(obs_yields[ientry].first,"Single_top")) continue; // Single Top
4156 +      if(Contains(obs_yields[ientry].first,"ee_mumu")) continue; // DY
4157 +      if(Contains(obs_yields[ientry].first,"tau_tau")) continue; // DY
4158 +      Value pred = neg_sf_yields[ientry].second + pos_of_yields[ientry].second - neg_of_yields[ientry].second;
4159 +      Value obs=obs_yields[ientry].second;
4160 +      Value diff=obs-pred;
4161 +      dout << obs_yields[ientry].first << "\t & \t " << obs << " \t & \t " << pred << "\t & \t " << diff << endl;
4162 +      TotObs=TotObs+obs_yields[ientry].second;
4163 +      TotPred=TotPred+pred;
4164 +    }
4165 +    
4166 +    float Systematic=sqrt(pow(TotPred.getValue(),2)*0.5*0.5 + pow(TotObs.getValue(),2)*0.5*0.5);
4167 +
4168 +        
4169 +  }
4170 +  
4171 +  delete yica;
4172 + }
4173 +      
4174   void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4175    dout << "Calculating background yields in MC:" << endl;
4176    
# Line 2281 | Line 4266 | void draw_ttbar_and_zjets_shape_for_one_
4266    TText *titlecenter;
4267    bool frommc=false;
4268    if(frommc) {
4269 <    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
4269 >    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TT_"));
4270      titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
4271    }
4272    else {
# Line 2498 | Line 4483 | float find_one_correction_factor(string
4483      (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
4484      (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
4485    }
4486 +  
4487    niceresponseplotd->Add(emuResponse,-1);
4488    
4489 +  //TF1 *resp_func = new TF1("resp_func","[0]+[1]/x + [2]/pow(x,2)",10,600);
4490 +  
4491    niceresponseplotd->SetStats(0);
4492    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
4493    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 2509 | Line 4497 | float find_one_correction_factor(string
4497    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
4498    profd->Rebin(2);
4499    profd->SetMarkerSize(DataMarkerSize);
4500 +  //profd->Fit(resp_func,"","same,e1",10,400);
4501    profd->Fit("pol0","","same,e1",100,400);
4502 +  //resp_func->SetLineColor(kBlue);
4503    DrawPrelim();
4504    string stitle="Data";
4505    if(!Contains(FindKeyword,"Data")) stitle="MC";
4506    TText* title = write_text(0.5,0.7,stitle.c_str());
4507    title->SetTextAlign(12);
4508    title->Draw();
4509 + //  TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4510    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4511    float correction=datapol->GetParameter(0);
4512 +  
4513 + //  float correction=resp_func->GetParameter(0);
4514    stringstream resstring;
4515    resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
4516    TText* restitle = write_text(0.5,0.65,resstring.str());
# Line 2538 | Line 4531 | void find_correction_factors(string &jzb
4531    float datacorrection=find_one_correction_factor("Data",true,"","Data");
4532    float mccorrection=find_one_correction_factor("DY",false,"","MC");
4533    
4534 <  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4534 > /*  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4535    float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
4536    
4537    float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
4538    float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
4539 <  
4539 >  */
4540    cout << "Corrections : " << endl;
4541    cout << "   Data : " << datacorrection << endl;
4542 <  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4542 > //   cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4543    cout << "   MC : " << mccorrection << endl;
4544 <  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4544 > //   cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4545    
4546    //Step 2: Processing the result and making it into something useful :-)
4547    stringstream jzbvardatas;
4548 +  /*
4549    jzbvardatas << "(";
4550    
4551    if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
# Line 2567 | Line 4561 | void find_correction_factors(string &jzb
4561    
4562    jzbvardatas << ")";
4563    jzbvardata=jzbvardatas.str();
4564 <  
4564 >  */
4565    stringstream jzbvarmcs;
4566 +  /*
4567    jzbvarmcs << "(";
4568 <  
4568 >
4569    if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4570    if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4571    
# Line 2584 | Line 4579 | void find_correction_factors(string &jzb
4579    
4580    jzbvarmcs << ")";
4581    jzbvarmc=jzbvarmcs.str();
4582 <
4582 >  */
4583 >  
4584 >  if(datacorrection>=1) jzbvardatas<<"(jzb[1]-" << datacorrection-1 << "*pt)";
4585 >  if(datacorrection<1)  jzbvardatas<<"(jzb[1]+" << 1-datacorrection << "*pt)";
4586 >  
4587 >  if(mccorrection>=1) jzbvarmcs<<"(jzb[1]-" << mccorrection-1 << "*pt)";
4588 >  if(mccorrection<1)  jzbvarmcs<<"(jzb[1]+" << 1-mccorrection << "*pt)";
4589 >  
4590 >  jzbvardata = jzbvardatas.str();
4591 >  jzbvarmc = jzbvarmcs.str();
4592 >  
4593    dout << "JZB Z pt correction summary : " << endl;
4594    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
4595    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
4596    
4597   }
4598  
4599 < void pick_up_events(string cut) {
4600 <  dout << "Picking up events with cut " << cut << endl;
2596 <  allsamples.PickUpEvents(cut);
4599 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
4600 >  allsamples.PickUpEvents(cut,filename,QuietMode);
4601   }
4602  
4603   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2679 | Line 4683 | void draw_all_ttbar_histos(TCanvas *can,
4683    }
4684   }
4685  
4686 < void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
4686 > void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring, TCut cut) {
4687    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4688    //in the case of the OFF peak analysis, we compare our control region to the real value
4689    TCut weightbackup=cutWeight;
4690    switch_overunderflow(true);
4691    
4692 <  bool doPURW=false;
4692 >  bool doPURW=true;
4693    
4694    
4695    if(!doPURW) {
# Line 2705 | Line 4709 | void ttbar_sidebands_comparison(string m
4709        
4710    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4711  
4712 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4713 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4712 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4713 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4714    TH1F *TSem;
4715    TH1F *nTSem;
4716 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4717 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4716 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4717 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4718    TH1F *TSeemm;
4719    TH1F *nTSeemm;
4720    
4721    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4722 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4723 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4724 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4725 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4722 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4723 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4724 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4725 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4726    }
4727  
4728    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 2973 | Line 4977 | void ttbar_sidebands_comparison(string m
4977   //  nicer_binning.push_back(300);
4978   //  nicer_binning.push_back(400);
4979    
4980 <  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4980 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/",TCut("mll>0"));
4981 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/CutAt20",TCut("mll>20"));
4982 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/LowMassRegion2070",TCut("mll>20&&mll<70"));
4983 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/ZWindow",Restrmasscut);
4984 >  
4985   }
4986  
4987  
4988   void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4989    cout << "****************************************************************************************************************************************************************" << endl;
4990    TCanvas *zcan = new TCanvas("zcan","zcan");  
2983 //  zcan->SetLogy(1);
4991    TCut weightbackup=cutWeight;
4992    
4993    bool UsePURW=true;
# Line 3006 | Line 5013 | void zjets_prediction_comparison(string
5013    }
5014  
5015    
5016 +  
5017    vector<float> binning;
5018    binning.push_back(0);
5019    binning.push_back(10);
5020 <  binning.push_back(20);
5021 <  binning.push_back(40);
5022 <  binning.push_back(60);
5023 < //   binning.push_back(50);
5020 >  binning.push_back(30);
5021 > //  binning.push_back(40);
5022 > //  binning.push_back(60);
5023 >   binning.push_back(50);
5024   //   binning.push_back(60);
5025   //   binning.push_back(70);
5026   //   binning.push_back(80);
# Line 3023 | Line 5031 | void zjets_prediction_comparison(string
5031    
5032    TCut kPos((mcjzb+">0").c_str());
5033    TCut kNeg((mcjzb+"<0").c_str());
5034 +  TCut reducedNJets(cutnJets);
5035    string var( "abs("+mcjzb+")" );
5036    
5037 <  TCut notTau("abs(genMID1)!=15");
5037 >  
5038 >  TCut notTau("!EventZToTaus");
5039    TCut ee_mm_tautau("mll>0");
5040    
5041 <
5042 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3033 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5041 >  TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5042 >  TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5043    
5044    hJZBpos->SetLineColor(kBlack);
5045    hJZBneg->SetLineColor(kRed);
# Line 3051 | Line 5060 | void zjets_prediction_comparison(string
5060    hratio->Divide(hJZBneg);
5061    
5062    for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
5063 <    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
5063 >    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;
5064    }
5065    
5066   //  zcan->SetLogy(0);
# Line 3059 | Line 5068 | void zjets_prediction_comparison(string
5068    hratio->GetYaxis()->SetTitle("Observed/Predicted");
5069    hratio->Draw("e1");
5070    
5071 <  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
5071 >  TLine *top = new TLine(binning[0],1.2,binning[binning.size()-1],1.2);
5072    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5073 <  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
5073 >  TLine *bottom = new TLine(binning[0],0.8,binning[binning.size()-1],0.8);
5074    
5075  
3067  cout << __LINE__ << endl;
5076    top->SetLineColor(kBlue);top->SetLineStyle(2);
5077    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5078    center->SetLineColor(kBlue);
# Line 3080 | Line 5088 | void zjets_prediction_comparison(string
5088    DrawMCPrelim(simulatedlumi);
5089    CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
5090    
5091 <  TCut reducedNJets(cutnJets);
5092 <  
5093 <  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5094 <  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3087 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3088 <  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5091 >  TH1F *TAUhJZBpos       = allsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5092 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5093 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5094 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5095  
3090  cout << __LINE__ << endl;
5096    TH1F *RcorrJZBSBem;
5097    TH1F *LcorrJZBSBem;
5098    TH1F *RcorrJZBSBeemm;
5099    TH1F *LcorrJZBSBeemm;
5100  
3096  cout << __LINE__ << endl;
5101    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5102 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5103 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5104 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5105 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5102 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5103 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5104 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5105 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5106    }
5107    
5108    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3116 | Line 5120 | void zjets_prediction_comparison(string
5120    
5121    Bpred->SetLineColor(kRed);
5122  
3119  cout << __LINE__ << endl;
5123    TAUhJZBpos->SetLineColor(kBlack);
5124    Bpred->SetLineColor(kRed);
5125    
# Line 3136 | Line 5139 | void zjets_prediction_comparison(string
5139    TAUhratio->Divide(Bpred);
5140    
5141    for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
5142 <    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
5142 >    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;
5143 >    
5144 >    
5145    }
5146    
5147    zcan->SetLogy(0);
# Line 3170 | Line 5175 | void zjets_prediction_comparison(string
5175      delete LcorrJZBSBeemm;
5176    }
5177    
5178 +  //***************************************************************************************************
5179 +  
5180 +  string jzbvar=var;
5181 +  /*
5182 +  for(int i=0;i<60;i+=10) {
5183 +    stringstream sSpecialJZBCut;
5184 +    sSpecialJZBCut << jzbvar << ">" << i;
5185 +  TCut SpecialJZBCut(sSpecialJZBCut.str().c_str());
5186 +  
5187 +  var="mll";
5188 +  
5189 +  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"));
5190 +  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"));
5191 +  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"));
5192 +  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"));
5193 +
5194 +  TH1F *RcorrJZBPlusSBem;
5195 +  TH1F *LcorrJZBPlusSBem;
5196 +  TH1F *RcorrJZBPlusSBeemm;
5197 +  TH1F *LcorrJZBPlusSBeemm;
5198 +
5199 +  
5200 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5201 +    RcorrJZBPlusSBem   = allsamples.Draw("RcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5202 +    LcorrJZBPlusSBem   = allsamples.Draw("LcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5203 +    RcorrJZBPlusSBeemm = allsamples.Draw("RcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5204 +    LcorrJZBPlusSBeemm = allsamples.Draw("LcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5205 +  }
5206 +  
5207 +  TH1F *BpredPrime = (TH1F*)LcorrJZBPluseemm->Clone("BpredPrime");
5208 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5209 +    BpredPrime->Add(RcorrJZBPlusem,1.0/3.);
5210 +    BpredPrime->Add(LcorrJZBPlusem,-1.0/3.);
5211 +    BpredPrime->Add(RcorrJZBPlusSBem,1.0/3.);
5212 +    BpredPrime->Add(LcorrJZBPlusSBem,-1.0/3.);
5213 +    BpredPrime->Add(RcorrJZBPlusSBeemm,1.0/3.);
5214 +    BpredPrime->Add(LcorrJZBPlusSBeemm,-1.0/3.);
5215 +  } else {
5216 +    BpredPrime->Add(RcorrJZBPlusem,1.0);
5217 +    BpredPrime->Add(LcorrJZBPlusem,-1.0);
5218 +  }
5219 +  
5220 +  BpredPrime->SetLineColor(kRed);
5221 +
5222 +  FullJZBhJZBpos->SetLineColor(kBlack);
5223 +  BpredPrime->SetLineColor(kRed);
5224 +  
5225 +  FullJZBhJZBpos->SetMinimum(1.0);
5226 +  FullJZBhJZBpos->Draw("e1");
5227 +  BpredPrime->Draw("same,hist");
5228 +  FullJZBhJZBpos->Draw("same,e1");
5229 +  
5230 +  TLegend *FullJZBleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
5231 +  FullJZBleg->AddEntry(FullJZBhJZBpos,"Observed","pe");
5232 +  FullJZBleg->AddEntry(BpredPrime,"Predicted","l");
5233 +  FullJZBleg->Draw("same");
5234 +  DrawMCPrelim(simulatedlumi);
5235 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"_zjets_eemumu_prediction__"+any2string(massregionname));
5236    
5237 +  TH1F* FullJZBhratio = (TH1F*)FullJZBhJZBpos->Clone("FullJZBhratio");
5238 +  FullJZBhratio->Divide(BpredPrime);
5239 +  
5240 +  zcan->SetLogy(0);
5241 +  FullJZBhratio->GetYaxis()->SetRangeUser(0,2.5);
5242 +  FullJZBhratio->GetYaxis()->SetTitle("Observed/Predicted");
5243 +  FullJZBhratio->Draw("e1");
5244 +  
5245 +  TLine *atop = new TLine(0,1.2,200,1.2);
5246 +  TLine *acenter = new TLine(0,1.0,200,1.0);
5247 +  TLine *abottom = new TLine(0,0.8,200,0.8);
5248 +  
5249 +  atop->SetLineColor(kBlue);
5250 +  atop->SetLineStyle(2);
5251 +  acenter->SetLineColor(kBlue);
5252 +  abottom->SetLineColor(kBlue);
5253 +  abottom->SetLineStyle(2);
5254 +  
5255 +  atop->Draw("same");
5256 +  acenter->Draw("same");
5257 +  abottom->Draw("same");
5258 +  
5259 +  TLegend *FullJZBleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
5260 +  FullJZBleg2->AddEntry(FullJZBhratio,"obs / pred","pe");
5261 +  FullJZBleg2->AddEntry(abottom,"syst. envelope","l");
5262 +  FullJZBleg2->Draw("same");
5263 +  DrawMCPrelim(simulatedlumi);
5264 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"zjets_eemumu_prediction_ratio"+any2string(massregionname));
5265 +  
5266 +  
5267 +  delete BpredPrime;
5268 +  delete FullJZBhJZBpos;
5269 +  delete LcorrJZBPluseemm;
5270 +  delete RcorrJZBPlusem;
5271 +  delete LcorrJZBPlusem;
5272 + //  delete FullJZBhJZBpos;
5273 +  
5274 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5275 +    delete RcorrJZBPlusSBem;
5276 +    delete LcorrJZBPlusSBem;
5277 +    delete RcorrJZBPlusSBeemm;
5278 +    delete LcorrJZBPlusSBeemm;
5279 +  }
5280 +  
5281 +  }
5282 +  //***************************************************************************************************
5283 +  */
5284    delete zcan;
5285    cutWeight=weightbackup;
3176
3177  cout << __LINE__ << endl;
5286   }
5287  
5288  
5289   void zjets_prediction_comparison(string mcjzbWithPUa) {
5290 <  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
5291 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
5290 >   zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20"), "nomasscut");
5291 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<10"), "Zwindow_10");
5292    zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
5293 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5293 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)>10&&mll>20"), "Outside_Zwindow_10");
5294 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5295   }
5296    
5297   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
# Line 3292 | Line 5401 | void make_table(samplecollection &coll,
5401   }
5402  
5403   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
5404 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
5405 +  assert(0);
5406    /*we want a table like this:
5407      __________________     50   |   100  | ...
5408      | Data prediction |  a vs b | a vs b | ...
# Line 3525 | Line 5636 | void qcd_plots(string datajzb, string mc
5636    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
5637    string ytitle("ratio");
5638    if ( use_data==1 ) ytitle = "data/pred";
5639 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5639 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5640 >  delete kinpad;
5641    
5642    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
5643    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3696 | Line 5808 | void met_vs_jzb_plots(string datajzb, st
5808    
5809    vector<string> findme;
5810    findme.push_back("DY");
5811 <  findme.push_back("TTJets");
5811 >  findme.push_back("TT_");
5812    findme.push_back("LM");
5813    /*
5814    for(int ifind=0;ifind<(int)findme.size();ifind++) {
# Line 3733 | Line 5845 | void met_vs_jzb_plots(string datajzb, st
5845    sRIGHT << "((" << mcjzb << ")>0)";
5846    TCut RIGHT(sRIGHT.str().c_str());
5847    
5848 <  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5849 <  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5850 <  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5851 <  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5848 >  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5849 >  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5850 >  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5851 >  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5852    
5853    
5854    TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
# Line 3762 | Line 5874 | void met_vs_jzb_plots(string datajzb, st
5874    lg->SetHeader("DY");
5875    
5876    lg->Draw();
5877 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5877 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5878    
5879    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5880    metpad3->cd();
# Line 3780 | Line 5892 | void met_vs_jzb_plots(string datajzb, st
5892  
5893    lg2->Draw();
5894    
5895 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5895 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5896    
5897    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5898    metpad2->cd();
5899    metpad2->SetLogy(1);
5900    
5901 <  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5902 <  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5903 <  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5904 <  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5901 >  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5902 >  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5903 >  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5904 >  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5905    
5906    metlefta->Add(metleftOa,-1);
5907    metrighta->Add(metrightOa,-1);
# Line 3799 | Line 5911 | void met_vs_jzb_plots(string datajzb, st
5911    metlefta->Draw("histo");
5912    metrighta->Draw("same");
5913    lg->Draw();
5914 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5914 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5915    
5916    delete Bpred;
5917    delete obs;
# Line 3808 | Line 5920 | void met_vs_jzb_plots(string datajzb, st
5920    int newNBins=30;
5921    
5922    TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5923 <  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5924 <  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5925 <  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5926 <  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5923 >  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5924 >  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5925 >  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5926 >  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5927    
5928    TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5929    aBpred->Add(AmetleftO,-1);
# Line 3826 | Line 5938 | void met_vs_jzb_plots(string datajzb, st
5938    aobs->Draw("same");
5939    lg->SetHeader("All MC");
5940    lg->Draw();
5941 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5941 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5942    
5943    
5944    delete lg;
# Line 3836 | Line 5948 | void met_vs_jzb_plots(string datajzb, st
5948    delete metright;
5949    delete metrightO;
5950   }
5951 +
5952 +
5953 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5954 +  
5955 +  if(PlottingSetup::RestrictToMassPeak) {
5956 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5957 +    assert(!PlottingSetup::RestrictToMassPeak);
5958 +  }
5959 +  
5960 +  vector<float> binning;
5961 +  
5962 +  binning.push_back(-200);
5963 +  binning.push_back(-150);
5964 +  binning.push_back(-125);
5965 +  binning.push_back(-100);
5966 +  binning.push_back(-75);
5967 +  binning.push_back(-50);
5968 +  binning.push_back(-25);
5969 +  binning.push_back(0);
5970 +  binning.push_back(25);
5971 +  binning.push_back(50);
5972 +  binning.push_back(75);
5973 +  binning.push_back(100);
5974 +  binning.push_back(125);
5975 +  binning.push_back(150);
5976 +  binning.push_back(200);
5977 +  
5978 +  switch_overunderflow(true);
5979 +  
5980 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5981 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5982 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5983 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5984 +  
5985 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5986 +  tcan->SetLogy(1);
5987 +  
5988 +  TZeemm->SetLineColor(kBlack);
5989 +  TZem->SetLineColor(kRed);
5990 +  TZeemm->SetMarkerColor(kBlack);
5991 +  TZem->SetMarkerColor(kRed);
5992 +  
5993 +  vector<TH1F*> histos;
5994 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5995 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5996 +  histos.push_back(TZem);
5997 +  histos.push_back(TZeemm);
5998 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5999 +  
6000 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
6001 +  leg->AddEntry(TZeemm,"SFZP","l");
6002 +  leg->AddEntry(TZem,"OFZP","l");
6003 +  leg->Draw("same");
6004 +  DrawMCPrelim();
6005 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
6006 +  
6007 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
6008 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
6009 +  TH1F *TSeemmcopy;
6010 +  TH1F *TSemcopy;
6011 +  
6012 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
6013 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
6014 +  
6015 +  vector<float> posbinning;
6016 +  for(unsigned int i=0;i<binning.size();i++) {
6017 +    if(binning[i]<0) continue;
6018 +    posbinning.push_back(binning[i]);
6019 +  }
6020 +  
6021 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
6022 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
6023 +  
6024 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
6025 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
6026 +    if(TZem->GetBinCenter(i)<0) {
6027 +      //we're on the left: subtract em!
6028 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
6029 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
6030 +      //we're on the left: add eemm!
6031 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
6032 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
6033 +    } else {
6034 +      //we're on the right: add em!
6035 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
6036 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
6037 +      //we're on the left: add eemm!
6038 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
6039 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
6040 +    }
6041 +  }
6042 +  
6043 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
6044 +  ratio2->Divide(obs2);
6045 +
6046 +  TZem->Divide(TZeemm);
6047 +  TZem->SetMarkerStyle(21);
6048 +
6049 +  TZem->SetTitle("OF / SF");
6050 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
6051 +  
6052 +  tcan->SetLogy(0);
6053 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
6054 +  TZem->GetYaxis()->SetTitle("ratio");
6055 +  TZem->Draw();
6056 +  
6057 +  float linepos=emuncertOFFPEAK;
6058 +  
6059 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
6060 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
6061 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
6062 +  
6063 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
6064 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
6065 +  center->SetLineColor(kBlue);
6066 +  
6067 +  top->Draw("same");
6068 +  center->Draw("same");
6069 +  bottom->Draw("same");
6070 +  
6071 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
6072 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
6073 +  leg2->AddEntry(bottom,"syst. envelope","l");
6074 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
6075 +  leg2->SetY1(0.65);
6076 +  
6077 +  leg2->Draw("same");
6078 +  
6079 +  DrawMCPrelim();
6080 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
6081 +  
6082 +  ratio2->SetLineColor(TZem->GetLineColor());
6083 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
6084 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
6085 +  ratio2->GetYaxis()->SetTitle("ratio");
6086 +  ratio2->Draw();
6087 +  
6088 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
6089 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
6090 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
6091 +  
6092 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
6093 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
6094 +  center2->SetLineColor(kBlue);
6095 +  
6096 +  top2->Draw("same");
6097 +  center2->Draw("same");
6098 +  bottom2->Draw("same");
6099 +  
6100 +  leg2->Draw("same");
6101 +  
6102 +  DrawMCPrelim();
6103 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
6104 +  
6105 +  delete TZem;
6106 +  delete nTZem;
6107 +  delete TZeemm;
6108 +  delete nTZeemm;
6109 +  delete obs2;
6110 +  delete pred2;
6111 +  delete tcan;
6112 +  switch_overunderflow(false);
6113 + }
6114 +
6115 + 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) {
6116 +    
6117 +  
6118 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
6119 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6120 +  vanilla_ratio->SetFillColor(kGreen);
6121 +  vanilla_ratio->SetLineColor(kGreen);
6122 +  vanilla_ratio->SetMarkerColor(kGreen);
6123 +  vanilla_ratio->SetFillStyle(3001);
6124 +  vanilla_ratio->Draw("e3");
6125 +  
6126 +  response_only_up_ratio->SetFillColor(kRed);
6127 +  response_only_up_ratio->SetMarkerColor(kRed);
6128 +  response_only_up_ratio->SetLineColor(kRed);
6129 +  response_only_up_ratio->SetFillStyle(3003);
6130 +  response_only_up_ratio->Draw("e3,same");
6131 +  
6132 +  response_only_down_ratio->SetFillColor(kOrange);
6133 +  response_only_down_ratio->SetMarkerColor(kOrange);
6134 +  response_only_down_ratio->SetLineColor(kOrange);
6135 +  response_only_down_ratio->SetFillStyle(3004);
6136 +  response_only_down_ratio->Draw("e3,same");
6137 +  
6138 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
6139 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
6140 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
6141 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
6142 +  reponse_plus_peak_up_ratio->Draw("e3,same");
6143 +  
6144 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
6145 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
6146 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
6147 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
6148 +  reponse_plus_peak_down_ratio->Draw("e3,same");
6149 +  
6150 +  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);
6151 +  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);
6152 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
6153 +  
6154 +  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);
6155 +  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);
6156 +  
6157 +  lhiA->SetLineColor(kRed);
6158 +  lhiA->SetLineStyle(2);
6159 +  llowA->SetLineColor(kRed);
6160 +  llowA->SetLineStyle(2);
6161 +  
6162 +  llow->SetLineColor(kBlue);
6163 +  llow->SetLineStyle(2);
6164 +  lhi->SetLineColor(kBlue);
6165 +  lhi->SetLineStyle(2);
6166 +  lOne->SetLineColor(kBlue);
6167 +  
6168 +  llow->Draw();
6169 +  lhi->Draw();
6170 +  lOne->Draw();
6171 +  
6172 +  llowA->Draw();
6173 +  lhiA->Draw();
6174 +  
6175 +  TLegend *leg = make_legend();
6176 +  leg->SetX1(0.15);
6177 +  leg->SetY1(0.7);
6178 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
6179 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
6180 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6181 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6182 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6183 +  leg->AddEntry(lhi,"Systematic envelope","l");
6184 + //  leg->SetNColumns(2);
6185 +  leg->Draw();
6186 +  
6187 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
6188 +  
6189 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6190 +  vanilla_ratio->Draw("e3");
6191 +  response_only_up_ratio->Draw("e3 same");
6192 +  response_only_down_ratio->Draw("e3 same");
6193 +  TLegend *leg2 = make_legend();
6194 +  leg2->SetX1(0.15);
6195 +  leg2->SetY1(0.7);
6196 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
6197 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
6198 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6199 +  leg2->AddEntry(lhi,"Systematic envelope","l");
6200 +  leg2->Draw();
6201 +  llow->Draw();
6202 +  lOne->Draw();
6203 +  llowA->Draw();
6204 +  lhiA->Draw();
6205 +  
6206 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
6207 +  
6208 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6209 +  response_only_up_ratio->Draw("e3");
6210 +  reponse_plus_peak_up_ratio->Draw("e3 same");
6211 +  reponse_plus_peak_down_ratio->Draw("e3 same");
6212 +  TLegend *leg3 = make_legend();
6213 +  leg3->SetX1(0.15);
6214 +  leg3->SetY1(0.7);
6215 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
6216 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6217 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6218 +  leg3->AddEntry(lhi,"Systematic envelope","l");
6219 +  leg3->Draw();
6220 +  llow->Draw();
6221 +  lOne->Draw();
6222 +  llowA->Draw();
6223 +  lhiA->Draw();
6224 +  
6225 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
6226 +  
6227 +  delete ttcan2;
6228 + }
6229 +
6230 + void ttbar_correction_tests() {
6231 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
6232 +    
6233 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
6234 +  
6235 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
6236 +  
6237 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
6238 +  
6239 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
6240 +  
6241 +  string vanilla="jzb[1]";
6242 +  string response_only_up="((jzb[1]+0.034665*pt))";
6243 +  string response_only_down="((jzb[1]-0.034665*pt))";
6244 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
6245 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
6246 +
6247 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
6248 +  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");
6249 +  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");
6250 +  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");
6251 +  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");
6252 +  
6253 +  ttcan->cd();
6254 +  
6255 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
6256 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
6257 +  
6258 +  delete vanilla_observed;
6259 +  delete response_only_up_observed;
6260 +  delete response_only_down_observed;
6261 +  delete reponse_plus_peak_up_observed;
6262 +  delete reponse_plus_peak_down_observed;
6263 +  
6264 +  delete vanilla_predicted;
6265 +  delete response_only_up_predicted;
6266 +  delete response_only_down_predicted;
6267 +  delete reponse_plus_peak_up_predicted;
6268 +  delete reponse_plus_peak_down_predicted;
6269 +  
6270 +  delete vanilla_ratio;
6271 +  delete response_only_up_ratio;
6272 +  delete response_only_down_ratio;
6273 +  delete reponse_plus_peak_up_ratio;
6274 +  delete reponse_plus_peak_down_ratio;
6275 +  
6276 +  delete ttcan;
6277 + }
6278 +
6279 + void ttbar_region_search(string mcjzb) {
6280 +  cout << "Looking for a nice control region" << endl;
6281 +  TCanvas *can = new TCanvas("can","can",1200,1200);
6282 +  can->Divide(2,2);
6283 +  can->cd(1);
6284 +  can->cd(1)->SetLogy(1);
6285 +  
6286 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6287 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6288 +  
6289 +  JZBdistSF.Draw("histo");
6290 +  JZBdistSF.SetMaximum(1000);
6291 +  JZBdistSF.SetMinimum(0.1);
6292 +  JZBdistSF.Draw("histo");
6293 +  DrawMCPrelim();
6294 +  
6295 +  can->cd(2);
6296 +  can->cd(2)->SetLogy(1);
6297 +  JZBdistOF.Draw("histo");
6298 +  JZBdistOF.SetMaximum(1000);
6299 +  JZBdistOF.SetMinimum(0.1);
6300 +  JZBdistOF.Draw("histo");
6301 +  DrawMCPrelim();
6302 +  
6303 +  can->cd(3);
6304 +  
6305 +  
6306 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
6307 +  
6308 +  DrawMCPrelim();
6309 +  
6310 +  /*
6311 +  THStack *Subtracted = new THStack();
6312 +  
6313 +  TIter nextSF(JZBdistSF.GetHists());
6314 +  TIter nextOF(JZBdistOF.GetHists());
6315 +  TObject* SFobj;
6316 +  TObject* OFobj;
6317 +  
6318 +  TH1* sfh = NULL;
6319 +  TH1* ofh = NULL;
6320 +  
6321 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
6322 +    TH1F *sfstart = (TH1*)SFobj->Clone();
6323 +    TH1F *ofstart = (TH1*)OFobj->Clone();
6324 +    TH1F *obs, *pred;
6325 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
6326 +    
6327 +    if ( !hratio ) {
6328 +      hratio = (TH1*)obj->Clone();
6329 +      hratio->SetName("hratio");
6330 +    } else hratio->Add( (TH1*)obj );
6331      
6332 +  }
6333 +  hratio->Divide(hdata);
6334 +  */
6335 +  
6336 +  
6337 +  can->cd(4);
6338 +  JZBdistOF.Draw("histo");
6339 +  DrawMCPrelim();
6340 +  
6341 +  
6342 +  
6343 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
6344 +  
6345 +  CleanLegends();
6346 +  delete can;
6347 + }
6348 +
6349 + void ttbar_tests(string mcjzb) {
6350 +  //ttbar_correction_tests();
6351 +  ttbar_region_search(mcjzb);
6352 + }
6353 +
6354 + Value GetYieldBetween(TH1F *h, float low, float high) {
6355 +  float Yield=0;
6356 +  float YieldErr=0;
6357 +  for(int i=1;i<=h->GetNbinsX()+1;i++) {
6358 +    if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
6359 +    if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
6360 +    Yield+=h->GetBinContent(i);
6361 +    YieldErr=sqrt(YieldErr*YieldErr+h->GetBinError(i)*h->GetBinError(i));
6362 +  }
6363 +  
6364 +  Value a(Yield,YieldErr);
6365 +  return a;
6366 + }
6367 +
6368 +
6369 + void make_SF_over_OF_plot(string datajzb, string mcjzb, TCut cut, string variable, int nbins, float xmin, float ymin, string varname, string filename) {
6370 +  TCanvas *SFoOF_can = new TCanvas("SFoOF_can","SFoOF_can");
6371 +  TH1F *data_sf = allsamples.Draw("data_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,data,luminosity);
6372 +  TH1F *data_of = allsamples.Draw("data_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,data,luminosity);
6373 +  
6374 +  TH1F *mc_sf = allsamples.Draw("mc_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6375 +  TH1F *mc_of = allsamples.Draw("mc_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6376 +  
6377 +  TH1F *mc_ratio = (TH1F*)mc_sf->Clone("mc_ratio");
6378 +  mc_ratio->Divide(mc_of);
6379 +  
6380 +  TH1F *data_ratio = (TH1F*)data_sf->Clone("data_ratio");
6381 +  data_ratio->Divide(data_of);
6382 +  
6383 +  mc_ratio->SetFillColor(TColor::GetColor("#00ADE1"));
6384 +  mc_ratio->SetMarkerColor(TColor::GetColor("#00ADE1"));
6385 +  mc_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6386 +  
6387 +  mc_ratio->GetYaxis()->SetTitle("R(SF / OF)");
6388 +  
6389 +  
6390 +  Value R_sf_of_low_mass = GetYieldBetween(data_sf,20,70)/GetYieldBetween(data_of,20,70);
6391 +  Value R_sf_of_high_mass = GetYieldBetween(data_sf,120,200)/GetYieldBetween(data_of,120,200);
6392 +  
6393 +  Value R_sf_of_low_mass_mc = GetYieldBetween(mc_sf,20,70)/GetYieldBetween(mc_of,20,70);
6394 +  Value R_sf_of_high_mass_mc = GetYieldBetween(mc_sf,120,200)/GetYieldBetween(mc_of,120,200);
6395 +  
6396 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6397 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6398 +  
6399 +  TGraphAsymmErrors *gra = produce_ratio_graph(mc_ratio);
6400 +  gra->Draw();
6401 +  mc_ratio->Draw();
6402 +  gra->Draw("e20");
6403 +  gra->SetFillColor(TColor::GetColor("#00ADE1"));
6404 +  gra->SetMarkerColor(TColor::GetColor("#00ADE1"));
6405 +  data_ratio->Draw("e1,same");
6406 +  
6407 +  TLegend *leg = new TLegend(0.17,0.16,0.53,0.31);
6408 + //   leg->SetHeader("R( SF / OF )");
6409 +  leg->SetFillColor(kWhite);
6410 +  leg->SetBorderSize(0);
6411 +  leg->AddEntry(data_ratio,"Data","p");
6412 +  leg->AddEntry(gra,"MC","fp");
6413 +  leg->Draw();
6414 +  
6415 +  TLine *g = new TLine(0,1.0,200,1.0);
6416 +  g->SetLineColor(kBlue);
6417 +  g->Draw();
6418 +  
6419 +  TLine *l = new TLine(70,0.5,70,1.5);
6420 +  l->SetLineStyle(2);
6421 +  l->SetLineColor(TColor::GetColor("#00ADE1"));
6422 +  TLine *m = new TLine(120,0.5,120,1.5);
6423 +  m->SetLineStyle(2);
6424 +  m->SetLineColor(TColor::GetColor("#00ADE1"));
6425 +  l->Draw();
6426 +  m->Draw();
6427 +  
6428 +  
6429 +  DrawPrelim();
6430 +  
6431 +  CompleteSave(SFoOF_can,"iTTbar/"+filename+"SF_vs_OF");
6432 +  
6433 +  delete leg;
6434 +  delete mc_sf;
6435 +  delete mc_of;
6436 +  delete mc_ratio;
6437 +  delete data_sf;
6438 +  delete data_of;
6439 +  delete data_ratio;
6440 +  delete SFoOF_can;
6441 + }  
6442 +
6443 + void make_iTTbar_JZB_plot(string datajzb, string mcjzb, TCut cut) {
6444 +  TCanvas *can = new TCanvas("can","can");
6445 +  vector<float> binning;
6446 +  binning.push_back(-100);
6447 +  binning.push_back(-50);
6448 +  binning.push_back(-20);
6449 +  binning.push_back(0);
6450 + //  binning.push_back(10);
6451 +  binning.push_back(20);
6452 + //  binning.push_back(30);
6453 +  binning.push_back(50);
6454 +  binning.push_back(100);
6455 +  binning.push_back(300);
6456 +  
6457 +  TH1F *hdata   = allsamples.Draw("hdata",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6458 +  TH1F *hodata  = allsamples.Draw("hodata", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6459 +  TH1F *hndata  = allsamples.Draw("hndata", "-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6460 +  TH1F *hnodata = allsamples.Draw("hnodata","-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6461 +  
6462 +  TH1F *hmc   = allsamples.Draw("hmc",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6463 +  TH1F *homc  = allsamples.Draw("homc", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6464 +  
6465 +  hodata->SetLineColor(kRed);
6466 +  hmc->SetLineColor(kRed);
6467 + //  hodata->Add(hndata);
6468 + //  hodata->Add(hnodata,-1);
6469 +  
6470 +  if(hdata->GetMaximum()>hodata->GetMaximum()) {
6471 +    hdata->SetMinimum(1.0);
6472 +    hdata->Draw();
6473 +    hodata->Draw("histo,same");
6474 +    hdata->Draw("same");
6475 +  } else {
6476 +    hodata->SetMinimum(1.0);
6477 +    hodata->Draw("histo");
6478 +    hdata->Draw("same");
6479 +  }
6480 +  
6481 +  CompleteSave(can,"iTTbar/JZB_plot");
6482 +  TH1F *ratio = (TH1F*)hdata->Clone("ratio");
6483 +  ratio->Divide(hodata);
6484 +  ratio->GetYaxis()->SetTitle("obs/pred");
6485 +  ratio->GetYaxis()->SetRangeUser(0,2);
6486 +  
6487 +  ratio->Draw();
6488 +  TLine *l = new TLine(-100,1.0,300,1.0);
6489 +  l->SetLineColor(kBlue);
6490 +  l->SetLineStyle(2);
6491 +  l->Draw();
6492 +  TLine *llow = new TLine(-100,1.0-0.07,300,1.0-0.07);
6493 +  TLine *lhi = new TLine(-100,1.0+0.07,300,1.0+0.07);
6494 +  llow->SetLineColor(kBlue);
6495 +  llow->SetLineStyle(2);
6496 +  llow->Draw();
6497 +  lhi->SetLineColor(kBlue);
6498 +  lhi->SetLineStyle(2);
6499 +  lhi->Draw();
6500 +  
6501 +  CompleteSave(can,"iTTbar/JZB_plot_ratio");
6502 +  
6503 +  delete hdata;
6504 +  delete hodata;
6505 +  delete ratio;
6506 +  delete can;
6507 + //  THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity));
6508 + //  THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity));
6509 + }
6510 +
6511 +  
6512 +  
6513 + void MakeSpecialiTTbarClosurePlot(TCut fullcut, string datajzb, string mcjzb, string MassRegion) {
6514 +  TCanvas *iTTbarClosureTestCanvas = new TCanvas("iTTbarClosureTestCanvas","iTTbarClosureTestCanvas");
6515 +  
6516 +  vector<float> binning;
6517 + /*
6518 +  binning.push_back(0);
6519 +  binning.push_back(20);
6520 +  binning.push_back(50);
6521 +  binning.push_back(100);
6522 + //  binning.push_back(200);
6523 + */
6524 +  binning.push_back(-100);
6525 +  binning.push_back(-50);
6526 +  binning.push_back(-30);
6527 +  binning.push_back(-10);
6528 +  binning.push_back(0);
6529 +  binning.push_back(10);
6530 +  binning.push_back(30);
6531 +  binning.push_back(50);
6532 +  binning.push_back(100);
6533 +  binning.push_back(200);
6534 +  
6535 +  
6536 +  TH1F *hdata  = allsamples.Draw("hdata", datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),data,luminosity);
6537 +  TH1F *hodata = allsamples.Draw("hodata",datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),data,luminosity);
6538 +  TH1F *hmc    = allsamples.Draw("hmc",   mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),mc,luminosity);
6539 +  TH1F *homc   = allsamples.Draw("homc",  mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),mc,luminosity);
6540 +  
6541 +  hdata->SetLineColor(kBlack);
6542 +  hmc->SetLineColor(kBlack);
6543 +  hodata->SetLineColor(kRed);
6544 +  homc->SetLineColor(kRed);
6545 +  hodata->SetMarkerColor(kRed);
6546 +  
6547 +  hdata->GetYaxis()->SetTitle("events");
6548 +  
6549 +  float maximum=hdata->GetMaximum()+1.2*sqrt(hdata->GetMaximum());
6550 +  float minimum=hdata->GetMinimum()-1.2*sqrt(hdata->GetMinimum());
6551 +  if(hmc->GetMinimum()<minimum) minimum=hmc->GetMinimum()-1.2*sqrt(hmc->GetMinimum());
6552 +  if(hmc->GetMaximum()>maximum) maximum=hmc->GetMaximum()+1.2*sqrt(hmc->GetMaximum());
6553 +  if(homc->GetMinimum()<minimum) minimum=homc->GetMinimum()-1.2*sqrt(homc->GetMinimum());
6554 +  if(homc->GetMaximum()>maximum) maximum=homc->GetMaximum()+1.2*sqrt(homc->GetMaximum());
6555 +  if(hodata->GetMinimum()<minimum) minimum=hodata->GetMinimum()-1.2*sqrt(hodata->GetMinimum());
6556 +  if(hodata->GetMaximum()>maximum) maximum=hodata->GetMaximum()+1.2*sqrt(hodata->GetMaximum());
6557 +  
6558 +  hdata->SetMaximum(maximum);
6559 +  hdata->SetMinimum(minimum);
6560 +  
6561 +  
6562 +  hdata->Draw();
6563 +  hmc->Draw("same,histo");
6564 +  homc->Draw("same,histo");
6565 +  hdata->Draw("same");
6566 +  hodata->Draw("same");
6567 +  
6568 +  TLegend *leg = make_legend();
6569 +  leg->AddEntry(hdata,"SF data","pe");
6570 +  leg->AddEntry(hodata,"OF data","pe");
6571 +  leg->AddEntry(hmc,"SF MC","l");
6572 +  leg->AddEntry(homc,"OF MC","l");
6573 +  leg->Draw();
6574 +  
6575 +  DrawPrelim();
6576 +  
6577 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_"+MassRegion);
6578 +  
6579 +  TH1F *ratio_data = (TH1F*)hdata->Clone("ratio_data");
6580 +  ratio_data->Divide(hodata);
6581 +  TH1F *ratio_mc = (TH1F*)hmc->Clone("ratio_mc");
6582 +  ratio_mc->Divide(homc);
6583 +  
6584 +  ratio_mc->SetFillColor(kBlue);
6585 +  ratio_mc->SetMarkerSize(0);
6586 +  
6587 +  TGraphAsymmErrors *eratio = produce_ratio_graph(ratio_mc);
6588 +  
6589 +  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
6590 +  ratio_data->GetYaxis()->SetRangeUser(0.5,1.5);
6591 +  ratio_data->Draw("e1");
6592 +  eratio->Draw("20");
6593 +  ratio_data->Draw("e1,same");
6594 +  
6595 +  TLegend *leg2 = make_legend();
6596 +  leg2->AddEntry(ratio_data,"R(SF/OF) in #bar{t}t CR, data","pe");
6597 +  leg2->AddEntry(eratio    ,"R(SF/OF) in #bar{t}t CR, MC"  ,"f");
6598 +  leg2->SetY1(0.8);
6599 +  leg2->SetX1(0.45);
6600 +  leg2->Draw();
6601 +  
6602 +  DrawPrelim();
6603 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_Ratio_"+MassRegion);
6604 +  
6605 +  TFile *f = new TFile("fout.root","RECREATE");
6606 +  eratio->Write();
6607 +  ratio_data->Write();
6608 +  leg2->Write();
6609 +  f->Close();
6610 +  
6611 +  
6612 +  delete leg;
6613 +  delete leg2;
6614 +  delete ratio_data;
6615 +  delete ratio_mc;
6616 +  delete hdata;
6617 +  delete hmc;
6618 +  delete hodata;
6619 +  delete iTTbarClosureTestCanvas;
6620 + }
6621 +  
6622 +  
6623 +  
6624 + void make_ijzb_ttbar_closure_test(string datajzb, string mcjzb) {
6625 +  TCut tt_nJets("pfJetGoodNum40==2");
6626 +  TCut tt_bJet("pfJetGoodNumBtag40==2 && met[4]>10");
6627 +  TCut tt_LowMass("mll>20&&mll<70");
6628 +  TCut tt_HighMass("mll>120&&mll<200");
6629 +  TCut tt_noZ(tt_LowMass || tt_HighMass);
6630 +  
6631 +  /*
6632 +  make_iTTbar_JZB_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ);
6633 + */
6634 +  TCanvas *can = new TCanvas("can","can");
6635 +
6636 +  TH1F *hdata  =                allsamples.Draw(        "hdata", "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,data,luminosity);
6637 +  THStack *hmc = new THStack(   allsamples.DrawStack(   "hmc",   "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,mc,  luminosity));
6638 +  TH1F *hodata =                allsamples.Draw(        "hodata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,data,luminosity);
6639 +  THStack *homc = new THStack(  allsamples.DrawStack(   "homc",  "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,mc,  luminosity));
6640 +  
6641 +  TH1F *coll_hmc = CollapseStack(hmc);
6642 +  TH1F *coll_homc = CollapseStack(homc);
6643 +  
6644 +  bool dolog=true;
6645 +  bool nolog=false;
6646 +  
6647 +  dout << " SF: " << endl;
6648 +  dout << "   Data : " << hdata->Integral() << endl;
6649 +  WriteYield(hmc, 0, 10000);
6650 +  dout << " OF: " << endl;
6651 +  dout << "   Data : " << hodata->Integral() << endl;
6652 +  WriteYield(homc, 0, 10000);
6653 +  hodata->SetLineColor(kRed);
6654 +  hdata->Draw();
6655 +  hmc->Draw("histo,same");
6656 +  hodata->Draw("histo,same");
6657 +  hdata->Draw("e1,same");
6658 +  DrawPrelim();
6659 +  CompleteSave(can,"TestingPrediction");
6660 +  
6661 +  dout << "We get an expected ratio of " << coll_hmc->Integral()/coll_homc->Integral() << endl;
6662 +  dout << "In data we find  " << hdata->Integral()/hodata->Integral() << endl;
6663 +  
6664 +  Value R_sf_of_low_mass = GetYieldBetween(hdata,20,70)/GetYieldBetween(hodata,20,70);
6665 +  Value R_sf_of_high_mass = GetYieldBetween(hdata,120,200)/GetYieldBetween(hodata,120,200);
6666 +  
6667 +  Value R_sf_of_low_mass_mc = GetYieldBetween(coll_hmc,20,70)/GetYieldBetween(coll_homc,20,70);
6668 +  Value R_sf_of_high_mass_mc = GetYieldBetween(coll_hmc,120,200)/GetYieldBetween(coll_homc,120,200);
6669 +  
6670 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6671 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6672 +  
6673 +  dout << "Composition at low mass : " << endl;
6674 +  dout << "Same flavor: " << endl;
6675 +  ProduceYields(20, 70, hdata, hmc);
6676 +  dout << "Opposite flavor: " << endl;
6677 +  ProduceYields(20, 70, hodata, homc);
6678 +  
6679 +  dout << endl << endl;
6680 +  
6681 +  dout << "Composition at high mass : " << endl;
6682 +  dout << "Same flavor: " << endl;
6683 +  ProduceYields(120, 200, hdata, hmc);
6684 +  dout << "Opposite flavor: " << endl;
6685 +  ProduceYields(120, 200, hodata, homc);
6686 +  
6687 +  
6688 +
6689 +  
6690 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),20,-200,200,dolog,"JZB","iTTbar/JZB_SF",false,true);
6691 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),20,-200,200,dolog,"JZB","iTTbar/JZB_OF",false,true);
6692 +
6693 +  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);
6694 +  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);
6695 +  
6696 +  make_SF_over_OF_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ,"mll",20,0,200,"m_{ll} [GeV]","mll");
6697 +  
6698 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_LowMass),datajzb,mcjzb,"LowMassRegion2070");
6699 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_HighMass),datajzb,mcjzb,"HighMassRegion");
6700 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_noZ),datajzb,mcjzb,"NoZ");
6701 +  
6702 + //   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);
6703 + //   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);
6704 + //  
6705 + //   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);
6706 + //   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);
6707 +  
6708 +  
6709 +  delete coll_hmc;
6710 +  delete coll_homc;
6711 +  delete hmc;
6712 +  delete homc;
6713 +  delete hdata;
6714 +  delete hodata;
6715 +  delete can;
6716 + }
6717 +
6718 + void compute_global_significance(float local_significance) {
6719 +    float global_sigificance = ROOT::Math::normal_quantile_c(ROOT::Math::normal_cdf_c(local_significance,1)*4,1);
6720 +    dout << "local significance  : " << local_significance << endl;
6721 +    dout << "global significance : " << global_sigificance << endl;
6722 + }
6723 +  
6724  
6725   void test() {
6726    
6727 +  
6728 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
6729 +  stringstream result, datajzb, mcjzb;
6730 +  bool doPUreweighting=true;
6731 +  bool SwitchOffNJetsCut=false;
6732 +  
6733 +  
6734 +  TCanvas *can = new TCanvas("can","can");
6735 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
6736 +  
6737 +  float NumVtxBin[6] = {0,5,10,15,20,30};
6738 +  
6739 +  stringstream NowCut;
6740 +  
6741 +  TGraphErrors *gMCPeak = new TGraphErrors();
6742 +  gMCPeak->SetTitle("gMCPeak");
6743 +  gMCPeak->SetName("gMCPeak");
6744 +  TGraphErrors *gDataPeak = new TGraphErrors();
6745 +  gDataPeak->SetTitle("gDataPeak");
6746 +  gDataPeak->SetName("gDataPeak");
6747 +  TGraphErrors *gMCWidth = new TGraphErrors();
6748 +  gMCWidth->SetTitle("gMCWidth");
6749 +  gMCWidth->SetName("gMCWidth");
6750 +  TGraphErrors *gDataWidth = new TGraphErrors();
6751 +  gDataWidth->SetTitle("gDataWidth");
6752 +  gDataWidth->SetName("gDataWidth");
6753 +  
6754 +  float AllMCPeaks[200];
6755 +  float AllMCPeaksErrors[200];
6756 +  
6757 +  for(int i=10;i<180;i+=20) {
6758 +    NowCut.str("");
6759 +    NowCut << "mll>=" << i << "&&mll<" << i+20;
6760 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
6761 +    AllMCPeaks[i]=MCPeak;
6762 +    AllMCPeaksErrors[i]=MCPeakError;
6763 +  }
6764 +  
6765 +  dout << "Summary : " << endl;
6766 +  for(int i=10;i<180;i+=20) {
6767 +    dout << "For the slice at [" << i << " , " << i+20 << "] we get a peak at " << AllMCPeaks[i] << " +/- " << AllMCPeaksErrors[i] << endl;
6768 +  }
6769 +  /*
6770    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
6771    testcanv->cd();
6772   //  switch_overunderflow(true);
6773 <  TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
6774 <  switch_overunderflow(false);
6775 <  ptdistr->Draw();
6776 <  testcanv->SaveAs("test.png");
3850 <  dout << "HELLO there!" << endl;
6773 >  TH1F *histo1 = new TH1F("histo","histo",100,0,1);
6774 >  histo1->Sumw2();
6775 >  TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
6776 >  histo2->Sumw2();
6777    
6778 +  for(int i=0;i<100;i++) {
6779 +    histo1->Fill(1.0/i,i);
6780 +    histo2->Fill(1.0/(i*i),i);
6781 +  }
6782 +
6783 +  histo1->Draw();
6784 +  histo2->Draw("e1,same");
6785 +  
6786 +  Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
6787 +  
6788 +  
6789 +  dout << "HELLO there!" << endl;
6790 +  */
6791   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines