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.73 by buchmann, Mon Dec 3 16:05:36 2012 UTC vs.
Revision 1.96 by buchmann, Wed May 22 07:50:52 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 + void Old_FindPeakPileUpCorrection() {
113 +  bool StoreResultsInSeparateFile=false;
114 +  PeakLibrary::StoreHistos=true;
115 +  
116 +  
117 +  dout << "Finding peak position as a function of PU" << endl;
118 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
119 +  stringstream result, datajzb, mcjzb;
120 +  bool doPUreweighting=true;
121 +  bool SwitchOffNJetsCut=false;
122 +  
123 +  
124 +  TCanvas *can = new TCanvas("can","can");
125 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
126 +  
127 +  float NumVtxBin[6] = {0,5,10,15,20,30};
128 +  
129 +  stringstream NowCut;
130 +  
131 +  TGraphErrors *gMCPeak = new TGraphErrors();
132 +  gMCPeak->SetTitle("gMCPeak");
133 +  gMCPeak->SetName("gMCPeak");
134 +  TGraphErrors *gDataPeak = new TGraphErrors();
135 +  gDataPeak->SetTitle("gDataPeak");
136 +  gDataPeak->SetName("gDataPeak");
137 +  TGraphErrors *gMCWidth = new TGraphErrors();
138 +  gMCWidth->SetTitle("gMCWidth");
139 +  gMCWidth->SetName("gMCWidth");
140 +  TGraphErrors *gDataWidth = new TGraphErrors();
141 +  gDataWidth->SetTitle("gDataWidth");
142 +  gDataWidth->SetName("gDataWidth");
143 +  
144 +  
145 +  for(int i=0;i<5;i++) {
146 +    NowCut.str("");
147 +    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
148 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
149 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
150 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
151 +    
152 +    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
153 +    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
154 +    
155 +    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
156 +    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
157 +    
158 +    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
159 +    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
160 +    
161 +    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
162 +    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
163 +  }
164 +  
165 +  can->cd();
166 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
167 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
168 +  gMCPeak->GetXaxis()->CenterTitle();
169 +  gMCPeak->GetYaxis()->CenterTitle();
170 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
171 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
172 +  gDataPeak->GetXaxis()->CenterTitle();
173 +  gDataPeak->GetYaxis()->CenterTitle();
174 +  
175 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
176 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
177 +  gDataWidth->GetXaxis()->CenterTitle();
178 +  gDataWidth->GetYaxis()->CenterTitle();
179 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
180 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
181 +  gMCWidth->GetXaxis()->CenterTitle();
182 +  gMCWidth->GetYaxis()->CenterTitle();
183 +  
184 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
185 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
186 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
187 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
188 +  
189 +  gMCPeak->Draw("A2");
190 +  DrawMCPrelim();
191 +  CompleteSave(can,"PUStudy/MCPeak");
192 +  can->cd();
193 +  gMCWidth->Draw("A2");
194 +  DrawMCPrelim();
195 +  CompleteSave(can,"PUStudy/MCWidth");
196 +  
197 +  can->cd();
198 +  gDataPeak->Draw("A2");
199 +  
200 +  DrawPrelim();
201 +  CompleteSave(can,"PUStudy/DataPeak");
202 +  can->cd();
203 +  gDataWidth->Draw("A2");
204 +  DrawPrelim();
205 +  CompleteSave(can,"PUStudy/DataWidth");
206 +  
207 +  if(StoreResultsInSeparateFile) {
208 +    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
209 +    gMCPeak->Write();
210 +    gDataPeak->Write();
211 +    gMCWidth->Write();
212 +    gDataWidth->Write();
213 +    PeakFinding->Close();
214 +  }
215 +  
216 +  gDataPeak->Fit("pol1","L");
217 +  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
218 +  gMCPeak->Fit("pol1","L");
219 +  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
220 +  
221 +  
222 +  can->cd();
223 +  gMCPeak->Draw("A2");
224 +  DrawMCPrelim();
225 +  CompleteSave(can,"PUStudy/MCPeak_WithFit");
226 +  can->cd();
227 +  
228 +  can->cd();
229 +  gDataPeak->Draw("A2");
230 +  DrawPrelim();
231 +  CompleteSave(can,"PUStudy/DataPeak_WithFit");
232 +  
233 +  
234 +  
235 +  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
236 +  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
237 +  
238 +  TLegend *leg = make_legend();
239 +  can->cd();
240 +  int j=0;
241 +  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
242 +    PeakLibrary::DataHistogram[i]->Rebin(5);
243 +    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
244 +    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
245 +    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
246 +    stringstream name;
247 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
248 +    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
249 +    j++;
250 +  }
251 +  
252 +  leg->Draw();
253 +  DrawPrelim();
254 +  CompleteSave(can,"PUStudy/DataOverview");
255 +  
256 +  TLegend *leg2 = make_legend();
257 +  can->cd();
258 +  j=0;
259 +  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
260 +    PeakLibrary::MCHistogram[i]->Rebin(5);
261 +    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
262 +    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
263 +    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
264 +    stringstream name;
265 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
266 +    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
267 +    j++;
268 +  }
269 +  
270 +  leg->Draw();
271 +  DrawPrelim();
272 +  CompleteSave(can,"PUStudy/MCOverview");
273 +  
274 +  delete can;
275 +  PeakLibrary::StoreHistos=false;
276 + }
277 +
278 + void FindPeakPileUpCorrection() {
279 +  bool StoreResultsInSeparateFile=true;
280 +  PeakLibrary::StoreHistos=true;
281 +  
282 +  
283 +  dout << "Finding peak position as a function of PU" << endl;
284 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
285 +  stringstream result, datajzb, mcjzb;
286 +  bool doPUreweighting=true;
287 +  bool SwitchOffNJetsCut=false;
288 +  
289 +  
290 +  TCanvas *can = new TCanvas("can","can");
291 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
292 +  
293 +  const int nbins=11;
294 +  float NumVtxBin[nbins] = {0,7,9,11,13,15,17,19,21,24,50};
295 +  
296 +  stringstream NowCut;
297 +  
298 +
299 +  Double_t mc_peak_x[nbins];
300 +  Double_t mc_peak_y[nbins];
301 +  Double_t mc_peak_dxh[nbins];
302 +  Double_t mc_peak_dxl[nbins];
303 +  Double_t mc_peak_dy[nbins];
304 +  
305 +  Double_t data_peak_x[nbins];
306 +  Double_t data_peak_y[nbins];
307 +  Double_t data_peak_dxh[nbins];
308 +  Double_t data_peak_dxl[nbins];
309 +  Double_t data_peak_dy[nbins];
310 +  
311 +  Double_t mc_width_x[nbins];
312 +  Double_t mc_width_y[nbins];
313 +  Double_t mc_width_dxh[nbins];
314 +  Double_t mc_width_dxl[nbins];
315 +  Double_t mc_width_dy[nbins];
316 +  
317 +  Double_t data_width_x[nbins];
318 +  Double_t data_width_y[nbins];
319 +  Double_t data_width_dxh[nbins];
320 +  Double_t data_width_dxl[nbins];
321 +  Double_t data_width_dy[nbins];
322 +
323 +  for(int i=0;i<nbins-1;i++) {
324 +    NowCut.str("");
325 +    NowCut << "numVtx>" << NumVtxBin[i] << "&&numVtx<=" << NumVtxBin[i+1];
326 +    cout << "NVtx cut is now : " << NowCut.str() << endl;
327 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
328 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
329 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
330 +    
331 +    TH1F *hDataSFNumVtx = allsamples.Draw("hDataSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
332 +    TH1F *hDataOFNumVtx = allsamples.Draw("hDataOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
333 +    TH1F *hMCSFNumVtx = allsamples.Draw("hMCSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
334 +    TH1F *hMCOFNumVtx = allsamples.Draw("hMCOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
335 +    
336 +    hDataSFNumVtx->Add(hDataOFNumVtx,-1);
337 +    hMCSFNumVtx->Add(hMCOFNumVtx,-1);
338 +    
339 +    mc_peak_x[i]=hMCSFNumVtx->GetMean();
340 +    mc_peak_y[i]=MCPeak;
341 +    mc_peak_dy[i]=MCPeakError;
342 +    
343 +    data_peak_x[i]=hDataSFNumVtx->GetMean();
344 +    data_peak_y[i]=DataPeak;
345 +    data_peak_dy[i]=DataPeakError;
346 +    
347 +    mc_width_x[i]=hMCSFNumVtx->GetMean();
348 +    mc_width_y[i]=mcSigma;
349 +    mc_width_dy[i]=mcSigmaError;
350 +    
351 +    data_width_x[i]=hDataSFNumVtx->GetMean();
352 +    data_width_y[i]=dataSigma;
353 +    data_width_dy[i]=dataSigmaError;
354 +    
355 +    delete hDataSFNumVtx;
356 +    delete hDataOFNumVtx;
357 +    delete hMCSFNumVtx;
358 +    delete hMCOFNumVtx;
359 +  }
360 +  
361 +  for(int i=0;i<nbins-1;i++) {
362 +    if(i==0) {
363 +      data_width_dxl[i]=data_width_x[i];
364 +      data_peak_dxl[i]=data_peak_x[i];
365 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
366 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
367 +      
368 +      mc_width_dxl[i]=mc_width_x[i];
369 +      mc_peak_dxl[i]=mc_peak_x[i];
370 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
371 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
372 +    } else if(i==nbins-2) {
373 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
374 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
375 +      data_width_dxh[i]=50-data_width_x[i];
376 +      data_peak_dxh[i]=50-data_peak_x[i];
377 +      
378 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
379 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
380 +      mc_width_dxh[i]=50-mc_width_x[i];
381 +      mc_peak_dxh[i]=50-mc_peak_x[i];
382 +    } else {
383 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
384 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
385 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
386 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
387 +      
388 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
389 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
390 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
391 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
392 +    }
393 +  }
394 +  
395 +  TGraphAsymmErrors *gMCPeak = new TGraphAsymmErrors(nbins-1,mc_peak_x,mc_peak_y,mc_peak_dxl,mc_peak_dxh,mc_peak_dy,mc_peak_dy);
396 +  gMCPeak->SetTitle("gMCPeak");
397 +  gMCPeak->SetName("gMCPeak");
398 +  
399 +  TGraphAsymmErrors *gDataPeak = new TGraphAsymmErrors(nbins-1,data_peak_x,data_peak_y,data_peak_dxl,data_peak_dxh,data_peak_dy,data_peak_dy);
400 +  gDataPeak->SetTitle("gDataPeak");
401 +  gDataPeak->SetName("gDataPeak");
402 +  
403 +  TGraphAsymmErrors *gMCWidth = new TGraphAsymmErrors(nbins-1,mc_width_x,mc_width_y,mc_width_dxl,mc_width_dxh,mc_width_dy,mc_width_dy);
404 +  gMCWidth->SetTitle("gMCWidth");
405 +  gMCWidth->SetName("gMCWidth");
406 +  
407 +  TGraphAsymmErrors *gDataWidth = new TGraphAsymmErrors(nbins-1,data_width_x,data_width_y,data_width_dxl,data_width_dxh,data_width_dy,data_width_dy);
408 +  gDataWidth->SetTitle("gDataWidth");
409 +  gDataWidth->SetName("gDataWidth");
410 +  
411 +  can->cd();
412 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
413 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
414 +  gMCPeak->GetXaxis()->CenterTitle();
415 +  gMCPeak->GetYaxis()->CenterTitle();
416 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
417 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
418 +  gDataPeak->GetXaxis()->CenterTitle();
419 +  gDataPeak->GetYaxis()->CenterTitle();
420 +  
421 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
422 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
423 +  gDataWidth->GetXaxis()->CenterTitle();
424 +  gDataWidth->GetYaxis()->CenterTitle();
425 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
426 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
427 +  gMCWidth->GetXaxis()->CenterTitle();
428 +  gMCWidth->GetYaxis()->CenterTitle();
429 +  
430 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
431 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
432 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
433 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
434 +  
435 +  gMCPeak->Draw("A2");
436 +  DrawMCPrelim();
437 +  CompleteSave(can,"PUStudy/MCPeak");
438 +  can->cd();
439 +  gMCWidth->Draw("A2");
440 +  DrawMCPrelim();
441 +  CompleteSave(can,"PUStudy/MCWidth");
442 +  
443 +  can->cd();
444 +  gDataPeak->Draw("A2");
445 +  
446 +  DrawPrelim();
447 +  CompleteSave(can,"PUStudy/DataPeak");
448 +  can->cd();
449 +  gDataWidth->Draw("A2");
450 +  DrawPrelim();
451 +  CompleteSave(can,"PUStudy/DataWidth");
452 +  
453 +  if(StoreResultsInSeparateFile) {
454 +    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
455 +    gMCPeak->Write();
456 +    gDataPeak->Write();
457 +    gMCWidth->Write();
458 +    gDataWidth->Write();
459 +    PeakFinding->Close();
460 +  }
461 +  
462 +  gDataPeak->Fit("pol1");
463 +  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
464 +  gMCPeak->Fit("pol1");
465 +  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
466 +  
467 +  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
468 +  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
469 +  
470 +  TLegend *leg = make_legend();
471 +  can->cd();
472 +  int j=0;
473 +  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
474 +    PeakLibrary::DataHistogram[i]->Rebin(5);
475 +    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
476 +    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
477 +    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
478 +    stringstream name;
479 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
480 +    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
481 +    j++;
482 +  }
483 +  
484 +  leg->Draw();
485 +  DrawPrelim();
486 +  CompleteSave(can,"PUStudy/DataOverview");
487 +  
488 +  TLegend *leg2 = make_legend();
489 +  can->cd();
490 +  j=0;
491 +  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
492 +    PeakLibrary::MCHistogram[i]->Rebin(5);
493 +    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
494 +    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
495 +    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
496 +    stringstream name;
497 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
498 +    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
499 +    j++;
500 +  }
501 +  
502 +  leg->Draw();
503 +  DrawPrelim();
504 +  CompleteSave(can,"PUStudy/MCOverview");
505 +  
506 +  delete can;
507 +  PeakLibrary::StoreHistos=false;
508 + }
509 +
510 +
511 +
512   void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
513   {
514    bool overunderflowstatus=addoverunderflowbins;
# Line 144 | Line 566 | void find_peaks(float &MCPeak,float &MCP
566      
567    } else {
568      datajzb << "(" << jzbvariabledata;
569 <      mcjzb << "(" << jzbvariablemc;
569 >    mcjzb   << "(" << jzbvariablemc;
570      
571      if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
572      else datajzb << "+ " << TMath::Abs(datapeak) << " ";
# Line 164 | Line 586 | void find_peaks(float &MCPeak,float &MCP
586      switch_overunderflow(overunderflowstatus);
587   }
588  
589 < void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
589 > void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth, int MCorData) {
590    float min=70.0;
591    float max=115.0;
592    if(!PlottingSetup::RestrictToMassPeak) {
# Line 173 | Line 595 | void make_special_obs_pred_mll_plot(stri
595    }
596    int nbins=int((max-min)/binWidth);
597    
598 +  string prefix="";
599 +  if(MCorData==mc) prefix="MC__";
600 +  
601 +  
602 +  if(MCorData==mc) datajzb=mcjzb;
603 +  
604    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
605    
606    stringstream largerzeroS;
# Line 188 | Line 616 | void make_special_obs_pred_mll_plot(stri
616    largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
617    TCut largerzeroM(largerzeroMS.str().c_str());
618    
619 <  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
620 <  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
621 <  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
622 <  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
623 <  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
619 >
620 >  stringstream smallerzeroMS;
621 >  smallerzeroMS << "(" << mcjzb << "<-" << jzbthreshold << ")";
622 >  TCut smallerzeroM(smallerzeroMS.str().c_str());
623 >  
624 >  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,MCorData,luminosity);
625 >  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
626 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,MCorData,luminosity);
627 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,MCorData,luminosity);
628 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,MCorData,luminosity);
629  
630    TH1F *RcorrJZBSBem;
631    TH1F *LcorrJZBSBem;
# Line 202 | Line 635 | void make_special_obs_pred_mll_plot(stri
635   //  TH1F *RcorrJZBeemmNoS;
636  
637    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
638 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
639 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
640 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
641 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
638 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,MCorData, luminosity);
639 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,MCorData, luminosity);
640 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,MCorData, luminosity);
641 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,MCorData, luminosity);
642    }
643 <  
644 <  // Separate predictions
643 >
644 >    // Separate predictions
645    TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
646    TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
647    TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
648 +  
649 +  TH1F *BpredSys = (TH1F*)SFN->Clone("BpredSys");
650 +  ClearHisto(BpredSys);
651 +  AddSquared(BpredSys,SFN,pow(PlottingSetup::zjetsestimateuncertOFFPEAK,2));
652 +
653    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
654      OFP->Scale(1.0/3.0);
655      OFP->Add(RcorrJZBSBem,1.0/3.);
# Line 219 | Line 657 | void make_special_obs_pred_mll_plot(stri
657      OFN->Scale(1.0/3.0);
658      OFN->Add(LcorrJZBSBem,1.0/3.);
659      OFN->Add(LcorrJZBSBeemm,1.0/3.);
660 <  }
660 >    AddSquared(BpredSys,RcorrJZBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
661 >    AddSquared(BpredSys,RcorrJZBSBem,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
662 >    AddSquared(BpredSys,RcorrJZBSBeemm,pow((1.0/3) * PlottingSetup::emuncertOFFPEAK,2));  
663 >  } else {
664 >    AddSquared(BpredSys,OFN,pow(PlottingSetup::emuncertOFFPEAK,2));  
665 >  }
666  
667 +  SQRT(BpredSys);
668 +  
669 +  TGraphErrors *BpredSysBand = new TGraphErrors();
670 + //  TH1F *BpredSysBand = (TH1F*)BpredSys->Clone("BpredSysBand");
671 +  
672 +  for(int i=1;i<=BpredSys->GetNbinsX();i++) {
673 +    /*BpredSysBand->SetBinError(i,BpredSysBand->GetBinContent(i));
674 +    BpredSysBand->SetBinContent(i,0);*/
675 +    float dx=0.5*BpredSys->GetBinWidth(i);
676 +    float dy=BpredSys->GetBinContent(i);
677 +    BpredSysBand->SetPoint(i-1,BpredSys->GetBinCenter(i),0);
678 +    BpredSysBand->SetPointError(i-1,dx,dy);
679 +  }
680 +  
681 +  delete BpredSys;
682 +  BpredSysBand->SetFillColor(TColor::GetColor("#2E9AFE"));
683 +  
684    TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
685    Bpred->Add(OFP);
686    Bpred->Add(OFN,-1);
# Line 228 | Line 688 | void make_special_obs_pred_mll_plot(stri
688    
689    RcorrJZBeemm->SetTitleOffset(1.3,"y");
690    RcorrJZBeemm->Draw();
691 <  mcRcorrJZBeemm.Draw("same");
691 >  mcRcorrJZBeemm.Draw("histo,same");
692    Bpred->Draw("histo,same");
693    RcorrJZBeemm->Draw("same");
694    
695    TLegend *leg = allsamples.allbglegend();
696    leg->SetX1(0.58);
697 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
697 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
698    leg->AddEntry(Bpred,"predicted (data)","l");
699    leg->Draw("same");
700    
701    stringstream saveas;
702 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
702 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold;
703    CompleteSave(ckin,saveas.str());
704    
705    // Draw all predictions overlayed
# Line 262 | Line 722 | void make_special_obs_pred_mll_plot(stri
722    RcorrJZBeemm->Draw("same");
723    
724    TLegend *leg2 = make_legend("",0.52,0.7);
725 <  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
726 <  leg2->AddEntry(Bpred,"predicted (data)","l");
727 <  leg2->AddEntry(SFN,  "  SF JZB<0","l");
728 <  leg2->AddEntry(OFN,  "  OF JZB<0","l");
729 <  leg2->AddEntry(OFP,  "  OF JZB>0","l");
725 >  if(MCorData==data) {
726 >    leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
727 >    leg2->AddEntry(Bpred,"predicted (data)","l");
728 >  } else {
729 >    leg2->AddEntry(RcorrJZBeemm,"true (MC)","lp");
730 >    leg2->AddEntry(Bpred,"predicted (MC)","l");
731 >  }
732 >
733 >  if(jzbthreshold>0) {
734 >    leg2->AddEntry(SFN,  ("  SF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
735 >    leg2->AddEntry(OFN,  ("  OF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
736 >  } else {
737 >    leg2->AddEntry(SFN,  "  SF JZB<0","l");
738 >    leg2->AddEntry(OFN,  "  OF JZB<0","l");
739 >  }
740 >  leg2->AddEntry(OFP,  ("  OF JZB>"+any2string(jzbthreshold)).c_str(),"l");
741    leg2->Draw("same");
742    
743    saveas.str("");
744 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
744 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc";
745    CompleteSave(ckin,saveas.str());
746    
747 +  
748 +  TH1F *diff = (TH1F*)RcorrJZBeemm->Clone("diff");
749 +  diff->Add(Bpred,-1);
750 +  
751 +  TLegend *dleg = make_legend();
752 +  if(MCorData==data) dleg->AddEntry(diff,"True-predicted","p");
753 +  else dleg->AddEntry(diff,"True-predicted","p");
754 +  dleg->AddEntry(BpredSysBand,"Systematic envelope","f");
755 +  
756 +  
757 +  diff->Draw("e1");
758 +  BpredSysBand->Draw("e2");
759 +  diff->Draw("e1,same");
760 +  dleg->Draw();
761 +  
762 +  if(MCorData==data) DrawPrelim();
763 +  else DrawMCPrelim();
764 +  
765 +  saveas.str("");
766 +  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc_Diff";
767 +  CompleteSave(ckin,saveas.str());
768 +
769 +  delete BpredSysBand;
770 +  delete diff;
771 +  
772    delete RcorrJZBeemm;
773    delete LcorrJZBeemm;
774    delete RcorrJZBem;
775    delete LcorrJZBem;
776 +
777    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
778      delete RcorrJZBSBeemm;
779      delete LcorrJZBSBeemm;
# Line 285 | Line 782 | void make_special_obs_pred_mll_plot(stri
782    }
783    delete Bpred;
784    delete ckin;
785 +  CleanLegends();
786   }
787  
788   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 331 | Line 829 | void make_special_mll_plot(int nbins, fl
829    delete datahistoOSOF;
830    delete datahistoOSSF;
831    delete ckin;
832 +  CleanLegends();
833   }
834    
835  
# Line 382 | Line 881 | float make_one_OFSF_plot(string variable
881    TCut cutSF;
882    TCut cutOF;
883  
884 +  cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
885    cutOF = cutOSOF&&cutnJets&&ibasiccut;
886    cutSF = cutOSSF&&cutnJets&&ibasiccut;
887 +  
888 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
889  
388  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
890    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
891    rcan->SetLogy(logscale);
892    rcan->cd();
# Line 410 | Line 911 | float make_one_OFSF_plot(string variable
911    }
912    if (ymax<0) {
913      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
914 <    else datahistoSF->SetMaximum(1.8*datahistoSF->GetMaximum());
914 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
915    } else {
916      datahistoSF->SetMaximum(ymax);
917    }
# Line 437 | Line 938 | float make_one_OFSF_plot(string variable
938    mleg->Draw();
939    DrawPrelim();
940    if (datahistoOF->Integral()>0) {
941 <    save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
941 >    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
942    } else {
943      CompleteSave(rcan, "SFOF/" + filename);
443    delete rcan;
944    }
945  
946    datahistoSF->Delete();
947    datahistoOF->Delete();
948    //signalhisto->Delete();
949    delete mleg;
950 <  delete ckin;
950 >  delete rcan;
951 >  delete ofsf_can;
952  
953    return ymaxSet;
954  
# Line 500 | Line 1001 | float make_data_comparison_plot(string v
1001    data2->Draw("HIST,SAMES");
1002    mleg->Draw();
1003    DrawPrelim();
1004 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
1004 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
1005  
1006    data1->Delete();
1007    data2->Delete();
1008    delete mleg;
1009 +  delete rcan;
1010    delete ckin;
1011  
1012   }
# Line 537 | Line 1039 | void make_OFSF_plots(string variable, st
1039  
1040   }
1041  
1042 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
1043 +  string scut=(string)(const char*)cut;
1044 +  string acut=ReplaceAll(scut,replacethis,withthis);
1045 +  return TCut(acut.c_str());
1046 + }
1047 +
1048 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1049 +  TCut cut=addcut&&basiccut;
1050 +
1051 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1052 +  ckin->SetLogy(dolog);
1053 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
1054 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1055 +  datahisto->SetMarkerSize(DataMarkerSize);
1056 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1057 +  else datahisto->SetMinimum(0.5);
1058 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1059 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1060 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
1061 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1062 +  TH1F *MCcentral = CollapseStack(mcstack);
1063 +
1064 +  TCut bkpcut = cut;
1065 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
1066 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
1067 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1068 +
1069 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
1070 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
1071 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1072 +  
1073 +  cut=bkpcut;
1074 +  TCut bkpweight = cutWeight;
1075 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
1076 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
1077 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1078 +  
1079 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
1080 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
1081 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1082 +  cutWeight=bkpweight;
1083 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
1084 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
1085 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1086 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
1087 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
1088 +    float jes   = jesdn>jesup?jesdn:jesup;
1089 +    
1090 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
1091 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
1092 +    float pu   = PUdn>PUup?PUdn:PUup;
1093 +    
1094 +    float sys=sqrt(jes*jes+pu*pu);
1095 +    sys/=MCcentral->GetBinContent(i);
1096 +    if(MCcentral->GetBinContent(i)==0) sys=0;
1097 +    Systematic->SetBinContent(i,sys);
1098 +  }
1099 +  
1100 +  datahisto->Draw("e1");
1101 +  ckin->Update();
1102 +  mcstack.Draw("histo,same");
1103 +  
1104 +  datahisto->Draw("same,e1");
1105 +  TLegend *kinleg = allsamples.allbglegend();
1106 +  kinleg->Draw();
1107 +
1108 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1109 +  kinpad->SetLogy(dolog);
1110 +  kinpad->cd();
1111 +  datahisto->Draw("e1");
1112 +  mcstack.Draw("histo,same");
1113 +  datahisto->Draw("same,e1");
1114 +  datahisto->Draw("same,axis");
1115 +  
1116 +  kinleg->Draw("same");
1117 +  DrawPrelim();
1118 +  string saveas="kin/"+filename;
1119 +  
1120 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1121 +  save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1122 +  
1123 +  ckin->cd();
1124 +  MCcentral->SetFillColor(kWhite);
1125 +  MCcentral->SetLineColor(kBlack);
1126 +  MCcentral->SetLineWidth(2);
1127 +  MCPUdn->SetLineColor(kRed);
1128 +  MCPUup->SetLineColor(kYellow);
1129 +  MCJESdn->SetLineColor(kBlue);
1130 +  MCJESup->SetLineColor(kGreen);
1131 +  
1132 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
1133 +  legsmall->SetNColumns(5);
1134 +  legsmall->AddEntry(MCcentral,"central","L");
1135 +  legsmall->AddEntry(MCPUdn,"PU down","L");
1136 +  legsmall->AddEntry(MCPUup,"PU up","L");
1137 +  legsmall->AddEntry(MCJESdn,"JES down","L");
1138 +  legsmall->AddEntry(MCJESup,"JES up","L");
1139 +  legsmall->SetFillColor(kWhite);
1140 +  legsmall->SetBorderSize(0);
1141 +  
1142 +  datahisto->Draw("e1");
1143 +  MCcentral->Draw("histo,same");
1144 +  MCPUdn->Draw("histo,same");
1145 +  MCPUup->Draw("histo,same");
1146 +  MCJESdn->Draw("histo,same");
1147 +  MCJESup->Draw("histo,same");
1148 +  datahisto->Draw("e1,same");
1149 +  legsmall->Draw();
1150 +  CompleteSave(ckin,saveas+"___AllLines");
1151 +  
1152 +  delete datahisto;
1153 +  delete MCcentral;
1154 +  delete MCPUdn;
1155 +  delete MCPUup;
1156 +  delete MCJESdn;
1157 +  delete MCJESup;
1158 +  delete ckin;
1159 + }
1160  
1161 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1162 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1163 + }
1164 +  
1165   float lastrange_min=0;
1166   float lastrange_max=0;
1167  
# Line 688 | Line 1312 | void make_kin_plot(string variable, stri
1312          DrawPrelim();
1313          string saveas="kin/"+filename;
1314          if(isPF) saveas="kin/"+filename+"__PF";
1315 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1315 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1316   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
1317   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
1318   //      delete with_ratio;
# Line 751 | Line 1375 | void make_plain_kin_plot(string variable
1375          DrawPrelim();
1376          string saveas="kin/"+filename;
1377          if(isPF) saveas="kin/"+filename+"__PF";
1378 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1378 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1379    } else {
1380          if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
1381          else CompleteSave(ckin,"kin/"+filename);
# Line 803 | Line 1427 | void make_JES_plot(TCut cut, string name
1427    CompleteSave(ckin,"Systematics/JES"+name);
1428    datahisto->Delete();
1429    delete ckin;
1430 <
1430 >  delete JESunc;
1431 >  delete JESup;
1432 >  delete JESdn;
1433 >  CleanLegends();
1434   }
1435  
1436   string Cut2Str(TCut cut) {
# Line 822 | Line 1449 | void MakeElegantTwoThreeComparisons() {
1449      string xlabel="m_{ll} [GeV]";
1450      
1451      TCanvas *can2 = new TCanvas("can2","can2");
1452 <    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1453 <    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1454 <    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1455 <    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1452 >    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1453 >    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1454 >    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1455 >    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1456      
1457      can2->cd(1);
1458      
# Line 843 | Line 1470 | void MakeElegantTwoThreeComparisons() {
1470      leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1471      leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1472      leg_SFOF_Two->Draw();
1473 <    save_with_ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1473 >    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1474      
1475      TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1476      kin4->cd();
# Line 854 | Line 1481 | void MakeElegantTwoThreeComparisons() {
1481      leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1482      leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1483      leg_SFOF_Three->Draw();
1484 <    save_with_ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1484 >    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1485      
1486      
1487      TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
# Line 867 | Line 1494 | void MakeElegantTwoThreeComparisons() {
1494      leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1495      leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1496      leg_SF_Two_Three->Draw();
1497 <    save_with_ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1497 >    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1498      
1499      TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1500      TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
# Line 879 | Line 1506 | void MakeElegantTwoThreeComparisons() {
1506      leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1507      leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1508      leg_OF_Two_Three->Draw();
1509 <    save_with_ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1509 >    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1510 >    
1511 > }
1512 >
1513 > void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1514 >  pad->cd();
1515 >  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1516 >  for(int i=1;i<=Down->GetNbinsX();i++) {
1517 >    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1518 >    float error=abs(Down->GetBinContent(i)-average);
1519 >    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1520 >    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1521 >  }
1522 >  gr->SetFillColor(TColor::GetColor("#F79F81"));
1523 >  gr->GetYaxis()->SetRangeUser(0,2);
1524 >  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1525 >  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1526 >  gr->GetXaxis()->CenterTitle();
1527 >  gr->GetYaxis()->CenterTitle();
1528 >  
1529 >  gr->Draw("A2");
1530 >  central->Draw("e1,same");
1531 >  DrawMCPrelim();
1532 >  TText *rtitle = write_text(0.8,0.8,title);
1533 >  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1534 >  line->SetLineColor(kBlue);
1535 >  line->SetLineStyle(2);
1536 >  line->Draw("same");
1537 >  rtitle->Draw("same");
1538 > }
1539 >
1540 > TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1541 >  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1542 >  basehisto->Add(originalttbar,-1);
1543 >  basehisto->Add(httbar);
1544 >  
1545 >  string sname=httbar->GetName();
1546 >  sname="R"+sname.substr(1,sname.length());
1547 >  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1548 >  ratio->Divide(basehisto);
1549 >  delete basehisto;
1550 >  return ratio;
1551 > }
1552 >  
1553 > void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1554 >  
1555 >  TCut cut=addcut&&basiccut;
1556 >  
1557 >  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1558 >  ckin->SetLogy(dolog);
1559 >  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1560 >  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1561 >  datahisto->SetMarkerSize(DataMarkerSize);
1562 >  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1563 >  else datahisto->SetMinimum(0.5);
1564 >  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1565 >  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1566 >  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1567 >  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1568 >  TH1F *MCcentral = CollapseStack(mcstack);
1569 >
1570 >  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1571 >  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("/TT_"));
1572 >  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1573 >  
1574 >  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1575 >  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1576 >  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1577 >  
1578 >  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1579 >  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1580 >  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1581 >  
1582 >  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1583 >  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1584 >  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1585 >  
1586 >  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1587 >  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1588 >  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1589 >  
1590 >  datahisto->Draw("e1");
1591 >  ckin->Update();
1592 >  mcstack.Draw("histo,same");
1593 >  
1594 >  datahisto->Draw("same,e1");
1595 >  TLegend *kinleg = allsamples.allbglegend();
1596 >  kinleg->Draw();
1597 >
1598 >  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1599 >  kinpad->SetLogy(dolog);
1600 >  kinpad->cd();
1601 >  datahisto->Draw("e1");
1602 >  mcstack.Draw("histo,same");
1603 >  datahisto->Draw("same,e1");
1604 >  datahisto->Draw("same,axis");
1605 >  
1606 >  kinleg->Draw("same");
1607 >  DrawPrelim();
1608 >  string saveas="kin/"+filename;
1609 >  
1610 >  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1611 >  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1612 >  delete kinpad;
1613 >  
1614 >  ckin->cd();
1615 >  TCentral->SetLineColor(kBlack);
1616 >  
1617 >  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1618 >  TMatchingUp->SetLineStyle(2);//dashed
1619 >  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1620 >  TMatchingDown->SetLineStyle(3);//dotted
1621 >  
1622 >  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1623 >  TScaleUp->SetLineStyle(2);//dashed
1624 >  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1625 >  TScaleDown->SetLineStyle(3);//dotted
1626 >  
1627 >  MCcentral->SetLineStyle(3);
1628 >  MCcentral->SetLineColor(kRed);
1629 >  
1630 >  TCentral->Draw("e1,same");
1631 >  TCentral->Draw("histo,same");
1632 >  TMatchingUp->Draw("histo,same");
1633 >  TMatchingDown->Draw("histo,same");
1634 >  TScaleUp->Draw("histo,same");
1635 >  TScaleDown->Draw("histo,same");
1636 >  
1637 >  TLegend *sleg = make_legend();
1638 >  sleg->AddEntry(TCentral,"Central","L");
1639 >  sleg->AddEntry(TMatchingUp,"matching up","L");
1640 >  sleg->AddEntry(TMatchingDown,"matching down","L");
1641 >  sleg->AddEntry(TScaleUp,"scale up","L");
1642 >  sleg->AddEntry(TScaleDown,"scale down","L");
1643 >  sleg->Draw();
1644 >  
1645 >  CompleteSave(ckin,saveas+"___AllLines");
1646 >  ckin->cd();
1647 >  ckin->SetLogy(0);
1648 >  
1649 >  RCentral->SetLineColor(kBlack);
1650 >  
1651 >  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1652 >  RMatchingUp->SetLineStyle(2);//dashed
1653 >  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1654 >  RMatchingDown->SetLineStyle(3);//dotted
1655 >  
1656 >  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1657 >  RScaleUp->SetLineStyle(2);//dashed
1658 >  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1659 >  RScaleDown->SetLineStyle(3);//dotted
1660 >  
1661 >  RCentral->GetYaxis()->SetRangeUser(0,2);
1662 >  RCentral->Draw("e1");
1663 >  RMatchingUp->Draw("histo,same");
1664 >  RMatchingDown->Draw("histo,same");
1665 >  RScaleUp->Draw("histo,same");
1666 >  RScaleDown->Draw("histo,same");
1667 >  
1668 >  CompleteSave(ckin,saveas+"___AllRatios");
1669 >
1670 >  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1671 >  multicanvas->Divide(2,1);
1672 >  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1673 >  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1674 >  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1675 >  
1676 >  
1677 >  delete datahisto;
1678 >  delete   TCentral;
1679 >  delete   TMatchingUp;
1680 >  delete   TMatchingDown;
1681 >  delete   TScaleUp;
1682 >  delete   TScaleDown;
1683 > //   delete   Ttmass166;
1684 > //   delete   Ttmass169;
1685 > //   delete   Ttmass175;
1686 > //   delete   Ttmass178;
1687 >  
1688 >  delete ckin;
1689 >  
1690 > }
1691 >  
1692 > void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1693 >  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1694 > }
1695 >
1696 > void ProduceJanPlots() {
1697 >  TCanvas *c1 = new TCanvas("c1","c1");
1698 >  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1699 >  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1700 >  
1701 >  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1702 >  rcan->cd();
1703 >
1704 >  metOF->SetLineColor(kRed);
1705 >  metSF->Draw("e1");
1706 >  metOF->Draw("histo,same");
1707 >  metSF->Draw("e1,same");
1708 >  
1709 >  TLegend *leg = make_legend();
1710 >  
1711 >  leg->AddEntry(metSF,"Data SF","p");
1712 >  leg->AddEntry(metOF,"Data OF","l");
1713 >  leg->Draw();
1714 >  
1715 >  DrawPrelim();
1716 >  
1717 >  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1718 >  
1719 >  delete rcan;
1720 >  delete metSF;
1721 >  delete metOF;
1722 >  delete c1;
1723 > }
1724 >
1725 > THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1726 >  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1727 >  
1728 >  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1729 >  if(variation!="Central") {
1730 >    TH1F *varttbar;
1731 >    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1732 >    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1733 >    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1734 >    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1735 >    assert(varttbar);
1736 >    
1737 >    TIter nextHisto(SystPlot.GetHists());
1738 >    TH1F* h;
1739 >    while ( h = (TH1F*)nextHisto() ) {
1740 >      if(Contains(h->GetName(),"t_bar_t")) {
1741 >        varttbar->Scale(h->Integral()/varttbar->Integral());
1742 >        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1743 >          h->SetBinContent(i,varttbar->GetBinContent(i));
1744 >          h->SetBinError(i,varttbar->GetBinError(i));
1745 >        }
1746 >        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1747 >        SystPlot.Modified();
1748 >      }
1749 >    }
1750 >    delete varttbar;
1751 >  } else {
1752 >    TIter nextHisto(SystPlot.GetHists());
1753 >    TH1F* h;
1754 >    while ( h = (TH1F*)nextHisto() ) {
1755 >      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1756 >    }
1757 >  }
1758      
1759 +  TLegend *fullleg = allsamples.allbglegend();
1760 +  fullleg->SetHeader(variation.c_str());
1761 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1762 +  kinpad->SetLogy(1);
1763 +  kinpad->cd();
1764 +  
1765 +  hdata->Draw("e1");
1766 +  SystPlot.Draw("histo,same");
1767 +  hdata->Draw("e1,same");
1768 +  fullleg->Draw();
1769 +  DrawPrelim();
1770 +  
1771 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1772 +  CleanLegends();
1773 +  
1774 +  delete kinpad;
1775 +  return SystPlot;
1776   }
1777 +  
1778  
1779  
1780 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1781 +  TCanvas *ca = new TCanvas("ca","ca");
1782 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1783 +  
1784 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1785 +  
1786 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1787 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1788 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1789 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1790 +  
1791 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1792 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1793 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1794 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1795 +  
1796 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1797 +  TH1F *HCentral = CollapseStack(Central);
1798 +  
1799 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1800 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1801 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1802 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1803 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1804 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1805 +    
1806 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1807 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1808 +    
1809 +    float sys=sqrt(matching*matching+scale*scale);
1810 +    sys/=HCentral->GetBinContent(i);
1811 +    if(HCentral->GetBinContent(i)==0) sys=0;
1812 +    Systematic->SetBinContent(i,sys);
1813 +  }
1814 +  
1815 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1816 +  kinpad->SetLogy(1);
1817 +  kinpad->cd();
1818 +  if(variable=="genMET") {
1819 +    Central.Draw("histo");
1820 +  } else {
1821 +    hdata->Draw("e1");
1822 +    Central.Draw("histo,same");
1823 +    hdata->Draw("e1,same");
1824 +  }
1825 +  
1826 +  DrawPrelim();
1827 +  
1828 +  save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1829 +  
1830 +  kinpad->cd();
1831 +  tCentral->SetFillColor(kWhite);
1832 +  tCentral->SetLineColor(kBlack);
1833 +  tScaleUp->SetLineColor(kRed);
1834 +  tScaleDown->SetLineColor(kRed);
1835 +  tMatchingUp->SetLineColor(kBlue);
1836 +  tMatchingDown->SetLineColor(kBlue);
1837 +  tScaleUp->SetLineStyle(2);
1838 +  tScaleDown->SetLineStyle(3);
1839 +  tMatchingUp->SetLineStyle(2);
1840 +  tMatchingDown->SetLineStyle(3);
1841 +  
1842 +  TLegend *leg2 = make_legend();
1843 +  leg2->AddEntry(hdata,"Data","p");
1844 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1845 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1846 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1847 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1848 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1849 +  if(variable=="genMET") {
1850 +    Central.Draw("histo");
1851 +  }else {
1852 +    hdata->Draw("e1");
1853 +    Central.Draw("histo,same");
1854 +    hdata->Draw("e1,same");
1855 +  }
1856 +  tCentral->Draw("histo,same");
1857 +  tScaleUp->Draw("histo,same");
1858 +  tScaleDown->Draw("histo,same");
1859 +  tMatchingUp->Draw("histo,same");
1860 +  tMatchingDown->Draw("histo,same");
1861 +  leg2->Draw();
1862 +  
1863 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1864 +  
1865 +  gStyle->SetOptFit(0);
1866 +  
1867 +  kinpad->cd();
1868 +  kinpad->SetLogy(0);
1869 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1870 +  MatchingRatio->Divide(tMatchingDown);
1871 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1872 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1873 +  lone->SetLineStyle(2);
1874 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1875 +  ScaleRatio->Divide(tScaleDown);
1876 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1877 +  MatchingRatio->Draw("e1");
1878 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1879 +  MatchingRatio->Fit("QP1","R");
1880 +  lone->Draw();
1881 +  stringstream summary;
1882 +  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);
1883 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1884 +  TText *infobox = write_title(summary.str());
1885 +  infobox->SetX(0.75);
1886 +  infobox->SetTextSize(0.03);
1887 +  infobox->SetY(0.75);
1888 +  infobox->Draw();
1889 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1890 +  kinpad->cd();
1891 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1892 +  ScaleRatio->Draw("e1");
1893 +  ScaleRatio->Fit("QP1","R");
1894 +  summary.str("");
1895 +  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);
1896 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1897 +  TText *infobox2 = write_title(summary.str());
1898 +  infobox2->SetX(0.75);
1899 +  infobox2->SetTextSize(0.03);
1900 +  infobox2->SetY(0.75);
1901 +  infobox2->Draw();
1902 +
1903 +  lone->Draw();
1904 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1905 +  
1906 +  
1907 +  delete QP1;
1908 +  delete infobox;
1909 +  delete infobox2;
1910 +  delete MatchingRatio;
1911 +  delete ScaleRatio;
1912 +  DeleteStack(ScaleUp);
1913 +  DeleteStack(ScaleDown);
1914 +  DeleteStack(MatchingUp);
1915 +  DeleteStack(MatchingDown);
1916 +  delete leg2;
1917 +  CleanLegends();
1918 +  DeleteStack(Central);
1919 +  delete Systematic;
1920 +  delete HScaleUp;
1921 +  delete HScaleDown;
1922 +  delete HMatchingUp;
1923 +  delete HMatchingDown;
1924 +  delete hdata;
1925 +  delete HCentral;
1926 +  delete ca;
1927 + }
1928 +
1929 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1930 +  float val=0,err=0;
1931 +  vector<float> bins;
1932 +  vector<float> vals;
1933 +  vector<float> errs;
1934 +  
1935 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1936 +  int iBin=1;
1937 +  
1938 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1939 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1940 +      bins.push_back(histo->GetBinLowEdge(i));
1941 +      vals.push_back(val);val=0;
1942 +      errs.push_back(err);err=0;
1943 +      iBin++;
1944 +    }
1945 +    val+=histo->GetBinContent(i);
1946 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1947 +  }
1948 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1949 +  vals.push_back(val);val=0;
1950 +  errs.push_back(err);err=0;
1951 +  
1952 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1953 +  for(unsigned int i=0;i<vals.size();i++) {
1954 +    h->SetBinContent(i+1,vals[i]);
1955 +    h->SetBinError(i+1,errs[i]);
1956 +  }
1957 +  
1958 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1959 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1960 +  
1961 +  h->GetXaxis()->CenterTitle();
1962 +  h->GetYaxis()->CenterTitle();
1963 +
1964 +  return h;
1965 + }
1966 +
1967 +
1968 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1969 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1970 +  float val=0,err=0;
1971 +  vector<float> bins;
1972 +  vector<float> vals;
1973 +  vector<float> errs;
1974 +  
1975 +  bins.push_back(histo->GetBinLowEdge(1));
1976 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1977 +    val+=histo->GetBinContent(i);
1978 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1979 +    if( val/statsperbin > 0.85) {
1980 +      if(bins.size()<nbins) {
1981 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1982 +        vals.push_back(val);val=0;
1983 +        errs.push_back(err);err=0;
1984 +      }
1985 +    }
1986 +    if(i==histo->GetNbinsX()) {
1987 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1988 +      vals.push_back(val);val=0;
1989 +      errs.push_back(err);err=0;
1990 +    }
1991 +  }
1992 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1993 +  
1994 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1995 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1996 +  
1997 +  h->GetXaxis()->CenterTitle();
1998 +  h->GetYaxis()->CenterTitle();
1999 +  
2000 +  for(unsigned int i=0;i<vals.size();i++) {
2001 +    h->SetBinContent(i+1,vals[i]);
2002 +    h->SetBinError(i+1,errs[i]);
2003 +  }
2004 +  
2005 +  return h;
2006 + }
2007 +
2008 +
2009 +  
2010 + void ShowBinning(TH1F *histo) {
2011 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
2012 +  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;
2013 + }
2014 +  
2015 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
2016 +  TCanvas *ca = new TCanvas("ca","ca");
2017 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
2018 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
2019 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
2020 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
2021 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
2022 +  
2023 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
2024 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
2025 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
2026 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
2027 +  tCentral->Scale(1.0/tCentral->Integral());
2028 +  
2029 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
2030 +  
2031 +  
2032 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
2033 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
2034 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
2035 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
2036 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
2037 +  
2038 +  float min=rtScaleUp->GetMinimum();
2039 +  float max=rtScaleUp->GetMaximum();
2040 +  
2041 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
2042 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2043 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2044 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
2045 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
2046 +  
2047 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
2048 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2049 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2050 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
2051 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
2052 +  
2053 +  rtCentral->SetMaximum(1.2*max);
2054 +  rtCentral->SetMinimum(0.8*min);
2055 +  
2056 + /*  tScaleUp->Rebin(40);
2057 +  tScaleDown->Rebin(40);
2058 +  tMatchingDown->Rebin(40);
2059 +  tMatchingUp->Rebin(40);
2060 +  tCentral->Rebin(40);*/
2061 +  
2062 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2063 +  kinpad->SetLogy(1);
2064 +  kinpad->cd();
2065 +  tCentral->SetFillColor(kWhite);
2066 +  tCentral->SetLineColor(kBlack);
2067 +  tScaleUp->SetLineColor(kRed);
2068 +  tScaleDown->SetLineColor(kRed);
2069 +  tMatchingUp->SetLineColor(kBlue);
2070 +  tMatchingDown->SetLineColor(kBlue);
2071 +  tScaleUp->SetLineStyle(2);
2072 +  tScaleDown->SetLineStyle(3);
2073 +  tMatchingUp->SetLineStyle(2);
2074 +  tMatchingDown->SetLineStyle(3);
2075 +  
2076 +  rtScaleDown->SetLineColor(kRed);
2077 +  rtMatchingUp->SetLineColor(kBlue);
2078 +  rtMatchingDown->SetLineColor(kBlue);
2079 +  rtScaleUp->SetLineStyle(2);
2080 +  rtScaleDown->SetLineStyle(3);
2081 +  rtMatchingUp->SetLineStyle(2);
2082 +  rtMatchingDown->SetLineStyle(3);
2083 +  
2084 +  TLegend *leg2 = make_legend();
2085 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
2086 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
2087 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
2088 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
2089 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
2090 +  
2091 +  tCentral->Draw("histo");
2092 +  tScaleUp->Draw("histo,same");
2093 +  tScaleDown->Draw("histo,same");
2094 +  tMatchingUp->Draw("histo,same");
2095 +  tMatchingDown->Draw("histo,same");
2096 +  leg2->Draw();
2097 +  DrawMCPrelim();
2098 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
2099 +  kinpad->cd();
2100 +  kinpad->SetLogy(0);
2101 +  rtCentral->Draw("histo");
2102 +  rtScaleUp->Draw("histo,same");
2103 +  rtScaleDown->Draw("histo,same");
2104 +  rtMatchingUp->Draw("histo,same");
2105 +  rtMatchingDown->Draw("histo,same");
2106 +  leg2->Draw();
2107 +  DrawMCPrelim();
2108 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
2109 +  
2110 +  
2111 +  gStyle->SetOptFit(0);
2112 +
2113 +  kinpad->cd();
2114 +  kinpad->SetLogy(0);
2115 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
2116 +  MatchingRatio->Divide(rtMatchingDown);
2117 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
2118 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
2119 +  lone->SetLineStyle(2);
2120 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
2121 +  ScaleRatio->Divide(rtScaleDown);
2122 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
2123 +  MatchingRatio->Draw("e1");
2124 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
2125 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
2126 +  lone->Draw();
2127 +  stringstream summary;
2128 +  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);
2129 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2130 +  TText *infobox = write_title(summary.str());
2131 +  infobox->SetX(0.75);
2132 +  infobox->SetTextSize(0.03);
2133 +  infobox->SetY(0.75);
2134 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
2135 +  DrawMCPrelim();
2136 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
2137 +  kinpad->cd();
2138 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
2139 +  ScaleRatio->Draw("e1");
2140 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
2141 +  summary.str("");
2142 +  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);
2143 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2144 +  TText *infobox2 = write_title(summary.str());
2145 +  infobox2->SetX(0.75);
2146 +  infobox2->SetTextSize(0.03);
2147 +  infobox2->SetY(0.75);
2148 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
2149 +
2150 +  lone->Draw();
2151 +  DrawMCPrelim();
2152 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
2153 +  
2154 +  kinpad->cd();
2155 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
2156 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
2157 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
2158 +  
2159 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
2160 +    float matching, scale;
2161 +    bool AssumeFactor=false;
2162 +    if(AssumeFactor) {
2163 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
2164 +      matching=0.;
2165 +      scale=0.;
2166 +    } else {
2167 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
2168 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
2169 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
2170 +    }
2171 +    
2172 +    SysMatching->SetBinContent(i,1+matching);
2173 +    SysScale->SetBinContent(i,1+scale);
2174 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
2175 +  }
2176 +  
2177 +  SysHisto->SetLineColor(kGreen);
2178 +  
2179 +  SysMatching->SetMaximum(3.0);
2180 +  SysMatching->SetMinimum(0.0);
2181 +  SysMatching->Draw("histo");
2182 +  SysScale->Draw("histo,same");
2183 +  SysHisto->Draw("histo,same");
2184 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
2185 +  
2186 +  delete SysMatching;
2187 +  delete SysScale;
2188 +  
2189 +  if(!Contains(variable,"gen")) {
2190 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
2191 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
2192 +    
2193 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
2194 +    
2195 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
2196 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
2197 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
2198 +      float sys = SysHisto->GetBinContent(iBin)-1;
2199 +      Systematic->SetBinContent(i,sys);
2200 +    }
2201 +    
2202 +    kinpad->cd();
2203 +    TLegend *leg = allsamples.allbglegend();
2204 +    hdata->Draw();
2205 +    smc.Draw("histo,same");
2206 +    hdata->Draw("same");
2207 +    leg->Draw();
2208 +    DrawPrelim();
2209 +    save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
2210 +    
2211 +    delete Systematic;
2212 +    delete hdata;
2213 +  }
2214 +  
2215 +  
2216 +  delete SysHisto;
2217 +  delete tScaleUp;
2218 +  delete tScaleDown;
2219 +  delete tCentral;
2220 +  delete tMatchingUp;
2221 +  delete tMatchingDown;
2222 +  delete rtScaleUp;
2223 +  delete rtScaleDown;
2224 +  delete rtCentral;
2225 +  delete rtMatchingUp;
2226 +  delete rtMatchingDown;
2227 +  delete QP1;
2228 +  delete infobox;
2229 +  delete infobox2;
2230 +  delete MatchingRatio;
2231 +  delete ScaleRatio;
2232 +  delete leg2;
2233 +  CleanLegends();
2234 +  delete ca;
2235 + }
2236 +
2237 + void ProduceMCSystematicPlots() {
2238 +  cout << "Getting ready to produce systematic plots " << endl;
2239 +  TCut cutweightBKP = cutWeight;
2240 +  
2241 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
2242 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
2243 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
2244 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
2245 +  
2246 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
2247 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
2248 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
2249 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
2250 +  
2251 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
2252 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
2253 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
2254 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
2255 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
2256 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
2257 +  
2258 +  
2259 +  
2260 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2261 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2262 +  cutWeight="1.0";
2263 +  
2264 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2265 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
2266 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2267 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2268 +  
2269 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2270 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
2271 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2272 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2273 +  
2274 +  
2275 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
2276 +  
2277 +  /*
2278 +  cutWeight=cutweightBKP;
2279 +  TCut essentialcutBKP = essentialcut;
2280 +  cout << (const char*) essentialcut << endl;
2281 +  
2282 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
2283 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2284 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2285 +  
2286 +  TCut cutnJetsBKP = cutnJets;
2287 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
2288 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
2289 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2290 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2291 +  
2292 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
2293 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
2294 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
2295 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
2296 +  
2297 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
2298 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
2299 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2300 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
2301 +  
2302 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
2303 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
2304 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2305 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
2306 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
2307 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
2308 +  
2309 +  
2310 +  
2311 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2312 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2313 +  cutWeight="1.0";
2314 +  
2315 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2316 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
2317 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2318 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2319 +  
2320 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2321 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
2322 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2323 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2324 +  
2325 +  cutnJets  = cutnJetsBKP;
2326 +  cutWeight = cutweightBKP;
2327 +  essentialcut = essentialcutBKP;
2328 +  */
2329 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
2330 + }
2331 +
2332 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
2333 +  TCut cut=pcut&&basiccut;
2334 +  string variable="mll";
2335 +  string xlabel="m_{ll} [GeV]";
2336 +  int nbins=40;
2337 +  float min=0;
2338 +  float max=200;
2339 +
2340 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
2341 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
2342 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
2343 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2344 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2345 +  datahistoSF->SetMarkerSize(DataMarkerSize);
2346 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
2347 +  datahistoOF->SetMarkerSize(DataMarkerSize);
2348 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
2349 +
2350 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
2351 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
2352 +  datahistoSF->Draw("e1");
2353 +  ckin->Update();
2354 +  mcstackSF.Draw("histo,same");
2355 +  
2356 +  datahistoSF->Draw("same,e1");
2357 +  TLegend *kinleg = allsamples.allbglegend();
2358 +  kinleg->Draw();
2359 +  
2360 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2361 +  kinpad->cd();
2362 +  datahistoSF->Draw("e1");
2363 +  mcstackSF.Draw("histo,same");
2364 +  datahistoSF->Draw("same,e1");
2365 +  datahistoSF->Draw("same,axis");
2366 +  kinleg->Draw();
2367 +  DrawPrelim();
2368 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
2369 +  
2370 +  kinpad->cd();
2371 +  datahistoOF->Draw("e1");
2372 +  mcstackOF.Draw("histo,same");
2373 +  datahistoOF->Draw("same,e1");
2374 +  datahistoOF->Draw("same,axis");
2375 +  kinleg->Draw();
2376 +  DrawPrelim();
2377 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
2378 +  
2379 +  kinpad->cd();
2380 +  tauSF->Draw("e1");
2381 +  tauOF->Draw("histo,same");
2382 +  tauSF->Draw("e1,same");
2383 +  TLegend *legtau = make_legend();
2384 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
2385 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
2386 +  legtau->Draw();
2387 +  DrawPrelim();
2388 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
2389 +  
2390 +  delete datahistoSF;
2391 +  delete datahistoOF;
2392 +  delete tauSF;
2393 +  delete tauOF;
2394 +  delete kinpad;
2395 +  delete ckin;
2396 +  CleanLegends();
2397 + }
2398 +  
2399 +
2400 + void TauQuestion() {
2401 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2402 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2403 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2404 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2405 + }
2406 +
2407 + void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2408 +  string BaseMetCut="met[4]>100";
2409 +  string Prefix="ETH/";
2410 +  if(isAachen) {
2411 +    BaseMetCut="met[4]>150";
2412 +    Prefix="Aachen/";
2413 +  }
2414 + //        make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "S_{T}", Prefix+"FrankT");
2415 +      make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2416 +
2417 +      make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2418 +      make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2419 +      make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2420 +  
2421 + //      make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2422 +      make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2423 +      make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2424 +      make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2425 +      
2426 + //      make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2427 + //      make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2428 +
2429 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut,                        7, 3, 10, true, "#(jets)", Prefix+"njets");
2430 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2431 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2432 +
2433 + //      make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 5, -0.5, 4.5, true, "N_{b-jets}", Prefix+"nbjets");
2434 + //      make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2435 + //      make_OFSF_plots("pfJetGoodPt",  BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2436 +
2437 + //      make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2438 + //      make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2439 +      make_OFSF_plots("pt",  BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2440 +      make_OFSF_plots("pt1",  BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2441 +      make_OFSF_plots("pt2",  BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2442 + //      make_OFSF_plots("eta1", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{1}", Prefix+"eta1", 0.15);
2443 + //      make_OFSF_plots("eta2", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{2}", Prefix+"eta2", 0.15);
2444 + //      make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", 0.2);
2445 + //      make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", 0.2);
2446 + //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", 0.2);
2447 + //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", 0.2);
2448 +    
2449 + //      make_OFSF_plots("met[4]",  BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET");
2450 + //      make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", 0.2);
2451 + //      make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", 0.2);
2452 + //      make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", 0.2);
2453 + //      make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2454 + //      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");
2455 + //      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");
2456 + //      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");
2457 +      
2458 + }
2459 +
2460 + void ProduceOFSFPlots(string mcjzb, string datajzb) {
2461 +  
2462 +  
2463 +  //FIRST : ETH SELECTION
2464 +  ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2465 +  
2466 +  
2467 +  
2468 +  string backup_cutnJets = (const char*)cutnJets;
2469 +  cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2470 +  cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2471 +  
2472 +  string backup_basiccut = (const char*)basiccut;
2473 +  basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2474 +  
2475 +  string backup_essential = (const char*) essentialcut;
2476 +  essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2477 +  
2478 +  ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2479 +  
2480 +  cutnJets     = TCut(backup_cutnJets.c_str());
2481 +  basiccut     = TCut(backup_basiccut.c_str());
2482 +  essentialcut = TCut(backup_essential.c_str());
2483 + }
2484 +  
2485 +
2486   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2487   {
2488   //  switch_overunderflow(true);
# Line 891 | Line 2490 | void do_kinematic_plots(string mcjzb, st
2490    bool nolog=false;
2491  
2492    bool doOFSF = false;
2493 <  bool doKin  = true;
2493 >  bool doKin  = false;
2494    bool doDataComp = false;
2495    bool MakeTwoThreeJetComparison = false;
2496    
# Line 905 | Line 2504 | void do_kinematic_plots(string mcjzb, st
2504    }
2505    
2506    if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2507 +  
2508 +  //TauQuestion();
2509  
2510 <  if ( doOFSF ) {
2511 <     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2512 <
2513 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2514 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2515 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
915 <
916 < //      make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
917 < //      make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
918 <
919 < //     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
920 < //     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
921 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
922 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
923 < //     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
924 < //     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
925 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
926 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
927 < //     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
928 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
929 < //    make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
930 < //    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
931 < //    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
932 < //    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");
933 < //    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");
934 < //    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");
935 < //    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");
936 <  }
2510 >  //ProduceJanPlots();
2511 >  //ProduceMCSystematicPlots();
2512 >  //assert(0);
2513 > //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2514 >  
2515 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2516  
2517    if ( doDataComp) {
2518      TCut mllCut("");
# Line 949 | Line 2528 | void do_kinematic_plots(string mcjzb, st
2528  
2529      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2530      
2531 < /*    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2531 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2532      make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2533      
2534      
# Line 960 | Line 2539 | void do_kinematic_plots(string mcjzb, st
2539      make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2540      
2541      make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2542 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2542 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2543      make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2544 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2545 < */
2544 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2545 >
2546    
2547      string basiccutsaved = (const char*)basiccut;
2548      
# Line 975 | Line 2554 | void do_kinematic_plots(string mcjzb, st
2554        newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2555        found = newbasiccut.find( "pt2>20" );
2556      }
2557 < //    basiccut=TCut(newbasiccut.c_str());
2558 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2559 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2560 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2561 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2562 < //    basiccut=TCut(basiccutsaved.c_str());
2563 <    
2564 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2565 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2566 <    
2567 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2568 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2569 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2570 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2571 <
2572 <    
2573 < /*     make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2574 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2575 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2576 <     make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2557 >    basiccut=TCut(newbasiccut.c_str());
2558 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2559 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2560 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2561 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2562 >    basiccut=TCut(basiccutsaved.c_str());
2563 >    
2564 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2565 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2566 >    
2567 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2568 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2569 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2570 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2571 >
2572 >    
2573 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2574 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2575 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2576 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2577      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2578      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2579      make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2580      make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2581 < */
2581 >
2582      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2583      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2584      
# Line 1012 | Line 2591 | void do_kinematic_plots(string mcjzb, st
2591      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2592      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2593  
2594 < /*
2594 >
2595      make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2596      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");
2597      make_data_comparison_plot("mll", cutmass&&cutOSOF&&"met[4]>100&&met[4]<150&&pfJetGoodNum40==2", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_CR");
# Line 1021 | Line 2600 | void do_kinematic_plots(string mcjzb, st
2600      make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2601      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2602      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2603 <  */
2603 >
2604    }
2605  
2606  
2607    if ( doKin ) {
2608      string mllCut("");
2609 < /*  
2609 >    /*
2610 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2611 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2612 >
2613 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2614 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2615 >
2616 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2617 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2618 >    
2619 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2620 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2621 >    
2622 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2623 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2624 >    
2625 >    make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2626 >    make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2627 >    
2628 >    make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2629 >    make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2630 >    
2631 >    
2632 >    assert(0);
2633 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2634 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2635 >  
2636      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);
2637      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);
2638      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);
# Line 1037 | Line 2642 | void do_kinematic_plots(string mcjzb, st
2642      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);
2643      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);
2644      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);
2645 < */
2646 <    
2645 >
2646 >
2647 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2648 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2649 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2650 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2651 >
2652      
2653      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);
2654      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);
# Line 1050 | Line 2660 | void do_kinematic_plots(string mcjzb, st
2660      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);
2661      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);
2662  
2663 <     /*make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2664 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
1055 <    
1056 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
1057 <     make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);*/
2663 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2664 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2665      
2666 < /*     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);
2667 <     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);
2666 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2667 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2668      
2669 <     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);
2670 <     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);
1064 < */
1065 <    write_info(__FUNCTION__,"Last plot");
2669 >    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);
2670 >    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);
2671      
2672 +    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);
2673 +    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);
2674 +
2675      
2676 +    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2677 +    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2678 +    // Plots in signal region
2679 +    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2680 +
2681 +
2682 +    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2683      
2684 +    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");
2685 +    /*
2686 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2687 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2688 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2689 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2690 +
2691 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2692 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2693 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2694 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2695 +
2696 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2697 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2698 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2699 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2700 +
2701 +    
2702 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2703 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2704 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2705 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2706 +
2707 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2708 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2709 +
2710 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2711 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2712      
2713 <    
2714 <    
2715 <    
2716 <    
2717 <     return;
2718 <    
2719 <    
2720 <    
2721 <     make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2722 <     make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2723 <    // Plots in signal region
2724 < //     make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2725 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2726 <     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);
2727 <     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);
2728 <     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);
2729 <    
1087 <     make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
1088 <     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
1089 <    
1090 < //     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);
1091 < //     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);
1092 < //     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);
1093 < //     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);
2713 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2714 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2715 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2716 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2717 >
2718 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2719 >    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);
2720 >    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);
2721 >    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);
2722 >    
2723 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2724 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2725 >    
2726 >    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);
2727 >    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);
2728 >    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);
2729 >    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);
2730      
2731      
2732 < //     make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2733 < //     make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2732 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2733 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2734  
2735      // Further inclusive invariant mass plots
2736      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2737 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2738 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2737 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2738 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2739      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2740      
2741 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2741 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2742      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2743      
2744      
2745      // Number of jets
2746      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2747      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2748 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2748 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2749      
2750      // Others
2751      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 1141 | Line 2777 | void do_kinematic_plots(string mcjzb, st
2777      
2778      //   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);
2779      //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);
2780 <    //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);
2780 >    //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);*/
2781    }
2782      
2783 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2784 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2785 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2786 <   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2787 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2788 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2789 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2790 <
2791 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2792 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2793 <
2783 >   int jzbcuts[7]={0,50,80,100,150,200,250};
2784 >   int MCorData[2]={data,mc};
2785 >  
2786 >   write_warning(__FUNCTION__,"Skipping data altogether");
2787 >   for(int d=1;d<2;d++) {
2788 >     for(int j=0;j<7;j++) {
2789 >       make_special_obs_pred_mll_plot(datajzb,mcjzb,jzbcuts[j],5.0,MCorData[d]); // 5.0 is the binwidth
2790 >     }
2791 >   }
2792 >  
2793 > /*
2794 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2795 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2796 > */
2797    switch_overunderflow(false);
2798   }
2799  
# Line 1176 | Line 2815 | void make_comp_plot( string var, string
2815    }
2816    
2817    string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
2818 +  if(!RestrictToMassPeak) {
2819 +    sRegions[0]="SF";
2820 +    sRegions[1]="OF";
2821 +  }
2822    TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass,     cutOSOF&&cutnJets&&cutmass,
2823                        cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
2824    
# Line 1238 | Line 2881 | void region_comparison_plots(string mcjz
2881      make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2882  
2883      make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2884 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2884 >    make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2885      make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2886      make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2887      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
# Line 1270 | Line 2913 | void signal_bg_comparison()
2913    
2914    float simulatedlumi=luminosity;//in pb please - adjust to your likings
2915    
2916 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
2916 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2917    TH1F *JZBplotLM4;
2918    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"));
2919    else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2920 <  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
2920 >  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TT_"));
2921    
2922    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
2923    JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
# Line 1285 | Line 2928 | void signal_bg_comparison()
2928  
2929    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2930    JZBplotTtbar->SetMinimum(0.01);
2931 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2931 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2932    JZBplotTtbar->DrawClone("histo");
2933    JZBplotZJETs->Draw("histo,same");
2934    JZBplotTtbar->SetFillColor(0);
2935    JZBplotTtbar->DrawClone("histo,same");
2936 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2936 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2937    JZBplotLM4->Draw("histo,same");
2938  
2939  
# Line 1328 | Line 2971 | void signal_bg_comparison()
2971    // Draw all plots overlaid
2972    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2973    JZBplotTtbar->SetMinimum(0.01);
2974 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2974 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2975    JZBplotTtbar->DrawClone("histo");
2976    JZBplotZJETs->Draw("histo,same");
2977    JZBplotTtbar->SetFillColor(0);
2978    JZBplotTtbar->DrawClone("histo,same");
2979 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2979 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2980  
2981    JZBplotSMS1->SetLineColor(kRed+1);
2982    JZBplotSMS2->SetLineColor(kBlue+1);
# Line 1540 | Line 3183 | if you want to start from scratch (witho
3183    return return_functions;
3184   }
3185  
3186 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3186 > void do_prediction_plot(TCut addcut, string Cname, string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3187   {
3188    
3189    bool is_data=false;
# Line 1561 | Line 3204 | void do_prediction_plot(string jzb, TCan
3204    
3205    
3206    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3207 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3208 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3209 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3210 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3207 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3208 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3209 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3210 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3211  
3212    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3213    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1580 | Line 3223 | void do_prediction_plot(string jzb, TCan
3223    TH1F *RcorrJZBeemmNoS;
3224  
3225    //these are for the ratio
3226 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3227 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3228 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3229 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3226 >  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);
3227 >  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);
3228 >  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);
3229 >  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);
3230    
3231    TH1F *JRcorrJZBSBem;
3232    TH1F *JLcorrJZBSBem;
3233    TH1F *JRcorrJZBSBeemm;
3234    TH1F *JLcorrJZBSBeemm;
3235    
3236 <  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);
3236 >  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);
3237  
3238    
3239    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3240 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3241 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3242 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3243 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3240 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3241 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3242 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3243 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3244      
3245      //these are for the ratio
3246 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3247 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3248 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3249 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3246 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3247 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3248 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3249 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3250    }
3251    
3252    TH1F *lm4RcorrJZBeemm;
3253 <  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"));
3253 >  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"));
3254    
3255    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3256    
# Line 1744 | Line 3387 | void do_prediction_plot(string jzb, TCan
3387      
3388      jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3389      jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3390 <    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3391 <    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3390 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3391 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3392      
3393      THStack predcomposition("predcomposition","prediction composition");
3394      predcomposition.Add(sidebandsemu);
# Line 1771 | Line 3414 | void do_prediction_plot(string jzb, TCan
3414   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3415   //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3416      speciallegBpred->Draw();
3417 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3417 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition"+Cname,true,true,"data/pred",BpredSys);
3418 >    delete predcomppad;
3419      
3420      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3421      specialcanv->SetLogy(1);
# Line 1837 | Line 3481 | void do_prediction_plot(string jzb, TCan
3481        
3482        RcorrJZBeemmNoS->SetLineStyle(2);
3483        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3484 < //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3484 >      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3485        legBpred2->Draw();
3486        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3487        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1850 | Line 3494 | void do_prediction_plot(string jzb, TCan
3494    }
3495  
3496  
3497 +  Bpredsaveas+="_"+Cname+"_";
3498    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3499    string ytitle("ratio");
3500    if ( use_data==1 ) ytitle = "data/pred";
3501    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3502 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3502 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3503 >  
3504 >  delete kinpad;
3505  
3506  
3507    
# Line 1896 | Line 3543 | void do_prediction_plot(string jzb, TCan
3543      if(use_data==1)
3544      {
3545        legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3546 <      legBpredc->AddEntry(Bpredem,"OFZP","l");
3547 <      legBpredc->AddEntry(BpredSBem,"OFSB","l");
3548 <      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3546 >      if(RestrictToMassPeak) {
3547 >        legBpredc->AddEntry(Bpredem,"OFZP","l");
3548 >        legBpredc->AddEntry(BpredSBem,"OFSB","l");
3549 >        legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3550 >      } else legBpredc->AddEntry(Bpredem,"OF","l");
3551 >        
3552 >        
3553        legBpredc->Draw();
3554        CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3555      }
3556      if(use_data==0) {
3557        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3558 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3559 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3560 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3558 >      if(RestrictToMassPeak) {
3559 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3560 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3561 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3562 >      } else legBpredc->AddEntry(Bpredem,"MC OF","l");
3563 >        
3564        legBpredc->Draw();
3565        CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3566      }
3567      if(use_data==2) {
3568        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3569 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3570 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3571 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3569 >      if(RestrictToMassPeak) {
3570 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3571 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3572 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3573 >      } else {
3574 >        legBpredc->AddEntry(Bpredem,"MC OF","l");
3575 >      }
3576   //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3577        legBpredc->Draw();
3578        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3579      }
3580    }
3581    
1924  TFile *f = new TFile("tester.root","RECREATE");
1925  RcorrJZBeemm->Write();
1926  Bpred->Write();
1927  f->Close();
1928  
3582    delete RcorrJZBeemm;
3583    delete LcorrJZBeemm;
3584    delete RcorrJZBem;
# Line 1955 | Line 3608 | void do_prediction_plot(string jzb, TCan
3608  
3609   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3610    switch_overunderflow(true);
3611 +  
3612 +  TCut cuts[3] = {TCut("mll>0"),Restrmasscut,TCut("mll>20&&mll<70")};
3613 +  string cutnames[3] = {"NoMassCut","ZWindow","LowMassRegion2070"};
3614 +  
3615    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3616 <  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3617 <  if ( !PlottingSetup::Approved ) {
3618 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3619 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3620 <  } else {
3621 <    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3616 >  for(int i=0;i<3;i++) {
3617 >    do_prediction_plot(cuts[i],cutnames[i],datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3618 >    if ( !PlottingSetup::Approved ) {
3619 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3620 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3621 >    } else {
3622 >      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3623 >    }
3624    }
3625 +  
3626    delete globalcanvas;
3627    switch_overunderflow(false);
3628   }
# Line 1987 | Line 3647 | void lepton_comparison_plots() {
3647    Float_t ymin = 1.e-5, ymax = 0.25;
3648    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3649    can->SetLogy(1);
3650 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
3651 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
3650 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3651 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3652    eemc->SetLineColor(kBlue);
3653    mmmc->SetLineColor(kRed);
3654    eemc->SetMinimum(0.1);
# Line 2051 | Line 3711 | void lepton_comparison_plots() {
3711    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3712    eemmlegend->Draw();
3713    DrawPrelim();
3714 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3714 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3715    
3716 <  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"));
3717 <  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"));
3718 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
3716 >  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"));
3717 >  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"));
3718 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3719    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3720    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3721    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 2174 | Line 3834 | void draw_pure_jzb_histo(TCut cut,string
3834    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3835    writeline1->SetTextSize(0.035);
3836    writeline1->Draw();
3837 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3838 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3837 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3838 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3839    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3840    jzbpad2->cd();
3841    jzbpad2->SetLogy(1);
# Line 2190 | Line 3850 | void draw_pure_jzb_histo(TCut cut,string
3850    writeline1->SetTextSize(0.035);
3851    writeline1->Draw();
3852    DrawPrelim();
3853 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3854 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3853 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3854 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3855    datahisto->Delete();
3856    mcstack.Delete();
3857   }
# Line 2259 | Line 3919 | void diboson_plots(string mcjzb, string
3919    TCanvas *gloca = new TCanvas("gloca","gloca");
3920    
3921    dout << "Going to produce prediction plots" << endl;
3922 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3923 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3922 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3923 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3924    delete gloca;
3925  
3926    dout << "Going to reset the cross section for diboson samples ... " << endl;
# Line 2299 | Line 3959 | void draw_normalized_data_vs_data_histo(
3959    leg->AddEntry(datahisto2,legentry2.c_str());
3960    leg->Draw();
3961    
3962 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3962 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3963    
3964    datahisto1->Delete();
3965    datahisto2->Delete();
# Line 2388 | Line 4048 | string jzb_tex_command(string region, st
4048   //  \SFZPJZBPOS
4049   //  Sample &  \OFZPJZBPOS  & \OFZPJZBNEG &  \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS  & \OFSBJZBNEG  & \SFSBJZBPOS  & \SFSBJZBNEG  \\\hline
4050    
4051 +  
4052 + void compute_Improved_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4053 +  dout << "Calculating background yields in MC:" << endl;
4054 +  
4055 +  TCanvas *yica = new TCanvas("yica","yield canvas");
4056 +  
4057 +  int nRegions=2;
4058 +  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
4059 +  string tsRegions[] = {"SFZP","OFZP"};
4060 +  string posneg[] = {"pos","neg"};
4061 +  TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass};
4062 +
4063 +  
4064 +  
4065 +  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
4066 +    TCut posJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos");
4067 +    TCut negJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg");
4068 +    
4069 +    dout << "_________________________________________________________" << endl;
4070 +    dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
4071 +    
4072 +    
4073 +    THStack *spstack = new THStack(allsamples.DrawStack("spstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4074 +    THStack *snstack = new THStack(allsamples.DrawStack("snstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4075 +    THStack *opstack = new THStack(allsamples.DrawStack("opstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4076 +    THStack *onstack = new THStack(allsamples.DrawStack("onstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4077 +    
4078 +    
4079 +    vector<pair<string,Value> > obs_yields     = WriteYield(spstack, -10, 10, true);
4080 +    vector<pair<string,Value> > neg_sf_yields  = WriteYield(snstack, -10, 10, true);
4081 +    vector<pair<string,Value> > pos_of_yields  = WriteYield(opstack, -10, 10, true);
4082 +    vector<pair<string,Value> > neg_of_yields  = WriteYield(onstack, -10, 10, true);
4083 +    
4084 +    Value TotObs=Value(0,0);
4085 +    Value TotPred=Value(0,0);
4086 +    
4087 +    for(int ientry=0;ientry<obs_yields.size();ientry++) {
4088 +      if(Contains(obs_yields[ientry].first,"t_bar_t")) continue; // ttbar
4089 +      if(Contains(obs_yields[ientry].first,"W_Jets")) continue; // W+Jets
4090 +      if(Contains(obs_yields[ientry].first,"WW_")) continue; // WW (fully flavor symmetric)
4091 +      if(Contains(obs_yields[ientry].first,"Single_top")) continue; // Single Top
4092 +      if(Contains(obs_yields[ientry].first,"ee_mumu")) continue; // DY
4093 +      if(Contains(obs_yields[ientry].first,"tau_tau")) continue; // DY
4094 +      Value pred = neg_sf_yields[ientry].second + pos_of_yields[ientry].second - neg_of_yields[ientry].second;
4095 +      Value obs=obs_yields[ientry].second;
4096 +      Value diff=obs-pred;
4097 +      dout << obs_yields[ientry].first << "\t & \t " << obs << " \t & \t " << pred << "\t & \t " << diff << endl;
4098 +      TotObs=TotObs+obs_yields[ientry].second;
4099 +      TotPred=TotPred+pred;
4100 +    }
4101 +    
4102 +    float Systematic=sqrt(pow(TotPred.getValue(),2)*0.5*0.5 + pow(TotObs.getValue(),2)*0.5*0.5);
4103 +
4104 +        
4105 +  }
4106 +  
4107 +  delete yica;
4108 + }
4109 +      
4110   void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4111    dout << "Calculating background yields in MC:" << endl;
4112    
# Line 2483 | Line 4202 | void draw_ttbar_and_zjets_shape_for_one_
4202    TText *titlecenter;
4203    bool frommc=false;
4204    if(frommc) {
4205 <    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
4205 >    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TT_"));
4206      titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
4207    }
4208    else {
# Line 2702 | Line 4421 | float find_one_correction_factor(string
4421    }
4422    niceresponseplotd->Add(emuResponse,-1);
4423    
4424 +  //TF1 *resp_func = new TF1("resp_func","[0]+[1]/x + [2]/pow(x,2)",10,600);
4425 +  
4426    niceresponseplotd->SetStats(0);
4427    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
4428    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 2711 | Line 4432 | float find_one_correction_factor(string
4432    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
4433    profd->Rebin(2);
4434    profd->SetMarkerSize(DataMarkerSize);
4435 <  profd->Fit("pol0","","same,e1",100,400);
4435 >  //profd->Fit(resp_func,"","same,e1",10,400);
4436 >  profd->Fit("pol2","","same,e1",10,400);
4437 >  //resp_func->SetLineColor(kBlue);
4438    DrawPrelim();
4439    string stitle="Data";
4440    if(!Contains(FindKeyword,"Data")) stitle="MC";
4441    TText* title = write_text(0.5,0.7,stitle.c_str());
4442    title->SetTextAlign(12);
4443    title->Draw();
4444 + //  TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4445    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4446    float correction=datapol->GetParameter(0);
4447 +  
4448 + //  float correction=resp_func->GetParameter(0);
4449    stringstream resstring;
4450    resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
4451    TText* restitle = write_text(0.5,0.65,resstring.str());
# Line 2740 | Line 4466 | void find_correction_factors(string &jzb
4466    float datacorrection=find_one_correction_factor("Data",true,"","Data");
4467    float mccorrection=find_one_correction_factor("DY",false,"","MC");
4468    
4469 <  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4469 > /*  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4470    float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
4471    
4472    float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
4473    float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
4474 <  
4474 >  */
4475    cout << "Corrections : " << endl;
4476    cout << "   Data : " << datacorrection << endl;
4477 <  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4477 > //   cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4478    cout << "   MC : " << mccorrection << endl;
4479 <  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4479 > //   cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4480    
4481    //Step 2: Processing the result and making it into something useful :-)
4482    stringstream jzbvardatas;
4483    jzbvardatas << "(";
4484    
4485 +  /*
4486    if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
4487    if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
4488    
# Line 2769 | Line 4496 | void find_correction_factors(string &jzb
4496    
4497    jzbvardatas << ")";
4498    jzbvardata=jzbvardatas.str();
4499 <  
4499 >  */
4500    stringstream jzbvarmcs;
4501    jzbvarmcs << "(";
4502 <  
4502 >  /*
4503    if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4504    if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4505    
# Line 2786 | Line 4513 | void find_correction_factors(string &jzb
4513    
4514    jzbvarmcs << ")";
4515    jzbvarmc=jzbvarmcs.str();
4516 <
4516 >  */
4517 >  
4518 >  if(datacorrection>=1) jzbvardatas<<"(jzb[1]-" << datacorrection-1 << "*pt)";
4519 >  if(datacorrection<1)  jzbvardatas<<"(jzb[1]+" << 1-datacorrection << "*pt)";
4520 >  
4521 >  if(mccorrection>=1) jzbvarmcs<<"(jzb[1]-" << mccorrection-1 << "*pt)";
4522 >  if(mccorrection<1)  jzbvarmcs<<"(jzb[1]+" << 1-mccorrection << "*pt)";
4523 >  
4524 >  jzbvardata = jzbvardatas.str();
4525 >  jzbvarmc = jzbvarmcs.str();
4526 >  
4527    dout << "JZB Z pt correction summary : " << endl;
4528    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
4529    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
4530    
4531   }
4532  
4533 < void pick_up_events(string cut) {
4534 <  dout << "Picking up events with cut " << cut << endl;
2798 <  allsamples.PickUpEvents(cut);
4533 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
4534 >  allsamples.PickUpEvents(cut,filename,QuietMode);
4535   }
4536  
4537   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2881 | Line 4617 | void draw_all_ttbar_histos(TCanvas *can,
4617    }
4618   }
4619  
4620 < void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
4620 > void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring, TCut cut) {
4621    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4622    //in the case of the OFF peak analysis, we compare our control region to the real value
4623    TCut weightbackup=cutWeight;
4624    switch_overunderflow(true);
4625    
4626 <  bool doPURW=false;
4626 >  bool doPURW=true;
4627    
4628    
4629    if(!doPURW) {
# Line 2907 | Line 4643 | void ttbar_sidebands_comparison(string m
4643        
4644    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4645  
4646 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4647 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4646 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4647 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4648    TH1F *TSem;
4649    TH1F *nTSem;
4650 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4651 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4650 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4651 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4652    TH1F *TSeemm;
4653    TH1F *nTSeemm;
4654    
4655    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4656 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4657 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4658 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4659 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4656 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4657 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4658 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4659 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4660    }
4661  
4662    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 3175 | Line 4911 | void ttbar_sidebands_comparison(string m
4911   //  nicer_binning.push_back(300);
4912   //  nicer_binning.push_back(400);
4913    
4914 <  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4914 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/",TCut("mll>0"));
4915 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/LowMassRegion2070",TCut("mll>20&&mll<70"));
4916 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/ZWindow",Restrmasscut);
4917 >  
4918   }
4919  
4920  
4921   void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4922    cout << "****************************************************************************************************************************************************************" << endl;
4923    TCanvas *zcan = new TCanvas("zcan","zcan");  
3185 //  zcan->SetLogy(1);
4924    TCut weightbackup=cutWeight;
4925    
4926    bool UsePURW=true;
# Line 3208 | Line 4946 | void zjets_prediction_comparison(string
4946    }
4947  
4948    
4949 +  
4950    vector<float> binning;
4951    binning.push_back(0);
4952    binning.push_back(10);
4953 <  binning.push_back(20);
4954 <  binning.push_back(40);
4955 <  binning.push_back(60);
4956 < //   binning.push_back(50);
4953 >  binning.push_back(30);
4954 > //  binning.push_back(40);
4955 > //  binning.push_back(60);
4956 >   binning.push_back(50);
4957   //   binning.push_back(60);
4958   //   binning.push_back(70);
4959   //   binning.push_back(80);
# Line 3225 | Line 4964 | void zjets_prediction_comparison(string
4964    
4965    TCut kPos((mcjzb+">0").c_str());
4966    TCut kNeg((mcjzb+"<0").c_str());
4967 +  TCut reducedNJets(cutnJets);
4968    string var( "abs("+mcjzb+")" );
4969    
4970 <  TCut notTau("abs(genMID1)!=15");
4970 >  
4971 >  TCut notTau("!EventZToTaus");
4972    TCut ee_mm_tautau("mll>0");
4973    
4974 <
4975 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3235 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4974 >  TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4975 >  TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4976    
4977    hJZBpos->SetLineColor(kBlack);
4978    hJZBneg->SetLineColor(kRed);
# Line 3253 | Line 4993 | void zjets_prediction_comparison(string
4993    hratio->Divide(hJZBneg);
4994    
4995    for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
4996 <    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4996 >    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;
4997    }
4998    
4999   //  zcan->SetLogy(0);
# Line 3261 | Line 5001 | void zjets_prediction_comparison(string
5001    hratio->GetYaxis()->SetTitle("Observed/Predicted");
5002    hratio->Draw("e1");
5003    
5004 <  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
5004 >  TLine *top = new TLine(binning[0],1.2,binning[binning.size()-1],1.2);
5005    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5006 <  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
5006 >  TLine *bottom = new TLine(binning[0],0.8,binning[binning.size()-1],0.8);
5007    
5008  
3269  cout << __LINE__ << endl;
5009    top->SetLineColor(kBlue);top->SetLineStyle(2);
5010    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5011    center->SetLineColor(kBlue);
# Line 3282 | Line 5021 | void zjets_prediction_comparison(string
5021    DrawMCPrelim(simulatedlumi);
5022    CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
5023    
5024 <  TCut reducedNJets(cutnJets);
5025 <  
5026 <  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5027 <  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3289 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3290 <  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5024 >  TH1F *TAUhJZBpos       = allsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5025 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5026 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5027 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5028  
3292  cout << __LINE__ << endl;
5029    TH1F *RcorrJZBSBem;
5030    TH1F *LcorrJZBSBem;
5031    TH1F *RcorrJZBSBeemm;
5032    TH1F *LcorrJZBSBeemm;
5033  
3298  cout << __LINE__ << endl;
5034    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5035 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5036 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5037 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5038 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5035 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5036 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5037 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5038 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5039    }
5040    
5041    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3318 | Line 5053 | void zjets_prediction_comparison(string
5053    
5054    Bpred->SetLineColor(kRed);
5055  
3321  cout << __LINE__ << endl;
5056    TAUhJZBpos->SetLineColor(kBlack);
5057    Bpred->SetLineColor(kRed);
5058    
# Line 3338 | Line 5072 | void zjets_prediction_comparison(string
5072    TAUhratio->Divide(Bpred);
5073    
5074    for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
5075 <    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
5075 >    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;
5076 >    
5077 >    
5078    }
5079    
5080    zcan->SetLogy(0);
# Line 3372 | Line 5108 | void zjets_prediction_comparison(string
5108      delete LcorrJZBSBeemm;
5109    }
5110    
5111 +  //***************************************************************************************************
5112 +  
5113 +  string jzbvar=var;
5114 +  /*
5115 +  for(int i=0;i<60;i+=10) {
5116 +    stringstream sSpecialJZBCut;
5117 +    sSpecialJZBCut << jzbvar << ">" << i;
5118 +  TCut SpecialJZBCut(sSpecialJZBCut.str().c_str());
5119 +  
5120 +  var="mll";
5121 +  
5122 +  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"));
5123 +  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"));
5124 +  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"));
5125 +  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"));
5126 +
5127 +  TH1F *RcorrJZBPlusSBem;
5128 +  TH1F *LcorrJZBPlusSBem;
5129 +  TH1F *RcorrJZBPlusSBeemm;
5130 +  TH1F *LcorrJZBPlusSBeemm;
5131 +
5132 +  
5133 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5134 +    RcorrJZBPlusSBem   = allsamples.Draw("RcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5135 +    LcorrJZBPlusSBem   = allsamples.Draw("LcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5136 +    RcorrJZBPlusSBeemm = allsamples.Draw("RcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5137 +    LcorrJZBPlusSBeemm = allsamples.Draw("LcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5138 +  }
5139 +  
5140 +  TH1F *BpredPrime = (TH1F*)LcorrJZBPluseemm->Clone("BpredPrime");
5141 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5142 +    BpredPrime->Add(RcorrJZBPlusem,1.0/3.);
5143 +    BpredPrime->Add(LcorrJZBPlusem,-1.0/3.);
5144 +    BpredPrime->Add(RcorrJZBPlusSBem,1.0/3.);
5145 +    BpredPrime->Add(LcorrJZBPlusSBem,-1.0/3.);
5146 +    BpredPrime->Add(RcorrJZBPlusSBeemm,1.0/3.);
5147 +    BpredPrime->Add(LcorrJZBPlusSBeemm,-1.0/3.);
5148 +  } else {
5149 +    BpredPrime->Add(RcorrJZBPlusem,1.0);
5150 +    BpredPrime->Add(LcorrJZBPlusem,-1.0);
5151 +  }
5152 +  
5153 +  BpredPrime->SetLineColor(kRed);
5154 +
5155 +  FullJZBhJZBpos->SetLineColor(kBlack);
5156 +  BpredPrime->SetLineColor(kRed);
5157 +  
5158 +  FullJZBhJZBpos->SetMinimum(1.0);
5159 +  FullJZBhJZBpos->Draw("e1");
5160 +  BpredPrime->Draw("same,hist");
5161 +  FullJZBhJZBpos->Draw("same,e1");
5162 +  
5163 +  TLegend *FullJZBleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
5164 +  FullJZBleg->AddEntry(FullJZBhJZBpos,"Observed","pe");
5165 +  FullJZBleg->AddEntry(BpredPrime,"Predicted","l");
5166 +  FullJZBleg->Draw("same");
5167 +  DrawMCPrelim(simulatedlumi);
5168 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"_zjets_eemumu_prediction__"+any2string(massregionname));
5169 +  
5170 +  TH1F* FullJZBhratio = (TH1F*)FullJZBhJZBpos->Clone("FullJZBhratio");
5171 +  FullJZBhratio->Divide(BpredPrime);
5172 +  
5173 +  zcan->SetLogy(0);
5174 +  FullJZBhratio->GetYaxis()->SetRangeUser(0,2.5);
5175 +  FullJZBhratio->GetYaxis()->SetTitle("Observed/Predicted");
5176 +  FullJZBhratio->Draw("e1");
5177 +  
5178 +  TLine *atop = new TLine(0,1.2,200,1.2);
5179 +  TLine *acenter = new TLine(0,1.0,200,1.0);
5180 +  TLine *abottom = new TLine(0,0.8,200,0.8);
5181 +  
5182 +  atop->SetLineColor(kBlue);
5183 +  atop->SetLineStyle(2);
5184 +  acenter->SetLineColor(kBlue);
5185 +  abottom->SetLineColor(kBlue);
5186 +  abottom->SetLineStyle(2);
5187 +  
5188 +  atop->Draw("same");
5189 +  acenter->Draw("same");
5190 +  abottom->Draw("same");
5191 +  
5192 +  TLegend *FullJZBleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
5193 +  FullJZBleg2->AddEntry(FullJZBhratio,"obs / pred","pe");
5194 +  FullJZBleg2->AddEntry(abottom,"syst. envelope","l");
5195 +  FullJZBleg2->Draw("same");
5196 +  DrawMCPrelim(simulatedlumi);
5197 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"zjets_eemumu_prediction_ratio"+any2string(massregionname));
5198 +  
5199 +  
5200 +  delete BpredPrime;
5201 +  delete FullJZBhJZBpos;
5202 +  delete LcorrJZBPluseemm;
5203 +  delete RcorrJZBPlusem;
5204 +  delete LcorrJZBPlusem;
5205 + //  delete FullJZBhJZBpos;
5206    
5207 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5208 +    delete RcorrJZBPlusSBem;
5209 +    delete LcorrJZBPlusSBem;
5210 +    delete RcorrJZBPlusSBeemm;
5211 +    delete LcorrJZBPlusSBeemm;
5212 +  }
5213 +  
5214 +  }
5215 +  //***************************************************************************************************
5216 +  */
5217    delete zcan;
5218    cutWeight=weightbackup;
3378
3379  cout << __LINE__ << endl;
5219   }
5220  
5221  
5222   void zjets_prediction_comparison(string mcjzbWithPUa) {
5223 <  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
5224 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
5223 >   zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20"), "nomasscut");
5224 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<10"), "Zwindow_10");
5225    zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
5226 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5226 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)>10&&mll>20"), "Outside_Zwindow_10");
5227 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5228   }
5229    
5230   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
# Line 3494 | Line 5334 | void make_table(samplecollection &coll,
5334   }
5335  
5336   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
5337 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
5338 +  assert(0);
5339    /*we want a table like this:
5340      __________________     50   |   100  | ...
5341      | Data prediction |  a vs b | a vs b | ...
# Line 3727 | Line 5569 | void qcd_plots(string datajzb, string mc
5569    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
5570    string ytitle("ratio");
5571    if ( use_data==1 ) ytitle = "data/pred";
5572 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5572 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5573 >  delete kinpad;
5574    
5575    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
5576    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3898 | Line 5741 | void met_vs_jzb_plots(string datajzb, st
5741    
5742    vector<string> findme;
5743    findme.push_back("DY");
5744 <  findme.push_back("TTJets");
5744 >  findme.push_back("TT_");
5745    findme.push_back("LM");
5746    /*
5747    for(int ifind=0;ifind<(int)findme.size();ifind++) {
# Line 3935 | Line 5778 | void met_vs_jzb_plots(string datajzb, st
5778    sRIGHT << "((" << mcjzb << ")>0)";
5779    TCut RIGHT(sRIGHT.str().c_str());
5780    
5781 <  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5782 <  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5783 <  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5784 <  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5781 >  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5782 >  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5783 >  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5784 >  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5785    
5786    
5787    TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
# Line 3964 | Line 5807 | void met_vs_jzb_plots(string datajzb, st
5807    lg->SetHeader("DY");
5808    
5809    lg->Draw();
5810 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5810 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5811    
5812    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5813    metpad3->cd();
# Line 3982 | Line 5825 | void met_vs_jzb_plots(string datajzb, st
5825  
5826    lg2->Draw();
5827    
5828 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5828 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5829    
5830    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5831    metpad2->cd();
5832    metpad2->SetLogy(1);
5833    
5834 <  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5835 <  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5836 <  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5837 <  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5834 >  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5835 >  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5836 >  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5837 >  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5838    
5839    metlefta->Add(metleftOa,-1);
5840    metrighta->Add(metrightOa,-1);
# Line 4001 | Line 5844 | void met_vs_jzb_plots(string datajzb, st
5844    metlefta->Draw("histo");
5845    metrighta->Draw("same");
5846    lg->Draw();
5847 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5847 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5848    
5849    delete Bpred;
5850    delete obs;
# Line 4010 | Line 5853 | void met_vs_jzb_plots(string datajzb, st
5853    int newNBins=30;
5854    
5855    TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5856 <  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5857 <  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5858 <  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5859 <  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5856 >  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5857 >  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5858 >  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5859 >  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5860    
5861    TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5862    aBpred->Add(AmetleftO,-1);
# Line 4028 | Line 5871 | void met_vs_jzb_plots(string datajzb, st
5871    aobs->Draw("same");
5872    lg->SetHeader("All MC");
5873    lg->Draw();
5874 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5874 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5875    
5876    
5877    delete lg;
# Line 4038 | Line 5881 | void met_vs_jzb_plots(string datajzb, st
5881    delete metright;
5882    delete metrightO;
5883   }
5884 +
5885 +
5886 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5887 +  
5888 +  if(PlottingSetup::RestrictToMassPeak) {
5889 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5890 +    assert(!PlottingSetup::RestrictToMassPeak);
5891 +  }
5892 +  
5893 +  vector<float> binning;
5894 +  
5895 +  binning.push_back(-200);
5896 +  binning.push_back(-150);
5897 +  binning.push_back(-125);
5898 +  binning.push_back(-100);
5899 +  binning.push_back(-75);
5900 +  binning.push_back(-50);
5901 +  binning.push_back(-25);
5902 +  binning.push_back(0);
5903 +  binning.push_back(25);
5904 +  binning.push_back(50);
5905 +  binning.push_back(75);
5906 +  binning.push_back(100);
5907 +  binning.push_back(125);
5908 +  binning.push_back(150);
5909 +  binning.push_back(200);
5910 +  
5911 +  switch_overunderflow(true);
5912 +  
5913 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5914 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5915 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5916 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5917 +  
5918 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5919 +  tcan->SetLogy(1);
5920 +  
5921 +  TZeemm->SetLineColor(kBlack);
5922 +  TZem->SetLineColor(kRed);
5923 +  TZeemm->SetMarkerColor(kBlack);
5924 +  TZem->SetMarkerColor(kRed);
5925 +  
5926 +  vector<TH1F*> histos;
5927 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5928 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5929 +  histos.push_back(TZem);
5930 +  histos.push_back(TZeemm);
5931 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5932 +  
5933 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5934 +  leg->AddEntry(TZeemm,"SFZP","l");
5935 +  leg->AddEntry(TZem,"OFZP","l");
5936 +  leg->Draw("same");
5937 +  DrawMCPrelim();
5938 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5939 +  
5940 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5941 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5942 +  TH1F *TSeemmcopy;
5943 +  TH1F *TSemcopy;
5944 +  
5945 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5946 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5947 +  
5948 +  vector<float> posbinning;
5949 +  for(unsigned int i=0;i<binning.size();i++) {
5950 +    if(binning[i]<0) continue;
5951 +    posbinning.push_back(binning[i]);
5952 +  }
5953 +  
5954 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5955 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5956 +  
5957 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5958 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5959 +    if(TZem->GetBinCenter(i)<0) {
5960 +      //we're on the left: subtract em!
5961 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5962 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5963 +      //we're on the left: add eemm!
5964 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5965 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5966 +    } else {
5967 +      //we're on the right: add em!
5968 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5969 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5970 +      //we're on the left: add eemm!
5971 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5972 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5973 +    }
5974 +  }
5975 +  
5976 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5977 +  ratio2->Divide(obs2);
5978 +
5979 +  TZem->Divide(TZeemm);
5980 +  TZem->SetMarkerStyle(21);
5981 +
5982 +  TZem->SetTitle("OF / SF");
5983 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5984 +  
5985 +  tcan->SetLogy(0);
5986 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
5987 +  TZem->GetYaxis()->SetTitle("ratio");
5988 +  TZem->Draw();
5989 +  
5990 +  float linepos=emuncertOFFPEAK;
5991 +  
5992 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5993 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5994 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5995 +  
5996 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
5997 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5998 +  center->SetLineColor(kBlue);
5999 +  
6000 +  top->Draw("same");
6001 +  center->Draw("same");
6002 +  bottom->Draw("same");
6003 +  
6004 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
6005 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
6006 +  leg2->AddEntry(bottom,"syst. envelope","l");
6007 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
6008 +  leg2->SetY1(0.65);
6009 +  
6010 +  leg2->Draw("same");
6011 +  
6012 +  DrawMCPrelim();
6013 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
6014 +  
6015 +  ratio2->SetLineColor(TZem->GetLineColor());
6016 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
6017 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
6018 +  ratio2->GetYaxis()->SetTitle("ratio");
6019 +  ratio2->Draw();
6020 +  
6021 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
6022 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
6023 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
6024 +  
6025 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
6026 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
6027 +  center2->SetLineColor(kBlue);
6028 +  
6029 +  top2->Draw("same");
6030 +  center2->Draw("same");
6031 +  bottom2->Draw("same");
6032 +  
6033 +  leg2->Draw("same");
6034 +  
6035 +  DrawMCPrelim();
6036 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
6037 +  
6038 +  delete TZem;
6039 +  delete nTZem;
6040 +  delete TZeemm;
6041 +  delete nTZeemm;
6042 +  delete obs2;
6043 +  delete pred2;
6044 +  delete tcan;
6045 +  switch_overunderflow(false);
6046 + }
6047 +
6048 + 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) {
6049      
6050 +  
6051 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
6052 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6053 +  vanilla_ratio->SetFillColor(kGreen);
6054 +  vanilla_ratio->SetLineColor(kGreen);
6055 +  vanilla_ratio->SetMarkerColor(kGreen);
6056 +  vanilla_ratio->SetFillStyle(3001);
6057 +  vanilla_ratio->Draw("e3");
6058 +  
6059 +  response_only_up_ratio->SetFillColor(kRed);
6060 +  response_only_up_ratio->SetMarkerColor(kRed);
6061 +  response_only_up_ratio->SetLineColor(kRed);
6062 +  response_only_up_ratio->SetFillStyle(3003);
6063 +  response_only_up_ratio->Draw("e3,same");
6064 +  
6065 +  response_only_down_ratio->SetFillColor(kOrange);
6066 +  response_only_down_ratio->SetMarkerColor(kOrange);
6067 +  response_only_down_ratio->SetLineColor(kOrange);
6068 +  response_only_down_ratio->SetFillStyle(3004);
6069 +  response_only_down_ratio->Draw("e3,same");
6070 +  
6071 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
6072 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
6073 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
6074 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
6075 +  reponse_plus_peak_up_ratio->Draw("e3,same");
6076 +  
6077 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
6078 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
6079 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
6080 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
6081 +  reponse_plus_peak_down_ratio->Draw("e3,same");
6082 +  
6083 +  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);
6084 +  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);
6085 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
6086 +  
6087 +  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);
6088 +  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);
6089 +  
6090 +  lhiA->SetLineColor(kRed);
6091 +  lhiA->SetLineStyle(2);
6092 +  llowA->SetLineColor(kRed);
6093 +  llowA->SetLineStyle(2);
6094 +  
6095 +  llow->SetLineColor(kBlue);
6096 +  llow->SetLineStyle(2);
6097 +  lhi->SetLineColor(kBlue);
6098 +  lhi->SetLineStyle(2);
6099 +  lOne->SetLineColor(kBlue);
6100 +  
6101 +  llow->Draw();
6102 +  lhi->Draw();
6103 +  lOne->Draw();
6104 +  
6105 +  llowA->Draw();
6106 +  lhiA->Draw();
6107 +  
6108 +  TLegend *leg = make_legend();
6109 +  leg->SetX1(0.15);
6110 +  leg->SetY1(0.7);
6111 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
6112 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
6113 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6114 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6115 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6116 +  leg->AddEntry(lhi,"Systematic envelope","l");
6117 + //  leg->SetNColumns(2);
6118 +  leg->Draw();
6119 +  
6120 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
6121 +  
6122 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6123 +  vanilla_ratio->Draw("e3");
6124 +  response_only_up_ratio->Draw("e3 same");
6125 +  response_only_down_ratio->Draw("e3 same");
6126 +  TLegend *leg2 = make_legend();
6127 +  leg2->SetX1(0.15);
6128 +  leg2->SetY1(0.7);
6129 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
6130 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
6131 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6132 +  leg2->AddEntry(lhi,"Systematic envelope","l");
6133 +  leg2->Draw();
6134 +  llow->Draw();
6135 +  lOne->Draw();
6136 +  llowA->Draw();
6137 +  lhiA->Draw();
6138 +  
6139 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
6140 +  
6141 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6142 +  response_only_up_ratio->Draw("e3");
6143 +  reponse_plus_peak_up_ratio->Draw("e3 same");
6144 +  reponse_plus_peak_down_ratio->Draw("e3 same");
6145 +  TLegend *leg3 = make_legend();
6146 +  leg3->SetX1(0.15);
6147 +  leg3->SetY1(0.7);
6148 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
6149 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6150 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6151 +  leg3->AddEntry(lhi,"Systematic envelope","l");
6152 +  leg3->Draw();
6153 +  llow->Draw();
6154 +  lOne->Draw();
6155 +  llowA->Draw();
6156 +  lhiA->Draw();
6157 +  
6158 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
6159 +  
6160 +  delete ttcan2;
6161 + }
6162 +
6163 + void ttbar_correction_tests() {
6164 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
6165 +    
6166 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
6167 +  
6168 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
6169 +  
6170 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
6171 +  
6172 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
6173 +  
6174 +  string vanilla="jzb[1]";
6175 +  string response_only_up="((jzb[1]+0.034665*pt))";
6176 +  string response_only_down="((jzb[1]-0.034665*pt))";
6177 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
6178 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
6179 +
6180 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
6181 +  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");
6182 +  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");
6183 +  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");
6184 +  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");
6185 +  
6186 +  ttcan->cd();
6187 +  
6188 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
6189 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
6190 +  
6191 +  delete vanilla_observed;
6192 +  delete response_only_up_observed;
6193 +  delete response_only_down_observed;
6194 +  delete reponse_plus_peak_up_observed;
6195 +  delete reponse_plus_peak_down_observed;
6196 +  
6197 +  delete vanilla_predicted;
6198 +  delete response_only_up_predicted;
6199 +  delete response_only_down_predicted;
6200 +  delete reponse_plus_peak_up_predicted;
6201 +  delete reponse_plus_peak_down_predicted;
6202 +  
6203 +  delete vanilla_ratio;
6204 +  delete response_only_up_ratio;
6205 +  delete response_only_down_ratio;
6206 +  delete reponse_plus_peak_up_ratio;
6207 +  delete reponse_plus_peak_down_ratio;
6208 +  
6209 +  delete ttcan;
6210 + }
6211 +
6212 + void ttbar_region_search(string mcjzb) {
6213 +  cout << "Looking for a nice control region" << endl;
6214 +  TCanvas *can = new TCanvas("can","can",1200,1200);
6215 +  can->Divide(2,2);
6216 +  can->cd(1);
6217 +  can->cd(1)->SetLogy(1);
6218 +  
6219 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6220 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6221 +  
6222 +  JZBdistSF.Draw("histo");
6223 +  JZBdistSF.SetMaximum(1000);
6224 +  JZBdistSF.SetMinimum(0.1);
6225 +  JZBdistSF.Draw("histo");
6226 +  DrawMCPrelim();
6227 +  
6228 +  can->cd(2);
6229 +  can->cd(2)->SetLogy(1);
6230 +  JZBdistOF.Draw("histo");
6231 +  JZBdistOF.SetMaximum(1000);
6232 +  JZBdistOF.SetMinimum(0.1);
6233 +  JZBdistOF.Draw("histo");
6234 +  DrawMCPrelim();
6235 +  
6236 +  can->cd(3);
6237 +  
6238 +  
6239 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
6240 +  
6241 +  DrawMCPrelim();
6242 +  
6243 +  /*
6244 +  THStack *Subtracted = new THStack();
6245 +  
6246 +  TIter nextSF(JZBdistSF.GetHists());
6247 +  TIter nextOF(JZBdistOF.GetHists());
6248 +  TObject* SFobj;
6249 +  TObject* OFobj;
6250 +  
6251 +  TH1* sfh = NULL;
6252 +  TH1* ofh = NULL;
6253 +  
6254 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
6255 +    TH1F *sfstart = (TH1*)SFobj->Clone();
6256 +    TH1F *ofstart = (TH1*)OFobj->Clone();
6257 +    TH1F *obs, *pred;
6258 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
6259 +    
6260 +    if ( !hratio ) {
6261 +      hratio = (TH1*)obj->Clone();
6262 +      hratio->SetName("hratio");
6263 +    } else hratio->Add( (TH1*)obj );
6264 +    
6265 +  }
6266 +  hratio->Divide(hdata);
6267 +  */
6268 +  
6269 +  
6270 +  can->cd(4);
6271 +  JZBdistOF.Draw("histo");
6272 +  DrawMCPrelim();
6273 +  
6274 +  
6275 +  
6276 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
6277 +  
6278 +  CleanLegends();
6279 +  delete can;
6280 + }
6281 +
6282 + void ttbar_tests(string mcjzb) {
6283 +  //ttbar_correction_tests();
6284 +  ttbar_region_search(mcjzb);
6285 + }
6286 +
6287 + Value GetYieldBetween(TH1F *h, float low, float high) {
6288 +  float Yield=0;
6289 +  float YieldErr=0;
6290 +  for(int i=1;i<=h->GetNbinsX()+1;i++) {
6291 +    if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
6292 +    if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
6293 +    Yield+=h->GetBinContent(i);
6294 +    YieldErr=sqrt(YieldErr*YieldErr+h->GetBinError(i)*h->GetBinError(i));
6295 +  }
6296 +  
6297 +  Value a(Yield,YieldErr);
6298 +  return a;
6299 + }
6300 +
6301 +
6302 + void make_SF_over_OF_plot(string datajzb, string mcjzb, TCut cut, string variable, int nbins, float xmin, float ymin, string varname, string filename) {
6303 +  TCanvas *SFoOF_can = new TCanvas("SFoOF_can","SFoOF_can");
6304 +  TH1F *data_sf = allsamples.Draw("data_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,data,luminosity);
6305 +  TH1F *data_of = allsamples.Draw("data_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,data,luminosity);
6306 +  
6307 +  TH1F *mc_sf = allsamples.Draw("mc_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6308 +  TH1F *mc_of = allsamples.Draw("mc_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6309 +  
6310 +  TH1F *mc_ratio = (TH1F*)mc_sf->Clone("mc_ratio");
6311 +  mc_ratio->Divide(mc_of);
6312 +  
6313 +  TH1F *data_ratio = (TH1F*)data_sf->Clone("data_ratio");
6314 +  data_ratio->Divide(data_of);
6315 +  
6316 +  mc_ratio->SetFillColor(TColor::GetColor("#00ADE1"));
6317 +  mc_ratio->SetMarkerColor(TColor::GetColor("#00ADE1"));
6318 +  mc_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6319 +  
6320 +  mc_ratio->GetYaxis()->SetTitle("R(SF / OF)");
6321 +  
6322 +  
6323 +  Value R_sf_of_low_mass = GetYieldBetween(data_sf,20,70)/GetYieldBetween(data_of,20,70);
6324 +  Value R_sf_of_high_mass = GetYieldBetween(data_sf,120,200)/GetYieldBetween(data_of,120,200);
6325 +  
6326 +  Value R_sf_of_low_mass_mc = GetYieldBetween(mc_sf,20,70)/GetYieldBetween(mc_of,20,70);
6327 +  Value R_sf_of_high_mass_mc = GetYieldBetween(mc_sf,120,200)/GetYieldBetween(mc_of,120,200);
6328 +  
6329 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6330 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6331 +  
6332 +  TGraphAsymmErrors *gra = produce_ratio_graph(mc_ratio);
6333 +  gra->Draw();
6334 +  mc_ratio->Draw();
6335 +  gra->Draw("e20");
6336 +  gra->SetFillColor(TColor::GetColor("#00ADE1"));
6337 +  gra->SetMarkerColor(TColor::GetColor("#00ADE1"));
6338 +  data_ratio->Draw("e1,same");
6339 +  
6340 +  TLegend *leg = new TLegend(0.17,0.16,0.53,0.31);
6341 + //   leg->SetHeader("R( SF / OF )");
6342 +  leg->SetFillColor(kWhite);
6343 +  leg->SetBorderSize(0);
6344 +  leg->AddEntry(data_ratio,"Data","p");
6345 +  leg->AddEntry(gra,"MC","fp");
6346 +  leg->Draw();
6347 +  
6348 +  TLine *g = new TLine(0,1.01,200,1.01);
6349 +  g->SetLineColor(kBlue);
6350 +  g->Draw();
6351 +  
6352 +  TLine *l = new TLine(70,0.5,70,1.5);
6353 +  l->SetLineStyle(2);
6354 +  l->SetLineColor(TColor::GetColor("#00ADE1"));
6355 +  TLine *m = new TLine(120,0.5,120,1.5);
6356 +  m->SetLineStyle(2);
6357 +  m->SetLineColor(TColor::GetColor("#00ADE1"));
6358 +  l->Draw();
6359 +  m->Draw();
6360 +  
6361 +  
6362 +  DrawPrelim();
6363 +  
6364 +  CompleteSave(SFoOF_can,"iTTbar/"+filename+"SF_vs_OF");
6365 +  
6366 +  delete leg;
6367 +  delete mc_sf;
6368 +  delete mc_of;
6369 +  delete mc_ratio;
6370 +  delete data_sf;
6371 +  delete data_of;
6372 +  delete data_ratio;
6373 +  delete SFoOF_can;
6374 + }  
6375 +
6376 + void make_iTTbar_JZB_plot(string datajzb, string mcjzb, TCut cut) {
6377 +  TCanvas *can = new TCanvas("can","can");
6378 +  vector<float> binning;
6379 +  binning.push_back(-100);
6380 +  binning.push_back(-50);
6381 +  binning.push_back(-20);
6382 +  binning.push_back(0);
6383 + //  binning.push_back(10);
6384 +  binning.push_back(20);
6385 + //  binning.push_back(30);
6386 +  binning.push_back(50);
6387 +  binning.push_back(100);
6388 +  binning.push_back(300);
6389 +  
6390 +  TH1F *hdata   = allsamples.Draw("hdata",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6391 +  TH1F *hodata  = allsamples.Draw("hodata", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6392 +  TH1F *hndata  = allsamples.Draw("hndata", "-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6393 +  TH1F *hnodata = allsamples.Draw("hnodata","-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6394 +  
6395 +  TH1F *hmc   = allsamples.Draw("hmc",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6396 +  TH1F *homc  = allsamples.Draw("homc", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6397 +  
6398 +  hodata->SetLineColor(kRed);
6399 +  hmc->SetLineColor(kRed);
6400 + //  hodata->Add(hndata);
6401 + //  hodata->Add(hnodata,-1);
6402 +  
6403 +  if(hdata->GetMaximum()>hodata->GetMaximum()) {
6404 +    hdata->SetMinimum(1.0);
6405 +    hdata->Draw();
6406 +    hodata->Draw("histo,same");
6407 +    hdata->Draw("same");
6408 +  } else {
6409 +    hodata->SetMinimum(1.0);
6410 +    hodata->Draw("histo");
6411 +    hdata->Draw("same");
6412 +  }
6413 +  
6414 +  CompleteSave(can,"iTTbar/JZB_plot");
6415 +  TH1F *ratio = (TH1F*)hdata->Clone("ratio");
6416 +  ratio->Divide(hodata);
6417 +  ratio->GetYaxis()->SetTitle("obs/pred");
6418 +  ratio->GetYaxis()->SetRangeUser(0,2);
6419 +  
6420 +  ratio->Draw();
6421 +  TLine *l = new TLine(-100,1.0,300,1.0);
6422 +  l->SetLineColor(kBlue);
6423 +  l->SetLineStyle(2);
6424 +  l->Draw();
6425 +  TLine *llow = new TLine(-100,1.0-0.07,300,1.0-0.07);
6426 +  TLine *lhi = new TLine(-100,1.0+0.07,300,1.0+0.07);
6427 +  llow->SetLineColor(kBlue);
6428 +  llow->SetLineStyle(2);
6429 +  llow->Draw();
6430 +  lhi->SetLineColor(kBlue);
6431 +  lhi->SetLineStyle(2);
6432 +  lhi->Draw();
6433 +  
6434 +  CompleteSave(can,"iTTbar/JZB_plot_ratio");
6435 +  
6436 +  delete hdata;
6437 +  delete hodata;
6438 +  delete ratio;
6439 +  delete can;
6440 + //  THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity));
6441 + //  THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity));
6442 + }
6443 +
6444 +  
6445 +  
6446 + void MakeSpecialiTTbarClosurePlot(TCut fullcut, string datajzb, string mcjzb, string MassRegion) {
6447 +  TCanvas *iTTbarClosureTestCanvas = new TCanvas("iTTbarClosureTestCanvas","iTTbarClosureTestCanvas");
6448 +  
6449 +  vector<float> binning;
6450 + /*
6451 +  binning.push_back(0);
6452 +  binning.push_back(20);
6453 +  binning.push_back(50);
6454 +  binning.push_back(100);
6455 + //  binning.push_back(200);
6456 + */
6457 +  binning.push_back(0);
6458 +  binning.push_back(10);
6459 +  binning.push_back(30);
6460 +  binning.push_back(50);
6461 +  binning.push_back(100);
6462 + //  binning.push_back(200);
6463 +  
6464 +  
6465 +  TH1F *hdata  = allsamples.Draw("hdata", datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),data,luminosity);
6466 +  TH1F *hodata = allsamples.Draw("hodata",datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),data,luminosity);
6467 +  TH1F *hmc    = allsamples.Draw("hmc",   mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),mc,luminosity);
6468 +  TH1F *homc   = allsamples.Draw("homc",  mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),mc,luminosity);
6469 +  
6470 +  hdata->SetLineColor(kBlack);
6471 +  hmc->SetLineColor(kBlack);
6472 +  hodata->SetLineColor(kRed);
6473 +  homc->SetLineColor(kRed);
6474 +  hodata->SetMarkerColor(kRed);
6475 +  
6476 +  hdata->GetYaxis()->SetTitle("events");
6477 +  
6478 +  float maximum=hdata->GetMaximum()+1.2*sqrt(hdata->GetMaximum());
6479 +  float minimum=hdata->GetMinimum()-1.2*sqrt(hdata->GetMinimum());
6480 +  if(hmc->GetMinimum()<minimum) minimum=hmc->GetMinimum()-1.2*sqrt(hmc->GetMinimum());
6481 +  if(hmc->GetMaximum()>maximum) maximum=hmc->GetMaximum()+1.2*sqrt(hmc->GetMaximum());
6482 +  if(homc->GetMinimum()<minimum) minimum=homc->GetMinimum()-1.2*sqrt(homc->GetMinimum());
6483 +  if(homc->GetMaximum()>maximum) maximum=homc->GetMaximum()+1.2*sqrt(homc->GetMaximum());
6484 +  if(hodata->GetMinimum()<minimum) minimum=hodata->GetMinimum()-1.2*sqrt(hodata->GetMinimum());
6485 +  if(hodata->GetMaximum()>maximum) maximum=hodata->GetMaximum()+1.2*sqrt(hodata->GetMaximum());
6486 +  
6487 +  hdata->SetMaximum(maximum);
6488 +  hdata->SetMinimum(minimum);
6489 +  
6490 +  
6491 +  hdata->Draw();
6492 +  hmc->Draw("same,histo");
6493 +  homc->Draw("same,histo");
6494 +  hdata->Draw("same");
6495 +  hodata->Draw("same");
6496 +  
6497 +  TLegend *leg = make_legend();
6498 +  leg->AddEntry(hdata,"SF data","pe");
6499 +  leg->AddEntry(hodata,"OF data","pe");
6500 +  leg->AddEntry(hmc,"SF MC","l");
6501 +  leg->AddEntry(homc,"OF MC","l");
6502 +  leg->Draw();
6503 +  
6504 +  DrawPrelim();
6505 +  
6506 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_"+MassRegion);
6507 +  
6508 +  TH1F *ratio_data = (TH1F*)hdata->Clone("ratio_data");
6509 +  ratio_data->Divide(hodata);
6510 +  TH1F *ratio_mc = (TH1F*)hmc->Clone("ratio_mc");
6511 +  ratio_mc->Divide(homc);
6512 +  
6513 +  ratio_mc->SetFillColor(kBlue);
6514 +  ratio_mc->SetMarkerSize(0);
6515 +  
6516 +  TGraphAsymmErrors *eratio = produce_ratio_graph(ratio_mc);
6517 +  
6518 +  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
6519 +  ratio_data->GetYaxis()->SetRangeUser(0.5,1.5);
6520 +  ratio_data->Draw("e1");
6521 +  eratio->Draw("20");
6522 +  ratio_data->Draw("e1,same");
6523 +  
6524 +  TLegend *leg2 = make_legend();
6525 +  leg2->AddEntry(ratio_data,"R(SF/OF) in #bar{t}t CR, data","pe");
6526 +  leg2->AddEntry(eratio    ,"R(SF/OF) in #bar{t}t CR, MC"  ,"f");
6527 +  leg2->SetY1(0.8);
6528 +  leg2->SetX1(0.45);
6529 +  leg2->Draw();
6530 +  
6531 +  DrawPrelim();
6532 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_Ratio_"+MassRegion);
6533 +  
6534 +  TFile *f = new TFile("fout.root","RECREATE");
6535 +  eratio->Write();
6536 +  ratio_data->Write();
6537 +  leg2->Write();
6538 +  f->Close();
6539 +  
6540 +  
6541 +  delete leg;
6542 +  delete leg2;
6543 +  delete ratio_data;
6544 +  delete ratio_mc;
6545 +  delete hdata;
6546 +  delete hmc;
6547 +  delete hodata;
6548 +  delete iTTbarClosureTestCanvas;
6549 + }
6550 +  
6551 +  
6552 +  
6553 + void make_ijzb_ttbar_closure_test(string datajzb, string mcjzb) {
6554 +  TCut tt_nJets("pfJetGoodNum40==2");
6555 +  TCut tt_bJet("pfJetGoodNumBtag40==2 && met[4]>20");
6556 +  TCut tt_LowMass("mll>20&&mll<70");
6557 +  TCut tt_HighMass("mll>120&&mll<200");
6558 +  TCut tt_noZ(tt_LowMass || tt_HighMass);
6559 +  
6560 +  /*
6561 +  make_iTTbar_JZB_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ);
6562 + */
6563 +  TCanvas *can = new TCanvas("can","can");
6564 +
6565 +  TH1F *hdata  =                allsamples.Draw(        "hdata", "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,data,luminosity);
6566 +  THStack *hmc = new THStack(   allsamples.DrawStack(   "hmc",   "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,mc,  luminosity));
6567 +  TH1F *hodata =                allsamples.Draw(        "hodata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,data,luminosity);
6568 +  THStack *homc = new THStack(  allsamples.DrawStack(   "homc",  "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,mc,  luminosity));
6569 +  
6570 +  TH1F *coll_hmc = CollapseStack(hmc);
6571 +  TH1F *coll_homc = CollapseStack(homc);
6572 +  
6573 +  bool dolog=true;
6574 +  bool nolog=false;
6575 +  
6576 +  dout << " SF: " << endl;
6577 +  dout << "   Data : " << hdata->Integral() << endl;
6578 +  WriteYield(hmc, 0, 10000);
6579 +  dout << " OF: " << endl;
6580 +  dout << "   Data : " << hodata->Integral() << endl;
6581 +  WriteYield(homc, 0, 10000);
6582 +  hodata->SetLineColor(kRed);
6583 +  hdata->Draw();
6584 +  hmc->Draw("histo,same");
6585 +  hodata->Draw("histo,same");
6586 +  hdata->Draw("e1,same");
6587 +  DrawPrelim();
6588 +  CompleteSave(can,"TestingPrediction");
6589 +  
6590 +  dout << "We get an expected ratio of " << coll_hmc->Integral()/coll_homc->Integral() << endl;
6591 +  dout << "In data we find  " << hdata->Integral()/hodata->Integral() << endl;
6592 +  
6593 +  Value R_sf_of_low_mass = GetYieldBetween(hdata,20,70)/GetYieldBetween(hodata,20,70);
6594 +  Value R_sf_of_high_mass = GetYieldBetween(hdata,120,200)/GetYieldBetween(hodata,120,200);
6595 +  
6596 +  Value R_sf_of_low_mass_mc = GetYieldBetween(coll_hmc,20,70)/GetYieldBetween(coll_homc,20,70);
6597 +  Value R_sf_of_high_mass_mc = GetYieldBetween(coll_hmc,120,200)/GetYieldBetween(coll_homc,120,200);
6598 +  
6599 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6600 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6601 +  
6602 +  dout << "Composition at low mass : " << endl;
6603 +  dout << "Same flavor: " << endl;
6604 +  ProduceYields(20, 70, hdata, hmc);
6605 +  dout << "Opposite flavor: " << endl;
6606 +  ProduceYields(20, 70, hodata, homc);
6607 +  
6608 +  dout << endl << endl;
6609 +  
6610 +  dout << "Composition at high mass : " << endl;
6611 +  dout << "Same flavor: " << endl;
6612 +  ProduceYields(120, 200, hdata, hmc);
6613 +  dout << "Opposite flavor: " << endl;
6614 +  ProduceYields(120, 200, hodata, homc);
6615 +  
6616 +  
6617 +
6618 +  
6619 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),20,-200,200,dolog,"JZB","iTTbar/JZB_SF",false,true);
6620 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),20,-200,200,dolog,"JZB","iTTbar/JZB_OF",false,true);
6621 +
6622 +  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);
6623 +  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);
6624 +  
6625 +  make_SF_over_OF_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ,"mll",20,0,200,"m_{ll} [GeV]","mll");
6626 +  
6627 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_LowMass),datajzb,mcjzb,"LowMassRegion2070");
6628 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_HighMass),datajzb,mcjzb,"HighMassRegion");
6629 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_noZ),datajzb,mcjzb,"NoZ");
6630 +  
6631 + //   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);
6632 + //   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);
6633 + //  
6634 + //   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);
6635 + //   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);
6636 +  
6637 +  
6638 +  delete coll_hmc;
6639 +  delete coll_homc;
6640 +  delete hmc;
6641 +  delete homc;
6642 +  delete hdata;
6643 +  delete hodata;
6644 +  delete can;
6645 + }
6646 +
6647 + void compute_global_significance(float local_significance) {
6648 +    float global_sigificance = ROOT::Math::normal_quantile_c(ROOT::Math::normal_cdf_c(local_significance,1)*4,1);
6649 +    dout << "local significance  : " << local_significance << endl;
6650 +    dout << "global significance : " << global_sigificance << endl;
6651 + }
6652 +  
6653  
6654   void test() {
6655    
6656 +  
6657 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
6658 +  stringstream result, datajzb, mcjzb;
6659 +  bool doPUreweighting=true;
6660 +  bool SwitchOffNJetsCut=false;
6661 +  
6662 +  
6663 +  TCanvas *can = new TCanvas("can","can");
6664 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
6665 +  
6666 +  float NumVtxBin[6] = {0,5,10,15,20,30};
6667 +  
6668 +  stringstream NowCut;
6669 +  
6670 +  TGraphErrors *gMCPeak = new TGraphErrors();
6671 +  gMCPeak->SetTitle("gMCPeak");
6672 +  gMCPeak->SetName("gMCPeak");
6673 +  TGraphErrors *gDataPeak = new TGraphErrors();
6674 +  gDataPeak->SetTitle("gDataPeak");
6675 +  gDataPeak->SetName("gDataPeak");
6676 +  TGraphErrors *gMCWidth = new TGraphErrors();
6677 +  gMCWidth->SetTitle("gMCWidth");
6678 +  gMCWidth->SetName("gMCWidth");
6679 +  TGraphErrors *gDataWidth = new TGraphErrors();
6680 +  gDataWidth->SetTitle("gDataWidth");
6681 +  gDataWidth->SetName("gDataWidth");
6682 +  
6683 +  float AllMCPeaks[200];
6684 +  float AllMCPeaksErrors[200];
6685 +  
6686 +  for(int i=10;i<180;i+=20) {
6687 +    NowCut.str("");
6688 +    NowCut << "mll>=" << i << "&&mll<" << i+20;
6689 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
6690 +    AllMCPeaks[i]=MCPeak;
6691 +    AllMCPeaksErrors[i]=MCPeakError;
6692 +  }
6693 +  
6694 +  dout << "Summary : " << endl;
6695 +  for(int i=10;i<180;i+=20) {
6696 +    dout << "For the slice at [" << i << " , " << i+20 << "] we get a peak at " << AllMCPeaks[i] << " +/- " << AllMCPeaksErrors[i] << endl;
6697 +  }
6698 +  /*
6699    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
6700    testcanv->cd();
6701   //  switch_overunderflow(true);
6702 <  TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
6703 <  switch_overunderflow(false);
6704 <  ptdistr->Draw();
6705 <  testcanv->SaveAs("test.png");
6706 <  dout << "HELLO there!" << endl;
6702 >  TH1F *histo1 = new TH1F("histo","histo",100,0,1);
6703 >  histo1->Sumw2();
6704 >  TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
6705 >  histo2->Sumw2();
6706 >  
6707 >  for(int i=0;i<100;i++) {
6708 >    histo1->Fill(1.0/i,i);
6709 >    histo2->Fill(1.0/(i*i),i);
6710 >  }
6711 >
6712 >  histo1->Draw();
6713 >  histo2->Draw("e1,same");
6714 >  
6715 >  Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
6716    
6717 +  
6718 +  dout << "HELLO there!" << endl;
6719 +  */
6720   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines