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

Comparing UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C (file contents):
Revision 1.56 by buchmann, Wed Sep 5 20:16:25 2012 UTC vs.
Revision 1.87 by buchmann, Mon Feb 25 18:00:09 2013 UTC

# Line 33 | Line 33 | void todo() {
33  
34  
35  
36 < void find_one_peak_combination(TCut specialcut, float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &MCSigmaError, float &DataSigma, float& DataSigmaError, stringstream &result, bool doPUreweighting = true, string saveas="")
36 > 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="")
37   {
38    // Temporarily switch off PU reweighting, if asked
39    TCut weightbackup=cutWeight;
# Line 42 | Line 42 | void find_one_peak_combination(TCut spec
42    int nbins=100;
43    if(PlottingSetup::DoBTag) nbins=25;
44    
45 +  TCut nJetsCut(cutnJets);
46 +  if(SwitchOffNJetsCut) nJetsCut=specialcut;
47 +  
48    TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
49 <  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,mc, luminosity);
50 <  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,data, luminosity);
51 <  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,mc, luminosity);
52 <  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,data, luminosity);
49 >  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,mc, luminosity);
50 >  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&nJetsCut&&specialcut,data, luminosity);
51 >  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&nJetsCut&&specialcut,mc, luminosity);
52 >  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&nJetsCut&&specialcut,data, luminosity);
53    TH1F *rawttbarjzbeemmMC;
54  
55    if(method==doKM) {
56      //we only need this histo for the KM fitting...
57 <    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,nbins, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&specialcut,mc,luminosity,allsamples.FindSample("TTJet"));
57 >    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,nbins, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&nJetsCut&&specialcut,mc,luminosity,allsamples.FindSample("TTJet"));
58      MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,MCSigmaError,method,saveas);
59      DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,DataSigmaError,method,saveas);
60      delete rawttbarjzbeemmMC;
# Line 84 | Line 87 | void find_one_peak_combination(TCut spec
87    delete tempcan;
88   }
89  
90 < void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb)
90 > void DoPeakVsPU() {
91 >  cout << "Trying to find peak position as a function of PU" << endl;
92 >  float MCPeak, MCPeakError, DataPeak, DataPeakError;
93 >  stringstream result, datajzb, mcjzb;
94 >  bool doPUreweighting=true;
95 >  bool SwitchOffNJetsCut=false;
96 >  
97 >  
98 >  TCanvas *can = new TCanvas("can","can");
99 >  float mcSigma,mcSigmaError,dataSigma,dataSigmaError;
100 >  
101 >  float NumVtxBin[6] = {0,5,10,15,20,30};
102 >  
103 >  stringstream NowCut;
104 >  
105 >  TGraphErrors *gMCPeak = new TGraphErrors();
106 >  gMCPeak->SetTitle("gMCPeak");
107 >  gMCPeak->SetName("gMCPeak");
108 >  TGraphErrors *gDataPeak = new TGraphErrors();
109 >  gDataPeak->SetTitle("gDataPeak");
110 >  gDataPeak->SetName("gDataPeak");
111 >  TGraphErrors *gMCWidth = new TGraphErrors();
112 >  gMCWidth->SetTitle("gMCWidth");
113 >  gMCWidth->SetName("gMCWidth");
114 >  TGraphErrors *gDataWidth = new TGraphErrors();
115 >  gDataWidth->SetTitle("gDataWidth");
116 >  gDataWidth->SetName("gDataWidth");
117 >  
118 >  for(int i=0;i<5;i++) {
119 >    NowCut.str("");
120 >    NowCut << "numVtx>=" << NumVtxBin[i] << "&&numVtx<" << NumVtxBin[i+1];
121 >    find_one_peak_combination(TCut(NowCut.str().c_str()),SwitchOffNJetsCut,MCPeak,MCPeakError, DataPeak,DataPeakError,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
122 >    cout << "    " << MCPeak << " +/- " << MCPeakError << endl;
123 >    cout << "    " << DataPeak << " +/- " << DataPeakError << endl;
124 >    
125 >    gMCPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),MCPeak);
126 >    gMCPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),MCPeakError);
127 >    
128 >    gDataPeak->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),DataPeak);
129 >    gDataPeak->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),DataPeakError);
130 >    
131 >    gMCWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),mcSigma);
132 >    gMCWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),mcSigmaError);
133 >    
134 >    gDataWidth->SetPoint(i,0.5*(NumVtxBin[i]+NumVtxBin[i+1]),dataSigma);
135 >    gDataWidth->SetPointError(i,0.5*(NumVtxBin[i+1]-NumVtxBin[i]),dataSigmaError);
136 >  }
137 >  
138 >  can->cd();
139 >  gMCPeak->GetXaxis()->SetTitle("N(Vertices)");
140 >  gMCPeak->GetYaxis()->SetTitle("Peak position");
141 >  gMCPeak->GetXaxis()->CenterTitle();
142 >  gMCPeak->GetYaxis()->CenterTitle();
143 >  gDataPeak->GetXaxis()->SetTitle("N(Vertices)");
144 >  gDataPeak->GetYaxis()->SetTitle("Peak position");
145 >  gDataPeak->GetXaxis()->CenterTitle();
146 >  gDataPeak->GetYaxis()->CenterTitle();
147 >  
148 >  gDataWidth->GetXaxis()->SetTitle("N(Vertices)");
149 >  gDataWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
150 >  gDataWidth->GetXaxis()->CenterTitle();
151 >  gDataWidth->GetYaxis()->CenterTitle();
152 >  gMCWidth->GetXaxis()->SetTitle("N(Vertices)");
153 >  gMCWidth->GetYaxis()->SetTitle("#sigma_{JZB}");
154 >  gMCWidth->GetXaxis()->CenterTitle();
155 >  gMCWidth->GetYaxis()->CenterTitle();
156 >  
157 >  gMCPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
158 >  gDataPeak->SetFillColor(TColor::GetColor("#2E9AFE"));
159 >  gDataWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
160 >  gMCWidth->SetFillColor(TColor::GetColor("#2E9AFE"));
161 >  
162 >  gMCPeak->Draw("A2");
163 >  DrawMCPrelim();
164 >  CompleteSave(can,"PUStudy/MCPeak");
165 >  can->cd();
166 >  gMCWidth->Draw("A2");
167 >  DrawMCPrelim();
168 >  CompleteSave(can,"PUStudy/MCWidth");
169 >  can->cd();
170 >  
171 >  gDataPeak->Draw("A2");
172 >  DrawPrelim();
173 >  CompleteSave(can,"PUStudy/DataPeak");
174 >  can->cd();
175 >  gDataWidth->Draw("A2");
176 >  DrawPrelim();
177 >  CompleteSave(can,"PUStudy/DataWidth");
178 >  
179 >  
180 >  
181 >  delete can;
182 >  
183 > }
184 >
185 > void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb, string sSpecialCut="", bool SwitchOffNJetsCut=false)
186   {
187 +  bool overunderflowstatus=addoverunderflowbins;
188    switch_overunderflow(false);
189 <
189 >  
190 >  TCut SpecialCut("mll>=0");
191 >  if(sSpecialCut!="") SpecialCut=TCut(sSpecialCut.c_str());
192 >  
193    bool DoInvidualeemmPeaks=false;
194    
195    float mcpeak, datapeak;
# Line 102 | Line 204 | void find_peaks(float &MCPeak,float &MCP
204    float mcSigma,mcSigmaError, dataSigma, dataSigmaError;
205    
206    dout << "Finding global peak : " << endl;
207 <  find_one_peak_combination(TCut(""),mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
207 >  find_one_peak_combination(SpecialCut,SwitchOffNJetsCut,mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
208    
209    if(DoInvidualeemmPeaks) {
210      dout << "Finding peak for electrons : " << endl;
211 <    find_one_peak_combination(TCut("id1==0"),mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
211 >    find_one_peak_combination(SpecialCut&&TCut("id1==0"),SwitchOffNJetsCut,mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
212      dout << "Finding peak for muons : " << endl;
213 <    find_one_peak_combination(TCut("id1==1"),mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
213 >    find_one_peak_combination(SpecialCut&&TCut("id1==1"),SwitchOffNJetsCut,mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
214      
215      datajzb << "(" << jzbvariabledata;
216      mcjzb << "(" << jzbvariablemc;
# Line 154 | Line 256 | void find_peaks(float &MCPeak,float &MCP
256      MCPeakError=mcpeakerr;
257      DataPeak=datapeak;
258      DataPeakError=datapeakerr;
259 <    
158 <    switch_overunderflow(true);
159 <  
259 >    switch_overunderflow(overunderflowstatus);
260   }
261  
262   void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
# Line 223 | Line 323 | void make_special_obs_pred_mll_plot(stri
323    
324    RcorrJZBeemm->SetTitleOffset(1.3,"y");
325    RcorrJZBeemm->Draw();
326 <  mcRcorrJZBeemm.Draw("same");
326 >  mcRcorrJZBeemm.Draw("histo,same");
327    Bpred->Draw("histo,same");
328    RcorrJZBeemm->Draw("same");
329    
# Line 280 | Line 380 | void make_special_obs_pred_mll_plot(stri
380    }
381    delete Bpred;
382    delete ckin;
383 +  CleanLegends();
384   }
385  
386   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
# Line 300 | Line 401 | void make_special_mll_plot(int nbins, fl
401    datahistoOSSF->SetMarkerSize(DataMarkerSize);
402    datahistoOSSF->Draw();
403  
404 <  mcstackOSSF.Draw("same");
404 >  mcstackOSSF.Draw("histo,same");
405    datahistoOSSF->Draw("same");
406  
407    datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
# Line 326 | Line 427 | void make_special_mll_plot(int nbins, fl
427    delete datahistoOSOF;
428    delete datahistoOSSF;
429    delete ckin;
430 +  CleanLegends();
431   }
432    
433  
# Line 367 | Line 469 | void draw_ratio_plot(TH1* hdata, THStack
469   }
470  
471   float make_one_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, float ymax, bool logscale,
472 <                        string xlabel, string filename, bool plotratio=true, bool loadlastminmax=false, float legendPosition=0.55) {
472 >                        string xlabel, string filename, float legendPosition=0.55) {
473  
474    TCut ibasiccut=basiccut;
475    bool draw_separation_lines=false;
# Line 379 | Line 481 | float make_one_OFSF_plot(string variable
481  
482    cutOF = cutOSOF&&cutnJets&&ibasiccut;
483    cutSF = cutOSSF&&cutnJets&&ibasiccut;
484 +  
485 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
486  
383  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
487    TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
488    rcan->SetLogy(logscale);
489    rcan->cd();
490  
491 +  std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
492    TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
493    TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
494 <  string signal("LM3");
495 <  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
496 <  int idx = signalsamples.FindSample(signal)[0];
497 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
498 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
499 <  signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
500 <  signalhisto->SetLineStyle(2);
494 > //   string signal("LM3");
495 > //   TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
496 > //   int idx = signalsamples.FindSample(signal)[0];
497 > //   (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
498 > //   signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
499 > //   signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
500 > //   signalhisto->SetLineStyle(2);
501    datahistoSF->SetMarkerSize(DataMarkerSize);
502    datahistoOF->SetLineColor(kRed);
503  
# Line 404 | Line 508 | float make_one_OFSF_plot(string variable
508    }
509    if (ymax<0) {
510      if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
511 <    else datahistoSF->SetMaximum(1.5*datahistoSF->GetMaximum());
511 >    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
512    } else {
513      datahistoSF->SetMaximum(ymax);
514    }
# Line 423 | Line 527 | float make_one_OFSF_plot(string variable
527    } else {
528      mleg->AddEntry((TObject*)0, "", "");
529    }
530 <  mleg->AddEntry(signalhisto, "LM3", "L");
530 >  //mleg->AddEntry(signalhisto, "LM3", "L");
531  
532    datahistoSF->Draw("E1");
533    if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
534 <  signalhisto->Draw("HIST,SAMES");
534 >  //signalhisto->Draw("HIST,SAMES");
535    mleg->Draw();
536    DrawPrelim();
537 <  if (datahistoOF->Integral()>0) save_with_ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
538 <  else CompleteSave(ckin, "SFOF/" + filename);
537 >  if (datahistoOF->Integral()>0) {
538 >    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
539 >  } else {
540 >    CompleteSave(rcan, "SFOF/" + filename);
541 >  }
542  
543    datahistoSF->Delete();
544    datahistoOF->Delete();
545 <  signalhisto->Delete();
545 >  //signalhisto->Delete();
546    delete mleg;
547 <  delete ckin;
547 >  delete rcan;
548 >  delete ofsf_can;
549  
550    return ymaxSet;
551  
# Line 458 | Line 566 | float make_data_comparison_plot(string v
566  
567    TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
568    TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
569 +  data1->Scale(5.0/9.2);
570  
571    data1->SetMarkerSize(DataMarkerSize);
572    data2->SetLineColor(kRed);
# Line 482 | Line 591 | float make_data_comparison_plot(string v
591    data1->GetYaxis()->CenterTitle();
592  
593    TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
594 <  mleg->AddEntry(data1, "Old 5/fb", "PL");
595 <  mleg->AddEntry(data2, "New x/fb", "L");
594 >  mleg->AddEntry(data1, "2012 data (scaled)", "PL");
595 >  mleg->AddEntry(data2, "2011 data", "L");
596  
597    data1->Draw("E1");
598    data2->Draw("HIST,SAMES");
599    mleg->Draw();
600    DrawPrelim();
601 <  save_with_ratio( data1, data2, rcan, "compareData/" + filename, false, false, "old/new" );
601 >  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
602  
603    data1->Delete();
604    data2->Delete();
605    delete mleg;
606 +  delete rcan;
607    delete ckin;
608  
609   }
# Line 501 | Line 611 | float make_data_comparison_plot(string v
611   void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
612                       string xlabel, string filename, float legendPosition=0.55) {
613  
614 <  string mllcuts[] = { "mll>20","mll>20&&mll<70", "mll>75&&mll<105", "mll>120" };
615 <  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "75 < m_{ll} < 105 GeV", "m_{ll} > 120 GeV" };
614 >  string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
615 >  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
616    string plotname[] = {"_all","_low","_peak","_high"};
617    float ymax;
618  
# Line 512 | Line 622 | void make_OFSF_plots(string variable, st
622    for ( int i=start; i<4; ++i ) {
623      if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
624      if ( i==start ) {
625 <      ymax = make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, -1, logscale, xlabel,
625 >      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
626                           filename+plotname[i], legendPosition );
627      } else {
628 <      make_one_OFSF_plot(variable, mllcuts[i],            mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
628 >      make_one_OFSF_plot(variable, mllcuts[i],        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
629                           filename+plotname[i], legendPosition );
630      }
631      make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
# Line 526 | Line 636 | void make_OFSF_plots(string variable, st
636  
637   }
638  
639 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
640 +  string scut=(string)(const char*)cut;
641 +  string acut=ReplaceAll(scut,replacethis,withthis);
642 +  return TCut(acut.c_str());
643 + }
644 +
645 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
646 +  TCut cut=addcut&&basiccut;
647  
648 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
649 +  ckin->SetLogy(dolog);
650 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
651 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
652 +  datahisto->SetMarkerSize(DataMarkerSize);
653 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
654 +  else datahisto->SetMinimum(0.5);
655 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
656 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
657 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
658 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
659 +  TH1F *MCcentral = CollapseStack(mcstack);
660 +
661 +  TCut bkpcut = cut;
662 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
663 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
664 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
665 +
666 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
667 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
668 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
669 +  
670 +  cut=bkpcut;
671 +  TCut bkpweight = cutWeight;
672 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
673 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
674 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
675 +  
676 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
677 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
678 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
679 +  cutWeight=bkpweight;
680 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
681 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
682 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
683 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
684 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
685 +    float jes   = jesdn>jesup?jesdn:jesup;
686 +    
687 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
688 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
689 +    float pu   = PUdn>PUup?PUdn:PUup;
690 +    
691 +    float sys=sqrt(jes*jes+pu*pu);
692 +    sys/=MCcentral->GetBinContent(i);
693 +    if(MCcentral->GetBinContent(i)==0) sys=0;
694 +    Systematic->SetBinContent(i,sys);
695 +  }
696 +  
697 +  datahisto->Draw("e1");
698 +  ckin->Update();
699 +  mcstack.Draw("histo,same");
700 +  
701 +  datahisto->Draw("same,e1");
702 +  TLegend *kinleg = allsamples.allbglegend();
703 +  kinleg->Draw();
704 +
705 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
706 +  kinpad->SetLogy(dolog);
707 +  kinpad->cd();
708 +  datahisto->Draw("e1");
709 +  mcstack.Draw("histo,same");
710 +  datahisto->Draw("same,e1");
711 +  datahisto->Draw("same,axis");
712 +  
713 +  kinleg->Draw("same");
714 +  DrawPrelim();
715 +  string saveas="kin/"+filename;
716 +  
717 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
718 +  save_with_ratio_and_sys_band( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
719 +  
720 +  ckin->cd();
721 +  MCcentral->SetFillColor(kWhite);
722 +  MCcentral->SetLineColor(kBlack);
723 +  MCcentral->SetLineWidth(2);
724 +  MCPUdn->SetLineColor(kRed);
725 +  MCPUup->SetLineColor(kYellow);
726 +  MCJESdn->SetLineColor(kBlue);
727 +  MCJESup->SetLineColor(kGreen);
728 +  
729 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
730 +  legsmall->SetNColumns(5);
731 +  legsmall->AddEntry(MCcentral,"central","L");
732 +  legsmall->AddEntry(MCPUdn,"PU down","L");
733 +  legsmall->AddEntry(MCPUup,"PU up","L");
734 +  legsmall->AddEntry(MCJESdn,"JES down","L");
735 +  legsmall->AddEntry(MCJESup,"JES up","L");
736 +  legsmall->SetFillColor(kWhite);
737 +  legsmall->SetBorderSize(0);
738 +  
739 +  datahisto->Draw("e1");
740 +  MCcentral->Draw("histo,same");
741 +  MCPUdn->Draw("histo,same");
742 +  MCPUup->Draw("histo,same");
743 +  MCJESdn->Draw("histo,same");
744 +  MCJESup->Draw("histo,same");
745 +  datahisto->Draw("e1,same");
746 +  legsmall->Draw();
747 +  CompleteSave(ckin,saveas+"___AllLines");
748 +  
749 +  delete datahisto;
750 +  delete MCcentral;
751 +  delete MCPUdn;
752 +  delete MCPUup;
753 +  delete MCJESdn;
754 +  delete MCJESup;
755 +  delete ckin;
756 + }
757 +
758 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
759 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
760 + }
761 +  
762   float lastrange_min=0;
763   float lastrange_max=0;
764  
# Line 535 | Line 767 | void make_kin_plot(string variable, stri
767   //  TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
768    TCut ibasiccut=basiccut;
769    bool draw_separation_lines=false;
770 +  bool drawsignal = false;
771    
772    if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
773  
# Line 556 | Line 789 | void make_kin_plot(string variable, stri
789    //Step 2: Refine the cut
790    TCut cut;
791    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
792 <  if(filename=="nJets" || filename=="nJets_inclusive") cut=cutmass&&cutOSSF&&ibasiccut;
793 <  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive") cut=cutmass&&cutOSOF&&ibasiccut;
792 >  if(filename=="nJets" || filename=="nJets_inclusive" || filename=="nJets_met100" || filename=="nJets_inclusive_met100") cut=cutmass&&cutOSSF&&ibasiccut;
793 >  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive" || filename=="nJets_osof_met100" || filename=="nJets_osof_inclusive_met100") cut=cutmass&&cutOSOF&&ibasiccut;
794    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
795 <  if(filename=="mll") {
795 >  if(filename=="mll"||filename=="mll_met100") {
796          cut=cutOSSF&&cutnJets&&ibasiccut;
797          draw_separation_lines=true;
798    }
799 <  if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
800 <  if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
801 <  if(filename=="mll_osof") {
799 >  if(filename=="mll_ee"||filename=="mll_ee_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
800 >  if(filename=="mll_mm"||filename=="mll_mm_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
801 >  if(filename=="mll_osof"||filename=="mll_osof_met100") {
802          cut=cutOSOF&&cutnJets&&ibasiccut;
803          draw_separation_lines=true;
804    }
# Line 573 | Line 806 | void make_kin_plot(string variable, stri
806    if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
807    if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
808    if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
809 <  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutmass&&cutOSSF;
810 <  if(filename=="mll_inclusive_osof") cut=cutmass&&cutOSOF;
811 <  if(filename=="mll_inclusive_ee") cut=cutmass&&cutOSSF&&"id1==0";
812 <  if(filename=="mll_inclusive_mm") cut=cutmass&&cutOSSF&&"id1==1";
809 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
810 >  if(filename=="mll_inclusive_osof") cut=cutOSOF;
811 >  if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
812 >  if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
813    if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
814    if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
815    if(filename=="numVtx") cut=cutmass&&ibasiccut;
# Line 597 | Line 830 | void make_kin_plot(string variable, stri
830    if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
831    else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
832  
833 <  cout << "******** Cut used : " << (const char*) cut << endl;
833 >  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
834    if(loadlastminmax) {
835          datahisto->SetMinimum(lastrange_min);
836          datahisto->SetMaximum(lastrange_max);
# Line 611 | Line 844 | void make_kin_plot(string variable, stri
844    string signal("LM3");
845    TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
846    int idx = signalsamples.FindSample(signal)[0];
847 <  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
848 <  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
849 <  signalhisto->SetLineColor(kOrange);
847 >  if(drawsignal) (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
848 >  if(drawsignal) signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
849 >  if(drawsignal) signalhisto->SetLineColor(kOrange);
850  
851    THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
852    datahisto->Draw("e1");
853    ckin->Update();
854 <  mcstack.Draw("same");
854 >  mcstack.Draw("histo,same");
855    
856    datahisto->Draw("same,e1");
857    TLegend *kinleg = allsamples.allbglegend();
# Line 661 | Line 894 | void make_kin_plot(string variable, stri
894          kinpad->cd();
895          kinpad->SetLogy(logscale);
896          datahisto->Draw("e1");
897 <        mcstack.Draw("same");
898 <        signalhisto->Draw("same");
897 >        mcstack.Draw("histo,same");
898 >        if(drawsignal) signalhisto->Draw("same");
899          datahisto->Draw("same,e1");
900          datahisto->Draw("same,axis");
901          if(RestrictToMassPeak&&draw_separation_lines) {
# Line 670 | Line 903 | void make_kin_plot(string variable, stri
903            upperboundary->Draw("same");
904          }
905            
906 <        kinleg->AddEntry("signalhisto",signal.c_str(),"l");
906 >        if(drawsignal) kinleg->AddEntry("signalhisto",signal.c_str(),"l");
907          kinleg->Draw();
908          write_cut->Draw();
909          DrawPrelim();
910          string saveas="kin/"+filename;
911          if(isPF) saveas="kin/"+filename+"__PF";
912 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
912 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
913   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
914   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
915   //      delete with_ratio;
# Line 685 | Line 918 | void make_kin_plot(string variable, stri
918          else CompleteSave(ckin,"kin/"+filename);
919    }
920    datahisto->Delete();
921 +  delete signalhisto;
922    delete ckin;
923   }
924  
925 +
926 + void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
927 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
928 +  TCut cut=TCut(addcut.c_str())&&basiccut;
929 +
930 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
931 +  ckin->SetLogy(logscale);
932 +  TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
933 +  datahisto->SetMarkerSize(DataMarkerSize);
934 +  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
935 +  else datahisto->SetMinimum(0.5);
936 +  // Custom max.
937 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
938 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
939 +
940 +  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
941 +  if(loadlastminmax) {
942 +        datahisto->SetMinimum(lastrange_min);
943 +        datahisto->SetMaximum(lastrange_max);
944 +        if(logscale) {
945 +                datahisto->SetMinimum(pow(10,lastrange_min));
946 +                datahisto->SetMaximum(pow(10,lastrange_max));
947 +        }              
948 +  }
949 +
950 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
951 +  datahisto->Draw("e1");
952 +  ckin->Update();
953 +  mcstack.Draw("histo,same");
954 +  
955 +  datahisto->Draw("same,e1");
956 +  TLegend *kinleg = allsamples.allbglegend();
957 +  kinleg->Draw();
958 +
959 +  lastrange_min=ckin->GetUymin();
960 +  lastrange_max=ckin->GetUymax();
961 +
962 +  if ( plotratio ) {
963 +        TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
964 +        kinpad->cd();
965 +        kinpad->SetLogy(logscale);
966 +        datahisto->Draw("e1");
967 +        mcstack.Draw("histo,same");
968 +        datahisto->Draw("same,e1");
969 +        datahisto->Draw("same,axis");
970 +          
971 +        kinleg->Draw();
972 +        DrawPrelim();
973 +        string saveas="kin/"+filename;
974 +        if(isPF) saveas="kin/"+filename+"__PF";
975 +        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
976 +  } else {
977 +        if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
978 +        else CompleteSave(ckin,"kin/"+filename);
979 +  }
980 +  datahisto->Delete();
981 +  delete ckin;
982 + }
983 +
984 +
985   void make_JES_plot(TCut cut, string name) {
986  
987    int nbins=10;
# Line 721 | Line 1015 | void make_JES_plot(TCut cut, string name
1015    JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
1016    JESunc->SetFillStyle(3002);
1017    datahisto->Draw("e1");
1018 <  mcstack.Draw("same");
1018 >  mcstack.Draw("histo,same");
1019    JESunc->Draw("2");
1020    datahisto->Draw("same,e1");
1021    TLegend *kinleg = allsamples.allbglegend();
# Line 730 | Line 1024 | void make_JES_plot(TCut cut, string name
1024    CompleteSave(ckin,"Systematics/JES"+name);
1025    datahisto->Delete();
1026    delete ckin;
1027 +  delete JESunc;
1028 +  delete JESup;
1029 +  delete JESdn;
1030 +  CleanLegends();
1031 + }
1032 +
1033 + string Cut2Str(TCut cut) {
1034 +  return ((string)(const char*)cut);
1035 + }
1036 +
1037 + void MakeElegantTwoThreeComparisons() {
1038 +    
1039 +    TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
1040 +    TCut TwoJets("pfJetGoodNum40==2");
1041 +    TCut ThreeJets("pfJetGoodNum40>=3");
1042 +    
1043 +    float min=20;
1044 +    float max=300;
1045 +    int nbins=int((max-min)/5.0);
1046 +    string xlabel="m_{ll} [GeV]";
1047 +    
1048 +    TCanvas *can2 = new TCanvas("can2","can2");
1049 +    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1050 +    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1051 +    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1052 +    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1053 +    
1054 +    can2->cd(1);
1055 +    
1056 +    TwoSF->SetFillColor(kWhite);
1057 +    TwoOF->SetFillColor(kWhite);
1058 +    ThreeSF->SetFillColor(kWhite);
1059 +    ThreeOF->SetFillColor(kWhite);
1060 +    
1061 +    TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1062 +    kin3->cd();
1063 +    TwoOF->Draw("histo");
1064 +    TwoSF->Draw("e1,same");
1065 +    TLegend *leg_SFOF_Two = make_legend();
1066 +    leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1067 +    leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1068 +    leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1069 +    leg_SFOF_Two->Draw();
1070 +    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1071 +    
1072 +    TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1073 +    kin4->cd();
1074 +    ThreeOF->Draw("histo");
1075 +    ThreeSF->Draw("e1,same");
1076 +    TLegend *leg_SFOF_Three = make_legend();
1077 +    leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1078 +    leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1079 +    leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1080 +    leg_SFOF_Three->Draw();
1081 +    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1082 +    
1083 +    
1084 +    TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1085 +    TPad *kin = new TPad("kin","kin",0,0,1,1);
1086 +    kin->cd();
1087 +    TwoSF->Draw("histo");
1088 +    ThreeSF->Draw("e1,same");
1089 +    TLegend *leg_SF_Two_Three = make_legend();
1090 +    leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1091 +    leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1092 +    leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1093 +    leg_SF_Two_Three->Draw();
1094 +    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1095 +    
1096 +    TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1097 +    TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1098 +    kin2->cd();
1099 +    TwoOF->Draw("histo");
1100 +    ThreeOF->Draw("e1,same");
1101 +    TLegend *leg_OF_Two_Three = make_legend();
1102 +    leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1103 +    leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1104 +    leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1105 +    leg_OF_Two_Three->Draw();
1106 +    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1107 +    
1108 + }
1109 +
1110 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1111 +  pad->cd();
1112 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1113 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1114 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1115 +    float error=abs(Down->GetBinContent(i)-average);
1116 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1117 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1118 +  }
1119 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1120 +  gr->GetYaxis()->SetRangeUser(0,2);
1121 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1122 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1123 +  gr->GetXaxis()->CenterTitle();
1124 +  gr->GetYaxis()->CenterTitle();
1125 +  
1126 +  gr->Draw("A2");
1127 +  central->Draw("e1,same");
1128 +  DrawMCPrelim();
1129 +  TText *rtitle = write_text(0.8,0.8,title);
1130 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1131 +  line->SetLineColor(kBlue);
1132 +  line->SetLineStyle(2);
1133 +  line->Draw("same");
1134 +  rtitle->Draw("same");
1135 + }
1136 +
1137 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1138 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1139 +  basehisto->Add(originalttbar,-1);
1140 +  basehisto->Add(httbar);
1141 +  
1142 +  string sname=httbar->GetName();
1143 +  sname="R"+sname.substr(1,sname.length());
1144 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1145 +  ratio->Divide(basehisto);
1146 +  delete basehisto;
1147 +  return ratio;
1148 + }
1149 +  
1150 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1151 +  
1152 +  TCut cut=addcut&&basiccut;
1153 +  
1154 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1155 +  ckin->SetLogy(dolog);
1156 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1157 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1158 +  datahisto->SetMarkerSize(DataMarkerSize);
1159 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1160 +  else datahisto->SetMinimum(0.5);
1161 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1162 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1163 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1164 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1165 +  TH1F *MCcentral = CollapseStack(mcstack);
1166 +
1167 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1168 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("TTJets_"));
1169 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1170 +  
1171 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1172 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1173 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1174 +  
1175 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1176 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1177 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1178 +  
1179 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1180 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1181 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1182 +  
1183 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1184 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1185 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1186 +  
1187 +  datahisto->Draw("e1");
1188 +  ckin->Update();
1189 +  mcstack.Draw("histo,same");
1190 +  
1191 +  datahisto->Draw("same,e1");
1192 +  TLegend *kinleg = allsamples.allbglegend();
1193 +  kinleg->Draw();
1194 +
1195 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1196 +  kinpad->SetLogy(dolog);
1197 +  kinpad->cd();
1198 +  datahisto->Draw("e1");
1199 +  mcstack.Draw("histo,same");
1200 +  datahisto->Draw("same,e1");
1201 +  datahisto->Draw("same,axis");
1202 +  
1203 +  kinleg->Draw("same");
1204 +  DrawPrelim();
1205 +  string saveas="kin/"+filename;
1206 +  
1207 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1208 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1209 +  delete kinpad;
1210 +  
1211 +  ckin->cd();
1212 +  TCentral->SetLineColor(kBlack);
1213 +  
1214 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1215 +  TMatchingUp->SetLineStyle(2);//dashed
1216 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1217 +  TMatchingDown->SetLineStyle(3);//dotted
1218 +  
1219 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1220 +  TScaleUp->SetLineStyle(2);//dashed
1221 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1222 +  TScaleDown->SetLineStyle(3);//dotted
1223 +  
1224 +  MCcentral->SetLineStyle(3);
1225 +  MCcentral->SetLineColor(kRed);
1226 +  
1227 +  TCentral->Draw("e1,same");
1228 +  TCentral->Draw("histo,same");
1229 +  TMatchingUp->Draw("histo,same");
1230 +  TMatchingDown->Draw("histo,same");
1231 +  TScaleUp->Draw("histo,same");
1232 +  TScaleDown->Draw("histo,same");
1233 +  
1234 +  TLegend *sleg = make_legend();
1235 +  sleg->AddEntry(TCentral,"Central","L");
1236 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1237 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1238 +  sleg->AddEntry(TScaleUp,"scale up","L");
1239 +  sleg->AddEntry(TScaleDown,"scale down","L");
1240 +  sleg->Draw();
1241 +  
1242 +  CompleteSave(ckin,saveas+"___AllLines");
1243 +  ckin->cd();
1244 +  ckin->SetLogy(0);
1245 +  
1246 +  RCentral->SetLineColor(kBlack);
1247 +  
1248 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1249 +  RMatchingUp->SetLineStyle(2);//dashed
1250 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1251 +  RMatchingDown->SetLineStyle(3);//dotted
1252 +  
1253 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1254 +  RScaleUp->SetLineStyle(2);//dashed
1255 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1256 +  RScaleDown->SetLineStyle(3);//dotted
1257 +  
1258 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1259 +  RCentral->Draw("e1");
1260 +  RMatchingUp->Draw("histo,same");
1261 +  RMatchingDown->Draw("histo,same");
1262 +  RScaleUp->Draw("histo,same");
1263 +  RScaleDown->Draw("histo,same");
1264 +  
1265 +  CompleteSave(ckin,saveas+"___AllRatios");
1266 +
1267 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1268 +  multicanvas->Divide(2,1);
1269 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1270 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1271 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1272 +  
1273 +  
1274 +  delete datahisto;
1275 +  delete   TCentral;
1276 +  delete   TMatchingUp;
1277 +  delete   TMatchingDown;
1278 +  delete   TScaleUp;
1279 +  delete   TScaleDown;
1280 + //   delete   Ttmass166;
1281 + //   delete   Ttmass169;
1282 + //   delete   Ttmass175;
1283 + //   delete   Ttmass178;
1284 +  
1285 +  delete ckin;
1286 +  
1287 + }
1288 +  
1289 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1290 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1291 + }
1292 +
1293 + void ProduceJanPlots() {
1294 +  TCanvas *c1 = new TCanvas("c1","c1");
1295 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1296 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1297 +  
1298 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1299 +  rcan->cd();
1300 +
1301 +  metOF->SetLineColor(kRed);
1302 +  metSF->Draw("e1");
1303 +  metOF->Draw("histo,same");
1304 +  metSF->Draw("e1,same");
1305 +  
1306 +  TLegend *leg = make_legend();
1307 +  
1308 +  leg->AddEntry(metSF,"Data SF","p");
1309 +  leg->AddEntry(metOF,"Data OF","l");
1310 +  leg->Draw();
1311 +  
1312 +  DrawPrelim();
1313 +  
1314 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1315 +  
1316 +  delete rcan;
1317 +  delete metSF;
1318 +  delete metOF;
1319 +  delete c1;
1320 + }
1321 +
1322 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1323 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1324 +  
1325 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1326 +  if(variation!="Central") {
1327 +    TH1F *varttbar;
1328 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1329 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1330 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1331 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1332 +    assert(varttbar);
1333 +    
1334 +    TIter nextHisto(SystPlot.GetHists());
1335 +    TH1F* h;
1336 +    while ( h = (TH1F*)nextHisto() ) {
1337 +      if(Contains(h->GetName(),"t_bar_t")) {
1338 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1339 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1340 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1341 +          h->SetBinError(i,varttbar->GetBinError(i));
1342 +        }
1343 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1344 +        SystPlot.Modified();
1345 +      }
1346 +    }
1347 +    delete varttbar;
1348 +  } else {
1349 +    TIter nextHisto(SystPlot.GetHists());
1350 +    TH1F* h;
1351 +    while ( h = (TH1F*)nextHisto() ) {
1352 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1353 +    }
1354 +  }
1355 +    
1356 +  TLegend *fullleg = allsamples.allbglegend();
1357 +  fullleg->SetHeader(variation.c_str());
1358 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1359 +  kinpad->SetLogy(1);
1360 +  kinpad->cd();
1361 +  
1362 +  hdata->Draw("e1");
1363 +  SystPlot.Draw("histo,same");
1364 +  hdata->Draw("e1,same");
1365 +  fullleg->Draw();
1366 +  DrawPrelim();
1367 +  
1368 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1369 +  CleanLegends();
1370 +  
1371 +  delete kinpad;
1372 +  return SystPlot;
1373 + }
1374 +  
1375 +
1376 +
1377 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1378 +  TCanvas *ca = new TCanvas("ca","ca");
1379 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1380 +  
1381 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1382 +  
1383 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1384 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1385 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1386 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1387 +  
1388 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1389 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1390 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1391 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1392 +  
1393 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1394 +  TH1F *HCentral = CollapseStack(Central);
1395 +  
1396 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1397 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1398 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1399 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1400 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1401 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1402 +    
1403 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1404 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1405 +    
1406 +    float sys=sqrt(matching*matching+scale*scale);
1407 +    sys/=HCentral->GetBinContent(i);
1408 +    if(HCentral->GetBinContent(i)==0) sys=0;
1409 +    Systematic->SetBinContent(i,sys);
1410 +  }
1411 +  
1412 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1413 +  kinpad->SetLogy(1);
1414 +  kinpad->cd();
1415 +  if(variable=="genMET") {
1416 +    Central.Draw("histo");
1417 +  } else {
1418 +    hdata->Draw("e1");
1419 +    Central.Draw("histo,same");
1420 +    hdata->Draw("e1,same");
1421 +  }
1422 +  
1423 +  DrawPrelim();
1424 +  
1425 +  save_with_ratio_and_sys_band( hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1426 +  
1427 +  kinpad->cd();
1428 +  tCentral->SetFillColor(kWhite);
1429 +  tCentral->SetLineColor(kBlack);
1430 +  tScaleUp->SetLineColor(kRed);
1431 +  tScaleDown->SetLineColor(kRed);
1432 +  tMatchingUp->SetLineColor(kBlue);
1433 +  tMatchingDown->SetLineColor(kBlue);
1434 +  tScaleUp->SetLineStyle(2);
1435 +  tScaleDown->SetLineStyle(3);
1436 +  tMatchingUp->SetLineStyle(2);
1437 +  tMatchingDown->SetLineStyle(3);
1438 +  
1439 +  TLegend *leg2 = make_legend();
1440 +  leg2->AddEntry(hdata,"Data","p");
1441 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1442 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1443 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1444 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1445 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1446 +  if(variable=="genMET") {
1447 +    Central.Draw("histo");
1448 +  }else {
1449 +    hdata->Draw("e1");
1450 +    Central.Draw("histo,same");
1451 +    hdata->Draw("e1,same");
1452 +  }
1453 +  tCentral->Draw("histo,same");
1454 +  tScaleUp->Draw("histo,same");
1455 +  tScaleDown->Draw("histo,same");
1456 +  tMatchingUp->Draw("histo,same");
1457 +  tMatchingDown->Draw("histo,same");
1458 +  leg2->Draw();
1459 +  
1460 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1461 +  
1462 +  gStyle->SetOptFit(0);
1463 +  
1464 +  kinpad->cd();
1465 +  kinpad->SetLogy(0);
1466 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1467 +  MatchingRatio->Divide(tMatchingDown);
1468 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1469 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1470 +  lone->SetLineStyle(2);
1471 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1472 +  ScaleRatio->Divide(tScaleDown);
1473 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1474 +  MatchingRatio->Draw("e1");
1475 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1476 +  MatchingRatio->Fit("QP1","R");
1477 +  lone->Draw();
1478 +  stringstream summary;
1479 +  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);
1480 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1481 +  TText *infobox = write_title(summary.str());
1482 +  infobox->SetX(0.75);
1483 +  infobox->SetTextSize(0.03);
1484 +  infobox->SetY(0.75);
1485 +  infobox->Draw();
1486 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1487 +  kinpad->cd();
1488 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1489 +  ScaleRatio->Draw("e1");
1490 +  ScaleRatio->Fit("QP1","R");
1491 +  summary.str("");
1492 +  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);
1493 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1494 +  TText *infobox2 = write_title(summary.str());
1495 +  infobox2->SetX(0.75);
1496 +  infobox2->SetTextSize(0.03);
1497 +  infobox2->SetY(0.75);
1498 +  infobox2->Draw();
1499 +
1500 +  lone->Draw();
1501 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1502 +  
1503 +  
1504 +  delete QP1;
1505 +  delete infobox;
1506 +  delete infobox2;
1507 +  delete MatchingRatio;
1508 +  delete ScaleRatio;
1509 +  DeleteStack(ScaleUp);
1510 +  DeleteStack(ScaleDown);
1511 +  DeleteStack(MatchingUp);
1512 +  DeleteStack(MatchingDown);
1513 +  delete leg2;
1514 +  CleanLegends();
1515 +  DeleteStack(Central);
1516 +  delete Systematic;
1517 +  delete HScaleUp;
1518 +  delete HScaleDown;
1519 +  delete HMatchingUp;
1520 +  delete HMatchingDown;
1521 +  delete hdata;
1522 +  delete HCentral;
1523 +  delete ca;
1524 + }
1525 +
1526 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1527 +  float val=0,err=0;
1528 +  vector<float> bins;
1529 +  vector<float> vals;
1530 +  vector<float> errs;
1531 +  
1532 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1533 +  int iBin=1;
1534 +  
1535 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1536 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1537 +      bins.push_back(histo->GetBinLowEdge(i));
1538 +      vals.push_back(val);val=0;
1539 +      errs.push_back(err);err=0;
1540 +      iBin++;
1541 +    }
1542 +    val+=histo->GetBinContent(i);
1543 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1544 +  }
1545 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1546 +  vals.push_back(val);val=0;
1547 +  errs.push_back(err);err=0;
1548 +  
1549 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1550 +  for(unsigned int i=0;i<vals.size();i++) {
1551 +    h->SetBinContent(i+1,vals[i]);
1552 +    h->SetBinError(i+1,errs[i]);
1553 +  }
1554 +  
1555 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1556 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1557 +  
1558 +  h->GetXaxis()->CenterTitle();
1559 +  h->GetYaxis()->CenterTitle();
1560 +
1561 +  return h;
1562 + }
1563 +
1564 +
1565 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1566 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1567 +  float val=0,err=0;
1568 +  vector<float> bins;
1569 +  vector<float> vals;
1570 +  vector<float> errs;
1571 +  
1572 +  bins.push_back(histo->GetBinLowEdge(1));
1573 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1574 +    val+=histo->GetBinContent(i);
1575 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1576 +    if( val/statsperbin > 0.85) {
1577 +      if(bins.size()<nbins) {
1578 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1579 +        vals.push_back(val);val=0;
1580 +        errs.push_back(err);err=0;
1581 +      }
1582 +    }
1583 +    if(i==histo->GetNbinsX()) {
1584 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1585 +      vals.push_back(val);val=0;
1586 +      errs.push_back(err);err=0;
1587 +    }
1588 +  }
1589 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1590 +  
1591 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1592 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1593 +  
1594 +  h->GetXaxis()->CenterTitle();
1595 +  h->GetYaxis()->CenterTitle();
1596 +  
1597 +  for(unsigned int i=0;i<vals.size();i++) {
1598 +    h->SetBinContent(i+1,vals[i]);
1599 +    h->SetBinError(i+1,errs[i]);
1600 +  }
1601 +  
1602 +  return h;
1603 + }
1604 +
1605 +
1606 +  
1607 + void ShowBinning(TH1F *histo) {
1608 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1609 +  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;
1610 + }
1611 +  
1612 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1613 +  TCanvas *ca = new TCanvas("ca","ca");
1614 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1615 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1616 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1617 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1618 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1619 +  
1620 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
1621 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
1622 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1623 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1624 +  tCentral->Scale(1.0/tCentral->Integral());
1625 +  
1626 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1627 +  
1628 +  
1629 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1630 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1631 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1632 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
1633 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
1634 +  
1635 +  float min=rtScaleUp->GetMinimum();
1636 +  float max=rtScaleUp->GetMaximum();
1637 +  
1638 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
1639 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1640 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1641 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
1642 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
1643 +  
1644 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
1645 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1646 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1647 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
1648 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
1649 +  
1650 +  rtCentral->SetMaximum(1.2*max);
1651 +  rtCentral->SetMinimum(0.8*min);
1652 +  
1653 + /*  tScaleUp->Rebin(40);
1654 +  tScaleDown->Rebin(40);
1655 +  tMatchingDown->Rebin(40);
1656 +  tMatchingUp->Rebin(40);
1657 +  tCentral->Rebin(40);*/
1658 +  
1659 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1660 +  kinpad->SetLogy(1);
1661 +  kinpad->cd();
1662 +  tCentral->SetFillColor(kWhite);
1663 +  tCentral->SetLineColor(kBlack);
1664 +  tScaleUp->SetLineColor(kRed);
1665 +  tScaleDown->SetLineColor(kRed);
1666 +  tMatchingUp->SetLineColor(kBlue);
1667 +  tMatchingDown->SetLineColor(kBlue);
1668 +  tScaleUp->SetLineStyle(2);
1669 +  tScaleDown->SetLineStyle(3);
1670 +  tMatchingUp->SetLineStyle(2);
1671 +  tMatchingDown->SetLineStyle(3);
1672 +  
1673 +  rtScaleDown->SetLineColor(kRed);
1674 +  rtMatchingUp->SetLineColor(kBlue);
1675 +  rtMatchingDown->SetLineColor(kBlue);
1676 +  rtScaleUp->SetLineStyle(2);
1677 +  rtScaleDown->SetLineStyle(3);
1678 +  rtMatchingUp->SetLineStyle(2);
1679 +  rtMatchingDown->SetLineStyle(3);
1680 +  
1681 +  TLegend *leg2 = make_legend();
1682 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1683 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1684 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1685 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1686 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1687 +  
1688 +  tCentral->Draw("histo");
1689 +  tScaleUp->Draw("histo,same");
1690 +  tScaleDown->Draw("histo,same");
1691 +  tMatchingUp->Draw("histo,same");
1692 +  tMatchingDown->Draw("histo,same");
1693 +  leg2->Draw();
1694 +  DrawMCPrelim();
1695 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1696 +  kinpad->cd();
1697 +  kinpad->SetLogy(0);
1698 +  rtCentral->Draw("histo");
1699 +  rtScaleUp->Draw("histo,same");
1700 +  rtScaleDown->Draw("histo,same");
1701 +  rtMatchingUp->Draw("histo,same");
1702 +  rtMatchingDown->Draw("histo,same");
1703 +  leg2->Draw();
1704 +  DrawMCPrelim();
1705 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
1706 +  
1707 +  
1708 +  gStyle->SetOptFit(0);
1709 +
1710 +  kinpad->cd();
1711 +  kinpad->SetLogy(0);
1712 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
1713 +  MatchingRatio->Divide(rtMatchingDown);
1714 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1715 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1716 +  lone->SetLineStyle(2);
1717 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
1718 +  ScaleRatio->Divide(rtScaleDown);
1719 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1720 +  MatchingRatio->Draw("e1");
1721 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1722 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
1723 +  lone->Draw();
1724 +  stringstream summary;
1725 +  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);
1726 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1727 +  TText *infobox = write_title(summary.str());
1728 +  infobox->SetX(0.75);
1729 +  infobox->SetTextSize(0.03);
1730 +  infobox->SetY(0.75);
1731 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
1732 +  DrawMCPrelim();
1733 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1734 +  kinpad->cd();
1735 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1736 +  ScaleRatio->Draw("e1");
1737 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
1738 +  summary.str("");
1739 +  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);
1740 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1741 +  TText *infobox2 = write_title(summary.str());
1742 +  infobox2->SetX(0.75);
1743 +  infobox2->SetTextSize(0.03);
1744 +  infobox2->SetY(0.75);
1745 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
1746 +
1747 +  lone->Draw();
1748 +  DrawMCPrelim();
1749 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1750 +  
1751 +  kinpad->cd();
1752 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
1753 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
1754 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
1755 +  
1756 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
1757 +    float matching, scale;
1758 +    bool AssumeFactor=false;
1759 +    if(AssumeFactor) {
1760 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
1761 +      matching=0.;
1762 +      scale=0.;
1763 +    } else {
1764 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
1765 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
1766 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
1767 +    }
1768 +    
1769 +    SysMatching->SetBinContent(i,1+matching);
1770 +    SysScale->SetBinContent(i,1+scale);
1771 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
1772 +  }
1773 +  
1774 +  SysHisto->SetLineColor(kGreen);
1775 +  
1776 +  SysMatching->SetMaximum(3.0);
1777 +  SysMatching->SetMinimum(0.0);
1778 +  SysMatching->Draw("histo");
1779 +  SysScale->Draw("histo,same");
1780 +  SysHisto->Draw("histo,same");
1781 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
1782 +  
1783 +  delete SysMatching;
1784 +  delete SysScale;
1785 +  
1786 +  if(!Contains(variable,"gen")) {
1787 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1788 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
1789 +    
1790 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1791 +    
1792 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
1793 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
1794 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
1795 +      float sys = SysHisto->GetBinContent(iBin)-1;
1796 +      Systematic->SetBinContent(i,sys);
1797 +    }
1798 +    
1799 +    kinpad->cd();
1800 +    TLegend *leg = allsamples.allbglegend();
1801 +    hdata->Draw();
1802 +    smc.Draw("histo,same");
1803 +    hdata->Draw("same");
1804 +    leg->Draw();
1805 +    DrawPrelim();
1806 +    save_with_ratio_and_sys_band( hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
1807 +    
1808 +    delete Systematic;
1809 +    delete hdata;
1810 +  }
1811 +  
1812 +  
1813 +  delete SysHisto;
1814 +  delete tScaleUp;
1815 +  delete tScaleDown;
1816 +  delete tCentral;
1817 +  delete tMatchingUp;
1818 +  delete tMatchingDown;
1819 +  delete rtScaleUp;
1820 +  delete rtScaleDown;
1821 +  delete rtCentral;
1822 +  delete rtMatchingUp;
1823 +  delete rtMatchingDown;
1824 +  delete QP1;
1825 +  delete infobox;
1826 +  delete infobox2;
1827 +  delete MatchingRatio;
1828 +  delete ScaleRatio;
1829 +  delete leg2;
1830 +  CleanLegends();
1831 +  delete ca;
1832 + }
1833 +
1834 + void ProduceMCSystematicPlots() {
1835 +  cout << "Getting ready to produce systematic plots " << endl;
1836 +  TCut cutweightBKP = cutWeight;
1837 +  
1838 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1839 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1840 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1841 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1842 +  
1843 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1844 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
1845 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1846 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
1847 +  
1848 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1849 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1850 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1851 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1852 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
1853 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
1854 +  
1855 +  
1856 +  
1857 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1858 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1859 +  cutWeight="1.0";
1860 +  
1861 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1862 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
1863 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1864 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1865 +  
1866 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1867 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1868 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1869 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1870 +  
1871 +  
1872 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
1873 +  
1874 +  /*
1875 +  cutWeight=cutweightBKP;
1876 +  TCut essentialcutBKP = essentialcut;
1877 +  cout << (const char*) essentialcut << endl;
1878 +  
1879 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
1880 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1881 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1882 +  
1883 +  TCut cutnJetsBKP = cutnJets;
1884 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
1885 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
1886 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1887 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1888 +  
1889 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1890 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
1891 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1892 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1893 +  
1894 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1895 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
1896 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1897 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
1898 +  
1899 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1900 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1901 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1902 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1903 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
1904 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
1905 +  
1906 +  
1907 +  
1908 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1909 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1910 +  cutWeight="1.0";
1911 +  
1912 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1913 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
1914 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1915 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"genMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1916 +  
1917 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1918 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1919 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1920 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PFMET [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1921 +  
1922 +  cutnJets  = cutnJetsBKP;
1923 +  cutWeight = cutweightBKP;
1924 +  essentialcut = essentialcutBKP;
1925 +  */
1926 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
1927 + }
1928 +
1929 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
1930 +  TCut cut=pcut&&basiccut;
1931 +  string variable="mll";
1932 +  string xlabel="m_{ll} [GeV]";
1933 +  int nbins=40;
1934 +  float min=0;
1935 +  float max=200;
1936 +
1937 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1938 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
1939 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
1940 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1941 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1942 +  datahistoSF->SetMarkerSize(DataMarkerSize);
1943 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
1944 +  datahistoOF->SetMarkerSize(DataMarkerSize);
1945 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
1946 +
1947 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
1948 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
1949 +  datahistoSF->Draw("e1");
1950 +  ckin->Update();
1951 +  mcstackSF.Draw("histo,same");
1952 +  
1953 +  datahistoSF->Draw("same,e1");
1954 +  TLegend *kinleg = allsamples.allbglegend();
1955 +  kinleg->Draw();
1956 +  
1957 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1958 +  kinpad->cd();
1959 +  datahistoSF->Draw("e1");
1960 +  mcstackSF.Draw("histo,same");
1961 +  datahistoSF->Draw("same,e1");
1962 +  datahistoSF->Draw("same,axis");
1963 +  kinleg->Draw();
1964 +  DrawPrelim();
1965 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
1966 +  
1967 +  kinpad->cd();
1968 +  datahistoOF->Draw("e1");
1969 +  mcstackOF.Draw("histo,same");
1970 +  datahistoOF->Draw("same,e1");
1971 +  datahistoOF->Draw("same,axis");
1972 +  kinleg->Draw();
1973 +  DrawPrelim();
1974 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
1975 +  
1976 +  kinpad->cd();
1977 +  tauSF->Draw("e1");
1978 +  tauOF->Draw("histo,same");
1979 +  tauSF->Draw("e1,same");
1980 +  TLegend *legtau = make_legend();
1981 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
1982 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
1983 +  legtau->Draw();
1984 +  DrawPrelim();
1985 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
1986 +  
1987 +  delete datahistoSF;
1988 +  delete datahistoOF;
1989 +  delete tauSF;
1990 +  delete tauOF;
1991 +  delete kinpad;
1992 +  delete ckin;
1993 +  CleanLegends();
1994 + }
1995 +  
1996  
1997 + void TauQuestion() {
1998 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
1999 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2000 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2001 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2002   }
2003  
2004   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2005   {
2006 + //  switch_overunderflow(true);
2007    bool dolog=true;
2008    bool nolog=false;
2009  
2010    bool doOFSF = false;
2011 <  bool doKin  = false;
2012 <  bool doDataComp = true;
2011 >  bool doKin  = true;
2012 >  bool doDataComp = false;
2013 >  bool MakeTwoThreeJetComparison = false;
2014    
2015  
2016    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
# Line 750 | Line 2020 | void do_kinematic_plots(string mcjzb, st
2020          mll_low=20;
2021          mll_hi=320;
2022    }
2023 +  
2024 +  if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2025 +  
2026 +  //TauQuestion();
2027  
2028 +  //ProduceJanPlots();
2029 +  ProduceMCSystematicPlots();
2030 +  assert(0);
2031 + //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2032 +  
2033    if ( doOFSF ) {
2034 <    make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2035 <
2036 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100", 7, 3, 10, true, "#(jets)", "njets");
2037 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2038 <    make_OFSF_plots("pfJetGoodNum40",     "met[4]>100&&pfJetGoodNumBtag30>0", 7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
2039 <
2040 <    make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
2041 <    make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2042 <    make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2043 <    //  make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2044 <    //  make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2045 <    make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2046 <    make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2047 <    //  make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2048 <    //  make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2049 <    //  make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2050 <    make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2034 >     make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2035 >     make_OFSF_plots("met[4]", "met[4]>100", 30, 100., 400., false, "PFMET", "met");
2036 >     make_OFSF_plots("leptonNum", "met[4]>100", 3, 2, 5., false, "N(leptons)", "NLeptons");
2037 >
2038 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2039 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2040 >     make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
2041 >
2042 >     make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, 0, 5, true, "#(b-jets)", "nbjets");
2043 >     make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
2044 >
2045 >     make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2046 >     make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2047 >     make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2048 >     make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2049 >     make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2050 >     make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2051 >     make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2052 >     make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2053 >     make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2054 >     make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2055      make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
2056 <    //  make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2057 <    //  make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2056 >    make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2057 >    make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2058      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");
2059      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");
2060      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");
2061      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");
2062    }
2063  
2064 <  if ( doDataComp && !PlottingSetup::openBox ) {
2064 >  if ( doDataComp) {
2065      TCut mllCut("");
2066 <    if ( !PlottingSetup::openBox ) mllCut = "mll>120";
2066 >    float massmin = 15.;
2067 >    float massmax = 315;
2068 >    int massnbins = 60;
2069 > /*    if ( !PlottingSetup::openBox ) {
2070 >      mllCut = "mll>70";
2071 >      massmin = 120;
2072 >      massmax = 360;
2073 >      massnbins = 14;
2074 >    }*/
2075  
2076      TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2077 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig");
2078 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee");
2079 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm");
2080 <
2081 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2082 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_btagVeto");
2083 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30==0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_btagVeto");
2084 <
2085 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",           60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2086 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==0&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_ee_AtLeastOneBJet");
2087 <    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"id1==1&&pfJetGoodNumBtag30>0", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_sig_mm_AtLeastOneBJet");
2077 >    
2078 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2079 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2080 >    
2081 >    
2082 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2083 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2084 >    make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2085 >    make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2086 >    make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2087 >    
2088 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2089 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2090 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2091 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2092 >
2093 >  
2094 >    string basiccutsaved = (const char*)basiccut;
2095 >    
2096 >    string newbasiccut=basiccutsaved;
2097 >    
2098 >    size_t found;
2099 >    found = newbasiccut.find( "pt2>20" );
2100 >    while (found!=string::npos){
2101 >      newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2102 >      found = newbasiccut.find( "pt2>20" );
2103 >    }
2104 >    basiccut=TCut(newbasiccut.c_str());
2105 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2106 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2107 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2108 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2109 >    basiccut=TCut(basiccutsaved.c_str());
2110 >    
2111 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2112 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2113 >    
2114 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2115 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2116 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2117 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2118 >
2119 >    
2120 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2121 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2122 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2123 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2124 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2125 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2126 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2127 >    make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2128 >
2129 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2130 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2131 >    
2132 >    make_data_comparison_plot("mll", TCut("abs(eta1)<1.4&&abs(eta2)<1.4") && cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_central");
2133 >    make_data_comparison_plot("mll", TCut("abs(eta1)<1.4&&abs(eta2)<1.4") && cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_central");
2134 >    
2135 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2136 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2137 >    
2138 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2139 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2140 >
2141 >
2142 >    make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2143 >    make_data_comparison_plot("mll", cutmass&&cutOSSF&&"met[4]>100&&met[4]<150&&pfJetGoodNum40==2", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_CR");
2144 >    make_data_comparison_plot("mll", cutmass&&cutOSOF&&"met[4]>100&&met[4]<150&&pfJetGoodNum40==2", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_CR");
2145 >
2146 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2147 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2148 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2149 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2150  
798    make_data_comparison_plot("mll", cutOSOF&&cutSignal, 60, 20., 320.,-1., false, "m_{ll}", "mll_OF_sig");
799    make_data_comparison_plot("mll", cutmass&&"met[4]>100&&met[4]<150&&pfJetGoodNum40<3", 60, 20., 320.,-1., false, "m_{ll}", "mll_SF_CR");
2151    }
2152  
2153  
2154    if ( doKin ) {
2155      string mllCut("");
2156 <    if ( !PlottingSetup::openBox ) mllCut = "&&mll>120";
2157 <
2156 >    
2157 >    
2158 >  
2159 >    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);
2160 >    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);
2161 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_2j",doPF,true);
2162 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/MET_OF_30to70_3j",doPF,true);
2163 >
2164 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_0j",doPF,true);
2165 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_1j",doPF,true);
2166 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_2j",doPF,true);
2167 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/MET_OF_Z_3j",doPF,true);
2168 >
2169 >
2170 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2171 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2172 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2173 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2174 >
2175 >    
2176 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_0j",doPF,true);
2177 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_1j",doPF,true);
2178 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_2j",doPF,true);
2179 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_30to70_3j",doPF,true);
2180 >
2181 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_0j",doPF,true);
2182 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_1j",doPF,true);
2183 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_2j",doPF,true);
2184 >    make_plain_kin_plot("met[1]",Cut2Str(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),40,0,400,dolog,"PFMET","Debunking/T1MET_OF_Z_3j",doPF,true);
2185 >
2186 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2187 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2188 >    
2189 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2190 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2191 >    
2192 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70___2jetsonly",doPF,true);
2193 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70___2jetsonly",doPF,true);
2194 >    
2195 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120___2jetsonly",doPF,true);
2196 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("pfJetGoodNum40==2")&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120___2jetsonly",doPF,true);
2197 >
2198 >    
2199 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2200 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2201      // Plots in signal region
2202      make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
2203 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2204 <    make_kin_plot("mll","mll>20&&met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2205 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2206 <    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2203 >
2204 >
2205 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2206 >    
2207 >    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");
2208 >    /*
2209 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2210 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2211 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2212 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2213 >
2214 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2215 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2216 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2217 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2218 >
2219 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2220 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2221 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2222 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2223 >
2224 >    
2225 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2226 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2227 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2228 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2229 >
2230 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2231 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2232 >
2233 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2234 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2235 >    
2236 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2237 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2238 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2239 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2240 >
2241 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2242 >    make_kin_plot("mll","mll>20",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2243 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2244 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2245 >    
2246 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2247 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2248 >    
2249 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_met100",doPF,true);
2250 >    make_kin_plot("mll","mll>20&&met[4]>100",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_met100",doPF,true,true);
2251 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee_met100",doPF,true);
2252 >    make_kin_plot("mll","mll>20&&met[4]>100"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm_met100",doPF,true);
2253 >    
2254      
2255 <    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2256 <    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2255 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2256 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2257  
2258      // Further inclusive invariant mass plots
2259 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2259 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2260      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2261      make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2262 <    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2262 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2263      
2264 <    //make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2264 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2265      //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2266      
826    //make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
827    //make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2267      
2268      // Number of jets
2269      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2270      make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2271 <    //make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2271 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2272      
2273      // Others
2274      make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
# Line 861 | Line 2300 | void do_kinematic_plots(string mcjzb, st
2300      
2301      //   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);
2302      //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);
2303 <    //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);
2303 >    //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);*/
2304    }
2305 <    
2306 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2307 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2308 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2309 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2310 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2311 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2312 < //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
874 <
875 < //   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
876 < //   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2305 >    /*
2306 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2307 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2308 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2309 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2310 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2311 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2312 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2313  
2314 +   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2315 +   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2316 + */
2317 +  switch_overunderflow(false);
2318   }
2319  
2320   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
# Line 914 | Line 2354 | void make_comp_plot( string var, string
2354        if (ymax>ymin) datahisto->SetMaximum(ymax);
2355        lm3histo->SetLineStyle(2);
2356        datahisto->Draw("e1");
2357 <      mcstack.Draw("same");
2357 >      mcstack.Draw("histo,same");
2358        datahisto->Draw("same,e1");
2359        lm3histo->Draw("hist,same");
2360        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
# Line 944 | Line 2384 | void region_comparison_plots(string mcjz
2384  
2385   //  switch_overunderflow(true);  // switching overflow/underflow bins on
2386      
2387 <  
2387 >  switch_overunderflow(true);
2388      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2389    for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2390      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
# Line 1261 | Line 2701 | if you want to start from scratch (witho
2701  
2702   void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
2703   {
2704 < //  switch_overunderflow(true);
2704 >  
2705    bool is_data=false;
2706    bool use_signal=false;
2707    if(use_data==1) is_data=true;
2708    if(use_data==2) use_signal=true;
2709 <  int nbins=50;//100;
2710 <  if(is_data) nbins=50;
2709 >  int nbins=int(high/10);//100;
2710 >  if(is_data) nbins=int(high/10);
2711    float low=0;
2712 <  float hi=500;
2712 >  float hi=high;
2713 >  
2714 >  stringstream cutpositiveS;
2715 >  cutpositiveS << "(" << jzb << ">0)";
2716 >  TCut cutpositive(cutpositiveS.str().c_str());
2717 >  stringstream cutnegativeS;
2718 >  cutnegativeS << "(" << jzb << "<0)";
2719 >  TCut cutnegative(cutnegativeS.str().c_str());
2720 >  
2721    
2722    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2723 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2724 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2725 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2726 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2723 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2724 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2725 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2726 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2727  
2728    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2729    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 1290 | Line 2738 | void do_prediction_plot(string jzb, TCan
2738    
2739    TH1F *RcorrJZBeemmNoS;
2740  
2741 <    //these are for the ratio
2742 <  
2743 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2744 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2745 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1298 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2741 >  //these are for the ratio
2742 >  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2743 >  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2744 >  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2745 >  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2746    
2747    TH1F *JRcorrJZBSBem;
2748    TH1F *JLcorrJZBSBem;
2749    TH1F *JRcorrJZBSBeemm;
2750    TH1F *JLcorrJZBSBeemm;
2751    
2752 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
2752 >  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);
2753  
2754    
2755    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2756 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2757 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2758 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2759 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2756 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2757 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2758 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2759 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2760      
2761      //these are for the ratio
2762 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2763 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2764 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2765 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2762 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2763 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2764 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2765 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2766    }
2767    
2768    TH1F *lm4RcorrJZBeemm;
2769 <  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
2769 >  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"));
2770    
2771    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2772    
# Line 1383 | Line 2830 | void do_prediction_plot(string jzb, TCan
2830    SQRT(BpredSys);
2831    BpredSys->Divide(JBpred);
2832  
1386  
2833    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2834    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
2835    Tpred->Add(LcorrJZBem,-1.0);
# Line 1436 | Line 2882 | void do_prediction_plot(string jzb, TCan
2882      Bpred->Draw("hist,same");
2883      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2884      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2885 <    lm4RcorrJZBeemm->Draw("hist,same");
2885 >    //lm4RcorrJZBeemm->Draw("hist,same");
2886      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
2887      legBpred->AddEntry(Bpred,"predicted","l");
2888   //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2889   //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2890 <    legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2890 > //     legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2891      legBpred->Draw();
2892      DrawPrelim();
2893  
# Line 1451 | Line 2897 | void do_prediction_plot(string jzb, TCan
2897      Bpred->SetLineWidth(2);
2898      predcomppad->cd();
2899      predcomppad->SetLogy(1);
1454    
2900      TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
2901      TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
2902      sidebandsemu->Add(jzbnegative,-1);
# Line 1473 | Line 2918 | void do_prediction_plot(string jzb, TCan
2918   //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
2919      lm4RcorrJZBeemm->SetLineWidth(2);
2920      //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
2921 <    lm4RcorrJZBeemm->Draw("histo,same");
2921 > //     lm4RcorrJZBeemm->Draw("histo,same");
2922      DrawPrelim();
2923      TLegend *speciallegBpred = make_legend("",0.45,0.55);
2924      //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
# Line 1483 | Line 2928 | void do_prediction_plot(string jzb, TCan
2928      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
2929      else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
2930   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
2931 <    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2931 > //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2932      speciallegBpred->Draw();
2933 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2933 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2934 >    delete predcomppad;
2935      
2936      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
2937      specialcanv->SetLogy(1);
2938   //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
2939      blankback->Draw();
2940   //    kostack.Draw("same");
2941 <    predcomposition.Draw();
2941 >    predcomposition.Draw("hist");
2942      Bpred->Draw("hist,same");
2943      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2944      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
# Line 1519 | Line 2965 | void do_prediction_plot(string jzb, TCan
2965      legBpred->AddEntry(Bpred,"MC predicted","l");    
2966      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
2967      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
2968 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2968 > //     if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2969      legBpred->Draw();
2970      DrawMCPrelim();
2971      Bpredsaveas="Bpred_MC";
# Line 1551 | Line 2997 | void do_prediction_plot(string jzb, TCan
2997        
2998        RcorrJZBeemmNoS->SetLineStyle(2);
2999        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3000 <      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3000 > //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3001        legBpred2->Draw();
3002        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3003        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1568 | Line 3014 | void do_prediction_plot(string jzb, TCan
3014    string ytitle("ratio");
3015    if ( use_data==1 ) ytitle = "data/pred";
3016    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3017 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3017 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3018 >  
3019 >  delete kinpad;
3020 >
3021  
3022    
3023    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
# Line 1628 | Line 3077 | void do_prediction_plot(string jzb, TCan
3077        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3078        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3079        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3080 <      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3080 > //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3081        legBpredc->Draw();
3082        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3083      }
# Line 1664 | Line 3113 | void do_prediction_plot(string jzb, TCan
3113      delete JLcorrJZBSBeemm;
3114    }
3115    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1667  switch_overunderflow(false);
3116   }
3117  
3118   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3119 +  switch_overunderflow(true);
3120    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3121    do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3122    if ( !PlottingSetup::Approved ) {
# Line 1676 | Line 3125 | void do_prediction_plots(string mcjzb, s
3125    } else {
3126      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3127    }
3128 < }
3129 <
1681 < void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1682 <  bool do_data=0;
1683 <  bool dosignal=0;
1684 <  if(is_data==1) do_data=1;
1685 <  if(is_data==2) dosignal=1;
1686 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1687 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1688 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1689 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1690 <  
1691 <  TH1F *RcorrJZBSBem;
1692 <  TH1F *LcorrJZBSBem;
1693 <  TH1F *RcorrJZBSBeemm;
1694 <  TH1F *LcorrJZBSbeemm;
1695 <  
1696 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
1697 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1698 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1699 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1700 <    LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1701 <  }
1702 <  
1703 <
1704 <
1705 <
1706 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1707 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1708 <  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
1709 <    Bpred->Add(RcorrJZBem,1.0/3);
1710 <    Bpred->Add(LcorrJZBem,-1.0/3);
1711 <    Bpred->Add(RcorrJZBSBem,1.0/3);
1712 <    Bpred->Add(LcorrJZBSBem,-1.0/3);
1713 <    Bpred->Add(RcorrJZBSBeemm,1.0/3);
1714 <    Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1715 <  } else {
1716 <    Bpred->Add(RcorrJZBem,1.0);
1717 <    Bpred->Add(LcorrJZBem,-1.0);
1718 <  }
1719 <
1720 <  can->cd();
1721 <  can->SetLogy(0);
1722 <  Bpred->SetLineColor(kRed);
1723 <  Bpred->SetStats(0);
1724 <  if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1725 <  TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1726 <  JZBratioforfitting->Divide(Bpred);
1727 <  TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1728 <  
1729 <  
1730 <  JZBratio->SetTitle("");
1731 <  JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1732 < //  if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1733 <  
1734 <  TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1735 <  TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1736 < //  straightline_fit->SetParameter(0,1);
1737 <  JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1738 <  pol0d->SetParameter(0,pol0->GetParameter(0));
1739 <  
1740 <  JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1741 <  JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1742 <  if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1743 <  JZBratio->GetYaxis()->SetNdivisions(519);
1744 <  JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1745 <  JZBratio->GetYaxis()->CenterTitle();
1746 <  JZBratio->GetXaxis()->CenterTitle();
1747 <  JZBratio->SetMarkerSize(DataMarkerSize);
1748 <  JZBratio->Draw("AP");
1749 <  /////----------------------------
1750 <  TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1751 <  writeresult->SetFillStyle(4000);
1752 <  writeresult->SetFillColor(kWhite);
1753 <  writeresult->SetTextFont(42);
1754 <  writeresult->SetTextSize(0.03);
1755 <  writeresult->SetTextAlign(12);
1756 <  ostringstream jzb_agreement_data_text;
1757 <  jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) <<  pol0->GetParError(0);
1758 <  if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1759 <  if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1760 < /*  if(is_data) writeresult->AddText("Data closure test");
1761 <  else writeresult->AddText("MC closure test");
1762 <  */
1763 <  writeresult->AddText(jzb_agreement_data_text.str().c_str());
1764 < //  writeresult->Draw("same");
1765 < //  pol0d->Draw("same");
1766 <  TF1 *topline =  new TF1("","1.5",0,1000);
1767 <  TF1 *bottomline =  new TF1("","0.5",0,1000);
1768 <  topline->SetLineColor(kBlue);
1769 <  topline->SetLineStyle(2);
1770 <  bottomline->SetLineColor(kBlue);
1771 <  bottomline->SetLineStyle(2);
1772 < //  topline->Draw("same");
1773 < //  bottomline->Draw("same");
1774 <  TF1 *oneline = new TF1("","1.0",0,1000);
1775 <  oneline->SetLineColor(kBlue);
1776 <  oneline->SetLineStyle(1);
1777 <  oneline->Draw("same");
1778 <  TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
1779 <  if(is_data==1) DrawPrelim();
1780 <  else DrawMCPrelim();
1781 <  TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1782 <  leg->SetTextFont(42);
1783 <  leg->SetTextSize(0.04);
1784 < //   if(is_data==1) leg->SetHeader("Ratio (data)");
1785 < //   else leg->SetHeader("Ratio (MC)");
1786 <
1787 <  TString MCtitle("MC ");
1788 <  if (is_data==1) MCtitle = "";
1789 <
1790 <  leg->SetFillStyle(4000);
1791 <  leg->SetFillColor(kWhite);
1792 <  leg->SetTextFont(42);
1793 < //  leg->AddEntry(topline,"+20\% sys envelope","l");
1794 <  leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1795 <  leg->AddEntry(oneline,"ratio = 1","l");
1796 < //  leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1797 < //  leg->AddEntry(bottomline,"#pm50% envelope","l");
1798 <
1799 <
1800 <  //leg->Draw("same"); // no longer drawing legend
1801 <
1802 <  if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1803 <  if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1804 <  if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1805 <  
1806 <  delete RcorrJZBeemm;
1807 <  delete LcorrJZBeemm;
1808 <  delete RcorrJZBem;
1809 <  delete LcorrJZBem;
1810 <  
1811 <  delete RcorrJZBSBem;
1812 <  delete LcorrJZBSBem;
1813 <  delete RcorrJZBSBeemm;
1814 <  delete LcorrJZBSbeemm;
1815 < }
1816 <
1817 < void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1818 <  TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1819 <  globalc->SetLogy(0);
1820 <  
1821 <  do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh  );
1822 <  do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh  );
1823 <  do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh  );
3128 >  delete globalcanvas;
3129 >  switch_overunderflow(false);
3130   }
3131  
3132   string give_jzb_expression(float peak, int type) {
# Line 1907 | Line 3213 | void lepton_comparison_plots() {
3213    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3214    eemmlegend->Draw();
3215    DrawPrelim();
3216 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3216 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3217    
3218    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"));
3219    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"));
# Line 2008 | Line 3314 | void draw_pure_jzb_histo(TCut cut,string
3314    datahisto->SetMinimum(0.1);
3315    datahisto->SetMarkerSize(DataMarkerSize);
3316    datahisto->Draw("e1");
3317 <  mcstack.Draw("same");
3317 >  mcstack.Draw("histo,same");
3318    datahisto->Draw("same,e1");
3319    
3320    TLegend *leg;
# Line 2030 | Line 3336 | void draw_pure_jzb_histo(TCut cut,string
3336    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3337    writeline1->SetTextSize(0.035);
3338    writeline1->Draw();
3339 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3340 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3339 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3340 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3341    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3342    jzbpad2->cd();
3343    jzbpad2->SetLogy(1);
# Line 2039 | Line 3345 | void draw_pure_jzb_histo(TCut cut,string
3345    datahisto->SetMinimum(0.1);
3346    datahisto->SetMarkerSize(DataMarkerSize);
3347    datahisto->Draw("e1");
3348 <  mcstack.Draw("same");
3348 >  mcstack.Draw("histo,same");
3349    datahisto->Draw("same,e1");
3350    leg->SetHeader("");
3351    leg->Draw();
3352    writeline1->SetTextSize(0.035);
3353    writeline1->Draw();
3354    DrawPrelim();
3355 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3356 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3355 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3356 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3357    datahisto->Delete();
3358    mcstack.Delete();
3359   }
# Line 2088 | Line 3394 | void produce_stretched_jzb_plots(string
3394    
3395  
3396   void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3397 +  switch_overunderflow(true);
3398    vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3399    
3400    if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
# Line 2127 | Line 3434 | void diboson_plots(string mcjzb, string
3434      dout << "     Reset xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " from " << Upxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ") and reset the correct name (from " << Upname << ")" << endl;
3435      
3436    }
3437 <  
3437 > //   switch_overunderflow(false);
3438   }
3439  
3440  
# Line 2154 | Line 3461 | void draw_normalized_data_vs_data_histo(
3461    leg->AddEntry(datahisto2,legentry2.c_str());
3462    leg->Draw();
3463    
3464 <  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3464 >  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3465    
3466    datahisto1->Delete();
3467    datahisto2->Delete();
# Line 2162 | Line 3469 | void draw_normalized_data_vs_data_histo(
3469  
3470  
3471   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3472 +  switch_overunderflow(true);
3473    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3474    float max=jzbHigh ;
3475    float min=-120;
# Line 2198 | Line 3506 | void jzb_plots(string mcjzb, string data
3506      if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3507    }
3508    delete can;
3509 +  switch_overunderflow(false);
3510   }
3511  
3512  
# Line 2646 | Line 3955 | void find_correction_factors(string &jzb
3955    
3956   }
3957  
3958 < void pick_up_events(string cut) {
3959 <  dout << "Picking up events with cut " << cut << endl;
2651 <  allsamples.PickUpEvents(cut);
3958 > void pick_up_events(string cut, string filename) {
3959 >  allsamples.PickUpEvents(cut,filename);
3960   }
3961  
3962   void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
# Line 2738 | Line 4046 | void ttbar_sidebands_comparison(string m
4046    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4047    //in the case of the OFF peak analysis, we compare our control region to the real value
4048    TCut weightbackup=cutWeight;
4049 +  switch_overunderflow(true);
4050    
4051    bool doPURW=false;
4052    
# Line 2759 | Line 4068 | void ttbar_sidebands_comparison(string m
4068        
4069    float simulatedlumi = luminosity; //in pb please - adjust to your likings
4070  
4071 <  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4072 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4071 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4072 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4073    TH1F *TSem;
4074    TH1F *nTSem;
4075 <  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4076 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4075 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4076 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4077    TH1F *TSeemm;
4078    TH1F *nTSeemm;
4079    
4080    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4081 <    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4082 <    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4083 <    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4084 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4081 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4082 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4083 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4084 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4085    }
4086  
4087    TCanvas *tcan = new TCanvas("tcan","tcan");
# Line 2804 | Line 4113 | void ttbar_sidebands_comparison(string m
4113      histos.push_back(TSem);
4114      histos.push_back(TSeemm);
4115    }
4116 <  draw_all_ttbar_histos(tcan,histos,"histo",1);
4116 >  draw_all_ttbar_histos(tcan,histos,"histo",8);
4117    
4118    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4119    leg->AddEntry(TZeemm,"SFZP","l");
# Line 2816 | Line 4125 | void ttbar_sidebands_comparison(string m
4125    leg->Draw("same");
4126    DrawMCPrelim(simulatedlumi);
4127    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
4128 +  
4129    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
4130    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
4131    TH1F *TSeemmcopy;
# Line 2881 | Line 4191 | void ttbar_sidebands_comparison(string m
4191    DrawMCPrelim(simulatedlumi);
4192    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4193    
4194 +  
4195    if (0) { // Turn this off: we don't need this
4196  
4197      ///-------------- second part: only look at the quantity we actually care about!
# Line 2986 | Line 4297 | void ttbar_sidebands_comparison(string m
4297  
4298    delete tcan;
4299    cutWeight=weightbackup;
4300 +  switch_overunderflow(false);
4301   }
4302  
4303   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
# Line 3020 | Line 4332 | void ttbar_sidebands_comparison(string m
4332    nicer_binning.push_back(150);
4333    //nicer_binning.push_back(175);
4334    nicer_binning.push_back(200);
4335 <  nicer_binning.push_back(250);
4336 <  nicer_binning.push_back(300);
4337 <  nicer_binning.push_back(400);
4335 > //  nicer_binning.push_back(250);
4336 > //  nicer_binning.push_back(300);
4337 > //  nicer_binning.push_back(400);
4338    
4339    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4340   }
4341  
4342  
4343 < void zjets_prediction_comparison(string mcjzbWithPUa) {
4343 > void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4344 >  cout << "****************************************************************************************************************************************************************" << endl;
4345    TCanvas *zcan = new TCanvas("zcan","zcan");  
4346   //  zcan->SetLogy(1);
4347    TCut weightbackup=cutWeight;
4348    
4349 <  bool UsePURW=false;
4349 >  bool UsePURW=true;
4350    
4351    
4352    string mcjzb;
4353    if(UsePURW) {
4354      mcjzb=mcjzbWithPUa;
4355 +    cout << "Using PURW peak positions" << endl;
4356    } else {
4357      // Do it without PU re-weighting
4358 +    cutWeight="1.0";
4359      float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4360      stringstream resultsNoPU;
4361      stringstream noPUdatajzb;
# Line 3051 | Line 4366 | void zjets_prediction_comparison(string
4366      
4367      mcjzb = noPUmcjzb.str();
4368      
3054    cutWeight="1.0";
4369    }
4370  
4371    
# Line 3075 | Line 4389 | void zjets_prediction_comparison(string
4389    string var( "abs("+mcjzb+")" );
4390    
4391    TCut notTau("abs(genMID1)!=15");
4392 <  TCut ONLYTau("mll>20");
4392 >  TCut ee_mm_tautau("mll>0");
4393    
4394  
4395 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4396 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4395 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4396 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4397    
4398    hJZBpos->SetLineColor(kBlack);
4399    hJZBneg->SetLineColor(kRed);
# Line 3094 | Line 4408 | void zjets_prediction_comparison(string
4408    leg->AddEntry(hJZBneg,"Predicted","l");
4409    leg->Draw("same");
4410    DrawMCPrelim(simulatedlumi);
4411 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
4411 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
4412    
4413    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
4414    hratio->Divide(hJZBneg);
# Line 3103 | Line 4417 | void zjets_prediction_comparison(string
4417      cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4418    }
4419    
4420 <  zcan->SetLogy(0);
4421 <  hratio->GetYaxis()->SetRangeUser(0,2.0);
4420 > //  zcan->SetLogy(0);
4421 >  hratio->GetYaxis()->SetRangeUser(0,2.5);
4422    hratio->GetYaxis()->SetTitle("Observed/Predicted");
4423    hratio->Draw("e1");
4424    
# Line 3126 | Line 4440 | void zjets_prediction_comparison(string
4440    leg2->AddEntry(bottom,"syst. envelope","l");
4441    leg2->Draw("same");
4442    DrawMCPrelim(simulatedlumi);
4443 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
4443 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4444    
4445    TCut reducedNJets(cutnJets);
4446    
4447 <  TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4448 <  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4449 <  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4450 <  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4447 >  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4448 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4449 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4450 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4451  
4452    TH1F *RcorrJZBSBem;
4453    TH1F *LcorrJZBSBem;
# Line 3141 | Line 4455 | void zjets_prediction_comparison(string
4455    TH1F *LcorrJZBSBeemm;
4456  
4457    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4458 <    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4459 <    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4460 <    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
4461 <    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4458 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4459 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4460 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4461 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4462    }
4463    
4464    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
# Line 3175 | Line 4489 | void zjets_prediction_comparison(string
4489    TAUleg->AddEntry(Bpred,"Predicted","l");
4490    TAUleg->Draw("same");
4491    DrawMCPrelim(simulatedlumi);
4492 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
4492 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
4493    
4494    TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
4495    TAUhratio->Divide(Bpred);
# Line 3193 | Line 4507 | void zjets_prediction_comparison(string
4507    center->Draw("same");
4508    bottom->Draw("same");
4509    
4510 <  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
4510 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4511    TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
4512    TAUleg2->AddEntry(bottom,"syst. envelope","l");
4513    TAUleg2->Draw("same");
4514    DrawMCPrelim(simulatedlumi);
4515 <  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
4515 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
4516    
4517    delete Bpred;
4518    delete TAUhJZBpos;
4519    delete LcorrJZBeemm;
4520    delete RcorrJZBem;
4521    delete LcorrJZBem;
4522 +  delete hJZBpos;
4523 +  delete hJZBneg;
4524    
4525    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4526      delete RcorrJZBSBem;
# Line 3216 | Line 4532 | void zjets_prediction_comparison(string
4532    
4533    delete zcan;
4534    cutWeight=weightbackup;
3219
4535   }
4536  
4537  
4538 <
4538 > void zjets_prediction_comparison(string mcjzbWithPUa) {
4539 >  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
4540 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
4541 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
4542 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
4543 > }
4544 >  
4545   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
4546    tout << endl << endl;
4547    stringstream bordercut;
# Line 3328 | Line 4649 | void make_table(samplecollection &coll,
4649   }
4650  
4651   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4652 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
4653 +  assert(0);
4654    /*we want a table like this:
4655      __________________     50   |   100  | ...
4656      | Data prediction |  a vs b | a vs b | ...
# Line 3561 | Line 4884 | void qcd_plots(string datajzb, string mc
4884    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
4885    string ytitle("ratio");
4886    if ( use_data==1 ) ytitle = "data/pred";
4887 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4887 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4888 >  delete kinpad;
4889    
4890    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
4891    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 3798 | Line 5122 | void met_vs_jzb_plots(string datajzb, st
5122    lg->SetHeader("DY");
5123    
5124    lg->Draw();
5125 <  save_with_ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5125 >  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5126    
5127    TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5128    metpad3->cd();
# Line 3816 | Line 5140 | void met_vs_jzb_plots(string datajzb, st
5140  
5141    lg2->Draw();
5142    
5143 <  save_with_ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5143 >  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5144    
5145    TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5146    metpad2->cd();
# Line 3835 | Line 5159 | void met_vs_jzb_plots(string datajzb, st
5159    metlefta->Draw("histo");
5160    metrighta->Draw("same");
5161    lg->Draw();
5162 <  save_with_ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5162 >  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5163    
5164    delete Bpred;
5165    delete obs;
# Line 3862 | Line 5186 | void met_vs_jzb_plots(string datajzb, st
5186    aobs->Draw("same");
5187    lg->SetHeader("All MC");
5188    lg->Draw();
5189 <  save_with_ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5189 >  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5190    
5191    
5192    delete lg;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines