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.15 by buchmann, Wed Apr 18 13:04:08 2012 UTC vs.
Revision 1.89 by buchmann, Mon Apr 8 14:14:42 2013 UTC

# Line 28 | Line 28 | void todo() {
28    dout << "Info : The pt requirement is currently set to " << (const char*) passtrig << endl;
29    dout << "Info : The mll requirement is currently set to " << (const char*) cutmass << endl;
30    dout << "Info : The lepton requirement is currently set to " << (const char*) leptoncut << endl;
31 +  dout << "Info : The weight applied to all MC is " << (const char*) cutWeight << endl;
32   }  
33  
34 < void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result, bool doPUreweighting = true )
34 >
35 >
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;
40    if ( !doPUreweighting ) cutWeight="1.0";
41 <
41 >  
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,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
50 <  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
51 <  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
52 <  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,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,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
58 <    MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
59 <    DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
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;
61    }
62    else {
63      TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
# Line 55 | Line 65 | void find_peaks(float &MCPeak,float &MCP
65      reducedMC->Add(rawJZBemMC,-1);
66      reducedData->Add(rawJZBemData,-1);
67      //this is Kostas' way of doing it - we subtract em to get rid of some of the ttbar contribution (in reality, of flavor-symmetric contribution)
68 <    MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
69 <    DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
70 <    
68 >    MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,MCSigmaError,method,saveas);
69 >    DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,DataSigmaError,method,saveas);
70 >    delete reducedMC;
71 >    delete reducedData;
72    }
73  
74    // Revert to original PU reweighting
# Line 65 | Line 76 | void find_peaks(float &MCPeak,float &MCP
76      
77   //  MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
78   //  DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
79 <  dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
80 <  result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
81 <  dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
82 <  result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
79 >  dout   << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
80 >  result << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
81 >  dout   << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
82 >  result << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
83 >  delete rawJZBeemmData;
84 >  delete rawJZBeemmMC;
85 >  delete rawJZBemData;
86 >  delete rawJZBemMC;
87    delete tempcan;
88   }
89  
90 < void make_special_obs_pred_mll_plot(string mcjzb, float jzbthreshold) {
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 >  
190 >  TCut SpecialCut("mll>=0");
191 >  if(sSpecialCut!="") SpecialCut=TCut(sSpecialCut.c_str());
192 >  
193 >  bool DoInvidualeemmPeaks=false;
194 >  
195 >  float mcpeak, datapeak;
196 >  float mcpeakerr, datapeakerr;
197 >  
198 >  float mceepeak,mcmmpeak;
199 >  float mceepeakerr,mcmmpeakerr;
200 >  
201 >  float datammpeak,dataeepeak;
202 >  float datammpeakerr,dataeepeakerr;
203 >  
204 >  float mcSigma,mcSigmaError, dataSigma, dataSigmaError;
205 >  
206 >  dout << "Finding global peak : " << endl;
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(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(SpecialCut&&TCut("id1==1"),SwitchOffNJetsCut,mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
214 >    
215 >    datajzb << "(" << jzbvariabledata;
216 >    mcjzb << "(" << jzbvariablemc;
217 >    
218 >    if(dataeepeak>0) datajzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
219 >    else datajzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
220 >    
221 >    if(datammpeak>0) datajzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
222 >    else datajzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
223 >    
224 >    if(datapeak>0) datajzb << "- (id1!=id2)*" << TMath::Abs(datapeak) << " ";
225 >    else datajzb << "+ (id1!=id2)*" << TMath::Abs(datapeak) << " ";
226 >    
227 >    datajzb << ")";
228 >    
229 >    if(mceepeak>0) mcjzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
230 >    else mcjzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
231 >    
232 >    if(mcmmpeak>0) mcjzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
233 >    else mcjzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
234 >    
235 >    if(mcpeak>0) mcjzb << "- (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
236 >    else mcjzb << "+ (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
237 >    
238 >    mcjzb << ")";
239 >    
240 >  } else {
241 >    datajzb << "(" << jzbvariabledata;
242 >      mcjzb << "(" << jzbvariablemc;
243 >    
244 >    if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
245 >    else datajzb << "+ " << TMath::Abs(datapeak) << " ";
246 >    
247 >    datajzb << ")";
248 >    
249 >    if(mcpeak>0) mcjzb << "- " << TMath::Abs(mcpeak) << " ";
250 >    else mcjzb << "+ " << TMath::Abs(mcpeak) << " ";
251 >    
252 >    mcjzb << ")";
253 >  }
254 >  
255 >    MCPeak=mcpeak;
256 >    MCPeakError=mcpeakerr;
257 >    DataPeak=datapeak;
258 >    DataPeakError=datapeakerr;
259 >    switch_overunderflow(overunderflowstatus);
260 > }
261 >
262 > void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
263    float min=70.0;
264    float max=115.0;
265    if(!PlottingSetup::RestrictToMassPeak) {
266 <    min=10;
267 <    max=150;
266 >    min=20;
267 >    max=300;
268    }
269 <  int nbins=int((max-min)/5);
269 >  int nbins=int((max-min)/binWidth);
270    
271    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
272    
273    stringstream largerzeroS;
274 <  largerzeroS << "(" << mcjzb << ">" << jzbthreshold << ")";
275 <  TCut largerzero(largerzeroS.str().c_str());
274 >  largerzeroS << "(" << datajzb << ">" << jzbthreshold << ")";
275 >  TCut largerzeroD(largerzeroS.str().c_str());
276    
277    stringstream smallerzeroS;
278 <  smallerzeroS << "(" << mcjzb << "<-" << jzbthreshold << ")";
279 <  TCut smallerzero(smallerzeroS.str().c_str());
280 <  
281 <  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,data,luminosity);
282 <  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,mc,luminosity);
283 <  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,data,luminosity);
284 <  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,data,luminosity);
285 <  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,data,luminosity);
278 >  smallerzeroS << "(" << datajzb << "<-" << jzbthreshold << ")";
279 >  TCut smallerzeroD(smallerzeroS.str().c_str());
280 >
281 >
282 >  stringstream largerzeroMS;
283 >  largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
284 >  TCut largerzeroM(largerzeroMS.str().c_str());
285 >  
286 >  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
287 >  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
288 >  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
289 >  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
290 >  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
291  
292    TH1F *RcorrJZBSBem;
293    TH1F *LcorrJZBSBem;
294    TH1F *RcorrJZBSBeemm;
295    TH1F *LcorrJZBSBeemm;
296    
297 <  TH1F *RcorrJZBeemmNoS;
297 > //  TH1F *RcorrJZBeemmNoS;
298  
299 <  if(PlottingSetup::RestrictToMassPeak) {
300 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,data, luminosity);
301 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,data, luminosity);
302 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,data, luminosity);
303 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,data, luminosity);
304 <  }
305 <  
306 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
307 <  if(PlottingSetup::RestrictToMassPeak) {
308 <    Bpred->Add(RcorrJZBem,1.0/3.);
309 <    Bpred->Add(LcorrJZBem,-1.0/3.);
310 <    Bpred->Add(RcorrJZBSBem,1.0/3.);
311 <    Bpred->Add(LcorrJZBSBem,-1.0/3.);
312 <    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
313 <    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
314 <  } else {
315 <    Bpred->Add(RcorrJZBem,1.0);
316 <    Bpred->Add(LcorrJZBem,-1.0);
317 <  }
318 <  
299 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
300 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
301 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
302 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
303 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
304 >  }
305 >  
306 >  // Separate predictions
307 >  TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
308 >  TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
309 >  TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
310 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
311 >    OFP->Scale(1.0/3.0);
312 >    OFP->Add(RcorrJZBSBem,1.0/3.);
313 >    OFP->Add(RcorrJZBSBeemm,1.0/3.);
314 >    OFN->Scale(1.0/3.0);
315 >    OFN->Add(LcorrJZBSBem,1.0/3.);
316 >    OFN->Add(LcorrJZBSBeemm,1.0/3.);
317 >  }
318 >
319 >  TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
320 >  Bpred->Add(OFP);
321 >  Bpred->Add(OFN,-1);
322    Bpred->SetLineColor(kRed);
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    
330    TLegend *leg = allsamples.allbglegend();
331    leg->SetX1(0.58);
332 <  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
332 > //  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
333    leg->AddEntry(Bpred,"predicted (data)","l");
334    leg->Draw("same");
335    
336    stringstream saveas;
337    saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
338    CompleteSave(ckin,saveas.str());
339 <
339 >  
340 >  // Draw all predictions overlayed
341 >  unsigned int w = gStyle->GetHistLineWidth()+1; // Make line a bit wider, since we dash it
342 >  SFN->SetLineColor(kGreen+2);
343 >  SFN->SetLineStyle(2);
344 >  SFN->SetLineWidth(w);
345 >  OFP->SetLineColor(kBlue+2);
346 >  OFP->SetLineStyle(2);
347 >  OFP->SetLineWidth(w);
348 >  OFN->SetLineColor(kMagenta+2);
349 >  OFN->SetLineStyle(3);
350 >  OFN->SetLineWidth(w);
351 >  
352 >  RcorrJZBeemm->Draw();
353 >  SFN->Draw("histo,same");
354 >  OFP->Draw("histo,same");
355 >  OFN->Draw("histo,same");
356 >  Bpred->Draw("histo,same");
357 >  RcorrJZBeemm->Draw("same");
358 >  
359 >  TLegend *leg2 = make_legend("",0.52,0.7);
360 > //  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
361 >  leg2->AddEntry(Bpred,"predicted (data)","l");
362 >  leg2->AddEntry(SFN,  "  SF JZB<0","l");
363 >  leg2->AddEntry(OFN,  "  OF JZB<0","l");
364 >  leg2->AddEntry(OFP,  "  OF JZB>0","l");
365 >  leg2->Draw("same");
366 >  
367 >  saveas.str("");
368 >  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
369 >  CompleteSave(ckin,saveas.str());
370 >  
371    delete RcorrJZBeemm;
372    delete LcorrJZBeemm;
373    delete RcorrJZBem;
374    delete LcorrJZBem;
375 <  if(PlottingSetup::RestrictToMassPeak) {
375 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
376      delete RcorrJZBSBeemm;
377      delete LcorrJZBSBeemm;
378      delete RcorrJZBSBem;
# Line 153 | 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 173 | 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 189 | Line 417 | void make_special_mll_plot(int nbins, fl
417    TIter next(bgleg->GetListOfPrimitives());
418    TObject* obj;
419    // Copy the nice bkgd legend skipping the "data"
420 <  while ( obj = next() )
420 >  while ( (obj = next()) )
421      if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
422        kinleg->GetListOfPrimitives()->Add(obj);
423  
# Line 199 | 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 208 | Line 437 | void draw_ratio_plot(TH1* hdata, THStack
437    TIter next(hmc.GetHists());
438    TObject* obj;
439    TH1* hratio = NULL;
440 <  while ( obj = next() ) {
440 >  while ( (obj = next()) ) {
441      if ( !hratio ) {
442        hratio = (TH1*)obj->Clone();
443        hratio->SetName("hratio");
# Line 239 | Line 468 | void draw_ratio_plot(TH1* hdata, THStack
468    oneline->Draw("same");
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, float legendPosition=0.55) {
473 +
474 +  TCut ibasiccut=basiccut;
475 +  bool draw_separation_lines=false;
476 +
477 +  if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
478 +
479 +  TCut cutSF;
480 +  TCut cutOF;
481 +
482 +  cutOF = cutOSOF&&cutnJets&&ibasiccut;
483 +  cutSF = cutOSSF&&cutnJets&&ibasiccut;
484 +  
485 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
486 +
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);
501 +  datahistoSF->SetMarkerSize(DataMarkerSize);
502 +  datahistoOF->SetLineColor(kRed);
503 +
504 +  if ( !logscale ) {
505 +    datahistoSF->SetMinimum(0); // Defaults
506 +  } else {
507 +    datahistoSF->SetMinimum(0.5);
508 +  }
509 +  if (ymax<0) {
510 +    if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
511 +    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
512 +  } else {
513 +    datahistoSF->SetMaximum(ymax);
514 +  }
515 +
516 +  float ymaxSet = datahistoSF->GetMaximum();
517 +
518 +  datahistoSF->GetXaxis()->SetTitle(xlabel.c_str());
519 +  datahistoSF->GetYaxis()->SetTitle("Events");
520 +  datahistoSF->GetXaxis()->CenterTitle();
521 +  datahistoSF->GetYaxis()->CenterTitle();
522 +
523 +  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.7,false,legendPosition+0.2);
524 +  mleg->AddEntry(datahistoSF, "Same-flavor", "PL");
525 +  if (datahistoOF->Integral()>0) {
526 +    mleg->AddEntry(datahistoOF, "Opposite-flavor", "L");
527 +  } else {
528 +    mleg->AddEntry((TObject*)0, "", "");
529 +  }
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");
535 +  mleg->Draw();
536 +  DrawPrelim();
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();
546 +  delete mleg;
547 +  delete rcan;
548 +  delete ofsf_can;
549 +
550 +  return ymaxSet;
551 +
552 + }
553 +
554 + // Compare data to data
555 + float make_data_comparison_plot(string variable, TCut cut, int nbins, float min, float max, float ymax, bool logscale,
556 +                                string xlabel, string filename, float legendPosition=0.55) {
557 +
558 +  TCut ibasiccut=basiccut&&cut;
559 +
560 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
561 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
562 +  rcan->SetLogy(logscale);
563 +  rcan->cd();
564 +
565 +  std::cout << "Data comparison: variable = " << variable << ", cut = " << ibasiccut.GetTitle() << std::endl;
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);
573 +
574 +  if ( !logscale ) {
575 +    data1->SetMinimum(0); // Defaults
576 +  } else {
577 +    data1->SetMinimum(0.5);
578 +  }
579 +  if (ymax<0) {
580 +    if ( logscale ) data1->SetMaximum(5.3*data1->GetMaximum());
581 +    else data1->SetMaximum(1.5*data1->GetMaximum());
582 +  } else {
583 +    data1->SetMaximum(ymax);
584 +  }
585 +
586 +  float ymaxSet = data1->GetMaximum();
587 +
588 +  data1->GetXaxis()->SetTitle(xlabel.c_str());
589 +  data1->GetYaxis()->SetTitle("Events");
590 +  data1->GetXaxis()->CenterTitle();
591 +  data1->GetYaxis()->CenterTitle();
592 +
593 +  TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
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, "new/old" );
602 +
603 +  data1->Delete();
604 +  data2->Delete();
605 +  delete mleg;
606 +  delete rcan;
607 +  delete ckin;
608 +
609 + }
610 +
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>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 +
619 +  int start = 0;
620 +  if ( !PlottingSetup::openBox ) start = 3;
621 +
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,
626 +                         filename+plotname[i], legendPosition );
627 +    } else {
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,
632 +                       filename+plotname[i]+"_mm", legendPosition );
633 +    make_one_OFSF_plot(variable, "id1==0&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
634 +                       filename+plotname[i]+"_ee", legendPosition );
635 +  }
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 247 | 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 268 | 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") cut=cutmass&&cutOSSF&&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_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    }
805 <  if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
806 <  if(Contains(filename,"mll_aboveJZB100")) cut=cutOSSF&&cutnJets&&ibasiccut;
805 >  if(Contains(filename,"aboveJZB")) cut=cutOSSF&&cutnJets&&ibasiccut;
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=cutOSSF;
810    if(filename=="mll_inclusive_osof") cut=cutOSOF;
# Line 288 | Line 812 | void make_kin_plot(string variable, stri
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;
816  
817    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
818    ckin->SetLogy(logscale);
819    TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
820    datahisto->SetMarkerSize(DataMarkerSize);
821 <  THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
821 >  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
822 >  else datahisto->SetMinimum(0.5);
823 >  // Custom max.
824 >  if(variable=="TMath::Abs(pfJetDphiMet[0])") datahisto->SetMaximum(1.5*datahisto->GetMaximum());
825    if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
826    if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
827 <  if(filename=="mll_inclusive") datahisto->SetMinimum(1);
827 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_mm"||filename=="mll_inclusive_ee") datahisto->SetMinimum(1);
828    if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
829    if(filename=="mll_osof") datahisto->SetMinimum(9);
830 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
831 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
832  
833 <  datahisto->SetMaximum(5.3*datahisto->GetMaximum());
304 <  datahisto->Draw("e1");
305 <  ckin->Update();
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 312 | Line 840 | void make_kin_plot(string variable, stri
840          }              
841    }
842  
843 <  mcstack.Draw("same");
843 >  // Draw signal by hand (for some reason I don't manage to use the sample class: it adds it to the stack!)
844 >  string signal("LM3");
845 >  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
846 >  int idx = signalsamples.FindSample(signal)[0];
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("histo,same");
855 >  
856    datahisto->Draw("same,e1");
857    TLegend *kinleg = allsamples.allbglegend();
858    kinleg->Draw();
# Line 354 | Line 894 | void make_kin_plot(string variable, stri
894          kinpad->cd();
895          kinpad->SetLogy(logscale);
896          datahisto->Draw("e1");
897 <        mcstack.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 362 | Line 903 | void make_kin_plot(string variable, stri
903            upperboundary->Draw("same");
904          }
905            
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 376 | 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 < void make_JES_plot() {
984 >
985 > void make_JES_plot(TCut cut, string name) {
986  
987    int nbins=10;
988    float min=-0.5;
989    float max = 9.5;
990    bool logscale=true;
991    string xlabel="nJets";
389  TCut cut=cutmass&&cutOSSF&&basiccut;
992  
993    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
994    ckin->SetLogy(logscale);
995 <  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
995 >  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,data,luminosity);
996    datahisto->SetMarkerSize(DataMarkerSize);
997 <  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
998 <  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
999 <  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
997 >  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,mc,luminosity);
998 >  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum40p1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
999 >  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum40n1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1000  
1001    datahisto->SetMinimum(1);
1002    datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
# Line 413 | Line 1015 | void make_JES_plot() {
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();
1022    kinleg->AddEntry(JESunc,"JES uncertainty","f");
1023    kinleg->Draw();
1024 <  CompleteSave(ckin,"Systematics/JES");
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,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1839 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1840 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1841 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1842 +  
1843 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1844 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
1845 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1846 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
1847 +  
1848 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1849 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1850 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1851 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [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,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1862 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
1863 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1864 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1865 +  
1866 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1867 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1868 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1869 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [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,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1890 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
1891 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1892 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1893 +  
1894 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1895 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
1896 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1897 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
1898 +  
1899 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1900 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1901 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1902 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [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,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1913 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
1914 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1915 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1916 +  
1917 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1918 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1919 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1920 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [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 = true;
2011 +  bool doKin  = false;
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!");
2017 <  float mll_low=40;
2017 >  float mll_low=50;
2018    float mll_hi=160;
2019    if(!PlottingSetup::RestrictToMassPeak) {
2020 <        mll_low=10;
2021 <        mll_hi=210;
2020 >        mll_low=20;
2021 >        mll_hi=320;
2022    }
2023 <  /*
2024 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2025 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2026 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2027 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2028 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2029 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2030 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2031 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2032 <  make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);/*
2033 <  make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
2034 <  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
2035 <  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
2036 <  make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
2037 <  make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
2038 <  make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
2039 <  make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
2040 <  make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
2041 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
2042 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);*//*
2043 <  if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2044 <  stringstream jzbcut;
2045 <  jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
2046 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2047 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB100",doPF,true);
2048 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2049 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB100",doPF,true);
2050 <  stringstream jzbcut2;
2051 <  jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
2052 <  make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
2053 <  make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB150",doPF,true);
2054 <  stringstream jzbcut3;
2055 <  jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
2056 <  make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof_aboveJZB50",doPF,true,true);
2057 <  */
2058 <  make_special_obs_pred_mll_plot(mcjzb,50);
2059 <  make_special_obs_pred_mll_plot(mcjzb,100);
2060 <  make_special_obs_pred_mll_plot(mcjzb,150);
2061 <  make_special_obs_pred_mll_plot(mcjzb,200);
2062 <  make_special_obs_pred_mll_plot(mcjzb,250);
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("st", "met[4]>100&&pfJetGoodNum40>=3", 20, 0, 2000., false, "S_{T}", "FrankT");
2035 >      make_OFSF_plots("pt1+pt2+met[4]+Sum$(pfJetGoodPt)", "met[4]>100&&pfJetGoodNum40>=3", 20, 0, 2000., false, "#tilde{S}_{T}", "FrankT");
2036 >      assert(0);
2037 >      
2038 > //      make_OFSF_plots("mll", "met[4]>100", 60, 20., 320., false, "m_{ll}", "mll");
2039 > //      make_OFSF_plots("leptonNum", "met[4]>100", 3, 2, 5., false, "N(leptons)", "NLeptons");
2040 >
2041 > //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100",                        7, 3, 10, true, "#(jets)", "njets");
2042 > //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", "njets_btagVeto");
2043 > //      make_OFSF_plots("pfJetGoodNum40", "met[4]>100&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", "njets_AtLeastOneBJet30");
2044 >
2045 > //      make_OFSF_plots("pfJetGoodNumBtag30", "met[4]>100", 5, -0, 4.5, true, "#(b-jets)", "nbjets");
2046 > //      make_OFSF_plots("pfJetGoodPtBtag[0]", "met[4]>100&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", "ptb1");
2047 >
2048 > //      make_OFSF_plots("iso1", "met[4]>100", 20, 0, 0.3, true, "lepton 1 isolation", "iso1");
2049 > //      make_OFSF_plots("iso2", "met[4]>100", 20, 0, 0.3, true, "lepton 2 isolation", "iso2");
2050 > //      make_OFSF_plots("pt1",  "met[4]>100", 30, 0., 300., true, "p_{T,1}", "pt1");
2051 >     make_OFSF_plots("pt",  "met[4]>100", 30, 0., 300., true, "p_{ll}", "pt");
2052 > //      make_OFSF_plots("pt2",  "met[4]>100", 22, 0., 220., true, "p_{T,2}", "pt2");
2053 > //      make_OFSF_plots("eta1", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{1}", "eta1", 0.15);
2054 > //      make_OFSF_plots("eta2", "met[4]>100", 10, -2.5, 2.5, false, "#eta_{2}", "eta2", 0.15);
2055 > //      make_OFSF_plots("phi1", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", "phi1", 0.2);
2056 > //      make_OFSF_plots("phi2", "met[4]>100", 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", "phi2", 0.2);
2057 > //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", "met[4]>100", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2", 0.2);
2058 > //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphij1met", 0.2);
2059 >    
2060 > //     make_OFSF_plots("TMath::Abs(dphi)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphi", 0.2);
2061 > //     make_OFSF_plots("TMath::Abs(dphiMet1)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1", 0.2);
2062 > //     make_OFSF_plots("TMath::Abs(dphiMet2)", "met[4]>100", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2", 0.2);
2063 > //     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");
2064 > //     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");
2065 > //     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");
2066 > //     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");
2067 >  }
2068 >
2069 >  if ( doDataComp) {
2070 >    TCut mllCut("");
2071 >    float massmin = 15.;
2072 >    float massmax = 315;
2073 >    int massnbins = 60;
2074 > /*    if ( !PlottingSetup::openBox ) {
2075 >      mllCut = "mll>70";
2076 >      massmin = 120;
2077 >      massmax = 360;
2078 >      massnbins = 14;
2079 >    }*/
2080 >
2081 >    TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2082 >    
2083 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2084 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2085 >    
2086 >    
2087 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2088 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2089 >    make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2090 >    make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2091 >    make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2092 >    
2093 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2094 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2095 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2096 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2097 >
2098 >  
2099 >    string basiccutsaved = (const char*)basiccut;
2100 >    
2101 >    string newbasiccut=basiccutsaved;
2102 >    
2103 >    size_t found;
2104 >    found = newbasiccut.find( "pt2>20" );
2105 >    while (found!=string::npos){
2106 >      newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2107 >      found = newbasiccut.find( "pt2>20" );
2108 >    }
2109 >    basiccut=TCut(newbasiccut.c_str());
2110 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2111 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2112 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2113 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2114 >    basiccut=TCut(basiccutsaved.c_str());
2115 >    
2116 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2117 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2118 >    
2119 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2120 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2121 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2122 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2123 >
2124 >    
2125 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2126 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2127 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2128 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2129 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2130 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2131 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2132 >    make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2133 >
2134 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2135 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2136 >    
2137 >    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");
2138 >    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");
2139 >    
2140 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2141 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2142 >    
2143 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2144 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2145 >
2146 >
2147 >    make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2148 >    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");
2149 >    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");
2150 >
2151 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2152 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2153 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2154 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2155 >
2156 >  }
2157 >
2158 >
2159 >  if ( doKin ) {
2160 >    string mllCut("");
2161 >    
2162 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2163 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2164 >    assert(0);
2165 >  
2166 >    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);
2167 >    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);
2168 >    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);
2169 >    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);
2170 >
2171 >    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);
2172 >    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);
2173 >    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);
2174 >    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);
2175 >
2176 >
2177 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2178 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2179 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2180 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2181 >
2182 >    
2183 >    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);
2184 >    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);
2185 >    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);
2186 >    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);
2187 >
2188 >    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);
2189 >    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);
2190 >    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);
2191 >    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);
2192 >
2193 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2194 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2195 >    
2196 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2197 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2198 >    
2199 >    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);
2200 >    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);
2201 >    
2202 >    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);
2203 >    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);
2204 >
2205 >    
2206 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2207 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2208 >    // Plots in signal region
2209 >    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2210 >
2211 >
2212 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2213 >    
2214 >    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");
2215 >    /*
2216 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2217 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2218 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2219 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2220 >
2221 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2222 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2223 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2224 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2225 >
2226 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2227 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2228 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2229 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2230 >
2231 >    
2232 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2233 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2234 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2235 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2236 >
2237 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2238 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2239 >
2240 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2241 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2242 >    
2243 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2244 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2245 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2246 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2247 >
2248 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2249 >    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);
2250 >    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);
2251 >    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);
2252 >    
2253 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2254 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2255 >    
2256 >    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);
2257 >    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);
2258 >    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);
2259 >    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);
2260 >    
2261 >    
2262 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2263 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2264 >
2265 >    // Further inclusive invariant mass plots
2266 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2267 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2268 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2269 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2270 >    
2271 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2272 >    //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2273 >    
2274 >    
2275 >    // Number of jets
2276 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2277 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2278 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2279 >    
2280 >    // Others
2281 >    make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
2282 >    //  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
2283 >    //  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
2284 >    make_kin_plot("pt","",50,0,500,dolog,"Z p_{T} [GeV]","Zpt",doPF);
2285 >    make_kin_plot("pt1","",50,0,200,nolog,"p_{T} [GeV]","pt1",doPF);
2286 >    make_kin_plot("pt2","",50,0,200,nolog,"p_{T} [GeV]","pt2",doPF);
2287 >    make_kin_plot("eta1","",40,-3,3,nolog,"#eta_{l}","eta",doPF);
2288 >    make_kin_plot("jzb[1]","",100,-150,200,dolog,"JZB [GeV]","jzb_ossf",doPF);
2289 >    //   stringstream jzbcut;
2290 >    //   jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
2291 >    //   make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2292 >    //   make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_osof_aboveJZB100",doPF,true);
2293 >    //   make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_ee_aboveJZB100",doPF,true);
2294 >    //   make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_mm_aboveJZB100",doPF,true);
2295 >    //   stringstream jzbcut2;
2296 >    //   jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
2297 >    //   make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
2298 >    //   make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_osof_aboveJZB150",doPF,true);
2299 >    //   make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_ee_aboveJZB150",doPF,true);
2300 >    //   make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_mm_aboveJZB150",doPF,true);
2301 >    //   stringstream jzbcut3;
2302 >    //   jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
2303 >    //   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);  
2304 >    //   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_osof_aboveJZB50",doPF,true,true);
2305 >    //   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_ee_aboveJZB50",doPF,true);  
2306 >    //   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_mm_aboveJZB50",doPF,true);  
2307 >    
2308 >    //   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);
2309 >    //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);
2310 >    //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);*/
2311 >  }
2312 >    
2313 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2314 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2315 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2316 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2317 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2318 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2319 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2320 > /*
2321 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2322 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2323 > */
2324 >  switch_overunderflow(false);
2325   }
2326  
2327   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
2328                       int nbins, float xmin, float xmax, bool log,
2329                       float ymin=0, float ymax=0, bool leftJustified=false ) {
2330 <      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
2330 >  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
2331  
2332    TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
2333    if(weightbackup==TCut("1.0")||weightbackup==TCut("1")) write_warning(__FUNCTION__,"WATCH OUT THE WEIGHT HAS POSSIBLY NOT BEEN RESET!!!! PLEASE CHANGE LINE "+any2string(__LINE__));
2334 <  if(var=="numVtx") cutWeight=TCut("1.0");
2334 >  //if(var=="numVtx") cutWeight=TCut("1.0");
2335    TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
2336    TCut jzbMC[]  = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
2337  
2338    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- below: the next ~20 lines changed!
2339    int nRegions=4;
2340 <  if(!PlottingSetup::RestrictToMassPeak) {
2340 >  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
2341      nRegions=2;
2342    }
2343    
# Line 509 | Line 2355 | void make_comp_plot( string var, string
2355        TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
2356        ccomp->SetLogy(log);
2357        TH1F *datahisto = allsamples.Draw("datahisto",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
2358 <      TH1F *lm4histo = signalsamples.Draw("lm4histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
2358 >      TH1F *lm3histo  = signalsamples.Draw("lm3histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],data,luminosity,signalsamples.FindSample("LM3"));
2359        THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],  mc,  luminosity);
2360        datahisto->SetMarkerSize(DataMarkerSize);
2361        if (ymax>ymin) datahisto->SetMaximum(ymax);
2362 <      lm4histo->SetLineStyle(2);
2362 >      lm3histo->SetLineStyle(2);
2363        datahisto->Draw("e1");
2364 <      mcstack.Draw("same");
2364 >      mcstack.Draw("histo,same");
2365        datahisto->Draw("same,e1");
2366 < //      lm4histo->Draw("hist,same");
2366 >      lm3histo->Draw("hist,same");
2367        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
2368        if ( leftJustified ) {
2369          Float_t w = kinleg->GetX2()-kinleg->GetX1();
2370          kinleg->SetX1(0.2);
2371          kinleg->SetX2(0.2+w);
2372        }
2373 < //      kinleg->AddEntry(lm4histo,"LM4","l");
2373 >      kinleg->AddEntry(lm3histo,"LM3","l");
2374        kinleg->Draw();
2375        TText* write_variable = write_text(0.99,0.01,var);
2376        write_variable->SetTextAlign(31);
# Line 533 | Line 2379 | void make_comp_plot( string var, string
2379        CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
2380        delete datahisto;
2381        delete ccomp;
2382 <      delete lm4histo;
2382 >      delete lm3histo;
2383      }
2384    cutWeight=weightbackup;
2385   }
# Line 543 | Line 2389 | void region_comparison_plots(string mcjz
2389    dout << "Creating comparison plots for signal and control regions" << endl;
2390    // Compare a few quantities in the signal region and all 7 control regions
2391  
2392 <  switch_overunderflow(true);  // switching overflow/underflow bins on
2392 > //  switch_overunderflow(true);  // switching overflow/underflow bins on
2393      
2394 <  
2394 >  switch_overunderflow(true);
2395      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2396 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
2396 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2397      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
2398      float mll_low=50;float mll_high=170;
2399      if(!PlottingSetup::RestrictToMassPeak) {
2400 <        mll_high=200;
2401 <        mll_low=50;
2400 >        mll_high=300;
2401 >        mll_low=20;
2402      }
2403 <    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,30,mll_low,mll_high,false,0,16.);
2404 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2405 <    make_comp_plot("pfJetGoodNum","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2403 >    make_comp_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",jzbcut,mcjzb,datajzb,100,0,10,true);
2404 >    make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2405 >
2406 >    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2407 >    make_comp_plot("met[4]","pf#slash{E}_{T} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2408 >    make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2409 >    make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2410      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
2411 <    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,20,0.,20.,false,0,16.);
2411 >    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,40,0.,40.,false,0,16.);
2412      make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2413      make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2414 +    make_comp_plot("eta1","#eta_1","eta1",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2415 +    make_comp_plot("eta2","#eta_2","eta2",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2416    }
2417  
2418    switch_overunderflow(false); // switching overflow/underflow bins off
# Line 759 | Line 2611 | vector<TF1*> do_extended_fit_to_plot(TH1
2611   //      the line above is not necessary anymore as we're now looking at a prediction without Z+Jets, and not multiplied with (1.0/3)
2612    TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
2613    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2614 <  if(PlottingSetup::RestrictToMassPeak) ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
2614 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
2615  
2616  
2617    TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
# Line 854 | Line 2706 | if you want to start from scratch (witho
2706    return return_functions;
2707   }
2708  
2709 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false,string subdir="" )
2709 > void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
2710   {
2711 <  // note: sigma is not used ATM
860 <  switch_overunderflow(true);
2711 >  
2712    bool is_data=false;
2713    bool use_signal=false;
2714    if(use_data==1) is_data=true;
2715    if(use_data==2) use_signal=true;
2716 <  int nbins=50;//100;
2717 <  if(is_data) nbins=50;
2716 >  int nbins=int(high/10);//100;
2717 >  if(is_data) nbins=int(high/10);
2718    float low=0;
2719 <  float hi=500;
2719 >  float hi=high;
2720 >  
2721 >  stringstream cutpositiveS;
2722 >  cutpositiveS << "(" << jzb << ">0)";
2723 >  TCut cutpositive(cutpositiveS.str().c_str());
2724 >  stringstream cutnegativeS;
2725 >  cutnegativeS << "(" << jzb << "<0)";
2726 >  TCut cutnegative(cutnegativeS.str().c_str());
2727    
870  stringstream largerzeroS;
871  largerzeroS << "("<<jzb<<">0)";
872  TCut largerzero(largerzeroS.str().c_str());
873  stringstream smallerzeroS;
874  smallerzeroS << "("<<jzb<<"<0)";
875  TCut smallerzero(smallerzeroS.str().c_str());
2728    
2729    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2730 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2731 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2732 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2733 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2730 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2731 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2732 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2733 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2734  
2735    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2736    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
# Line 893 | Line 2745 | void do_prediction_plot(string jzb, TCan
2745    
2746    TH1F *RcorrJZBeemmNoS;
2747  
2748 <    //these are for the ratio
2749 <  
2750 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2751 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2752 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
901 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2748 >  //these are for the ratio
2749 >  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2750 >  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2751 >  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2752 >  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2753    
2754    TH1F *JRcorrJZBSBem;
2755    TH1F *JLcorrJZBSBem;
2756    TH1F *JRcorrJZBSBeemm;
2757    TH1F *JLcorrJZBSBeemm;
2758    
2759 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,false);
2759 >  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);
2760  
2761    
2762 <  if(PlottingSetup::RestrictToMassPeak) {
2763 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2764 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2765 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2766 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2762 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2763 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2764 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2765 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2766 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2767      
2768      //these are for the ratio
2769 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2770 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2771 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzero,is_data, luminosity,use_signal);
2772 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzero,is_data, luminosity,use_signal);
2769 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2770 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2771 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2772 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2773    }
2774    
2775    TH1F *lm4RcorrJZBeemm;
2776 <  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&&largerzero,is_data, luminosity,allsamples.FindSample("LM"));
2776 >  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"));
2777    
2778    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2779    
# Line 931 | Line 2782 | void do_prediction_plot(string jzb, TCan
2782      
2783    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2784    TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
2785 <  if(PlottingSetup::RestrictToMassPeak) {
2785 >    
2786 >  TH1F *BpredSys = new TH1F("Bpredsys","Bpredsys",PlottingSetup::global_ratio_binning.size()-1,&PlottingSetup::global_ratio_binning[0]);
2787 >  ClearHisto(BpredSys);
2788 >    
2789 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2790      Bpred->Add(RcorrJZBem,1.0/3.);
2791      Bpred->Add(LcorrJZBem,-1.0/3.);
2792      Bpred->Add(RcorrJZBSBem,1.0/3.);
# Line 953 | Line 2808 | void do_prediction_plot(string jzb, TCan
2808      JBpred->Add(JLcorrJZBSBem,-1.0/3.);
2809      JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
2810      JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
2811 +      
2812 +    //Systematics:
2813 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertONPEAK*zjetsestimateuncertONPEAK);
2814 +    AddSquared(BpredSys,JRcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2815 +    AddSquared(BpredSys,JLcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2816 +    AddSquared(BpredSys,JRcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2817 +    AddSquared(BpredSys,JLcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2818 +    AddSquared(BpredSys,JRcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2819 +    AddSquared(BpredSys,JLcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2820    } else {
2821      Bpred->Add(RcorrJZBem,1.0);
2822      Bpred->Add(LcorrJZBem,-1.0);
# Line 962 | Line 2826 | void do_prediction_plot(string jzb, TCan
2826      //these are for the ratio
2827      JBpred->Add(JRcorrJZBem,1.0);
2828      JBpred->Add(JLcorrJZBem,-1.0);
2829 +      
2830 +    //Systematics
2831 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertOFFPEAK*zjetsestimateuncertOFFPEAK);
2832 +    AddSquared(BpredSys,JRcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2833 +    AddSquared(BpredSys,JLcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2834 +
2835    }
2836      
2837 <  
2838 <  
2837 >  SQRT(BpredSys);
2838 >  BpredSys->Divide(JBpred);
2839 >
2840    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2841    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
2842    Tpred->Add(LcorrJZBem,-1.0);
2843 <  if(PlottingSetup::RestrictToMassPeak) {
2843 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2844      Tpred->Add(RcorrJZBSBem,1.0);
2845      Tpred->Add(LcorrJZBSBem,-1.0);
2846      Tpred->Add(RcorrJZBSBeemm,1.0);
# Line 1018 | Line 2889 | void do_prediction_plot(string jzb, TCan
2889      Bpred->Draw("hist,same");
2890      //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2891      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2892 <    lm4RcorrJZBeemm->Draw("hist,same");
2892 >    //lm4RcorrJZBeemm->Draw("hist,same");
2893      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
2894      legBpred->AddEntry(Bpred,"predicted","l");
2895 <    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2896 <    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2897 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2895 > //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2896 > //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2897 > //     legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2898      legBpred->Draw();
2899      DrawPrelim();
2900  
# Line 1033 | Line 2904 | void do_prediction_plot(string jzb, TCan
2904      Bpred->SetLineWidth(2);
2905      predcomppad->cd();
2906      predcomppad->SetLogy(1);
1036    
2907      TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
2908      TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
2909      sidebandsemu->Add(jzbnegative,-1);
# Line 1055 | Line 2925 | void do_prediction_plot(string jzb, TCan
2925   //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
2926      lm4RcorrJZBeemm->SetLineWidth(2);
2927      //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
2928 <    lm4RcorrJZBeemm->Draw("histo,same");
2928 > //     lm4RcorrJZBeemm->Draw("histo,same");
2929      DrawPrelim();
2930      TLegend *speciallegBpred = make_legend("",0.45,0.55);
2931      //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
2932      speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
2933      speciallegBpred->AddEntry(Bpred,"Total background","l");
2934      speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
2935 <    speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
2935 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
2936 >    else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
2937   //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
2938 <    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2938 > //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2939      speciallegBpred->Draw();
2940 <    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,use_data!=1,"data/pred");
2940 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
2941 >    delete predcomppad;
2942      
2943      TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
2944 <    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
2944 >    specialcanv->SetLogy(1);
2945 > //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
2946      blankback->Draw();
2947 <    kostack.Draw("same");
2947 > //    kostack.Draw("same");
2948 >    predcomposition.Draw("hist");
2949      Bpred->Draw("hist,same");
2950 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2950 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2951      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2952      legBpred->Draw();
2953      DrawPrelim();
2954      CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
2955      Bpred->SetLineWidth((int)CurrentBpredLineWidth);
2956      
2957 +    
2958 +    //for(int i=1;i<=Bpred->GetNbinsX();i++) cout << Bpred->GetBinLowEdge(i) << ";" << Bpred->GetBinLowEdge(i)+Bpred->GetBinWidth(i) << ";;" << RcorrJZBeemm->GetBinContent(i) << ";" << LcorrJZBeemm->GetBinContent(i) << ";" << RcorrJZBem->GetBinContent(i) << ";" << LcorrJZBem->GetBinContent(i) << endl;
2959 +    
2960      delete speciallegBpred;
2961      delete Zjetspred;
2962      delete TTbarpred;
# Line 1092 | Line 2969 | void do_prediction_plot(string jzb, TCan
2969      Bpred->Draw("hist,same");
2970      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2971      legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
2972 <    legBpred->AddEntry(Bpred,"MC predicted","l");
2972 >    legBpred->AddEntry(Bpred,"MC predicted","l");    
2973      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
2974      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
2975 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2975 > //     if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2976      legBpred->Draw();
2977      DrawMCPrelim();
2978      Bpredsaveas="Bpred_MC";
# Line 1127 | Line 3004 | void do_prediction_plot(string jzb, TCan
3004        
3005        RcorrJZBeemmNoS->SetLineStyle(2);
3006        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3007 <      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3007 > //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3008        legBpred2->Draw();
3009        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3010        RcorrJZBeemmNoS->Draw("histo,same");
# Line 1144 | Line 3021 | void do_prediction_plot(string jzb, TCan
3021    string ytitle("ratio");
3022    if ( use_data==1 ) ytitle = "data/pred";
3023    //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3024 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle);//not extending the y range anymore up to 4
3024 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3025 >  
3026 >  delete kinpad;
3027 >
3028  
3029    
3030    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3031 <  /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
3032 <  if(PlottingSetup::RestrictToMassPeak) {
3031 >  // The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
3032 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3033      TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
3034      Bpredem->Add(RcorrJZBem);
3035      Bpredem->Add(LcorrJZBem,-1);
# Line 1204 | Line 3084 | void do_prediction_plot(string jzb, TCan
3084        legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3085        legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3086        legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3087 <      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3087 > //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3088        legBpredc->Draw();
3089        CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3090      }
3091    }
3092    
3093 +  TFile *f = new TFile("tester.root","RECREATE");
3094 +  RcorrJZBeemm->Write();
3095 +  Bpred->Write();
3096 +  f->Close();
3097 +  
3098    delete RcorrJZBeemm;
3099    delete LcorrJZBeemm;
3100    delete RcorrJZBem;
# Line 1222 | Line 3107 | void do_prediction_plot(string jzb, TCan
3107  
3108    delete blankback;
3109    
3110 <  if(PlottingSetup::RestrictToMassPeak) {
3110 >  delete BpredSys;
3111 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3112      delete RcorrJZBSBem;
3113      delete LcorrJZBSBem;
3114      delete RcorrJZBSBeemm;
# Line 1234 | Line 3120 | void do_prediction_plot(string jzb, TCan
3120      delete JLcorrJZBSBeemm;
3121    }
3122    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1237  switch_overunderflow(false);
3123   }
3124  
3125   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3126 +  switch_overunderflow(true);
3127    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3128 <  do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
3128 >  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3129    if ( !PlottingSetup::Approved ) {
3130 <    do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
3131 <    do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
3130 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3131 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3132    } else {
3133      write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3134    }
3135 < }
3136 <
1251 < void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1252 <  bool do_data=0;
1253 <  bool dosignal=0;
1254 <  if(is_data==1) do_data=1;
1255 <  if(is_data==2) dosignal=1;
1256 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1257 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1258 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1259 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1260 <  
1261 <  TH1F *RcorrJZBSBem;
1262 <  TH1F *LcorrJZBSBem;
1263 <  TH1F *RcorrJZBSBeemm;
1264 <  TH1F *LcorrJZBSbeemm;
1265 <  
1266 <  if(PlottingSetup::RestrictToMassPeak) {
1267 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1268 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1269 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1270 <    LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1271 <  }
1272 <  
1273 <
1274 <
1275 <
1276 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1277 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1278 <  if(PlottingSetup::RestrictToMassPeak) {
1279 <    Bpred->Add(RcorrJZBem,1.0/3);
1280 <    Bpred->Add(LcorrJZBem,-1.0/3);
1281 <    Bpred->Add(RcorrJZBSBem,1.0/3);
1282 <    Bpred->Add(LcorrJZBSBem,-1.0/3);
1283 <    Bpred->Add(RcorrJZBSBeemm,1.0/3);
1284 <    Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1285 <  } else {
1286 <    Bpred->Add(RcorrJZBem,1.0);
1287 <    Bpred->Add(LcorrJZBem,-1.0);
1288 <  }
1289 <
1290 <  can->cd();
1291 <  can->SetLogy(0);
1292 <  Bpred->SetLineColor(kRed);
1293 <  Bpred->SetStats(0);
1294 <  if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1295 <  TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1296 <  JZBratioforfitting->Divide(Bpred);
1297 <  TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1298 <  
1299 <  
1300 <  JZBratio->SetTitle("");
1301 <  JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1302 < //  if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1303 <  
1304 <  TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1305 <  TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1306 < //  straightline_fit->SetParameter(0,1);
1307 <  JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1308 <  pol0d->SetParameter(0,pol0->GetParameter(0));
1309 <  
1310 <  JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1311 <  JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1312 <  if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1313 <  JZBratio->GetYaxis()->SetNdivisions(519);
1314 <  JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1315 <  JZBratio->GetYaxis()->CenterTitle();
1316 <  JZBratio->GetXaxis()->CenterTitle();
1317 <  JZBratio->SetMarkerSize(DataMarkerSize);
1318 <  JZBratio->Draw("AP");
1319 <  /////----------------------------
1320 <  TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1321 <  writeresult->SetFillStyle(4000);
1322 <  writeresult->SetFillColor(kWhite);
1323 <  writeresult->SetTextFont(42);
1324 <  writeresult->SetTextSize(0.03);
1325 <  writeresult->SetTextAlign(12);
1326 <  ostringstream jzb_agreement_data_text;
1327 <  jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) <<  pol0->GetParError(0);
1328 <  if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1329 <  if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1330 < /*  if(is_data) writeresult->AddText("Data closure test");
1331 <  else writeresult->AddText("MC closure test");
1332 <  */
1333 <  writeresult->AddText(jzb_agreement_data_text.str().c_str());
1334 < //  writeresult->Draw("same");
1335 < //  pol0d->Draw("same");
1336 <  TF1 *topline =  new TF1("","1.5",0,1000);
1337 <  TF1 *bottomline =  new TF1("","0.5",0,1000);
1338 <  topline->SetLineColor(kBlue);
1339 <  topline->SetLineStyle(2);
1340 <  bottomline->SetLineColor(kBlue);
1341 <  bottomline->SetLineStyle(2);
1342 < //  topline->Draw("same");
1343 < //  bottomline->Draw("same");
1344 <  TF1 *oneline = new TF1("","1.0",0,1000);
1345 <  oneline->SetLineColor(kBlue);
1346 <  oneline->SetLineStyle(1);
1347 <  oneline->Draw("same");
1348 <  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.
1349 <  if(is_data==1) DrawPrelim();
1350 <  else DrawMCPrelim();
1351 <  TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1352 <  leg->SetTextFont(42);
1353 <  leg->SetTextSize(0.04);
1354 < //   if(is_data==1) leg->SetHeader("Ratio (data)");
1355 < //   else leg->SetHeader("Ratio (MC)");
1356 <
1357 <  TString MCtitle("MC ");
1358 <  if (is_data==1) MCtitle = "";
1359 <
1360 <  leg->SetFillStyle(4000);
1361 <  leg->SetFillColor(kWhite);
1362 <  leg->SetTextFont(42);
1363 < //  leg->AddEntry(topline,"+20\% sys envelope","l");
1364 <  leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1365 <  leg->AddEntry(oneline,"ratio = 1","l");
1366 < //  leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1367 < //  leg->AddEntry(bottomline,"#pm50% envelope","l");
1368 <
1369 <
1370 <  //leg->Draw("same"); // no longer drawing legend
1371 <
1372 <  if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1373 <  if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1374 <  if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1375 <  
1376 <  delete RcorrJZBeemm;
1377 <  delete LcorrJZBeemm;
1378 <  delete RcorrJZBem;
1379 <  delete LcorrJZBem;
1380 <  
1381 <  delete RcorrJZBSBem;
1382 <  delete LcorrJZBSBem;
1383 <  delete RcorrJZBSBeemm;
1384 <  delete LcorrJZBSbeemm;
1385 < }
1386 <
1387 < void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1388 <  TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1389 <  globalc->SetLogy(0);
1390 <  
1391 <  do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh  );
1392 <  do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh  );
1393 <  do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh  );
3135 >  delete globalcanvas;
3136 >  switch_overunderflow(false);
3137   }
3138  
3139   string give_jzb_expression(float peak, int type) {
# Line 1477 | Line 3220 | void lepton_comparison_plots() {
3220    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3221    eemmlegend->Draw();
3222    DrawPrelim();
3223 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3223 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3224    
3225    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"));
3226    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 1578 | Line 3321 | void draw_pure_jzb_histo(TCut cut,string
3321    datahisto->SetMinimum(0.1);
3322    datahisto->SetMarkerSize(DataMarkerSize);
3323    datahisto->Draw("e1");
3324 <  mcstack.Draw("same");
3324 >  mcstack.Draw("histo,same");
3325    datahisto->Draw("same,e1");
3326    
3327    TLegend *leg;
3328 <  if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
3329 <  else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
3330 <  else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
3331 <  else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
3332 <  else {
3333 <    std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
3334 <    exit(-1);
3335 <      }
3328 >  if (!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
3329 >    if(is_OF(cut)) leg = allsamples.allbglegend("Opposite flavor",datahisto);
3330 >    else leg = allsamples.allbglegend("Same flavor",datahisto);
3331 >  } else {
3332 >    if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
3333 >    else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
3334 >    else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
3335 >    else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
3336 >    else {
3337 >      std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
3338 >      exit(-1);
3339 >    }
3340 >  }
3341    leg->Draw();
3342    string write_cut = decipher_cut(cut,"");
3343    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3344    writeline1->SetTextSize(0.035);
3345    writeline1->Draw();
3346 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3347 <  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
3346 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3347 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3348    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3349    jzbpad2->cd();
3350    jzbpad2->SetLogy(1);
# Line 1604 | Line 3352 | void draw_pure_jzb_histo(TCut cut,string
3352    datahisto->SetMinimum(0.1);
3353    datahisto->SetMarkerSize(DataMarkerSize);
3354    datahisto->Draw("e1");
3355 <  mcstack.Draw("same");
3355 >  mcstack.Draw("histo,same");
3356    datahisto->Draw("same,e1");
3357    leg->SetHeader("");
3358    leg->Draw();
3359    writeline1->SetTextSize(0.035);
3360    writeline1->Draw();
3361    DrawPrelim();
3362 <  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3363 <  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3362 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3363 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3364    datahisto->Delete();
3365    mcstack.Delete();
3366   }
# Line 1640 | Line 3388 | void produce_stretched_jzb_plots(string
3388    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
3389    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
3390    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
3391 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
3392 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
3391 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
3392 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
3393    
3394    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
3395    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
3396 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
3397 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
3396 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
3397 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
3398    
3399    delete dican;
3400   }
3401    
3402  
3403   void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3404 +  switch_overunderflow(true);
3405    vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3406    
3407    if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
# Line 1665 | Line 3414 | void diboson_plots(string mcjzb, string
3414    
3415    
3416    dout << "Going to increase the cross section for diboson samples ... " << endl;
3417 <  for(int i=0;i<SamplesToBeModified.size();i++) {
3417 >  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3418      float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3419      (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
3420      dout << "     Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
# Line 1677 | Line 3426 | void diboson_plots(string mcjzb, string
3426    dout << "Going to produce JZB plots" << endl;
3427    produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
3428    TCanvas *gloca = new TCanvas("gloca","gloca");
1680  float sigma=123456;
3429    
3430    dout << "Going to produce prediction plots" << endl;
3431 <  do_prediction_plot(mcjzb, gloca, sigma, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3432 <  do_prediction_plot(mcjzb, gloca, sigma, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3431 >  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3432 >  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3433    delete gloca;
3434  
3435    dout << "Going to reset the cross section for diboson samples ... " << endl;
3436 <  for(int i=0;i<SamplesToBeModified.size();i++) {
3436 >  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3437      float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3438      (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
3439      string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
# Line 1693 | Line 3441 | void diboson_plots(string mcjzb, string
3441      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;
3442      
3443    }
3444 + //   switch_overunderflow(false);
3445 + }
3446 +
3447 +
3448 + void draw_normalized_data_vs_data_histo(TCut cut1, TCut cut2, string variable, string legentry1, string legentry2, string savename, TCanvas *can,vector<float> binning) {
3449 +  TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
3450 +  jzbpad->cd();
3451 +  jzbpad->SetLogy(1);
3452 +  string xlabel="JZB [GeV]";
3453 +
3454 +  TH1F *datahisto1 = allsamples.Draw("datahisto1",variable,binning, xlabel, "events",cut1,data,luminosity);
3455 +  datahisto1->SetLineColor(kRed);
3456 +  datahisto1->SetMarkerColor(kRed);
3457 +  TH1F *datahisto2 = allsamples.Draw("datahisto2",variable,binning, xlabel, "events",cut2,data,luminosity);
3458 +  datahisto2->SetLineColor(kBlue);
3459 +  datahisto2->SetMarkerColor(kBlue);
3460 +  
3461 +  datahisto2->SetMarkerSize(DataMarkerSize);
3462 +  datahisto1->DrawNormalized("e1");
3463 +  datahisto2->DrawNormalized("histo,same");
3464 +  datahisto1->DrawNormalized("same,e1");
3465 +  
3466 +  TLegend *leg = make_legend();
3467 +  leg->AddEntry(datahisto1,legentry1.c_str());
3468 +  leg->AddEntry(datahisto2,legentry2.c_str());
3469 +  leg->Draw();
3470 +  
3471 +  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3472    
3473 +  datahisto1->Delete();
3474 +  datahisto2->Delete();
3475   }
3476 +
3477 +
3478   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3479 +  switch_overunderflow(true);
3480    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3481    float max=jzbHigh ;
3482    float min=-120;
# Line 1716 | Line 3497 | void jzb_plots(string mcjzb, string data
3497      draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
3498      draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
3499      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3500 <    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
3501 <    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
3500 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
3501 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
3502 >    draw_normalized_data_vs_data_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,"ee","mm","jzb_ee_vs_mm",can,binning);
3503 >    draw_normalized_data_vs_data_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,"ee","mm","jzb_ee_vs_mm_coarse",can,coarse_binning);
3504 >    draw_normalized_data_vs_data_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,"ee","mm","jzb_ee_vs_mm_coarsest",can,coarsest_binning);
3505 >
3506    }
3507    
3508    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
3509    if ( !PlottingSetup::Approved ) {
3510      draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
3511      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3512 <    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
3513 <    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3512 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
3513 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3514    }
3515    delete can;
3516 +  switch_overunderflow(false);
3517   }
3518  
3519  
# Line 1777 | Line 3563 | void compute_MC_yields(string mcjzb,vect
3563    TCanvas *yica = new TCanvas("yica","yield canvas");
3564    
3565    int nRegions=4;
3566 <  if(!PlottingSetup::RestrictToMassPeak) nRegions=2;
3566 >  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
3567    string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
3568    string posneg[] = {"pos","neg"};
3569    TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
3570  
3571 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
3571 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
3572      TCut jzbMC[]  = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
3573      dout << "_________________________________________________________" << endl;
3574      dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
3575 <    for(int isample=0;isample<(allsamples.collection).size();isample++) {
3575 >    for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
3576        if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << "  &  ";
3577        else dout << "Sample & ";
3578        for(int iregion=0;iregion<nRegions;iregion++) {
# Line 2045 | Line 3831 | void draw_ttbar_and_zjets_shape_for_one_
3831  
3832   void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
3833    int all_leptons=-1;
2048  int electrons_only=0;
2049  int mu_only=1;
2050  int twojetswith50gev=1;
3834    int threejetswith30gev=0;
3835   /*  
3836 +  int twojetswith50gev=1;
3837 +  int electrons_only=0;
3838 +  int mu_only=1;
3839 +
3840    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
3841    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
3842    
# Line 2063 | Line 3850 | void draw_ttbar_and_zjets_shape(string m
3850    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
3851   }
3852  
3853 < void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
2067 <  //first: colorful plots
3853 > float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
3854    TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
3855    cancorr->SetLogz();
3856    cancorr->SetRightMargin(0.13);
3857 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3858 <  TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
3857 >  TCut zptforresponsepresentation(Restrmasscut&&SpecialCut&&passtrig);
3858 >
3859 >  if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
3860    TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
3861 <  (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
3861 >  niceresponseplotd->Sumw2();
3862 >  TH2F* emuResponse = (TH2F*)niceresponseplotd->Clone("emuResponse");
3863 >  vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
3864 >  for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
3865 >    if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
3866 >    if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
3867 >    
3868 >    dout << "   Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
3869 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
3870 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
3871 >  }
3872 >  niceresponseplotd->Add(emuResponse,-1);
3873 >  
3874    niceresponseplotd->SetStats(0);
3875    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
3876    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 2079 | Line 3878 | void find_correction_factors(string &jzb
3878    niceresponseplotd->GetYaxis()->CenterTitle();
3879    niceresponseplotd->Draw("COLZ");
3880    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
3881 +  profd->Rebin(2);
3882    profd->SetMarkerSize(DataMarkerSize);
3883 <  profd->Fit("pol0","","same,e1",30,400);
3883 >  profd->Fit("pol0","","same,e1",100,400);
3884    DrawPrelim();
3885 <  TText* title = write_text(0.5,0.7,"Data");
3885 >  string stitle="Data";
3886 >  if(!Contains(FindKeyword,"Data")) stitle="MC";
3887 >  TText* title = write_text(0.5,0.7,stitle.c_str());
3888    title->SetTextAlign(12);
3889    title->Draw();
3890    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
3891 <  float datacorrection=datapol->GetParameter(0);
3892 <  stringstream dataresstring;
3893 <  dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
3894 <  TText* restitle = write_text(0.5,0.65,dataresstring.str());
3891 >  float correction=datapol->GetParameter(0);
3892 >  stringstream resstring;
3893 >  resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
3894 >  TText* restitle = write_text(0.5,0.65,resstring.str());
3895    restitle->SetTextAlign(12);
3896    restitle->SetTextSize(0.03);
3897    restitle->Draw();
3898 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
3899 <  
3900 <  TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
3901 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
3902 <  niceresponseplotm->SetStats(0);
3903 <  niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
3904 <  niceresponseplotm->GetYaxis()->SetTitle("Response");
3905 <  niceresponseplotm->GetXaxis()->CenterTitle();
2104 <  niceresponseplotm->GetYaxis()->CenterTitle();
2105 <  niceresponseplotm->Draw("COLZ");
2106 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
2107 <  TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
2108 <  profm->SetMarkerSize(DataMarkerSize);
2109 <  profm->Fit("pol0","","same,e1",30,400);
2110 <  DrawMCPrelim();
2111 <  title = write_text(0.5,0.7,"MC simulation");
2112 <  title->SetTextAlign(12);
2113 <  title->Draw();
2114 <  TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
2115 <  float mccorrection=mcpol->GetParameter(0);
2116 <  stringstream mcresstring;
2117 <  mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
2118 <  TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
2119 <  mcrestitle->SetTextAlign(12);
2120 <  mcrestitle->SetTextSize(0.03);
2121 <  mcrestitle->Draw();
2122 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
3898 >  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
3899 >  delete cancorr;
3900 >  delete niceresponseplotd;
3901 >  delete profd;
3902 >  return correction;
3903 > }
3904 >
3905 > void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
3906    
3907 +  dout << "Computing response corrections: " << endl;
3908 +  //Step 1 : Get results
3909 +  float datacorrection=find_one_correction_factor("Data",true,"","Data");
3910 +  float mccorrection=find_one_correction_factor("DY",false,"","MC");
3911 +  
3912 +  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
3913 +  float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
3914 +  
3915 +  float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
3916 +  float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
3917 +  
3918 +  cout << "Corrections : " << endl;
3919 +  cout << "   Data : " << datacorrection << endl;
3920 +  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
3921 +  cout << "   MC : " << mccorrection << endl;
3922 +  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
3923    
3924 <  //Step 2: Getting the result
2126 < //  TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
3924 >  //Step 2: Processing the result and making it into something useful :-)
3925    stringstream jzbvardatas;
3926 <  if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
3927 <  if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
3926 >  jzbvardatas << "(";
3927 >  
3928 >  if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
3929 >  if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
3930 >  
3931 >  if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
3932 >  if(dataMMcorrection<1)  jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
3933 >  
3934 >  float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
3935 >  
3936 >  if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
3937 >  if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
3938 >  
3939 >  jzbvardatas << ")";
3940    jzbvardata=jzbvardatas.str();
3941 +  
3942    stringstream jzbvarmcs;
3943 <  if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
3944 <  if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
3943 >  jzbvarmcs << "(";
3944 >  
3945 >  if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
3946 >  if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
3947 >  
3948 >  if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
3949 >  if(mcMMcorrection<1)  jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
3950 >  
3951 >  float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
3952 >  
3953 >  if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
3954 >  if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
3955 >  
3956 >  jzbvarmcs << ")";
3957    jzbvarmc=jzbvarmcs.str();
3958 +
3959    dout << "JZB Z pt correction summary : " << endl;
3960    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
3961    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
3962 +  
3963   }
3964  
3965 < void pick_up_events(string cut) {
3966 <  dout << "Picking up events with cut " << cut << endl;
2142 <  allsamples.PickUpEvents(cut);
3965 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
3966 >  allsamples.PickUpEvents(cut,filename,QuietMode);
3967   }
3968  
3969 < void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError) {
3969 > void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
3970    dout << "Saving configuration template!" << endl;
3971    ofstream configfile;
3972    configfile.open("../DistributedModelCalculations/last_configuration.C");
# Line 2162 | Line 3986 | void save_template(string mcjzb, string
3986    configfile<<"string datajzb=\"datajzb_ERROR\";\n";
3987    configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
3988    configfile<<"vector<float>jzb_cuts;\n";
3989 +  configfile<<"vector<float>jzb_shape_limit_bins;\n";
3990    configfile<<"float MCPeakError=-999;\n";
3991    configfile<<"float DataPeakError=-999;\n";
3992    configfile<<"}\n\n";
# Line 2171 | Line 3996 | void save_template(string mcjzb, string
3996    configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
3997    configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
3998    configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
3999 <  for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
3999 >  for(int i=0;i<(int)jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4000    configfile<<"\n\n";
4001 <  for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4002 <  for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4003 <  for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4001 >  for(int i=0;i<(int)Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4002 >  for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4003 >  for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4004 >  configfile<<"\n\n";
4005 >  for(int i=0;i<(int)flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4006 >  for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4007 >  for(int i=0;i<(int)flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4008 >  for(int i=0;i<(int)jzb_shape_limit_bins.size();i++) configfile<<"jzb_shape_limit_bins.push_back("<<jzb_shape_limit_bins[i]<<"); // JZB shape bin boundary at " << jzb_shape_limit_bins[i] << "\n";
4009    configfile<<"\n\n";
2180  for(int i=0;i<flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2181  for(int i=0;i<flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2182  for(int i=0;i<flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4010    configfile<<"\n\n";
4011    configfile<<"luminosity="<<luminosity<<";\n";
4012    configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
4013 +  configfile<<"UseSidebandsForcJZB="<<UseSidebandsForcJZB<<";//tells us whether to use the sidebands or not\n";
4014    
4015    configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
4016    
# Line 2205 | Line 4033 | void draw_all_ttbar_histos(TCanvas *can,
4033    float max=histos[0]->GetMaximum();
4034    if(manualmin>=0) min=manualmin;
4035    else {
4036 <    for(int i=1;i<histos.size();i++) {
4036 >    for(int i=1;i<(int)histos.size();i++) {
4037        float curmin=get_nonzero_minimum(histos[i]);
4038        float curmax=histos[i]->GetMaximum();
4039        if(curmin<min) min=curmin;
# Line 2216 | Line 4044 | void draw_all_ttbar_histos(TCanvas *can,
4044    histos[0]->Draw(drawoption.c_str());
4045    stringstream drawopt;
4046    drawopt << drawoption << ",same";
4047 <  for(int i=1;i<histos.size();i++) {
4047 >  for(int i=1;i<(int)histos.size();i++) {
4048      histos[i]->Draw(drawopt.str().c_str());
4049    }
4050   }
# Line 2225 | Line 4053 | void ttbar_sidebands_comparison(string m
4053    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4054    //in the case of the OFF peak analysis, we compare our control region to the real value
4055    TCut weightbackup=cutWeight;
4056 <  cutWeight="1.0";
4057 <  float simulatedlumi = luminosity; //in pb please - adjust to your likings
4056 >  switch_overunderflow(true);
4057 >  
4058 >  bool doPURW=false;
4059    
4060 +  
4061 +  if(!doPURW) {
4062 +    dout << "Not doing PU reweighting for ttbar closure test" << endl;
4063 +    cutWeight="1.0";
4064 +    // Do it without PU re-weighting
4065 +    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4066 +    stringstream resultsNoPU;
4067 +    stringstream noPUdatajzb;
4068 +    stringstream noPUmcjzb;
4069 +    
4070 +    stringstream mcjzbnoPU;
4071 +    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
4072 +    mcjzb = noPUmcjzb.str();
4073 +  }
4074  
4075 <  TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4076 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4075 >      
4076 >  float simulatedlumi = luminosity; //in pb please - adjust to your likings
4077 >
4078 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4079 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4080    TH1F *TSem;
4081    TH1F *nTSem;
4082 <  TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4083 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4082 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4083 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4084    TH1F *TSeemm;
4085    TH1F *nTSeemm;
4086    
4087 <  if(PlottingSetup::RestrictToMassPeak) {
4088 <    TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4089 <    nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4090 <    TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4091 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4087 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4088 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4089 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4090 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4091 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4092    }
4093  
4094    TCanvas *tcan = new TCanvas("tcan","tcan");
2249  
4095    tcan->SetLogy(1);
4096    
4097    TZeemm->SetLineColor(kBlack);
# Line 2255 | Line 4100 | void ttbar_sidebands_comparison(string m
4100    TZem->SetMarkerColor(kRed);
4101  
4102  
4103 <  if(PlottingSetup::RestrictToMassPeak) {
4103 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4104          TSem->SetLineColor(TColor::GetColor("#00A616"));
4105          TSeemm->SetLineColor(kMagenta+2);
4106          TSem->SetMarkerColor(TColor::GetColor("#00A616"));
# Line 2265 | Line 4110 | void ttbar_sidebands_comparison(string m
4110    }
4111    
4112    vector<TH1F*> histos;
4113 +  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4114 +  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4115    histos.push_back(TZem);
4116    histos.push_back(TZeemm);
4117 <  if(PlottingSetup::RestrictToMassPeak) {
4117 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4118 >    TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4119 >    TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4120      histos.push_back(TSem);
4121      histos.push_back(TSeemm);
4122    }
4123 <  draw_all_ttbar_histos(tcan,histos,"histo",0.04);
4123 >  draw_all_ttbar_histos(tcan,histos,"histo",8);
4124    
4125    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4126    leg->AddEntry(TZeemm,"SFZP","l");
4127    leg->AddEntry(TZem,"OFZP","l");
4128 <  if(PlottingSetup::RestrictToMassPeak) {
4128 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4129      leg->AddEntry(TSeemm,"SFSB","l");
4130      leg->AddEntry(TSem,"OFSB","l");
4131    }
4132    leg->Draw("same");
4133    DrawMCPrelim(simulatedlumi);
4134    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
4135 < cout << __LINE__ << endl;  
4135 >  
4136    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2288 cout << __LINE__ << endl;  
4137    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2290 cout << __LINE__ << endl;  
4138    TH1F *TSeemmcopy;
4139    TH1F *TSemcopy;
4140 <  if(PlottingSetup::RestrictToMassPeak) {
4140 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4141      TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
4142      TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
4143    }
4144  
4145    TZem->Divide(TZeemm);
4146    TZem->SetMarkerStyle(21);
4147 <  if(PlottingSetup::RestrictToMassPeak) {
4147 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4148      TSem->Divide(TZeemm);
4149      TSeemm->Divide(TZeemm);
4150      TSem->SetMarkerStyle(24);
4151      TSeemm->SetMarkerStyle(32);
4152 < }
4152 >  }
4153  
4154    tcan->SetLogy(0);
4155    TZem->GetYaxis()->SetRangeUser(0,2.5);
4156    TZem->GetYaxis()->SetTitle("ratio");
4157    TZem->Draw();
4158 <  if(PlottingSetup::RestrictToMassPeak) {
4158 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4159      TSem->Draw("same");
4160      TSeemm->Draw("same");
4161    }
4162    
4163 <  float linepos=0.25;
4164 <  if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
4165 <  if(!PlottingSetup::RestrictToMassPeak) linepos=0.1; //sys uncertainty for iJZB
4163 >  float linepos=emuncertONPEAK;
4164 >  if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
4165 >  
4166    TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
4167    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4168    TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
# Line 2338 | Line 4185 | cout << __LINE__ << endl;
4185    
4186    TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
4187    leg2->AddEntry(TZem,"OFZP / SFZP","ple");
4188 <  if(PlottingSetup::RestrictToMassPeak) {
4188 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4189      leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
4190      leg2->AddEntry(TSem,"OFSB / SFZP","ple");
4191    }
# Line 2351 | Line 4198 | cout << __LINE__ << endl;
4198    DrawMCPrelim(simulatedlumi);
4199    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4200    
4201 +  
4202 +  if (0) { // Turn this off: we don't need this
4203  
4204 < ///-------------- second part: only look at the quantity we actually care about!
4205 <  TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
4206 <  TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
4207 <  rightsfzp->Add(leftsfzp,-1);
4208 <  TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
4209 <  TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
4210 <  rightofzp->Add(leftofzp,-1);
4211 <  TH1F *leftofsb;
4212 <  TH1F *rightofsb;
4213 <  TH1F *leftsfsb;
4214 <  TH1F *rightsfsb;
4215 <  if(PlottingSetup::RestrictToMassPeak) {
4216 <        leftofsb  = (TH1F*)nTSem->Clone("leftofsb");
4217 <        rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
4218 <        rightofsb->Add(leftofsb,-1);
4219 <        leftsfsb  = (TH1F*)nTSeemm->Clone("leftsfsb");
4220 <        rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
4221 <        rightsfsb->Add(leftsfsb,-1);
4222 <  }
4204 >    ///-------------- second part: only look at the quantity we actually care about!
4205 >    TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
4206 >    TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
4207 >    rightsfzp->Add(leftsfzp,-1);
4208 >    TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
4209 >    TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
4210 >    rightofzp->Add(leftofzp,-1);
4211 >    TH1F *leftofsb;
4212 >    TH1F *rightofsb;
4213 >    TH1F *leftsfsb;
4214 >    TH1F *rightsfsb;
4215 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4216 >      leftofsb  = (TH1F*)nTSem->Clone("leftofsb");
4217 >      rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
4218 >      rightofsb->Add(leftofsb,-1);
4219 >      leftsfsb  = (TH1F*)nTSeemm->Clone("leftsfsb");
4220 >      rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
4221 >      rightsfsb->Add(leftsfsb,-1);
4222 >    }
4223  
4224 <  tcan->SetLogy(1);
4225 <  rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
4226 <  rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
4227 <  rightsfzp->Draw("histo");
4228 <  rightofzp->Draw("histo,same");
4229 <  if(PlottingSetup::RestrictToMassPeak) {
4230 <    rightofsb->Draw("histo,same");
4231 <    rightsfsb->Draw("histo,same");
4232 <  }
4233 <  DrawMCPrelim(simulatedlumi);
4224 >    tcan->SetLogy(1);
4225 >    rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
4226 >    rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
4227 >    rightsfzp->Draw("histo");
4228 >    rightofzp->Draw("histo,same");
4229 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4230 >      rightofsb->Draw("histo,same");
4231 >      rightsfsb->Draw("histo,same");
4232 >    }
4233 >    DrawMCPrelim(simulatedlumi);
4234  
4235 <  TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
4236 <  legA->AddEntry(rightsfzp,"SFZP","l");
4237 <  legA->AddEntry(rightofzp,"OFZP","l");
4238 <  if(PlottingSetup::RestrictToMassPeak) {
4239 <    legA->AddEntry(rightofsb,"SFSB","l");
4240 <    legA->AddEntry(rightsfsb,"OFSB","l");
4241 <  }
4242 <  legA->Draw();
4235 >    TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
4236 >    legA->AddEntry(rightsfzp,"SFZP","l");
4237 >    legA->AddEntry(rightofzp,"OFZP","l");
4238 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4239 >      legA->AddEntry(rightofsb,"SFSB","l");
4240 >      legA->AddEntry(rightsfsb,"OFSB","l");
4241 >    }
4242 >    legA->Draw();
4243  
4244 <  CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
4244 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
4245  
4246 <  tcan->SetLogy(0);
4247 <  rightofzp->Divide(rightsfzp);
4248 <  rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
4249 <  rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
4250 <  rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
4251 <  rightofzp->Draw();
4252 <  if(PlottingSetup::RestrictToMassPeak) {
4253 <    rightofsb->Divide(rightsfzp);
4254 <    rightsfsb->Divide(rightsfzp);
4255 <    rightofsb->Draw("same");
4256 <    rightsfsb->Draw("same");
4257 <  }
4246 >    tcan->SetLogy(0);
4247 >    rightofzp->Divide(rightsfzp);
4248 >    rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
4249 >    rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
4250 >    rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
4251 >    rightofzp->Draw();
4252 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4253 >      rightofsb->Divide(rightsfzp);
4254 >      rightsfsb->Divide(rightsfzp);
4255 >      rightofsb->Draw("same");
4256 >      rightsfsb->Draw("same");
4257 >    }
4258  
4259 <  TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
4260 <  TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
4261 <  TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
4259 >    TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
4260 >    TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
4261 >    TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
4262 >  
4263 >    top2->SetLineColor(kBlue);top2->SetLineStyle(2);
4264 >    bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
4265 >    center2->SetLineColor(kBlue);
4266 >  
4267 >    top2->Draw("same");
4268 >    center2->Draw("same");
4269 >    bottom2->Draw("same");
4270 >
4271 >    rightofzp->SetMarkerStyle(21);
4272 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4273 >      rightofsb->SetMarkerStyle(24);
4274 >      rightsfsb->SetMarkerStyle(32);
4275 >    }
4276 >
4277 >    TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
4278 >    leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
4279 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4280 >      leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
4281 >      leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
4282 >    }
4283 >    leg3->AddEntry(bottom,"syst. envelope","l");
4284 >    leg3->SetX1(0.25);leg3->SetX2(0.6);
4285 >    leg3->SetY1(0.65);
4286    
4287 <  top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2415 <  bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2416 <  center2->SetLineColor(kBlue);
4287 >    leg3->Draw("same");
4288    
4289 <  top2->Draw("same");
4290 <  center2->Draw("same");
2420 <  bottom2->Draw("same");
4289 >    DrawMCPrelim(simulatedlumi);
4290 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
4291  
2422  rightofzp->SetMarkerStyle(21);
2423  if(PlottingSetup::RestrictToMassPeak) {
2424    rightofsb->SetMarkerStyle(24);
2425    rightsfsb->SetMarkerStyle(32);
2426  }
2427
2428  TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2429  leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2430  if(PlottingSetup::RestrictToMassPeak) {
2431        leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2432        leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
4292    }
2434  leg3->AddEntry(bottom,"syst. envelope","l");
2435  leg3->SetX1(0.25);leg3->SetX2(0.6);
2436  leg3->SetY1(0.65);
2437  
2438  leg3->Draw("same");
2439  
2440  DrawMCPrelim(simulatedlumi);
2441  CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
4293  
4294    delete TZem;
4295    delete nTZem;
4296    delete TZeemm;
4297    delete nTZeemm;
4298 <  if(PlottingSetup::RestrictToMassPeak) {
4298 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4299          delete TSem;
4300          delete nTSem;
4301          delete TSeemm;
# Line 2453 | Line 4304 | cout << __LINE__ << endl;
4304  
4305    delete tcan;
4306    cutWeight=weightbackup;
4307 +  switch_overunderflow(false);
4308   }
4309  
4310   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
4311    vector<float> nicer_binning;
4312 <  nicer_binning.push_back(-125);
4312 >  
4313 > /*  nicer_binning.push_back(-400);
4314 >  nicer_binning.push_back(-250);
4315 >  nicer_binning.push_back(-200);
4316 >  nicer_binning.push_back(-150);
4317 >  nicer_binning.push_back(-100);
4318 >  nicer_binning.push_back(-50);
4319 >  nicer_binning.push_back(-20);
4320 >  
4321 >  nicer_binning.push_back(0);
4322 >  nicer_binning.push_back(20);
4323 >  nicer_binning.push_back(50);
4324 >  nicer_binning.push_back(100);
4325 >  nicer_binning.push_back(150);
4326 >  nicer_binning.push_back(200);
4327 >  nicer_binning.push_back(250);
4328 >  nicer_binning.push_back(400);*/
4329 >  
4330    nicer_binning.push_back(-100);
2462  nicer_binning.push_back(-75);
4331    nicer_binning.push_back(-50);
4332    nicer_binning.push_back(-25);
4333    nicer_binning.push_back(0);
# Line 2469 | Line 4337 | void ttbar_sidebands_comparison(string m
4337    nicer_binning.push_back(100);
4338    nicer_binning.push_back(125);
4339    nicer_binning.push_back(150);
4340 <  nicer_binning.push_back(175);
4340 >  //nicer_binning.push_back(175);
4341    nicer_binning.push_back(200);
4342 <  nicer_binning.push_back(230);
4343 <  nicer_binning.push_back(280);
4344 <  nicer_binning.push_back(400);
4342 > //  nicer_binning.push_back(250);
4343 > //  nicer_binning.push_back(300);
4344 > //  nicer_binning.push_back(400);
4345 >  
4346    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4347   }
4348  
4349  
4350 < void zjets_prediction_comparison() {
4351 <  // Do it without PU re-weighting
4352 <  float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4353 <  stringstream resultsNoPU;
4354 <
4355 <  stringstream mcjzbnoPU;
4356 <  find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
4357 <  if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
4358 <  else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
4350 > void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4351 >  cout << "****************************************************************************************************************************************************************" << endl;
4352 >  TCanvas *zcan = new TCanvas("zcan","zcan");  
4353 > //  zcan->SetLogy(1);
4354 >  TCut weightbackup=cutWeight;
4355 >  
4356 >  bool UsePURW=true;
4357 >  
4358 >  
4359 >  string mcjzb;
4360 >  if(UsePURW) {
4361 >    mcjzb=mcjzbWithPUa;
4362 >    cout << "Using PURW peak positions" << endl;
4363 >  } else {
4364 >    // Do it without PU re-weighting
4365 >    cutWeight="1.0";
4366 >    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4367 >    stringstream resultsNoPU;
4368 >    stringstream noPUdatajzb;
4369 >    stringstream noPUmcjzb;
4370 >    
4371 >    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
4372 >    dout << "The peak corrected JZB expression for MC without pileup is : " <<  noPUmcjzb.str() << endl;
4373 >    
4374 >    mcjzb = noPUmcjzb.str();
4375 >    
4376 >  }
4377  
4378 <  string mcjzb = mcjzbnoPU.str();
4379 <  dout << "The peak corrected JZB expression for MC without pileup is : " <<  mcjzb << endl;
4378 >  
4379 >  vector<float> binning;
4380 >  binning.push_back(0);
4381 >  binning.push_back(10);
4382 >  binning.push_back(20);
4383 >  binning.push_back(40);
4384 >  binning.push_back(60);
4385 > //   binning.push_back(50);
4386 > //   binning.push_back(60);
4387 > //   binning.push_back(70);
4388 > //   binning.push_back(80);
4389 > //   binning.push_back(90);
4390 >  binning.push_back(100);
4391  
2494  TCut weightbackup=cutWeight;
2495  cutWeight="1.0";
2496  float sbg_min=0.;
2497  float sbg_max=100.;
2498  int sbg_nbins=5;
4392    float simulatedlumi = luminosity;//in pb please - adjust to your likings
4393    
4394    TCut kPos((mcjzb+">0").c_str());
4395    TCut kNeg((mcjzb+"<0").c_str());
4396    string var( "abs("+mcjzb+")" );
4397 +  
4398 +  TCut notTau("abs(genMID1)!=15");
4399 +  TCut ee_mm_tautau("mll>0");
4400 +  
4401  
4402 <  TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
4403 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
4404 <                                  kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2508 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2509 <                                  kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
4402 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4403 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4404 >  
4405    hJZBpos->SetLineColor(kBlack);
4406    hJZBneg->SetLineColor(kRed);
4407    
4408 <  Int_t nbins = 5;
2514 <  Float_t xmax = 100.;
2515 <
2516 <  
2517 <  TCanvas *zcan = new TCanvas("zcan","zcan");  
2518 <  zcan->SetLogy(1);
2519 <
4408 >  hJZBpos->SetMinimum(1.0);
4409    hJZBpos->Draw("e1");
4410    hJZBneg->Draw("same,hist");
4411    hJZBpos->Draw("same,e1"); // So it's on top...
4412    
4413 <  TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
4413 >  TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
4414    leg->AddEntry(hJZBpos,"Observed","pe");
4415    leg->AddEntry(hJZBneg,"Predicted","l");
4416    leg->Draw("same");
4417    DrawMCPrelim(simulatedlumi);
4418 <  CompleteSave(zcan,"Systematics/zjets_prediction");
4418 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
4419    
4420    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
4421    hratio->Divide(hJZBneg);
4422    
4423 <  zcan->SetLogy(0);
4423 >  for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
4424 >    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4425 >  }
4426 >  
4427 > //  zcan->SetLogy(0);
4428    hratio->GetYaxis()->SetRangeUser(0,2.5);
4429    hratio->GetYaxis()->SetTitle("Observed/Predicted");
4430    hratio->Draw("e1");
4431    
4432 <  TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
4433 <  TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
4434 <  TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
4432 >  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
4433 >  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4434 >  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
4435    
4436  
4437    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 2549 | Line 4442 | void zjets_prediction_comparison() {
4442    center->Draw("same");
4443    bottom->Draw("same");
4444    
4445 <  TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
4445 >  TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4446    leg2->AddEntry(hratio,"obs / pred","pe");
4447    leg2->AddEntry(bottom,"syst. envelope","l");
4448    leg2->Draw("same");
4449    DrawMCPrelim(simulatedlumi);
4450 <  CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
4450 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4451 >  
4452 >  TCut reducedNJets(cutnJets);
4453 >  
4454 >  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4455 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4456 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4457 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4458 >
4459 >  TH1F *RcorrJZBSBem;
4460 >  TH1F *LcorrJZBSBem;
4461 >  TH1F *RcorrJZBSBeemm;
4462 >  TH1F *LcorrJZBSBeemm;
4463 >
4464 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4465 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4466 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4467 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4468 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4469 >  }
4470 >  
4471 >  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4472 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4473 >    Bpred->Add(RcorrJZBem,1.0/3.);
4474 >    Bpred->Add(LcorrJZBem,-1.0/3.);
4475 >    Bpred->Add(RcorrJZBSBem,1.0/3.);
4476 >    Bpred->Add(LcorrJZBSBem,-1.0/3.);
4477 >    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
4478 >    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
4479 >  } else {
4480 >    Bpred->Add(RcorrJZBem,1.0);
4481 >    Bpred->Add(LcorrJZBem,-1.0);
4482 >  }
4483 >  
4484 >  Bpred->SetLineColor(kRed);
4485 >
4486 >  TAUhJZBpos->SetLineColor(kBlack);
4487 >  Bpred->SetLineColor(kRed);
4488 >  
4489 >  TAUhJZBpos->SetMinimum(1.0);
4490 >  TAUhJZBpos->Draw("e1");
4491 >  Bpred->Draw("same,hist");
4492 >  TAUhJZBpos->Draw("same,e1");
4493 >  
4494 >  TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
4495 >  TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
4496 >  TAUleg->AddEntry(Bpred,"Predicted","l");
4497 >  TAUleg->Draw("same");
4498 >  DrawMCPrelim(simulatedlumi);
4499 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
4500 >  
4501 >  TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
4502 >  TAUhratio->Divide(Bpred);
4503 >  
4504 >  for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
4505 >    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
4506 >  }
4507 >  
4508 >  zcan->SetLogy(0);
4509 >  TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
4510 >  TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
4511 >  TAUhratio->Draw("e1");
4512 >  
4513 >  top->Draw("same");
4514 >  center->Draw("same");
4515 >  bottom->Draw("same");
4516 >  
4517 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4518 >  TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
4519 >  TAUleg2->AddEntry(bottom,"syst. envelope","l");
4520 >  TAUleg2->Draw("same");
4521 >  DrawMCPrelim(simulatedlumi);
4522 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
4523 >  
4524 >  delete Bpred;
4525 >  delete TAUhJZBpos;
4526 >  delete LcorrJZBeemm;
4527 >  delete RcorrJZBem;
4528 >  delete LcorrJZBem;
4529 >  delete hJZBpos;
4530 >  delete hJZBneg;
4531 >  
4532 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4533 >    delete RcorrJZBSBem;
4534 >    delete LcorrJZBSBem;
4535 >    delete RcorrJZBSBeemm;
4536 >    delete LcorrJZBSBeemm;
4537 >  }
4538 >  
4539    
4540    delete zcan;
4541    cutWeight=weightbackup;
2561
4542   }
4543  
4544  
4545 <
4545 > void zjets_prediction_comparison(string mcjzbWithPUa) {
4546 >  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
4547 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
4548 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
4549 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
4550 > }
4551 >  
4552   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
4553    tout << endl << endl;
4554    stringstream bordercut;
# Line 2580 | Line 4566 | void sideband_assessment(string datajzb,
4566    tout << "\\begin{tabular}{l|cc}" << endl;
4567    tout << "\\hline" << endl;
4568    tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
4569 <  tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
4569 >  tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
4570    tout << "\\end{tabular}" << endl;
4571    tout << "\\end{center}" << endl;
4572    tout << "\\end{table}" << endl;
# Line 2598 | Line 4584 | void make_table(samplecollection &coll,
4584    
4585    TCanvas *cannie = new TCanvas("cannie","cannie");
4586    
4587 <  for(int icut=0;icut<jzb_cuts.size();icut++) {
4587 >  for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
4588      float currcut=jzb_cuts[icut];
4589      int nbins=1;float low=currcut;
4590      vector<int> mysample;
# Line 2613 | Line 4599 | void make_table(samplecollection &coll,
4599      TH1F *RcorrJZBSBeemm;
4600      TH1F *LcorrJZBSBeemm;
4601      
4602 <    if(PlottingSetup::RestrictToMassPeak) {
4602 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4603        RcorrJZBSBem   = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4604        LcorrJZBSBem   = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4605        RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
# Line 2621 | Line 4607 | void make_table(samplecollection &coll,
4607      }
4608      
4609      TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4610 <    if(PlottingSetup::RestrictToMassPeak) {
4610 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4611        Bpred->Add(RcorrJZBem,1.0/3.);
4612        Bpred->Add(LcorrJZBem,-1.0/3.);
4613        Bpred->Add(RcorrJZBSBem,1.0/3.);
# Line 2657 | Line 4643 | void make_table(samplecollection &coll,
4643    //prediction part
4644    if(is_data) cout << "Data prediction & ";
4645    if(subselection!="none") cout << subselection << " prediction &";
4646 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
4646 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
4647    
4648    cout << endl;
4649    //observation part
4650    if(is_data) cout << "Data observation & ";
4651    if(subselection!="none") cout << subselection << " observation &";
4652 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
4652 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
4653    cout << endl;
4654    cout << "_________________________________________________________________" << endl;
4655    delete cannie;
4656   }
4657  
4658   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4659 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
4660 +  assert(0);
4661    /*we want a table like this:
4662      __________________     50   |   100  | ...
4663      | Data prediction |  a vs b | a vs b | ...
# Line 2724 | Line 4712 | void JZBSelEff(string mcjzb, TTree* even
4712    leg->SetLineColor(kBlack);
4713    leg->SetTextFont(62);
4714  
4715 <  for ( int icut=0; icut<jzb_bins.size(); ++icut ) {
4715 >  for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
4716  
4717      ostringstream selection;
4718      selection << mcjzb << ">" << jzb_bins[icut];
# Line 2776 | Line 4764 | void JZBSelEff(string mcjzb, TTree* even
4764   // Calls the above function for each signal sample
4765   void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
4766   {  
4767 <  for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
4767 >  for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
4768      dout << "JZB selection efficiency curve: " << std::endl;
4769      JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
4770    }
# Line 2819 | Line 4807 | void qcd_plots(string datajzb, string mc
4807    TH1F *RcorrJZBSBeemm;
4808    TH1F *LcorrJZBSBeemm;
4809    
4810 <  TH1F *RcorrJZBeemmNoS;
4810 > //  TH1F *RcorrJZBeemmNoS;
4811  
4812      //these are for the ratio
4813    TH1F *JRcorrJZBeemm   = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
# Line 2832 | Line 4820 | void qcd_plots(string datajzb, string mc
4820    TH1F *JRcorrJZBSBeemm;
4821    TH1F *JLcorrJZBSBeemm;
4822    
4823 <  if(PlottingSetup::RestrictToMassPeak) {
4823 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4824      RcorrJZBSBem   = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4825      LcorrJZBSBem   = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4826      RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
# Line 2853 | Line 4841 | void qcd_plots(string datajzb, string mc
4841      
4842    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4843    TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
4844 <  if(PlottingSetup::RestrictToMassPeak) {
4844 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4845      Bpred->Add(RcorrJZBem,1.0/3.);
4846      Bpred->Add(LcorrJZBem,-1.0/3.);
4847      Bpred->Add(RcorrJZBSBem,1.0/3.);
# Line 2903 | Line 4891 | void qcd_plots(string datajzb, string mc
4891    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
4892    string ytitle("ratio");
4893    if ( use_data==1 ) ytitle = "data/pred";
4894 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,use_data!=1,ytitle);
4894 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4895 >  delete kinpad;
4896    
4897    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
4898    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 2923 | Line 4912 | void qcd_plots(string datajzb, string mc
4912    dout << "______________________________________________" << endl;
4913    dout << "How QCD shows up in the different regions: " << endl;
4914    dout << "OSSF: " << endl;
4915 <  if(PlottingSetup::RestrictToMassPeak) {
4915 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4916      dout << "     Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
4917      dout << "     sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
4918    } else {
4919      dout << "     " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
4920    }
4921    dout << "OSOF: " << endl;
4922 <  if(PlottingSetup::RestrictToMassPeak) {
4922 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4923      dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
4924      dout << "     sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
4925    } else {
4926      dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
4927    }
4928    dout << "Therefore: " << endl;
4929 <  if(PlottingSetup::RestrictToMassPeak) {
4929 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4930      dout << "    Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
4931      dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
4932      dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
# Line 2950 | Line 4939 | void qcd_plots(string datajzb, string mc
4939    dout << "    Observation increases by : " << RcorrJZBeemm->Integral() << endl;
4940    
4941    dout << endl;
4942 <  for(int i=0;i<bins.size();i++) {
4942 >  for(int i=0;i<(int)bins.size();i++) {
4943      dout << " JZB > " << bins[i] << " : " << endl;
4944      dout << "    Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
4945 <    if(PlottingSetup::RestrictToMassPeak) {
4945 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4946          dout << "    Prediction increases by : " << LcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + (1.0/3)*(RcorrJZBSBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBSBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBSBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBSBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX())) << endl;
4947      } else {
4948          dout << "    Prediction increases by : " << LcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) + RcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) - LcorrJZBem->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
# Line 2967 | Line 4956 | void qcd_plots(string datajzb, string mc
4956    if(LcorrJZBem) delete LcorrJZBem;
4957    if(RcorrJZBeemm) delete RcorrJZBeemm;
4958    if(LcorrJZBeemm) delete LcorrJZBeemm;
4959 <  if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBem) delete RcorrJZBSBem;
4960 <  if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBem) delete LcorrJZBSBem;
4961 <  if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
4962 <  if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
4959 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBem) delete RcorrJZBSBem;
4960 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBem) delete LcorrJZBSBem;
4961 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
4962 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
4963   }
4964  
4965   void check_ptsanity() {
# Line 2998 | Line 4987 | void check_ptsanity() {
4987    leg->SetY2(1.0);
4988    
4989    
4990 <  for(int isample=0;isample<allsamples.collection.size();isample++) {
4990 >  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
4991      string nowname=(allsamples.collection)[isample].filename;
4992      cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
4993      individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
# Line 3022 | Line 5011 | void check_ptsanity() {
5011    ptsancan->cd(2);
5012    fpt2->Draw();
5013  
5014 <  for(int isample=0;isample<allsamples.collection.size();isample++) {
5014 >  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
5015      ptsancan->cd(1);
5016      individualpt1histos[isample]->DrawNormalized("same,histo");
5017      ptsancan->cd(2);
# Line 3038 | Line 5027 | void check_ptsanity() {
5027   void do_mlls_plot(string mcjzb) {
5028    cout << "At this point we'd plot the mll distribution" << endl;
5029    TCanvas *sigcan = new TCanvas("sigcan","sigcan");
5030 <  for(int isig=0;isig<(signalsamples.collection).size();isig++) {
5030 >  for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
5031      if(!(signalsamples.collection)[isig].events) continue;
5032      string nowname=(signalsamples.collection)[isig].filename;
5033      TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
# Line 3067 | Line 5056 | void do_mlls_plot(string mcjzb) {
5056    }
5057   }
5058  
5059 < void met_vs_jzb_plots() {
5059 > void met_vs_jzb_plots(string datajzb, string mcjzb) {
5060    
5061    TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
5062    canmetjzb->SetRightMargin(0.16);
# Line 3076 | Line 5065 | void met_vs_jzb_plots() {
5065    findme.push_back("DY");
5066    findme.push_back("TTJets");
5067    findme.push_back("LM");
5068 <  
5069 <  for(int ifind=0;ifind<findme.size();ifind++) {
5068 >  /*
5069 >  for(int ifind=0;ifind<(int)findme.size();ifind++) {
5070      vector<int> selsamples = allsamples.FindSample(findme[ifind]);
5071      TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
5072 <    for(int isel=0;isel<selsamples.size();isel++) {
5073 <      cout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
5074 <      allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF);
5072 >    for(int isel=0;isel<(int)selsamples.size();isel++) {
5073 >      dout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
5074 >      allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF&&cutnJets);
5075      }
5076      metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
5077      metvsjzb->SetStats(0);
# Line 3096 | Line 5085 | void met_vs_jzb_plots() {
5085      title->Draw();
5086      CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
5087    }
5088 +  */
5089 +  
5090 +  dout << "About to produce MET plot for DY split up by JZB" << endl;
5091 +  
5092 +  int nbins=14;
5093 +  float low=0;
5094 +  float high=140;
5095 +  
5096 +  stringstream sLEFT;
5097 +  sLEFT << "((" << mcjzb << ")<0)";
5098 +  TCut LEFT(sLEFT.str().c_str());
5099 +  stringstream sRIGHT;
5100 +  sRIGHT << "((" << mcjzb << ")>0)";
5101 +  TCut RIGHT(sRIGHT.str().c_str());
5102 +  
5103 +  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5104 +  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5105 +  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5106 +  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5107 +  
5108 +  
5109 +  TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
5110 +  Bpred->Add(metleftO,-1);
5111 +  Bpred->Add(metrightO);
5112 +  TH1F *obs = (TH1F*)metright->Clone("obs");
5113 +  
5114 +  metleft->Add(metleftO,-1);
5115 +  metright->Add(metrightO,-1);
5116 +  
5117 +  metleft->SetLineColor(kRed);
5118 +  metright->SetLineColor(kBlack);
5119 +  TPad *metpad = new TPad("metpad","metpad",0,0,1,1);
5120 +  metpad->cd();
5121 +  metpad->SetLogy(1);
5122 +  metleft->Draw("histo");
5123 +  metright->Draw("same");
5124 +  TLegend *lg = make_legend();
5125 +  lg->SetX1(0.5);
5126 +  lg->SetY1(0.7);
5127 +  lg->AddEntry(metright,"JZB>0 (OSOF corrected)","P");
5128 +  lg->AddEntry(metleft,"JZB<0 (OSOF corrected)","L");
5129 +  lg->SetHeader("DY");
5130 +  
5131 +  lg->Draw();
5132 +  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5133 +  
5134 +  TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5135 +  metpad3->cd();
5136 +  metpad3->SetLogy(1);
5137 +  Bpred->SetLineColor(kRed);
5138 +  Bpred->Draw("histo");
5139 +  obs->SetLineColor(kBlack);
5140 +  obs->Draw("same");
5141 +  TLegend *lg2 = make_legend();
5142 +  lg2->SetX1(0.5);
5143 +  lg2->SetY1(0.7);
5144 +  lg2->AddEntry(obs,"observed","P");
5145 +  lg2->AddEntry(Bpred,"predicted","L");
5146 +  lg2->SetHeader("DY");
5147 +
5148 +  lg2->Draw();
5149 +  
5150 +  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5151 +  
5152 +  TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5153 +  metpad2->cd();
5154 +  metpad2->SetLogy(1);
5155 +  
5156 +  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5157 +  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5158 +  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5159 +  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5160 +  
5161 +  metlefta->Add(metleftOa,-1);
5162 +  metrighta->Add(metrightOa,-1);
5163 +  
5164 +  metlefta->SetLineColor(kRed);
5165 +  metpad2->cd();
5166 +  metlefta->Draw("histo");
5167 +  metrighta->Draw("same");
5168 +  lg->Draw();
5169 +  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5170 +  
5171 +  delete Bpred;
5172 +  delete obs;
5173 +  
5174 +  float newhigh=300;
5175 +  int newNBins=30;
5176 +  
5177 +  TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5178 +  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5179 +  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5180 +  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5181 +  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5182 +  
5183 +  TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5184 +  aBpred->Add(AmetleftO,-1);
5185 +  aBpred->Add(AmetrightO);
5186 +  aBpred->SetLineColor(kRed);
5187 +  
5188 +  TH1F *aobs = (TH1F*)Ametright->Clone("aobs");
5189 +  metpad4->cd();
5190 +  metpad4->SetLogy(1);
5191 +  aobs->Draw();
5192 +  aBpred->Draw("histo,same");
5193 +  aobs->Draw("same");
5194 +  lg->SetHeader("All MC");
5195 +  lg->Draw();
5196 +  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5197 +  
5198 +  
5199 +  delete lg;
5200 +  delete canmetjzb;
5201 +  delete metleft;
5202 +  delete metleftO;
5203 +  delete metright;
5204 +  delete metrightO;
5205   }
5206 +
5207 +
5208 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5209 +  
5210 +  if(PlottingSetup::RestrictToMassPeak) {
5211 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5212 +    assert(!PlottingSetup::RestrictToMassPeak);
5213 +  }
5214 +  
5215 +  vector<float> binning;
5216 +  
5217 +  binning.push_back(-200);
5218 +  binning.push_back(-150);
5219 +  binning.push_back(-125);
5220 +  binning.push_back(-100);
5221 +  binning.push_back(-75);
5222 +  binning.push_back(-50);
5223 +  binning.push_back(-25);
5224 +  binning.push_back(0);
5225 +  binning.push_back(25);
5226 +  binning.push_back(50);
5227 +  binning.push_back(75);
5228 +  binning.push_back(100);
5229 +  binning.push_back(125);
5230 +  binning.push_back(150);
5231 +  binning.push_back(200);
5232 +  
5233 +  switch_overunderflow(true);
5234 +  
5235 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5236 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5237 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5238 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5239 +  
5240 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5241 +  tcan->SetLogy(1);
5242 +  
5243 +  TZeemm->SetLineColor(kBlack);
5244 +  TZem->SetLineColor(kRed);
5245 +  TZeemm->SetMarkerColor(kBlack);
5246 +  TZem->SetMarkerColor(kRed);
5247 +  
5248 +  vector<TH1F*> histos;
5249 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5250 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5251 +  histos.push_back(TZem);
5252 +  histos.push_back(TZeemm);
5253 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5254 +  
5255 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5256 +  leg->AddEntry(TZeemm,"SFZP","l");
5257 +  leg->AddEntry(TZem,"OFZP","l");
5258 +  leg->Draw("same");
5259 +  DrawMCPrelim();
5260 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5261 +  
5262 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5263 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5264 +  TH1F *TSeemmcopy;
5265 +  TH1F *TSemcopy;
5266 +  
5267 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5268 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5269 +  
5270 +  vector<float> posbinning;
5271 +  for(unsigned int i=0;i<binning.size();i++) {
5272 +    if(binning[i]<0) continue;
5273 +    posbinning.push_back(binning[i]);
5274 +  }
5275 +  
5276 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5277 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5278 +  
5279 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5280 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5281 +    if(TZem->GetBinCenter(i)<0) {
5282 +      //we're on the left: subtract em!
5283 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5284 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5285 +      //we're on the left: add eemm!
5286 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5287 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5288 +    } else {
5289 +      //we're on the right: add em!
5290 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5291 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5292 +      //we're on the left: add eemm!
5293 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5294 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5295 +    }
5296 +  }
5297 +  
5298 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5299 +  ratio2->Divide(obs2);
5300 +
5301 +  TZem->Divide(TZeemm);
5302 +  TZem->SetMarkerStyle(21);
5303 +
5304 +  TZem->SetTitle("OF / SF");
5305 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5306 +  
5307 +  tcan->SetLogy(0);
5308 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
5309 +  TZem->GetYaxis()->SetTitle("ratio");
5310 +  TZem->Draw();
5311 +  
5312 +  float linepos=emuncertOFFPEAK;
5313 +  
5314 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5315 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5316 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5317 +  
5318 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
5319 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5320 +  center->SetLineColor(kBlue);
5321 +  
5322 +  top->Draw("same");
5323 +  center->Draw("same");
5324 +  bottom->Draw("same");
5325 +  
5326 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
5327 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
5328 +  leg2->AddEntry(bottom,"syst. envelope","l");
5329 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
5330 +  leg2->SetY1(0.65);
5331 +  
5332 +  leg2->Draw("same");
5333 +  
5334 +  DrawMCPrelim();
5335 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
5336 +  
5337 +  ratio2->SetLineColor(TZem->GetLineColor());
5338 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
5339 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
5340 +  ratio2->GetYaxis()->SetTitle("ratio");
5341 +  ratio2->Draw();
5342 +  
5343 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
5344 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
5345 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
5346 +  
5347 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
5348 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
5349 +  center2->SetLineColor(kBlue);
5350 +  
5351 +  top2->Draw("same");
5352 +  center2->Draw("same");
5353 +  bottom2->Draw("same");
5354 +  
5355 +  leg2->Draw("same");
5356 +  
5357 +  DrawMCPrelim();
5358 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
5359 +  
5360 +  delete TZem;
5361 +  delete nTZem;
5362 +  delete TZeemm;
5363 +  delete nTZeemm;
5364 +  delete obs2;
5365 +  delete pred2;
5366 +  delete tcan;
5367 +  switch_overunderflow(false);
5368 + }
5369 +
5370 + void IllustrateVariation(TH1F *vanilla_ratio, TH1F *response_only_up_ratio, TH1F *response_only_down_ratio, TH1F *reponse_plus_peak_up_ratio, TH1F *reponse_plus_peak_down_ratio, string PostString) {
5371 +    
5372 +  
5373 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
5374 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5375 +  vanilla_ratio->SetFillColor(kGreen);
5376 +  vanilla_ratio->SetLineColor(kGreen);
5377 +  vanilla_ratio->SetMarkerColor(kGreen);
5378 +  vanilla_ratio->SetFillStyle(3001);
5379 +  vanilla_ratio->Draw("e3");
5380 +  
5381 +  response_only_up_ratio->SetFillColor(kRed);
5382 +  response_only_up_ratio->SetMarkerColor(kRed);
5383 +  response_only_up_ratio->SetLineColor(kRed);
5384 +  response_only_up_ratio->SetFillStyle(3003);
5385 +  response_only_up_ratio->Draw("e3,same");
5386 +  
5387 +  response_only_down_ratio->SetFillColor(kOrange);
5388 +  response_only_down_ratio->SetMarkerColor(kOrange);
5389 +  response_only_down_ratio->SetLineColor(kOrange);
5390 +  response_only_down_ratio->SetFillStyle(3004);
5391 +  response_only_down_ratio->Draw("e3,same");
5392 +  
5393 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
5394 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
5395 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
5396 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
5397 +  reponse_plus_peak_up_ratio->Draw("e3,same");
5398 +  
5399 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
5400 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
5401 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
5402 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
5403 +  reponse_plus_peak_down_ratio->Draw("e3,same");
5404 +  
5405 +  TLine *llow = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-emuncertOFFPEAK);
5406 +  TLine *lhi = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+emuncertOFFPEAK,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+emuncertOFFPEAK);
5407 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
5408 +  
5409 +  TLine *llowA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0-0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0-0.07);
5410 +  TLine *lhiA = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0+0.07,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0+0.07);
5411 +  
5412 +  lhiA->SetLineColor(kRed);
5413 +  lhiA->SetLineStyle(2);
5414 +  llowA->SetLineColor(kRed);
5415 +  llowA->SetLineStyle(2);
5416 +  
5417 +  llow->SetLineColor(kBlue);
5418 +  llow->SetLineStyle(2);
5419 +  lhi->SetLineColor(kBlue);
5420 +  lhi->SetLineStyle(2);
5421 +  lOne->SetLineColor(kBlue);
5422 +  
5423 +  llow->Draw();
5424 +  lhi->Draw();
5425 +  lOne->Draw();
5426 +  
5427 +  llowA->Draw();
5428 +  lhiA->Draw();
5429 +  
5430 +  TLegend *leg = make_legend();
5431 +  leg->SetX1(0.15);
5432 +  leg->SetY1(0.7);
5433 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
5434 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
5435 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5436 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5437 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5438 +  leg->AddEntry(lhi,"Systematic envelope","l");
5439 + //  leg->SetNColumns(2);
5440 +  leg->Draw();
5441 +  
5442 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
5443 +  
5444 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5445 +  vanilla_ratio->Draw("e3");
5446 +  response_only_up_ratio->Draw("e3 same");
5447 +  response_only_down_ratio->Draw("e3 same");
5448 +  TLegend *leg2 = make_legend();
5449 +  leg2->SetX1(0.15);
5450 +  leg2->SetY1(0.7);
5451 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
5452 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
5453 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5454 +  leg2->AddEntry(lhi,"Systematic envelope","l");
5455 +  leg2->Draw();
5456 +  llow->Draw();
5457 +  lOne->Draw();
5458 +  llowA->Draw();
5459 +  lhiA->Draw();
5460 +  
5461 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
5462 +  
5463 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5464 +  response_only_up_ratio->Draw("e3");
5465 +  reponse_plus_peak_up_ratio->Draw("e3 same");
5466 +  reponse_plus_peak_down_ratio->Draw("e3 same");
5467 +  TLegend *leg3 = make_legend();
5468 +  leg3->SetX1(0.15);
5469 +  leg3->SetY1(0.7);
5470 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
5471 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5472 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5473 +  leg3->AddEntry(lhi,"Systematic envelope","l");
5474 +  leg3->Draw();
5475 +  llow->Draw();
5476 +  lOne->Draw();
5477 +  llowA->Draw();
5478 +  lhiA->Draw();
5479 +  
5480 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
5481 +  
5482 +  delete ttcan2;
5483 + }
5484 +
5485 + void ttbar_correction_tests() {
5486 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
5487      
5488 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
5489 +  
5490 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
5491 +  
5492 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
5493 +  
5494 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
5495 +  
5496 +  string vanilla="jzb[1]";
5497 +  string response_only_up="((jzb[1]+0.034665*pt))";
5498 +  string response_only_down="((jzb[1]-0.034665*pt))";
5499 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
5500 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
5501 +
5502 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
5503 +  do_one_ttbar_test(response_only_up_observed,response_only_up_predicted,response_only_up_ratio,response_only_up_ratio2,response_only_up,"response_only_up");
5504 +  do_one_ttbar_test(response_only_down_observed,response_only_down_predicted,response_only_down_ratio,response_only_down_ratio2,response_only_down,"response_only_down");
5505 +  do_one_ttbar_test(reponse_plus_peak_up_observed,reponse_plus_peak_up_predicted,reponse_plus_peak_up_ratio,reponse_plus_peak_up_ratio2,reponse_plus_peak_up,"reponse_plus_peak_up");
5506 +  do_one_ttbar_test(reponse_plus_peak_down_observed,reponse_plus_peak_down_predicted,reponse_plus_peak_down_ratio,reponse_plus_peak_down_ratio2,reponse_plus_peak_down,"reponse_plus_peak_down");
5507 +  
5508 +  ttcan->cd();
5509 +  
5510 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
5511 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
5512 +  
5513 +  delete vanilla_observed;
5514 +  delete response_only_up_observed;
5515 +  delete response_only_down_observed;
5516 +  delete reponse_plus_peak_up_observed;
5517 +  delete reponse_plus_peak_down_observed;
5518 +  
5519 +  delete vanilla_predicted;
5520 +  delete response_only_up_predicted;
5521 +  delete response_only_down_predicted;
5522 +  delete reponse_plus_peak_up_predicted;
5523 +  delete reponse_plus_peak_down_predicted;
5524 +  
5525 +  delete vanilla_ratio;
5526 +  delete response_only_up_ratio;
5527 +  delete response_only_down_ratio;
5528 +  delete reponse_plus_peak_up_ratio;
5529 +  delete reponse_plus_peak_down_ratio;
5530 +  
5531 +  delete ttcan;
5532 + }
5533 +
5534 + void ttbar_region_search(string mcjzb) {
5535 +  cout << "Looking for a nice control region" << endl;
5536 +  TCanvas *can = new TCanvas("can","can",1200,1200);
5537 +  can->Divide(2,2);
5538 +  can->cd(1);
5539 +  can->cd(1)->SetLogy(1);
5540 +  
5541 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5542 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5543 +  
5544 +  JZBdistSF.Draw("histo");
5545 +  JZBdistSF.SetMaximum(1000);
5546 +  JZBdistSF.SetMinimum(0.1);
5547 +  JZBdistSF.Draw("histo");
5548 +  DrawMCPrelim();
5549 +  
5550 +  can->cd(2);
5551 +  can->cd(2)->SetLogy(1);
5552 +  JZBdistOF.Draw("histo");
5553 +  JZBdistOF.SetMaximum(1000);
5554 +  JZBdistOF.SetMinimum(0.1);
5555 +  JZBdistOF.Draw("histo");
5556 +  DrawMCPrelim();
5557 +  
5558 +  can->cd(3);
5559 +  
5560 +  
5561 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
5562 +  
5563 +  DrawMCPrelim();
5564 +  
5565 +  /*
5566 +  THStack *Subtracted = new THStack();
5567 +  
5568 +  TIter nextSF(JZBdistSF.GetHists());
5569 +  TIter nextOF(JZBdistOF.GetHists());
5570 +  TObject* SFobj;
5571 +  TObject* OFobj;
5572 +  
5573 +  TH1* sfh = NULL;
5574 +  TH1* ofh = NULL;
5575 +  
5576 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
5577 +    TH1F *sfstart = (TH1*)SFobj->Clone();
5578 +    TH1F *ofstart = (TH1*)OFobj->Clone();
5579 +    TH1F *obs, *pred;
5580 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
5581 +    
5582 +    if ( !hratio ) {
5583 +      hratio = (TH1*)obj->Clone();
5584 +      hratio->SetName("hratio");
5585 +    } else hratio->Add( (TH1*)obj );
5586 +    
5587 +  }
5588 +  hratio->Divide(hdata);
5589 +  */
5590 +  
5591 +  
5592 +  can->cd(4);
5593 +  JZBdistOF.Draw("histo");
5594 +  DrawMCPrelim();
5595 +  
5596 +  
5597 +  
5598 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
5599 +  
5600 +  CleanLegends();
5601 +  delete can;
5602 + }
5603 +
5604 + void ttbar_tests(string mcjzb) {
5605 +  //ttbar_correction_tests();
5606 +  ttbar_region_search(mcjzb);
5607 + }
5608  
5609   void test() {
5610    
5611    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
5612    testcanv->cd();
5613 <  switch_overunderflow(true);
5613 > //  switch_overunderflow(true);
5614    TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
5615 <  switch_overunderflow(false);
5615 > //  switch_overunderflow(false);
5616    ptdistr->Draw();
5617    testcanv->SaveAs("test.png");
5618    dout << "HELLO there!" << endl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines