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.2 by buchmann, Thu Feb 9 16:02:21 2012 UTC vs.
Revision 1.91 by buchmann, Mon Apr 22 12:13:34 2013 UTC

# Line 23 | Line 23 | using namespace PlottingSetup;
23   void todo() {
24    dout << "My to do list: " << endl;
25    dout << "  - ExperimentalModule::Poisson_ratio_plot : Get the second part to work!" << endl;
26 +  dout << "  - compare_onpeak_offpeak_signal_distributions: Implement this function ... " << endl;
27    dout << "Info : The trigger requirement is currently set to " << (const char*) passtrig << endl;
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 51 | 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 61 | 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 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=20;
267 +    max=300;
268 +  }
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 << "(" << datajzb << ">" << jzbthreshold << ")";
275 +  TCut largerzeroD(largerzeroS.str().c_str());
276 +  
277 +  stringstream smallerzeroS;
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;
298 +
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("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");
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 +  
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&&PlottingSetup::UseSidebandsForcJZB) {
376 +    delete RcorrJZBSBeemm;
377 +    delete LcorrJZBSBeemm;
378 +    delete RcorrJZBSBem;
379 +    delete LcorrJZBSBem;
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) {
387    
388    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
# Line 86 | 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 102 | 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 112 | 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 121 | 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 152 | 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 +  cout << "Going to use cutOSSF " << (const char*) cutOSSF << " and cutnJets " << (const char*) cutnJets << " and ibasiccut " << (const char*) ibasiccut << endl;
483 +  cutOF = cutOSOF&&cutnJets&&ibasiccut;
484 +  cutSF = cutOSSF&&cutnJets&&ibasiccut;
485 +  
486 +  TCanvas *ofsf_can = new TCanvas("ofsf_can","ofsf_can");
487 +
488 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
489 +  rcan->SetLogy(logscale);
490 +  rcan->cd();
491 +
492 +  std::cout << "OF/SF comparison: variable = " << variable << ", cut = " << cutSF.GetTitle() << std::endl;
493 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
494 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
495 + //   string signal("LM3");
496 + //   TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
497 + //   int idx = signalsamples.FindSample(signal)[0];
498 + //   (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
499 + //   signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
500 + //   signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
501 + //   signalhisto->SetLineStyle(2);
502 +  datahistoSF->SetMarkerSize(DataMarkerSize);
503 +  datahistoOF->SetLineColor(kRed);
504 +
505 +  if ( !logscale ) {
506 +    datahistoSF->SetMinimum(0); // Defaults
507 +  } else {
508 +    datahistoSF->SetMinimum(0.5);
509 +  }
510 +  if (ymax<0) {
511 +    if ( logscale ) datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
512 +    else datahistoSF->SetMaximum(0.8*datahistoSF->GetMaximum());
513 +  } else {
514 +    datahistoSF->SetMaximum(ymax);
515 +  }
516 +
517 +  float ymaxSet = datahistoSF->GetMaximum();
518 +
519 +  datahistoSF->GetXaxis()->SetTitle(xlabel.c_str());
520 +  datahistoSF->GetYaxis()->SetTitle("Events");
521 +  datahistoSF->GetXaxis()->CenterTitle();
522 +  datahistoSF->GetYaxis()->CenterTitle();
523 +
524 +  TLegend *mleg = make_legend(legendTitle.c_str(),legendPosition,0.7,false,legendPosition+0.2);
525 +  mleg->AddEntry(datahistoSF, "Same-flavor", "PL");
526 +  if (datahistoOF->Integral()>0) {
527 +    mleg->AddEntry(datahistoOF, "Opposite-flavor", "L");
528 +  } else {
529 +    mleg->AddEntry((TObject*)0, "", "");
530 +  }
531 +  //mleg->AddEntry(signalhisto, "LM3", "L");
532 +
533 +  datahistoSF->Draw("E1");
534 +  if (datahistoOF->Integral()>0) datahistoOF->Draw("HIST,SAMES");
535 +  //signalhisto->Draw("HIST,SAMES");
536 +  mleg->Draw();
537 +  DrawPrelim();
538 +  if (datahistoOF->Integral()>0) {
539 +    Save_With_Ratio( datahistoSF, datahistoOF, rcan, "SFOF/" + filename, false, false, "SF/OF" );
540 +  } else {
541 +    CompleteSave(rcan, "SFOF/" + filename);
542 +  }
543 +
544 +  datahistoSF->Delete();
545 +  datahistoOF->Delete();
546 +  //signalhisto->Delete();
547 +  delete mleg;
548 +  delete rcan;
549 +  delete ofsf_can;
550 +
551 +  return ymaxSet;
552 +
553 + }
554 +
555 + // Compare data to data
556 + float make_data_comparison_plot(string variable, TCut cut, int nbins, float min, float max, float ymax, bool logscale,
557 +                                string xlabel, string filename, float legendPosition=0.55) {
558 +
559 +  TCut ibasiccut=basiccut&&cut;
560 +
561 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
562 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
563 +  rcan->SetLogy(logscale);
564 +  rcan->cd();
565 +
566 +  std::cout << "Data comparison: variable = " << variable << ", cut = " << ibasiccut.GetTitle() << std::endl;
567 +
568 +  TH1F *data1 = allsamples.Draw("data1",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
569 +  TH1F *data2 = comparesamples.Draw("data2",variable,nbins,min,max, xlabel, "events",ibasiccut,data,luminosity);
570 +  data1->Scale(5.0/9.2);
571 +
572 +  data1->SetMarkerSize(DataMarkerSize);
573 +  data2->SetLineColor(kRed);
574 +
575 +  if ( !logscale ) {
576 +    data1->SetMinimum(0); // Defaults
577 +  } else {
578 +    data1->SetMinimum(0.5);
579 +  }
580 +  if (ymax<0) {
581 +    if ( logscale ) data1->SetMaximum(5.3*data1->GetMaximum());
582 +    else data1->SetMaximum(1.5*data1->GetMaximum());
583 +  } else {
584 +    data1->SetMaximum(ymax);
585 +  }
586 +
587 +  float ymaxSet = data1->GetMaximum();
588 +
589 +  data1->GetXaxis()->SetTitle(xlabel.c_str());
590 +  data1->GetYaxis()->SetTitle("Events");
591 +  data1->GetXaxis()->CenterTitle();
592 +  data1->GetYaxis()->CenterTitle();
593 +
594 +  TLegend *mleg = make_legend("",legendPosition,0.7,false,legendPosition+0.2);
595 +  mleg->AddEntry(data1, "2012 data (scaled)", "PL");
596 +  mleg->AddEntry(data2, "2011 data", "L");
597 +
598 +  data1->Draw("E1");
599 +  data2->Draw("HIST,SAMES");
600 +  mleg->Draw();
601 +  DrawPrelim();
602 +  Save_With_Ratio( data1, data2, rcan, "compareData/" + filename, false, false, "new/old" );
603 +
604 +  data1->Delete();
605 +  data2->Delete();
606 +  delete mleg;
607 +  delete rcan;
608 +  delete ckin;
609 +
610 + }
611 +
612 + void make_OFSF_plots(string variable, string addcut, int nbins, float min, float max, bool logscale,
613 +                     string xlabel, string filename, float legendPosition=0.55) {
614 +
615 +  string mllcuts[] = { "mll>20","mll>15&&mll<70", "mll>75&&mll<105", "mll>120" };
616 +  string mllcutname[] = { "m_{ll} > 20 GeV", "20 < m_{ll} < 70 GeV", "70 < m_{ll} < 110 GeV", "m_{ll} > 120 GeV" };
617 +  string plotname[] = {"_all","_low","_peak","_high"};
618 +  float ymax;
619 +
620 +  int start = 0;
621 +  if ( !PlottingSetup::openBox ) start = 3;
622 +
623 +  for ( int i=start; i<4; ++i ) {
624 +    if ( addcut != "" ) mllcuts[i] += "&&"+addcut;
625 +    if ( i==start ) {
626 +      ymax = make_one_OFSF_plot(variable, mllcuts[i], mllcutname[i], nbins, min, max, -1, logscale, xlabel,
627 +                         filename+plotname[i], legendPosition );
628 +    } else {
629 +      make_one_OFSF_plot(variable, mllcuts[i],        mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
630 +                         filename+plotname[i], legendPosition );
631 +    }
632 +    make_one_OFSF_plot(variable, "id1==1&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
633 +                       filename+plotname[i]+"_mm", legendPosition );
634 +    make_one_OFSF_plot(variable, "id1==0&&id1==id2&&"+mllcuts[i], mllcutname[i], nbins, min, max, ymax, logscale, xlabel,
635 +                       filename+plotname[i]+"_ee", legendPosition );
636 +  }
637 +
638 + }
639 +
640 + TCut ReplaceInCut(TCut cut, string replacethis, string withthis) {
641 +  string scut=(string)(const char*)cut;
642 +  string acut=ReplaceAll(scut,replacethis,withthis);
643 +  return TCut(acut.c_str());
644 + }
645 +
646 + void DoMCSystPlot(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
647 +  TCut cut=addcut&&basiccut;
648 +
649 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
650 +  ckin->SetLogy(dolog);
651 +  cout << "\r Creating " << filename << " : data   (1/6)" << std::flush;
652 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
653 +  datahisto->SetMarkerSize(DataMarkerSize);
654 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
655 +  else datahisto->SetMinimum(0.5);
656 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
657 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
658 +  cout << "\r Creating " << filename << " : MC central   (2/6)" << std::flush;
659 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
660 +  TH1F *MCcentral = CollapseStack(mcstack);
661 +
662 +  TCut bkpcut = cut;
663 +  cut = ReplaceInCut(cut,"pfJetGoodNum40","pfJetGoodNum40p1sigma");
664 +  cout << "\r Creating " << filename << " : MC JES up   (3/6)" << std::flush;
665 +  TH1F *MCJESup   = allsamples.Draw("MCJESup",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
666 +
667 +  cut = ReplaceInCut(cut,"pfJetGoodNum40p1sigma","pfJetGoodNum40n1sigma");
668 +  cout << "\r Creating " << filename << " : MC JES down   (4/6)" << std::flush;
669 +  TH1F *MCJESdn   = allsamples.Draw("MCJESdn",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
670 +  
671 +  cut=bkpcut;
672 +  TCut bkpweight = cutWeight;
673 +  cutWeight= ReplaceInCut(cutWeight,"weight","PUweightUP");
674 +  cout << "\r Creating " << filename << " : MC PU up   (5/6)" << std::flush;
675 +  TH1F *MCPUup    = allsamples.Draw("MCPUup",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
676 +  
677 +  cutWeight= ReplaceInCut(cutWeight,"PUweightUP","PUweightDOWN");
678 +  cout << "\r Creating " << filename << " : MC PU down   (6/6)" << std::flush;
679 +  TH1F *MCPUdn    = allsamples.Draw("MCPUdn",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
680 +  cutWeight=bkpweight;
681 +  cout << "\r Creating " << filename << " : Processing systematics ..." << std::flush;
682 +  TH1F *Systematic = (TH1F*)MCPUdn->Clone("Systematic");
683 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
684 +    float jesdn = abs(MCcentral->GetBinContent(i)-MCJESdn->GetBinContent(i));
685 +    float jesup = abs(MCcentral->GetBinContent(i)-MCJESup->GetBinContent(i));
686 +    float jes   = jesdn>jesup?jesdn:jesup;
687 +    
688 +    float PUup = abs(MCcentral->GetBinContent(i)-MCPUup->GetBinContent(i));
689 +    float PUdn = abs(MCcentral->GetBinContent(i)-MCPUdn->GetBinContent(i));
690 +    float pu   = PUdn>PUup?PUdn:PUup;
691 +    
692 +    float sys=sqrt(jes*jes+pu*pu);
693 +    sys/=MCcentral->GetBinContent(i);
694 +    if(MCcentral->GetBinContent(i)==0) sys=0;
695 +    Systematic->SetBinContent(i,sys);
696 +  }
697 +  
698 +  datahisto->Draw("e1");
699 +  ckin->Update();
700 +  mcstack.Draw("histo,same");
701 +  
702 +  datahisto->Draw("same,e1");
703 +  TLegend *kinleg = allsamples.allbglegend();
704 +  kinleg->Draw();
705 +
706 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
707 +  kinpad->SetLogy(dolog);
708 +  kinpad->cd();
709 +  datahisto->Draw("e1");
710 +  mcstack.Draw("histo,same");
711 +  datahisto->Draw("same,e1");
712 +  datahisto->Draw("same,axis");
713 +  
714 +  kinleg->Draw("same");
715 +  DrawPrelim();
716 +  string saveas="kin/"+filename;
717 +  
718 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
719 +  save_with_ratio_and_sys_band(0.0, datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc",Systematic );
720 +  
721 +  ckin->cd();
722 +  MCcentral->SetFillColor(kWhite);
723 +  MCcentral->SetLineColor(kBlack);
724 +  MCcentral->SetLineWidth(2);
725 +  MCPUdn->SetLineColor(kRed);
726 +  MCPUup->SetLineColor(kYellow);
727 +  MCJESdn->SetLineColor(kBlue);
728 +  MCJESup->SetLineColor(kGreen);
729 +  
730 +  TLegend *legsmall = new TLegend(0.0,0.85,1.0,1.00);
731 +  legsmall->SetNColumns(5);
732 +  legsmall->AddEntry(MCcentral,"central","L");
733 +  legsmall->AddEntry(MCPUdn,"PU down","L");
734 +  legsmall->AddEntry(MCPUup,"PU up","L");
735 +  legsmall->AddEntry(MCJESdn,"JES down","L");
736 +  legsmall->AddEntry(MCJESup,"JES up","L");
737 +  legsmall->SetFillColor(kWhite);
738 +  legsmall->SetBorderSize(0);
739 +  
740 +  datahisto->Draw("e1");
741 +  MCcentral->Draw("histo,same");
742 +  MCPUdn->Draw("histo,same");
743 +  MCPUup->Draw("histo,same");
744 +  MCJESdn->Draw("histo,same");
745 +  MCJESup->Draw("histo,same");
746 +  datahisto->Draw("e1,same");
747 +  legsmall->Draw();
748 +  CompleteSave(ckin,saveas+"___AllLines");
749 +  
750 +  delete datahisto;
751 +  delete MCcentral;
752 +  delete MCPUdn;
753 +  delete MCPUup;
754 +  delete MCJESdn;
755 +  delete MCJESup;
756 +  delete ckin;
757 + }
758 +
759 + void DoMCSystPlot(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
760 +  DoMCSystPlot(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
761 + }
762 +  
763   float lastrange_min=0;
764   float lastrange_max=0;
765  
# Line 160 | Line 768 | void make_kin_plot(string variable, stri
768   //  TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
769    TCut ibasiccut=basiccut;
770    bool draw_separation_lines=false;
771 +  bool drawsignal = false;
772    
773    if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
774  
# Line 181 | Line 790 | void make_kin_plot(string variable, stri
790    //Step 2: Refine the cut
791    TCut cut;
792    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
793 <  if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
793 >  if(filename=="nJets" || filename=="nJets_inclusive" || filename=="nJets_met100" || filename=="nJets_inclusive_met100") cut=cutmass&&cutOSSF&&ibasiccut;
794 >  if(filename=="nJets_osof" || filename=="nJets_osof_inclusive" || filename=="nJets_osof_met100" || filename=="nJets_osof_inclusive_met100") cut=cutmass&&cutOSOF&&ibasiccut;
795    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
796 <  if(filename=="mll") {
796 >  if(filename=="mll"||filename=="mll_met100") {
797          cut=cutOSSF&&cutnJets&&ibasiccut;
798          draw_separation_lines=true;
799    }
800 <  if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
801 <  if(filename=="mll_osof") {
800 >  if(filename=="mll_ee"||filename=="mll_ee_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
801 >  if(filename=="mll_mm"||filename=="mll_mm_met100") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
802 >  if(filename=="mll_osof"||filename=="mll_osof_met100") {
803          cut=cutOSOF&&cutnJets&&ibasiccut;
804          draw_separation_lines=true;
805    }
806 <  if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
807 <  if(filename=="mll_aboveJZB100") cut=cutOSSF&&cutnJets&&ibasiccut;
806 >  if(Contains(filename,"aboveJZB")) cut=cutOSSF&&cutnJets&&ibasiccut;
807 >  if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
808 >  if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
809 >  if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
810    if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
811    if(filename=="mll_inclusive_osof") cut=cutOSOF;
812    if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
813    if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
814    if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
815    if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
816 +  if(filename=="numVtx") cut=cutmass&&ibasiccut;
817  
818    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
819    ckin->SetLogy(logscale);
820    TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
821    datahisto->SetMarkerSize(DataMarkerSize);
822 <  THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
822 >  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
823 >  else datahisto->SetMinimum(0.5);
824 >  // Custom max.
825 >  if(variable=="TMath::Abs(pfJetDphiMet[0])") datahisto->SetMaximum(1.5*datahisto->GetMaximum());
826    if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
827    if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
828 <  if(filename=="mll_inclusive") datahisto->SetMinimum(1);
828 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_mm"||filename=="mll_inclusive_ee") datahisto->SetMinimum(1);
829    if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
830    if(filename=="mll_osof") datahisto->SetMinimum(9);
831 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
832 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
833  
834 <  datahisto->SetMaximum(5.3*datahisto->GetMaximum());
216 <  datahisto->Draw("e1");
217 <  ckin->Update();
834 >  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
835    if(loadlastminmax) {
836          datahisto->SetMinimum(lastrange_min);
837          datahisto->SetMaximum(lastrange_max);
# Line 224 | Line 841 | void make_kin_plot(string variable, stri
841          }              
842    }
843  
844 <  mcstack.Draw("same");
844 >  // Draw signal by hand (for some reason I don't manage to use the sample class: it adds it to the stack!)
845 >  string signal("LM3");
846 >  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
847 >  int idx = signalsamples.FindSample(signal)[0];
848 >  if(drawsignal) (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
849 >  if(drawsignal) signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
850 >  if(drawsignal) signalhisto->SetLineColor(kOrange);
851 >
852 >  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
853 >  datahisto->Draw("e1");
854 >  ckin->Update();
855 >  mcstack.Draw("histo,same");
856 >  
857    datahisto->Draw("same,e1");
858    TLegend *kinleg = allsamples.allbglegend();
859    kinleg->Draw();
# Line 266 | Line 895 | void make_kin_plot(string variable, stri
895          kinpad->cd();
896          kinpad->SetLogy(logscale);
897          datahisto->Draw("e1");
898 <        mcstack.Draw("same");
898 >        mcstack.Draw("histo,same");
899 >        if(drawsignal) signalhisto->Draw("same");
900          datahisto->Draw("same,e1");
901          datahisto->Draw("same,axis");
902          if(RestrictToMassPeak&&draw_separation_lines) {
# Line 274 | Line 904 | void make_kin_plot(string variable, stri
904            upperboundary->Draw("same");
905          }
906            
907 +        if(drawsignal) kinleg->AddEntry("signalhisto",signal.c_str(),"l");
908          kinleg->Draw();
909          write_cut->Draw();
910          DrawPrelim();
911          string saveas="kin/"+filename;
912          if(isPF) saveas="kin/"+filename+"__PF";
913 <        save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
913 >        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
914   //      if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
915   //      else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
916   //      delete with_ratio;
# Line 288 | Line 919 | void make_kin_plot(string variable, stri
919          else CompleteSave(ckin,"kin/"+filename);
920    }
921    datahisto->Delete();
922 +  delete signalhisto;
923 +  delete ckin;
924 + }
925 +
926 +
927 + void make_plain_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
928 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
929 +  TCut cut=TCut(addcut.c_str())&&basiccut;
930 +
931 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
932 +  ckin->SetLogy(logscale);
933 +  TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
934 +  datahisto->SetMarkerSize(DataMarkerSize);
935 +  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
936 +  else datahisto->SetMinimum(0.5);
937 +  // Custom max.
938 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
939 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
940 +
941 +  cout << "******** Cut used : " << (const char*) cut << " for plot " << filename << endl;
942 +  if(loadlastminmax) {
943 +        datahisto->SetMinimum(lastrange_min);
944 +        datahisto->SetMaximum(lastrange_max);
945 +        if(logscale) {
946 +                datahisto->SetMinimum(pow(10,lastrange_min));
947 +                datahisto->SetMaximum(pow(10,lastrange_max));
948 +        }              
949 +  }
950 +
951 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
952 +  datahisto->Draw("e1");
953 +  ckin->Update();
954 +  mcstack.Draw("histo,same");
955 +  
956 +  datahisto->Draw("same,e1");
957 +  TLegend *kinleg = allsamples.allbglegend();
958 +  kinleg->Draw();
959 +
960 +  lastrange_min=ckin->GetUymin();
961 +  lastrange_max=ckin->GetUymax();
962 +
963 +  if ( plotratio ) {
964 +        TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
965 +        kinpad->cd();
966 +        kinpad->SetLogy(logscale);
967 +        datahisto->Draw("e1");
968 +        mcstack.Draw("histo,same");
969 +        datahisto->Draw("same,e1");
970 +        datahisto->Draw("same,axis");
971 +          
972 +        kinleg->Draw();
973 +        DrawPrelim();
974 +        string saveas="kin/"+filename;
975 +        if(isPF) saveas="kin/"+filename+"__PF";
976 +        Save_With_Ratio(datahisto,mcstack,kinpad->cd(),saveas);
977 +  } else {
978 +        if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
979 +        else CompleteSave(ckin,"kin/"+filename);
980 +  }
981 +  datahisto->Delete();
982    delete ckin;
983   }
984  
985  
986 < void make_JES_plot() {
986 > void make_JES_plot(TCut cut, string name) {
987  
988    int nbins=10;
989    float min=-0.5;
990    float max = 9.5;
991    bool logscale=true;
992    string xlabel="nJets";
302  TCut cut=cutmass&&cutOSSF&&basiccut;
993  
994    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
995    ckin->SetLogy(logscale);
996 <  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
996 >  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,data,luminosity);
997    datahisto->SetMarkerSize(DataMarkerSize);
998 <  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
999 <  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1000 <  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
998 >  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,mc,luminosity);
999 >  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum40p1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1000 >  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum40n1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
1001  
1002    datahisto->SetMinimum(1);
1003    datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
# Line 326 | Line 1016 | void make_JES_plot() {
1016    JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
1017    JESunc->SetFillStyle(3002);
1018    datahisto->Draw("e1");
1019 <  mcstack.Draw("same");
1019 >  mcstack.Draw("histo,same");
1020    JESunc->Draw("2");
1021    datahisto->Draw("same,e1");
1022    TLegend *kinleg = allsamples.allbglegend();
1023    kinleg->AddEntry(JESunc,"JES uncertainty","f");
1024    kinleg->Draw();
1025 <  CompleteSave(ckin,"Systematics/JES");
1025 >  CompleteSave(ckin,"Systematics/JES"+name);
1026    datahisto->Delete();
1027    delete ckin;
1028 +  delete JESunc;
1029 +  delete JESup;
1030 +  delete JESdn;
1031 +  CleanLegends();
1032 + }
1033 +
1034 + string Cut2Str(TCut cut) {
1035 +  return ((string)(const char*)cut);
1036 + }
1037 +
1038 + void MakeElegantTwoThreeComparisons() {
1039 +    
1040 +    TCut signal("met[4]>100&&met[4]<150&&mll>20"&&PlottingSetup::basicqualitycut);
1041 +    TCut TwoJets("pfJetGoodNum40==2");
1042 +    TCut ThreeJets("pfJetGoodNum40>=3");
1043 +    
1044 +    float min=20;
1045 +    float max=300;
1046 +    int nbins=int((max-min)/5.0);
1047 +    string xlabel="m_{ll} [GeV]";
1048 +    
1049 +    TCanvas *can2 = new TCanvas("can2","can2");
1050 +    TH1F *TwoOF = allsamples.Draw("TwoOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1051 +    TH1F *TwoSF = allsamples.Draw("TwoSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&TwoJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1052 +    TH1F *ThreeOF = allsamples.Draw("ThreeOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1053 +    TH1F *ThreeSF = allsamples.Draw("ThreeSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&signal&&ThreeJets,mc,luminosity,allsamples.FindSample("TTJets_"));
1054 +    
1055 +    can2->cd(1);
1056 +    
1057 +    TwoSF->SetFillColor(kWhite);
1058 +    TwoOF->SetFillColor(kWhite);
1059 +    ThreeSF->SetFillColor(kWhite);
1060 +    ThreeOF->SetFillColor(kWhite);
1061 +    
1062 +    TPad *kin3 = new TPad("kin3","kin3",0,0,1,1);
1063 +    kin3->cd();
1064 +    TwoOF->Draw("histo");
1065 +    TwoSF->Draw("e1,same");
1066 +    TLegend *leg_SFOF_Two = make_legend();
1067 +    leg_SFOF_Two->SetHeader("t#bar{t} MC:");
1068 +    leg_SFOF_Two->AddEntry(TwoOF,"OF, nJets==2","l");
1069 +    leg_SFOF_Two->AddEntry(TwoSF,"SF, nJets==2","lp");
1070 +    leg_SFOF_Two->Draw();
1071 +    Save_With_Ratio(TwoSF,TwoOF,kin3->cd(),"DoubleRatios/SFOF_Two");
1072 +    
1073 +    TPad *kin4 = new TPad("kin4","kin4",0,0,1,1);
1074 +    kin4->cd();
1075 +    ThreeOF->Draw("histo");
1076 +    ThreeSF->Draw("e1,same");
1077 +    TLegend *leg_SFOF_Three = make_legend();
1078 +    leg_SFOF_Three->SetHeader("t#bar{t} MC:");
1079 +    leg_SFOF_Three->AddEntry(TwoOF,"OF, nJet#geq3","l");
1080 +    leg_SFOF_Three->AddEntry(TwoSF,"SF, nJets#geq3","lp");
1081 +    leg_SFOF_Three->Draw();
1082 +    Save_With_Ratio(ThreeSF,ThreeOF,kin4->cd(),"DoubleRatios/SFOF_Three");
1083 +    
1084 +    
1085 +    TwoSF->Scale(ThreeSF->Integral()/TwoSF->Integral());
1086 +    TPad *kin = new TPad("kin","kin",0,0,1,1);
1087 +    kin->cd();
1088 +    TwoSF->Draw("histo");
1089 +    ThreeSF->Draw("e1,same");
1090 +    TLegend *leg_SF_Two_Three = make_legend();
1091 +    leg_SF_Two_Three->SetHeader("t#bar{t} MC:");
1092 +    leg_SF_Two_Three->AddEntry(TwoSF,"#splitline{SF, nJets==2}{ (scaled)}","l");
1093 +    leg_SF_Two_Three->AddEntry(ThreeSF,"SF, nJets#geq3","lp");
1094 +    leg_SF_Two_Three->Draw();
1095 +    Save_With_Ratio(TwoSF,ThreeSF,kin->cd(),"DoubleRatios/SF_Two_Three");
1096 +    
1097 +    TwoOF->Scale(ThreeOF->Integral()/TwoOF->Integral());
1098 +    TPad *kin2 = new TPad("kin2","kin2",0,0,1,1);
1099 +    kin2->cd();
1100 +    TwoOF->Draw("histo");
1101 +    ThreeOF->Draw("e1,same");
1102 +    TLegend *leg_OF_Two_Three = make_legend();
1103 +    leg_OF_Two_Three->SetHeader("t#bar{t} MC:");
1104 +    leg_OF_Two_Three->AddEntry(TwoSF,"#splitline{OF, nJets==2}{ (scaled)}","l");
1105 +    leg_OF_Two_Three->AddEntry(ThreeSF,"OF, nJets#geq3","lp");
1106 +    leg_OF_Two_Three->Draw();
1107 +    Save_With_Ratio(TwoOF,ThreeOF,kin2->cd(),"DoubleRatios/OF_Two_Three");
1108 +    
1109 + }
1110 +
1111 + void PresentRange(TH1F *Down, TH1F *Up, TH1F *central, TVirtualPad *pad, string title) {
1112 +  pad->cd();
1113 +  TGraphErrors *gr = new TGraphErrors(Down->GetNbinsX());
1114 +  for(int i=1;i<=Down->GetNbinsX();i++) {
1115 +    float average=0.5*(Down->GetBinContent(i)+Up->GetBinContent(i));
1116 +    float error=abs(Down->GetBinContent(i)-average);
1117 +    gr->SetPoint(i-1,Down->GetBinCenter(i),average);
1118 +    gr->SetPointError(i-1,Down->GetBinWidth(i)/2.0,error);
1119 +  }
1120 +  gr->SetFillColor(TColor::GetColor("#F79F81"));
1121 +  gr->GetYaxis()->SetRangeUser(0,2);
1122 +  gr->GetXaxis()->SetTitle(central->GetXaxis()->GetTitle());
1123 +  gr->GetYaxis()->SetTitle(central->GetYaxis()->GetTitle());
1124 +  gr->GetXaxis()->CenterTitle();
1125 +  gr->GetYaxis()->CenterTitle();
1126 +  
1127 +  gr->Draw("A2");
1128 +  central->Draw("e1,same");
1129 +  DrawMCPrelim();
1130 +  TText *rtitle = write_text(0.8,0.8,title);
1131 +  TLine *line = new TLine(Down->GetBinLowEdge(1),1.0,Down->GetBinLowEdge(Down->GetNbinsX())+Down->GetBinWidth(Down->GetNbinsX()),1.0);
1132 +  line->SetLineColor(kBlue);
1133 +  line->SetLineStyle(2);
1134 +  line->Draw("same");
1135 +  rtitle->Draw("same");
1136 + }
1137 +
1138 + TH1F* ProduceTTbarRatio(TH1F *datahisto, TH1F *fullmc, TH1F *originalttbar, TH1F *httbar) {
1139 +  TH1F *basehisto = (TH1F*)fullmc->Clone("basehisto");
1140 +  basehisto->Add(originalttbar,-1);
1141 +  basehisto->Add(httbar);
1142 +  
1143 +  string sname=httbar->GetName();
1144 +  sname="R"+sname.substr(1,sname.length());
1145 +  TH1F *ratio = (TH1F*)datahisto->Clone(sname.c_str());
1146 +  ratio->Divide(basehisto);
1147 +  delete basehisto;
1148 +  return ratio;
1149 + }
1150 +  
1151 + void make_ttbar_comparison(string datavariable, string mcvariable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1152 +  
1153 +  TCut cut=addcut&&basiccut;
1154 +  
1155 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1156 +  ckin->SetLogy(dolog);
1157 +  cout << "\r Creating " << filename << " : data   (1/7)" << std::flush;
1158 +  TH1F *datahisto = allsamples.Draw("datahisto",datavariable,nbins,min,max, xlabel, "events",cut,data,luminosity);
1159 +  datahisto->SetMarkerSize(DataMarkerSize);
1160 +  if ( !dolog ) datahisto->SetMinimum(0); // Defaults
1161 +  else datahisto->SetMinimum(0.5);
1162 +  if (dolog) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
1163 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
1164 +  cout << "\r Creating " << filename << " : MC central  (stack) (2/7)" << std::flush;
1165 +  THStack mcstack   = allsamples.DrawStack("mcstack",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
1166 +  TH1F *MCcentral = CollapseStack(mcstack);
1167 +
1168 +  cout << "\r Creating " << filename << " : MC central (histo)   (3/7)" << std::flush;
1169 +  TH1F *TCentral        = allsamples.Draw ("TCentral",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,allsamples.FindSample("TTJets_"));
1170 +  TH1F *RCentral        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TCentral);
1171 +  
1172 +  cout << "\r Creating " << filename << " : MC Matching up   (4/7)" << std::flush;
1173 +  TH1F *TMatchingUp     = systsamples.Draw("TMatchingUp",  mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingup"));
1174 +  TH1F *RMatchingUp     = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingUp);
1175 +  
1176 +  cout << "\r Creating " << filename << " : MC Matching down   (5/7)" << std::flush;
1177 +  TH1F *TMatchingDown   = systsamples.Draw("TMatchingDown",mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_matchingdown"));
1178 +  TH1F *RMatchingDown   = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TMatchingDown);
1179 +  
1180 +  cout << "\r Creating " << filename << " : MC Scale up   (6/7)" << std::flush;
1181 +  TH1F *TScaleUp        = systsamples.Draw("TScaleUp",     mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaleup"));
1182 +  TH1F *RScaleUp        = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleUp);
1183 +  
1184 +  cout << "\r Creating " << filename << " : MC Scale down   (7/7)" << std::flush;
1185 +  TH1F *TScaleDown      = systsamples.Draw("TScaleDown",   mcvariable,nbins,min,max,xlabel,"events",cut,mc,luminosity,systsamples.FindSample("TTJets_scaledown"));
1186 +  TH1F *RScaleDown      = ProduceTTbarRatio(datahisto,MCcentral,TCentral,TScaleDown);
1187 +  
1188 +  datahisto->Draw("e1");
1189 +  ckin->Update();
1190 +  mcstack.Draw("histo,same");
1191 +  
1192 +  datahisto->Draw("same,e1");
1193 +  TLegend *kinleg = allsamples.allbglegend();
1194 +  kinleg->Draw();
1195 +
1196 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1197 +  kinpad->SetLogy(dolog);
1198 +  kinpad->cd();
1199 +  datahisto->Draw("e1");
1200 +  mcstack.Draw("histo,same");
1201 +  datahisto->Draw("same,e1");
1202 +  datahisto->Draw("same,axis");
1203 +  
1204 +  kinleg->Draw("same");
1205 +  DrawPrelim();
1206 +  string saveas="kin/"+filename;
1207 +  
1208 +  cout << "Passing filename to be saved : " << filename << " as " << saveas << endl;
1209 +  Save_With_Ratio( datahisto, CollapseStack(mcstack), kinpad->cd(), saveas, false, false, "data/mc");
1210 +  delete kinpad;
1211 +  
1212 +  ckin->cd();
1213 +  TCentral->SetLineColor(kBlack);
1214 +  
1215 +  TMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1216 +  TMatchingUp->SetLineStyle(2);//dashed
1217 +  TMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1218 +  TMatchingDown->SetLineStyle(3);//dotted
1219 +  
1220 +  TScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1221 +  TScaleUp->SetLineStyle(2);//dashed
1222 +  TScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1223 +  TScaleDown->SetLineStyle(3);//dotted
1224 +  
1225 +  MCcentral->SetLineStyle(3);
1226 +  MCcentral->SetLineColor(kRed);
1227 +  
1228 +  TCentral->Draw("e1,same");
1229 +  TCentral->Draw("histo,same");
1230 +  TMatchingUp->Draw("histo,same");
1231 +  TMatchingDown->Draw("histo,same");
1232 +  TScaleUp->Draw("histo,same");
1233 +  TScaleDown->Draw("histo,same");
1234 +  
1235 +  TLegend *sleg = make_legend();
1236 +  sleg->AddEntry(TCentral,"Central","L");
1237 +  sleg->AddEntry(TMatchingUp,"matching up","L");
1238 +  sleg->AddEntry(TMatchingDown,"matching down","L");
1239 +  sleg->AddEntry(TScaleUp,"scale up","L");
1240 +  sleg->AddEntry(TScaleDown,"scale down","L");
1241 +  sleg->Draw();
1242 +  
1243 +  CompleteSave(ckin,saveas+"___AllLines");
1244 +  ckin->cd();
1245 +  ckin->SetLogy(0);
1246 +  
1247 +  RCentral->SetLineColor(kBlack);
1248 +  
1249 +  RMatchingUp->SetLineColor(TColor::GetColor("#2c17b1"));//blue
1250 +  RMatchingUp->SetLineStyle(2);//dashed
1251 +  RMatchingDown->SetLineColor(TColor::GetColor("#2c17b1"));
1252 +  RMatchingDown->SetLineStyle(3);//dotted
1253 +  
1254 +  RScaleUp->SetLineColor(TColor::GetColor("#FF8500"));//orange
1255 +  RScaleUp->SetLineStyle(2);//dashed
1256 +  RScaleDown->SetLineColor(TColor::GetColor("#FF8500"));
1257 +  RScaleDown->SetLineStyle(3);//dotted
1258 +  
1259 +  RCentral->GetYaxis()->SetRangeUser(0,2);
1260 +  RCentral->Draw("e1");
1261 +  RMatchingUp->Draw("histo,same");
1262 +  RMatchingDown->Draw("histo,same");
1263 +  RScaleUp->Draw("histo,same");
1264 +  RScaleDown->Draw("histo,same");
1265 +  
1266 +  CompleteSave(ckin,saveas+"___AllRatios");
1267 +
1268 +  TCanvas *multicanvas = new TCanvas("multicanvas","multicanvas",1400,700);
1269 +  multicanvas->Divide(2,1);
1270 +  PresentRange(RMatchingUp,RMatchingDown,RCentral,multicanvas->cd(1),"Matching");
1271 +  PresentRange(RScaleUp,RScaleDown,RCentral,multicanvas->cd(2),"Scale");
1272 +  CompleteSave(multicanvas,saveas+"___RangeIllustration");
1273 +  
1274 +  
1275 +  delete datahisto;
1276 +  delete   TCentral;
1277 +  delete   TMatchingUp;
1278 +  delete   TMatchingDown;
1279 +  delete   TScaleUp;
1280 +  delete   TScaleDown;
1281 + //   delete   Ttmass166;
1282 + //   delete   Ttmass169;
1283 + //   delete   Ttmass175;
1284 + //   delete   Ttmass178;
1285 +  
1286 +  delete ckin;
1287 +  
1288 + }
1289 +  
1290 + void make_ttbar_comparison(string variable, int nbins, float min, float max, TCut addcut, bool dolog, string xlabel, string filename) {
1291 +  make_ttbar_comparison(variable, variable, nbins, min, max, addcut, dolog, xlabel, filename);
1292 + }
1293 +
1294 + void ProduceJanPlots() {
1295 +  TCanvas *c1 = new TCanvas("c1","c1");
1296 +  TH1F *metSF = allsamples.Draw("metSF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1297 +  TH1F *metOF = allsamples.Draw("metOF","met[4]",30,100,400, "E_{T}^{miss} [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1298 +  
1299 +  TPad* rcan = new TPad("rcan","rcan",0,0,1,1);
1300 +  rcan->cd();
1301 +
1302 +  metOF->SetLineColor(kRed);
1303 +  metSF->Draw("e1");
1304 +  metOF->Draw("histo,same");
1305 +  metSF->Draw("e1,same");
1306 +  
1307 +  TLegend *leg = make_legend();
1308 +  
1309 +  leg->AddEntry(metSF,"Data SF","p");
1310 +  leg->AddEntry(metOF,"Data OF","l");
1311 +  leg->Draw();
1312 +  
1313 +  DrawPrelim();
1314 +  
1315 +  Save_With_Ratio(metSF,metOF,rcan,"JanPlots/ETHConfig",false,false,"SF/OF");
1316 +  
1317 +  delete rcan;
1318 +  delete metSF;
1319 +  delete metOF;
1320 +  delete c1;
1321 + }
1322 +
1323 + THStack MakeOneSystematicsPlot(TCut cut, string saveas, string variation, TH1F *hdata, string variable, int nbins, float bmin, float bmax, string label, TH1F* &thisto) {
1324 +  THStack SystPlot = allsamples.DrawStack(variation,variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity);
1325 +  
1326 +  //now need to process the plot (calculate the variation and set the member of thstack accordingly!)
1327 +  if(variation!="Central") {
1328 +    TH1F *varttbar;
1329 +    if(variation=="MatchingUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingup_TuneZ2s"));
1330 +    if(variation=="MatchingDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_matchingdown"));
1331 +    if(variation=="ScaleUp") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaleup"));
1332 +    if(variation=="ScaleDown") varttbar = systsamples.Draw("varttbar",variable,nbins,bmin,bmax,label,"events",cut,mc,PlottingSetup::luminosity,systsamples.FindSample("TTJets_scaledown"));
1333 +    assert(varttbar);
1334 +    
1335 +    TIter nextHisto(SystPlot.GetHists());
1336 +    TH1F* h;
1337 +    while ( h = (TH1F*)nextHisto() ) {
1338 +      if(Contains(h->GetName(),"t_bar_t")) {
1339 +        varttbar->Scale(h->Integral()/varttbar->Integral());
1340 +        for(int i=0;i<=h->GetNbinsX()+1;i++) {//note that we deliberatly consider the under/overflow bin as well!
1341 +          h->SetBinContent(i,varttbar->GetBinContent(i));
1342 +          h->SetBinError(i,varttbar->GetBinError(i));
1343 +        }
1344 +        thisto=(TH1F*)varttbar->Clone(variation.c_str());
1345 +        SystPlot.Modified();
1346 +      }
1347 +    }
1348 +    delete varttbar;
1349 +  } else {
1350 +    TIter nextHisto(SystPlot.GetHists());
1351 +    TH1F* h;
1352 +    while ( h = (TH1F*)nextHisto() ) {
1353 +      if(Contains(h->GetName(),"t_bar_t")) thisto=(TH1F*)h->Clone(variation.c_str());
1354 +    }
1355 +  }
1356 +    
1357 +  TLegend *fullleg = allsamples.allbglegend();
1358 +  fullleg->SetHeader(variation.c_str());
1359 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1360 +  kinpad->SetLogy(1);
1361 +  kinpad->cd();
1362 +  
1363 +  hdata->Draw("e1");
1364 +  SystPlot.Draw("histo,same");
1365 +  hdata->Draw("e1,same");
1366 +  fullleg->Draw();
1367 +  DrawPrelim();
1368 +  
1369 +  Save_With_Ratio(hdata,SystPlot,kinpad,saveas+"_"+variation);
1370 +  CleanLegends();
1371 +  
1372 +  delete kinpad;
1373 +  return SystPlot;
1374 + }
1375 +  
1376 +
1377 +
1378 + void ProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1379 +  TCanvas *ca = new TCanvas("ca","ca");
1380 +  TH1F *hdata = allsamples.Draw("hdata",variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1381 +  
1382 +  TH1F *tScaleUp,*tScaleDown,*tMatchingUp,*tMatchingDown,*tCentral;
1383 +  
1384 +  THStack ScaleUp      = MakeOneSystematicsPlot(thiscut,saveas,"ScaleUp",hdata,variable, nbins, bmin, bmax, label,tScaleUp);
1385 +  THStack ScaleDown    = MakeOneSystematicsPlot(thiscut,saveas,"ScaleDown",hdata,variable, nbins, bmin, bmax, label,tScaleDown);
1386 +  THStack MatchingUp   = MakeOneSystematicsPlot(thiscut,saveas,"MatchingUp",hdata,variable, nbins, bmin, bmax, label,tMatchingUp);
1387 +  THStack MatchingDown = MakeOneSystematicsPlot(thiscut,saveas,"MatchingDown",hdata,variable, nbins, bmin, bmax, label,tMatchingDown);
1388 +  
1389 +  TH1F *HScaleUp = CollapseStack(ScaleUp);
1390 +  TH1F *HScaleDown = CollapseStack(ScaleDown);
1391 +  TH1F *HMatchingUp = CollapseStack(MatchingUp);
1392 +  TH1F *HMatchingDown = CollapseStack(MatchingDown);
1393 +  
1394 +  THStack Central = MakeOneSystematicsPlot(thiscut,saveas,"Central",hdata,variable, nbins, bmin, bmax, label,tCentral);
1395 +  TH1F *HCentral = CollapseStack(Central);
1396 +  
1397 +  TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1398 +  for(int i=1;i<=Systematic->GetNbinsX();i++) {
1399 +    float matchingup   = abs(HMatchingUp->GetBinContent(i)-HCentral->GetBinContent(i));
1400 +    float matchingdown = abs(HMatchingDown->GetBinContent(i)-HCentral->GetBinContent(i));
1401 +    float scaleup   = abs(HScaleUp->GetBinContent(i)-HCentral->GetBinContent(i));
1402 +    float scaledown = abs(HScaleDown->GetBinContent(i)-HCentral->GetBinContent(i));
1403 +    
1404 +    float matching = matchingup>matchingdown?matchingup:matchingdown;
1405 +    float scale    = scaleup>scaledown?scaleup:scaledown;
1406 +    
1407 +    float sys=sqrt(matching*matching+scale*scale);
1408 +    sys/=HCentral->GetBinContent(i);
1409 +    if(HCentral->GetBinContent(i)==0) sys=0;
1410 +    Systematic->SetBinContent(i,sys);
1411 +  }
1412 +  
1413 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1414 +  kinpad->SetLogy(1);
1415 +  kinpad->cd();
1416 +  if(variable=="genMET") {
1417 +    Central.Draw("histo");
1418 +  } else {
1419 +    hdata->Draw("e1");
1420 +    Central.Draw("histo,same");
1421 +    hdata->Draw("e1,same");
1422 +  }
1423 +  
1424 +  DrawPrelim();
1425 +  
1426 +  save_with_ratio_and_sys_band( 0.0, hdata, HCentral, kinpad->cd(), saveas, false, false, "data/mc",Systematic );
1427 +  
1428 +  kinpad->cd();
1429 +  tCentral->SetFillColor(kWhite);
1430 +  tCentral->SetLineColor(kBlack);
1431 +  tScaleUp->SetLineColor(kRed);
1432 +  tScaleDown->SetLineColor(kRed);
1433 +  tMatchingUp->SetLineColor(kBlue);
1434 +  tMatchingDown->SetLineColor(kBlue);
1435 +  tScaleUp->SetLineStyle(2);
1436 +  tScaleDown->SetLineStyle(3);
1437 +  tMatchingUp->SetLineStyle(2);
1438 +  tMatchingDown->SetLineStyle(3);
1439 +  
1440 +  TLegend *leg2 = make_legend();
1441 +  leg2->AddEntry(hdata,"Data","p");
1442 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1443 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1444 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1445 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1446 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1447 +  if(variable=="genMET") {
1448 +    Central.Draw("histo");
1449 +  }else {
1450 +    hdata->Draw("e1");
1451 +    Central.Draw("histo,same");
1452 +    hdata->Draw("e1,same");
1453 +  }
1454 +  tCentral->Draw("histo,same");
1455 +  tScaleUp->Draw("histo,same");
1456 +  tScaleDown->Draw("histo,same");
1457 +  tMatchingUp->Draw("histo,same");
1458 +  tMatchingDown->Draw("histo,same");
1459 +  leg2->Draw();
1460 +  
1461 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1462 +  
1463 +  gStyle->SetOptFit(0);
1464 +  
1465 +  kinpad->cd();
1466 +  kinpad->SetLogy(0);
1467 +  TH1F *MatchingRatio = (TH1F*)tMatchingUp->Clone("MatchingRatio");
1468 +  MatchingRatio->Divide(tMatchingDown);
1469 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1470 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1471 +  lone->SetLineStyle(2);
1472 +  TH1F *ScaleRatio = (TH1F*)tScaleUp->Clone("ScaleRatio");
1473 +  ScaleRatio->Divide(tScaleDown);
1474 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1475 +  MatchingRatio->Draw("e1");
1476 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1477 +  MatchingRatio->Fit("QP1","R");
1478 +  lone->Draw();
1479 +  stringstream summary;
1480 +  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);
1481 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1482 +  TText *infobox = write_title(summary.str());
1483 +  infobox->SetX(0.75);
1484 +  infobox->SetTextSize(0.03);
1485 +  infobox->SetY(0.75);
1486 +  infobox->Draw();
1487 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1488 +  kinpad->cd();
1489 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1490 +  ScaleRatio->Draw("e1");
1491 +  ScaleRatio->Fit("QP1","R");
1492 +  summary.str("");
1493 +  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);
1494 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1495 +  TText *infobox2 = write_title(summary.str());
1496 +  infobox2->SetX(0.75);
1497 +  infobox2->SetTextSize(0.03);
1498 +  infobox2->SetY(0.75);
1499 +  infobox2->Draw();
1500 +
1501 +  lone->Draw();
1502 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1503 +  
1504 +  
1505 +  delete QP1;
1506 +  delete infobox;
1507 +  delete infobox2;
1508 +  delete MatchingRatio;
1509 +  delete ScaleRatio;
1510 +  DeleteStack(ScaleUp);
1511 +  DeleteStack(ScaleDown);
1512 +  DeleteStack(MatchingUp);
1513 +  DeleteStack(MatchingDown);
1514 +  delete leg2;
1515 +  CleanLegends();
1516 +  DeleteStack(Central);
1517 +  delete Systematic;
1518 +  delete HScaleUp;
1519 +  delete HScaleDown;
1520 +  delete HMatchingUp;
1521 +  delete HMatchingDown;
1522 +  delete hdata;
1523 +  delete HCentral;
1524 +  delete ca;
1525 + }
1526 +
1527 + TH1F* ImposeBinning(TH1F *binninghisto, TH1F* histo) {
1528 +  float val=0,err=0;
1529 +  vector<float> bins;
1530 +  vector<float> vals;
1531 +  vector<float> errs;
1532 +  
1533 +  bins.push_back(binninghisto->GetBinLowEdge(1));
1534 +  int iBin=1;
1535 +  
1536 +  for(unsigned int i=1;i<histo->GetNbinsX();i++) {//going to second last one on purpose!
1537 +    if((histo->GetBinLowEdge(i)+0.00001>=binninghisto->GetBinLowEdge(iBin)+binninghisto->GetBinWidth(iBin))) {
1538 +      bins.push_back(histo->GetBinLowEdge(i));
1539 +      vals.push_back(val);val=0;
1540 +      errs.push_back(err);err=0;
1541 +      iBin++;
1542 +    }
1543 +    val+=histo->GetBinContent(i);
1544 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1545 +  }
1546 +  bins.push_back(histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()));
1547 +  vals.push_back(val);val=0;
1548 +  errs.push_back(err);err=0;
1549 +  
1550 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1551 +  for(unsigned int i=0;i<vals.size();i++) {
1552 +    h->SetBinContent(i+1,vals[i]);
1553 +    h->SetBinError(i+1,errs[i]);
1554 +  }
1555 +  
1556 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1557 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1558 +  
1559 +  h->GetXaxis()->CenterTitle();
1560 +  h->GetYaxis()->CenterTitle();
1561 +
1562 +  return h;
1563 + }
1564 +
1565 +
1566 + TH1F* ReBinOptimizingStats(int nbins, TH1F *histo) {
1567 +  float statsperbin = (1/(float)nbins) * histo->Integral();
1568 +  float val=0,err=0;
1569 +  vector<float> bins;
1570 +  vector<float> vals;
1571 +  vector<float> errs;
1572 +  
1573 +  bins.push_back(histo->GetBinLowEdge(1));
1574 +  for(unsigned int i=1;i<=histo->GetNbinsX();i++) {
1575 +    val+=histo->GetBinContent(i);
1576 +    err=sqrt(err*err+histo->GetBinError(i)*histo->GetBinError(i));
1577 +    if( val/statsperbin > 0.85) {
1578 +      if(bins.size()<nbins) {
1579 +        bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1580 +        vals.push_back(val);val=0;
1581 +        errs.push_back(err);err=0;
1582 +      }
1583 +    }
1584 +    if(i==histo->GetNbinsX()) {
1585 +      bins.push_back(histo->GetBinLowEdge(i)+histo->GetBinWidth(i));
1586 +      vals.push_back(val);val=0;
1587 +      errs.push_back(err);err=0;
1588 +    }
1589 +  }
1590 +  TH1F *h = new TH1F(("r"+(string)histo->GetName()).c_str(),("r"+(string)histo->GetName()).c_str(),bins.size()-1,&bins[0]);
1591 +  
1592 +  h->GetXaxis()->SetTitle(histo->GetXaxis()->GetTitle());
1593 +  h->GetYaxis()->SetTitle(histo->GetYaxis()->GetTitle());
1594 +  
1595 +  h->GetXaxis()->CenterTitle();
1596 +  h->GetYaxis()->CenterTitle();
1597 +  
1598 +  for(unsigned int i=0;i<vals.size();i++) {
1599 +    h->SetBinContent(i+1,vals[i]);
1600 +    h->SetBinError(i+1,errs[i]);
1601 +  }
1602 +  
1603 +  return h;
1604 + }
1605 +
1606 +
1607 +  
1608 + void ShowBinning(TH1F *histo) {
1609 +  cout << "Showing binning for " << histo->GetName() << " (\" " << histo->GetTitle() << "\")" << endl;
1610 +  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;
1611 + }
1612 +  
1613 + void QuickProduceMCSystematicPlot(string variable, int nbins, float bmin, float bmax, string label, TCut thiscut, string saveas) {
1614 +  TCanvas *ca = new TCanvas("ca","ca");
1615 +  TH1F *tScaleUp = systsamples.Draw("tScaleUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaleup"));
1616 +  TH1F *tScaleDown = systsamples.Draw("tScaleDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("scaledown"));
1617 +  TH1F *tMatchingUp = systsamples.Draw("tMatchingUp",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingup"));
1618 +  TH1F *tMatchingDown = systsamples.Draw("tMatchingDown",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("matchingdown"));
1619 +  TH1F *tCentral = systsamples.Draw("tCentral",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity,systsamples.FindSample("TTJets_MassiveBinDECAY_TuneZ2sta"));
1620 +  
1621 +  tScaleUp->Scale(1.0/tScaleUp->Integral());
1622 +  tScaleDown->Scale(1.0/tScaleDown->Integral());
1623 +  tMatchingDown->Scale(1.0/tMatchingDown->Integral());
1624 +  tMatchingUp->Scale(1.0/tMatchingUp->Integral());
1625 +  tCentral->Scale(1.0/tCentral->Integral());
1626 +  
1627 +  cout << "At this point we want to rebin the scale/matching histograms so we get decent stats!" << endl;
1628 +  
1629 +  
1630 +  TH1F *rtScaleUp = ReBinOptimizingStats(7,tScaleUp); // using the scale up sample to get the binning (shouldn't use the central one for obvious reasons)
1631 +  TH1F *rtScaleDown = ImposeBinning(rtScaleUp,tScaleDown);
1632 +  TH1F *rtMatchingDown = ImposeBinning(rtScaleUp,tMatchingDown);
1633 +  TH1F *rtMatchingUp = ImposeBinning(rtScaleUp,tMatchingUp);
1634 +  TH1F *rtCentral = ImposeBinning(rtScaleUp,tCentral);
1635 +  
1636 +  float min=rtScaleUp->GetMinimum();
1637 +  float max=rtScaleUp->GetMaximum();
1638 +  
1639 +  if(rtScaleDown->GetMinimum()<min) min=rtScaleDown->GetMinimum();
1640 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1641 +  if(rtMatchingDown->GetMinimum()<min) min=rtMatchingDown->GetMinimum();
1642 +  if(rtMatchingUp->GetMinimum()<min) min=rtMatchingUp->GetMinimum();
1643 +  if(rtCentral->GetMinimum()<min) min=rtCentral->GetMinimum();
1644 +  
1645 +  if(rtScaleDown->GetMaximum()<min) max=rtScaleDown->GetMaximum();
1646 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1647 +  if(rtMatchingDown->GetMaximum()<min) max=rtMatchingDown->GetMaximum();
1648 +  if(rtMatchingUp->GetMaximum()<min) max=rtMatchingUp->GetMaximum();
1649 +  if(rtCentral->GetMaximum()<min) max=rtCentral->GetMaximum();
1650 +  
1651 +  rtCentral->SetMaximum(1.2*max);
1652 +  rtCentral->SetMinimum(0.8*min);
1653 +  
1654 + /*  tScaleUp->Rebin(40);
1655 +  tScaleDown->Rebin(40);
1656 +  tMatchingDown->Rebin(40);
1657 +  tMatchingUp->Rebin(40);
1658 +  tCentral->Rebin(40);*/
1659 +  
1660 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1661 +  kinpad->SetLogy(1);
1662 +  kinpad->cd();
1663 +  tCentral->SetFillColor(kWhite);
1664 +  tCentral->SetLineColor(kBlack);
1665 +  tScaleUp->SetLineColor(kRed);
1666 +  tScaleDown->SetLineColor(kRed);
1667 +  tMatchingUp->SetLineColor(kBlue);
1668 +  tMatchingDown->SetLineColor(kBlue);
1669 +  tScaleUp->SetLineStyle(2);
1670 +  tScaleDown->SetLineStyle(3);
1671 +  tMatchingUp->SetLineStyle(2);
1672 +  tMatchingDown->SetLineStyle(3);
1673 +  
1674 +  rtScaleDown->SetLineColor(kRed);
1675 +  rtMatchingUp->SetLineColor(kBlue);
1676 +  rtMatchingDown->SetLineColor(kBlue);
1677 +  rtScaleUp->SetLineStyle(2);
1678 +  rtScaleDown->SetLineStyle(3);
1679 +  rtMatchingUp->SetLineStyle(2);
1680 +  rtMatchingDown->SetLineStyle(3);
1681 +  
1682 +  TLegend *leg2 = make_legend();
1683 +  leg2->AddEntry(tCentral,"Central (ttbar)","l");
1684 +  leg2->AddEntry(tScaleUp,"ScaleUp (ttbar)","l");
1685 +  leg2->AddEntry(tScaleDown,"ScaleDown (ttbar)","l");
1686 +  leg2->AddEntry(tMatchingUp,"MatchingUp (ttbar)","l");
1687 +  leg2->AddEntry(tMatchingDown,"MatchingDown (ttbar)","l");
1688 +  
1689 +  tCentral->Draw("histo");
1690 +  tScaleUp->Draw("histo,same");
1691 +  tScaleDown->Draw("histo,same");
1692 +  tMatchingUp->Draw("histo,same");
1693 +  tMatchingDown->Draw("histo,same");
1694 +  leg2->Draw();
1695 +  DrawMCPrelim();
1696 +  CompleteSave(kinpad,saveas+"__TTbarComparison");
1697 +  kinpad->cd();
1698 +  kinpad->SetLogy(0);
1699 +  rtCentral->Draw("histo");
1700 +  rtScaleUp->Draw("histo,same");
1701 +  rtScaleDown->Draw("histo,same");
1702 +  rtMatchingUp->Draw("histo,same");
1703 +  rtMatchingDown->Draw("histo,same");
1704 +  leg2->Draw();
1705 +  DrawMCPrelim();
1706 +  CompleteSave(kinpad,saveas+"__TTbarComparison__REBINNED");
1707 +  
1708 +  
1709 +  gStyle->SetOptFit(0);
1710 +
1711 +  kinpad->cd();
1712 +  kinpad->SetLogy(0);
1713 +  TH1F *MatchingRatio = (TH1F*)rtMatchingUp->Clone("MatchingRatio");
1714 +  MatchingRatio->Divide(rtMatchingDown);
1715 +  TLine *lone = new TLine(tScaleUp->GetBinLowEdge(1),1,tScaleUp->GetBinLowEdge(tScaleUp->GetNbinsX())+tScaleUp->GetBinWidth(tScaleUp->GetNbinsX()),1);
1716 +  lone->SetLineColor(TColor::GetColor("#01DF01"));
1717 +  lone->SetLineStyle(2);
1718 +  TH1F *ScaleRatio = (TH1F*)rtScaleUp->Clone("ScaleRatio");
1719 +  ScaleRatio->Divide(rtScaleDown);
1720 +  MatchingRatio->GetYaxis()->SetRangeUser(0,3);
1721 +  MatchingRatio->Draw("e1");
1722 +  TF1 *QP1 = new TF1("QP1","[0]+[1]*x",50,200);//simple linear function ranging from 50 to 200
1723 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") MatchingRatio->Fit("QP1","RQ");
1724 +  lone->Draw();
1725 +  stringstream summary;
1726 +  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);
1727 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1728 +  TText *infobox = write_title(summary.str());
1729 +  infobox->SetX(0.75);
1730 +  infobox->SetTextSize(0.03);
1731 +  infobox->SetY(0.75);
1732 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox->Draw();
1733 +  DrawMCPrelim();
1734 +  CompleteSave(kinpad,saveas+"__TTbarComparison_MatchingUpDividedMatchingDown");
1735 +  kinpad->cd();
1736 +  ScaleRatio->GetYaxis()->SetRangeUser(0,3);
1737 +  ScaleRatio->Draw("e1");
1738 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") ScaleRatio->Fit("QP1","RQ");
1739 +  summary.str("");
1740 +  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);
1741 +  summary << " +/- " << DigitsAfterComma(QP1->GetParError(1),4) << "}}";
1742 +  TText *infobox2 = write_title(summary.str());
1743 +  infobox2->SetX(0.75);
1744 +  infobox2->SetTextSize(0.03);
1745 +  infobox2->SetY(0.75);
1746 +  if(variable=="genMET" || variable=="met[4]" || variable=="met[1]") infobox2->Draw();
1747 +
1748 +  lone->Draw();
1749 +  DrawMCPrelim();
1750 +  CompleteSave(kinpad,saveas+"__TTbarComparison_ScaleUpDividedScaleDown");
1751 +  
1752 +  kinpad->cd();
1753 +  TH1F *SysMatching = (TH1F*)rtMatchingDown->Clone("SysMatching");
1754 +  TH1F *SysScale = (TH1F*)rtScaleDown->Clone("SysMatching");
1755 +  TH1F *SysHisto = (TH1F*)rtScaleDown->Clone("SysHisto");
1756 +  
1757 +  for(int i=1;i<=SysScale->GetNbinsX();i++) {
1758 +    float matching, scale;
1759 +    bool AssumeFactor=false;
1760 +    if(AssumeFactor) {
1761 +      // assume that an upward/downward variation means a change by a constant factor, i.e. f(up) = alpha * f(central)
1762 +      matching=0.;
1763 +      scale=0.;
1764 +    } else {
1765 +      // assume that the central value is exactly between up & down, i.e. central = (up-down)/2
1766 +      matching = fabs(    ( rtMatchingUp->GetBinContent(i) - rtMatchingDown->GetBinContent(i)) / (rtMatchingUp->GetBinContent(i) + rtMatchingDown->GetBinContent(i)) );
1767 +      scale    = fabs(    ( rtScaleUp->GetBinContent(i) - rtScaleDown->GetBinContent(i)) / (rtScaleUp->GetBinContent(i) + rtScaleDown->GetBinContent(i)) );
1768 +    }
1769 +    
1770 +    SysMatching->SetBinContent(i,1+matching);
1771 +    SysScale->SetBinContent(i,1+scale);
1772 +    SysHisto->SetBinContent(i,sqrt(matching*matching+scale*scale)+1);
1773 +  }
1774 +  
1775 +  SysHisto->SetLineColor(kGreen);
1776 +  
1777 +  SysMatching->SetMaximum(3.0);
1778 +  SysMatching->SetMinimum(0.0);
1779 +  SysMatching->Draw("histo");
1780 +  SysScale->Draw("histo,same");
1781 +  SysHisto->Draw("histo,same");
1782 +  CompleteSave(kinpad,saveas+"__TTbarComparison_DerivedSystematic");
1783 +  
1784 +  delete SysMatching;
1785 +  delete SysScale;
1786 +  
1787 +  if(!Contains(variable,"gen")) {
1788 +    TH1F *hdata  = allsamples.Draw("hdata",   variable,nbins,bmin,bmax,label,"events",thiscut,data,luminosity);
1789 +    THStack smc = allsamples.DrawStack("smc",variable,nbins,bmin,bmax,label,"events",thiscut,mc,luminosity);
1790 +    
1791 +    TH1F *Systematic = (TH1F*)hdata->Clone("Systematic");
1792 +    
1793 +    for(int i=1;i<=Systematic->GetNbinsX();i++) {
1794 +      int iBin=SysHisto->FindBin(Systematic->GetBinCenter(i));
1795 +      if(iBin>SysHisto->GetNbinsX()) --iBin; // if we're over the end of the histo, use the last bin
1796 +      float sys = SysHisto->GetBinContent(iBin)-1;
1797 +      Systematic->SetBinContent(i,sys);
1798 +    }
1799 +    
1800 +    kinpad->cd();
1801 +    TLegend *leg = allsamples.allbglegend();
1802 +    hdata->Draw();
1803 +    smc.Draw("histo,same");
1804 +    hdata->Draw("same");
1805 +    leg->Draw();
1806 +    DrawPrelim();
1807 +    save_with_ratio_and_sys_band( 0.0, hdata, CollapseStack(smc), kinpad->cd(), saveas+"__DataVsMC", false, false, "data/mc",Systematic );
1808 +    
1809 +    delete Systematic;
1810 +    delete hdata;
1811 +  }
1812 +  
1813 +  
1814 +  delete SysHisto;
1815 +  delete tScaleUp;
1816 +  delete tScaleDown;
1817 +  delete tCentral;
1818 +  delete tMatchingUp;
1819 +  delete tMatchingDown;
1820 +  delete rtScaleUp;
1821 +  delete rtScaleDown;
1822 +  delete rtCentral;
1823 +  delete rtMatchingUp;
1824 +  delete rtMatchingDown;
1825 +  delete QP1;
1826 +  delete infobox;
1827 +  delete infobox2;
1828 +  delete MatchingRatio;
1829 +  delete ScaleRatio;
1830 +  delete leg2;
1831 +  CleanLegends();
1832 +  delete ca;
1833 + }
1834 +
1835 + void ProduceMCSystematicPlots() {
1836 +  cout << "Getting ready to produce systematic plots " << endl;
1837 +  TCut cutweightBKP = cutWeight;
1838 +  
1839 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor");
1840 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor");
1841 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor");
1842 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor");
1843 +  
1844 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE");
1845 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE");  
1846 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass");
1847 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass");  
1848 +  
1849 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE");
1850 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE");
1851 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass");
1852 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass");
1853 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_SameFlavor");
1854 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/ETH_OppositeFlavor");
1855 +  
1856 +  
1857 +  
1858 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1859 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1860 +  cutWeight="1.0";
1861 +  
1862 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1863 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");  
1864 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1865 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1866 +  
1867 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE__NOPURW");
1868 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE__NOPURW");
1869 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/ETH_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1870 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/ETH_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1871 +  
1872 +  
1873 +  // --------------------------------------    ***** AACHEN *****      --------------------------------------    
1874 +  
1875 +  /*
1876 +  cutWeight=cutweightBKP;
1877 +  TCut essentialcutBKP = essentialcut;
1878 +  cout << (const char*) essentialcut << endl;
1879 +  
1880 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"pt2>20","pt2>10")).c_str());
1881 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1882 +  essentialcut = TCut((ReplaceAll((const char*)essentialcut,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1883 +  
1884 +  TCut cutnJetsBKP = cutnJets;
1885 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pt2>20","pt2>10")).c_str());
1886 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2")).c_str());
1887 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta2)<1.4","abs(eta2)<2.4")).c_str());
1888 +  cutnJets = TCut((ReplaceAll((const char*)cutnJets,"abs(eta1)<1.4","abs(eta1)<2.4")).c_str());
1889 +  
1890 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor");
1891 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor");  
1892 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor");
1893 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor");
1894 +  
1895 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE");
1896 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE");  
1897 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1898 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");  
1899 +  
1900 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE");
1901 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE");
1902 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass");
1903 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass");
1904 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSSF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_SameFlavor");
1905 +  QuickProduceMCSystematicPlot("pfJetGoodNum40",8,-0.5,7.5,"NJets",cutOSOF&&cutnJets&&TCut("mll>20&&mll<70&&met[4]>100"),"MCSystPlots/NJets/Aachen_OppositeFlavor");
1906 +  
1907 +  
1908 +  
1909 +  cout << "Kicking cutWeight  " << (const char*) cutWeight << endl;
1910 +  cout << "Keeping OSSF cut " << (const char*)cutOSSF << endl;
1911 +  cutWeight="1.0";
1912 +  
1913 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1914 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");  
1915 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1916 +  QuickProduceMCSystematicPlot("genMET",20,0,200,"gen#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/genMET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");  
1917 +  
1918 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE__NOPURW");
1919 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>20&&mll<70"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE__NOPURW");
1920 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSSF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_SameFlavor_INCLUSIVE_HighMass__NOPURW");
1921 +  QuickProduceMCSystematicPlot("met[4]",20,0,200,"PF#slash{E}_{T} [GeV]",cutOSOF&&TCut("mll>120"),"MCSystPlots/MET/Aachen_OppositeFlavor_INCLUSIVE_HighMass__NOPURW");
1922 +  
1923 +  cutnJets  = cutnJetsBKP;
1924 +  cutWeight = cutweightBKP;
1925 +  essentialcut = essentialcutBKP;
1926 +  */
1927 +  write_error(__FUNCTION__,"Still need to add systematic shape");assert(0);
1928 + }
1929 +
1930 + void MakeTauPlot(string label, TCut pcut, string filename, bool TauOnly) {
1931 +  TCut cut=pcut&&basiccut;
1932 +  string variable="mll";
1933 +  string xlabel="m_{ll} [GeV]";
1934 +  int nbins=40;
1935 +  float min=0;
1936 +  float max=200;
1937 +
1938 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
1939 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity);
1940 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity);
1941 +  TH1F *tauSF = allsamples.Draw("tauSF",variable,nbins,min,max, xlabel, "events",cut&&cutOSSF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1942 +  TH1F *tauOF = allsamples.Draw("tauOF",variable,nbins,min,max, xlabel, "events",cut&&cutOSOF,data,luminosity,systsamples.FindSample("DYToTauTau"));
1943 +  datahistoSF->SetMarkerSize(DataMarkerSize);
1944 +  datahistoSF->SetMaximum(1.3*datahistoSF->GetMaximum());
1945 +  datahistoOF->SetMarkerSize(DataMarkerSize);
1946 +  datahistoOF->SetMaximum(1.3*datahistoOF->GetMaximum());
1947 +
1948 +  THStack mcstackSF   = allsamples.DrawStack("mcstackSF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSSF,mc,luminosity);
1949 +  THStack mcstackOF   = allsamples.DrawStack("mcstackOF",  variable,nbins,min,max,xlabel,"events",cut&&cutOSOF,mc,luminosity);
1950 +  datahistoSF->Draw("e1");
1951 +  ckin->Update();
1952 +  mcstackSF.Draw("histo,same");
1953 +  
1954 +  datahistoSF->Draw("same,e1");
1955 +  TLegend *kinleg = allsamples.allbglegend();
1956 +  kinleg->Draw();
1957 +  
1958 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
1959 +  kinpad->cd();
1960 +  datahistoSF->Draw("e1");
1961 +  mcstackSF.Draw("histo,same");
1962 +  datahistoSF->Draw("same,e1");
1963 +  datahistoSF->Draw("same,axis");
1964 +  kinleg->Draw();
1965 +  DrawPrelim();
1966 +  Save_With_Ratio(datahistoSF,mcstackSF,kinpad->cd(),filename+"__SF_mc");
1967 +  
1968 +  kinpad->cd();
1969 +  datahistoOF->Draw("e1");
1970 +  mcstackOF.Draw("histo,same");
1971 +  datahistoOF->Draw("same,e1");
1972 +  datahistoOF->Draw("same,axis");
1973 +  kinleg->Draw();
1974 +  DrawPrelim();
1975 +  Save_With_Ratio(datahistoOF,mcstackOF,kinpad->cd(),filename+"__OF_mc");
1976 +  
1977 +  kinpad->cd();
1978 +  tauSF->Draw("e1");
1979 +  tauOF->Draw("histo,same");
1980 +  tauSF->Draw("e1,same");
1981 +  TLegend *legtau = make_legend();
1982 +  legtau->AddEntry(tauSF,"DY->#tau#tau, SF","p");
1983 +  legtau->AddEntry(tauSF,"DY->#tau#tau, OF","l");
1984 +  legtau->Draw();
1985 +  DrawPrelim();
1986 +  Save_With_Ratio(tauSF,tauOF,kinpad->cd(),filename+"__Tau_SF_vs_OF");
1987 +  
1988 +  delete datahistoSF;
1989 +  delete datahistoOF;
1990 +  delete tauSF;
1991 +  delete tauOF;
1992 +  delete kinpad;
1993 +  delete ckin;
1994 +  CleanLegends();
1995 + }
1996 +  
1997 +
1998 + void TauQuestion() {
1999 + //   MakeTauPlot("MET>100 GeV, #geq 3 jets",cutnJets&&TCut("met[4]>100"),"TauQ/MET100_3Jets",true);
2000 + //   MakeTauPlot("MET>100 GeV",TCut("met[4]>100"),"TauQ/MET100",true);
2001 + //   MakeTauPlot("MET>0 GeV",TCut("met[4]>0"),"TauQ/MET0",true);
2002 +  MakeTauPlot("b-tag veto, 50<MET<100",TCut("pfJetGoodNumBtag30==0&&met[4]>50&&met[4]<100"),"TauQ/ControlPlots",false);
2003 + }
2004 +
2005 + void ProduceOFSFPlots(string mcjzb, string datajzb, bool isAachen) {
2006 +  string BaseMetCut="met[4]>100";
2007 +  string Prefix="ETH/";
2008 +  if(isAachen) {
2009 +    BaseMetCut="met[4]>150";
2010 +    Prefix="Aachen/";
2011 +  }
2012 + //        make_OFSF_plots("st", BaseMetCut, 20, 0, 2000., false, "S_{T}", Prefix+"FrankT");
2013 +      make_OFSF_plots("mt2j", BaseMetCut, 35, 0, 700., false, "M_{T2J}", Prefix+"MT2J");
2014 +
2015 +      make_OFSF_plots("ml1b", BaseMetCut, 20, 0, 800., false, "m_{l_{1}b}", Prefix+"ML1B");
2016 +      make_OFSF_plots("ml2b", BaseMetCut, 20, 0, 400., false, "m_{l_{2}b}", Prefix+"ML2B");
2017 +      make_OFSF_plots("min(ml1b,ml2b)", BaseMetCut, 20, 0, 400., false, "m_{lb}", Prefix+"MLB");
2018 +  
2019 + //      make_OFSF_plots(datajzb, BaseMetCut, 55, -100, 450., false, "JZB", Prefix+"JZB_In_Signal_Region");
2020 +      make_OFSF_plots("mt2", BaseMetCut, 15, 0, 150., false, "M_{T2}", Prefix+"MT2");
2021 +      make_OFSF_plots("d2", BaseMetCut, 20, 0, 200., true, "D2", Prefix+"D2");
2022 +      make_OFSF_plots("pfJetGoodNum40", BaseMetCut, 10, -0.5, 9.5, true, "N_{jets}", Prefix+"nJets");
2023 +      
2024 + //      make_OFSF_plots("mll", BaseMetCut, 60, 20., 320., false, "m_{ll}", Prefix+"mll");
2025 + //      make_OFSF_plots("leptonNum", BaseMetCut, 3, 2, 5., false, "N(leptons)", Prefix+"NLeptons");
2026 +
2027 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut,                        7, 3, 10, true, "#(jets)", Prefix+"njets");
2028 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut+"&&pfJetGoodNumBtag30==0", 7, 3, 10, true, "#(jets)", Prefix+"njets_btagVeto");
2029 + //      make_OFSF_plots("pfJetGoodNum40", BaseMetCut"&&pfJetGoodNumBtag30>0",  7, 3, 10, true, "#(jets)", Prefix+"njets_AtLeastOneBJet30");
2030  
2031 + //      make_OFSF_plots("pfJetGoodNumBtag30", BaseMetCut, 5, -0.5, 4.5, true, "N_{b-jets}", Prefix+"nbjets");
2032 + //      make_OFSF_plots("pfJetGoodPtBtag[0]", BaseMetCut+"&&pfJetGoodNumBtag30>0", 20, 0, 400, true, "p_{T}(leading b-jet)", Prefix+"ptb1");
2033 + //      make_OFSF_plots("pfJetGoodPt",  BaseMetCut, 30, 0., 400., true, "p_{T}^{J}", Prefix+"ptJet");
2034 +
2035 + //      make_OFSF_plots("iso1", BaseMetCut, 20, 0, 0.3, true, "lepton 1 isolation", Prefix+"iso1");
2036 + //      make_OFSF_plots("iso2", BaseMetCut, 20, 0, 0.3, true, "lepton 2 isolation", Prefix+"iso2");
2037 +      make_OFSF_plots("pt",  BaseMetCut, 30, 0., 300., true, "p_{ll}", Prefix+"pt");
2038 +      make_OFSF_plots("pt1",  BaseMetCut, 30, 0., 300., true, "p_{T,1}", Prefix+"pt1");
2039 +      make_OFSF_plots("pt2",  BaseMetCut, 22, 0., 220., true, "p_{T,2}", Prefix+"pt2");
2040 + //      make_OFSF_plots("eta1", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{1}", Prefix+"eta1", 0.15);
2041 + //      make_OFSF_plots("eta2", BaseMetCut, 10, -2.5, 2.5, false, "#eta_{2}", Prefix+"eta2", 0.15);
2042 + //      make_OFSF_plots("phi1", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{1}", Prefix+"phi1", 0.2);
2043 + //      make_OFSF_plots("phi2", BaseMetCut, 10, -TMath::Pi(), TMath::Pi(), false, "#phi_{2}", Prefix+"phi2", 0.2);
2044 + //      make_OFSF_plots("pfJetGoodPt[0]/pfJetGoodPt[1]", BaseMetCut, 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", Prefix+"jpt1pt2", 0.2);
2045 + //      make_OFSF_plots("TMath::Abs(pfJetDphiMet[0])", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", Prefix+"dphij1met", 0.2);
2046 +    
2047 + //      make_OFSF_plots("met[4]",  BaseMetCut, 30, 100., 400., true, "E_{T}^{miss}", Prefix+"MET");
2048 + //      make_OFSF_plots("TMath::Abs(dphi)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", Prefix+"dphi", 0.2);
2049 + //      make_OFSF_plots("TMath::Abs(dphiMet1)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", Prefix+"dphiMet1", 0.2);
2050 + //      make_OFSF_plots("TMath::Abs(dphiMet2)", BaseMetCut, 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", Prefix+"dphiMet2", 0.2);
2051 + //      make_OFSF_plots("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", Prefix+"dphilc");
2052 + //      make_OFSF_plots("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", BaseMetCut, 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", Prefix+"dphijc");
2053 + //      make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(l,MET)|)", Prefix+"dphilco");
2054 + //      make_OFSF_plots("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", BaseMetCut, 16, 0, 3.2, false, "Min(#pi - |#Delta#phi(jet,MET)|)", Prefix+"dphijco");
2055 +      
2056 + }
2057 +
2058 + void ProduceOFSFPlots(string mcjzb, string datajzb) {
2059 +  
2060 +  
2061 +  //FIRST : ETH SELECTION
2062 +  ProduceOFSFPlots(mcjzb,datajzb,0); // this is the ETH selection
2063 +  
2064 +  
2065 +  
2066 +  string backup_cutnJets = (const char*)cutnJets;
2067 +  cutnJets = ReplaceInCut(cutnJets,"pfJetGoodNum40>=3","pfJetGoodNum40>=2");
2068 +  cutnJets = ReplaceInCut(cutnJets,"1.4","2.4");
2069 +  
2070 +  string backup_basiccut = (const char*)basiccut;
2071 +  basiccut = ReplaceInCut(basiccut,"1.4","2.4");
2072 +  
2073 +  string backup_essential = (const char*) essentialcut;
2074 +  essentialcut = ReplaceInCut(essentialcut,"1.4","2.4");
2075 +  
2076 +  ProduceOFSFPlots(mcjzb,datajzb,1); // this is the Aachen selection
2077 +  
2078 +  cutnJets     = TCut(backup_cutnJets.c_str());
2079 +  basiccut     = TCut(backup_basiccut.c_str());
2080 +  essentialcut = TCut(backup_essential.c_str());
2081   }
2082 +  
2083  
2084   void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
2085   {
2086 + //  switch_overunderflow(true);
2087    bool dolog=true;
2088    bool nolog=false;
2089 +
2090 +  bool doOFSF = true;
2091 +  bool doKin  = false;
2092 +  bool doDataComp = false;
2093 +  bool MakeTwoThreeJetComparison = false;
2094 +  
2095 +
2096    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
2097 <  float mll_low=40;
2097 >  float mll_low=50;
2098    float mll_hi=160;
2099    if(!PlottingSetup::RestrictToMassPeak) {
2100 <        mll_low=30;
2101 <        mll_hi=180;
2100 >        mll_low=20;
2101 >        mll_hi=320;
2102 >  }
2103 >  
2104 >  if(MakeTwoThreeJetComparison) MakeElegantTwoThreeComparisons();
2105 >  
2106 >  //TauQuestion();
2107 >
2108 >  //ProduceJanPlots();
2109 >  //ProduceMCSystematicPlots();
2110 >  //assert(0);
2111 > //  make_plain_kin_plot("pt",Cut2Str(cutOSSF&&TCut("mll>20&&pfJetGoodNumBtag30>=2")),40,0,200,nolog,"Z p_{T}","PlotForKostas",doPF,true);
2112 >  
2113 >  if ( doOFSF ) ProduceOFSFPlots(mcjzb,datajzb);
2114 >  assert(0);
2115 >
2116 >  if ( doDataComp) {
2117 >    TCut mllCut("");
2118 >    float massmin = 15.;
2119 >    float massmax = 315;
2120 >    int massnbins = 60;
2121 > /*    if ( !PlottingSetup::openBox ) {
2122 >      mllCut = "mll>70";
2123 >      massmin = 120;
2124 >      massmax = 360;
2125 >      massnbins = 14;
2126 >    }*/
2127 >
2128 >    TCut cutSignal = cutmass&&cutnJets&&"met[4]>100";
2129 >    
2130 >    make_data_comparison_plot("numVtx", "",40, -0.5, 39.5,-1., true, "N(Vertices)", "numVtx");
2131 >    make_data_comparison_plot("pfJetGoodEta[0]", "",50, -3.0, 3.0,-1., true, "N(Jets)", "pfJetGoodEta0");
2132 >    
2133 >    
2134 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF,10, -0.5, 9.5,-1., true, "N(Jets)", "njets_OF");
2135 >    make_data_comparison_plot("met[4]", cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_inclusive");
2136 >    make_data_comparison_plot("met[1]", cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_inclusive");
2137 >    make_data_comparison_plot("met[4]", cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_inclusive");
2138 >    make_data_comparison_plot("met[1]", cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_inclusive");
2139 >    
2140 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "pfMET", "met_SF_exclusive");
2141 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSSF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_SF_exclusive");
2142 >    make_data_comparison_plot("met[4]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "pfMET", "met_OF_exclusive");
2143 >    make_data_comparison_plot("met[1]", cutnJets&&cutOSOF,60, 0., 300.,-1., true, "type 1 corrected pfMET", "mett1_OF_exclusive");
2144 >
2145 >  
2146 >    string basiccutsaved = (const char*)basiccut;
2147 >    
2148 >    string newbasiccut=basiccutsaved;
2149 >    
2150 >    size_t found;
2151 >    found = newbasiccut.find( "pt2>20" );
2152 >    while (found!=string::npos){
2153 >      newbasiccut.replace( found, string( "pt2>20" ).length(), "pt2>10" );
2154 >      found = newbasiccut.find( "pt2>20" );
2155 >    }
2156 >    basiccut=TCut(newbasiccut.c_str());
2157 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSSF,60, 0., 300.,-1., false, "mll", "mll_SF_Aachen_pt2010_met");
2158 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[4]>150")&&cutOSOF,60, 0., 300.,-1., false, "mll", "mll_OF_Aachen_pt2010_met");
2159 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_Aachen_pt2010_t1cpfmet");
2160 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=2&&met[1]>150")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_Aachen_pt2010_t1cpfmet");
2161 >    basiccut=TCut(basiccutsaved.c_str());
2162 >    
2163 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF, 8, 0., 8.,-1., true, "#(jets)", "njets_SF");
2164 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF, 8, 0., 8.,-1., true, "#(jets)", "njets_OF");
2165 >    
2166 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_met");
2167 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[4]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_met");
2168 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSSF,60, 0., 300.,-1., true, "mll", "mll_SF_ETH_t1cpfmet");
2169 >    make_data_comparison_plot("mll", TCut("pfJetGoodNum40>=3&&met[1]>100")&&cutOSOF,60, 0., 300.,-1., true, "mll", "mll_OF_ETH_t1cpfmet");
2170 >
2171 >    
2172 >    make_data_comparison_plot("mll", cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive");
2173 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_ee");
2174 >    make_data_comparison_plot("mll", cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_inclusive_mm");
2175 >    make_data_comparison_plot("mll", cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_inclusive");
2176 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==0"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_ee");
2177 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF&&TCut("id1==1"),60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive_mm");
2178 >    make_data_comparison_plot("mll", cutnJets&&cutOSSF,60, 15., 315.,-1., true, "m_{ll}", "mll_SF_exclusive");
2179 >    make_data_comparison_plot("mll", cutnJets&&cutOSOF,60, 15., 315.,-1., true, "m_{ll}", "mll_OF_exclusive");
2180 >
2181 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig");
2182 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut,           massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2183 >    
2184 >    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");
2185 >    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");
2186 >    
2187 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_btagVeto");
2188 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30==0", massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_btagVeto");
2189 >    
2190 >    make_data_comparison_plot("mll", cutOSSF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_SF_sig_AtLeastOneBJet");
2191 >    make_data_comparison_plot("mll", cutOSOF&&cutSignal&&mllCut&&"pfJetGoodNumBtag30>0",  massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig_AtLeastOneBJet");
2192 >
2193 >
2194 >    make_data_comparison_plot("mll", mllCut&&cutOSOF&&cutSignal, massnbins, 15., 315.,-1., false, "m_{ll}", "mll_OF_sig");
2195 >    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");
2196 >    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");
2197 >
2198 >    make_data_comparison_plot("pfJetGoodNum40", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_SF_sig");
2199 >    make_data_comparison_plot("pfJetGoodNum40", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(jets)", "njets_OF_sig");
2200 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSSF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_SF_sig");
2201 >    make_data_comparison_plot("pfJetGoodNumBtag30", cutOSOF&&cutSignal&&mllCut, 8, 0., 8.,-1., false, "#(b-jets)", "nbjets_OF_sig");
2202 >
2203 >  }
2204 >
2205 >
2206 >  if ( doKin ) {
2207 >    string mllCut("");
2208 >    
2209 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_SF",doPF,true);
2210 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>20")),56,20,300,dolog,"m_{ll}","NoPreselection/mll_OF",doPF,true);
2211 >
2212 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_SF",doPF,true);
2213 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"E_{T}^{miss}","NoPreselection/met_OF",doPF,true);
2214 >
2215 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_SF",doPF,true);
2216 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&TCut("mll>20")),20,0,800,dolog,"H_{T}","NoPreselection/HT_OF",doPF,true);
2217 >    
2218 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_SF",doPF,true);
2219 >    make_plain_kin_plot("pfJetGoodNum40",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{jets}","NoPreselection/NJets_OF",doPF,true);
2220 >    
2221 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSSF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_SF",doPF,true);
2222 >    make_plain_kin_plot("pfJetGoodNumBtag30",Cut2Str(cutOSOF&&TCut("mll>20")),10,-0.5,9.5,dolog,"n_{btags}","NoPreselection/NBTags_OF",doPF,true);
2223 >    
2224 >    make_plain_kin_plot("pt1",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_SF",doPF,true);
2225 >    make_plain_kin_plot("pt1",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{1}","NoPreselection/Pt1_OF",doPF,true);
2226 >    
2227 >    make_plain_kin_plot("pt2",Cut2Str(cutOSSF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_SF",doPF,true);
2228 >    make_plain_kin_plot("pt2",Cut2Str(cutOSOF&&TCut("mll>20")),80,0,400,dolog,"p_{T}^{2}","NoPreselection/Pt2_OF",doPF,true);
2229 >    
2230 >    
2231 >    assert(0);
2232 >    make_plain_kin_plot("mll",Cut2Str(cutOSSF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_SF",doPF,true);
2233 >    make_plain_kin_plot("mll",Cut2Str(cutOSOF&&TCut("mll>60&&mll<120")),60,60,120,dolog,"m_{ll}","TestingLuminosity_OF",doPF,true);
2234 >  
2235 >    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);
2236 >    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);
2237 >    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);
2238 >    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);
2239 >
2240 >    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);
2241 >    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);
2242 >    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);
2243 >    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);
2244 >
2245 >
2246 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets),120,0,1200,dolog,"H_{T}","HT_3jets_OF",doPF,true);
2247 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF",doPF,true);
2248 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSOF&&cutnJets&&TCut("met[4]>100")),120,0,1200,dolog,"H_{T}","HT_3jets_OF_MET100",doPF,true);
2249 >    make_plain_kin_plot("pfTightHT",Cut2Str(cutOSSF&&cutnJets&&TCut("met[4]>100")) ,120,0,1200,dolog,"H_{T}","HT_3jets_SF_MET100",doPF,true);
2250 >
2251 >    
2252 >    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);
2253 >    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);
2254 >    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);
2255 >    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);
2256 >
2257 >    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);
2258 >    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);
2259 >    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);
2260 >    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);
2261 >
2262 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_SF_20to70",doPF,true);
2263 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>20&&mll<70")),50,0,300,dolog,"PFMET","MET_OF_20to70",doPF,true);
2264 >    
2265 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSSF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_SF_above120",doPF,true);
2266 >    make_plain_kin_plot("met[4]",Cut2Str(cutOSOF&&cutnJets&&TCut("mll>120")),50,0,300,dolog,"PFMET","MET_OF_above120",doPF,true);
2267 >    
2268 >    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);
2269 >    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);
2270 >    
2271 >    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);
2272 >    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);
2273 >
2274 >    
2275 >    make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
2276 >    make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
2277 >    // Plots in signal region
2278 >    make_kin_plot("met[4]","",70,0,350,dolog,"#slash{E}_{T} [GeV]","met",doPF,true);
2279 >
2280 >
2281 >    make_kin_plot("MetFactor","",20,0,2,nolog,"MetFactor","MetFactor",doPF,true);
2282 >    
2283 >    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");
2284 >    /*
2285 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_30to70_0j");
2286 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_30to70_1j");
2287 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_30to70_2j");
2288 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_30to70_3j");
2289 >
2290 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_SF_30to70_0j");
2291 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_SF_30to70_1j");
2292 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_SF_30to70_2j");
2293 >    DoMCSystPlot("met[4]",40,0,400,(cutOSSF&&TCut("mll>30&&mll<70&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_SF_30to70_3j");
2294 >
2295 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==0")),dolog,"PFMET","Debunking/MET_OF_Z_0j");
2296 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfJetGoodNum40==1")),dolog,"PFMET","Debunking/MET_OF_Z_1j");
2297 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==2")),dolog,"PFMET","Debunking/MET_OF_Z_2j");
2298 >    DoMCSystPlot("met[4]",40,0,400,(cutOSOF&&TCut("mll>80&&mll<100&&pfTightHT>100&&pfJetGoodNum40==3")),dolog,"PFMET","Debunking/MET_OF_Z_3j");
2299 >
2300 >    
2301 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll");
2302 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==0"),dolog,"m_{ll} [GeV]","kinSys/mll_ee");
2303 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSSF&&TCut("id1==1"),dolog,"m_{ll} [GeV]","kinSys/mll_mm");
2304 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutnJets&&cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_osof");
2305 >
2306 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSSF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive");
2307 >    DoMCSystPlot("mll", (int)((mll_hi-mll_low)/5),mll_low,mll_hi,cutOSOF,dolog,"m_{ll} [GeV]","kinSys/mll_inclusive_osof");
2308 >
2309 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSSF,dolog,"nJets","kinSys/nJets_ossf");
2310 >    DoMCSystPlot("pfJetGoodNum40", 9,-0.5,8.5,cutOSOF,dolog,"nJets","kinSys/nJets_osof");
2311 >    
2312 >    DoMCSystPlot("pfJetGoodPt[0]/pfJetGoodPt[1]",45,1,10,cutnJets&&cutOSSF,dolog,"p_{T}^{J1} / p_{T}^{J2}","kinSys/j1j2ratio");
2313 >    DoMCSystPlot("TMath::Abs(pfJetDphiMet[0])",32,0,3.2,cutnJets&&cutOSSF,dolog,"|#Delta#phi(jet1,MET)|","kinSys/dphiJ1MET");
2314 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSSF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_SFZP");
2315 >    DoMCSystPlot(datajzb,mcjzb, (int)((PlottingSetup::jzbHigh+110)/10),-110,PlottingSetup::jzbHigh,cutnJets&&cutOSOF&&Restrmasscut,dolog,"m_{ll} [GeV]","kinSys/jzb_OS_OFZP");
2316 >
2317 >    make_kin_plot("mll","mll>20"+mllCut,(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2318 >    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);
2319 >    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);
2320 >    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);
2321 >    
2322 >    make_kin_plot("pfJetGoodNum40",mllCut,9,-0.5,8.5,dolog,"nJets","nJets",doPF);
2323 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
2324 >    
2325 >    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);
2326 >    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);
2327 >    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);
2328 >    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);
2329 >    
2330 >    
2331 >    make_kin_plot("pfJetGoodNum40","met[4]>100"+mllCut,9,-0.5,8.5,dolog,"nJets","nJets_met100",doPF);
2332 >    make_kin_plot("pfJetGoodNum40","met[4]>100",9,-0.5,8.5,dolog,"nJets","nJets_osof_met100",doPF);
2333 >
2334 >    // Further inclusive invariant mass plots
2335 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2336 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2337 >    make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2338 >    make_kin_plot("mll",mllCut,(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2339 >    
2340 >    make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2341 >    //if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
2342 >    
2343 >    
2344 >    // Number of jets
2345 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_inclusive",doPF);
2346 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof_inclusive",doPF);
2347 >    make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
2348 >    
2349 >    // Others
2350 >    make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
2351 >    //  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
2352 >    //  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
2353 >    make_kin_plot("pt","",50,0,500,dolog,"Z p_{T} [GeV]","Zpt",doPF);
2354 >    make_kin_plot("pt1","",50,0,200,nolog,"p_{T} [GeV]","pt1",doPF);
2355 >    make_kin_plot("pt2","",50,0,200,nolog,"p_{T} [GeV]","pt2",doPF);
2356 >    make_kin_plot("eta1","",40,-3,3,nolog,"#eta_{l}","eta",doPF);
2357 >    make_kin_plot("jzb[1]","",100,-150,200,dolog,"JZB [GeV]","jzb_ossf",doPF);
2358 >    //   stringstream jzbcut;
2359 >    //   jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
2360 >    //   make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2361 >    //   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);
2362 >    //   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);
2363 >    //   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);
2364 >    //   stringstream jzbcut2;
2365 >    //   jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
2366 >    //   make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
2367 >    //   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);
2368 >    //   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);
2369 >    //   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);
2370 >    //   stringstream jzbcut3;
2371 >    //   jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
2372 >    //   make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);  
2373 >    //   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);
2374 >    //   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);  
2375 >    //   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);  
2376 >    
2377 >    //   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);
2378 >    //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);
2379 >    //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);*/
2380    }
2381 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
2382 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
2383 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
2384 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
2385 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
2386 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
2387 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
2388 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
2389 <  make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
2390 <  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
2391 <  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
2392 <  make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
2393 <  make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
365 <  make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
366 <  make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
367 <  make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
368 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
369 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
370 <  if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
371 <  stringstream jzbcut;
372 <  jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
373 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
2381 >    
2382 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
2383 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
2384 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
2385 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
2386 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
2387 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
2388 >   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
2389 > /*
2390 >   make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
2391 >   make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
2392 > */
2393 >  switch_overunderflow(false);
2394   }
2395  
2396   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
2397                       int nbins, float xmin, float xmax, bool log,
2398                       float ymin=0, float ymax=0, bool leftJustified=false ) {
2399 <      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
2399 >  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
2400  
2401    TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
2402    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__));
2403 <  if(var=="numVtx") cutWeight=TCut("1.0");
2403 >  //if(var=="numVtx") cutWeight=TCut("1.0");
2404    TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
2405    TCut jzbMC[]  = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
2406  
2407    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- below: the next ~20 lines changed!
2408    int nRegions=4;
2409 <  if(!PlottingSetup::RestrictToMassPeak) {
2409 >  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
2410      nRegions=2;
2411    }
2412    
# Line 404 | Line 2424 | void make_comp_plot( string var, string
2424        TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
2425        ccomp->SetLogy(log);
2426        TH1F *datahisto = allsamples.Draw("datahisto",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
2427 <      TH1F *lm4histo = signalsamples.Draw("lm4histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
2427 >      TH1F *lm3histo  = signalsamples.Draw("lm3histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],data,luminosity,signalsamples.FindSample("LM3"));
2428        THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],  mc,  luminosity);
2429        datahisto->SetMarkerSize(DataMarkerSize);
2430        if (ymax>ymin) datahisto->SetMaximum(ymax);
2431 <      lm4histo->SetLineStyle(2);
2431 >      lm3histo->SetLineStyle(2);
2432        datahisto->Draw("e1");
2433 <      mcstack.Draw("same");
2433 >      mcstack.Draw("histo,same");
2434        datahisto->Draw("same,e1");
2435 < //      lm4histo->Draw("hist,same");
2435 >      lm3histo->Draw("hist,same");
2436        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
2437        if ( leftJustified ) {
2438          Float_t w = kinleg->GetX2()-kinleg->GetX1();
2439          kinleg->SetX1(0.2);
2440          kinleg->SetX2(0.2+w);
2441        }
2442 < //      kinleg->AddEntry(lm4histo,"LM4","l");
2442 >      kinleg->AddEntry(lm3histo,"LM3","l");
2443        kinleg->Draw();
2444        TText* write_variable = write_text(0.99,0.01,var);
2445        write_variable->SetTextAlign(31);
# Line 428 | Line 2448 | void make_comp_plot( string var, string
2448        CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
2449        delete datahisto;
2450        delete ccomp;
2451 <      delete lm4histo;
2451 >      delete lm3histo;
2452      }
2453    cutWeight=weightbackup;
2454   }
# Line 438 | Line 2458 | void region_comparison_plots(string mcjz
2458    dout << "Creating comparison plots for signal and control regions" << endl;
2459    // Compare a few quantities in the signal region and all 7 control regions
2460  
2461 <  switch_overunderflow(true);  // switching overflow/underflow bins on
2461 > //  switch_overunderflow(true);  // switching overflow/underflow bins on
2462      
2463 <  
2463 >  switch_overunderflow(true);
2464      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
2465 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
2465 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2466      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
2467      float mll_low=50;float mll_high=170;
2468      if(!PlottingSetup::RestrictToMassPeak) {
2469 <        mll_high=200;
2470 <        mll_low=50;
2469 >        mll_high=300;
2470 >        mll_low=20;
2471      }
2472 <    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,30,mll_low,mll_high,false,0,16.);
2473 <    make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2474 <    make_comp_plot("pfJetGoodNum","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2472 >    make_comp_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",jzbcut,mcjzb,datajzb,100,0,10,true);
2473 >    make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
2474 >
2475 >    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
2476 >    make_comp_plot("met[4]","E_{T}^{miss} [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
2477 >    make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2478 >    make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
2479      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
2480 <    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,20,0.,20.,false,0,16.);
2480 >    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,40,0.,40.,false,0,16.);
2481      make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2482      make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
2483 +    make_comp_plot("eta1","#eta_1","eta1",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2484 +    make_comp_plot("eta2","#eta_2","eta2",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
2485    }
2486  
2487    switch_overunderflow(false); // switching overflow/underflow bins off
# Line 479 | Line 2505 | void signal_bg_comparison()
2505    
2506    float simulatedlumi=luminosity;//in pb please - adjust to your likings
2507    
2508 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
2509 <  TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
2508 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
2509 >  TH1F *JZBplotLM4;
2510 >  if(PlottingSetup::RestrictToMassPeak) JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
2511 >  else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
2512    TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
2513    
2514    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
# Line 504 | Line 2532 | void signal_bg_comparison()
2532    TLegend *signal_bg_comparison_leg2 =  make_legend("",0.55,0.75,false);
2533    signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
2534    signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
2535 <  signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
2535 >  if(PlottingSetup::RestrictToMassPeak) signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
2536 >  else signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM3","f");
2537    signal_bg_comparison_leg2->Draw();
2538    DrawMCPrelim(simulatedlumi);
2539    CompleteSave(can,"jzb_bg_vs_signal_distribution");
# Line 651 | Line 2680 | vector<TF1*> do_extended_fit_to_plot(TH1
2680   //      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)
2681    TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
2682    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2683 <  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);
2683 >  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);
2684  
2685  
2686    TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
# Line 746 | Line 2775 | if you want to start from scratch (witho
2775    return return_functions;
2776   }
2777  
2778 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false )
2778 > void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
2779   {
2780 +  
2781    bool is_data=false;
2782    bool use_signal=false;
2783    if(use_data==1) is_data=true;
2784    if(use_data==2) use_signal=true;
2785 <  int nbins=50;//100;
2786 <  if(is_data) nbins=50;
2785 >  int nbins=int(high/10);//100;
2786 >  if(is_data) nbins=int(high/10);
2787    float low=0;
2788 <  float hi=500;
2788 >  float hi=high;
2789 >  
2790 >  stringstream cutpositiveS;
2791 >  cutpositiveS << "(" << jzb << ">0)";
2792 >  TCut cutpositive(cutpositiveS.str().c_str());
2793 >  stringstream cutnegativeS;
2794 >  cutnegativeS << "(" << jzb << "<0)";
2795 >  TCut cutnegative(cutnegativeS.str().c_str());
2796 >  
2797 >  
2798    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
2799 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2800 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2801 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2802 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2799 >  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2800 >  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2801 >  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2802 >  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2803 >
2804    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
2805    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
2806    blankback->GetXaxis()->CenterTitle();
# Line 774 | Line 2814 | void do_prediction_plot(string jzb, TCan
2814    
2815    TH1F *RcorrJZBeemmNoS;
2816  
2817 <    //these are for the ratio
2818 <  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2819 <  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2820 <  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2821 <  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2817 >  //these are for the ratio
2818 >  TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2819 >  TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2820 >  TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2821 >  TH1F *JLcorrJZBem     = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2822    
2823    TH1F *JRcorrJZBSBem;
2824    TH1F *JLcorrJZBSBem;
2825    TH1F *JRcorrJZBSBeemm;
2826    TH1F *JLcorrJZBSBeemm;
2827    
2828 <  if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
2828 >  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);
2829  
2830    
2831 <  if(PlottingSetup::RestrictToMassPeak) {
2832 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2833 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2834 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2835 <    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2836 <
2831 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2832 >    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2833 >    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2834 >    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2835 >    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2836 >    
2837      //these are for the ratio
2838 <    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2839 <    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2840 <    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2841 <    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
802 <
2838 >    JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2839 >    JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
2840 >    JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutpositive&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2841 >    JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutnegative&&sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
2842    }
2843    
2844    TH1F *lm4RcorrJZBeemm;
2845 <  if(overlay_signal || use_data == 2 ) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM4"));
2845 >  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"));
2846    
2847    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
2848    
# Line 812 | Line 2851 | void do_prediction_plot(string jzb, TCan
2851      
2852    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2853    TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
2854 <  if(PlottingSetup::RestrictToMassPeak) {
2854 >    
2855 >  TH1F *BpredSys = new TH1F("Bpredsys","Bpredsys",PlottingSetup::global_ratio_binning.size()-1,&PlottingSetup::global_ratio_binning[0]);
2856 >  ClearHisto(BpredSys);
2857 >    
2858 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2859      Bpred->Add(RcorrJZBem,1.0/3.);
2860      Bpred->Add(LcorrJZBem,-1.0/3.);
2861      Bpred->Add(RcorrJZBSBem,1.0/3.);
# Line 834 | Line 2877 | void do_prediction_plot(string jzb, TCan
2877      JBpred->Add(JLcorrJZBSBem,-1.0/3.);
2878      JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
2879      JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
2880 +      
2881 +    //Systematics:
2882 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertONPEAK*zjetsestimateuncertONPEAK);
2883 +    AddSquared(BpredSys,JRcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2884 +    AddSquared(BpredSys,JLcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
2885 +    AddSquared(BpredSys,JRcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2886 +    AddSquared(BpredSys,JLcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
2887 +    AddSquared(BpredSys,JRcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2888 +    AddSquared(BpredSys,JLcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
2889    } else {
2890      Bpred->Add(RcorrJZBem,1.0);
2891      Bpred->Add(LcorrJZBem,-1.0);
# Line 843 | Line 2895 | void do_prediction_plot(string jzb, TCan
2895      //these are for the ratio
2896      JBpred->Add(JRcorrJZBem,1.0);
2897      JBpred->Add(JLcorrJZBem,-1.0);
2898 +      
2899 +    //Systematics
2900 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertOFFPEAK*zjetsestimateuncertOFFPEAK);
2901 +    AddSquared(BpredSys,JRcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2902 +    AddSquared(BpredSys,JLcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
2903 +
2904    }
2905      
2906 <  
2907 <  
2906 >  SQRT(BpredSys);
2907 >  BpredSys->Divide(JBpred);
2908 >
2909    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
2910    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
2911    Tpred->Add(LcorrJZBem,-1.0);
2912 <  if(PlottingSetup::RestrictToMassPeak) {
2912 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
2913      Tpred->Add(RcorrJZBSBem,1.0);
2914      Tpred->Add(LcorrJZBSBem,-1.0);
2915      Tpred->Add(RcorrJZBSBeemm,1.0);
# Line 890 | Line 2949 | void do_prediction_plot(string jzb, TCan
2949    blankback->Draw();
2950    if(use_data==1)
2951    {
2952 +    //Bpred->SetLineWidth(3); //paper style.overruled.
2953 +    //lm4RcorrJZBeemm->SetLineWidth(3); //paper style.overruled.
2954      analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
2955      kinpad->cd();//necessary because the extended fit function creates its own canvas
2956      RcorrJZBeemm->Draw("e1x0,same");
2957  
2958      Bpred->Draw("hist,same");
2959 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2959 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2960      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2961 +    //lm4RcorrJZBeemm->Draw("hist,same");
2962      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
2963      legBpred->AddEntry(Bpred,"predicted","l");
2964 <    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2965 <    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2966 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
2964 > //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
2965 > //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
2966 > //     legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
2967      legBpred->Draw();
2968      DrawPrelim();
2969  
2970      //this plot shows what the prediction is composed of
2971 <    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
2972 <    specialcanv->SetLogy(1);
2973 <    Zjetspred->SetFillColor(kYellow);
2974 <    Zjetspred->SetLineColor(kYellow);
2975 <    TTbarpred->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2976 <    TTbarpred->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2971 >    TPad *predcomppad = new TPad("predcomppad","predcomppad",0,0,1,1);
2972 >    float CurrentBpredLineWidth=Bpred->GetLineWidth();
2973 >    Bpred->SetLineWidth(2);
2974 >    predcomppad->cd();
2975 >    predcomppad->SetLogy(1);
2976 >    TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
2977 >    TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
2978 >    sidebandsemu->Add(jzbnegative,-1);
2979 >    
2980 >    jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
2981 >    jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
2982 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2983 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
2984 >    
2985      THStack predcomposition("predcomposition","prediction composition");
2986 <    predcomposition.Add(TTbarpred);
2987 <    predcomposition.Add(Zjetspred);
2986 >    predcomposition.Add(sidebandsemu);
2987 >    predcomposition.Add(jzbnegative);
2988      blankback->Draw();
2989      RcorrJZBeemm->Draw("e1x0,same");
2990      predcomposition.Draw("histo,same");//
2991      Bpred->Draw("hist,same");
2992 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2992 > //    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
2993      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
2994 <    legBpred->Draw();
2994 > //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
2995 >    lm4RcorrJZBeemm->SetLineWidth(2);
2996 >    //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
2997 > //     lm4RcorrJZBeemm->Draw("histo,same");
2998      DrawPrelim();
2999 <    TLegend *specialleg = new TLegend(0.6,0.4,0.89,0.55);
3000 <    specialleg->SetFillColor(kWhite);specialleg->SetLineColor(kWhite);
3001 <    specialleg->AddEntry(Zjetspred,"Z+Jets prediction","f");
3002 <    specialleg->AddEntry(TTbarpred,"t#bar{t} prediction","f");
3003 <    specialleg->Draw("same");
3004 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionComposition");
3005 <
3006 <    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
2999 >    TLegend *speciallegBpred = make_legend("",0.45,0.55);
3000 >    //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
3001 >    speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
3002 >    speciallegBpred->AddEntry(Bpred,"Total background","l");
3003 >    speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
3004 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
3005 >    else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
3006 > //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
3007 > //     speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3008 >    speciallegBpred->Draw();
3009 >    Save_With_Ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
3010 >    delete predcomppad;
3011 >    
3012 >    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
3013 >    specialcanv->SetLogy(1);
3014 > //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
3015      blankback->Draw();
3016 <    kostack.Draw("same");
3016 > //    kostack.Draw("same");
3017 >    predcomposition.Draw("hist");
3018      Bpred->Draw("hist,same");
3019 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3019 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
3020      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3021      legBpred->Draw();
3022      DrawPrelim();
3023 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionCompositioninMC");
3023 >    CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
3024 >    Bpred->SetLineWidth((int)CurrentBpredLineWidth);
3025 >    
3026      
3027 <    delete specialcanv;
3028 <    delete specialleg;
3027 >    //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;
3028 >    
3029 >    delete speciallegBpred;
3030      delete Zjetspred;
3031      delete TTbarpred;
3032      
# Line 949 | Line 3034 | void do_prediction_plot(string jzb, TCan
3034    }
3035    if(use_data==0) {
3036      RcorrJZBeemm->Draw("e1x0,same");
3037 +    //Bpred->SetLineWidth(3); // paper style. overruled.
3038      Bpred->Draw("hist,same");
3039      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3040 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
3041 <    legBpred->AddEntry(Bpred,"MC predicted","l");
3040 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
3041 >    legBpred->AddEntry(Bpred,"MC predicted","l");    
3042      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
3043      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
3044 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3044 > //     if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3045      legBpred->Draw();
3046      DrawMCPrelim();
3047      Bpredsaveas="Bpred_MC";
# Line 963 | Line 3049 | void do_prediction_plot(string jzb, TCan
3049    }
3050    if(use_data==2) {
3051      RcorrJZBeemm->Draw("e1x0,same");
3052 +    //Bpred->SetLineWidth(3); // paper style. overruled.
3053      Bpred->Draw("hist,same");
3054      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3055 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
3055 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
3056      legBpred->AddEntry(Bpred,"MC predicted","l");
3057 <    legBpred2->AddEntry(RcorrJZBeemm,"MC observed","p");
3057 >    legBpred2->AddEntry(RcorrJZBeemm,"MC true","p");
3058      legBpred2->AddEntry(Bpred,"MC predicted","l");
3059      {
3060        if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
# Line 978 | Line 3065 | void do_prediction_plot(string jzb, TCan
3065   //      CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
3066      }
3067      {
3068 +      //lm4RcorrJZBeemm->SetLineWidth(3); //paper style. overruled.
3069 +      //RcorrJZBeemmNoS->SetLineWidth(3); //paper style. overruled.
3070 +      //lm4RcorrJZBeemm->SetLineStyle(2); //paper style. overruled.
3071 +      //RcorrJZBeemmNoS->SetLineStyle(3); //paper style. overruled.
3072 +      //lm4RcorrJZBeemm->SetLineColor(kOrange+1); //paper style. overruled.
3073 +      
3074        RcorrJZBeemmNoS->SetLineStyle(2);
3075        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
3076 <      legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3076 > //       legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
3077        legBpred2->Draw();
3078        RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
3079        RcorrJZBeemmNoS->Draw("histo,same");
# Line 996 | Line 3089 | void do_prediction_plot(string jzb, TCan
3089    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3090    string ytitle("ratio");
3091    if ( use_data==1 ) ytitle = "data/pred";
3092 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3093 <
3092 >  //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
3093 >  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
3094    
3095 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1003 <  /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1004 <  if(!PlottingSetup::RestrictToMassPeak) return;
1005 <  TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1006 <  Bpredem->Add(RcorrJZBem);
1007 <  Bpredem->Add(LcorrJZBem,-1);
1008 <  TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1009 <  BpredSBem->Add(RcorrJZBSBem);
1010 <  Bpred->Add(LcorrJZBSBem,-1);
1011 <  TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
1012 <  BpredSBeemm->Add(RcorrJZBSBeemm);
1013 <  BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1014 <  globalcanvas->cd();
1015 <  globalcanvas->SetLogy(1);
3095 >  delete kinpad;
3096  
1017  RcorrJZBeemm->SetMarkerStyle(20);
1018  RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1019  blankback->Draw();
1020  RcorrJZBeemm->Draw("e1x0,same");
1021  RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1022  
1023  Bpredem->SetLineColor(kRed+1);
1024  Bpredem->SetStats(0);
1025  Bpredem->Draw("hist,same");
1026
1027  BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1028  BpredSBem->SetLineStyle(2);
1029  BpredSBem->Draw("hist,same");
1030
1031  BpredSBeemm->SetLineColor(kBlue+1);
1032  BpredSBeemm->SetLineStyle(3);
1033  BpredSBeemm->Draw("hist,same");
1034  RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3097  
3098 <  TLegend *legBpredc = make_legend("",0.6,0.55);
3099 <  if(use_data==1)
3100 <  {
3101 <    legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3102 <    legBpredc->AddEntry(Bpredem,"OFZP","l");
3103 <    legBpredc->AddEntry(BpredSBem,"OFSB","l");
3104 <    legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3105 <    legBpredc->Draw();
3106 <    CompleteSave(globalcanvas,"Bpred_Data_comparison");
3107 <  }
3108 <  if(use_data==0) {
3109 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
3110 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3111 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3112 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3113 <    legBpredc->Draw();
3114 <    CompleteSave(globalcanvas,"Bpred_MC_comparison");
3115 <  }
3116 <  if(use_data==2) {
3117 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
3118 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3119 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3120 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3121 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3122 <    legBpredc->Draw();
3123 <    CompleteSave(globalcanvas,"Bpred_MCwithS_comparison");
3098 >  
3099 >  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3100 >  // The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
3101 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3102 >    TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
3103 >    Bpredem->Add(RcorrJZBem);
3104 >    Bpredem->Add(LcorrJZBem,-1);
3105 >    TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
3106 >    BpredSBem->Add(RcorrJZBSBem);
3107 >    Bpred->Add(LcorrJZBSBem,-1);
3108 >    TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
3109 >    BpredSBeemm->Add(RcorrJZBSBeemm);
3110 >    BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
3111 >    globalcanvas->cd();
3112 >    globalcanvas->SetLogy(1);
3113 >    
3114 >    RcorrJZBeemm->SetMarkerStyle(20);
3115 >    RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
3116 >    blankback->Draw();
3117 >    RcorrJZBeemm->Draw("e1x0,same");
3118 >    RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
3119 >    
3120 >    Bpredem->SetLineColor(kRed+1);
3121 >    Bpredem->SetStats(0);
3122 >    Bpredem->Draw("hist,same");
3123 >    
3124 >    BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
3125 >    BpredSBem->SetLineStyle(2);
3126 >    BpredSBem->Draw("hist,same");
3127 >    
3128 >    BpredSBeemm->SetLineColor(kBlue+1);
3129 >    BpredSBeemm->SetLineStyle(3);
3130 >    BpredSBeemm->Draw("hist,same");
3131 >    RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3132 >    
3133 >    TLegend *legBpredc = make_legend("",0.6,0.55);
3134 >    if(use_data==1)
3135 >    {
3136 >      legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
3137 >      legBpredc->AddEntry(Bpredem,"OFZP","l");
3138 >      legBpredc->AddEntry(BpredSBem,"OFSB","l");
3139 >      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
3140 >      legBpredc->Draw();
3141 >      CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
3142 >    }
3143 >    if(use_data==0) {
3144 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3145 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3146 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3147 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3148 >      legBpredc->Draw();
3149 >      CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
3150 >    }
3151 >    if(use_data==2) {
3152 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
3153 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
3154 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
3155 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
3156 > //       if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
3157 >      legBpredc->Draw();
3158 >      CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
3159 >    }
3160    }
3161 +  
3162 +  TFile *f = new TFile("tester.root","RECREATE");
3163 +  RcorrJZBeemm->Write();
3164 +  Bpred->Write();
3165 +  f->Close();
3166 +  
3167    delete RcorrJZBeemm;
3168    delete LcorrJZBeemm;
3169    delete RcorrJZBem;
# Line 1072 | Line 3176 | void do_prediction_plot(string jzb, TCan
3176  
3177    delete blankback;
3178    
3179 <  if(PlottingSetup::RestrictToMassPeak) {
3179 >  delete BpredSys;
3180 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
3181      delete RcorrJZBSBem;
3182      delete LcorrJZBSBem;
3183      delete RcorrJZBSBeemm;
# Line 1087 | Line 3192 | void do_prediction_plot(string jzb, TCan
3192   }
3193  
3194   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
3195 +  switch_overunderflow(true);
3196    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
3197 <  do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
3198 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
3199 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
3200 < }
1095 <
1096 < void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1097 <  bool do_data=0;
1098 <  bool dosignal=0;
1099 <  if(is_data==1) do_data=1;
1100 <  if(is_data==2) dosignal=1;
1101 <  TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1102 <  TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1103 <  TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1104 <  TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1105 <  
1106 <  TH1F *RcorrJZBSBem;
1107 <  TH1F *LcorrJZBSBem;
1108 <  TH1F *RcorrJZBSBeemm;
1109 <  TH1F *LcorrJZBSbeemm;
1110 <  
1111 <  if(PlottingSetup::RestrictToMassPeak) {
1112 <    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1113 <    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1114 <    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1115 <    LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1116 <  }
1117 <  
1118 <
1119 <
1120 <
1121 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1122 <  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1123 <  if(PlottingSetup::RestrictToMassPeak) {
1124 <    Bpred->Add(RcorrJZBem,1.0/3);
1125 <    Bpred->Add(LcorrJZBem,-1.0/3);
1126 <    Bpred->Add(RcorrJZBSBem,1.0/3);
1127 <    Bpred->Add(LcorrJZBSBem,-1.0/3);
1128 <    Bpred->Add(RcorrJZBSBeemm,1.0/3);
1129 <    Bpred->Add(LcorrJZBSbeemm,-1.0/3);
3197 >  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
3198 >  if ( !PlottingSetup::Approved ) {
3199 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
3200 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
3201    } else {
3202 <    Bpred->Add(RcorrJZBem,1.0);
1132 <    Bpred->Add(LcorrJZBem,-1.0);
3202 >    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
3203    }
3204 <
3205 <  can->cd();
1136 <  can->SetLogy(0);
1137 <  Bpred->SetLineColor(kRed);
1138 <  Bpred->SetStats(0);
1139 <  if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1140 <  TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1141 <  JZBratioforfitting->Divide(Bpred);
1142 <  TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1143 <  
1144 <  
1145 <  JZBratio->SetTitle("");
1146 <  JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1147 < //  if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1148 <  
1149 <  TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1150 <  TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1151 < //  straightline_fit->SetParameter(0,1);
1152 <  JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1153 <  pol0d->SetParameter(0,pol0->GetParameter(0));
1154 <  
1155 <  JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1156 <  JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1157 <  if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1158 <  JZBratio->GetYaxis()->SetNdivisions(519);
1159 <  JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1160 <  JZBratio->GetYaxis()->CenterTitle();
1161 <  JZBratio->GetXaxis()->CenterTitle();
1162 <  JZBratio->SetMarkerSize(DataMarkerSize);
1163 <  JZBratio->Draw("AP");
1164 <  /////----------------------------
1165 <  TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1166 <  writeresult->SetFillStyle(4000);
1167 <  writeresult->SetFillColor(kWhite);
1168 <  writeresult->SetTextFont(42);
1169 <  writeresult->SetTextSize(0.03);
1170 <  writeresult->SetTextAlign(12);
1171 <  ostringstream jzb_agreement_data_text;
1172 <  jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) <<  pol0->GetParError(0);
1173 <  if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1174 <  if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1175 < /*  if(is_data) writeresult->AddText("Data closure test");
1176 <  else writeresult->AddText("MC closure test");
1177 <  */
1178 <  writeresult->AddText(jzb_agreement_data_text.str().c_str());
1179 < //  writeresult->Draw("same");
1180 < //  pol0d->Draw("same");
1181 <  TF1 *topline =  new TF1("","1.5",0,1000);
1182 <  TF1 *bottomline =  new TF1("","0.5",0,1000);
1183 <  topline->SetLineColor(kBlue);
1184 <  topline->SetLineStyle(2);
1185 <  bottomline->SetLineColor(kBlue);
1186 <  bottomline->SetLineStyle(2);
1187 < //  topline->Draw("same");
1188 < //  bottomline->Draw("same");
1189 <  TF1 *oneline = new TF1("","1.0",0,1000);
1190 <  oneline->SetLineColor(kBlue);
1191 <  oneline->SetLineStyle(1);
1192 <  oneline->Draw("same");
1193 <  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.
1194 <  if(is_data==1) DrawPrelim();
1195 <  else DrawMCPrelim();
1196 <  TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1197 <  leg->SetTextFont(42);
1198 <  leg->SetTextSize(0.04);
1199 < //   if(is_data==1) leg->SetHeader("Ratio (data)");
1200 < //   else leg->SetHeader("Ratio (MC)");
1201 <
1202 <  TString MCtitle("MC ");
1203 <  if (is_data==1) MCtitle = "";
1204 <
1205 <  leg->SetFillStyle(4000);
1206 <  leg->SetFillColor(kWhite);
1207 <  leg->SetTextFont(42);
1208 < //  leg->AddEntry(topline,"+20\% sys envelope","l");
1209 <  leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1210 <  leg->AddEntry(oneline,"ratio = 1","l");
1211 < //  leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1212 < //  leg->AddEntry(bottomline,"#pm50% envelope","l");
1213 <
1214 <
1215 <  //leg->Draw("same"); // no longer drawing legend
1216 <
1217 <  if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1218 <  if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1219 <  if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1220 <  
1221 <  delete RcorrJZBeemm;
1222 <  delete LcorrJZBeemm;
1223 <  delete RcorrJZBem;
1224 <  delete LcorrJZBem;
1225 <  
1226 <  delete RcorrJZBSBem;
1227 <  delete LcorrJZBSBem;
1228 <  delete RcorrJZBSBeemm;
1229 <  delete LcorrJZBSbeemm;
1230 < }
1231 <
1232 < void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1233 <  TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1234 <  globalc->SetLogy(0);
1235 <  
1236 <  do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh  );
1237 <  do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh  );
1238 <  do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh  );
3204 >  delete globalcanvas;
3205 >  switch_overunderflow(false);
3206   }
3207  
3208   string give_jzb_expression(float peak, int type) {
# Line 1258 | Line 3225 | void lepton_comparison_plots() {
3225    Float_t ymin = 1.e-5, ymax = 0.25;
3226    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
3227    can->SetLogy(1);
3228 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3229 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
3228 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
3229 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
3230    eemc->SetLineColor(kBlue);
3231    mmmc->SetLineColor(kRed);
3232    eemc->SetMinimum(0.1);
# Line 1322 | Line 3289 | void lepton_comparison_plots() {
3289    eemmlegend->AddEntry(jmmd,"#mu#mu","l");
3290    eemmlegend->Draw();
3291    DrawPrelim();
3292 <  save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3292 >  Save_With_Ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
3293    
3294 <  TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc,  luminosity,allsamples.FindSample("DYJets"));
3295 <  TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc,  luminosity,allsamples.FindSample("DYJets"));
3296 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJets"));
3294 >  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"));
3295 >  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"));
3296 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
3297    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
3298    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
3299    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 1423 | Line 3390 | void draw_pure_jzb_histo(TCut cut,string
3390    datahisto->SetMinimum(0.1);
3391    datahisto->SetMarkerSize(DataMarkerSize);
3392    datahisto->Draw("e1");
3393 <  mcstack.Draw("same");
3393 >  mcstack.Draw("histo,same");
3394    datahisto->Draw("same,e1");
3395    
3396    TLegend *leg;
3397 <  if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
3398 <  else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
3399 <  else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
3400 <  else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
3401 <  else {
3402 <    std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
3403 <    exit(-1);
3404 <      }
3397 >  if (!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) {
3398 >    if(is_OF(cut)) leg = allsamples.allbglegend("Opposite flavor",datahisto);
3399 >    else leg = allsamples.allbglegend("Same flavor",datahisto);
3400 >  } else {
3401 >    if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
3402 >    else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
3403 >    else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
3404 >    else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
3405 >    else {
3406 >      std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
3407 >      exit(-1);
3408 >    }
3409 >  }
3410    leg->Draw();
3411    string write_cut = decipher_cut(cut,"");
3412    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
3413    writeline1->SetTextSize(0.035);
3414    writeline1->Draw();
3415 <  save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3415 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
3416 >  else Save_With_Ratio(datahisto,mcstack,jzbpad->cd(),savename);
3417    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
3418    jzbpad2->cd();
3419    jzbpad2->SetLogy(1);
# Line 1448 | Line 3421 | void draw_pure_jzb_histo(TCut cut,string
3421    datahisto->SetMinimum(0.1);
3422    datahisto->SetMarkerSize(DataMarkerSize);
3423    datahisto->Draw("e1");
3424 <  mcstack.Draw("same");
3424 >  mcstack.Draw("histo,same");
3425    datahisto->Draw("same,e1");
3426    leg->SetHeader("");
3427    leg->Draw();
3428    writeline1->SetTextSize(0.035);
3429    writeline1->Draw();
3430    DrawPrelim();
3431 <  save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3431 >  if(!Contains(savename,"Dibosons")) Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
3432 >  else Save_With_Ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
3433    datahisto->Delete();
3434    mcstack.Delete();
3435   }
# Line 1463 | Line 3437 | void draw_pure_jzb_histo(TCut cut,string
3437   Double_t GausR(Double_t *x, Double_t *par) {
3438    return gRandom->Gaus(x[0],par[0]);
3439   }
3440 +
3441 + void produce_stretched_jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3442 +  TCanvas *dican = new TCanvas("dican","JZB Plots Canvas");
3443 +  float max=jzbHigh ;
3444 +  float min=-120;
3445 +  int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
3446 +  int coarserbins=int(nbins/2.0);
3447 +  int rebinnedbins=int(nbins/4.0);
3448 +  
3449 +  vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
3450 +  for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
3451 +  for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
3452 +  for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
3453 +
3454 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP",dican,binning);
3455 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP",dican,binning);
3456 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_SFZP",dican,binning);
3457 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
3458 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
3459 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
3460 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
3461 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
3462 +  
3463 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
3464 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
3465 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
3466 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
3467 +  
3468 +  delete dican;
3469 + }
3470    
3471 +
3472 + void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3473 +  switch_overunderflow(true);
3474 +  vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
3475 +  
3476 +  if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
3477 +    write_error(__FUNCTION__,"Could not find any diboson samples - aborting diboson plots");
3478 +    return;
3479 +  }
3480 +  
3481 +  float stretchfactor = 100.0;
3482 +  vector<string> labels;
3483 +  
3484 +  
3485 +  dout << "Going to increase the cross section for diboson samples ... " << endl;
3486 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3487 +    float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3488 +    (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
3489 +    dout << "     Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
3490 +    labels.push_back((allsamples.collection)[SamplesToBeModified[i]].samplename);
3491 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=any2string(int(stretchfactor))+" x "+(allsamples.collection)[SamplesToBeModified[i]].samplename;
3492 +    dout << "         (also renamed it to " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " )" << endl;
3493 +  }
3494 +  
3495 +  dout << "Going to produce JZB plots" << endl;
3496 +  produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
3497 +  TCanvas *gloca = new TCanvas("gloca","gloca");
3498 +  
3499 +  dout << "Going to produce prediction plots" << endl;
3500 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
3501 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
3502 +  delete gloca;
3503 +
3504 +  dout << "Going to reset the cross section for diboson samples ... " << endl;
3505 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
3506 +    float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
3507 +    (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
3508 +    string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
3509 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=labels[i];
3510 +    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;
3511 +    
3512 +  }
3513 + //   switch_overunderflow(false);
3514 + }
3515 +
3516 +
3517 + void draw_normalized_data_vs_data_histo(TCut cut1, TCut cut2, string variable, string legentry1, string legentry2, string savename, TCanvas *can,vector<float> binning) {
3518 +  TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
3519 +  jzbpad->cd();
3520 +  jzbpad->SetLogy(1);
3521 +  string xlabel="JZB [GeV]";
3522 +
3523 +  TH1F *datahisto1 = allsamples.Draw("datahisto1",variable,binning, xlabel, "events",cut1,data,luminosity);
3524 +  datahisto1->SetLineColor(kRed);
3525 +  datahisto1->SetMarkerColor(kRed);
3526 +  TH1F *datahisto2 = allsamples.Draw("datahisto2",variable,binning, xlabel, "events",cut2,data,luminosity);
3527 +  datahisto2->SetLineColor(kBlue);
3528 +  datahisto2->SetMarkerColor(kBlue);
3529 +  
3530 +  datahisto2->SetMarkerSize(DataMarkerSize);
3531 +  datahisto1->DrawNormalized("e1");
3532 +  datahisto2->DrawNormalized("histo,same");
3533 +  datahisto1->DrawNormalized("same,e1");
3534 +  
3535 +  TLegend *leg = make_legend();
3536 +  leg->AddEntry(datahisto1,legentry1.c_str());
3537 +  leg->AddEntry(datahisto2,legentry2.c_str());
3538 +  leg->Draw();
3539 +  
3540 +  Save_With_Ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
3541 +  
3542 +  datahisto1->Delete();
3543 +  datahisto2->Delete();
3544 + }
3545 +
3546 +
3547   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
3548 +  switch_overunderflow(true);
3549    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
3550    float max=jzbHigh ;
3551    float min=-120;
# Line 1477 | Line 3558 | void jzb_plots(string mcjzb, string data
3558    for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
3559    for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
3560  
3561 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
3562 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
3563 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
3564 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
3565 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
3566 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
3567 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3568 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
3569 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
3561 >  if ( !PlottingSetup::Approved ) {
3562 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
3563 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
3564 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
3565 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
3566 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
3567 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
3568 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3569 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
3570 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
3571 >    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);
3572 >    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);
3573 >    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);
3574 >
3575 >  }
3576    
3577    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
3578 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
3579 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3580 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
3581 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3582 <
3583 < //  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
3584 < //  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
3585 < //  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1499 < //  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarsest",can,coarsest_binning);
1500 < //  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarsest",can,coarsest_binning);
3578 >  if ( !PlottingSetup::Approved ) {
3579 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
3580 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
3581 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
3582 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
3583 >  }
3584 >  delete can;
3585 >  switch_overunderflow(false);
3586   }
3587  
3588  
# Line 1547 | Line 3632 | void compute_MC_yields(string mcjzb,vect
3632    TCanvas *yica = new TCanvas("yica","yield canvas");
3633    
3634    int nRegions=4;
3635 <  if(!PlottingSetup::RestrictToMassPeak) nRegions=2;
3635 >  if(!PlottingSetup::RestrictToMassPeak||!PlottingSetup::UseSidebandsForcJZB) nRegions=2;
3636    string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
3637    string posneg[] = {"pos","neg"};
3638    TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
3639  
3640 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
3640 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
3641      TCut jzbMC[]  = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
3642      dout << "_________________________________________________________" << endl;
3643      dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
3644 <    for(int isample=0;isample<(allsamples.collection).size();isample++) {
3644 >    for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
3645        if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << "  &  ";
3646        else dout << "Sample & ";
3647        for(int iregion=0;iregion<nRegions;iregion++) {
# Line 1815 | Line 3900 | void draw_ttbar_and_zjets_shape_for_one_
3900  
3901   void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
3902    int all_leptons=-1;
1818  int electrons_only=0;
1819  int mu_only=1;
1820  int twojetswith50gev=1;
3903    int threejetswith30gev=0;
3904   /*  
3905 +  int twojetswith50gev=1;
3906 +  int electrons_only=0;
3907 +  int mu_only=1;
3908 +
3909    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
3910    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
3911    
# Line 1833 | Line 3919 | void draw_ttbar_and_zjets_shape(string m
3919    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
3920   }
3921  
3922 < void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1837 <  //first: colorful plots
3922 > float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
3923    TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
3924    cancorr->SetLogz();
3925    cancorr->SetRightMargin(0.13);
3926 <  flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
3927 <  TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
3926 >  TCut zptforresponsepresentation(Restrmasscut&&SpecialCut&&passtrig);
3927 >
3928 >  if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
3929    TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
3930 <  (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
3930 >  niceresponseplotd->Sumw2();
3931 >  TH2F* emuResponse = (TH2F*)niceresponseplotd->Clone("emuResponse");
3932 >  vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
3933 >  for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
3934 >    if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
3935 >    if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
3936 >    
3937 >    dout << "   Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
3938 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
3939 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
3940 >  }
3941 >  niceresponseplotd->Add(emuResponse,-1);
3942 >  
3943    niceresponseplotd->SetStats(0);
3944    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
3945    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 1849 | Line 3947 | void find_correction_factors(string &jzb
3947    niceresponseplotd->GetYaxis()->CenterTitle();
3948    niceresponseplotd->Draw("COLZ");
3949    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
3950 +  profd->Rebin(2);
3951    profd->SetMarkerSize(DataMarkerSize);
3952 <  profd->Fit("pol0","","same,e1",30,400);
3952 >  profd->Fit("pol0","","same,e1",100,400);
3953    DrawPrelim();
3954 <  TText* title = write_text(0.5,0.7,"Data");
3954 >  string stitle="Data";
3955 >  if(!Contains(FindKeyword,"Data")) stitle="MC";
3956 >  TText* title = write_text(0.5,0.7,stitle.c_str());
3957    title->SetTextAlign(12);
3958    title->Draw();
3959    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
3960 <  float datacorrection=datapol->GetParameter(0);
3961 <  stringstream dataresstring;
3962 <  dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
3963 <  TText* restitle = write_text(0.5,0.65,dataresstring.str());
3960 >  float correction=datapol->GetParameter(0);
3961 >  stringstream resstring;
3962 >  resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
3963 >  TText* restitle = write_text(0.5,0.65,resstring.str());
3964    restitle->SetTextAlign(12);
3965    restitle->SetTextSize(0.03);
3966    restitle->Draw();
3967 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
3968 <  
3969 <  TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
3970 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
3971 <  niceresponseplotm->SetStats(0);
3972 <  niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
3973 <  niceresponseplotm->GetYaxis()->SetTitle("Response");
3974 <  niceresponseplotm->GetXaxis()->CenterTitle();
1874 <  niceresponseplotm->GetYaxis()->CenterTitle();
1875 <  niceresponseplotm->Draw("COLZ");
1876 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
1877 <  TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
1878 <  profm->SetMarkerSize(DataMarkerSize);
1879 <  profm->Fit("pol0","","same,e1",30,400);
1880 <  DrawMCPrelim();
1881 <  title = write_text(0.5,0.7,"MC simulation");
1882 <  title->SetTextAlign(12);
1883 <  title->Draw();
1884 <  TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
1885 <  float mccorrection=mcpol->GetParameter(0);
1886 <  stringstream mcresstring;
1887 <  mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
1888 <  TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
1889 <  mcrestitle->SetTextAlign(12);
1890 <  mcrestitle->SetTextSize(0.03);
1891 <  mcrestitle->Draw();
1892 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
3967 >  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
3968 >  delete cancorr;
3969 >  delete niceresponseplotd;
3970 >  delete profd;
3971 >  return correction;
3972 > }
3973 >
3974 > void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
3975    
3976 +  dout << "Computing response corrections: " << endl;
3977 +  //Step 1 : Get results
3978 +  float datacorrection=find_one_correction_factor("Data",true,"","Data");
3979 +  float mccorrection=find_one_correction_factor("DY",false,"","MC");
3980 +  
3981 +  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
3982 +  float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
3983 +  
3984 +  float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
3985 +  float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
3986 +  
3987 +  cout << "Corrections : " << endl;
3988 +  cout << "   Data : " << datacorrection << endl;
3989 +  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
3990 +  cout << "   MC : " << mccorrection << endl;
3991 +  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
3992    
3993 <  //Step 2: Getting the result
1896 < //  TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
3993 >  //Step 2: Processing the result and making it into something useful :-)
3994    stringstream jzbvardatas;
3995 <  if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
3996 <  if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
3995 >  jzbvardatas << "(";
3996 >  
3997 >  if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
3998 >  if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
3999 >  
4000 >  if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
4001 >  if(dataMMcorrection<1)  jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
4002 >  
4003 >  float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
4004 >  
4005 >  if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
4006 >  if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
4007 >  
4008 >  jzbvardatas << ")";
4009    jzbvardata=jzbvardatas.str();
4010 +  
4011    stringstream jzbvarmcs;
4012 <  if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
4013 <  if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
4012 >  jzbvarmcs << "(";
4013 >  
4014 >  if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
4015 >  if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
4016 >  
4017 >  if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
4018 >  if(mcMMcorrection<1)  jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
4019 >  
4020 >  float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
4021 >  
4022 >  if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
4023 >  if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
4024 >  
4025 >  jzbvarmcs << ")";
4026    jzbvarmc=jzbvarmcs.str();
4027 +
4028    dout << "JZB Z pt correction summary : " << endl;
4029    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
4030    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
4031 +  
4032   }
4033  
4034 < void pick_up_events(string cut) {
4035 <  dout << "Picking up events with cut " << cut << endl;
1912 <  allsamples.PickUpEvents(cut);
4034 > void pick_up_events(string cut, string filename, bool QuietMode=false) {
4035 >  allsamples.PickUpEvents(cut,filename,QuietMode);
4036   }
4037  
4038 < void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
4038 > void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
4039    dout << "Saving configuration template!" << endl;
4040    ofstream configfile;
4041    configfile.open("../DistributedModelCalculations/last_configuration.C");
# Line 1932 | Line 4055 | void save_template(string mcjzb, string
4055    configfile<<"string datajzb=\"datajzb_ERROR\";\n";
4056    configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
4057    configfile<<"vector<float>jzb_cuts;\n";
4058 +  configfile<<"vector<float>jzb_shape_limit_bins;\n";
4059    configfile<<"float MCPeakError=-999;\n";
4060 +  configfile<<"float DataPeakError=-999;\n";
4061    configfile<<"}\n\n";
4062  
4063    configfile<<"void read_config() {\n";
4064    configfile<<"datajzb=\""<<datajzb<<"\";\n";
4065    configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
4066 <  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
4067 <  for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4066 >  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
4067 >  configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
4068 >  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";
4069    configfile<<"\n\n";
4070 <  for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4071 <  for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4072 <  for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4070 >  for(int i=0;i<(int)Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4071 >  for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4072 >  for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4073 >  configfile<<"\n\n";
4074 >  for(int i=0;i<(int)flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4075 >  for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4076 >  for(int i=0;i<(int)flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4077 >  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";
4078    configfile<<"\n\n";
1948  for(int i=0;i<flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1949  for(int i=0;i<flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1950  for(int i=0;i<flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
4079    configfile<<"\n\n";
4080    configfile<<"luminosity="<<luminosity<<";\n";
4081 +  configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
4082 +  configfile<<"UseSidebandsForcJZB="<<UseSidebandsForcJZB<<";//tells us whether to use the sidebands or not\n";
4083    
4084    configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
4085    
# Line 1972 | Line 4102 | void draw_all_ttbar_histos(TCanvas *can,
4102    float max=histos[0]->GetMaximum();
4103    if(manualmin>=0) min=manualmin;
4104    else {
4105 <    for(int i=1;i<histos.size();i++) {
4105 >    for(int i=1;i<(int)histos.size();i++) {
4106        float curmin=get_nonzero_minimum(histos[i]);
4107        float curmax=histos[i]->GetMaximum();
4108        if(curmin<min) min=curmin;
# Line 1983 | Line 4113 | void draw_all_ttbar_histos(TCanvas *can,
4113    histos[0]->Draw(drawoption.c_str());
4114    stringstream drawopt;
4115    drawopt << drawoption << ",same";
4116 <  for(int i=1;i<histos.size();i++) {
4116 >  for(int i=1;i<(int)histos.size();i++) {
4117      histos[i]->Draw(drawopt.str().c_str());
4118    }
4119   }
# Line 1992 | Line 4122 | void ttbar_sidebands_comparison(string m
4122    //in the case of the on peak analysis, we compare the 3 control regions to the real value
4123    //in the case of the OFF peak analysis, we compare our control region to the real value
4124    TCut weightbackup=cutWeight;
4125 <  cutWeight="1.0";
1996 <  float simulatedlumi = luminosity; //in pb please - adjust to your likings
4125 >  switch_overunderflow(true);
4126    
4127 +  bool doPURW=false;
4128 +  
4129 +  
4130 +  if(!doPURW) {
4131 +    dout << "Not doing PU reweighting for ttbar closure test" << endl;
4132 +    cutWeight="1.0";
4133 +    // Do it without PU re-weighting
4134 +    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4135 +    stringstream resultsNoPU;
4136 +    stringstream noPUdatajzb;
4137 +    stringstream noPUmcjzb;
4138 +    
4139 +    stringstream mcjzbnoPU;
4140 +    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
4141 +    mcjzb = noPUmcjzb.str();
4142 +  }
4143  
4144 <  TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4145 <  TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4144 >      
4145 >  float simulatedlumi = luminosity; //in pb please - adjust to your likings
4146 >
4147 >  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4148 >  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4149    TH1F *TSem;
4150    TH1F *nTSem;
4151 <  TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4152 <  TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4151 >  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4152 >  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4153    TH1F *TSeemm;
4154    TH1F *nTSeemm;
4155    
4156 <  if(PlottingSetup::RestrictToMassPeak) {
4157 <    TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4158 <    nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4159 <    TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4160 <    nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
4156 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4157 >    TSem    = allsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4158 >    nTSem   = allsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4159 >    TSeemm  = allsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4160 >    nTSeemm = allsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/TT"));
4161    }
4162  
4163    TCanvas *tcan = new TCanvas("tcan","tcan");
2016  
4164    tcan->SetLogy(1);
4165    
4166    TZeemm->SetLineColor(kBlack);
# Line 2022 | Line 4169 | void ttbar_sidebands_comparison(string m
4169    TZem->SetMarkerColor(kRed);
4170  
4171  
4172 <  if(PlottingSetup::RestrictToMassPeak) {
4172 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4173          TSem->SetLineColor(TColor::GetColor("#00A616"));
4174          TSeemm->SetLineColor(kMagenta+2);
4175          TSem->SetMarkerColor(TColor::GetColor("#00A616"));
# Line 2032 | Line 4179 | void ttbar_sidebands_comparison(string m
4179    }
4180    
4181    vector<TH1F*> histos;
4182 +  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4183 +  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4184    histos.push_back(TZem);
4185    histos.push_back(TZeemm);
4186 <  if(PlottingSetup::RestrictToMassPeak) {
4186 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4187 >    TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4188 >    TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
4189      histos.push_back(TSem);
4190      histos.push_back(TSeemm);
4191    }
4192 <  draw_all_ttbar_histos(tcan,histos,"histo",0.04);
4192 >  draw_all_ttbar_histos(tcan,histos,"histo",8);
4193    
4194    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
4195    leg->AddEntry(TZeemm,"SFZP","l");
4196    leg->AddEntry(TZem,"OFZP","l");
4197 <  if(PlottingSetup::RestrictToMassPeak) {
4197 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4198      leg->AddEntry(TSeemm,"SFSB","l");
4199      leg->AddEntry(TSem,"OFSB","l");
4200    }
# Line 2053 | Line 4204 | void ttbar_sidebands_comparison(string m
4204    
4205    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
4206    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
4207 <  TH1F *TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
4208 <  TH1F *TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
4207 >  TH1F *TSeemmcopy;
4208 >  TH1F *TSemcopy;
4209 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4210 >    TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
4211 >    TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
4212 >  }
4213  
4214    TZem->Divide(TZeemm);
4215    TZem->SetMarkerStyle(21);
4216 <  if(PlottingSetup::RestrictToMassPeak) {
4216 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4217      TSem->Divide(TZeemm);
4218      TSeemm->Divide(TZeemm);
4219      TSem->SetMarkerStyle(24);
4220      TSeemm->SetMarkerStyle(32);
4221 < }
4221 >  }
4222  
4223    tcan->SetLogy(0);
4224    TZem->GetYaxis()->SetRangeUser(0,2.5);
4225    TZem->GetYaxis()->SetTitle("ratio");
4226    TZem->Draw();
4227 <  if(PlottingSetup::RestrictToMassPeak) {
4227 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4228      TSem->Draw("same");
4229      TSeemm->Draw("same");
4230    }
4231    
4232 <  float linepos=0.25;
4233 <  if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
4232 >  float linepos=emuncertONPEAK;
4233 >  if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
4234 >  
4235    TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
4236    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4237    TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
4238    
4239 +  /*write_warning(__FUNCTION__,"These two lines are to be removed!");
4240 +  TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
4241 +  TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
4242 +  topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
4243 +  bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
4244 +  topalt->Draw("same");bottomalt->Draw("same");*/
4245 +  
4246 +  
4247    top->SetLineColor(kBlue);top->SetLineStyle(2);
4248    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
4249    center->SetLineColor(kBlue);
# Line 2090 | Line 4254 | void ttbar_sidebands_comparison(string m
4254    
4255    TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
4256    leg2->AddEntry(TZem,"OFZP / SFZP","ple");
4257 <  if(PlottingSetup::RestrictToMassPeak) {
4257 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4258      leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
4259      leg2->AddEntry(TSem,"OFSB / SFZP","ple");
4260    }
# Line 2103 | Line 4267 | void ttbar_sidebands_comparison(string m
4267    DrawMCPrelim(simulatedlumi);
4268    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
4269    
4270 +  
4271 +  if (0) { // Turn this off: we don't need this
4272  
4273 +    ///-------------- second part: only look at the quantity we actually care about!
4274 +    TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
4275 +    TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
4276 +    rightsfzp->Add(leftsfzp,-1);
4277 +    TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
4278 +    TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
4279 +    rightofzp->Add(leftofzp,-1);
4280 +    TH1F *leftofsb;
4281 +    TH1F *rightofsb;
4282 +    TH1F *leftsfsb;
4283 +    TH1F *rightsfsb;
4284 +    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4285 +      leftofsb  = (TH1F*)nTSem->Clone("leftofsb");
4286 +      rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
4287 +      rightofsb->Add(leftofsb,-1);
4288 +      leftsfsb  = (TH1F*)nTSeemm->Clone("leftsfsb");
4289 +      rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
4290 +      rightsfsb->Add(leftsfsb,-1);
4291 +    }
4292  
4293 < ///-------------- second part: only look at the quantity we actually care about!
4294 <  TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
4295 <  TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
4296 <  rightsfzp->Add(leftsfzp,-1);
4297 <  TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
4298 <  TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
4299 <  rightofzp->Add(leftofzp,-1);
4300 <  TH1F *leftofsb;
4301 <  TH1F *rightofsb;
4302 <  TH1F *leftsfsb;
2118 <  TH1F *rightsfsb;
2119 <  if(PlottingSetup::RestrictToMassPeak) {
2120 <        leftofsb  = (TH1F*)nTSem->Clone("leftofsb");
2121 <        rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
2122 <        rightofsb->Add(leftofsb,-1);
2123 <        leftsfsb  = (TH1F*)nTSeemm->Clone("leftsfsb");
2124 <        rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
2125 <        rightsfsb->Add(leftsfsb,-1);
2126 <  }
4293 >    tcan->SetLogy(1);
4294 >    rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
4295 >    rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
4296 >    rightsfzp->Draw("histo");
4297 >    rightofzp->Draw("histo,same");
4298 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4299 >      rightofsb->Draw("histo,same");
4300 >      rightsfsb->Draw("histo,same");
4301 >    }
4302 >    DrawMCPrelim(simulatedlumi);
4303  
4304 <  tcan->SetLogy(1);
4305 <  rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
4306 <  rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
4307 <  rightsfzp->Draw("histo");
4308 <  rightofzp->Draw("histo,same");
4309 <  if(PlottingSetup::RestrictToMassPeak) {
4310 <    rightofsb->Draw("histo,same");
4311 <    rightsfsb->Draw("histo,same");
2136 <  }
2137 <  DrawMCPrelim(simulatedlumi);
4304 >    TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
4305 >    legA->AddEntry(rightsfzp,"SFZP","l");
4306 >    legA->AddEntry(rightofzp,"OFZP","l");
4307 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4308 >      legA->AddEntry(rightofsb,"SFSB","l");
4309 >      legA->AddEntry(rightsfsb,"OFSB","l");
4310 >    }
4311 >    legA->Draw();
4312  
4313 <  TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2140 <  legA->AddEntry(rightsfzp,"SFZP","l");
2141 <  legA->AddEntry(rightofzp,"OFZP","l");
2142 <  if(PlottingSetup::RestrictToMassPeak) {
2143 <    legA->AddEntry(rightofsb,"SFSB","l");
2144 <    legA->AddEntry(rightsfsb,"OFSB","l");
2145 <  }
2146 <  legA->Draw();
4313 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
4314  
4315 <  CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
4315 >    tcan->SetLogy(0);
4316 >    rightofzp->Divide(rightsfzp);
4317 >    rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
4318 >    rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
4319 >    rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
4320 >    rightofzp->Draw();
4321 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4322 >      rightofsb->Divide(rightsfzp);
4323 >      rightsfsb->Divide(rightsfzp);
4324 >      rightofsb->Draw("same");
4325 >      rightsfsb->Draw("same");
4326 >    }
4327  
4328 <  tcan->SetLogy(0);
4329 <  rightofzp->Divide(rightsfzp);
4330 <  rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
4331 <  rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
4332 <  rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
4333 <  rightofzp->Draw();
4334 <  if(PlottingSetup::RestrictToMassPeak) {
4335 <    rightofsb->Divide(rightsfzp);
4336 <    rightsfsb->Divide(rightsfzp);
4337 <    rightofsb->Draw("same");
4338 <    rightsfsb->Draw("same");
4339 <  }
4328 >    TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
4329 >    TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
4330 >    TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
4331 >  
4332 >    top2->SetLineColor(kBlue);top2->SetLineStyle(2);
4333 >    bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
4334 >    center2->SetLineColor(kBlue);
4335 >  
4336 >    top2->Draw("same");
4337 >    center2->Draw("same");
4338 >    bottom2->Draw("same");
4339 >
4340 >    rightofzp->SetMarkerStyle(21);
4341 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4342 >      rightofsb->SetMarkerStyle(24);
4343 >      rightsfsb->SetMarkerStyle(32);
4344 >    }
4345  
4346 <  TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
4347 <  TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
4348 <  TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
4346 >    TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
4347 >    leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
4348 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4349 >      leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
4350 >      leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
4351 >    }
4352 >    leg3->AddEntry(bottom,"syst. envelope","l");
4353 >    leg3->SetX1(0.25);leg3->SetX2(0.6);
4354 >    leg3->SetY1(0.65);
4355    
4356 <  top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2168 <  bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2169 <  center2->SetLineColor(kBlue);
4356 >    leg3->Draw("same");
4357    
4358 <  top2->Draw("same");
4359 <  center2->Draw("same");
2173 <  bottom2->Draw("same");
4358 >    DrawMCPrelim(simulatedlumi);
4359 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
4360  
2175  rightofzp->SetMarkerStyle(21);
2176  if(PlottingSetup::RestrictToMassPeak) {
2177    rightofsb->SetMarkerStyle(24);
2178    rightsfsb->SetMarkerStyle(32);
4361    }
4362  
2181  TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2182  leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2183  if(PlottingSetup::RestrictToMassPeak) {
2184        leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2185        leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
2186  }
2187  leg3->AddEntry(bottom,"syst. envelope","l");
2188  leg3->SetX1(0.25);leg3->SetX2(0.6);
2189  leg3->SetY1(0.65);
2190  
2191  leg3->Draw("same");
2192  
2193  DrawMCPrelim(simulatedlumi);
2194  CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
2195
4363    delete TZem;
4364    delete nTZem;
4365    delete TZeemm;
4366    delete nTZeemm;
4367 <  if(PlottingSetup::RestrictToMassPeak) {
4367 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4368          delete TSem;
4369          delete nTSem;
4370          delete TSeemm;
# Line 2206 | Line 4373 | void ttbar_sidebands_comparison(string m
4373  
4374    delete tcan;
4375    cutWeight=weightbackup;
4376 +  switch_overunderflow(false);
4377   }
4378  
4379   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
4380    vector<float> nicer_binning;
4381 <  nicer_binning.push_back(-125);
4381 >  
4382 > /*  nicer_binning.push_back(-400);
4383 >  nicer_binning.push_back(-250);
4384 >  nicer_binning.push_back(-200);
4385 >  nicer_binning.push_back(-150);
4386 >  nicer_binning.push_back(-100);
4387 >  nicer_binning.push_back(-50);
4388 >  nicer_binning.push_back(-20);
4389 >  
4390 >  nicer_binning.push_back(0);
4391 >  nicer_binning.push_back(20);
4392 >  nicer_binning.push_back(50);
4393 >  nicer_binning.push_back(100);
4394 >  nicer_binning.push_back(150);
4395 >  nicer_binning.push_back(200);
4396 >  nicer_binning.push_back(250);
4397 >  nicer_binning.push_back(400);*/
4398 >  
4399    nicer_binning.push_back(-100);
2215  nicer_binning.push_back(-75);
4400    nicer_binning.push_back(-50);
4401    nicer_binning.push_back(-25);
4402    nicer_binning.push_back(0);
# Line 2222 | Line 4406 | void ttbar_sidebands_comparison(string m
4406    nicer_binning.push_back(100);
4407    nicer_binning.push_back(125);
4408    nicer_binning.push_back(150);
4409 <  nicer_binning.push_back(175);
4409 >  //nicer_binning.push_back(175);
4410    nicer_binning.push_back(200);
4411 <  nicer_binning.push_back(230);
4412 <  nicer_binning.push_back(280);
4413 <  nicer_binning.push_back(400);
4411 > //  nicer_binning.push_back(250);
4412 > //  nicer_binning.push_back(300);
4413 > //  nicer_binning.push_back(400);
4414 >  
4415    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
4416   }
4417  
4418  
4419 < void zjets_prediction_comparison() {
4420 <  // Do it without PU re-weighting
4421 <  float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4422 <  stringstream resultsNoPU;
4423 <
4424 <  stringstream mcjzbnoPU;
4425 <  find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
4426 <  if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
4427 <  else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
4419 > void zjets_prediction_comparison(string mcjzbWithPUa, TCut massregioncut, string massregionname) {
4420 >  cout << "****************************************************************************************************************************************************************" << endl;
4421 >  TCanvas *zcan = new TCanvas("zcan","zcan");  
4422 > //  zcan->SetLogy(1);
4423 >  TCut weightbackup=cutWeight;
4424 >  
4425 >  bool UsePURW=true;
4426 >  
4427 >  
4428 >  string mcjzb;
4429 >  if(UsePURW) {
4430 >    mcjzb=mcjzbWithPUa;
4431 >    cout << "Using PURW peak positions" << endl;
4432 >  } else {
4433 >    // Do it without PU re-weighting
4434 >    cutWeight="1.0";
4435 >    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
4436 >    stringstream resultsNoPU;
4437 >    stringstream noPUdatajzb;
4438 >    stringstream noPUmcjzb;
4439 >    
4440 >    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
4441 >    dout << "The peak corrected JZB expression for MC without pileup is : " <<  noPUmcjzb.str() << endl;
4442 >    
4443 >    mcjzb = noPUmcjzb.str();
4444 >    
4445 >  }
4446  
4447 <  string mcjzb = mcjzbnoPU.str();
4448 <  dout << "The peak corrected JZB expression for MC without pileup is : " <<  mcjzb << endl;
4447 >  
4448 >  vector<float> binning;
4449 >  binning.push_back(0);
4450 >  binning.push_back(10);
4451 >  binning.push_back(20);
4452 >  binning.push_back(40);
4453 >  binning.push_back(60);
4454 > //   binning.push_back(50);
4455 > //   binning.push_back(60);
4456 > //   binning.push_back(70);
4457 > //   binning.push_back(80);
4458 > //   binning.push_back(90);
4459 >  binning.push_back(100);
4460  
2247  TCut weightbackup=cutWeight;
2248  cutWeight="1.0";
2249  float sbg_min=0.;
2250  float sbg_max=100.;
2251  int sbg_nbins=5;
4461    float simulatedlumi = luminosity;//in pb please - adjust to your likings
4462    
4463    TCut kPos((mcjzb+">0").c_str());
4464    TCut kNeg((mcjzb+"<0").c_str());
4465    string var( "abs("+mcjzb+")" );
4466 +  
4467 +  TCut notTau("abs(genMID1)!=15");
4468 +  TCut ee_mm_tautau("mll>0");
4469 +  
4470  
4471 <  TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
4472 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
4473 <                                  kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("DYJets"));
2261 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2262 <                                  kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("DYJets"));
4471 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4472 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4473 >  
4474    hJZBpos->SetLineColor(kBlack);
4475    hJZBneg->SetLineColor(kRed);
4476    
4477 <  Int_t nbins = 5;
2267 <  Float_t xmax = 100.;
2268 <
2269 <  
2270 <  TCanvas *zcan = new TCanvas("zcan","zcan");  
2271 <  zcan->SetLogy(1);
2272 <
4477 >  hJZBpos->SetMinimum(1.0);
4478    hJZBpos->Draw("e1");
4479    hJZBneg->Draw("same,hist");
4480    hJZBpos->Draw("same,e1"); // So it's on top...
4481    
4482 <  TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
4482 >  TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
4483    leg->AddEntry(hJZBpos,"Observed","pe");
4484    leg->AddEntry(hJZBneg,"Predicted","l");
4485    leg->Draw("same");
4486    DrawMCPrelim(simulatedlumi);
4487 <  CompleteSave(zcan,"Systematics/zjets_prediction");
4487 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction"+any2string(massregionname));
4488    
4489    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
4490    hratio->Divide(hJZBneg);
4491    
4492 <  zcan->SetLogy(0);
4492 >  for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
4493 >    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
4494 >  }
4495 >  
4496 > //  zcan->SetLogy(0);
4497    hratio->GetYaxis()->SetRangeUser(0,2.5);
4498    hratio->GetYaxis()->SetTitle("Observed/Predicted");
4499    hratio->Draw("e1");
4500    
4501 <  TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
4502 <  TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
4503 <  TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
4501 >  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
4502 >  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
4503 >  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
4504    
4505  
4506    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 2302 | Line 4511 | void zjets_prediction_comparison() {
4511    center->Draw("same");
4512    bottom->Draw("same");
4513    
4514 <  TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
4514 >  TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4515    leg2->AddEntry(hratio,"obs / pred","pe");
4516    leg2->AddEntry(bottom,"syst. envelope","l");
4517    leg2->Draw("same");
4518    DrawMCPrelim(simulatedlumi);
4519 <  CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
4519 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio"+any2string(massregionname));
4520 >  
4521 >  TCut reducedNJets(cutnJets);
4522 >  
4523 >  TH1F *TAUhJZBpos       = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4524 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4525 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4526 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4527 >
4528 >  TH1F *RcorrJZBSBem;
4529 >  TH1F *LcorrJZBSBem;
4530 >  TH1F *RcorrJZBSBeemm;
4531 >  TH1F *LcorrJZBSBeemm;
4532 >
4533 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4534 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4535 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4536 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kPos&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4537 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ee_mm_tautau&&kNeg&&massregioncut,mc,simulatedlumi,systsamples.FindSample("/DY"));
4538 >  }
4539 >  
4540 >  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4541 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4542 >    Bpred->Add(RcorrJZBem,1.0/3.);
4543 >    Bpred->Add(LcorrJZBem,-1.0/3.);
4544 >    Bpred->Add(RcorrJZBSBem,1.0/3.);
4545 >    Bpred->Add(LcorrJZBSBem,-1.0/3.);
4546 >    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
4547 >    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
4548 >  } else {
4549 >    Bpred->Add(RcorrJZBem,1.0);
4550 >    Bpred->Add(LcorrJZBem,-1.0);
4551 >  }
4552 >  
4553 >  Bpred->SetLineColor(kRed);
4554 >
4555 >  TAUhJZBpos->SetLineColor(kBlack);
4556 >  Bpred->SetLineColor(kRed);
4557 >  
4558 >  TAUhJZBpos->SetMinimum(1.0);
4559 >  TAUhJZBpos->Draw("e1");
4560 >  Bpred->Draw("same,hist");
4561 >  TAUhJZBpos->Draw("same,e1");
4562 >  
4563 >  TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
4564 >  TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
4565 >  TAUleg->AddEntry(Bpred,"Predicted","l");
4566 >  TAUleg->Draw("same");
4567 >  DrawMCPrelim(simulatedlumi);
4568 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction__"+any2string(massregionname));
4569 >  
4570 >  TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
4571 >  TAUhratio->Divide(Bpred);
4572 >  
4573 >  for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
4574 >    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
4575 >  }
4576 >  
4577 >  zcan->SetLogy(0);
4578 >  TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
4579 >  TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
4580 >  TAUhratio->Draw("e1");
4581 >  
4582 >  top->Draw("same");
4583 >  center->Draw("same");
4584 >  bottom->Draw("same");
4585 >  
4586 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
4587 >  TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
4588 >  TAUleg2->AddEntry(bottom,"syst. envelope","l");
4589 >  TAUleg2->Draw("same");
4590 >  DrawMCPrelim(simulatedlumi);
4591 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio"+any2string(massregionname));
4592 >  
4593 >  delete Bpred;
4594 >  delete TAUhJZBpos;
4595 >  delete LcorrJZBeemm;
4596 >  delete RcorrJZBem;
4597 >  delete LcorrJZBem;
4598 >  delete hJZBpos;
4599 >  delete hJZBneg;
4600 >  
4601 >  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4602 >    delete RcorrJZBSBem;
4603 >    delete LcorrJZBSBem;
4604 >    delete RcorrJZBSBeemm;
4605 >    delete LcorrJZBSBeemm;
4606 >  }
4607 >  
4608    
4609    delete zcan;
4610    cutWeight=weightbackup;
2314
4611   }
4612  
4613  
4614 <
4614 > void zjets_prediction_comparison(string mcjzbWithPUa) {
4615 >  zjets_prediction_comparison(mcjzbWithPUa, TCut(""), "nomasscut");
4616 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("abs(mll-91)<20"), "Zwindow_20");
4617 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>20&&mll<70"), "LowMassRegion2070");
4618 >  zjets_prediction_comparison(mcjzbWithPUa, TCut("mll>110"), "HighMassRegion110");
4619 > }
4620 >  
4621   void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
4622    tout << endl << endl;
4623    stringstream bordercut;
# Line 2333 | Line 4635 | void sideband_assessment(string datajzb,
4635    tout << "\\begin{tabular}{l|cc}" << endl;
4636    tout << "\\hline" << endl;
4637    tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
4638 <  tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
4638 >  tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
4639    tout << "\\end{tabular}" << endl;
4640    tout << "\\end{center}" << endl;
4641    tout << "\\end{table}" << endl;
# Line 2351 | Line 4653 | void make_table(samplecollection &coll,
4653    
4654    TCanvas *cannie = new TCanvas("cannie","cannie");
4655    
4656 <  for(int icut=0;icut<jzb_cuts.size();icut++) {
4656 >  for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
4657      float currcut=jzb_cuts[icut];
4658      int nbins=1;float low=currcut;
4659      vector<int> mysample;
# Line 2366 | Line 4668 | void make_table(samplecollection &coll,
4668      TH1F *RcorrJZBSBeemm;
4669      TH1F *LcorrJZBSBeemm;
4670      
4671 <    if(PlottingSetup::RestrictToMassPeak) {
4671 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4672        RcorrJZBSBem   = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4673        LcorrJZBSBem   = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
4674        RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
# Line 2374 | Line 4676 | void make_table(samplecollection &coll,
4676      }
4677      
4678      TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4679 <    if(PlottingSetup::RestrictToMassPeak) {
4679 >    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4680        Bpred->Add(RcorrJZBem,1.0/3.);
4681        Bpred->Add(LcorrJZBem,-1.0/3.);
4682        Bpred->Add(RcorrJZBSBem,1.0/3.);
# Line 2410 | Line 4712 | void make_table(samplecollection &coll,
4712    //prediction part
4713    if(is_data) cout << "Data prediction & ";
4714    if(subselection!="none") cout << subselection << " prediction &";
4715 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
4715 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
4716    
4717    cout << endl;
4718    //observation part
4719    if(is_data) cout << "Data observation & ";
4720    if(subselection!="none") cout << subselection << " observation &";
4721 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
4721 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
4722    cout << endl;
4723    cout << "_________________________________________________________________" << endl;
4724    delete cannie;
4725   }
4726  
4727   void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
4728 +  cout << "You probably don't want --met, you want --metplots ... " << endl;
4729 +  assert(0);
4730    /*we want a table like this:
4731      __________________     50   |   100  | ...
4732      | Data prediction |  a vs b | a vs b | ...
# Line 2451 | Line 4755 | void JZBSelEff(string mcjzb, TTree* even
4755    int nbins = sizeof(xbins)/sizeof(float)-1;
4756    int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
4757  
4758 <  TH1F* heff  = new TH1F("heff", "JZB eff ; generator-level JZB [GeV]; efficiency",nbins,xbins);
4759 <  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator-level JZB [GeV]; efficiency",nbins,xbins);
4760 <  TH1F* hreco = new TH1F("hreco","JZB reco ; generator-level JZB [GeV]; efficiency",nbins,xbins);
4758 >  
4759 >  TH1F* heff  = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
4760 >  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
4761 >  TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
4762  
4763    TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
4764    TCut kreco(cutmass);
# Line 2469 | Line 4774 | void JZBSelEff(string mcjzb, TTree* even
4774    TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
4775    can->SetGridx(1);
4776    can->SetGridy(1);
4777 +  can->SetLeftMargin(0.16);
4778 +  can->SetRightMargin(0.05);
4779    TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
4780 +  leg->SetBorderSize(1);
4781 +  leg->SetLineColor(kBlack);
4782 +  leg->SetTextFont(62);
4783  
4784 <  
2475 <
2476 <  for ( int icut=0; icut<jzb_bins.size(); ++icut ) {
4784 >  for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
4785  
4786      ostringstream selection;
4787      selection << mcjzb << ">" << jzb_bins[icut];
# Line 2489 | Line 4797 | void JZBSelEff(string mcjzb, TTree* even
4797      }
4798    
4799      heff->GetXaxis()->SetRangeUser(min, max);
4800 + //    heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
4801 + //    heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
4802 + //    heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
4803 + //    heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
4804      heff->SetMarkerStyle(markers[icut]);
4805      heff->Fit("func","Q+","same");
4806  
# Line 2500 | Line 4812 | void JZBSelEff(string mcjzb, TTree* even
4812  
4813      // Store plot
4814      TH1F* h = (TH1F*)heff->Clone(hname);
4815 +    h->SetNdivisions(505,"X");
4816      if ( icut) h->Draw("same");
4817      else h->Draw();
4818      char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
# Line 2520 | Line 4833 | void JZBSelEff(string mcjzb, TTree* even
4833   // Calls the above function for each signal sample
4834   void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
4835   {  
4836 <  for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
4836 >  for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
4837      dout << "JZB selection efficiency curve: " << std::endl;
4838      JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
4839    }
4840   }
4841 +
4842 + void qcd_plots(string datajzb, string mcjzb, vector<float> bins) {
4843 +  // What this function aims to do:
4844 +  // Illustrate cut flow for QCD (requiring only one lepton, requiring etc.)
4845 +  // Illustrate how little QCD is left over! i.e. make some pointless JZB plot with only QCD to visualize the fact that there's not much really.
4846 +  TCanvas *can = new TCanvas("can","can");
4847 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
4848 +  kinpad->cd();
4849 +  
4850 +  string jzb=mcjzb;
4851 +  
4852 +  float hi=400;
4853 +  bool use_signal=false;
4854 +  bool use_data=false;
4855 +  
4856 +  bool is_data=false;
4857 +  int nbins=50;//100;
4858 +  float low=0;
4859 +  float high=500;
4860 +  int versok=false;
4861 +  if(gROOT->GetVersionInt()>=53000) versok=true;
4862 +
4863 +  TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
4864 +  TH1F *RcorrJZBeemm   = qcdsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4865 +  TH1F *LcorrJZBeemm   = qcdsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4866 +  TH1F *RcorrJZBem     = qcdsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4867 +  TH1F *LcorrJZBem     = qcdsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4868 +  blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
4869 +  blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
4870 +  blankback->GetXaxis()->CenterTitle();
4871 +  blankback->GetYaxis()->CenterTitle();
4872 +  
4873 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
4874 +  TH1F *RcorrJZBSBem;
4875 +  TH1F *LcorrJZBSBem;
4876 +  TH1F *RcorrJZBSBeemm;
4877 +  TH1F *LcorrJZBSBeemm;
4878 +  
4879 + //  TH1F *RcorrJZBeemmNoS;
4880 +
4881 +    //these are for the ratio
4882 +  TH1F *JRcorrJZBeemm   = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4883 +  TH1F *JLcorrJZBeemm   = qcdsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4884 +  TH1F *JRcorrJZBem     = qcdsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4885 +  TH1F *JLcorrJZBem     = qcdsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4886 +  
4887 +  TH1F *JRcorrJZBSBem;
4888 +  TH1F *JLcorrJZBSBem;
4889 +  TH1F *JRcorrJZBSBeemm;
4890 +  TH1F *JLcorrJZBSBeemm;
4891 +  
4892 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4893 +    RcorrJZBSBem   = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4894 +    LcorrJZBSBem   = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4895 +    RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4896 +    LcorrJZBSBeemm = qcdsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4897 +
4898 +    //these are for the ratio
4899 +    JRcorrJZBSBem   = qcdsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4900 +    JLcorrJZBSBem   = qcdsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
4901 +    JRcorrJZBSBeemm = qcdsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4902 +    JLcorrJZBSBeemm = qcdsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
4903 +
4904 +  }
4905 +  
4906 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
4907 +  
4908 +  TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
4909 +  TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
4910 +    
4911 +  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
4912 +  TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
4913 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4914 +    Bpred->Add(RcorrJZBem,1.0/3.);
4915 +    Bpred->Add(LcorrJZBem,-1.0/3.);
4916 +    Bpred->Add(RcorrJZBSBem,1.0/3.);
4917 +    Bpred->Add(LcorrJZBSBem,-1.0/3.);
4918 +    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
4919 +    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
4920 +    
4921 +    TTbarpred->Scale(1.0/3);
4922 +    Zjetspred->Add(LcorrJZBem,-1.0/3.);
4923 +    Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
4924 +    TTbarpred->Add(RcorrJZBSBem,1.0/3.);
4925 +    Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
4926 +    TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
4927 +    
4928 +    //these are for the ratio
4929 +    JBpred->Add(JRcorrJZBem,1.0/3.);
4930 +    JBpred->Add(JLcorrJZBem,-1.0/3.);
4931 +    JBpred->Add(JRcorrJZBSBem,1.0/3.);
4932 +    JBpred->Add(JLcorrJZBSBem,-1.0/3.);
4933 +    JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
4934 +    JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
4935 +  } else {
4936 +    Bpred->Add(RcorrJZBem,1.0);
4937 +    Bpred->Add(LcorrJZBem,-1.0);
4938 +    
4939 +    Zjetspred->Add(LcorrJZBem,-1.0);
4940 +    
4941 +    //these are for the ratio
4942 +    JBpred->Add(JRcorrJZBem,1.0);
4943 +    JBpred->Add(JLcorrJZBem,-1.0);
4944 +  }
4945 +    
4946 +  
4947 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
4948 +  
4949 +  TLegend *legBpred = make_legend("",0.6,0.55,false);
4950 +  RcorrJZBeemm->Draw("e1x0,same");
4951 +  Bpred->Draw("hist,same");
4952 +  RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
4953 +  legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
4954 +  legBpred->AddEntry(Bpred,"MC predicted","l");
4955 +  if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
4956 +  if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
4957 +  legBpred->Draw();
4958 +  DrawMCPrelim();
4959 +
4960 +  //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
4961 +  string ytitle("ratio");
4962 +  if ( use_data==1 ) ytitle = "data/pred";
4963 +  Save_With_Ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
4964 +  delete kinpad;
4965 +  
4966 +  TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
4967 +  TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
4968 +  TH1F *osof = qcdsamples.Draw("osof","pfJetGoodNum",1,0,100, "internal code", "events", cutOSOF ,mc, luminosity);
4969 +  TH1F *njossf = qcdsamples.Draw("njossf","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSSF ,mc, luminosity);
4970 +  TH1F *njosof = qcdsamples.Draw("njosof","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSOF ,mc, luminosity);
4971 +  
4972 +  dout << "______________________________________________" << endl;
4973 +  dout << "QCD contribution: " << endl;
4974 +  dout << "Total number of events: " << allevents->Integral() << endl;
4975 +  dout << "OSSF events: " << ossf->Integral() << endl;
4976 +  dout << "OSOF events: " << osof->Integral() << endl;
4977 +  dout << "OSSF events with >=3 jets:" << njossf->Integral() << endl;
4978 +  dout << "OSOF events with >=3 jets:" << njosof->Integral() << endl;
4979 +  dout << "(note that no mass requirement has been imposed)" << endl;
4980 +  
4981 +  dout << "______________________________________________" << endl;
4982 +  dout << "How QCD shows up in the different regions: " << endl;
4983 +  dout << "OSSF: " << endl;
4984 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4985 +    dout << "     Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
4986 +    dout << "     sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
4987 +  } else {
4988 +    dout << "     " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
4989 +  }
4990 +  dout << "OSOF: " << endl;
4991 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4992 +    dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
4993 +    dout << "     sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
4994 +  } else {
4995 +    dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
4996 +  }
4997 +  dout << "Therefore: " << endl;
4998 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
4999 +    dout << "    Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
5000 +    dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
5001 +    dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
5002 +    dout << " = " << LcorrJZBeemm->Integral() + (1.0/3)*(RcorrJZBSBeemm->Integral() - LcorrJZBSBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() + RcorrJZBSBem->Integral() - LcorrJZBSBem->Integral()) << endl;
5003 +  } else {
5004 +    dout << "    Prediction increases by : " << LcorrJZBeemm->Integral();
5005 +    dout << " + (" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
5006 +    dout << " = " << LcorrJZBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() << endl;
5007 +  }
5008 +  dout << "    Observation increases by : " << RcorrJZBeemm->Integral() << endl;
5009 +  
5010 +  dout << endl;
5011 +  for(int i=0;i<(int)bins.size();i++) {
5012 +    dout << " JZB > " << bins[i] << " : " << endl;
5013 +    dout << "    Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
5014 +    if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB) {
5015 +        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;
5016 +    } else {
5017 +        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;
5018 +    }
5019 +  }
5020 +      
5021 +  delete can;
5022 +  delete allevents;
5023 +  if(ossf) delete ossf;
5024 +  if(RcorrJZBem) delete RcorrJZBem;
5025 +  if(LcorrJZBem) delete LcorrJZBem;
5026 +  if(RcorrJZBeemm) delete RcorrJZBeemm;
5027 +  if(LcorrJZBeemm) delete LcorrJZBeemm;
5028 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBem) delete RcorrJZBSBem;
5029 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBem) delete LcorrJZBSBem;
5030 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
5031 +  if(PlottingSetup::RestrictToMassPeak&&PlottingSetup::UseSidebandsForcJZB&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
5032 + }
5033 +
5034 + void check_ptsanity() {
5035 +  TCanvas *ptsancan = new TCanvas("ptsancan","ptsancan",600,1800);
5036 +  TH1F *individualpt1histos[allsamples.collection.size()];
5037 +  TH1F *individualpt2histos[allsamples.collection.size()];
5038 +  TH1F *fpt1 = new TH1F("fpt1","fpt1",50,0,50);
5039 +  fpt1->GetYaxis()->SetRangeUser(0,1);
5040 +  fpt1->GetXaxis()->SetTitle("p_{T,1}");
5041 +  fpt1->GetXaxis()->CenterTitle();
5042 +
5043 +  TH1F *fpt2 = new TH1F("fpt2","fpt2",50,0,50);
5044 +  fpt2->GetXaxis()->SetTitle("p_{T,2}");
5045 +  fpt2->GetXaxis()->CenterTitle();
5046 +  
5047 +  ptsancan->Divide(1,3);
5048 +  ptsancan->cd(1);
5049 +  float maxpt1entry=0;
5050 +  float maxpt2entry=0;
5051 +  
5052 +  TLegend *leg = make_legend();
5053 +  leg->SetX1(0.0);
5054 +  leg->SetY1(0.0);
5055 +  leg->SetX2(1.0);
5056 +  leg->SetY2(1.0);
5057 +  
5058 +  
5059 +  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
5060 +    string nowname=(allsamples.collection)[isample].filename;
5061 +    cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
5062 +    individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
5063 +    individualpt2histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt2",50,0,50, "p_{T,2}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
5064 +    individualpt1histos[isample]->SetLineColor(isample+1);
5065 +    individualpt2histos[isample]->SetLineColor(isample+1);
5066 +    float currmaxpt1entry=individualpt1histos[isample]->GetMaximum()/individualpt1histos[isample]->Integral();
5067 +    float currmaxpt2entry=individualpt2histos[isample]->GetMaximum()/individualpt2histos[isample]->Integral();
5068 +    cout << "      pt 1 histo contains; " << individualpt1histos[isample]->Integral() << endl;
5069 +    cout << "      pt 2 histo contains; " << individualpt2histos[isample]->Integral() << endl;
5070 +    if(currmaxpt1entry>maxpt1entry)maxpt1entry=currmaxpt1entry;
5071 +    if(currmaxpt2entry>maxpt2entry)maxpt2entry=currmaxpt2entry;
5072 +    leg->AddEntry(individualpt2histos[isample],((allsamples.collection)[isample].filename).c_str(),"f");
5073 +  }
5074 +
5075 +  fpt1->GetYaxis()->SetRangeUser(0,maxpt1entry);
5076 +  fpt2->GetYaxis()->SetRangeUser(0,maxpt2entry);
5077 +
5078 +  ptsancan->cd(1);
5079 +  fpt1->Draw();
5080 +  ptsancan->cd(2);
5081 +  fpt2->Draw();
5082 +
5083 +  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
5084 +    ptsancan->cd(1);
5085 +    individualpt1histos[isample]->DrawNormalized("same,histo");
5086 +    ptsancan->cd(2);
5087 +    individualpt2histos[isample]->DrawNormalized("same,histo");
5088 +  }
5089 +  ptsancan->cd(3);
5090 +  leg->Draw();
5091 +  CompleteSave(ptsancan,"PtSanityCheck");
5092 +  
5093 +  delete ptsancan;
5094 + }
5095 +
5096 + void do_mlls_plot(string mcjzb) {
5097 +  cout << "At this point we'd plot the mll distribution" << endl;
5098 +  TCanvas *sigcan = new TCanvas("sigcan","sigcan");
5099 +  for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
5100 +    if(!(signalsamples.collection)[isig].events) continue;
5101 +    string nowname=(signalsamples.collection)[isig].filename;
5102 +    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
5103 + //    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
5104 +    mll->SetLineColor(TColor::GetColor("#04B404"));
5105 +    stringstream poscutS;
5106 +    poscutS << "((" << mcjzb <<")>50)";
5107 +    TCut poscut(poscutS.str().c_str());
5108 +    TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
5109 +    mllP->SetLineColor(TColor::GetColor("#0040FF"));
5110 +    mll->Draw("histo");
5111 +    mllP->Draw("histo,same");
5112 +    TLegend *leg = make_legend();
5113 +    leg->SetY1(0.8);
5114 +    leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
5115 +    leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
5116 +    leg->Draw();
5117 +    TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
5118 +    TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
5119 +    lin->Draw("same");
5120 +    lin2->Draw("same");
5121 +    
5122 +    CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
5123 +    delete mll;
5124 +    delete mllP;
5125 +  }
5126 + }
5127 +
5128 + void met_vs_jzb_plots(string datajzb, string mcjzb) {
5129 +  
5130 +  TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
5131 +  canmetjzb->SetRightMargin(0.16);
5132    
5133 +  vector<string> findme;
5134 +  findme.push_back("DY");
5135 +  findme.push_back("TTJets");
5136 +  findme.push_back("LM");
5137 +  /*
5138 +  for(int ifind=0;ifind<(int)findme.size();ifind++) {
5139 +    vector<int> selsamples = allsamples.FindSample(findme[ifind]);
5140 +    TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
5141 +    for(int isel=0;isel<(int)selsamples.size();isel++) {
5142 +      dout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
5143 +      allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF&&cutnJets);
5144 +    }
5145 +    metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
5146 +    metvsjzb->SetStats(0);
5147 +    metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
5148 +    metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
5149 +    metvsjzb->GetXaxis()->CenterTitle();
5150 +    metvsjzb->GetYaxis()->CenterTitle();
5151 +    metvsjzb->Draw("COLZ");
5152 +    TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
5153 +    title->SetTextAlign(12);
5154 +    title->Draw();
5155 +    CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
5156 +  }
5157 +  */
5158 +  
5159 +  dout << "About to produce MET plot for DY split up by JZB" << endl;
5160 +  
5161 +  int nbins=14;
5162 +  float low=0;
5163 +  float high=140;
5164 +  
5165 +  stringstream sLEFT;
5166 +  sLEFT << "((" << mcjzb << ")<0)";
5167 +  TCut LEFT(sLEFT.str().c_str());
5168 +  stringstream sRIGHT;
5169 +  sRIGHT << "((" << mcjzb << ")>0)";
5170 +  TCut RIGHT(sRIGHT.str().c_str());
5171 +  
5172 +  TH1F *metleft   = allsamples.Draw("metleft","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5173 +  TH1F *metleftO  = allsamples.Draw("metleftO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5174 +  TH1F *metright  = allsamples.Draw("metright","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5175 +  TH1F *metrightO = allsamples.Draw("metrightO","met[4]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5176 +  
5177 +  
5178 +  TH1F *Bpred =  (TH1F*)metleft->Clone("Bpred");
5179 +  Bpred->Add(metleftO,-1);
5180 +  Bpred->Add(metrightO);
5181 +  TH1F *obs = (TH1F*)metright->Clone("obs");
5182 +  
5183 +  metleft->Add(metleftO,-1);
5184 +  metright->Add(metrightO,-1);
5185 +  
5186 +  metleft->SetLineColor(kRed);
5187 +  metright->SetLineColor(kBlack);
5188 +  TPad *metpad = new TPad("metpad","metpad",0,0,1,1);
5189 +  metpad->cd();
5190 +  metpad->SetLogy(1);
5191 +  metleft->Draw("histo");
5192 +  metright->Draw("same");
5193 +  TLegend *lg = make_legend();
5194 +  lg->SetX1(0.5);
5195 +  lg->SetY1(0.7);
5196 +  lg->AddEntry(metright,"JZB>0 (OSOF corrected)","P");
5197 +  lg->AddEntry(metleft,"JZB<0 (OSOF corrected)","L");
5198 +  lg->SetHeader("DY");
5199 +  
5200 +  lg->Draw();
5201 +  Save_With_Ratio(metright,metleft,metpad->cd(),"METvsJZBplots/ComparingLeftToRightinMETspectrum");
5202 +  
5203 +  TPad *metpad3 = new TPad("metpad3","metpad3",0,0,1,1);
5204 +  metpad3->cd();
5205 +  metpad3->SetLogy(1);
5206 +  Bpred->SetLineColor(kRed);
5207 +  Bpred->Draw("histo");
5208 +  obs->SetLineColor(kBlack);
5209 +  obs->Draw("same");
5210 +  TLegend *lg2 = make_legend();
5211 +  lg2->SetX1(0.5);
5212 +  lg2->SetY1(0.7);
5213 +  lg2->AddEntry(obs,"observed","P");
5214 +  lg2->AddEntry(Bpred,"predicted","L");
5215 +  lg2->SetHeader("DY");
5216 +
5217 +  lg2->Draw();
5218 +  
5219 +  Save_With_Ratio(obs,Bpred,metpad3->cd(),"METvsJZBplots/ComparingPredObsinMET");
5220 +  
5221 +  TPad *metpad2 = new TPad("metpad2","metpad2",0,0,1,1);
5222 +  metpad2->cd();
5223 +  metpad2->SetLogy(1);
5224 +  
5225 +  TH1F *metlefta   = allsamples.Draw("metlefta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5226 +  TH1F *metleftOa  = allsamples.Draw("metleftOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity, allsamples.FindSample("DYJets"));
5227 +  TH1F *metrighta  = allsamples.Draw("metrighta","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5228 +  TH1F *metrightOa = allsamples.Draw("metrightOa","met[2]",nbins,low,high, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity, allsamples.FindSample("DYJets"));
5229 +  
5230 +  metlefta->Add(metleftOa,-1);
5231 +  metrighta->Add(metrightOa,-1);
5232 +  
5233 +  metlefta->SetLineColor(kRed);
5234 +  metpad2->cd();
5235 +  metlefta->Draw("histo");
5236 +  metrighta->Draw("same");
5237 +  lg->Draw();
5238 +  Save_With_Ratio(metrighta,metlefta,metpad2->cd(),"METvsJZBplots/ComparingLeftToRightinMET_type1_spectrum");
5239 +  
5240 +  delete Bpred;
5241 +  delete obs;
5242 +  
5243 +  float newhigh=300;
5244 +  int newNBins=30;
5245 +  
5246 +  TPad *metpad4 = new TPad("metpad4","metpad4",0,0,1,1);
5247 +  TH1F *Ametleft   = allsamples.Draw("Ametleft","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&LEFT,mc, luminosity);
5248 +  TH1F *AmetleftO  = allsamples.Draw("AmetleftO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&LEFT,mc, luminosity);
5249 +  TH1F *Ametright  = allsamples.Draw("Ametright","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&RIGHT,mc, luminosity);
5250 +  TH1F *AmetrightO = allsamples.Draw("AmetrightO","met[4]",newNBins,low,newhigh, "#slash{E}_{T} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&RIGHT,mc, luminosity);
5251 +  
5252 +  TH1F *aBpred = (TH1F*)Ametleft->Clone("aBpred");
5253 +  aBpred->Add(AmetleftO,-1);
5254 +  aBpred->Add(AmetrightO);
5255 +  aBpred->SetLineColor(kRed);
5256 +  
5257 +  TH1F *aobs = (TH1F*)Ametright->Clone("aobs");
5258 +  metpad4->cd();
5259 +  metpad4->SetLogy(1);
5260 +  aobs->Draw();
5261 +  aBpred->Draw("histo,same");
5262 +  aobs->Draw("same");
5263 +  lg->SetHeader("All MC");
5264 +  lg->Draw();
5265 +  Save_With_Ratio(aobs,aBpred,metpad4->cd(),"METvsJZBplots/ComparingPredObsinMET_ALLSAMPLES");
5266 +  
5267 +  
5268 +  delete lg;
5269 +  delete canmetjzb;
5270 +  delete metleft;
5271 +  delete metleftO;
5272 +  delete metright;
5273 +  delete metrightO;
5274 + }
5275 +
5276 +
5277 + void do_one_ttbar_test(TH1F* &observed, TH1F* &predicted, TH1F* &ratio, TH1F* &ratio2, string mcjzb, string prestring) {
5278 +  
5279 +  if(PlottingSetup::RestrictToMassPeak) {
5280 +    write_error(__FUNCTION__,"This function (ttbar_tests) was not written for on-peak studies - sorry.");
5281 +    assert(!PlottingSetup::RestrictToMassPeak);
5282 +  }
5283 +  
5284 +  vector<float> binning;
5285 +  
5286 +  binning.push_back(-200);
5287 +  binning.push_back(-150);
5288 +  binning.push_back(-125);
5289 +  binning.push_back(-100);
5290 +  binning.push_back(-75);
5291 +  binning.push_back(-50);
5292 +  binning.push_back(-25);
5293 +  binning.push_back(0);
5294 +  binning.push_back(25);
5295 +  binning.push_back(50);
5296 +  binning.push_back(75);
5297 +  binning.push_back(100);
5298 +  binning.push_back(125);
5299 +  binning.push_back(150);
5300 +  binning.push_back(200);
5301 +  
5302 +  switch_overunderflow(true);
5303 +  
5304 +  TH1F *TZem  = allsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5305 +  TH1F *nTZem = allsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5306 +  TH1F *TZeemm  = allsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5307 +  TH1F *nTZeemm = allsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("/TT"));
5308 +  
5309 +  TCanvas *tcan = new TCanvas("tcan","tcan");
5310 +  tcan->SetLogy(1);
5311 +  
5312 +  TZeemm->SetLineColor(kBlack);
5313 +  TZem->SetLineColor(kRed);
5314 +  TZeemm->SetMarkerColor(kBlack);
5315 +  TZem->SetMarkerColor(kRed);
5316 +  
5317 +  vector<TH1F*> histos;
5318 + //  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5319 + //  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
5320 +  histos.push_back(TZem);
5321 +  histos.push_back(TZeemm);
5322 +  draw_all_ttbar_histos(tcan,histos,"histo",8);
5323 +  
5324 +  TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
5325 +  leg->AddEntry(TZeemm,"SFZP","l");
5326 +  leg->AddEntry(TZem,"OFZP","l");
5327 +  leg->Draw("same");
5328 +  DrawMCPrelim();
5329 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison");
5330 +  
5331 +  TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
5332 +  TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
5333 +  TH1F *TSeemmcopy;
5334 +  TH1F *TSemcopy;
5335 +  
5336 +  predicted=(TH1F*)TZem->Clone(((string)"predicted_"+prestring).c_str());
5337 +  observed=(TH1F*)TZeemm->Clone(((string)"observed_"+prestring).c_str());
5338 +  
5339 +  vector<float> posbinning;
5340 +  for(unsigned int i=0;i<binning.size();i++) {
5341 +    if(binning[i]<0) continue;
5342 +    posbinning.push_back(binning[i]);
5343 +  }
5344 +  
5345 +  TH1F *pred2 = new TH1F("pred2","pred2",posbinning.size()-1,&posbinning[0]);pred2->Sumw2();
5346 +  TH1F *obs2 = new TH1F("obs2","obs2",posbinning.size()-1,&posbinning[0]);obs2->Sumw2();
5347 +  
5348 +  for(unsigned int i=1;i<=predicted->GetNbinsX();i++) {
5349 +    int index=pred2->FindBin(abs(TZem->GetBinCenter(i)));
5350 +    if(TZem->GetBinCenter(i)<0) {
5351 +      //we're on the left: subtract em!
5352 +      pred2->SetBinContent(index,pred2->GetBinContent(index)-TZem->GetBinContent(i));
5353 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5354 +      //we're on the left: add eemm!
5355 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZeemm->GetBinContent(i));
5356 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5357 +    } else {
5358 +      //we're on the right: add em!
5359 +      pred2->SetBinContent(index,pred2->GetBinContent(index)+TZem->GetBinContent(i));
5360 +      pred2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZem->GetBinError(i),2)));
5361 +      //we're on the left: add eemm!
5362 +      obs2->SetBinContent(index,obs2->GetBinContent(index)+TZeemm->GetBinContent(i));
5363 +      obs2->SetBinError(index,sqrt(pow(pred2->GetBinError(index),2)+pow(TZeemm->GetBinError(i),2)));
5364 +    }
5365 +  }
5366 +  
5367 +  ratio2 = (TH1F*)pred2->Clone(((string)"ratio2_"+prestring).c_str());
5368 +  ratio2->Divide(obs2);
5369 +
5370 +  TZem->Divide(TZeemm);
5371 +  TZem->SetMarkerStyle(21);
5372 +
5373 +  TZem->SetTitle("OF / SF");
5374 +  ratio = (TH1F*)TZem->Clone(((string)"ratio_"+prestring).c_str());
5375 +  
5376 +  tcan->SetLogy(0);
5377 +  TZem->GetYaxis()->SetRangeUser(0,2.5);
5378 +  TZem->GetYaxis()->SetTitle("ratio");
5379 +  TZem->Draw();
5380 +  
5381 +  float linepos=emuncertOFFPEAK;
5382 +  
5383 +  TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
5384 +  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
5385 +  TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
5386 +  
5387 +  top->SetLineColor(kBlue);top->SetLineStyle(2);
5388 +  bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
5389 +  center->SetLineColor(kBlue);
5390 +  
5391 +  top->Draw("same");
5392 +  center->Draw("same");
5393 +  bottom->Draw("same");
5394 +  
5395 +  TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
5396 +  leg2->AddEntry(TZem,"OFZP / SFZP","ple");
5397 +  leg2->AddEntry(bottom,"syst. envelope","l");
5398 +  leg2->SetX1(0.25);leg2->SetX2(0.6);
5399 +  leg2->SetY1(0.65);
5400 +  
5401 +  leg2->Draw("same");
5402 +  
5403 +  DrawMCPrelim();
5404 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_ratio");
5405 +  
5406 +  ratio2->SetLineColor(TZem->GetLineColor());
5407 +  ratio2->SetMarkerColor(TZem->GetMarkerColor());
5408 +  ratio2->GetYaxis()->SetRangeUser(0,2.5);
5409 +  ratio2->GetYaxis()->SetTitle("ratio");
5410 +  ratio2->Draw();
5411 +  
5412 +  TLine *top2 = new TLine(0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
5413 +  TLine *center2 = new TLine(0,1.0,binning[binning.size()-1],1.0);
5414 +  TLine *bottom2 = new TLine(0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
5415 +  
5416 +  top2->SetLineColor(kBlue);top->SetLineStyle(2);
5417 +  bottom2->SetLineColor(kBlue);bottom->SetLineStyle(2);
5418 +  center2->SetLineColor(kBlue);
5419 +  
5420 +  top2->Draw("same");
5421 +  center2->Draw("same");
5422 +  bottom2->Draw("same");
5423 +  
5424 +  leg2->Draw("same");
5425 +  
5426 +  DrawMCPrelim();
5427 +  CompleteSave(tcan,"Systematics/TtbarTests/"+prestring+"/ttbar_shape_comparison_FINALratio");
5428 +  
5429 +  delete TZem;
5430 +  delete nTZem;
5431 +  delete TZeemm;
5432 +  delete nTZeemm;
5433 +  delete obs2;
5434 +  delete pred2;
5435 +  delete tcan;
5436 +  switch_overunderflow(false);
5437 + }
5438 +
5439 + 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) {
5440 +    
5441 +  
5442 +  TCanvas *ttcan2 = new TCanvas("ttcan2","ttcan2");
5443 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5444 +  vanilla_ratio->SetFillColor(kGreen);
5445 +  vanilla_ratio->SetLineColor(kGreen);
5446 +  vanilla_ratio->SetMarkerColor(kGreen);
5447 +  vanilla_ratio->SetFillStyle(3001);
5448 +  vanilla_ratio->Draw("e3");
5449 +  
5450 +  response_only_up_ratio->SetFillColor(kRed);
5451 +  response_only_up_ratio->SetMarkerColor(kRed);
5452 +  response_only_up_ratio->SetLineColor(kRed);
5453 +  response_only_up_ratio->SetFillStyle(3003);
5454 +  response_only_up_ratio->Draw("e3,same");
5455 +  
5456 +  response_only_down_ratio->SetFillColor(kOrange);
5457 +  response_only_down_ratio->SetMarkerColor(kOrange);
5458 +  response_only_down_ratio->SetLineColor(kOrange);
5459 +  response_only_down_ratio->SetFillStyle(3004);
5460 +  response_only_down_ratio->Draw("e3,same");
5461 +  
5462 +  reponse_plus_peak_up_ratio->SetFillColor(TColor::GetColor("#BDBDBD"));
5463 +  reponse_plus_peak_up_ratio->SetMarkerColor(TColor::GetColor("#BDBDBD"));
5464 +  reponse_plus_peak_up_ratio->SetLineColor(TColor::GetColor("#BDBDBD"));
5465 +  reponse_plus_peak_up_ratio->SetFillStyle(3005);
5466 +  reponse_plus_peak_up_ratio->Draw("e3,same");
5467 +  
5468 +  reponse_plus_peak_down_ratio->SetFillColor(kBlue);
5469 +  reponse_plus_peak_down_ratio->SetMarkerColor(kBlue);
5470 +  reponse_plus_peak_down_ratio->SetLineColor(kBlue);
5471 +  reponse_plus_peak_down_ratio->SetFillStyle(3006);
5472 +  reponse_plus_peak_down_ratio->Draw("e3,same");
5473 +  
5474 +  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);
5475 +  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);
5476 +  TLine *lOne = new TLine(vanilla_ratio->GetBinLowEdge(1),1.0,vanilla_ratio->GetBinLowEdge(vanilla_ratio->GetNbinsX())+vanilla_ratio->GetBinWidth(vanilla_ratio->GetNbinsX()),1.0);
5477 +  
5478 +  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);
5479 +  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);
5480 +  
5481 +  lhiA->SetLineColor(kRed);
5482 +  lhiA->SetLineStyle(2);
5483 +  llowA->SetLineColor(kRed);
5484 +  llowA->SetLineStyle(2);
5485 +  
5486 +  llow->SetLineColor(kBlue);
5487 +  llow->SetLineStyle(2);
5488 +  lhi->SetLineColor(kBlue);
5489 +  lhi->SetLineStyle(2);
5490 +  lOne->SetLineColor(kBlue);
5491 +  
5492 +  llow->Draw();
5493 +  lhi->Draw();
5494 +  lOne->Draw();
5495 +  
5496 +  llowA->Draw();
5497 +  lhiA->Draw();
5498 +  
5499 +  TLegend *leg = make_legend();
5500 +  leg->SetX1(0.15);
5501 +  leg->SetY1(0.7);
5502 +  leg->AddEntry(vanilla_ratio,"Raw JZB","pf");
5503 +  leg->AddEntry(response_only_up_ratio,"With response correction","pf");
5504 +  leg->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5505 +  leg->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5506 +  leg->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5507 +  leg->AddEntry(lhi,"Systematic envelope","l");
5508 + //  leg->SetNColumns(2);
5509 +  leg->Draw();
5510 +  
5511 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison"+PostString);
5512 +  
5513 +  vanilla_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5514 +  vanilla_ratio->Draw("e3");
5515 +  response_only_up_ratio->Draw("e3 same");
5516 +  response_only_down_ratio->Draw("e3 same");
5517 +  TLegend *leg2 = make_legend();
5518 +  leg2->SetX1(0.15);
5519 +  leg2->SetY1(0.7);
5520 +  leg2->AddEntry(vanilla_ratio,"Raw JZB","pf");
5521 +  leg2->AddEntry(response_only_up_ratio,"With response correction","pf");
5522 +  leg2->AddEntry(response_only_down_ratio,"With inverted response correction","pf");
5523 +  leg2->AddEntry(lhi,"Systematic envelope","l");
5524 +  leg2->Draw();
5525 +  llow->Draw();
5526 +  lOne->Draw();
5527 +  llowA->Draw();
5528 +  lhiA->Draw();
5529 +  
5530 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Response"+PostString);
5531 +  
5532 +  response_only_up_ratio->GetYaxis()->SetRangeUser(0.6,1.4);
5533 +  response_only_up_ratio->Draw("e3");
5534 +  reponse_plus_peak_up_ratio->Draw("e3 same");
5535 +  reponse_plus_peak_down_ratio->Draw("e3 same");
5536 +  TLegend *leg3 = make_legend();
5537 +  leg3->SetX1(0.15);
5538 +  leg3->SetY1(0.7);
5539 +  leg3->AddEntry(response_only_up_ratio,"With response correction","pf");
5540 +  leg3->AddEntry(reponse_plus_peak_up_ratio,"With response and peak correction","pf");
5541 +  leg3->AddEntry(reponse_plus_peak_down_ratio,"With response and inverted peak corr.","pf");
5542 +  leg3->AddEntry(lhi,"Systematic envelope","l");
5543 +  leg3->Draw();
5544 +  llow->Draw();
5545 +  lOne->Draw();
5546 +  llowA->Draw();
5547 +  lhiA->Draw();
5548 +  
5549 +  CompleteSave(ttcan2,"Systematics/TtbarTests/Comparison_Peak"+PostString);
5550 +  
5551 +  delete ttcan2;
5552 + }
5553 +
5554 + void ttbar_correction_tests() {
5555 +  TCanvas *ttcan = new TCanvas("ttcan","ttcan");
5556 +    
5557 +  TH1F *vanilla_observed, *response_only_up_observed, *response_only_down_observed, *reponse_plus_peak_up_observed, *reponse_plus_peak_down_observed;
5558 +  
5559 +  TH1F *vanilla_predicted, *response_only_up_predicted, *response_only_down_predicted, *reponse_plus_peak_up_predicted, *reponse_plus_peak_down_predicted;
5560 +  
5561 +  TH1F *vanilla_ratio, *response_only_up_ratio, *response_only_down_ratio, *reponse_plus_peak_up_ratio, *reponse_plus_peak_down_ratio;
5562 +  
5563 +  TH1F *vanilla_ratio2, *response_only_up_ratio2, *response_only_down_ratio2, *reponse_plus_peak_up_ratio2, *reponse_plus_peak_down_ratio2;
5564 +  
5565 +  string vanilla="jzb[1]";
5566 +  string response_only_up="((jzb[1]+0.034665*pt))";
5567 +  string response_only_down="((jzb[1]-0.034665*pt))";
5568 +  string reponse_plus_peak_up="((jzb[1]+0.034665*pt)- 3.58273 )";
5569 +  string reponse_plus_peak_down="((jzb[1]+0.034665*pt)+ 3.58273 )";
5570 +
5571 +  do_one_ttbar_test(vanilla_observed,vanilla_predicted,vanilla_ratio,vanilla_ratio2,vanilla,"vanilla");
5572 +  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");
5573 +  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");
5574 +  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");
5575 +  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");
5576 +  
5577 +  ttcan->cd();
5578 +  
5579 +  IllustrateVariation(vanilla_ratio,response_only_up_ratio,response_only_down_ratio,reponse_plus_peak_up_ratio,reponse_plus_peak_down_ratio,"PartialRatio");
5580 +  IllustrateVariation(vanilla_ratio2,response_only_up_ratio2,response_only_down_ratio2,reponse_plus_peak_up_ratio2,reponse_plus_peak_down_ratio2,"FullRatio");
5581 +  
5582 +  delete vanilla_observed;
5583 +  delete response_only_up_observed;
5584 +  delete response_only_down_observed;
5585 +  delete reponse_plus_peak_up_observed;
5586 +  delete reponse_plus_peak_down_observed;
5587 +  
5588 +  delete vanilla_predicted;
5589 +  delete response_only_up_predicted;
5590 +  delete response_only_down_predicted;
5591 +  delete reponse_plus_peak_up_predicted;
5592 +  delete reponse_plus_peak_down_predicted;
5593 +  
5594 +  delete vanilla_ratio;
5595 +  delete response_only_up_ratio;
5596 +  delete response_only_down_ratio;
5597 +  delete reponse_plus_peak_up_ratio;
5598 +  delete reponse_plus_peak_down_ratio;
5599 +  
5600 +  delete ttcan;
5601 + }
5602 +
5603 + void ttbar_region_search(string mcjzb) {
5604 +  cout << "Looking for a nice control region" << endl;
5605 +  TCanvas *can = new TCanvas("can","can",1200,1200);
5606 +  can->Divide(2,2);
5607 +  can->cd(1);
5608 +  can->cd(1)->SetLogy(1);
5609 +  
5610 +  THStack JZBdistSF = allsamples.DrawStack("JZBdistSF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5611 +  THStack JZBdistOF = allsamples.DrawStack("JZBdistOF",mcjzb,100,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&TCut("pfJetGoodNum40==2"),mc, luminosity);
5612 +  
5613 +  JZBdistSF.Draw("histo");
5614 +  JZBdistSF.SetMaximum(1000);
5615 +  JZBdistSF.SetMinimum(0.1);
5616 +  JZBdistSF.Draw("histo");
5617 +  DrawMCPrelim();
5618 +  
5619 +  can->cd(2);
5620 +  can->cd(2)->SetLogy(1);
5621 +  JZBdistOF.Draw("histo");
5622 +  JZBdistOF.SetMaximum(1000);
5623 +  JZBdistOF.SetMinimum(0.1);
5624 +  JZBdistOF.Draw("histo");
5625 +  DrawMCPrelim();
5626 +  
5627 +  can->cd(3);
5628 +  
5629 +  
5630 +  write_warning(__FUNCTION__,"Missing negative JZB subtraction  ");
5631 +  
5632 +  DrawMCPrelim();
5633 +  
5634 +  /*
5635 +  THStack *Subtracted = new THStack();
5636 +  
5637 +  TIter nextSF(JZBdistSF.GetHists());
5638 +  TIter nextOF(JZBdistOF.GetHists());
5639 +  TObject* SFobj;
5640 +  TObject* OFobj;
5641 +  
5642 +  TH1* sfh = NULL;
5643 +  TH1* ofh = NULL;
5644 +  
5645 +  while ( (SFobj = nextSF()) && (OFobj = nextOF()) ) {
5646 +    TH1F *sfstart = (TH1*)SFobj->Clone();
5647 +    TH1F *ofstart = (TH1*)OFobj->Clone();
5648 +    TH1F *obs, *pred;
5649 +    MakeObservationPrediction(obs,pred,sfstart,ofstart);
5650 +    
5651 +    if ( !hratio ) {
5652 +      hratio = (TH1*)obj->Clone();
5653 +      hratio->SetName("hratio");
5654 +    } else hratio->Add( (TH1*)obj );
5655 +    
5656 +  }
5657 +  hratio->Divide(hdata);
5658 +  */
5659 +  
5660 +  
5661 +  can->cd(4);
5662 +  JZBdistOF.Draw("histo");
5663 +  DrawMCPrelim();
5664 +  
5665 +  
5666 +  
5667 +  CompleteSave(can,"Systematics/TtbarTests/ControlRegion");
5668 +  
5669 +  CleanLegends();
5670 +  delete can;
5671 + }
5672 +
5673 + void ttbar_tests(string mcjzb) {
5674 +  //ttbar_correction_tests();
5675 +  ttbar_region_search(mcjzb);
5676 + }
5677  
5678   void test() {
5679    
5680    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
5681    testcanv->cd();
5682 <  switch_overunderflow(true);
5683 <  TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
5684 <  switch_overunderflow(false);
5685 <  ptdistr->Draw();
5686 <  testcanv->SaveAs("test.png");
5682 > //  switch_overunderflow(true);
5683 >  TH1F *histo1 = new TH1F("histo","histo",100,0,1);
5684 >  histo1->Sumw2();
5685 >  TH1F *histo2 = new TH1F("histo2","histo2",100,0,1);
5686 >  histo2->Sumw2();
5687 >  
5688 >  for(int i=0;i<100;i++) {
5689 >    histo1->Fill(1.0/i,i);
5690 >    histo2->Fill(1.0/(i*i),i);
5691 >  }
5692 >
5693 >  histo1->Draw();
5694 >  histo2->Draw("e1,same");
5695 >  
5696 >  Save_With_Ratio( histo1, histo2, testcanv->cd(), "Bullshit", false, false, "AnyCrap" );
5697 >  
5698 >  
5699    dout << "HELLO there!" << endl;
5700    
5701   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines