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.80 by buchmann, Thu Jan 24 08:16:17 2013 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 234 | Line 666 | void make_special_obs_pred_mll_plot(stri
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  
854    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
855    rcan->SetLogy(logscale);
# Line 409 | 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 446 | Line 912 | float make_one_OFSF_plot(string variable
912    //signalhisto->Delete();
913    delete mleg;
914    delete rcan;
915 +  delete ofsf_can;
916  
917    return ymaxSet;
918  
# Line 615 | Line 1082 | void DoMCSystPlot(string datavariable, s
1082    string saveas="kin/"+filename;
1083    
1084    cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1085 <  save_with_ratio_and_sys_band( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
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);
# Line 924 | 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 943 | 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 1050 | Line 1520 | void make_ttbar_comparison(string datava
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/11)" << std::flush;
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/11)" << std::flush;
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/11)" << std::flush;
1535 <  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("TTJets_"));
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/11)" << std::flush;
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/11)" << std::flush;
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/11)" << std::flush;
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/11)" << std::flush;
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    
1084  cout << "\r Creating " << filename << " : MC mass=166   (8/11)" << std::flush;
1085  TH1F *Ttmass166       = systsamples.Draw("Ttmass166",    mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_mass166"));
1086  TH1F *Rtmass166       = ProduceTTbarRatio(datahisto,MCcentral,TCentral,Ttmass166);
1087  
1088  cout << "\r Creating " << filename << " : MC mass=169   (9/11)" << std::flush;
1089  TH1F *Ttmass169       = systsamples.Draw("Ttmass169",    mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_mass169"));
1090  TH1F *Rtmass169       = ProduceTTbarRatio(datahisto,MCcentral,TCentral,Ttmass169);
1091  
1092  cout << "\r Creating " << filename << " : MC mass=175   (10/11)" << std::flush;
1093  TH1F *Ttmass175       = systsamples.Draw("Ttmass175",    mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_mass175"));
1094  TH1F *Rtmass175       = ProduceTTbarRatio(datahisto,MCcentral,TCentral,Ttmass175);
1095  
1096  cout << "\r Creating " << filename << " : MC mass=178   (11/11)" << std::flush;
1097  TH1F *Ttmass178       = systsamples.Draw("Ttmass178",    mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_mass178"));
1098  TH1F *Rtmass178       = ProduceTTbarRatio(datahisto,MCcentral,TCentral,Ttmass178);
1099  
1100  
1554    datahisto->Draw("e1");
1555    ckin->Update();
1556    mcstack.Draw("histo,same");
# Line 1135 | Line 1588 | void make_ttbar_comparison(string datava
1588    TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1589    TScaleDown->SetLineStyle(3);//dotted
1590    
1138  Ttmass166->SetLineColor(TColor::GetColor("#0acf00"));//green
1139  Ttmass166->SetLineStyle(3);//dotted
1140  Ttmass178->SetLineColor(TColor::GetColor("#0acf00"));
1141  Ttmass178->SetLineStyle(2);//dashed
1142  
1143  
1144  Ttmass169->SetLineColor(TColor::GetColor("#FF52F1"));//purple
1145  Ttmass169->SetLineStyle(3);//dotted
1146  Ttmass175->SetLineColor(TColor::GetColor("#FF52F1"));
1147  Ttmass175->SetLineStyle(2);//dashed
1148  
1149  
1150  
1151  
1591    MCcentral->SetLineStyle(3);
1592    MCcentral->SetLineColor(kRed);
1593    
# Line 1158 | Line 1597 | void make_ttbar_comparison(string datava
1597    TMatchingDown->Draw("histo,same");
1598    TScaleUp->Draw("histo,same");
1599    TScaleDown->Draw("histo,same");
1161  Ttmass166->Draw("histo,same");
1162  Ttmass169->Draw("histo,same");
1163  Ttmass175->Draw("histo,same");
1164  Ttmass178->Draw("histo,same");
1600    
1601    TLegend *sleg = make_legend();
1602    sleg->AddEntry(TCentral,"Central","L");
# Line 1169 | Line 1604 | void make_ttbar_comparison(string datava
1604    sleg->AddEntry(TMatchingDown,"matching down","L");
1605    sleg->AddEntry(TScaleUp,"scale up","L");
1606    sleg->AddEntry(TScaleDown,"scale down","L");
1172  sleg->AddEntry(Ttmass166,"m_{t}=166","L");
1173  sleg->AddEntry(Ttmass169,"m_{t}=169","L");
1174  sleg->AddEntry(Ttmass175,"m_{t}=175","L");
1175  sleg->AddEntry(Ttmass178,"m_{t}=178","L");
1607    sleg->Draw();
1608    
1609    CompleteSave(ckin,saveas+"___AllLines");
# Line 1191 | Line 1622 | void make_ttbar_comparison(string datava
1622    RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1623    RScaleDown->SetLineStyle(3);//dotted
1624    
1194  Rtmass166->SetLineColor(TColor::GetColor("#0acf00"));//green
1195  Rtmass166->SetLineStyle(3);//dotted
1196  Rtmass178->SetLineColor(TColor::GetColor("#0acf00"));
1197  Rtmass178->SetLineStyle(2);//dashed
1198  
1199  
1200  Rtmass169->SetLineColor(TColor::GetColor("#FF52F1"));//purple
1201  Rtmass169->SetLineStyle(3);//dotted
1202  Rtmass175->SetLineColor(TColor::GetColor("#FF52F1"));
1203  Rtmass175->SetLineStyle(2);//dashed
1204
1205  
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");
1212  Rtmass166->Draw("histo,same");
1213  Rtmass169->Draw("histo,same");
1214  Rtmass175->Draw("histo,same");
1215  Rtmass178->Draw("histo,same");
1631    
1632    CompleteSave(ckin,saveas+"___AllRatios");
1633  
1634 <  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1000,1000);
1635 <  multicanvas->Divide(2,2);
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");
1223  PresentRange(Rtmass166,Rtmass178,RCentral,multicanvas->cd(3),"m_{t} (2#sigma)");
1224  PresentRange(Rtmass169,Rtmass175,RCentral,multicanvas->cd(4),"m_{t} (1#sigma)");
1638    CompleteSave(multicanvas,saveas+"___RangeIllustration");
1639    
1640    
# Line 1231 | Line 1644 | void make_ttbar_comparison(string datava
1644    delete   TMatchingDown;
1645    delete   TScaleUp;
1646    delete   TScaleDown;
1647 <  delete   Ttmass166;
1648 <  delete   Ttmass169;
1649 <  delete   Ttmass175;
1650 <  delete   Ttmass178;
1647 > //   delete   Ttmass166;
1648 > //   delete   Ttmass169;
1649 > //   delete   Ttmass175;
1650 > //   delete   Ttmass178;
1651    
1652    delete ckin;
1653    
# Line 1273 | Line 1686 | void ProduceJanPlots() {
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) {
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!)
# Line 1294 | Line 1707 | THStack MakeOneSystematicsPlot(TCut cut,
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 <  
1722 >    
1723    TLegend *fullleg = allsamples.allbglegend();
1724    fullleg->SetHeader(variation.c_str());
1725    TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
# Line 1323 | Line 1743 | THStack MakeOneSystematicsPlot(TCut cut,
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");
1326
1746    TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1747    
1748 <  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label);
1749 <  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label);
1750 <  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label);
1751 <  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label);
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 <  DeleteStack(ScaleUp);
1340 <  DeleteStack(ScaleDown);
1341 <  DeleteStack(MatchingUp);
1342 <  DeleteStack(MatchingDown);
1343 <  
1344 <  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label);
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");
# Line 1363 | Line 1779 | void ProduceMCSystematicPlot(string vari
1779    TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1780    kinpad->SetLogy(1);
1781    kinpad->cd();
1782 <  hdata->Draw("e1");
1783 <  Central.Draw("histo,same");
1784 <  hdata->Draw("e1,same");
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();
1370
1371  save_with_ratio_and_sys_band( hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
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;
# Line 1382 | Line 1890 | void ProduceMCSystematicPlot(string vari
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 <  ProduceMCSystematicPlot("met[4]",80,0,400,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
2206 <  ProduceMCSystematicPlot("met[4]",80,0,400,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
2207 <  ProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
2208 <  ProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
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());
# Line 1396 | Line 2253 | void ProduceMCSystematicPlots() {
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 <  ProduceMCSystematicPlot("met[4]",80,0,400,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
2257 <  ProduceMCSystematicPlot("met[4]",80,0,400,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
2258 <  ProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>150"),"MCSystPlots/NJets/Aachen_SameFlavor");
2259 <  ProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>150"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
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 1410 | Line 2453 | void do_kinematic_plots(string mcjzb, st
2453    bool dolog=true;
2454    bool nolog=false;
2455  
2456 <  bool doOFSF = true;
2457 <  bool doKin  = true;
2458 <  bool doDataComp = true;
2459 <  bool MakeTwoThreeJetComparison = true;
2456 >  bool doOFSF = false;
2457 >  bool doKin  = false;
2458 >  bool doDataComp = false;
2459 >  bool MakeTwoThreeJetComparison = false;
2460    
2461  
2462    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
# Line 1425 | Line 2468 | void do_kinematic_plots(string mcjzb, st
2468    }
2469    
2470    if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2471 +  
2472 +  //TauQuestion();
2473  
2474    //ProduceJanPlots();
2475 < //   ProduceMCSystematicPlots();
2476 <  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
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 ) {
1434 <     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
1435 <
1436 <     make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
1437 <     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
1438 <     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
1439 <
1440 <     make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
1441 <     make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
1442 <
1443 <     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
1444 <     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
1445 <     make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
1446 <     make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
1447 <     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
1448 <     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
1449 <     make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
1450 <     make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
1451 <     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
1452 <     make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
1453 <    make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
1454 <    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
1455 <    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
1456 <    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");
1457 <    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");
1458 <    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");
1459 <    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");
1460 <  }
2479 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2480  
2481    if ( doDataComp) {
2482      TCut mllCut("");
# Line 1551 | Line 2570 | void do_kinematic_plots(string mcjzb, st
2570  
2571    if ( doKin ) {
2572      string mllCut("");
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);
# Line 1597 | Line 2640 | void do_kinematic_plots(string mcjzb, st
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,"MET [GeV]","met",doPF,true);
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 <    
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");
# Line 1693 | 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 <
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 <
2760 > */
2761    switch_overunderflow(false);
2762   }
2763  
# Line 1728 | 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 1790 | 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 1822 | 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 1837 | 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 1880 | 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 2092 | 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 2113 | 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 2132 | 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 2296 | 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 2323 | 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");
# Line 2390 | 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 2403 | 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";
# Line 2451 | 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    
2479  TFile *f = new TFile("tester.root","RECREATE");
2480  RcorrJZBeemm->Write();
2481  Bpred->Write();
2482  f->Close();
2483  
3546    delete RcorrJZBeemm;
3547    delete LcorrJZBeemm;
3548    delete RcorrJZBem;
# Line 2510 | 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 2542 | 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 2608 | Line 3677 | void lepton_comparison_plots() {
3677    DrawPrelim();
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 2814 | 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 2943 | 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 3038 | 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 3257 | 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 3266 | 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 3295 | 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 3324 | 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 3341 | 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;
3353 <  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 3436 | 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 3462 | 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 3730 | 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");  
3740 //  zcan->SetLogy(1);
4888    TCut weightbackup=cutWeight;
4889    
4890    bool UsePURW=true;
# Line 3763 | 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 3780 | 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"));
3790 <  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 3808 | 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 3816 | 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  
4973    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 3836 | 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"));
3843 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
3844 <  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  
4993    TH1F *RcorrJZBSBem;
4994    TH1F *LcorrJZBSBem;
# Line 3849 | Line 4996 | void zjets_prediction_comparison(string
4996    TH1F *LcorrJZBSBeemm;
4997  
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 3889 | 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 3923 | 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;
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 4450 | 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 4487 | 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 4540 | Line 5795 | void met_vs_jzb_plots(string datajzb, st
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 4562 | 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 4590 | 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