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.95 by buchmann, Tue May 21 09:59:18 2013 UTC

# Line 32 | Line 32 | void todo() {
32   }  
33  
34  
35 + namespace PeakLibrary {
36 +  bool StoreHistos=false;
37 +  vector<TH1F*> DataHistogram;
38 +  vector<TH1F*> MCHistogram;
39 + }
40 +
41  
42   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="")
43   {
# Line 45 | Line 51 | void find_one_peak_combination(TCut spec
51    TCut nJetsCut(cutnJets);
52    if(SwitchOffNJetsCut) nJetsCut=specialcut;
53    
54 +  
55    TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
56    TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,mc, luminosity);
57    TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,data, luminosity);
# Line 80 | Line 87 | void find_one_peak_combination(TCut spec
87    result << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
88    dout   << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
89    result << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
90 <  delete rawJZBeemmData;
91 <  delete rawJZBeemmMC;
90 >  
91 >  if(!PeakLibrary::StoreHistos) {
92 >    delete rawJZBeemmData;
93 >    delete rawJZBeemmMC;
94 >  } else {
95 >    rawJZBeemmMC->SetName(GetNumericHistoName().c_str());
96 >    rawJZBeemmData->SetName(GetNumericHistoName().c_str());
97 >    rawJZBeemmMC->Add(rawJZBemMC,-1);
98 >    rawJZBeemmData->Add(rawJZBemData,-1);
99 >    PeakLibrary::DataHistogram.push_back(rawJZBeemmData);
100 >    PeakLibrary::MCHistogram.push_back(rawJZBeemmMC);
101 >  }
102 >  
103 >
104 >  
105    delete rawJZBemData;
106    delete rawJZBemMC;
107    delete tempcan;
108   }
109  
110 + void Old_FindPeakPileUpCorrection() {
111 +  bool StoreResultsInSeparateFile=false;
112 +  PeakLibrary::StoreHistos=true;
113 +  
114 +  
115 +  dout << "Finding peak position as a function of PU" << endl;
116 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
117 +  stringstream result, datajzb, mcjzb;
118 +  bool doPUreweighting=true;
119 +  bool SwitchOffNJetsCut=false;
120 +  
121 +  
122 +  TCanvas *can = new TCanvas("can","can");
123 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
124 +  
125 +  float NumVtxBin[6] = {0,5,10,15,20,30};
126 +  
127 +  stringstream NowCut;
128 +  
129 +  TGraphErrors *gMCPeak = new TGraphErrors();
130 +  gMCPeak->SetTitle("gMCPeak");
131 +  gMCPeak->SetName("gMCPeak");
132 +  TGraphErrors *gDataPeak = new TGraphErrors();
133 +  gDataPeak->SetTitle("gDataPeak");
134 +  gDataPeak->SetName("gDataPeak");
135 +  TGraphErrors *gMCWidth = new TGraphErrors();
136 +  gMCWidth->SetTitle("gMCWidth");
137 +  gMCWidth->SetName("gMCWidth");
138 +  TGraphErrors *gDataWidth = new TGraphErrors();
139 +  gDataWidth->SetTitle("gDataWidth");
140 +  gDataWidth->SetName("gDataWidth");
141 +  
142 +  
143 +  for(int i=0;i<5;i++) {
144 +    NowCut.str("");
145 +    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
146 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
147 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
148 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
149 +    
150 +    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
151 +    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
152 +    
153 +    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
154 +    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
155 +    
156 +    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
157 +    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
158 +    
159 +    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
160 +    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
161 +  }
162 +  
163 +  can->cd();
164 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
165 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
166 +  gMCPeak->GetXaxis()->CenterTitle();
167 +  gMCPeak->GetYaxis()->CenterTitle();
168 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
169 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
170 +  gDataPeak->GetXaxis()->CenterTitle();
171 +  gDataPeak->GetYaxis()->CenterTitle();
172 +  
173 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
174 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
175 +  gDataWidth->GetXaxis()->CenterTitle();
176 +  gDataWidth->GetYaxis()->CenterTitle();
177 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
178 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
179 +  gMCWidth->GetXaxis()->CenterTitle();
180 +  gMCWidth->GetYaxis()->CenterTitle();
181 +  
182 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
183 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
184 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
185 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
186 +  
187 +  gMCPeak->Draw("A2");
188 +  DrawMCPrelim();
189 +  CompleteSave(can,"PUStudy/MCPeak");
190 +  can->cd();
191 +  gMCWidth->Draw("A2");
192 +  DrawMCPrelim();
193 +  CompleteSave(can,"PUStudy/MCWidth");
194 +  
195 +  can->cd();
196 +  gDataPeak->Draw("A2");
197 +  
198 +  DrawPrelim();
199 +  CompleteSave(can,"PUStudy/DataPeak");
200 +  can->cd();
201 +  gDataWidth->Draw("A2");
202 +  DrawPrelim();
203 +  CompleteSave(can,"PUStudy/DataWidth");
204 +  
205 +  if(StoreResultsInSeparateFile) {
206 +    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
207 +    gMCPeak->Write();
208 +    gDataPeak->Write();
209 +    gMCWidth->Write();
210 +    gDataWidth->Write();
211 +    PeakFinding->Close();
212 +  }
213 +  
214 +  gDataPeak->Fit("pol1","L");
215 +  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
216 +  gMCPeak->Fit("pol1","L");
217 +  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
218 +  
219 +  
220 +  can->cd();
221 +  gMCPeak->Draw("A2");
222 +  DrawMCPrelim();
223 +  CompleteSave(can,"PUStudy/MCPeak_WithFit");
224 +  can->cd();
225 +  
226 +  can->cd();
227 +  gDataPeak->Draw("A2");
228 +  DrawPrelim();
229 +  CompleteSave(can,"PUStudy/DataPeak_WithFit");
230 +  
231 +  
232 +  
233 +  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
234 +  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
235 +  
236 +  TLegend *leg = make_legend();
237 +  can->cd();
238 +  int j=0;
239 +  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
240 +    PeakLibrary::DataHistogram[i]->Rebin(5);
241 +    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
242 +    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
243 +    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
244 +    stringstream name;
245 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
246 +    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
247 +    j++;
248 +  }
249 +  
250 +  leg->Draw();
251 +  DrawPrelim();
252 +  CompleteSave(can,"PUStudy/DataOverview");
253 +  
254 +  TLegend *leg2 = make_legend();
255 +  can->cd();
256 +  j=0;
257 +  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
258 +    PeakLibrary::MCHistogram[i]->Rebin(5);
259 +    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
260 +    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
261 +    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
262 +    stringstream name;
263 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
264 +    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
265 +    j++;
266 +  }
267 +  
268 +  leg->Draw();
269 +  DrawPrelim();
270 +  CompleteSave(can,"PUStudy/MCOverview");
271 +  
272 +  delete can;
273 +  PeakLibrary::StoreHistos=false;
274 + }
275 +
276 + void FindPeakPileUpCorrection() {
277 +  bool StoreResultsInSeparateFile=true;
278 +  PeakLibrary::StoreHistos=true;
279 +  
280 +  
281 +  dout << "Finding peak position as a function of PU" << endl;
282 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
283 +  stringstream result, datajzb, mcjzb;
284 +  bool doPUreweighting=true;
285 +  bool SwitchOffNJetsCut=false;
286 +  
287 +  
288 +  TCanvas *can = new TCanvas("can","can");
289 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
290 +  
291 +  const int nbins=11;
292 +  float NumVtxBin[nbins] = {0,7,9,11,13,15,17,19,21,24,50};
293 +  
294 +  stringstream NowCut;
295 +  
296 +
297 +  Double_t mc_peak_x[nbins];
298 +  Double_t mc_peak_y[nbins];
299 +  Double_t mc_peak_dxh[nbins];
300 +  Double_t mc_peak_dxl[nbins];
301 +  Double_t mc_peak_dy[nbins];
302 +  
303 +  Double_t data_peak_x[nbins];
304 +  Double_t data_peak_y[nbins];
305 +  Double_t data_peak_dxh[nbins];
306 +  Double_t data_peak_dxl[nbins];
307 +  Double_t data_peak_dy[nbins];
308 +  
309 +  Double_t mc_width_x[nbins];
310 +  Double_t mc_width_y[nbins];
311 +  Double_t mc_width_dxh[nbins];
312 +  Double_t mc_width_dxl[nbins];
313 +  Double_t mc_width_dy[nbins];
314 +  
315 +  Double_t data_width_x[nbins];
316 +  Double_t data_width_y[nbins];
317 +  Double_t data_width_dxh[nbins];
318 +  Double_t data_width_dxl[nbins];
319 +  Double_t data_width_dy[nbins];
320 +
321 +  for(int i=0;i<nbins-1;i++) {
322 +    NowCut.str("");
323 +    NowCut << "numVtx>" << NumVtxBin[i] << "&&numVtx<=" << NumVtxBin[i+1];
324 +    cout << "NVtx cut is now : " << NowCut.str() << endl;
325 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
326 +    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
327 +    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
328 +    
329 +    TH1F *hDataSFNumVtx = allsamples.Draw("hDataSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
330 +    TH1F *hDataOFNumVtx = allsamples.Draw("hDataOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),data, luminosity);
331 +    TH1F *hMCSFNumVtx = allsamples.Draw("hMCSFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSSF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
332 +    TH1F *hMCOFNumVtx = allsamples.Draw("hMCOFNumVtx","numVtx",100,-0.5,49.5, "N_{vtx}", "events", cutmass&&cutOSOF&&cutnJets&&TCut(NowCut.str().c_str()),mc, luminosity);
333 +    
334 +    hDataSFNumVtx->Add(hDataOFNumVtx,-1);
335 +    hMCSFNumVtx->Add(hMCOFNumVtx,-1);
336 +    
337 +    mc_peak_x[i]=hMCSFNumVtx->GetMean();
338 +    mc_peak_y[i]=MCPeak;
339 +    mc_peak_dy[i]=MCPeakError;
340 +    
341 +    data_peak_x[i]=hDataSFNumVtx->GetMean();
342 +    data_peak_y[i]=DataPeak;
343 +    data_peak_dy[i]=DataPeakError;
344 +    
345 +    mc_width_x[i]=hMCSFNumVtx->GetMean();
346 +    mc_width_y[i]=mcSigma;
347 +    mc_width_dy[i]=mcSigmaError;
348 +    
349 +    data_width_x[i]=hDataSFNumVtx->GetMean();
350 +    data_width_y[i]=dataSigma;
351 +    data_width_dy[i]=dataSigmaError;
352 +    
353 +    delete hDataSFNumVtx;
354 +    delete hDataOFNumVtx;
355 +    delete hMCSFNumVtx;
356 +    delete hMCOFNumVtx;
357 +  }
358 +  
359 +  for(int i=0;i<nbins-1;i++) {
360 +    if(i==0) {
361 +      data_width_dxl[i]=data_width_x[i];
362 +      data_peak_dxl[i]=data_peak_x[i];
363 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
364 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
365 +      
366 +      mc_width_dxl[i]=mc_width_x[i];
367 +      mc_peak_dxl[i]=mc_peak_x[i];
368 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
369 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
370 +    } else if(i==nbins-2) {
371 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
372 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
373 +      data_width_dxh[i]=50-data_width_x[i];
374 +      data_peak_dxh[i]=50-data_peak_x[i];
375 +      
376 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
377 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
378 +      mc_width_dxh[i]=50-mc_width_x[i];
379 +      mc_peak_dxh[i]=50-mc_peak_x[i];
380 +    } else {
381 +      data_width_dxl[i]=0.5*(data_width_x[i]-data_width_x[i-1]);
382 +      data_peak_dxl[i]=0.5*(data_peak_x[i]-data_peak_x[i-1]);
383 +      data_width_dxh[i]=0.5*(data_width_x[i+1]-data_width_x[i]);
384 +      data_peak_dxh[i]=0.5*(data_peak_x[i+1]-data_peak_x[i]);
385 +      
386 +      mc_width_dxl[i]=0.5*(mc_width_x[i]-mc_width_x[i-1]);
387 +      mc_peak_dxl[i]=0.5*(mc_peak_x[i]-mc_peak_x[i-1]);
388 +      mc_width_dxh[i]=0.5*(mc_width_x[i+1]-mc_width_x[i]);
389 +      mc_peak_dxh[i]=0.5*(mc_peak_x[i+1]-mc_peak_x[i]);
390 +    }
391 +  }
392 +  
393 +  TGraphAsymmErrors *gMCPeak = new TGraphAsymmErrors(nbins-1,mc_peak_x,mc_peak_y,mc_peak_dxl,mc_peak_dxh,mc_peak_dy,mc_peak_dy);
394 +  gMCPeak->SetTitle("gMCPeak");
395 +  gMCPeak->SetName("gMCPeak");
396 +  
397 +  TGraphAsymmErrors *gDataPeak = new TGraphAsymmErrors(nbins-1,data_peak_x,data_peak_y,data_peak_dxl,data_peak_dxh,data_peak_dy,data_peak_dy);
398 +  gDataPeak->SetTitle("gDataPeak");
399 +  gDataPeak->SetName("gDataPeak");
400 +  
401 +  TGraphAsymmErrors *gMCWidth = new TGraphAsymmErrors(nbins-1,mc_width_x,mc_width_y,mc_width_dxl,mc_width_dxh,mc_width_dy,mc_width_dy);
402 +  gMCWidth->SetTitle("gMCWidth");
403 +  gMCWidth->SetName("gMCWidth");
404 +  
405 +  TGraphAsymmErrors *gDataWidth = new TGraphAsymmErrors(nbins-1,data_width_x,data_width_y,data_width_dxl,data_width_dxh,data_width_dy,data_width_dy);
406 +  gDataWidth->SetTitle("gDataWidth");
407 +  gDataWidth->SetName("gDataWidth");
408 +  
409 +  can->cd();
410 +  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
411 +  gMCPeak->GetYaxis()->SetTitle("Peak position");
412 +  gMCPeak->GetXaxis()->CenterTitle();
413 +  gMCPeak->GetYaxis()->CenterTitle();
414 +  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
415 +  gDataPeak->GetYaxis()->SetTitle("Peak position");
416 +  gDataPeak->GetXaxis()->CenterTitle();
417 +  gDataPeak->GetYaxis()->CenterTitle();
418 +  
419 +  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
420 +  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
421 +  gDataWidth->GetXaxis()->CenterTitle();
422 +  gDataWidth->GetYaxis()->CenterTitle();
423 +  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
424 +  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
425 +  gMCWidth->GetXaxis()->CenterTitle();
426 +  gMCWidth->GetYaxis()->CenterTitle();
427 +  
428 +  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
429 +  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
430 +  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
431 +  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
432 +  
433 +  gMCPeak->Draw("A2");
434 +  DrawMCPrelim();
435 +  CompleteSave(can,"PUStudy/MCPeak");
436 +  can->cd();
437 +  gMCWidth->Draw("A2");
438 +  DrawMCPrelim();
439 +  CompleteSave(can,"PUStudy/MCWidth");
440 +  
441 +  can->cd();
442 +  gDataPeak->Draw("A2");
443 +  
444 +  DrawPrelim();
445 +  CompleteSave(can,"PUStudy/DataPeak");
446 +  can->cd();
447 +  gDataWidth->Draw("A2");
448 +  DrawPrelim();
449 +  CompleteSave(can,"PUStudy/DataWidth");
450 +  
451 +  if(StoreResultsInSeparateFile) {
452 +    TFile *PeakFinding = new TFile("PeakFindingWithPeakCorrection.root","RECREATE");
453 +    gMCPeak->Write();
454 +    gDataPeak->Write();
455 +    gMCWidth->Write();
456 +    gDataWidth->Write();
457 +    PeakFinding->Close();
458 +  }
459 +  
460 +  gDataPeak->Fit("pol1");
461 +  TF1 *DataFit = (TF1*)gDataPeak->GetFunction("pol1");
462 +  gMCPeak->Fit("pol1");
463 +  TF1 *MCFit = (TF1*)gMCPeak->GetFunction("pol1");
464 +  
465 +  dout << "The suggested correction for Data is : " << DataFit->GetParameter(1) << endl;
466 +  dout << "The suggested correction for MC is   : " << MCFit->GetParameter(1) << endl;
467 +  
468 +  TLegend *leg = make_legend();
469 +  can->cd();
470 +  int j=0;
471 +  for(int i=PeakLibrary::DataHistogram.size()-5;i<PeakLibrary::DataHistogram.size();i++) {
472 +    PeakLibrary::DataHistogram[i]->Rebin(5);
473 +    PeakLibrary::DataHistogram[i]->SetLineColor(j+1);
474 +    if(i==PeakLibrary::DataHistogram.size()-5) PeakLibrary::DataHistogram[i]->DrawNormalized("histo");
475 +    else PeakLibrary::DataHistogram[i]->DrawNormalized("histo,same");
476 +    stringstream name;
477 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
478 +    leg->AddEntry(PeakLibrary::DataHistogram[i],name.str().c_str(),"l");
479 +    j++;
480 +  }
481 +  
482 +  leg->Draw();
483 +  DrawPrelim();
484 +  CompleteSave(can,"PUStudy/DataOverview");
485 +  
486 +  TLegend *leg2 = make_legend();
487 +  can->cd();
488 +  j=0;
489 +  for(int i=PeakLibrary::MCHistogram.size()-5;i<PeakLibrary::MCHistogram.size();i++) {
490 +    PeakLibrary::MCHistogram[i]->Rebin(5);
491 +    PeakLibrary::MCHistogram[i]->SetLineColor(j+1);
492 +    if(i==PeakLibrary::MCHistogram.size()-5) PeakLibrary::MCHistogram[i]->DrawNormalized("histo");
493 +    else PeakLibrary::MCHistogram[i]->DrawNormalized("histo,same");
494 +    stringstream name;
495 +    name << NumVtxBin[j] << " < N_{vtx} < " << NumVtxBin[j+1];
496 +    leg->AddEntry(PeakLibrary::MCHistogram[i],name.str().c_str(),"l");
497 +    j++;
498 +  }
499 +  
500 +  leg->Draw();
501 +  DrawPrelim();
502 +  CompleteSave(can,"PUStudy/MCOverview");
503 +  
504 +  delete can;
505 +  PeakLibrary::StoreHistos=false;
506 + }
507 +
508 +
509 +
510   void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
511   {
512    bool overunderflowstatus=addoverunderflowbins;
# Line 144 | Line 564 | void find_peaks(float &MCPeak,float &MCP
564      
565    } else {
566      datajzb << "(" << jzbvariabledata;
567 <      mcjzb << "(" << jzbvariablemc;
567 >    mcjzb   << "(" << jzbvariablemc;
568      
569      if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
570      else datajzb << "+ " << TMath::Abs(datapeak) << " ";
# Line 164 | Line 584 | void find_peaks(float &MCPeak,float &MCP
584      switch_overunderflow(overunderflowstatus);
585   }
586  
587 < void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
587 > void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth, int MCorData) {
588    float min=70.0;
589    float max=115.0;
590    if(!PlottingSetup::RestrictToMassPeak) {
# Line 173 | Line 593 | void make_special_obs_pred_mll_plot(stri
593    }
594    int nbins=int((max-min)/binWidth);
595    
596 +  string prefix="";
597 +  if(MCorData==mc) prefix="MC__";
598 +  
599 +  
600 +  if(MCorData==mc) datajzb=mcjzb;
601 +  
602    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
603    
604    stringstream largerzeroS;
# Line 188 | Line 614 | void make_special_obs_pred_mll_plot(stri
614    largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
615    TCut largerzeroM(largerzeroMS.str().c_str());
616    
617 <  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
618 <  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
619 <  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
620 <  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
621 <  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
617 >
618 >  stringstream smallerzeroMS;
619 >  smallerzeroMS << "(" << mcjzb << "<-" << jzbthreshold << ")";
620 >  TCut smallerzeroM(smallerzeroMS.str().c_str());
621 >  
622 >  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,MCorData,luminosity);
623 >  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
624 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,MCorData,luminosity);
625 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,MCorData,luminosity);
626 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,MCorData,luminosity);
627  
628    TH1F *RcorrJZBSBem;
629    TH1F *LcorrJZBSBem;
# Line 202 | Line 633 | void make_special_obs_pred_mll_plot(stri
633   //  TH1F *RcorrJZBeemmNoS;
634  
635    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
636 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
637 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
638 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
639 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
636 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,MCorData, luminosity);
637 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,MCorData, luminosity);
638 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,MCorData, luminosity);
639 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,MCorData, luminosity);
640    }
641 <  
642 <  // Separate predictions
641 >
642 >    // Separate predictions
643    TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
644    TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
645    TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
646 +  
647    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
648      OFP->Scale(1.0/3.0);
649      OFP->Add(RcorrJZBSBem,1.0/3.);
# Line 228 | Line 660 | void make_special_obs_pred_mll_plot(stri
660    
661    RcorrJZBeemm->SetTitleOffset(1.3,"y");
662    RcorrJZBeemm->Draw();
663 <  mcRcorrJZBeemm.Draw("same");
663 >  mcRcorrJZBeemm.Draw("histo,same");
664    Bpred->Draw("histo,same");
665    RcorrJZBeemm->Draw("same");
666    
667    TLegend *leg = allsamples.allbglegend();
668    leg->SetX1(0.58);
669 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
669 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
670    leg->AddEntry(Bpred,"predicted (data)","l");
671    leg->Draw("same");
672    
673    stringstream saveas;
674 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
674 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold;
675    CompleteSave(ckin,saveas.str());
676    
677    // Draw all predictions overlayed
# Line 262 | Line 694 | void make_special_obs_pred_mll_plot(stri
694    RcorrJZBeemm->Draw("same");
695    
696    TLegend *leg2 = make_legend("",0.52,0.7);
697 <  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
698 <  leg2->AddEntry(Bpred,"predicted (data)","l");
699 <  leg2->AddEntry(SFN,  "  SF JZB<0","l");
700 <  leg2->AddEntry(OFN,  "  OF JZB<0","l");
701 <  leg2->AddEntry(OFP,  "  OF JZB>0","l");
697 >  if(MCorData==data) {
698 >    leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
699 >    leg2->AddEntry(Bpred,"predicted (data)","l");
700 >  } else {
701 >    leg2->AddEntry(RcorrJZBeemm,"true (MC)","lp");
702 >    leg2->AddEntry(Bpred,"predicted (MC)","l");
703 >  }
704 >
705 >  if(jzbthreshold>0) {
706 >    leg2->AddEntry(SFN,  ("  SF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
707 >    leg2->AddEntry(OFN,  ("  OF JZB<-"+any2string(jzbthreshold)).c_str(),"l");
708 >  } else {
709 >    leg2->AddEntry(SFN,  "  SF JZB<0","l");
710 >    leg2->AddEntry(OFN,  "  OF JZB<0","l");
711 >  }
712 >  leg2->AddEntry(OFP,  ("  OF JZB>"+any2string(jzbthreshold)).c_str(),"l");
713    leg2->Draw("same");
714    
715    saveas.str("");
716 <  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
716 >  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc";
717    CompleteSave(ckin,saveas.str());
718    
719 +  
720 +  TH1F *diff = (TH1F*)RcorrJZBeemm->Clone("diff");
721 +  diff->Add(Bpred,-1);
722 +  
723 +  diff->Draw("e1");
724 +  if(MCorData==data) DrawPrelim();
725 +  else DrawMCPrelim();
726 +  
727 +  saveas.str("");
728 +  saveas << "kin/Mll_After_Cut/" << prefix << "Cut_At" << jzbthreshold << "_nomc_Diff";
729 +  CompleteSave(ckin,saveas.str());
730 +  
731 +
732 +
733 +  
734 +  delete diff;
735 +  
736    delete RcorrJZBeemm;
737    delete LcorrJZBeemm;
738    delete RcorrJZBem;
739    delete LcorrJZBem;
740 +
741    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
742      delete RcorrJZBSBeemm;
743      delete LcorrJZBSBeemm;
# Line 285 | Line 746 | void make_special_obs_pred_mll_plot(stri
746    }
747    delete Bpred;
748    delete ckin;
749 +  CleanLegends();
750   }
751  
752   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 331 | Line 793 | void make_special_mll_plot(int nbins, fl
793    delete datahistoOSOF;
794    delete datahistoOSSF;
795    delete ckin;
796 +  CleanLegends();
797   }
798    
799  
# Line 382 | Line 845 | float make_one_OFSF_plot(string variable
845    TCut cutSF;
846    TCut cutOF;
847  
848 +  cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
849    cutOF = cutOSOF&&cutnJets&&ibasiccut;
850    cutSF = cutOSSF&&cutnJets&&ibasiccut;
851 +  
852 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
853  
388  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
854    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
855    rcan->SetLogy(logscale);
856    rcan->cd();
# Line 410 | Line 875 | float make_one_OFSF_plot(string variable
875    }
876    if (ymax<0) {
877      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
878 <    else datahistoSF->SetMaximum(1.8*datahistoSF->GetMaximum());
878 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
879    } else {
880      datahistoSF->SetMaximum(ymax);
881    }
# Line 437 | Line 902 | float make_one_OFSF_plot(string variable
902    mleg->Draw();
903    DrawPrelim();
904    if (datahistoOF->Integral()>0) {
905 <    save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
905 >    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
906    } else {
907      CompleteSave(rcan, "SFOF/" + filename);
443    delete rcan;
908    }
909  
910    datahistoSF->Delete();
911    datahistoOF->Delete();
912    //signalhisto->Delete();
913    delete mleg;
914 <  delete ckin;
914 >  delete rcan;
915 >  delete ofsf_can;
916  
917    return ymaxSet;
918  
# Line 500 | Line 965 | float make_data_comparison_plot(string v
965    data2->Draw("HIST,SAMES");
966    mleg->Draw();
967    DrawPrelim();
968 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
968 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
969  
970    data1->Delete();
971    data2->Delete();
972    delete mleg;
973 +  delete rcan;
974    delete ckin;
975  
976   }
# Line 537 | Line 1003 | void make_OFSF_plots(string variable, st
1003  
1004   }
1005  
1006 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
1007 +  string scut=(string)(const char*)cut;
1008 +  string acut=ReplaceAll(scut,replacethis,withthis);
1009 +  return TCut(acut.c_str());
1010 + }
1011 +
1012 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1013 +  TCut cut=addcut&&basiccut;
1014  
1015 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1016 +  ckin->SetLogy(dolog);
1017 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
1018 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1019 +  datahisto->SetMarkerSize(DataMarkerSize);
1020 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1021 +  else datahisto->SetMinimum(0.5);
1022 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1023 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1024 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
1025 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1026 +  TH1F *MCcentral = CollapseStack(mcstack);
1027 +
1028 +  TCut bkpcut = cut;
1029 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
1030 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
1031 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1032 +
1033 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
1034 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
1035 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1036 +  
1037 +  cut=bkpcut;
1038 +  TCut bkpweight = cutWeight;
1039 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
1040 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
1041 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1042 +  
1043 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
1044 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
1045 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1046 +  cutWeight=bkpweight;
1047 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
1048 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
1049 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1050 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
1051 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
1052 +    float jes   = jesdn>jesup?jesdn:jesup;
1053 +    
1054 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
1055 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
1056 +    float pu   = PUdn>PUup?PUdn:PUup;
1057 +    
1058 +    float sys=sqrt(jes*jes+pu*pu);
1059 +    sys/=MCcentral->GetBinContent(i);
1060 +    if(MCcentral->GetBinContent(i)==0) sys=0;
1061 +    Systematic->SetBinContent(i,sys);
1062 +  }
1063 +  
1064 +  datahisto->Draw("e1");
1065 +  ckin->Update();
1066 +  mcstack.Draw("histo,same");
1067 +  
1068 +  datahisto->Draw("same,e1");
1069 +  TLegend *kinleg = allsamples.allbglegend();
1070 +  kinleg->Draw();
1071 +
1072 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1073 +  kinpad->SetLogy(dolog);
1074 +  kinpad->cd();
1075 +  datahisto->Draw("e1");
1076 +  mcstack.Draw("histo,same");
1077 +  datahisto->Draw("same,e1");
1078 +  datahisto->Draw("same,axis");
1079 +  
1080 +  kinleg->Draw("same");
1081 +  DrawPrelim();
1082 +  string saveas="kin/"+filename;
1083 +  
1084 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1085 +  save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1086 +  
1087 +  ckin->cd();
1088 +  MCcentral->SetFillColor(kWhite);
1089 +  MCcentral->SetLineColor(kBlack);
1090 +  MCcentral->SetLineWidth(2);
1091 +  MCPUdn->SetLineColor(kRed);
1092 +  MCPUup->SetLineColor(kYellow);
1093 +  MCJESdn->SetLineColor(kBlue);
1094 +  MCJESup->SetLineColor(kGreen);
1095 +  
1096 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
1097 +  legsmall->SetNColumns(5);
1098 +  legsmall->AddEntry(MCcentral,"central","L");
1099 +  legsmall->AddEntry(MCPUdn,"PU down","L");
1100 +  legsmall->AddEntry(MCPUup,"PU up","L");
1101 +  legsmall->AddEntry(MCJESdn,"JES down","L");
1102 +  legsmall->AddEntry(MCJESup,"JES up","L");
1103 +  legsmall->SetFillColor(kWhite);
1104 +  legsmall->SetBorderSize(0);
1105 +  
1106 +  datahisto->Draw("e1");
1107 +  MCcentral->Draw("histo,same");
1108 +  MCPUdn->Draw("histo,same");
1109 +  MCPUup->Draw("histo,same");
1110 +  MCJESdn->Draw("histo,same");
1111 +  MCJESup->Draw("histo,same");
1112 +  datahisto->Draw("e1,same");
1113 +  legsmall->Draw();
1114 +  CompleteSave(ckin,saveas+"___AllLines");
1115 +  
1116 +  delete datahisto;
1117 +  delete MCcentral;
1118 +  delete MCPUdn;
1119 +  delete MCPUup;
1120 +  delete MCJESdn;
1121 +  delete MCJESup;
1122 +  delete ckin;
1123 + }
1124 +
1125 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1126 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1127 + }
1128 +  
1129   float lastrange_min=0;
1130   float lastrange_max=0;
1131  
# Line 688 | Line 1276 | void make_kin_plot(string variable, stri
1276          DrawPrelim();
1277          string saveas="kin/"+filename;
1278          if(isPF) saveas="kin/"+filename+"__PF";
1279 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1279 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1280   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
1281   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
1282   //      delete with_ratio;
# Line 751 | Line 1339 | void make_plain_kin_plot(string variable
1339          DrawPrelim();
1340          string saveas="kin/"+filename;
1341          if(isPF) saveas="kin/"+filename+"__PF";
1342 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
1342 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
1343    } else {
1344          if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
1345          else CompleteSave(ckin,"kin/"+filename);
# Line 803 | Line 1391 | void make_JES_plot(TCut cut, string name
1391    CompleteSave(ckin,"Systematics/JES"+name);
1392    datahisto->Delete();
1393    delete ckin;
1394 <
1394 >  delete JESunc;
1395 >  delete JESup;
1396 >  delete JESdn;
1397 >  CleanLegends();
1398   }
1399  
1400   string Cut2Str(TCut cut) {
# Line 822 | Line 1413 | void MakeElegantTwoThreeComparisons() {
1413      string xlabel="m_{ll} [GeV]";
1414      
1415      TCanvas *can2 = new TCanvas("can2","can2");
1416 <    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1417 <    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1418 <    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1419 <    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1416 >    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1417 >    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("/TT_"));
1418 >    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1419 >    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("/TT_"));
1420      
1421      can2->cd(1);
1422      
# Line 843 | Line 1434 | void MakeElegantTwoThreeComparisons() {
1434      leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1435      leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1436      leg_SFOF_Two->Draw();
1437 <    save_with_ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1437 >    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1438      
1439      TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1440      kin4->cd();
# Line 854 | Line 1445 | void MakeElegantTwoThreeComparisons() {
1445      leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1446      leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1447      leg_SFOF_Three->Draw();
1448 <    save_with_ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1448 >    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1449      
1450      
1451      TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
# Line 867 | Line 1458 | void MakeElegantTwoThreeComparisons() {
1458      leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1459      leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1460      leg_SF_Two_Three->Draw();
1461 <    save_with_ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1461 >    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1462      
1463      TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1464      TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
# Line 879 | Line 1470 | void MakeElegantTwoThreeComparisons() {
1470      leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1471      leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1472      leg_OF_Two_Three->Draw();
1473 <    save_with_ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1473 >    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1474      
1475   }
1476  
1477 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1478 +  pad->cd();
1479 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1480 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1481 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1482 +    float error=abs(Down->GetBinContent(i)-average);
1483 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1484 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1485 +  }
1486 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1487 +  gr->GetYaxis()->SetRangeUser(0,2);
1488 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1489 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1490 +  gr->GetXaxis()->CenterTitle();
1491 +  gr->GetYaxis()->CenterTitle();
1492 +  
1493 +  gr->Draw("A2");
1494 +  central->Draw("e1,same");
1495 +  DrawMCPrelim();
1496 +  TText *rtitle = write_text(0.8,0.8,title);
1497 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1498 +  line->SetLineColor(kBlue);
1499 +  line->SetLineStyle(2);
1500 +  line->Draw("same");
1501 +  rtitle->Draw("same");
1502 + }
1503 +
1504 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1505 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1506 +  basehisto->Add(originalttbar,-1);
1507 +  basehisto->Add(httbar);
1508 +  
1509 +  string sname=httbar->GetName();
1510 +  sname="R"+sname.substr(1,sname.length());
1511 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1512 +  ratio->Divide(basehisto);
1513 +  delete basehisto;
1514 +  return ratio;
1515 + }
1516 +  
1517 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1518 +  
1519 +  TCut cut=addcut&&basiccut;
1520 +  
1521 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1522 +  ckin->SetLogy(dolog);
1523 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1524 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1525 +  datahisto->SetMarkerSize(DataMarkerSize);
1526 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1527 +  else datahisto->SetMinimum(0.5);
1528 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1529 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1530 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1531 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1532 +  TH1F *MCcentral = CollapseStack(mcstack);
1533 +
1534 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1535 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("/TT_"));
1536 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1537 +  
1538 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1539 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1540 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1541 +  
1542 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1543 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1544 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1545 +  
1546 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1547 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1548 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1549 +  
1550 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1551 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1552 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1553 +  
1554 +  datahisto->Draw("e1");
1555 +  ckin->Update();
1556 +  mcstack.Draw("histo,same");
1557 +  
1558 +  datahisto->Draw("same,e1");
1559 +  TLegend *kinleg = allsamples.allbglegend();
1560 +  kinleg->Draw();
1561 +
1562 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1563 +  kinpad->SetLogy(dolog);
1564 +  kinpad->cd();
1565 +  datahisto->Draw("e1");
1566 +  mcstack.Draw("histo,same");
1567 +  datahisto->Draw("same,e1");
1568 +  datahisto->Draw("same,axis");
1569 +  
1570 +  kinleg->Draw("same");
1571 +  DrawPrelim();
1572 +  string saveas="kin/"+filename;
1573 +  
1574 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1575 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1576 +  delete kinpad;
1577 +  
1578 +  ckin->cd();
1579 +  TCentral->SetLineColor(kBlack);
1580 +  
1581 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1582 +  TMatchingUp->SetLineStyle(2);//dashed
1583 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1584 +  TMatchingDown->SetLineStyle(3);//dotted
1585 +  
1586 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1587 +  TScaleUp->SetLineStyle(2);//dashed
1588 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1589 +  TScaleDown->SetLineStyle(3);//dotted
1590 +  
1591 +  MCcentral->SetLineStyle(3);
1592 +  MCcentral->SetLineColor(kRed);
1593 +  
1594 +  TCentral->Draw("e1,same");
1595 +  TCentral->Draw("histo,same");
1596 +  TMatchingUp->Draw("histo,same");
1597 +  TMatchingDown->Draw("histo,same");
1598 +  TScaleUp->Draw("histo,same");
1599 +  TScaleDown->Draw("histo,same");
1600 +  
1601 +  TLegend *sleg = make_legend();
1602 +  sleg->AddEntry(TCentral,"Central","L");
1603 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1604 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1605 +  sleg->AddEntry(TScaleUp,"scale up","L");
1606 +  sleg->AddEntry(TScaleDown,"scale down","L");
1607 +  sleg->Draw();
1608 +  
1609 +  CompleteSave(ckin,saveas+"___AllLines");
1610 +  ckin->cd();
1611 +  ckin->SetLogy(0);
1612 +  
1613 +  RCentral->SetLineColor(kBlack);
1614 +  
1615 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1616 +  RMatchingUp->SetLineStyle(2);//dashed
1617 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1618 +  RMatchingDown->SetLineStyle(3);//dotted
1619 +  
1620 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1621 +  RScaleUp->SetLineStyle(2);//dashed
1622 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1623 +  RScaleDown->SetLineStyle(3);//dotted
1624 +  
1625 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1626 +  RCentral->Draw("e1");
1627 +  RMatchingUp->Draw("histo,same");
1628 +  RMatchingDown->Draw("histo,same");
1629 +  RScaleUp->Draw("histo,same");
1630 +  RScaleDown->Draw("histo,same");
1631 +  
1632 +  CompleteSave(ckin,saveas+"___AllRatios");
1633 +
1634 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1635 +  multicanvas->Divide(2,1);
1636 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1637 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1638 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1639 +  
1640 +  
1641 +  delete datahisto;
1642 +  delete   TCentral;
1643 +  delete   TMatchingUp;
1644 +  delete   TMatchingDown;
1645 +  delete   TScaleUp;
1646 +  delete   TScaleDown;
1647 + //   delete   Ttmass166;
1648 + //   delete   Ttmass169;
1649 + //   delete   Ttmass175;
1650 + //   delete   Ttmass178;
1651 +  
1652 +  delete ckin;
1653 +  
1654 + }
1655 +  
1656 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1657 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1658 + }
1659 +
1660 + void ProduceJanPlots() {
1661 +  TCanvas *c1 = new TCanvas("c1","c1");
1662 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1663 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1664 +  
1665 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1666 +  rcan->cd();
1667 +
1668 +  metOF->SetLineColor(kRed);
1669 +  metSF->Draw("e1");
1670 +  metOF->Draw("histo,same");
1671 +  metSF->Draw("e1,same");
1672 +  
1673 +  TLegend *leg = make_legend();
1674 +  
1675 +  leg->AddEntry(metSF,"Data SF","p");
1676 +  leg->AddEntry(metOF,"Data OF","l");
1677 +  leg->Draw();
1678 +  
1679 +  DrawPrelim();
1680 +  
1681 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1682 +  
1683 +  delete rcan;
1684 +  delete metSF;
1685 +  delete metOF;
1686 +  delete c1;
1687 + }
1688 +
1689 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1690 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1691 +  
1692 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1693 +  if(variation!="Central") {
1694 +    TH1F *varttbar;
1695 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1696 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1697 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1698 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1699 +    assert(varttbar);
1700 +    
1701 +    TIter nextHisto(SystPlot.GetHists());
1702 +    TH1F* h;
1703 +    while ( h = (TH1F*)nextHisto() ) {
1704 +      if(Contains(h->GetName(),"t_bar_t")) {
1705 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1706 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1707 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1708 +          h->SetBinError(i,varttbar->GetBinError(i));
1709 +        }
1710 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1711 +        SystPlot.Modified();
1712 +      }
1713 +    }
1714 +    delete varttbar;
1715 +  } else {
1716 +    TIter nextHisto(SystPlot.GetHists());
1717 +    TH1F* h;
1718 +    while ( h = (TH1F*)nextHisto() ) {
1719 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1720 +    }
1721 +  }
1722 +    
1723 +  TLegend *fullleg = allsamples.allbglegend();
1724 +  fullleg->SetHeader(variation.c_str());
1725 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1726 +  kinpad->SetLogy(1);
1727 +  kinpad->cd();
1728 +  
1729 +  hdata->Draw("e1");
1730 +  SystPlot.Draw("histo,same");
1731 +  hdata->Draw("e1,same");
1732 +  fullleg->Draw();
1733 +  DrawPrelim();
1734 +  
1735 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1736 +  CleanLegends();
1737 +  
1738 +  delete kinpad;
1739 +  return SystPlot;
1740 + }
1741 +  
1742 +
1743 +
1744 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1745 +  TCanvas *ca = new TCanvas("ca","ca");
1746 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1747 +  
1748 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1749 +  
1750 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1751 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1752 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1753 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1754 +  
1755 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1756 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1757 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1758 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1759 +  
1760 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1761 +  TH1F *HCentral = CollapseStack(Central);
1762 +  
1763 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1764 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1765 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1766 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1767 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1768 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1769 +    
1770 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1771 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1772 +    
1773 +    float sys=sqrt(matching*matching+scale*scale);
1774 +    sys/=HCentral->GetBinContent(i);
1775 +    if(HCentral->GetBinContent(i)==0) sys=0;
1776 +    Systematic->SetBinContent(i,sys);
1777 +  }
1778 +  
1779 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1780 +  kinpad->SetLogy(1);
1781 +  kinpad->cd();
1782 +  if(variable=="genMET") {
1783 +    Central.Draw("histo");
1784 +  } else {
1785 +    hdata->Draw("e1");
1786 +    Central.Draw("histo,same");
1787 +    hdata->Draw("e1,same");
1788 +  }
1789 +  
1790 +  DrawPrelim();
1791 +  
1792 +  save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1793 +  
1794 +  kinpad->cd();
1795 +  tCentral->SetFillColor(kWhite);
1796 +  tCentral->SetLineColor(kBlack);
1797 +  tScaleUp->SetLineColor(kRed);
1798 +  tScaleDown->SetLineColor(kRed);
1799 +  tMatchingUp->SetLineColor(kBlue);
1800 +  tMatchingDown->SetLineColor(kBlue);
1801 +  tScaleUp->SetLineStyle(2);
1802 +  tScaleDown->SetLineStyle(3);
1803 +  tMatchingUp->SetLineStyle(2);
1804 +  tMatchingDown->SetLineStyle(3);
1805 +  
1806 +  TLegend *leg2 = make_legend();
1807 +  leg2->AddEntry(hdata,"Data","p");
1808 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1809 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1810 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1811 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1812 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1813 +  if(variable=="genMET") {
1814 +    Central.Draw("histo");
1815 +  }else {
1816 +    hdata->Draw("e1");
1817 +    Central.Draw("histo,same");
1818 +    hdata->Draw("e1,same");
1819 +  }
1820 +  tCentral->Draw("histo,same");
1821 +  tScaleUp->Draw("histo,same");
1822 +  tScaleDown->Draw("histo,same");
1823 +  tMatchingUp->Draw("histo,same");
1824 +  tMatchingDown->Draw("histo,same");
1825 +  leg2->Draw();
1826 +  
1827 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1828 +  
1829 +  gStyle->SetOptFit(0);
1830 +  
1831 +  kinpad->cd();
1832 +  kinpad->SetLogy(0);
1833 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1834 +  MatchingRatio->Divide(tMatchingDown);
1835 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1836 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1837 +  lone->SetLineStyle(2);
1838 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1839 +  ScaleRatio->Divide(tScaleDown);
1840 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1841 +  MatchingRatio->Draw("e1");
1842 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1843 +  MatchingRatio->Fit("QP1","R");
1844 +  lone->Draw();
1845 +  stringstream summary;
1846 +  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);
1847 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1848 +  TText *infobox = write_title(summary.str());
1849 +  infobox->SetX(0.75);
1850 +  infobox->SetTextSize(0.03);
1851 +  infobox->SetY(0.75);
1852 +  infobox->Draw();
1853 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1854 +  kinpad->cd();
1855 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1856 +  ScaleRatio->Draw("e1");
1857 +  ScaleRatio->Fit("QP1","R");
1858 +  summary.str("");
1859 +  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);
1860 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1861 +  TText *infobox2 = write_title(summary.str());
1862 +  infobox2->SetX(0.75);
1863 +  infobox2->SetTextSize(0.03);
1864 +  infobox2->SetY(0.75);
1865 +  infobox2->Draw();
1866 +
1867 +  lone->Draw();
1868 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1869 +  
1870 +  
1871 +  delete QP1;
1872 +  delete infobox;
1873 +  delete infobox2;
1874 +  delete MatchingRatio;
1875 +  delete ScaleRatio;
1876 +  DeleteStack(ScaleUp);
1877 +  DeleteStack(ScaleDown);
1878 +  DeleteStack(MatchingUp);
1879 +  DeleteStack(MatchingDown);
1880 +  delete leg2;
1881 +  CleanLegends();
1882 +  DeleteStack(Central);
1883 +  delete Systematic;
1884 +  delete HScaleUp;
1885 +  delete HScaleDown;
1886 +  delete HMatchingUp;
1887 +  delete HMatchingDown;
1888 +  delete hdata;
1889 +  delete HCentral;
1890 +  delete ca;
1891 + }
1892 +
1893 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1894 +  float val=0,err=0;
1895 +  vector<float> bins;
1896 +  vector<float> vals;
1897 +  vector<float> errs;
1898 +  
1899 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1900 +  int iBin=1;
1901 +  
1902 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1903 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1904 +      bins.push_back(histo->GetBinLowEdge(i));
1905 +      vals.push_back(val);val=0;
1906 +      errs.push_back(err);err=0;
1907 +      iBin++;
1908 +    }
1909 +    val+=histo->GetBinContent(i);
1910 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1911 +  }
1912 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1913 +  vals.push_back(val);val=0;
1914 +  errs.push_back(err);err=0;
1915 +  
1916 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1917 +  for(unsigned int i=0;i<vals.size();i++) {
1918 +    h->SetBinContent(i+1,vals[i]);
1919 +    h->SetBinError(i+1,errs[i]);
1920 +  }
1921 +  
1922 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1923 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1924 +  
1925 +  h->GetXaxis()->CenterTitle();
1926 +  h->GetYaxis()->CenterTitle();
1927 +
1928 +  return h;
1929 + }
1930 +
1931 +
1932 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1933 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1934 +  float val=0,err=0;
1935 +  vector<float> bins;
1936 +  vector<float> vals;
1937 +  vector<float> errs;
1938 +  
1939 +  bins.push_back(histo->GetBinLowEdge(1));
1940 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1941 +    val+=histo->GetBinContent(i);
1942 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1943 +    if( val/statsperbin > 0.85) {
1944 +      if(bins.size()<nbins) {
1945 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1946 +        vals.push_back(val);val=0;
1947 +        errs.push_back(err);err=0;
1948 +      }
1949 +    }
1950 +    if(i==histo->GetNbinsX()) {
1951 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1952 +      vals.push_back(val);val=0;
1953 +      errs.push_back(err);err=0;
1954 +    }
1955 +  }
1956 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
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 +  for(unsigned int i=0;i<vals.size();i++) {
1965 +    h->SetBinContent(i+1,vals[i]);
1966 +    h->SetBinError(i+1,errs[i]);
1967 +  }
1968 +  
1969 +  return h;
1970 + }
1971 +
1972 +
1973 +  
1974 + void ShowBinning(TH1F *histo) {
1975 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1976 +  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;
1977 + }
1978 +  
1979 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1980 +  TCanvas *ca = new TCanvas("ca","ca");
1981 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1982 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1983 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1984 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1985 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1986 +  
1987 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
1988 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
1989 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1990 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1991 +  tCentral->Scale(1.0/tCentral->Integral());
1992 +  
1993 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1994 +  
1995 +  
1996 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1997 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1998 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1999 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
2000 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
2001 +  
2002 +  float min=rtScaleUp->GetMinimum();
2003 +  float max=rtScaleUp->GetMaximum();
2004 +  
2005 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
2006 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2007 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
2008 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
2009 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
2010 +  
2011 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
2012 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2013 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
2014 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
2015 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
2016 +  
2017 +  rtCentral->SetMaximum(1.2*max);
2018 +  rtCentral->SetMinimum(0.8*min);
2019 +  
2020 + /*  tScaleUp->Rebin(40);
2021 +  tScaleDown->Rebin(40);
2022 +  tMatchingDown->Rebin(40);
2023 +  tMatchingUp->Rebin(40);
2024 +  tCentral->Rebin(40);*/
2025 +  
2026 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2027 +  kinpad->SetLogy(1);
2028 +  kinpad->cd();
2029 +  tCentral->SetFillColor(kWhite);
2030 +  tCentral->SetLineColor(kBlack);
2031 +  tScaleUp->SetLineColor(kRed);
2032 +  tScaleDown->SetLineColor(kRed);
2033 +  tMatchingUp->SetLineColor(kBlue);
2034 +  tMatchingDown->SetLineColor(kBlue);
2035 +  tScaleUp->SetLineStyle(2);
2036 +  tScaleDown->SetLineStyle(3);
2037 +  tMatchingUp->SetLineStyle(2);
2038 +  tMatchingDown->SetLineStyle(3);
2039 +  
2040 +  rtScaleDown->SetLineColor(kRed);
2041 +  rtMatchingUp->SetLineColor(kBlue);
2042 +  rtMatchingDown->SetLineColor(kBlue);
2043 +  rtScaleUp->SetLineStyle(2);
2044 +  rtScaleDown->SetLineStyle(3);
2045 +  rtMatchingUp->SetLineStyle(2);
2046 +  rtMatchingDown->SetLineStyle(3);
2047 +  
2048 +  TLegend *leg2 = make_legend();
2049 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
2050 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
2051 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
2052 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
2053 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
2054 +  
2055 +  tCentral->Draw("histo");
2056 +  tScaleUp->Draw("histo,same");
2057 +  tScaleDown->Draw("histo,same");
2058 +  tMatchingUp->Draw("histo,same");
2059 +  tMatchingDown->Draw("histo,same");
2060 +  leg2->Draw();
2061 +  DrawMCPrelim();
2062 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
2063 +  kinpad->cd();
2064 +  kinpad->SetLogy(0);
2065 +  rtCentral->Draw("histo");
2066 +  rtScaleUp->Draw("histo,same");
2067 +  rtScaleDown->Draw("histo,same");
2068 +  rtMatchingUp->Draw("histo,same");
2069 +  rtMatchingDown->Draw("histo,same");
2070 +  leg2->Draw();
2071 +  DrawMCPrelim();
2072 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
2073 +  
2074 +  
2075 +  gStyle->SetOptFit(0);
2076 +
2077 +  kinpad->cd();
2078 +  kinpad->SetLogy(0);
2079 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
2080 +  MatchingRatio->Divide(rtMatchingDown);
2081 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
2082 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
2083 +  lone->SetLineStyle(2);
2084 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
2085 +  ScaleRatio->Divide(rtScaleDown);
2086 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
2087 +  MatchingRatio->Draw("e1");
2088 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
2089 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
2090 +  lone->Draw();
2091 +  stringstream summary;
2092 +  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);
2093 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2094 +  TText *infobox = write_title(summary.str());
2095 +  infobox->SetX(0.75);
2096 +  infobox->SetTextSize(0.03);
2097 +  infobox->SetY(0.75);
2098 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
2099 +  DrawMCPrelim();
2100 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
2101 +  kinpad->cd();
2102 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
2103 +  ScaleRatio->Draw("e1");
2104 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
2105 +  summary.str("");
2106 +  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);
2107 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
2108 +  TText *infobox2 = write_title(summary.str());
2109 +  infobox2->SetX(0.75);
2110 +  infobox2->SetTextSize(0.03);
2111 +  infobox2->SetY(0.75);
2112 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
2113 +
2114 +  lone->Draw();
2115 +  DrawMCPrelim();
2116 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
2117 +  
2118 +  kinpad->cd();
2119 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
2120 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
2121 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
2122 +  
2123 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
2124 +    float matching, scale;
2125 +    bool AssumeFactor=false;
2126 +    if(AssumeFactor) {
2127 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
2128 +      matching=0.;
2129 +      scale=0.;
2130 +    } else {
2131 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
2132 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
2133 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
2134 +    }
2135 +    
2136 +    SysMatching->SetBinContent(i,1+matching);
2137 +    SysScale->SetBinContent(i,1+scale);
2138 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
2139 +  }
2140 +  
2141 +  SysHisto->SetLineColor(kGreen);
2142 +  
2143 +  SysMatching->SetMaximum(3.0);
2144 +  SysMatching->SetMinimum(0.0);
2145 +  SysMatching->Draw("histo");
2146 +  SysScale->Draw("histo,same");
2147 +  SysHisto->Draw("histo,same");
2148 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
2149 +  
2150 +  delete SysMatching;
2151 +  delete SysScale;
2152 +  
2153 +  if(!Contains(variable,"gen")) {
2154 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
2155 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
2156 +    
2157 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
2158 +    
2159 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
2160 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
2161 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
2162 +      float sys = SysHisto->GetBinContent(iBin)-1;
2163 +      Systematic->SetBinContent(i,sys);
2164 +    }
2165 +    
2166 +    kinpad->cd();
2167 +    TLegend *leg = allsamples.allbglegend();
2168 +    hdata->Draw();
2169 +    smc.Draw("histo,same");
2170 +    hdata->Draw("same");
2171 +    leg->Draw();
2172 +    DrawPrelim();
2173 +    save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
2174 +    
2175 +    delete Systematic;
2176 +    delete hdata;
2177 +  }
2178 +  
2179 +  
2180 +  delete SysHisto;
2181 +  delete tScaleUp;
2182 +  delete tScaleDown;
2183 +  delete tCentral;
2184 +  delete tMatchingUp;
2185 +  delete tMatchingDown;
2186 +  delete rtScaleUp;
2187 +  delete rtScaleDown;
2188 +  delete rtCentral;
2189 +  delete rtMatchingUp;
2190 +  delete rtMatchingDown;
2191 +  delete QP1;
2192 +  delete infobox;
2193 +  delete infobox2;
2194 +  delete MatchingRatio;
2195 +  delete ScaleRatio;
2196 +  delete leg2;
2197 +  CleanLegends();
2198 +  delete ca;
2199 + }
2200 +
2201 + void ProduceMCSystematicPlots() {
2202 +  cout << "Getting ready to produce systematic plots " << endl;
2203 +  TCut cutweightBKP = cutWeight;
2204 +  
2205 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
2206 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
2207 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
2208 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
2209 +  
2210 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
2211 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
2212 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
2213 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
2214 +  
2215 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
2216 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
2217 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
2218 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
2219 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
2220 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
2221 +  
2222 +  
2223 +  
2224 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2225 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2226 +  cutWeight="1.0";
2227 +  
2228 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2229 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
2230 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2231 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2232 +  
2233 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
2234 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
2235 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2236 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2237 +  
2238 +  
2239 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
2240 +  
2241 +  /*
2242 +  cutWeight=cutweightBKP;
2243 +  TCut essentialcutBKP = essentialcut;
2244 +  cout << (const char*) essentialcut << endl;
2245 +  
2246 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
2247 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2248 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2249 +  
2250 +  TCut cutnJetsBKP = cutnJets;
2251 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
2252 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
2253 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
2254 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
2255 +  
2256 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
2257 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
2258 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
2259 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
2260 +  
2261 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
2262 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
2263 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2264 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
2265 +  
2266 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
2267 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
2268 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
2269 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
2270 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
2271 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
2272 +  
2273 +  
2274 +  
2275 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
2276 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
2277 +  cutWeight="1.0";
2278 +  
2279 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2280 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
2281 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2282 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
2283 +  
2284 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
2285 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
2286 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
2287 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
2288 +  
2289 +  cutnJets  = cutnJetsBKP;
2290 +  cutWeight = cutweightBKP;
2291 +  essentialcut = essentialcutBKP;
2292 +  */
2293 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
2294 + }
2295 +
2296 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
2297 +  TCut cut=pcut&&basiccut;
2298 +  string variable="mll";
2299 +  string xlabel="m_{ll} [GeV]";
2300 +  int nbins=40;
2301 +  float min=0;
2302 +  float max=200;
2303 +
2304 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
2305 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
2306 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
2307 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2308 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
2309 +  datahistoSF->SetMarkerSize(DataMarkerSize);
2310 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
2311 +  datahistoOF->SetMarkerSize(DataMarkerSize);
2312 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
2313 +
2314 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
2315 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
2316 +  datahistoSF->Draw("e1");
2317 +  ckin->Update();
2318 +  mcstackSF.Draw("histo,same");
2319 +  
2320 +  datahistoSF->Draw("same,e1");
2321 +  TLegend *kinleg = allsamples.allbglegend();
2322 +  kinleg->Draw();
2323 +  
2324 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
2325 +  kinpad->cd();
2326 +  datahistoSF->Draw("e1");
2327 +  mcstackSF.Draw("histo,same");
2328 +  datahistoSF->Draw("same,e1");
2329 +  datahistoSF->Draw("same,axis");
2330 +  kinleg->Draw();
2331 +  DrawPrelim();
2332 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
2333 +  
2334 +  kinpad->cd();
2335 +  datahistoOF->Draw("e1");
2336 +  mcstackOF.Draw("histo,same");
2337 +  datahistoOF->Draw("same,e1");
2338 +  datahistoOF->Draw("same,axis");
2339 +  kinleg->Draw();
2340 +  DrawPrelim();
2341 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
2342 +  
2343 +  kinpad->cd();
2344 +  tauSF->Draw("e1");
2345 +  tauOF->Draw("histo,same");
2346 +  tauSF->Draw("e1,same");
2347 +  TLegend *legtau = make_legend();
2348 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
2349 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
2350 +  legtau->Draw();
2351 +  DrawPrelim();
2352 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
2353 +  
2354 +  delete datahistoSF;
2355 +  delete datahistoOF;
2356 +  delete tauSF;
2357 +  delete tauOF;
2358 +  delete kinpad;
2359 +  delete ckin;
2360 +  CleanLegends();
2361 + }
2362 +  
2363 +
2364 + void TauQuestion() {
2365 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2366 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2367 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2368 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2369 + }
2370 +
2371 + void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2372 +  string BaseMetCut="met[4]>100";
2373 +  string Prefix="ETH/";
2374 +  if(isAachen) {
2375 +    BaseMetCut="met[4]>150";
2376 +    Prefix="Aachen/";
2377 +  }
2378 + //        make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "S_{T}", Prefix+"FrankT");
2379 +      make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2380 +
2381 +      make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2382 +      make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2383 +      make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2384 +  
2385 + //      make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2386 +      make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2387 +      make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2388 +      make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2389 +      
2390 + //      make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2391 + //      make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2392 +
2393 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut,                        7, 3, 10, true, "#(jets)", Prefix+"njets");
2394 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2395 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2396 +
2397 + //      make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 5, -0.5, 4.5, true, "N_{b-jets}", Prefix+"nbjets");
2398 + //      make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2399 + //      make_OFSF_plots("pfJetGoodPt",  BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2400 +
2401 + //      make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2402 + //      make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2403 +      make_OFSF_plots("pt",  BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2404 +      make_OFSF_plots("pt1",  BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2405 +      make_OFSF_plots("pt2",  BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2406 + //      make_OFSF_plots("eta1", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{1}", Prefix+"eta1", 0.15);
2407 + //      make_OFSF_plots("eta2", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{2}", Prefix+"eta2", 0.15);
2408 + //      make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", 0.2);
2409 + //      make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", 0.2);
2410 + //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", 0.2);
2411 + //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", 0.2);
2412 +    
2413 + //      make_OFSF_plots("met[4]",  BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET");
2414 + //      make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", 0.2);
2415 + //      make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", 0.2);
2416 + //      make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", 0.2);
2417 + //      make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2418 + //      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");
2419 + //      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");
2420 + //      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");
2421 +      
2422 + }
2423 +
2424 + void ProduceOFSFPlots(string mcjzb, string datajzb) {
2425 +  
2426 +  
2427 +  //FIRST : ETH SELECTION
2428 +  ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2429 +  
2430 +  
2431 +  
2432 +  string backup_cutnJets = (const char*)cutnJets;
2433 +  cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2434 +  cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2435 +  
2436 +  string backup_basiccut = (const char*)basiccut;
2437 +  basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2438 +  
2439 +  string backup_essential = (const char*) essentialcut;
2440 +  essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2441 +  
2442 +  ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2443 +  
2444 +  cutnJets     = TCut(backup_cutnJets.c_str());
2445 +  basiccut     = TCut(backup_basiccut.c_str());
2446 +  essentialcut = TCut(backup_essential.c_str());
2447 + }
2448 +  
2449  
2450   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2451   {
# Line 891 | Line 2454 | void do_kinematic_plots(string mcjzb, st
2454    bool nolog=false;
2455  
2456    bool doOFSF = false;
2457 <  bool doKin  = true;
2457 >  bool doKin  = false;
2458    bool doDataComp = false;
2459    bool MakeTwoThreeJetComparison = false;
2460    
# Line 905 | Line 2468 | void do_kinematic_plots(string mcjzb, st
2468    }
2469    
2470    if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2471 +  
2472 +  //TauQuestion();
2473  
2474 <  if ( doOFSF ) {
2475 <     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2476 <
2477 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2478 < //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2479 < //      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 <  }
2474 >  //ProduceJanPlots();
2475 >  //ProduceMCSystematicPlots();
2476 >  //assert(0);
2477 > //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2478 >  
2479 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2480  
2481    if ( doDataComp) {
2482      TCut mllCut("");
# Line 949 | Line 2492 | void do_kinematic_plots(string mcjzb, st
2492  
2493      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2494      
2495 < /*    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2495 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2496      make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2497      
2498      
# Line 960 | Line 2503 | void do_kinematic_plots(string mcjzb, st
2503      make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2504      
2505      make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2506 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2506 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2507      make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2508 < //    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2509 < */
2508 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2509 >
2510    
2511      string basiccutsaved = (const char*)basiccut;
2512      
# Line 975 | Line 2518 | void do_kinematic_plots(string mcjzb, st
2518        newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2519        found = newbasiccut.find( "pt2>20" );
2520      }
2521 < //    basiccut=TCut(newbasiccut.c_str());
2522 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2523 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2524 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2525 < //    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2526 < //    basiccut=TCut(basiccutsaved.c_str());
2527 <    
2528 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2529 < //     make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2530 <    
2531 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2532 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2533 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2534 < //     make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2535 <
2536 <    
2537 < /*     make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2538 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2539 <     make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2540 <     make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2521 >    basiccut=TCut(newbasiccut.c_str());
2522 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2523 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2524 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2525 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2526 >    basiccut=TCut(basiccutsaved.c_str());
2527 >    
2528 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2529 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2530 >    
2531 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2532 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2533 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2534 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2535 >
2536 >    
2537 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2538 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2539 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2540 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2541      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2542      make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2543      make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2544      make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2545 < */
2545 >
2546      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2547      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2548      
# Line 1012 | Line 2555 | void do_kinematic_plots(string mcjzb, st
2555      make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2556      make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2557  
2558 < /*
2558 >
2559      make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2560      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");
2561      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 2564 | void do_kinematic_plots(string mcjzb, st
2564      make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2565      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2566      make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2567 <  */
2567 >
2568    }
2569  
2570  
2571    if ( doKin ) {
2572      string mllCut("");
2573 < /*  
2573 >    /*
2574 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2575 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2576 >
2577 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2578 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2579 >
2580 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2581 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2582 >    
2583 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2584 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2585 >    
2586 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2587 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2588 >    
2589 >    make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2590 >    make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2591 >    
2592 >    make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2593 >    make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2594 >    
2595 >    
2596 >    assert(0);
2597 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2598 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2599 >  
2600      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);
2601      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);
2602      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 2606 | void do_kinematic_plots(string mcjzb, st
2606      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);
2607      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);
2608      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);
2609 < */
2610 <    
2609 >
2610 >
2611 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2612 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2613 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2614 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2615 >
2616      
2617      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);
2618      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 2624 | void do_kinematic_plots(string mcjzb, st
2624      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);
2625      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);
2626  
2627 <     /*make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2628 <     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);*/
1058 <    
1059 < /*     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);
1060 <     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);
1061 <    
1062 <     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);
1063 <     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");
1066 <    
2627 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2628 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2629      
2630 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2631 +    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2632      
2633 +    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);
2634 +    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);
2635      
2636 +    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);
2637 +    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);
2638 +
2639      
2640 +    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2641 +    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2642 +    // Plots in signal region
2643 +    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2644 +
2645 +
2646 +    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2647      
2648 +    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");
2649 +    /*
2650 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2651 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2652 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2653 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2654 +
2655 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2656 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2657 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2658 +    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2659 +
2660 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2661 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2662 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2663 +    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2664 +
2665 +    
2666 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2667 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2668 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2669 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2670 +
2671 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2672 +    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2673 +
2674 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2675 +    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2676      
2677 <    
2678 <     return;
2679 <    
2680 <    
2681 <    
2682 <     make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2683 <     make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2684 <    // Plots in signal region
2685 < //     make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2686 <     make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2687 <     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);
2688 <     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);
2689 <     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);
2690 <    
2691 <     make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2692 <     make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2693 <    
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);
2677 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2678 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2679 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2680 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2681 >
2682 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2683 >    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);
2684 >    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);
2685 >    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);
2686 >    
2687 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2688 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2689 >    
2690 >    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);
2691 >    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);
2692 >    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);
2693 >    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);
2694      
2695      
2696 < //     make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2697 < //     make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2696 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2697 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2698  
2699      // Further inclusive invariant mass plots
2700      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2701 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2702 < //     make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2701 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2702 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2703      make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2704      
2705 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2705 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2706      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2707      
2708      
2709      // Number of jets
2710      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2711      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2712 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2712 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2713      
2714      // Others
2715      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 1141 | Line 2741 | void do_kinematic_plots(string mcjzb, st
2741      
2742      //   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);
2743      //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);
2744 <    //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);
2744 >    //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);*/
2745    }
2746      
2747 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2748 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2749 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2750 <   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2751 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2752 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2753 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2754 <
2755 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2756 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2757 <
2747 >   int jzbcuts[7]={0,50,80,100,150,200,250};
2748 >   int MCorData[2]={data,mc};
2749 >  
2750 >   write_warning(__FUNCTION__,"Skipping data altogether");
2751 >   for(int d=1;d<2;d++) {
2752 >     for(int j=0;j<7;j++) {
2753 >       make_special_obs_pred_mll_plot(datajzb,mcjzb,jzbcuts[j],5.0,MCorData[d]); // 5.0 is the binwidth
2754 >     }
2755 >   }
2756 >  
2757 > /*
2758 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2759 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2760 > */
2761    switch_overunderflow(false);
2762   }
2763  
# Line 1176 | Line 2779 | void make_comp_plot( string var, string
2779    }
2780    
2781    string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
2782 +  if(!RestrictToMassPeak) {
2783 +    sRegions[0]="SF";
2784 +    sRegions[1]="OF";
2785 +  }
2786    TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass,     cutOSOF&&cutnJets&&cutmass,
2787                        cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
2788    
# Line 1238 | Line 2845 | void region_comparison_plots(string mcjz
2845      make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2846  
2847      make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2848 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2848 >    make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2849      make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2850      make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2851      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
# Line 1270 | Line 2877 | void signal_bg_comparison()
2877    
2878    float simulatedlumi=luminosity;//in pb please - adjust to your likings
2879    
2880 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
2880 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2881    TH1F *JZBplotLM4;
2882    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"));
2883    else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2884 <  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
2884 >  TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TT_"));
2885    
2886    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
2887    JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
# Line 1285 | Line 2892 | void signal_bg_comparison()
2892  
2893    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2894    JZBplotTtbar->SetMinimum(0.01);
2895 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2895 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2896    JZBplotTtbar->DrawClone("histo");
2897    JZBplotZJETs->Draw("histo,same");
2898    JZBplotTtbar->SetFillColor(0);
2899    JZBplotTtbar->DrawClone("histo,same");
2900 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2900 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2901    JZBplotLM4->Draw("histo,same");
2902  
2903  
# Line 1328 | Line 2935 | void signal_bg_comparison()
2935    // Draw all plots overlaid
2936    JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
2937    JZBplotTtbar->SetMinimum(0.01);
2938 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2938 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2939    JZBplotTtbar->DrawClone("histo");
2940    JZBplotZJETs->Draw("histo,same");
2941    JZBplotTtbar->SetFillColor(0);
2942    JZBplotTtbar->DrawClone("histo,same");
2943 <  JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
2943 >  JZBplotTtbar->SetFillColor(allsamples.GetColor("TT_"));
2944  
2945    JZBplotSMS1->SetLineColor(kRed+1);
2946    JZBplotSMS2->SetLineColor(kBlue+1);
# Line 1540 | Line 3147 | if you want to start from scratch (witho
3147    return return_functions;
3148   }
3149  
3150 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3150 > void do_prediction_plot(TCut addcut, string Cname, string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
3151   {
3152    
3153    bool is_data=false;
# Line 1561 | Line 3168 | void do_prediction_plot(string jzb, TCan
3168    
3169    
3170    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3171 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3172 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3173 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3174 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3171 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3172 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3173 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3174 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3175  
3176    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3177    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1580 | Line 3187 | void do_prediction_plot(string jzb, TCan
3187    TH1F *RcorrJZBeemmNoS;
3188  
3189    //these are for the ratio
3190 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3191 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3192 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3193 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3190 >  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);
3191 >  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);
3192 >  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);
3193 >  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);
3194    
3195    TH1F *JRcorrJZBSBem;
3196    TH1F *JLcorrJZBSBem;
3197    TH1F *JRcorrJZBSBeemm;
3198    TH1F *JLcorrJZBSBeemm;
3199    
3200 <  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);
3200 >  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);
3201  
3202    
3203    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3204 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3205 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3206 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3207 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3204 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3205 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3206 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3207 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3208      
3209      //these are for the ratio
3210 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3211 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3212 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3213 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3210 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3211 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3212 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3213 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", addcut&&cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3214    }
3215    
3216    TH1F *lm4RcorrJZBeemm;
3217 <  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"));
3217 >  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"));
3218    
3219    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3220    
# Line 1744 | Line 3351 | void do_prediction_plot(string jzb, TCan
3351      
3352      jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3353      jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
3354 <    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3355 <    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
3354 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3355 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TT_"))[0]));
3356      
3357      THStack predcomposition("predcomposition","prediction composition");
3358      predcomposition.Add(sidebandsemu);
# Line 1771 | Line 3378 | void do_prediction_plot(string jzb, TCan
3378   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3379   //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3380      speciallegBpred->Draw();
3381 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3381 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition"+Cname,true,true,"data/pred",BpredSys);
3382 >    delete predcomppad;
3383      
3384      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3385      specialcanv->SetLogy(1);
# Line 1837 | Line 3445 | void do_prediction_plot(string jzb, TCan
3445        
3446        RcorrJZBeemmNoS->SetLineStyle(2);
3447        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3448 < //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3448 >      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3449        legBpred2->Draw();
3450        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3451        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1850 | Line 3458 | void do_prediction_plot(string jzb, TCan
3458    }
3459  
3460  
3461 +  Bpredsaveas+="_"+Cname+"_";
3462    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3463    string ytitle("ratio");
3464    if ( use_data==1 ) ytitle = "data/pred";
3465    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3466 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3466 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3467 >  
3468 >  delete kinpad;
3469  
3470  
3471    
# Line 1896 | Line 3507 | void do_prediction_plot(string jzb, TCan
3507      if(use_data==1)
3508      {
3509        legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3510 <      legBpredc->AddEntry(Bpredem,"OFZP","l");
3511 <      legBpredc->AddEntry(BpredSBem,"OFSB","l");
3512 <      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3510 >      if(RestrictToMassPeak) {
3511 >        legBpredc->AddEntry(Bpredem,"OFZP","l");
3512 >        legBpredc->AddEntry(BpredSBem,"OFSB","l");
3513 >        legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3514 >      } else legBpredc->AddEntry(Bpredem,"OF","l");
3515 >        
3516 >        
3517        legBpredc->Draw();
3518        CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3519      }
3520      if(use_data==0) {
3521        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3522 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3523 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3524 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3522 >      if(RestrictToMassPeak) {
3523 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3524 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3525 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3526 >      } else legBpredc->AddEntry(Bpredem,"MC OF","l");
3527 >        
3528        legBpredc->Draw();
3529        CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3530      }
3531      if(use_data==2) {
3532        legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3533 <      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3534 <      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3535 <      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3533 >      if(RestrictToMassPeak) {
3534 >        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3535 >        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3536 >        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3537 >      } else {
3538 >        legBpredc->AddEntry(Bpredem,"MC OF","l");
3539 >      }
3540   //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3541        legBpredc->Draw();
3542        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3543      }
3544    }
3545    
1924  TFile *f = new TFile("tester.root","RECREATE");
1925  RcorrJZBeemm->Write();
1926  Bpred->Write();
1927  f->Close();
1928  
3546    delete RcorrJZBeemm;
3547    delete LcorrJZBeemm;
3548    delete RcorrJZBem;
# Line 1955 | Line 3572 | void do_prediction_plot(string jzb, TCan
3572  
3573   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3574    switch_overunderflow(true);
3575 +  
3576 +  TCut cuts[3] = {TCut("mll>0"),Restrmasscut,TCut("mll>20&&mll<70")};
3577 +  string cutnames[3] = {"NoMassCut","ZWindow","LowMassRegion2070"};
3578 +  
3579    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3580 <  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3581 <  if ( !PlottingSetup::Approved ) {
3582 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3583 <    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3584 <  } else {
3585 <    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3580 >  for(int i=0;i<3;i++) {
3581 >    do_prediction_plot(cuts[i],cutnames[i],datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3582 >    if ( !PlottingSetup::Approved ) {
3583 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3584 >      do_prediction_plot(cuts[i],cutnames[i],mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3585 >    } else {
3586 >      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3587 >    }
3588    }
3589 +  
3590    delete globalcanvas;
3591    switch_overunderflow(false);
3592   }
# Line 1987 | Line 3611 | void lepton_comparison_plots() {
3611    Float_t ymin = 1.e-5, ymax = 0.25;
3612    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3613    can->SetLogy(1);
3614 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
3615 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
3614 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3615 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3616    eemc->SetLineColor(kBlue);
3617    mmmc->SetLineColor(kRed);
3618    eemc->SetMinimum(0.1);
# Line 2051 | Line 3675 | void lepton_comparison_plots() {
3675    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3676    eemmlegend->Draw();
3677    DrawPrelim();
3678 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3678 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3679    
3680 <  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"));
3681 <  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"));
3682 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
3680 >  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"));
3681 >  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"));
3682 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJetsToLL"));
3683    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3684    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3685    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 2174 | Line 3798 | void draw_pure_jzb_histo(TCut cut,string
3798    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3799    writeline1->SetTextSize(0.035);
3800    writeline1->Draw();
3801 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3802 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3801 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3802 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3803    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3804    jzbpad2->cd();
3805    jzbpad2->SetLogy(1);
# Line 2190 | Line 3814 | void draw_pure_jzb_histo(TCut cut,string
3814    writeline1->SetTextSize(0.035);
3815    writeline1->Draw();
3816    DrawPrelim();
3817 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3818 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3817 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3818 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3819    datahisto->Delete();
3820    mcstack.Delete();
3821   }
# Line 2259 | Line 3883 | void diboson_plots(string mcjzb, string
3883    TCanvas *gloca = new TCanvas("gloca","gloca");
3884    
3885    dout << "Going to produce prediction plots" << endl;
3886 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3887 <  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3886 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3887 >  do_prediction_plot(TCut("mll>0"),"",mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3888    delete gloca;
3889  
3890    dout << "Going to reset the cross section for diboson samples ... " << endl;
# Line 2299 | Line 3923 | void draw_normalized_data_vs_data_histo(
3923    leg->AddEntry(datahisto2,legentry2.c_str());
3924    leg->Draw();
3925    
3926 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3926 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3927    
3928    datahisto1->Delete();
3929    datahisto2->Delete();
# Line 2388 | Line 4012 | string jzb_tex_command(string region, st
4012   //  \SFZPJZBPOS
4013   //  Sample &  \OFZPJZBPOS  & \OFZPJZBNEG &  \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS  & \OFSBJZBNEG  & \SFSBJZBPOS  & \SFSBJZBNEG  \\\hline
4014    
4015 +  
4016 + void compute_Improved_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4017 +  dout << "Calculating background yields in MC:" << endl;
4018 +  
4019 +  TCanvas *yica = new TCanvas("yica","yield canvas");
4020 +  
4021 +  int nRegions=2;
4022 +  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
4023 +  string tsRegions[] = {"SFZP","OFZP"};
4024 +  string posneg[] = {"pos","neg"};
4025 +  TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass};
4026 +
4027 +  
4028 +  
4029 +  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
4030 +    TCut posJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos");
4031 +    TCut negJZB = give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg");
4032 +    
4033 +    dout << "_________________________________________________________" << endl;
4034 +    dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
4035 +    
4036 +    
4037 +    THStack *spstack = new THStack(allsamples.DrawStack("spstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4038 +    THStack *snstack = new THStack(allsamples.DrawStack("snstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSSF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4039 +    THStack *opstack = new THStack(allsamples.DrawStack("opstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&posJZB,mc,luminosity));
4040 +    THStack *onstack = new THStack(allsamples.DrawStack("onstack","mll<10e6||mll>1",1,0,500,"tester","events",cutOSOF&&cutnJets&&cutmass&&negJZB,mc,luminosity));
4041 +    
4042 +    
4043 +    vector<pair<string,Value> > obs_yields     = WriteYield(spstack, -10, 10, true);
4044 +    vector<pair<string,Value> > neg_sf_yields  = WriteYield(snstack, -10, 10, true);
4045 +    vector<pair<string,Value> > pos_of_yields  = WriteYield(opstack, -10, 10, true);
4046 +    vector<pair<string,Value> > neg_of_yields  = WriteYield(onstack, -10, 10, true);
4047 +    
4048 +    Value TotObs=Value(0,0);
4049 +    Value TotPred=Value(0,0);
4050 +    
4051 +    for(int ientry=0;ientry<obs_yields.size();ientry++) {
4052 +      if(Contains(obs_yields[ientry].first,"t_bar_t")) continue; // ttbar
4053 +      if(Contains(obs_yields[ientry].first,"W_Jets")) continue; // W+Jets
4054 +      if(Contains(obs_yields[ientry].first,"WW_")) continue; // WW (fully flavor symmetric)
4055 +      if(Contains(obs_yields[ientry].first,"Single_top")) continue; // Single Top
4056 +      if(Contains(obs_yields[ientry].first,"ee_mumu")) continue; // DY
4057 +      if(Contains(obs_yields[ientry].first,"tau_tau")) continue; // DY
4058 +      Value pred = neg_sf_yields[ientry].second + pos_of_yields[ientry].second - neg_of_yields[ientry].second;
4059 +      Value obs=obs_yields[ientry].second;
4060 +      Value diff=obs-pred;
4061 +      dout << obs_yields[ientry].first << "\t & \t " << obs << " \t & \t " << pred << "\t & \t " << diff << endl;
4062 +      TotObs=TotObs+obs_yields[ientry].second;
4063 +      TotPred=TotPred+pred;
4064 +    }
4065 +    
4066 +    float Systematic=sqrt(pow(TotPred.getValue(),2)*0.5*0.5 + pow(TotObs.getValue(),2)*0.5*0.5);
4067 +
4068 +        
4069 +  }
4070 +  
4071 +  delete yica;
4072 + }
4073 +      
4074   void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
4075    dout << "Calculating background yields in MC:" << endl;
4076    
# Line 2483 | Line 4166 | void draw_ttbar_and_zjets_shape_for_one_
4166    TText *titlecenter;
4167    bool frommc=false;
4168    if(frommc) {
4169 <    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
4169 >    osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TT_"));
4170      titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
4171    }
4172    else {
# Line 2702 | Line 4385 | float find_one_correction_factor(string
4385    }
4386    niceresponseplotd->Add(emuResponse,-1);
4387    
4388 +  //TF1 *resp_func = new TF1("resp_func","[0]+[1]/x + [2]/pow(x,2)",10,600);
4389 +  
4390    niceresponseplotd->SetStats(0);
4391    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
4392    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 2711 | Line 4396 | float find_one_correction_factor(string
4396    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
4397    profd->Rebin(2);
4398    profd->SetMarkerSize(DataMarkerSize);
4399 <  profd->Fit("pol0","","same,e1",100,400);
4399 >  //profd->Fit(resp_func,"","same,e1",10,400);
4400 >  profd->Fit("pol2","","same,e1",10,400);
4401 >  //resp_func->SetLineColor(kBlue);
4402    DrawPrelim();
4403    string stitle="Data";
4404    if(!Contains(FindKeyword,"Data")) stitle="MC";
4405    TText* title = write_text(0.5,0.7,stitle.c_str());
4406    title->SetTextAlign(12);
4407    title->Draw();
4408 + //  TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4409    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
4410    float correction=datapol->GetParameter(0);
4411 +  
4412 + //  float correction=resp_func->GetParameter(0);
4413    stringstream resstring;
4414    resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
4415    TText* restitle = write_text(0.5,0.65,resstring.str());
# Line 2740 | Line 4430 | void find_correction_factors(string &jzb
4430    float datacorrection=find_one_correction_factor("Data",true,"","Data");
4431    float mccorrection=find_one_correction_factor("DY",false,"","MC");
4432    
4433 <  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4433 > /*  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
4434    float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
4435    
4436    float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
4437    float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
4438 <  
4438 >  */
4439    cout << "Corrections : " << endl;
4440    cout << "   Data : " << datacorrection << endl;
4441 <  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4441 > //   cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
4442    cout << "   MC : " << mccorrection << endl;
4443 <  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4443 > //   cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
4444    
4445    //Step 2: Processing the result and making it into something useful :-)
4446    stringstream jzbvardatas;
4447    jzbvardatas << "(";
4448    
4449 +  /*
4450    if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
4451    if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
4452    
# Line 2769 | Line 4460 | void find_correction_factors(string &jzb
4460    
4461    jzbvardatas << ")";
4462    jzbvardata=jzbvardatas.str();
4463 <  
4463 >  */
4464    stringstream jzbvarmcs;
4465    jzbvarmcs << "(";
4466 <  
4466 >  /*
4467    if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4468    if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4469    
# Line 2786 | Line 4477 | void find_correction_factors(string &jzb
4477    
4478    jzbvarmcs << ")";
4479    jzbvarmc=jzbvarmcs.str();
4480 <
4480 >  */
4481 >  
4482 >  if(datacorrection>=1) jzbvardatas<<"(jzb[1]-" << datacorrection-1 << "*pt)";
4483 >  if(datacorrection<1)  jzbvardatas<<"(jzb[1]+" << 1-datacorrection << "*pt)";
4484 >  
4485 >  if(mccorrection>=1) jzbvarmcs<<"(jzb[1]-" << mccorrection-1 << "*pt)";
4486 >  if(mccorrection<1)  jzbvarmcs<<"(jzb[1]+" << 1-mccorrection << "*pt)";
4487 >  
4488 >  jzbvardata = jzbvardatas.str();
4489 >  jzbvarmc = jzbvarmcs.str();
4490 >  
4491    dout << "JZB Z pt correction summary : " << endl;
4492    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
4493    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
4494    
4495   }
4496  
4497 < void pick_up_events(string cut) {
4498 <  dout << "Picking up events with cut " << cut << endl;
2798 <  allsamples.PickUpEvents(cut);
4497 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
4498 >  allsamples.PickUpEvents(cut,filename,QuietMode);
4499   }
4500  
4501   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2881 | Line 4581 | void draw_all_ttbar_histos(TCanvas *can,
4581    }
4582   }
4583  
4584 < void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
4584 > void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring, TCut cut) {
4585    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4586    //in the case of the OFF peak analysis, we compare our control region to the real value
4587    TCut weightbackup=cutWeight;
4588    switch_overunderflow(true);
4589    
4590 <  bool doPURW=false;
4590 >  bool doPURW=true;
4591    
4592    
4593    if(!doPURW) {
# Line 2907 | Line 4607 | void ttbar_sidebands_comparison(string m
4607        
4608    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4609  
4610 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4611 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4610 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4611 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4612    TH1F *TSem;
4613    TH1F *nTSem;
4614 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4615 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4614 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4615 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4616    TH1F *TSeemm;
4617    TH1F *nTSeemm;
4618    
4619    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4620 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4621 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4622 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4623 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTT"));
4620 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4621 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4622 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4623 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets&&cut,mc,simulatedlumi,allsamples.FindSample("/TT"));
4624    }
4625  
4626    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 3175 | Line 4875 | void ttbar_sidebands_comparison(string m
4875   //  nicer_binning.push_back(300);
4876   //  nicer_binning.push_back(400);
4877    
4878 <  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4878 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/",TCut("mll>0"));
4879 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/LowMassRegion2070",TCut("mll>20&&mll<70"));
4880 >  ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/ZWindow",Restrmasscut);
4881 >  
4882   }
4883  
4884  
4885   void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4886    cout << "****************************************************************************************************************************************************************" << endl;
4887    TCanvas *zcan = new TCanvas("zcan","zcan");  
3185 //  zcan->SetLogy(1);
4888    TCut weightbackup=cutWeight;
4889    
4890    bool UsePURW=true;
# Line 3208 | Line 4910 | void zjets_prediction_comparison(string
4910    }
4911  
4912    
4913 +  
4914    vector<float> binning;
4915    binning.push_back(0);
4916    binning.push_back(10);
4917 <  binning.push_back(20);
4918 <  binning.push_back(40);
4919 <  binning.push_back(60);
4920 < //   binning.push_back(50);
4917 >  binning.push_back(30);
4918 > //  binning.push_back(40);
4919 > //  binning.push_back(60);
4920 >   binning.push_back(50);
4921   //   binning.push_back(60);
4922   //   binning.push_back(70);
4923   //   binning.push_back(80);
# Line 3225 | Line 4928 | void zjets_prediction_comparison(string
4928    
4929    TCut kPos((mcjzb+">0").c_str());
4930    TCut kNeg((mcjzb+"<0").c_str());
4931 +  TCut reducedNJets(cutnJets);
4932    string var( "abs("+mcjzb+")" );
4933    
4934 <  TCut notTau("abs(genMID1)!=15");
4934 >  
4935 >  TCut notTau("!EventZToTaus");
4936    TCut ee_mm_tautau("mll>0");
4937    
4938 <
4939 <  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"));
4938 >  TH1F *hJZBpos = allsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4939 >  TH1F *hJZBneg = allsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4940    
4941    hJZBpos->SetLineColor(kBlack);
4942    hJZBneg->SetLineColor(kRed);
# Line 3253 | Line 4957 | void zjets_prediction_comparison(string
4957    hratio->Divide(hJZBneg);
4958    
4959    for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
4960 <    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4960 >    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;
4961    }
4962    
4963   //  zcan->SetLogy(0);
# Line 3261 | Line 4965 | void zjets_prediction_comparison(string
4965    hratio->GetYaxis()->SetTitle("Observed/Predicted");
4966    hratio->Draw("e1");
4967    
4968 <  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
4968 >  TLine *top = new TLine(binning[0],1.2,binning[binning.size()-1],1.2);
4969    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4970 <  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
4970 >  TLine *bottom = new TLine(binning[0],0.8,binning[binning.size()-1],0.8);
4971    
4972  
3269  cout << __LINE__ << endl;
4973    top->SetLineColor(kBlue);top->SetLineStyle(2);
4974    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
4975    center->SetLineColor(kBlue);
# Line 3282 | Line 4985 | void zjets_prediction_comparison(string
4985    DrawMCPrelim(simulatedlumi);
4986    CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4987    
4988 <  TCut reducedNJets(cutnJets);
4989 <  
4990 <  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4991 <  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"));
4988 >  TH1F *TAUhJZBpos       = allsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4989 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4990 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4991 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
4992  
3292  cout << __LINE__ << endl;
4993    TH1F *RcorrJZBSBem;
4994    TH1F *LcorrJZBSBem;
4995    TH1F *RcorrJZBSBeemm;
4996    TH1F *LcorrJZBSBeemm;
4997  
3298  cout << __LINE__ << endl;
4998    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4999 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5000 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5001 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
5002 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4999 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5000 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5001 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5002 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5003    }
5004    
5005    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3318 | Line 5017 | void zjets_prediction_comparison(string
5017    
5018    Bpred->SetLineColor(kRed);
5019  
3321  cout << __LINE__ << endl;
5020    TAUhJZBpos->SetLineColor(kBlack);
5021    Bpred->SetLineColor(kRed);
5022    
# Line 3338 | Line 5036 | void zjets_prediction_comparison(string
5036    TAUhratio->Divide(Bpred);
5037    
5038    for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
5039 <    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
5039 >    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;
5040 >    
5041 >    
5042    }
5043    
5044    zcan->SetLogy(0);
# Line 3372 | Line 5072 | void zjets_prediction_comparison(string
5072      delete LcorrJZBSBeemm;
5073    }
5074    
5075 +  //***************************************************************************************************
5076 +  
5077 +  string jzbvar=var;
5078 +  /*
5079 +  for(int i=0;i<60;i+=10) {
5080 +    stringstream sSpecialJZBCut;
5081 +    sSpecialJZBCut << jzbvar << ">" << i;
5082 +  TCut SpecialJZBCut(sSpecialJZBCut.str().c_str());
5083 +  
5084 +  var="mll";
5085 +  
5086 +  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"));
5087 +  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"));
5088 +  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"));
5089 +  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"));
5090 +
5091 +  TH1F *RcorrJZBPlusSBem;
5092 +  TH1F *LcorrJZBPlusSBem;
5093 +  TH1F *RcorrJZBPlusSBeemm;
5094 +  TH1F *LcorrJZBPlusSBeemm;
5095 +
5096 +  
5097 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5098 +    RcorrJZBPlusSBem   = allsamples.Draw("RcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5099 +    LcorrJZBPlusSBem   = allsamples.Draw("LcorrJZBPlusSBem",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5100 +    RcorrJZBPlusSBeemm = allsamples.Draw("RcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kPos&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5101 +    LcorrJZBPlusSBeemm = allsamples.Draw("LcorrJZBPlusSBeemm",var,10,0,200, "m_{ll} [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&notTau&&kNeg&&massregioncut&&SpecialJZBCut,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
5102 +  }
5103 +  
5104 +  TH1F *BpredPrime = (TH1F*)LcorrJZBPluseemm->Clone("BpredPrime");
5105 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5106 +    BpredPrime->Add(RcorrJZBPlusem,1.0/3.);
5107 +    BpredPrime->Add(LcorrJZBPlusem,-1.0/3.);
5108 +    BpredPrime->Add(RcorrJZBPlusSBem,1.0/3.);
5109 +    BpredPrime->Add(LcorrJZBPlusSBem,-1.0/3.);
5110 +    BpredPrime->Add(RcorrJZBPlusSBeemm,1.0/3.);
5111 +    BpredPrime->Add(LcorrJZBPlusSBeemm,-1.0/3.);
5112 +  } else {
5113 +    BpredPrime->Add(RcorrJZBPlusem,1.0);
5114 +    BpredPrime->Add(LcorrJZBPlusem,-1.0);
5115 +  }
5116 +  
5117 +  BpredPrime->SetLineColor(kRed);
5118 +
5119 +  FullJZBhJZBpos->SetLineColor(kBlack);
5120 +  BpredPrime->SetLineColor(kRed);
5121 +  
5122 +  FullJZBhJZBpos->SetMinimum(1.0);
5123 +  FullJZBhJZBpos->Draw("e1");
5124 +  BpredPrime->Draw("same,hist");
5125 +  FullJZBhJZBpos->Draw("same,e1");
5126 +  
5127 +  TLegend *FullJZBleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
5128 +  FullJZBleg->AddEntry(FullJZBhJZBpos,"Observed","pe");
5129 +  FullJZBleg->AddEntry(BpredPrime,"Predicted","l");
5130 +  FullJZBleg->Draw("same");
5131 +  DrawMCPrelim(simulatedlumi);
5132 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"_zjets_eemumu_prediction__"+any2string(massregionname));
5133 +  
5134 +  TH1F* FullJZBhratio = (TH1F*)FullJZBhJZBpos->Clone("FullJZBhratio");
5135 +  FullJZBhratio->Divide(BpredPrime);
5136 +  
5137 +  zcan->SetLogy(0);
5138 +  FullJZBhratio->GetYaxis()->SetRangeUser(0,2.5);
5139 +  FullJZBhratio->GetYaxis()->SetTitle("Observed/Predicted");
5140 +  FullJZBhratio->Draw("e1");
5141 +  
5142 +  TLine *atop = new TLine(0,1.2,200,1.2);
5143 +  TLine *acenter = new TLine(0,1.0,200,1.0);
5144 +  TLine *abottom = new TLine(0,0.8,200,0.8);
5145 +  
5146 +  atop->SetLineColor(kBlue);
5147 +  atop->SetLineStyle(2);
5148 +  acenter->SetLineColor(kBlue);
5149 +  abottom->SetLineColor(kBlue);
5150 +  abottom->SetLineStyle(2);
5151 +  
5152 +  atop->Draw("same");
5153 +  acenter->Draw("same");
5154 +  abottom->Draw("same");
5155 +  
5156 +  TLegend *FullJZBleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
5157 +  FullJZBleg2->AddEntry(FullJZBhratio,"obs / pred","pe");
5158 +  FullJZBleg2->AddEntry(abottom,"syst. envelope","l");
5159 +  FullJZBleg2->Draw("same");
5160 +  DrawMCPrelim(simulatedlumi);
5161 +  CompleteSave(zcan,"Systematics/ZJets/Mll_Distribution_JZB"+any2string(i)+"zjets_eemumu_prediction_ratio"+any2string(massregionname));
5162 +  
5163 +  
5164 +  delete BpredPrime;
5165 +  delete FullJZBhJZBpos;
5166 +  delete LcorrJZBPluseemm;
5167 +  delete RcorrJZBPlusem;
5168 +  delete LcorrJZBPlusem;
5169 + //  delete FullJZBhJZBpos;
5170 +  
5171 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5172 +    delete RcorrJZBPlusSBem;
5173 +    delete LcorrJZBPlusSBem;
5174 +    delete RcorrJZBPlusSBeemm;
5175 +    delete LcorrJZBPlusSBeemm;
5176 +  }
5177    
5178 +  }
5179 +  //***************************************************************************************************
5180 +  */
5181    delete zcan;
5182    cutWeight=weightbackup;
3378
3379  cout << __LINE__ << endl;
5183   }
5184  
5185  
5186   void zjets_prediction_comparison(string mcjzbWithPUa) {
5187 <  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
5188 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
5187 >   zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20"), "nomasscut");
5188 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<10"), "Zwindow_10");
5189    zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
5190 <  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5190 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)>10&&mll>20"), "Outside_Zwindow_10");
5191 > //  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
5192   }
5193    
5194   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
# Line 3494 | Line 5298 | void make_table(samplecollection &coll,
5298   }
5299  
5300   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
5301 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
5302 +  assert(0);
5303    /*we want a table like this:
5304      __________________     50   |   100  | ...
5305      | Data prediction |  a vs b | a vs b | ...
# Line 3727 | Line 5533 | void qcd_plots(string datajzb, string mc
5533    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
5534    string ytitle("ratio");
5535    if ( use_data==1 ) ytitle = "data/pred";
5536 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5536 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
5537 >  delete kinpad;
5538    
5539    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
5540    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3898 | Line 5705 | void met_vs_jzb_plots(string datajzb, st
5705    
5706    vector<string> findme;
5707    findme.push_back("DY");
5708 <  findme.push_back("TTJets");
5708 >  findme.push_back("TT_");
5709    findme.push_back("LM");
5710    /*
5711    for(int ifind=0;ifind<(int)findme.size();ifind++) {
# Line 3935 | Line 5742 | void met_vs_jzb_plots(string datajzb, st
5742    sRIGHT << "((" << mcjzb << ")>0)";
5743    TCut RIGHT(sRIGHT.str().c_str());
5744    
5745 <  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5746 <  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5747 <  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5748 <  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5745 >  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5746 >  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5747 >  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5748 >  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5749    
5750    
5751    TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
# Line 3964 | Line 5771 | void met_vs_jzb_plots(string datajzb, st
5771    lg->SetHeader("DY");
5772    
5773    lg->Draw();
5774 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5774 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5775    
5776    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5777    metpad3->cd();
# Line 3982 | Line 5789 | void met_vs_jzb_plots(string datajzb, st
5789  
5790    lg2->Draw();
5791    
5792 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5792 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5793    
5794    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5795    metpad2->cd();
5796    metpad2->SetLogy(1);
5797    
5798 <  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5799 <  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5800 <  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5801 <  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5798 >  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5799 >  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5800 >  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5801 >  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5802    
5803    metlefta->Add(metleftOa,-1);
5804    metrighta->Add(metrightOa,-1);
# Line 4001 | Line 5808 | void met_vs_jzb_plots(string datajzb, st
5808    metlefta->Draw("histo");
5809    metrighta->Draw("same");
5810    lg->Draw();
5811 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5811 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5812    
5813    delete Bpred;
5814    delete obs;
# Line 4010 | Line 5817 | void met_vs_jzb_plots(string datajzb, st
5817    int newNBins=30;
5818    
5819    TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5820 <  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5821 <  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5822 <  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5823 <  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "MET [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5820 >  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5821 >  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5822 >  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5823 >  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5824    
5825    TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5826    aBpred->Add(AmetleftO,-1);
# Line 4028 | Line 5835 | void met_vs_jzb_plots(string datajzb, st
5835    aobs->Draw("same");
5836    lg->SetHeader("All MC");
5837    lg->Draw();
5838 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5838 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5839    
5840    
5841    delete lg;
# Line 4038 | Line 5845 | void met_vs_jzb_plots(string datajzb, st
5845    delete metright;
5846    delete metrightO;
5847   }
5848 +
5849 +
5850 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5851 +  
5852 +  if(PlottingSetup::RestrictToMassPeak) {
5853 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5854 +    assert(!PlottingSetup::RestrictToMassPeak);
5855 +  }
5856 +  
5857 +  vector<float> binning;
5858 +  
5859 +  binning.push_back(-200);
5860 +  binning.push_back(-150);
5861 +  binning.push_back(-125);
5862 +  binning.push_back(-100);
5863 +  binning.push_back(-75);
5864 +  binning.push_back(-50);
5865 +  binning.push_back(-25);
5866 +  binning.push_back(0);
5867 +  binning.push_back(25);
5868 +  binning.push_back(50);
5869 +  binning.push_back(75);
5870 +  binning.push_back(100);
5871 +  binning.push_back(125);
5872 +  binning.push_back(150);
5873 +  binning.push_back(200);
5874 +  
5875 +  switch_overunderflow(true);
5876 +  
5877 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5878 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5879 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5880 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5881 +  
5882 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5883 +  tcan->SetLogy(1);
5884 +  
5885 +  TZeemm->SetLineColor(kBlack);
5886 +  TZem->SetLineColor(kRed);
5887 +  TZeemm->SetMarkerColor(kBlack);
5888 +  TZem->SetMarkerColor(kRed);
5889 +  
5890 +  vector<TH1F*> histos;
5891 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5892 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5893 +  histos.push_back(TZem);
5894 +  histos.push_back(TZeemm);
5895 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5896 +  
5897 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5898 +  leg->AddEntry(TZeemm,"SFZP","l");
5899 +  leg->AddEntry(TZem,"OFZP","l");
5900 +  leg->Draw("same");
5901 +  DrawMCPrelim();
5902 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5903 +  
5904 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5905 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5906 +  TH1F *TSeemmcopy;
5907 +  TH1F *TSemcopy;
5908 +  
5909 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5910 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5911 +  
5912 +  vector<float> posbinning;
5913 +  for(unsigned int i=0;i<binning.size();i++) {
5914 +    if(binning[i]<0) continue;
5915 +    posbinning.push_back(binning[i]);
5916 +  }
5917 +  
5918 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5919 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5920 +  
5921 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5922 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5923 +    if(TZem->GetBinCenter(i)<0) {
5924 +      //we're on the left: subtract em!
5925 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5926 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5927 +      //we're on the left: add eemm!
5928 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5929 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5930 +    } else {
5931 +      //we're on the right: add em!
5932 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5933 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5934 +      //we're on the left: add eemm!
5935 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5936 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5937 +    }
5938 +  }
5939 +  
5940 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5941 +  ratio2->Divide(obs2);
5942 +
5943 +  TZem->Divide(TZeemm);
5944 +  TZem->SetMarkerStyle(21);
5945 +
5946 +  TZem->SetTitle("OF / SF");
5947 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5948 +  
5949 +  tcan->SetLogy(0);
5950 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
5951 +  TZem->GetYaxis()->SetTitle("ratio");
5952 +  TZem->Draw();
5953 +  
5954 +  float linepos=emuncertOFFPEAK;
5955 +  
5956 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5957 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5958 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5959 +  
5960 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
5961 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5962 +  center->SetLineColor(kBlue);
5963 +  
5964 +  top->Draw("same");
5965 +  center->Draw("same");
5966 +  bottom->Draw("same");
5967 +  
5968 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
5969 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
5970 +  leg2->AddEntry(bottom,"syst. envelope","l");
5971 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
5972 +  leg2->SetY1(0.65);
5973 +  
5974 +  leg2->Draw("same");
5975 +  
5976 +  DrawMCPrelim();
5977 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
5978 +  
5979 +  ratio2->SetLineColor(TZem->GetLineColor());
5980 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
5981 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
5982 +  ratio2->GetYaxis()->SetTitle("ratio");
5983 +  ratio2->Draw();
5984 +  
5985 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
5986 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
5987 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
5988 +  
5989 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
5990 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
5991 +  center2->SetLineColor(kBlue);
5992 +  
5993 +  top2->Draw("same");
5994 +  center2->Draw("same");
5995 +  bottom2->Draw("same");
5996 +  
5997 +  leg2->Draw("same");
5998 +  
5999 +  DrawMCPrelim();
6000 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
6001 +  
6002 +  delete TZem;
6003 +  delete nTZem;
6004 +  delete TZeemm;
6005 +  delete nTZeemm;
6006 +  delete obs2;
6007 +  delete pred2;
6008 +  delete tcan;
6009 +  switch_overunderflow(false);
6010 + }
6011 +
6012 + 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) {
6013 +    
6014 +  
6015 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
6016 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6017 +  vanilla_ratio->SetFillColor(kGreen);
6018 +  vanilla_ratio->SetLineColor(kGreen);
6019 +  vanilla_ratio->SetMarkerColor(kGreen);
6020 +  vanilla_ratio->SetFillStyle(3001);
6021 +  vanilla_ratio->Draw("e3");
6022 +  
6023 +  response_only_up_ratio->SetFillColor(kRed);
6024 +  response_only_up_ratio->SetMarkerColor(kRed);
6025 +  response_only_up_ratio->SetLineColor(kRed);
6026 +  response_only_up_ratio->SetFillStyle(3003);
6027 +  response_only_up_ratio->Draw("e3,same");
6028 +  
6029 +  response_only_down_ratio->SetFillColor(kOrange);
6030 +  response_only_down_ratio->SetMarkerColor(kOrange);
6031 +  response_only_down_ratio->SetLineColor(kOrange);
6032 +  response_only_down_ratio->SetFillStyle(3004);
6033 +  response_only_down_ratio->Draw("e3,same");
6034 +  
6035 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
6036 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
6037 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
6038 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
6039 +  reponse_plus_peak_up_ratio->Draw("e3,same");
6040 +  
6041 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
6042 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
6043 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
6044 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
6045 +  reponse_plus_peak_down_ratio->Draw("e3,same");
6046 +  
6047 +  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);
6048 +  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);
6049 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
6050 +  
6051 +  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);
6052 +  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);
6053 +  
6054 +  lhiA->SetLineColor(kRed);
6055 +  lhiA->SetLineStyle(2);
6056 +  llowA->SetLineColor(kRed);
6057 +  llowA->SetLineStyle(2);
6058 +  
6059 +  llow->SetLineColor(kBlue);
6060 +  llow->SetLineStyle(2);
6061 +  lhi->SetLineColor(kBlue);
6062 +  lhi->SetLineStyle(2);
6063 +  lOne->SetLineColor(kBlue);
6064 +  
6065 +  llow->Draw();
6066 +  lhi->Draw();
6067 +  lOne->Draw();
6068 +  
6069 +  llowA->Draw();
6070 +  lhiA->Draw();
6071 +  
6072 +  TLegend *leg = make_legend();
6073 +  leg->SetX1(0.15);
6074 +  leg->SetY1(0.7);
6075 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
6076 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
6077 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6078 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6079 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6080 +  leg->AddEntry(lhi,"Systematic envelope","l");
6081 + //  leg->SetNColumns(2);
6082 +  leg->Draw();
6083 +  
6084 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
6085 +  
6086 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6087 +  vanilla_ratio->Draw("e3");
6088 +  response_only_up_ratio->Draw("e3 same");
6089 +  response_only_down_ratio->Draw("e3 same");
6090 +  TLegend *leg2 = make_legend();
6091 +  leg2->SetX1(0.15);
6092 +  leg2->SetY1(0.7);
6093 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
6094 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
6095 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
6096 +  leg2->AddEntry(lhi,"Systematic envelope","l");
6097 +  leg2->Draw();
6098 +  llow->Draw();
6099 +  lOne->Draw();
6100 +  llowA->Draw();
6101 +  lhiA->Draw();
6102 +  
6103 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
6104 +  
6105 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
6106 +  response_only_up_ratio->Draw("e3");
6107 +  reponse_plus_peak_up_ratio->Draw("e3 same");
6108 +  reponse_plus_peak_down_ratio->Draw("e3 same");
6109 +  TLegend *leg3 = make_legend();
6110 +  leg3->SetX1(0.15);
6111 +  leg3->SetY1(0.7);
6112 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
6113 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
6114 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
6115 +  leg3->AddEntry(lhi,"Systematic envelope","l");
6116 +  leg3->Draw();
6117 +  llow->Draw();
6118 +  lOne->Draw();
6119 +  llowA->Draw();
6120 +  lhiA->Draw();
6121 +  
6122 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
6123 +  
6124 +  delete ttcan2;
6125 + }
6126 +
6127 + void ttbar_correction_tests() {
6128 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
6129      
6130 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
6131 +  
6132 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
6133 +  
6134 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
6135 +  
6136 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
6137 +  
6138 +  string vanilla="jzb[1]";
6139 +  string response_only_up="((jzb[1]+0.034665*pt))";
6140 +  string response_only_down="((jzb[1]-0.034665*pt))";
6141 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
6142 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
6143 +
6144 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
6145 +  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");
6146 +  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");
6147 +  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");
6148 +  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");
6149 +  
6150 +  ttcan->cd();
6151 +  
6152 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
6153 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
6154 +  
6155 +  delete vanilla_observed;
6156 +  delete response_only_up_observed;
6157 +  delete response_only_down_observed;
6158 +  delete reponse_plus_peak_up_observed;
6159 +  delete reponse_plus_peak_down_observed;
6160 +  
6161 +  delete vanilla_predicted;
6162 +  delete response_only_up_predicted;
6163 +  delete response_only_down_predicted;
6164 +  delete reponse_plus_peak_up_predicted;
6165 +  delete reponse_plus_peak_down_predicted;
6166 +  
6167 +  delete vanilla_ratio;
6168 +  delete response_only_up_ratio;
6169 +  delete response_only_down_ratio;
6170 +  delete reponse_plus_peak_up_ratio;
6171 +  delete reponse_plus_peak_down_ratio;
6172 +  
6173 +  delete ttcan;
6174 + }
6175 +
6176 + void ttbar_region_search(string mcjzb) {
6177 +  cout << "Looking for a nice control region" << endl;
6178 +  TCanvas *can = new TCanvas("can","can",1200,1200);
6179 +  can->Divide(2,2);
6180 +  can->cd(1);
6181 +  can->cd(1)->SetLogy(1);
6182 +  
6183 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6184 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
6185 +  
6186 +  JZBdistSF.Draw("histo");
6187 +  JZBdistSF.SetMaximum(1000);
6188 +  JZBdistSF.SetMinimum(0.1);
6189 +  JZBdistSF.Draw("histo");
6190 +  DrawMCPrelim();
6191 +  
6192 +  can->cd(2);
6193 +  can->cd(2)->SetLogy(1);
6194 +  JZBdistOF.Draw("histo");
6195 +  JZBdistOF.SetMaximum(1000);
6196 +  JZBdistOF.SetMinimum(0.1);
6197 +  JZBdistOF.Draw("histo");
6198 +  DrawMCPrelim();
6199 +  
6200 +  can->cd(3);
6201 +  
6202 +  
6203 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
6204 +  
6205 +  DrawMCPrelim();
6206 +  
6207 +  /*
6208 +  THStack *Subtracted = new THStack();
6209 +  
6210 +  TIter nextSF(JZBdistSF.GetHists());
6211 +  TIter nextOF(JZBdistOF.GetHists());
6212 +  TObject* SFobj;
6213 +  TObject* OFobj;
6214 +  
6215 +  TH1* sfh = NULL;
6216 +  TH1* ofh = NULL;
6217 +  
6218 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
6219 +    TH1F *sfstart = (TH1*)SFobj->Clone();
6220 +    TH1F *ofstart = (TH1*)OFobj->Clone();
6221 +    TH1F *obs, *pred;
6222 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
6223 +    
6224 +    if ( !hratio ) {
6225 +      hratio = (TH1*)obj->Clone();
6226 +      hratio->SetName("hratio");
6227 +    } else hratio->Add( (TH1*)obj );
6228 +    
6229 +  }
6230 +  hratio->Divide(hdata);
6231 +  */
6232 +  
6233 +  
6234 +  can->cd(4);
6235 +  JZBdistOF.Draw("histo");
6236 +  DrawMCPrelim();
6237 +  
6238 +  
6239 +  
6240 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
6241 +  
6242 +  CleanLegends();
6243 +  delete can;
6244 + }
6245 +
6246 + void ttbar_tests(string mcjzb) {
6247 +  //ttbar_correction_tests();
6248 +  ttbar_region_search(mcjzb);
6249 + }
6250 +
6251 + Value GetYieldBetween(TH1F *h, float low, float high) {
6252 +  float Yield=0;
6253 +  float YieldErr=0;
6254 +  for(int i=1;i<=h->GetNbinsX()+1;i++) {
6255 +    if(h->GetBinLowEdge(i)+h->GetBinWidth(i)<=low) continue;// considered in the next bin
6256 +    if(h->GetBinLowEdge(i)>=high) continue;//above the threshold, out!
6257 +    Yield+=h->GetBinContent(i);
6258 +    YieldErr=sqrt(YieldErr*YieldErr+h->GetBinError(i)*h->GetBinError(i));
6259 +  }
6260 +  
6261 +  Value a(Yield,YieldErr);
6262 +  return a;
6263 + }
6264 +
6265 +
6266 + void make_SF_over_OF_plot(string datajzb, string mcjzb, TCut cut, string variable, int nbins, float xmin, float ymin, string varname, string filename) {
6267 +  TCanvas *SFoOF_can = new TCanvas("SFoOF_can","SFoOF_can");
6268 +  TH1F *data_sf = allsamples.Draw("data_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,data,luminosity);
6269 +  TH1F *data_of = allsamples.Draw("data_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,data,luminosity);
6270 +  
6271 +  TH1F *mc_sf = allsamples.Draw("mc_sf","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6272 +  TH1F *mc_of = allsamples.Draw("mc_of","mll",20,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6273 +  
6274 +  TH1F *mc_ratio = (TH1F*)mc_sf->Clone("mc_ratio");
6275 +  mc_ratio->Divide(mc_of);
6276 +  
6277 +  TH1F *data_ratio = (TH1F*)data_sf->Clone("data_ratio");
6278 +  data_ratio->Divide(data_of);
6279 +  
6280 +  mc_ratio->SetFillColor(TColor::GetColor("#00ADE1"));
6281 +  mc_ratio->SetMarkerColor(TColor::GetColor("#00ADE1"));
6282 +  mc_ratio->GetYaxis()->SetRangeUser(0.5,1.5);
6283 +  
6284 +  mc_ratio->GetYaxis()->SetTitle("R(SF / OF)");
6285 +  
6286 +  
6287 +  Value R_sf_of_low_mass = GetYieldBetween(data_sf,20,70)/GetYieldBetween(data_of,20,70);
6288 +  Value R_sf_of_high_mass = GetYieldBetween(data_sf,120,200)/GetYieldBetween(data_of,120,200);
6289 +  
6290 +  Value R_sf_of_low_mass_mc = GetYieldBetween(mc_sf,20,70)/GetYieldBetween(mc_of,20,70);
6291 +  Value R_sf_of_high_mass_mc = GetYieldBetween(mc_sf,120,200)/GetYieldBetween(mc_of,120,200);
6292 +  
6293 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6294 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6295 +  
6296 +  TGraphAsymmErrors *gra = produce_ratio_graph(mc_ratio);
6297 +  gra->Draw();
6298 +  mc_ratio->Draw();
6299 +  gra->Draw("e20");
6300 +  gra->SetFillColor(TColor::GetColor("#00ADE1"));
6301 +  gra->SetMarkerColor(TColor::GetColor("#00ADE1"));
6302 +  data_ratio->Draw("e1,same");
6303 +  
6304 +  TLegend *leg = new TLegend(0.17,0.16,0.53,0.31);
6305 + //   leg->SetHeader("R( SF / OF )");
6306 +  leg->SetFillColor(kWhite);
6307 +  leg->SetBorderSize(0);
6308 +  leg->AddEntry(data_ratio,"Data","p");
6309 +  leg->AddEntry(gra,"MC","fp");
6310 +  leg->Draw();
6311 +  
6312 +  TLine *g = new TLine(0,1.01,200,1.01);
6313 +  g->SetLineColor(kBlue);
6314 +  g->Draw();
6315 +  
6316 +  TLine *l = new TLine(70,0.5,70,1.5);
6317 +  l->SetLineStyle(2);
6318 +  l->SetLineColor(TColor::GetColor("#00ADE1"));
6319 +  TLine *m = new TLine(120,0.5,120,1.5);
6320 +  m->SetLineStyle(2);
6321 +  m->SetLineColor(TColor::GetColor("#00ADE1"));
6322 +  l->Draw();
6323 +  m->Draw();
6324 +  
6325 +  
6326 +  DrawPrelim();
6327 +  
6328 +  CompleteSave(SFoOF_can,"iTTbar/"+filename+"SF_vs_OF");
6329 +  
6330 +  delete leg;
6331 +  delete mc_sf;
6332 +  delete mc_of;
6333 +  delete mc_ratio;
6334 +  delete data_sf;
6335 +  delete data_of;
6336 +  delete data_ratio;
6337 +  delete SFoOF_can;
6338 + }  
6339 +
6340 + void make_iTTbar_JZB_plot(string datajzb, string mcjzb, TCut cut) {
6341 +  TCanvas *can = new TCanvas("can","can");
6342 +  vector<float> binning;
6343 +  binning.push_back(-100);
6344 +  binning.push_back(-50);
6345 +  binning.push_back(-20);
6346 +  binning.push_back(0);
6347 + //  binning.push_back(10);
6348 +  binning.push_back(20);
6349 + //  binning.push_back(30);
6350 +  binning.push_back(50);
6351 +  binning.push_back(100);
6352 +  binning.push_back(300);
6353 +  
6354 +  TH1F *hdata   = allsamples.Draw("hdata",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6355 +  TH1F *hodata  = allsamples.Draw("hodata", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6356 +  TH1F *hndata  = allsamples.Draw("hndata", "-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSSF,data,luminosity);
6357 +  TH1F *hnodata = allsamples.Draw("hnodata","-"+datajzb,binning, "JZB [GeV]", "events", cut&&cutOSOF,data,luminosity);
6358 +  
6359 +  TH1F *hmc   = allsamples.Draw("hmc",  datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSSF,mc,luminosity);
6360 +  TH1F *homc  = allsamples.Draw("homc", datajzb,    binning, "JZB [GeV]", "events", cut&&cutOSOF,mc,luminosity);
6361 +  
6362 +  hodata->SetLineColor(kRed);
6363 +  hmc->SetLineColor(kRed);
6364 + //  hodata->Add(hndata);
6365 + //  hodata->Add(hnodata,-1);
6366 +  
6367 +  if(hdata->GetMaximum()>hodata->GetMaximum()) {
6368 +    hdata->SetMinimum(1.0);
6369 +    hdata->Draw();
6370 +    hodata->Draw("histo,same");
6371 +    hdata->Draw("same");
6372 +  } else {
6373 +    hodata->SetMinimum(1.0);
6374 +    hodata->Draw("histo");
6375 +    hdata->Draw("same");
6376 +  }
6377 +  
6378 +  CompleteSave(can,"iTTbar/JZB_plot");
6379 +  TH1F *ratio = (TH1F*)hdata->Clone("ratio");
6380 +  ratio->Divide(hodata);
6381 +  ratio->GetYaxis()->SetTitle("obs/pred");
6382 +  ratio->GetYaxis()->SetRangeUser(0,2);
6383 +  
6384 +  ratio->Draw();
6385 +  TLine *l = new TLine(-100,1.0,300,1.0);
6386 +  l->SetLineColor(kBlue);
6387 +  l->SetLineStyle(2);
6388 +  l->Draw();
6389 +  TLine *llow = new TLine(-100,1.0-0.07,300,1.0-0.07);
6390 +  TLine *lhi = new TLine(-100,1.0+0.07,300,1.0+0.07);
6391 +  llow->SetLineColor(kBlue);
6392 +  llow->SetLineStyle(2);
6393 +  llow->Draw();
6394 +  lhi->SetLineColor(kBlue);
6395 +  lhi->SetLineStyle(2);
6396 +  lhi->Draw();
6397 +  
6398 +  CompleteSave(can,"iTTbar/JZB_plot_ratio");
6399 +  
6400 +  delete hdata;
6401 +  delete hodata;
6402 +  delete ratio;
6403 +  delete can;
6404 + //  THStack *hmc = new THStack(allsamples.DrawStack("hmc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSSF,mc,luminosity));
6405 + //  THStack *homc = new THStack(allsamples.DrawStack("homc","mll",40,0,200, "m_{ll} [GeV]", "events", cut&&cutOSOF,mc,luminosity));
6406 + }
6407 +
6408 +  
6409 +  
6410 + void MakeSpecialiTTbarClosurePlot(TCut fullcut, string datajzb, string mcjzb, string MassRegion) {
6411 +  TCanvas *iTTbarClosureTestCanvas = new TCanvas("iTTbarClosureTestCanvas","iTTbarClosureTestCanvas");
6412 +  
6413 +  vector<float> binning;
6414 + /*
6415 +  binning.push_back(0);
6416 +  binning.push_back(20);
6417 +  binning.push_back(50);
6418 +  binning.push_back(100);
6419 + //  binning.push_back(200);
6420 + */
6421 +  binning.push_back(0);
6422 +  binning.push_back(10);
6423 +  binning.push_back(30);
6424 +  binning.push_back(50);
6425 +  binning.push_back(100);
6426 + //  binning.push_back(200);
6427 +  
6428 +  
6429 +  TH1F *hdata  = allsamples.Draw("hdata", datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),data,luminosity);
6430 +  TH1F *hodata = allsamples.Draw("hodata",datajzb,binning, "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),data,luminosity);
6431 +  TH1F *hmc    = allsamples.Draw("hmc",   mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1==id2"),mc,luminosity);
6432 +  TH1F *homc   = allsamples.Draw("homc",  mcjzb,binning,   "JZB [GeV]", "events", fullcut&&TCut("id1!=id2"),mc,luminosity);
6433 +  
6434 +  hdata->SetLineColor(kBlack);
6435 +  hmc->SetLineColor(kBlack);
6436 +  hodata->SetLineColor(kRed);
6437 +  homc->SetLineColor(kRed);
6438 +  hodata->SetMarkerColor(kRed);
6439 +  
6440 +  hdata->GetYaxis()->SetTitle("events");
6441 +  
6442 +  float maximum=hdata->GetMaximum()+1.2*sqrt(hdata->GetMaximum());
6443 +  float minimum=hdata->GetMinimum()-1.2*sqrt(hdata->GetMinimum());
6444 +  if(hmc->GetMinimum()<minimum) minimum=hmc->GetMinimum()-1.2*sqrt(hmc->GetMinimum());
6445 +  if(hmc->GetMaximum()>maximum) maximum=hmc->GetMaximum()+1.2*sqrt(hmc->GetMaximum());
6446 +  if(homc->GetMinimum()<minimum) minimum=homc->GetMinimum()-1.2*sqrt(homc->GetMinimum());
6447 +  if(homc->GetMaximum()>maximum) maximum=homc->GetMaximum()+1.2*sqrt(homc->GetMaximum());
6448 +  if(hodata->GetMinimum()<minimum) minimum=hodata->GetMinimum()-1.2*sqrt(hodata->GetMinimum());
6449 +  if(hodata->GetMaximum()>maximum) maximum=hodata->GetMaximum()+1.2*sqrt(hodata->GetMaximum());
6450 +  
6451 +  hdata->SetMaximum(maximum);
6452 +  hdata->SetMinimum(minimum);
6453 +  
6454 +  
6455 +  hdata->Draw();
6456 +  hmc->Draw("same,histo");
6457 +  homc->Draw("same,histo");
6458 +  hdata->Draw("same");
6459 +  hodata->Draw("same");
6460 +  
6461 +  TLegend *leg = make_legend();
6462 +  leg->AddEntry(hdata,"SF data","pe");
6463 +  leg->AddEntry(hodata,"OF data","pe");
6464 +  leg->AddEntry(hmc,"SF MC","l");
6465 +  leg->AddEntry(homc,"OF MC","l");
6466 +  leg->Draw();
6467 +  
6468 +  DrawPrelim();
6469 +  
6470 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_"+MassRegion);
6471 +  
6472 +  TH1F *ratio_data = (TH1F*)hdata->Clone("ratio_data");
6473 +  ratio_data->Divide(hodata);
6474 +  TH1F *ratio_mc = (TH1F*)hmc->Clone("ratio_mc");
6475 +  ratio_mc->Divide(homc);
6476 +  
6477 +  ratio_mc->SetFillColor(kBlue);
6478 +  ratio_mc->SetMarkerSize(0);
6479 +  
6480 +  TGraphAsymmErrors *eratio = produce_ratio_graph(ratio_mc);
6481 +  
6482 +  eratio->SetFillColor(TColor::GetColor("#00ADE1"));
6483 +  ratio_data->GetYaxis()->SetRangeUser(0.5,1.5);
6484 +  ratio_data->Draw("e1");
6485 +  eratio->Draw("20");
6486 +  ratio_data->Draw("e1,same");
6487 +  
6488 +  TLegend *leg2 = make_legend();
6489 +  leg2->AddEntry(ratio_data,"R(SF/OF) in #bar{t}t CR, data","pe");
6490 +  leg2->AddEntry(eratio    ,"R(SF/OF) in #bar{t}t CR, MC"  ,"f");
6491 +  leg2->SetY1(0.8);
6492 +  leg2->SetX1(0.45);
6493 +  leg2->Draw();
6494 +  
6495 +  DrawPrelim();
6496 +  CompleteSave(iTTbarClosureTestCanvas,"iTTbar/TTbar_CR_Closure_Ratio_"+MassRegion);
6497 +  
6498 +  TFile *f = new TFile("fout.root","RECREATE");
6499 +  eratio->Write();
6500 +  ratio_data->Write();
6501 +  leg2->Write();
6502 +  f->Close();
6503 +  
6504 +  
6505 +  delete leg;
6506 +  delete leg2;
6507 +  delete ratio_data;
6508 +  delete ratio_mc;
6509 +  delete hdata;
6510 +  delete hmc;
6511 +  delete hodata;
6512 +  delete iTTbarClosureTestCanvas;
6513 + }
6514 +  
6515 +  
6516 +  
6517 + void make_ijzb_ttbar_closure_test(string datajzb, string mcjzb) {
6518 +  TCut tt_nJets("pfJetGoodNum40==2");
6519 +  TCut tt_bJet("pfJetGoodNumBtag40==2");
6520 +  TCut tt_LowMass("mll>20&&mll<70");
6521 +  TCut tt_HighMass("mll>120&&mll<200");
6522 +  TCut tt_noZ(tt_LowMass || tt_HighMass);
6523 +  
6524 +  /*
6525 +  make_iTTbar_JZB_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ);
6526 + */
6527 +  TCanvas *can = new TCanvas("can","can");
6528 +
6529 +  TH1F *hdata  =                allsamples.Draw(        "hdata", "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,data,luminosity);
6530 +  THStack *hmc = new THStack(   allsamples.DrawStack(   "hmc",   "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF,mc,  luminosity));
6531 +  TH1F *hodata =                allsamples.Draw(        "hodata","mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,data,luminosity);
6532 +  THStack *homc = new THStack(  allsamples.DrawStack(   "homc",  "mll",40,0,200, "m_{ll} [GeV]", "events", tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF,mc,  luminosity));
6533 +  
6534 +  TH1F *coll_hmc = CollapseStack(hmc);
6535 +  TH1F *coll_homc = CollapseStack(homc);
6536 +  
6537 +  bool dolog=true;
6538 +  bool nolog=false;
6539 +  
6540 +  dout << " SF: " << endl;
6541 +  dout << "   Data : " << hdata->Integral() << endl;
6542 +  WriteYield(hmc, 0, 10000);
6543 +  dout << " OF: " << endl;
6544 +  dout << "   Data : " << hodata->Integral() << endl;
6545 +  WriteYield(homc, 0, 10000);
6546 +  hodata->SetLineColor(kRed);
6547 +  hdata->Draw();
6548 +  hmc->Draw("histo,same");
6549 +  hodata->Draw("histo,same");
6550 +  hdata->Draw("e1,same");
6551 +  DrawPrelim();
6552 +  CompleteSave(can,"TestingPrediction");
6553 +  
6554 +  dout << "We get an expected ratio of " << coll_hmc->Integral()/coll_homc->Integral() << endl;
6555 +  dout << "In data we find  " << hdata->Integral()/hodata->Integral() << endl;
6556 +  
6557 +  Value R_sf_of_low_mass = GetYieldBetween(hdata,20,70)/GetYieldBetween(hodata,20,70);
6558 +  Value R_sf_of_high_mass = GetYieldBetween(hdata,120,200)/GetYieldBetween(hodata,120,200);
6559 +  
6560 +  Value R_sf_of_low_mass_mc = GetYieldBetween(coll_hmc,20,70)/GetYieldBetween(coll_homc,20,70);
6561 +  Value R_sf_of_high_mass_mc = GetYieldBetween(coll_hmc,120,200)/GetYieldBetween(coll_homc,120,200);
6562 +  
6563 +  dout << "Ratio at low mass  : " << R_sf_of_low_mass  << " (mc : " << R_sf_of_low_mass_mc << " )" << endl;
6564 +  dout << "Ratio at high mass : " << R_sf_of_high_mass << " (mc : " << R_sf_of_high_mass_mc << " )" << endl;
6565 +  
6566 +  dout << "Composition at low mass : " << endl;
6567 +  dout << "Same flavor: " << endl;
6568 +  ProduceYields(20, 70, hdata, hmc);
6569 +  dout << "Opposite flavor: " << endl;
6570 +  ProduceYields(20, 70, hodata, homc);
6571 +  
6572 +  dout << endl << endl;
6573 +  
6574 +  dout << "Composition at high mass : " << endl;
6575 +  dout << "Same flavor: " << endl;
6576 +  ProduceYields(120, 200, hdata, hmc);
6577 +  dout << "Opposite flavor: " << endl;
6578 +  ProduceYields(120, 200, hodata, homc);
6579 +  
6580 +  
6581 +
6582 +  
6583 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSSF),20,-200,200,dolog,"JZB","iTTbar/JZB_SF",false,true);
6584 +  make_plain_kin_plot(mcjzb,(const char*) (tt_nJets&&tt_bJet&&tt_noZ&&cutOSOF),20,-200,200,dolog,"JZB","iTTbar/JZB_OF",false,true);
6585 +
6586 +  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);
6587 +  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);
6588 +  
6589 +  make_SF_over_OF_plot(datajzb, mcjzb,tt_nJets&&tt_bJet&&tt_noZ,"mll",20,0,200,"m_{ll} [GeV]","mll");
6590 +  
6591 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_LowMass),datajzb,mcjzb,"LowMassRegion2070");
6592 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_HighMass),datajzb,mcjzb,"HighMassRegion");
6593 +  MakeSpecialiTTbarClosurePlot((tt_nJets&&tt_bJet&&tt_noZ),datajzb,mcjzb,"NoZ");
6594 +  
6595 + //   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);
6596 + //   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);
6597 + //  
6598 + //   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);
6599 + //   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);
6600 +  
6601 +  
6602 +  delete coll_hmc;
6603 +  delete coll_homc;
6604 +  delete hmc;
6605 +  delete homc;
6606 +  delete hdata;
6607 +  delete hodata;
6608 +  delete can;
6609 + }
6610 +  
6611  
6612   void test() {
6613    
6614 +  
6615 +  float MCPeak, MCPeakError, DataPeak, DataPeakError;
6616 +  stringstream result, datajzb, mcjzb;
6617 +  bool doPUreweighting=true;
6618 +  bool SwitchOffNJetsCut=false;
6619 +  
6620 +  
6621 +  TCanvas *can = new TCanvas("can","can");
6622 +  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
6623 +  
6624 +  float NumVtxBin[6] = {0,5,10,15,20,30};
6625 +  
6626 +  stringstream NowCut;
6627 +  
6628 +  TGraphErrors *gMCPeak = new TGraphErrors();
6629 +  gMCPeak->SetTitle("gMCPeak");
6630 +  gMCPeak->SetName("gMCPeak");
6631 +  TGraphErrors *gDataPeak = new TGraphErrors();
6632 +  gDataPeak->SetTitle("gDataPeak");
6633 +  gDataPeak->SetName("gDataPeak");
6634 +  TGraphErrors *gMCWidth = new TGraphErrors();
6635 +  gMCWidth->SetTitle("gMCWidth");
6636 +  gMCWidth->SetName("gMCWidth");
6637 +  TGraphErrors *gDataWidth = new TGraphErrors();
6638 +  gDataWidth->SetTitle("gDataWidth");
6639 +  gDataWidth->SetName("gDataWidth");
6640 +  
6641 +  float AllMCPeaks[200];
6642 +  float AllMCPeaksErrors[200];
6643 +  
6644 +  for(int i=10;i<180;i+=20) {
6645 +    NowCut.str("");
6646 +    NowCut << "mll>=" << i << "&&mll<" << i+20;
6647 +    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
6648 +    AllMCPeaks[i]=MCPeak;
6649 +    AllMCPeaksErrors[i]=MCPeakError;
6650 +  }
6651 +  
6652 +  dout << "Summary : " << endl;
6653 +  for(int i=10;i<180;i+=20) {
6654 +    dout << "For the slice at [" << i << " , " << i+20 << "] we get a peak at " << AllMCPeaks[i] << " +/- " << AllMCPeaksErrors[i] << endl;
6655 +  }
6656 +  /*
6657    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
6658    testcanv->cd();
6659   //  switch_overunderflow(true);
6660 <  TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
6661 <  switch_overunderflow(false);
6662 <  ptdistr->Draw();
6663 <  testcanv->SaveAs("test.png");
6664 <  dout << "HELLO there!" << endl;
6660 >  TH1F *histo1 = new TH1F("histo","histo",100,0,1);
6661 >  histo1->Sumw2();
6662 >  TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
6663 >  histo2->Sumw2();
6664 >  
6665 >  for(int i=0;i<100;i++) {
6666 >    histo1->Fill(1.0/i,i);
6667 >    histo2->Fill(1.0/(i*i),i);
6668 >  }
6669 >
6670 >  histo1->Draw();
6671 >  histo2->Draw("e1,same");
6672 >  
6673 >  Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
6674    
6675 +  
6676 +  dout << "HELLO there!" << endl;
6677 +  */
6678   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines