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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines