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

Comparing UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C (file contents):
Revision 1.2 by buchmann, Thu Feb 9 16:02:21 2012 UTC vs.
Revision 1.46 by pablom, Thu Aug 2 16:45:47 2012 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, 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    TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
46 <  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
47 <  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
48 <  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
49 <  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
46 >  TH1F *rawJZBeemmMC      = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,mc, luminosity);
47 >  TH1F *rawJZBeemmData    = allsamples.Draw("rawJZBeemmData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&specialcut,data, luminosity);
48 >  TH1F *rawJZBemMC      = allsamples.Draw("rawJZBemMC",jzbvariablemc,nbins,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,mc, luminosity);
49 >  TH1F *rawJZBemData    = allsamples.Draw("rawJZBemData",jzbvariabledata,nbins, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&specialcut,data, luminosity);
50    TH1F *rawttbarjzbeemmMC;
51  
52    if(method==doKM) {
53      //we only need this histo for the KM fitting...
54 <    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
55 <    MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
56 <    DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
54 >    rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,nbins, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&specialcut,mc,luminosity,allsamples.FindSample("TTJet"));
55 >    MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,MCSigmaError,method,saveas);
56 >    DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,DataSigmaError,method,saveas);
57 >    delete rawttbarjzbeemmMC;
58    }
59    else {
60      TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
# Line 51 | Line 62 | void find_peaks(float &MCPeak,float &MCP
62      reducedMC->Add(rawJZBemMC,-1);
63      reducedData->Add(rawJZBemData,-1);
64      //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)
65 <    MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
66 <    DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
67 <    
65 >    MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,MCSigmaError,method,saveas);
66 >    DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,DataSigmaError,method,saveas);
67 >    delete reducedMC;
68 >    delete reducedData;
69    }
70  
71    // Revert to original PU reweighting
# Line 61 | Line 73 | void find_peaks(float &MCPeak,float &MCP
73      
74   //  MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
75   //  DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
76 <  dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
77 <  result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
78 <  dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
79 <  result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
76 >  dout   << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
77 >  result << "   We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- " << DataSigmaError << endl;
78 >  dout   << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
79 >  result << "   We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- " << MCSigmaError << endl;
80 >  delete rawJZBeemmData;
81 >  delete rawJZBeemmMC;
82 >  delete rawJZBemData;
83 >  delete rawJZBemMC;
84    delete tempcan;
85   }
86  
87 + void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, stringstream &result, bool doPUreweighting, stringstream &datajzb, stringstream &mcjzb)
88 + {
89 +  
90 +  bool DoInvidualeemmPeaks=false;
91 +  
92 +  float mcpeak, datapeak;
93 +  float mcpeakerr, datapeakerr;
94 +  
95 +  float mceepeak,mcmmpeak;
96 +  float mceepeakerr,mcmmpeakerr;
97 +  
98 +  float datammpeak,dataeepeak;
99 +  float datammpeakerr,dataeepeakerr;
100 +  
101 +  float mcSigma,mcSigmaError, dataSigma, dataSigmaError;
102 +  
103 +  dout << "Finding global peak : " << endl;
104 +  find_one_peak_combination(TCut(""),mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma,mcSigmaError, dataSigma,dataSigmaError,result,doPUreweighting,"");
105 +  
106 +  if(DoInvidualeemmPeaks) {
107 +    dout << "Finding peak for electrons : " << endl;
108 +    find_one_peak_combination(TCut("id1==0"),mceepeak,mceepeakerr,dataeepeak,dataeepeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_ele");
109 +    dout << "Finding peak for muons : " << endl;
110 +    find_one_peak_combination(TCut("id1==1"),mcmmpeak,mcmmpeakerr,datammpeak,datammpeakerr,mcSigma,mcSigmaError,dataSigma,dataSigmaError,result,doPUreweighting,"_mu");
111 +    
112 +    datajzb << "(" << jzbvariabledata;
113 +    mcjzb << "(" << jzbvariablemc;
114 +    
115 +    if(dataeepeak>0) datajzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
116 +    else datajzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(dataeepeak) << " ";
117 +    
118 +    if(datammpeak>0) datajzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
119 +    else datajzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(datammpeak) << " ";
120 +    
121 +    if(datapeak>0) datajzb << "- (id1!=id2)*" << TMath::Abs(datapeak) << " ";
122 +    else datajzb << "+ (id1!=id2)*" << TMath::Abs(datapeak) << " ";
123 +    
124 +    datajzb << ")";
125 +    
126 +    if(mceepeak>0) mcjzb << "- (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
127 +    else mcjzb << "+ (id1==id2)*(id1==0)*" << TMath::Abs(mceepeak) << " ";
128 +    
129 +    if(mcmmpeak>0) mcjzb << "- (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
130 +    else mcjzb << "+ (id1==id2)*(id1==1)*" << TMath::Abs(mcmmpeak) << " ";
131 +    
132 +    if(mcpeak>0) mcjzb << "- (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
133 +    else mcjzb << "+ (id1!=id2)*" << TMath::Abs(mcpeak) << " ";
134 +    
135 +    mcjzb << ")";
136 +  } else {
137 +    datajzb << "(" << jzbvariabledata;
138 +      mcjzb << "(" << jzbvariablemc;
139 +    
140 +    if(datapeak>0) datajzb << "- " << TMath::Abs(datapeak) << " ";
141 +    else datajzb << "+ " << TMath::Abs(datapeak) << " ";
142 +    
143 +    datajzb << ")";
144 +    
145 +    if(mcpeak>0) mcjzb << "- " << TMath::Abs(mcpeak) << " ";
146 +    else mcjzb << "+ " << TMath::Abs(mcpeak) << " ";
147 +    
148 +    mcjzb << ")";
149 +  }
150 +  
151 +  
152 + }
153 +
154 + void make_special_obs_pred_mll_plot(string datajzb, string mcjzb, float jzbthreshold, float binWidth = 5.0) {
155 +  float min=70.0;
156 +  float max=115.0;
157 +  if(!PlottingSetup::RestrictToMassPeak) {
158 +    min=20;
159 +    max=300;
160 +  }
161 +  int nbins=int((max-min)/binWidth);
162 +  
163 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
164 +  
165 +  stringstream largerzeroS;
166 +  largerzeroS << "(" << datajzb << ">" << jzbthreshold << ")";
167 +  TCut largerzeroD(largerzeroS.str().c_str());
168 +  
169 +  stringstream smallerzeroS;
170 +  smallerzeroS << "(" << datajzb << "<-" << jzbthreshold << ")";
171 +  TCut smallerzeroD(smallerzeroS.str().c_str());
172 +
173 +
174 +  stringstream largerzeroMS;
175 +  largerzeroMS << "(" << mcjzb << ">" << jzbthreshold << ")";
176 +  TCut largerzeroM(largerzeroMS.str().c_str());
177 +  
178 +  TH1F *RcorrJZBeemm     = allsamples.Draw("RcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroD,data,luminosity);
179 +  THStack mcRcorrJZBeemm = allsamples.DrawStack("mcRcorrJZBeemm","mll",nbins,min,max, "m_{ll} [GeV}", "events", cutmass&&cutOSSF&&cutnJets&&largerzeroM,mc,luminosity);
180 +  TH1F *LcorrJZBeemm     = allsamples.Draw("LcorrJZBeemm",       "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&smallerzeroD,data,luminosity);
181 +  TH1F *RcorrJZBem       = allsamples.Draw("RcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&largerzeroD,data,luminosity);
182 +  TH1F *LcorrJZBem       = allsamples.Draw("LcorrJZBem",         "mll",nbins,min,max, "m_{ll} [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&smallerzeroD,data,luminosity);
183 +
184 +  TH1F *RcorrJZBSBem;
185 +  TH1F *LcorrJZBSBem;
186 +  TH1F *RcorrJZBSBeemm;
187 +  TH1F *LcorrJZBSBeemm;
188 +  
189 + //  TH1F *RcorrJZBeemmNoS;
190 +
191 +  if(PlottingSetup::RestrictToMassPeak) {
192 +    RcorrJZBSBem   = allsamples.Draw("RcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&largerzeroD,data, luminosity);
193 +    LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",  "mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&smallerzeroD,data, luminosity);
194 +    RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&largerzeroD,data, luminosity);
195 +    LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm","mll",nbins,min,max, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets&&smallerzeroD,data, luminosity);
196 +  }
197 +  
198 +  // Separate predictions
199 +  TH1F* SFN = (TH1F*)LcorrJZBeemm->Clone("SFN");
200 +  TH1F* OFP = (TH1F*)RcorrJZBem->Clone("OFP");
201 +  TH1F* OFN = (TH1F*)LcorrJZBem->Clone("OFN");
202 +  if(PlottingSetup::RestrictToMassPeak) {
203 +    OFP->Scale(1.0/3.0);
204 +    OFP->Add(RcorrJZBSBem,1.0/3.);
205 +    OFP->Add(RcorrJZBSBeemm,1.0/3.);
206 +    OFN->Scale(1.0/3.0);
207 +    OFN->Add(LcorrJZBSBem,1.0/3.);
208 +    OFN->Add(LcorrJZBSBeemm,1.0/3.);
209 +  }
210 +
211 +  TH1F* Bpred = (TH1F*)SFN->Clone("Bpred");
212 +  Bpred->Add(OFP);
213 +  Bpred->Add(OFN,-1);
214 +  Bpred->SetLineColor(kRed);
215 +  
216 +  RcorrJZBeemm->SetTitleOffset(1.3,"y");
217 +  RcorrJZBeemm->Draw();
218 +  mcRcorrJZBeemm.Draw("same");
219 +  Bpred->Draw("histo,same");
220 +  RcorrJZBeemm->Draw("same");
221 +  
222 +  TLegend *leg = allsamples.allbglegend();
223 +  leg->SetX1(0.58);
224 +  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
225 +  leg->AddEntry(Bpred,"predicted (data)","l");
226 +  leg->Draw("same");
227 +  
228 +  stringstream saveas;
229 +  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
230 +  CompleteSave(ckin,saveas.str());
231 +  
232 +  // Draw all predictions overlayed
233 +  unsigned int w = gStyle->GetHistLineWidth()+1; // Make line a bit wider, since we dash it
234 +  SFN->SetLineColor(kGreen+2);
235 +  SFN->SetLineStyle(2);
236 +  SFN->SetLineWidth(w);
237 +  OFP->SetLineColor(kBlue+2);
238 +  OFP->SetLineStyle(2);
239 +  OFP->SetLineWidth(w);
240 +  OFN->SetLineColor(kMagenta+2);
241 +  OFN->SetLineStyle(3);
242 +  OFN->SetLineWidth(w);
243 +  
244 +  RcorrJZBeemm->Draw();
245 +  SFN->Draw("histo,same");
246 +  OFP->Draw("histo,same");
247 +  OFN->Draw("histo,same");
248 +  Bpred->Draw("histo,same");
249 +  RcorrJZBeemm->Draw("same");
250 +  
251 +  TLegend *leg2 = make_legend("",0.52,0.7);
252 +  leg2->AddEntry(RcorrJZBeemm,"observed (data)","lp");
253 +  leg2->AddEntry(Bpred,"predicted (data)","l");
254 +  leg2->AddEntry(SFN,  "  SF JZB<0","l");
255 +  leg2->AddEntry(OFN,  "  OF JZB<0","l");
256 +  leg2->AddEntry(OFP,  "  OF JZB>0","l");
257 +  leg2->Draw("same");
258 +  
259 +  saveas.str("");
260 +  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
261 +  CompleteSave(ckin,saveas.str());
262 +  
263 +  
264 +
265 +  delete RcorrJZBeemm;
266 +  delete LcorrJZBeemm;
267 +  delete RcorrJZBem;
268 +  delete LcorrJZBem;
269 +  if(PlottingSetup::RestrictToMassPeak) {
270 +    delete RcorrJZBSBeemm;
271 +    delete LcorrJZBSBeemm;
272 +    delete RcorrJZBSBem;
273 +    delete LcorrJZBSBem;
274 +  }
275 +  delete Bpred;
276 +  delete ckin;
277 + }
278 +
279   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
280    
281    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
# Line 102 | Line 310 | void make_special_mll_plot(int nbins, fl
310    TIter next(bgleg->GetListOfPrimitives());
311    TObject* obj;
312    // Copy the nice bkgd legend skipping the "data"
313 <  while ( obj = next() )
313 >  while ( (obj = next()) )
314      if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
315        kinleg->GetListOfPrimitives()->Add(obj);
316  
# Line 121 | Line 329 | void draw_ratio_plot(TH1* hdata, THStack
329    TIter next(hmc.GetHists());
330    TObject* obj;
331    TH1* hratio = NULL;
332 <  while ( obj = next() ) {
332 >  while ( (obj = next()) ) {
333      if ( !hratio ) {
334        hratio = (TH1*)obj->Clone();
335        hratio->SetName("hratio");
# Line 152 | Line 360 | void draw_ratio_plot(TH1* hdata, THStack
360    oneline->Draw("same");
361   }
362  
363 + void make_OFSF_plot(string variable, string addcut, string legendTitle, int nbins, float min, float max, bool logscale,
364 +                   string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false, float legendPosition=0.3) {
365 +
366 +  TCut ibasiccut=basiccut;
367 +  bool draw_separation_lines=false;
368 +
369 +  if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
370 +
371 +  if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
372 +
373 +  TCut cutSF;
374 +  TCut cutOF;
375 +
376 +  cutOF=cutOSOF&&cutnJets&&ibasiccut;
377 +  cutSF=cutOSSF&&cutnJets&&ibasiccut;
378 +
379 +
380 +  TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
381 +  ckin->SetLogy(logscale);
382 +  TH1F *datahistoSF = allsamples.Draw("datahistoSF",variable,nbins,min,max, xlabel, "events",cutSF,data,luminosity);
383 +  TH1F *datahistoOF = allsamples.Draw("datahistoOF",variable,nbins,min,max, xlabel, "events",cutOF,data,luminosity);
384 +  string signal("LM3");
385 +  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
386 +  int idx = signalsamples.FindSample(signal)[0];
387 +  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cutSF);
388 +  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
389 +  signalhisto->SetLineColor((signalsamples.collection)[idx].samplecolor);
390 +  datahistoSF->SetMarkerSize(DataMarkerSize);
391 +  datahistoOF->SetLineColor(kRed);
392 +
393 +  if ( !logscale ) {
394 +    datahistoSF->SetMinimum(0); // Defaults
395 +    datahistoOF->SetMinimum(0); // Defaults
396 +  } else {
397 +    datahistoSF->SetMinimum(0.5);
398 +    datahistoOF->SetMinimum(0.5);
399 +  }
400 +  if (logscale) {
401 +    datahistoSF->SetMaximum(5.3*datahistoSF->GetMaximum());
402 +    datahistoOF->SetMaximum(5.3*datahistoSF->GetMaximum());
403 +  } else {
404 +    datahistoSF->SetMaximum(2.0*datahistoSF->GetMaximum());
405 +    datahistoOF->SetMaximum(2.0*datahistoOF->GetMaximum());
406 +  }
407 +
408 +  datahistoSF->GetXaxis()->SetTitle(xlabel.c_str());
409 +  datahistoOF->GetXaxis()->SetTitle(xlabel.c_str());
410 +  signalhisto->GetXaxis()->SetTitle(xlabel.c_str());
411 +  datahistoSF->GetYaxis()->SetTitle("N. Events");
412 +  datahistoOF->GetYaxis()->SetTitle("N. Events");
413 +  signalhisto->GetYaxis()->SetTitle("N. Events");
414 +  datahistoSF->GetXaxis()->CenterTitle();
415 +  datahistoOF->GetXaxis()->CenterTitle();
416 +  signalhisto->GetXaxis()->CenterTitle();
417 +  datahistoSF->GetYaxis()->CenterTitle();
418 +  datahistoOF->GetYaxis()->CenterTitle();
419 +  signalhisto->GetYaxis()->CenterTitle();
420 +
421 +  TLegend *mleg = new TLegend(0.2+legendPosition, 0.72, 0.55+legendPosition, 0.87, legendTitle.c_str());
422 +  mleg->SetFillColor(kWhite);
423 +  mleg->SetTextFont(42);
424 +  mleg->SetTextSize(0.048);
425 +  mleg->SetLineWidth(0);
426 +  mleg->SetBorderSize(0);
427 +  mleg->AddEntry(datahistoSF, "S. Flavor", "PL");
428 +  mleg->AddEntry(datahistoOF, "O. Flavor", "L");
429 +  mleg->AddEntry(signalhisto, "LM3", "L");
430 +
431 +  datahistoSF->Draw("E1");
432 +  datahistoOF->Draw("HIST,SAMES");
433 +  signalhisto->Draw("HIST,SAMES");
434 +  mleg->Draw();
435 +  DrawPrelim();
436 +  CompleteSave(ckin, "./SFOF/" + filename);
437 +
438 +  datahistoSF->Delete();
439 +  datahistoOF->Delete();
440 +  signalhisto->Delete();
441 +  delete mleg;
442 +  delete ckin;
443 +
444 + }
445 +
446 +
447 +
448   float lastrange_min=0;
449   float lastrange_max=0;
450  
# Line 182 | Line 475 | void make_kin_plot(string variable, stri
475    TCut cut;
476    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
477    if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
478 +  if(filename=="nJets_osof") cut=cutmass&&cutOSOF&&ibasiccut;
479    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
480    if(filename=="mll") {
481          cut=cutOSSF&&cutnJets&&ibasiccut;
# Line 193 | Line 487 | void make_kin_plot(string variable, stri
487          draw_separation_lines=true;
488    }
489    if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
490 <  if(filename=="mll_aboveJZB100") cut=cutOSSF&&cutnJets&&ibasiccut;
490 >  if(Contains(filename,"aboveJZB")) cut=cutOSSF&&cutnJets&&ibasiccut;
491 >  if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
492 >  if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
493 >  if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
494    if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
495    if(filename=="mll_inclusive_osof") cut=cutOSOF;
496    if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
# Line 205 | Line 502 | void make_kin_plot(string variable, stri
502    ckin->SetLogy(logscale);
503    TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
504    datahisto->SetMarkerSize(DataMarkerSize);
505 <  THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
505 >  if ( !logscale ) datahisto->SetMinimum(0); // Defaults
506 >  else datahisto->SetMinimum(0.5);
507 >  // Custom max.
508 >  if(variable=="TMath::Abs(pfJetDphiMet[0])") datahisto->SetMaximum(1.5*datahisto->GetMaximum());
509    if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
510    if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
511 <  if(filename=="mll_inclusive") datahisto->SetMinimum(1);
511 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_mm"||filename=="mll_inclusive_ee") datahisto->SetMinimum(1);
512    if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
513    if(filename=="mll_osof") datahisto->SetMinimum(9);
514 +  if (logscale) datahisto->SetMaximum(5.3*datahisto->GetMaximum());
515 +  else datahisto->SetMaximum(1.3*datahisto->GetMaximum());
516  
215  datahisto->SetMaximum(5.3*datahisto->GetMaximum());
216  datahisto->Draw("e1");
217  ckin->Update();
517    if(loadlastminmax) {
518          datahisto->SetMinimum(lastrange_min);
519          datahisto->SetMaximum(lastrange_max);
# Line 224 | Line 523 | void make_kin_plot(string variable, stri
523          }              
524    }
525  
526 +  // Draw signal by hand (for some reason I don't manage to use the sample class: it adds it to the stack!)
527 +  string signal("LM3");
528 +  TH1F* signalhisto = new TH1F("signalhisto",signal.c_str(),nbins,min,max);
529 +  int idx = signalsamples.FindSample(signal)[0];
530 +  (signalsamples.collection)[idx].events->Project("signalhisto",variable.c_str(),cut);
531 +  signalhisto->Scale((signalsamples.collection)[idx].weight*luminosity);
532 +  signalhisto->SetLineColor(kOrange);
533 +
534 +  THStack mcstack   = allsamples.DrawStack("mcstack",  variable,nbins,min,max,xlabel,"events",cut,mc,luminosity);
535 +  datahisto->Draw("e1");
536 +  ckin->Update();
537    mcstack.Draw("same");
538 +  
539    datahisto->Draw("same,e1");
540    TLegend *kinleg = allsamples.allbglegend();
541    kinleg->Draw();
# Line 267 | Line 578 | void make_kin_plot(string variable, stri
578          kinpad->SetLogy(logscale);
579          datahisto->Draw("e1");
580          mcstack.Draw("same");
581 +        signalhisto->Draw("same");
582          datahisto->Draw("same,e1");
583          datahisto->Draw("same,axis");
584          if(RestrictToMassPeak&&draw_separation_lines) {
# Line 274 | Line 586 | void make_kin_plot(string variable, stri
586            upperboundary->Draw("same");
587          }
588            
589 +        kinleg->AddEntry("signalhisto",signal.c_str(),"l");
590          kinleg->Draw();
591          write_cut->Draw();
592          DrawPrelim();
# Line 291 | Line 604 | void make_kin_plot(string variable, stri
604    delete ckin;
605   }
606  
607 <
295 < void make_JES_plot() {
607 > void make_JES_plot(TCut cut, string name) {
608  
609    int nbins=10;
610    float min=-0.5;
611    float max = 9.5;
612    bool logscale=true;
613    string xlabel="nJets";
302  TCut cut=cutmass&&cutOSSF&&basiccut;
614  
615    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
616    ckin->SetLogy(logscale);
617 <  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
617 >  TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,data,luminosity);
618    datahisto->SetMarkerSize(DataMarkerSize);
619 <  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
620 <  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
621 <  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
619 >  THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum40",nbins,min,max, xlabel, "events",cut,mc,luminosity);
620 >  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum40p1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
621 >  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum40n1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
622  
623    datahisto->SetMinimum(1);
624    datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
# Line 332 | Line 643 | void make_JES_plot() {
643    TLegend *kinleg = allsamples.allbglegend();
644    kinleg->AddEntry(JESunc,"JES uncertainty","f");
645    kinleg->Draw();
646 <  CompleteSave(ckin,"Systematics/JES");
646 >  CompleteSave(ckin,"Systematics/JES"+name);
647    datahisto->Delete();
648    delete ckin;
649  
# Line 343 | Line 654 | void do_kinematic_plots(string mcjzb, st
654    bool dolog=true;
655    bool nolog=false;
656    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
657 <  float mll_low=40;
657 >  float mll_low=50;
658    float mll_hi=160;
659    if(!PlottingSetup::RestrictToMassPeak) {
660 <        mll_low=30;
661 <        mll_hi=180;
660 >        mll_low=20;
661 >        mll_hi=300;
662    }
663 +
664 +  make_OFSF_plot("pfJetGoodNum40", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 5, 3, 8, true, "N. jets", "njetsLow", false, false, false, 0.2);
665 +  make_OFSF_plot("pfJetGoodNum40", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 5, 3, 8, true, "N. jets", "njetsMed", false, false, false, 0.2);
666 +  make_OFSF_plot("pfJetGoodPt[0]/pfJetGoodPt[1]", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2Low", false, false, false, 0.2);
667 +  make_OFSF_plot("pfJetGoodPt[0]/pfJetGoodPt[1]", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 20, 1, 10, true, "pt_{j}^{1}/pt_{j}^{2}", "jpt1pt2Med", false, false, false, 0.2);
668 +  make_OFSF_plot("TMath::Abs(pfJetDphiMet[0])", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphijetmetLow", false, false, false, 0.0);
669 +  make_OFSF_plot("TMath::Abs(pfJetDphiMet[0])", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "|#Delta#phi(jet1,MET)|", "dphijetmetMed", false, false, false, 0.0);
670 +  make_OFSF_plot("TMath::Abs(dphi)", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphiLow", false, false, false, 0.2);
671 +  make_OFSF_plot("TMath::Abs(dphi)", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "|#Delta#phi(l1,l2)|", "dphiMed", false, false, false, 0.2);
672 +  make_OFSF_plot("TMath::Abs(dphiMet1)", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1Low", false, false, false, 0.2);
673 +  make_OFSF_plot("TMath::Abs(dphiMet1)", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "|#Delta#phi(l1,MET)|", "dphiMet1Med", false, false, false, 0.2);
674 +  make_OFSF_plot("TMath::Abs(dphiMet2)", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2Low", false, false, false, 0.2);
675 +  make_OFSF_plot("TMath::Abs(dphiMet2)", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "|#Delta#phi(l2,MET)|", "dphiMet2Med", false, false, false, 0.2);
676 +  make_OFSF_plot("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", "dphilcLow", false, false, false, 0.2);
677 +  make_OFSF_plot("TMath::Min(TMath::Abs(dphiMet1), TMath::Abs(dphiMet2))", "mll>40&&mll<70&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "Min(|#Delta#phi(l,MET)|)", "dphilcMed", false, false, false, 0.2);
678 +  make_OFSF_plot("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", "dphijcLow", false, false, false, 0.2);
679 +  make_OFSF_plot("TMath::Min(TMath::Abs(pfJetDphiMet[0]), TMath::Min(TMath::Abs(pfJetDphiMet[1]), TMath::Abs(pfJetDphiMet[2])))", "mll>20&&mll<40&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "Min(|#Delta#phi(jet,MET)|)", "dphijcMed", false, false, false, 0.2);
680 +  make_OFSF_plot("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "Min(#Pi - |#Delta#phi(l,MET)|)", "dphilcoLow", false, false, false, 0.2);
681 +  make_OFSF_plot("TMath::Min((TMath::Pi()-TMath::Abs(dphiMet1)), (TMath::Pi() - TMath::Abs(dphiMet2)))", "mll>20&&mll<40&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "Min(#Pi - |#Delta#phi(l,MET)|)", "dphilcoMed", false, false, false, 0.2);
682 +  make_OFSF_plot("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", "mll>20&&mll<40&&met[4]>100", "20 GeV < mll < 40 GeV", 16, 0, 3.2, false, "Min(#Pi - |#Delta#phi(jet,MET)|)", "dphijcoLow", false, false, false, 0.2);
683 +  make_OFSF_plot("TMath::Min((TMath::Pi()-TMath::Abs(pfJetDphiMet[0])), TMath::Min( (TMath::Pi()-TMath::Abs(pfJetDphiMet[1])), (TMath::Pi() - TMath::Abs(pfJetDphiMet[2]))))", "mll>20&&mll<40&&met[4]>100", "40 GeV < mll < 70 GeV", 16, 0, 3.2, false, "Min(#Pi - |#Delta#phi(jet,MET)|)", "dphijcoMed", false, false, false, 0.2);
684 +
685 +
686 +
687 +  make_kin_plot("met[4]","",70,0,350,dolog,"MET [GeV]","met",doPF,true);
688 +
689    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
690    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
691    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
692    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
693 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
694 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
695 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
696 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
697 <  make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
361 <  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
362 <  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
363 <  make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
364 <  make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
365 <  make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
366 <  make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
367 <  make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
368 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
369 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
693 >  make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
694 >  make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
695 >  make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
696 >  make_kin_plot("mll","",(int)((mll_hi-mll_low))/5,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
697 >  make_kin_plot("mll","",(int)((350-mll_low))/5,mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
698    if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
699 +
700 +  make_kin_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","",45,1,10,dolog,"pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",doPF,true);
701 +  make_kin_plot("TMath::Abs(pfJetDphiMet[0])","",32,0,3.2,nolog,"|#Delta#phi(jet1,MET)|","dphiJ1MET",doPF,true);
702 +
703 +  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets",doPF);
704 +  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
705 +  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
706 +
707 +  make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
708 + //  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
709 + //  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
710 +  make_kin_plot("pt","",50,0,500,dolog,"Z p_{T} [GeV]","Zpt",doPF);
711 +  make_kin_plot("pt1","",50,0,200,nolog,"p_{T} [GeV]","pt1",doPF);
712 +  make_kin_plot("pt2","",50,0,200,nolog,"p_{T} [GeV]","pt2",doPF);
713 +  make_kin_plot("eta1","",40,-3,3,nolog,"#eta_{l}","eta",doPF);
714 +  make_kin_plot("jzb[1]","",100,-150,200,dolog,"JZB [GeV]","jzb_ossf",doPF);
715    stringstream jzbcut;
716    jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
717 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
717 >  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
718 >  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);
719 >  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);
720 >  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);
721 >  stringstream jzbcut2;
722 >  jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
723 >  make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
724 >  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);
725 >  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);
726 >  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);
727 >  stringstream jzbcut3;
728 >  jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
729 >  make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);  
730 >  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);
731 >  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);  
732 >  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);  
733 >
734 >  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",doPF,true);
735 >
736 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
737 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
738 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,80);
739 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
740 > //   make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
741 > //   make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
742 > //   make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
743 >
744 >  make_JES_plot(cutmass&&cutOSSF&&basiccut,"_ossf");
745 >  make_JES_plot(cutmass&&cutOSOF&&basiccut,"_osof");
746 >
747 >
748   }
749  
750   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
751                       int nbins, float xmin, float xmax, bool log,
752                       float ymin=0, float ymax=0, bool leftJustified=false ) {
753 <      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
753 >  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
754  
755    TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
756    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__));
757 <  if(var=="numVtx") cutWeight=TCut("1.0");
757 >  //if(var=="numVtx") cutWeight=TCut("1.0");
758    TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
759    TCut jzbMC[]  = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
760  
# Line 404 | Line 778 | void make_comp_plot( string var, string
778        TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
779        ccomp->SetLogy(log);
780        TH1F *datahisto = allsamples.Draw("datahisto",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
781 <      TH1F *lm4histo = signalsamples.Draw("lm4histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
781 >      TH1F *lm3histo  = signalsamples.Draw("lm3histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],data,luminosity,signalsamples.FindSample("LM3"));
782        THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],  mc,  luminosity);
783        datahisto->SetMarkerSize(DataMarkerSize);
784        if (ymax>ymin) datahisto->SetMaximum(ymax);
785 <      lm4histo->SetLineStyle(2);
785 >      lm3histo->SetLineStyle(2);
786        datahisto->Draw("e1");
787        mcstack.Draw("same");
788        datahisto->Draw("same,e1");
789 < //      lm4histo->Draw("hist,same");
789 >      lm3histo->Draw("hist,same");
790        TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
791        if ( leftJustified ) {
792          Float_t w = kinleg->GetX2()-kinleg->GetX1();
793          kinleg->SetX1(0.2);
794          kinleg->SetX2(0.2+w);
795        }
796 < //      kinleg->AddEntry(lm4histo,"LM4","l");
796 >      kinleg->AddEntry(lm3histo,"LM3","l");
797        kinleg->Draw();
798        TText* write_variable = write_text(0.99,0.01,var);
799        write_variable->SetTextAlign(31);
# Line 428 | Line 802 | void make_comp_plot( string var, string
802        CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
803        delete datahisto;
804        delete ccomp;
805 <      delete lm4histo;
805 >      delete lm3histo;
806      }
807    cutWeight=weightbackup;
808   }
# Line 438 | Line 812 | void region_comparison_plots(string mcjz
812    dout << "Creating comparison plots for signal and control regions" << endl;
813    // Compare a few quantities in the signal region and all 7 control regions
814  
815 <  switch_overunderflow(true);  // switching overflow/underflow bins on
815 > //  switch_overunderflow(true);  // switching overflow/underflow bins on
816      
817    
818      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
819 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
819 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
820      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
821      float mll_low=50;float mll_high=170;
822      if(!PlottingSetup::RestrictToMassPeak) {
823 <        mll_high=200;
824 <        mll_low=50;
823 >        mll_high=300;
824 >        mll_low=20;
825      }
826 <    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,30,mll_low,mll_high,false,0,16.);
826 >    make_comp_plot("pfJetGoodPt[0]/pfJetGoodPt[1]","pt_{j}^{1}/pt_{j}^{2}","j1j2ratio",jzbcut,mcjzb,datajzb,100,0,10,true);
827 >    make_comp_plot("TMath::Abs(pfJetDphiMet[0])","|#Delta#phi(jet1,MET)|","dphiJ1MET",jzbcut,mcjzb,datajzb,32,0,3.2,false,0,0,true);
828 >
829 >    make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,56,mll_low,mll_high,false,0,16.);
830      make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
831 <    make_comp_plot("pfJetGoodNum","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
831 >    make_comp_plot("pfJetGoodNum40","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
832 >    make_comp_plot("pfJetGoodNumBtag","#(b-jets)","nBjets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
833      make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
834 <    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,20,0.,20.,false,0,16.);
834 >    make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,40,0.,40.,false,0,16.);
835      make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
836      make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
837 +    make_comp_plot("eta1","#eta_1","eta1",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
838 +    make_comp_plot("eta2","#eta_2","eta2",jzbcut,mcjzb,datajzb,10,0.,2.5,false,0,16.);
839    }
840  
841    switch_overunderflow(false); // switching overflow/underflow bins off
# Line 479 | Line 859 | void signal_bg_comparison()
859    
860    float simulatedlumi=luminosity;//in pb please - adjust to your likings
861    
862 <  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
863 <  TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
862 >  TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
863 >  TH1F *JZBplotLM4;
864 >  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"));
865 >  else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
866    TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
867    
868    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
# Line 504 | Line 886 | void signal_bg_comparison()
886    TLegend *signal_bg_comparison_leg2 =  make_legend("",0.55,0.75,false);
887    signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
888    signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
889 <  signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
889 >  if(PlottingSetup::RestrictToMassPeak) signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
890 >  else signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM3","f");
891    signal_bg_comparison_leg2->Draw();
892    DrawMCPrelim(simulatedlumi);
893    CompleteSave(can,"jzb_bg_vs_signal_distribution");
# Line 746 | Line 1129 | if you want to start from scratch (witho
1129    return return_functions;
1130   }
1131  
1132 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false )
1132 > void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
1133   {
1134 + //  switch_overunderflow(true);
1135    bool is_data=false;
1136    bool use_signal=false;
1137    if(use_data==1) is_data=true;
# Line 756 | Line 1140 | void do_prediction_plot(string jzb, TCan
1140    if(is_data) nbins=50;
1141    float low=0;
1142    float hi=500;
1143 +  
1144    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
1145    TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1146    TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1147    TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1148    TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1149 +
1150    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
1151    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
1152    blankback->GetXaxis()->CenterTitle();
# Line 775 | Line 1161 | void do_prediction_plot(string jzb, TCan
1161    TH1F *RcorrJZBeemmNoS;
1162  
1163      //these are for the ratio
1164 +  
1165    TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1166    TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1167    TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
# Line 793 | Line 1180 | void do_prediction_plot(string jzb, TCan
1180      LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1181      RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1182      LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1183 <
1183 >    
1184      //these are for the ratio
1185      JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1186      JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1187      JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1188      JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
802
1189    }
1190    
1191    TH1F *lm4RcorrJZBeemm;
1192 <  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"));
1192 >  if(overlay_signal || use_data == 2 || use_data == 1) lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM"));
1193    
1194    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
1195    
# Line 812 | Line 1198 | void do_prediction_plot(string jzb, TCan
1198      
1199    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1200    TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
1201 +    
1202 +  TH1F *BpredSys = new TH1F("Bpredsys","Bpredsys",PlottingSetup::global_ratio_binning.size()-1,&PlottingSetup::global_ratio_binning[0]);
1203 +  ClearHisto(BpredSys);
1204 +    
1205    if(PlottingSetup::RestrictToMassPeak) {
1206      Bpred->Add(RcorrJZBem,1.0/3.);
1207      Bpred->Add(LcorrJZBem,-1.0/3.);
# Line 834 | Line 1224 | void do_prediction_plot(string jzb, TCan
1224      JBpred->Add(JLcorrJZBSBem,-1.0/3.);
1225      JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
1226      JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
1227 +      
1228 +    //Systematics:
1229 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertONPEAK*zjetsestimateuncertONPEAK);
1230 +    AddSquared(BpredSys,JRcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
1231 +    AddSquared(BpredSys,JLcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
1232 +    AddSquared(BpredSys,JRcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
1233 +    AddSquared(BpredSys,JLcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
1234 +    AddSquared(BpredSys,JRcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
1235 +    AddSquared(BpredSys,JLcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
1236    } else {
1237      Bpred->Add(RcorrJZBem,1.0);
1238      Bpred->Add(LcorrJZBem,-1.0);
# Line 843 | Line 1242 | void do_prediction_plot(string jzb, TCan
1242      //these are for the ratio
1243      JBpred->Add(JRcorrJZBem,1.0);
1244      JBpred->Add(JLcorrJZBem,-1.0);
1245 +      
1246 +    //Systematics
1247 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertOFFPEAK*zjetsestimateuncertOFFPEAK);
1248 +    AddSquared(BpredSys,JRcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
1249 +    AddSquared(BpredSys,JLcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
1250 +
1251    }
1252      
1253 <  
1253 >  SQRT(BpredSys);
1254 >  BpredSys->Divide(JBpred);
1255 >
1256    
1257    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
1258    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
# Line 890 | Line 1297 | void do_prediction_plot(string jzb, TCan
1297    blankback->Draw();
1298    if(use_data==1)
1299    {
1300 +    //Bpred->SetLineWidth(3); //paper style.overruled.
1301 +    //lm4RcorrJZBeemm->SetLineWidth(3); //paper style.overruled.
1302      analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
1303      kinpad->cd();//necessary because the extended fit function creates its own canvas
1304      RcorrJZBeemm->Draw("e1x0,same");
1305  
1306      Bpred->Draw("hist,same");
1307 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1307 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1308      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1309 +    lm4RcorrJZBeemm->Draw("hist,same");
1310      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
1311      legBpred->AddEntry(Bpred,"predicted","l");
1312 <    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
1313 <    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
1314 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1312 > //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
1313 > //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
1314 >    legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
1315      legBpred->Draw();
1316      DrawPrelim();
1317  
1318      //this plot shows what the prediction is composed of
1319 <    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
1320 <    specialcanv->SetLogy(1);
1321 <    Zjetspred->SetFillColor(kYellow);
1322 <    Zjetspred->SetLineColor(kYellow);
1323 <    TTbarpred->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1324 <    TTbarpred->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1319 >    TPad *predcomppad = new TPad("predcomppad","predcomppad",0,0,1,1);
1320 >    float CurrentBpredLineWidth=Bpred->GetLineWidth();
1321 >    Bpred->SetLineWidth(2);
1322 >    predcomppad->cd();
1323 >    predcomppad->SetLogy(1);
1324 >    
1325 >    TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
1326 >    TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
1327 >    sidebandsemu->Add(jzbnegative,-1);
1328 >    
1329 >    jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1330 >    jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1331 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1332 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1333 >    
1334      THStack predcomposition("predcomposition","prediction composition");
1335 <    predcomposition.Add(TTbarpred);
1336 <    predcomposition.Add(Zjetspred);
1335 >    predcomposition.Add(sidebandsemu);
1336 >    predcomposition.Add(jzbnegative);
1337      blankback->Draw();
1338      RcorrJZBeemm->Draw("e1x0,same");
1339      predcomposition.Draw("histo,same");//
1340      Bpred->Draw("hist,same");
1341 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1341 > //    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1342      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1343 <    legBpred->Draw();
1343 > //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
1344 >    lm4RcorrJZBeemm->SetLineWidth(2);
1345 >    //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
1346 >    lm4RcorrJZBeemm->Draw("histo,same");
1347      DrawPrelim();
1348 <    TLegend *specialleg = new TLegend(0.6,0.4,0.89,0.55);
1349 <    specialleg->SetFillColor(kWhite);specialleg->SetLineColor(kWhite);
1350 <    specialleg->AddEntry(Zjetspred,"Z+Jets prediction","f");
1351 <    specialleg->AddEntry(TTbarpred,"t#bar{t} prediction","f");
1352 <    specialleg->Draw("same");
1353 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionComposition");
1354 <
1355 <    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
1348 >    TLegend *speciallegBpred = make_legend("",0.45,0.55);
1349 >    //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
1350 >    speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
1351 >    speciallegBpred->AddEntry(Bpred,"Total background","l");
1352 >    speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
1353 >    if(PlottingSetup::RestrictToMassPeak) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
1354 >    else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
1355 > //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
1356 >    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1357 >    speciallegBpred->Draw();
1358 >    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
1359 >    
1360 >    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
1361 >    specialcanv->SetLogy(1);
1362 > //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
1363      blankback->Draw();
1364 <    kostack.Draw("same");
1364 > //    kostack.Draw("same");
1365 >    predcomposition.Draw();
1366      Bpred->Draw("hist,same");
1367 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1367 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1368      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1369      legBpred->Draw();
1370      DrawPrelim();
1371 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionCompositioninMC");
1371 >    CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
1372 >    Bpred->SetLineWidth((int)CurrentBpredLineWidth);
1373      
1374 <    delete specialcanv;
1375 <    delete specialleg;
1374 >    
1375 >    //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;
1376 >    
1377 >    delete speciallegBpred;
1378      delete Zjetspred;
1379      delete TTbarpred;
1380      
# Line 949 | Line 1382 | void do_prediction_plot(string jzb, TCan
1382    }
1383    if(use_data==0) {
1384      RcorrJZBeemm->Draw("e1x0,same");
1385 +    //Bpred->SetLineWidth(3); // paper style. overruled.
1386      Bpred->Draw("hist,same");
1387      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1388 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
1389 <    legBpred->AddEntry(Bpred,"MC predicted","l");
1388 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1389 >    legBpred->AddEntry(Bpred,"MC predicted","l");    
1390      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
1391      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
1392      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
# Line 963 | Line 1397 | void do_prediction_plot(string jzb, TCan
1397    }
1398    if(use_data==2) {
1399      RcorrJZBeemm->Draw("e1x0,same");
1400 +    //Bpred->SetLineWidth(3); // paper style. overruled.
1401      Bpred->Draw("hist,same");
1402      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1403 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
1403 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1404      legBpred->AddEntry(Bpred,"MC predicted","l");
1405 <    legBpred2->AddEntry(RcorrJZBeemm,"MC observed","p");
1405 >    legBpred2->AddEntry(RcorrJZBeemm,"MC true","p");
1406      legBpred2->AddEntry(Bpred,"MC predicted","l");
1407      {
1408        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 1413 | void do_prediction_plot(string jzb, TCan
1413   //      CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
1414      }
1415      {
1416 +      //lm4RcorrJZBeemm->SetLineWidth(3); //paper style. overruled.
1417 +      //RcorrJZBeemmNoS->SetLineWidth(3); //paper style. overruled.
1418 +      //lm4RcorrJZBeemm->SetLineStyle(2); //paper style. overruled.
1419 +      //RcorrJZBeemmNoS->SetLineStyle(3); //paper style. overruled.
1420 +      //lm4RcorrJZBeemm->SetLineColor(kOrange+1); //paper style. overruled.
1421 +      
1422        RcorrJZBeemmNoS->SetLineStyle(2);
1423        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
1424        legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
# Line 996 | Line 1437 | void do_prediction_plot(string jzb, TCan
1437    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
1438    string ytitle("ratio");
1439    if ( use_data==1 ) ytitle = "data/pred";
1440 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
1440 >  //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
1441 >  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,false,ytitle,BpredSys);//not extending the y range anymore up to 4
1442  
1443    
1444    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1445 <  /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1446 <  if(!PlottingSetup::RestrictToMassPeak) return;
1447 <  TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1448 <  Bpredem->Add(RcorrJZBem);
1449 <  Bpredem->Add(LcorrJZBem,-1);
1450 <  TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1451 <  BpredSBem->Add(RcorrJZBSBem);
1452 <  Bpred->Add(LcorrJZBSBem,-1);
1453 <  TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
1454 <  BpredSBeemm->Add(RcorrJZBSBeemm);
1455 <  BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1456 <  globalcanvas->cd();
1457 <  globalcanvas->SetLogy(1);
1458 <
1459 <  RcorrJZBeemm->SetMarkerStyle(20);
1460 <  RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1461 <  blankback->Draw();
1462 <  RcorrJZBeemm->Draw("e1x0,same");
1463 <  RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1464 <  
1465 <  Bpredem->SetLineColor(kRed+1);
1466 <  Bpredem->SetStats(0);
1467 <  Bpredem->Draw("hist,same");
1468 <
1469 <  BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1470 <  BpredSBem->SetLineStyle(2);
1471 <  BpredSBem->Draw("hist,same");
1472 <
1473 <  BpredSBeemm->SetLineColor(kBlue+1);
1474 <  BpredSBeemm->SetLineStyle(3);
1475 <  BpredSBeemm->Draw("hist,same");
1476 <  RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1477 <
1478 <  TLegend *legBpredc = make_legend("",0.6,0.55);
1479 <  if(use_data==1)
1480 <  {
1481 <    legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1482 <    legBpredc->AddEntry(Bpredem,"OFZP","l");
1483 <    legBpredc->AddEntry(BpredSBem,"OFSB","l");
1484 <    legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1485 <    legBpredc->Draw();
1486 <    CompleteSave(globalcanvas,"Bpred_Data_comparison");
1487 <  }
1488 <  if(use_data==0) {
1489 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1490 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1491 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1492 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1493 <    legBpredc->Draw();
1494 <    CompleteSave(globalcanvas,"Bpred_MC_comparison");
1495 <  }
1496 <  if(use_data==2) {
1497 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1498 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1499 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1500 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1501 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1502 <    legBpredc->Draw();
1503 <    CompleteSave(globalcanvas,"Bpred_MCwithS_comparison");
1445 >  // The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1446 >  if(PlottingSetup::RestrictToMassPeak) {
1447 >    TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1448 >    Bpredem->Add(RcorrJZBem);
1449 >    Bpredem->Add(LcorrJZBem,-1);
1450 >    TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1451 >    BpredSBem->Add(RcorrJZBSBem);
1452 >    Bpred->Add(LcorrJZBSBem,-1);
1453 >    TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
1454 >    BpredSBeemm->Add(RcorrJZBSBeemm);
1455 >    BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1456 >    globalcanvas->cd();
1457 >    globalcanvas->SetLogy(1);
1458 >    
1459 >    RcorrJZBeemm->SetMarkerStyle(20);
1460 >    RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1461 >    blankback->Draw();
1462 >    RcorrJZBeemm->Draw("e1x0,same");
1463 >    RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1464 >    
1465 >    Bpredem->SetLineColor(kRed+1);
1466 >    Bpredem->SetStats(0);
1467 >    Bpredem->Draw("hist,same");
1468 >    
1469 >    BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1470 >    BpredSBem->SetLineStyle(2);
1471 >    BpredSBem->Draw("hist,same");
1472 >    
1473 >    BpredSBeemm->SetLineColor(kBlue+1);
1474 >    BpredSBeemm->SetLineStyle(3);
1475 >    BpredSBeemm->Draw("hist,same");
1476 >    RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1477 >    
1478 >    TLegend *legBpredc = make_legend("",0.6,0.55);
1479 >    if(use_data==1)
1480 >    {
1481 >      legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1482 >      legBpredc->AddEntry(Bpredem,"OFZP","l");
1483 >      legBpredc->AddEntry(BpredSBem,"OFSB","l");
1484 >      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1485 >      legBpredc->Draw();
1486 >      CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
1487 >    }
1488 >    if(use_data==0) {
1489 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1490 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1491 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1492 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1493 >      legBpredc->Draw();
1494 >      CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
1495 >    }
1496 >    if(use_data==2) {
1497 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1498 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1499 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1500 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1501 >      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1502 >      legBpredc->Draw();
1503 >      CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
1504 >    }
1505    }
1506 +  
1507 +  TFile *f = new TFile("tester.root","RECREATE");
1508 +  RcorrJZBeemm->Write();
1509 +  Bpred->Write();
1510 +  f->Close();
1511 +  
1512    delete RcorrJZBeemm;
1513    delete LcorrJZBeemm;
1514    delete RcorrJZBem;
# Line 1072 | Line 1521 | void do_prediction_plot(string jzb, TCan
1521  
1522    delete blankback;
1523    
1524 +  delete BpredSys;
1525    if(PlottingSetup::RestrictToMassPeak) {
1526      delete RcorrJZBSBem;
1527      delete LcorrJZBSBem;
# Line 1084 | Line 1534 | void do_prediction_plot(string jzb, TCan
1534      delete JLcorrJZBSBeemm;
1535    }
1536    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1537 +  switch_overunderflow(false);
1538   }
1539  
1540   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
1541    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
1542 <  do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
1543 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
1544 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
1542 >  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
1543 >  if ( !PlottingSetup::Approved ) {
1544 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
1545 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
1546 >  } else {
1547 >    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
1548 >  }
1549   }
1550  
1551   void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
# Line 1258 | Line 1713 | void lepton_comparison_plots() {
1713    Float_t ymin = 1.e-5, ymax = 0.25;
1714    TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
1715    can->SetLogy(1);
1716 <  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
1717 <  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
1716 >  TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("/DY"));
1717 >  TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("/DY"));
1718    eemc->SetLineColor(kBlue);
1719    mmmc->SetLineColor(kRed);
1720    eemc->SetMinimum(0.1);
# Line 1324 | Line 1779 | void lepton_comparison_plots() {
1779    DrawPrelim();
1780    save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
1781    
1782 <  TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc,  luminosity,allsamples.FindSample("DYJets"));
1783 <  TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc,    int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc,  luminosity,allsamples.FindSample("DYJets"));
1784 <  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("DYJets"));
1782 >  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"));
1783 >  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"));
1784 >  TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,            mc,  luminosity,allsamples.FindSample("/DY"));
1785    dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
1786    dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
1787    dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
# Line 1427 | Line 1882 | void draw_pure_jzb_histo(TCut cut,string
1882    datahisto->Draw("same,e1");
1883    
1884    TLegend *leg;
1885 <  if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
1886 <  else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1887 <  else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1888 <  else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1889 <  else {
1890 <    std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1891 <    exit(-1);
1892 <      }
1885 >  if (!PlottingSetup::RestrictToMassPeak) {
1886 >    if(is_OF(cut)) leg = allsamples.allbglegend("Opposite flavor",datahisto);
1887 >    else leg = allsamples.allbglegend("Same flavor",datahisto);
1888 >  } else {
1889 >    if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
1890 >    else if(!is_OF(cut) &&  is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1891 >    else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1892 >    else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1893 >    else {
1894 >      std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1895 >      exit(-1);
1896 >    }
1897 >  }
1898    leg->Draw();
1899    string write_cut = decipher_cut(cut,"");
1900    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1901    writeline1->SetTextSize(0.035);
1902    writeline1->Draw();
1903 <  save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1903 >  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1904 >  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
1905    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
1906    jzbpad2->cd();
1907    jzbpad2->SetLogy(1);
# Line 1455 | Line 1916 | void draw_pure_jzb_histo(TCut cut,string
1916    writeline1->SetTextSize(0.035);
1917    writeline1->Draw();
1918    DrawPrelim();
1919 <  save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1919 >  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1920 >  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
1921    datahisto->Delete();
1922    mcstack.Delete();
1923   }
# Line 1463 | Line 1925 | void draw_pure_jzb_histo(TCut cut,string
1925   Double_t GausR(Double_t *x, Double_t *par) {
1926    return gRandom->Gaus(x[0],par[0]);
1927   }
1928 +
1929 + void produce_stretched_jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1930 +  TCanvas *dican = new TCanvas("dican","JZB Plots Canvas");
1931 +  float max=jzbHigh ;
1932 +  float min=-120;
1933 +  int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
1934 +  int coarserbins=int(nbins/2.0);
1935 +  int rebinnedbins=int(nbins/4.0);
1936    
1937 +  vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1938 +  for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1939 +  for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1940 +  for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1941 +
1942 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP",dican,binning);
1943 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP",dican,binning);
1944 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_SFZP",dican,binning);
1945 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
1946 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
1947 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
1948 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
1949 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
1950 +  
1951 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
1952 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
1953 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
1954 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
1955 +  
1956 +  delete dican;
1957 + }
1958 +  
1959 +
1960 + void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1961 +  vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
1962 +  
1963 +  if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
1964 +    write_error(__FUNCTION__,"Could not find any diboson samples - aborting diboson plots");
1965 +    return;
1966 +  }
1967 +  
1968 +  float stretchfactor = 100.0;
1969 +  vector<string> labels;
1970 +  
1971 +  
1972 +  dout << "Going to increase the cross section for diboson samples ... " << endl;
1973 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1974 +    float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1975 +    (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
1976 +    dout << "     Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
1977 +    labels.push_back((allsamples.collection)[SamplesToBeModified[i]].samplename);
1978 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=any2string(int(stretchfactor))+" x "+(allsamples.collection)[SamplesToBeModified[i]].samplename;
1979 +    dout << "         (also renamed it to " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " )" << endl;
1980 +  }
1981 +  
1982 +  dout << "Going to produce JZB plots" << endl;
1983 +  produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
1984 +  TCanvas *gloca = new TCanvas("gloca","gloca");
1985 +  
1986 +  dout << "Going to produce prediction plots" << endl;
1987 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
1988 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
1989 +  delete gloca;
1990 +
1991 +  dout << "Going to reset the cross section for diboson samples ... " << endl;
1992 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1993 +    float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1994 +    (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
1995 +    string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
1996 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=labels[i];
1997 +    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;
1998 +    
1999 +  }
2000 +  
2001 + }
2002 +
2003 +
2004 + void draw_normalized_data_vs_data_histo(TCut cut1, TCut cut2, string variable, string legentry1, string legentry2, string savename, TCanvas *can,vector<float> binning) {
2005 +  TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
2006 +  jzbpad->cd();
2007 +  jzbpad->SetLogy(1);
2008 +  string xlabel="JZB [GeV]";
2009 +
2010 +  TH1F *datahisto1 = allsamples.Draw("datahisto1",variable,binning, xlabel, "events",cut1,data,luminosity);
2011 +  datahisto1->SetLineColor(kRed);
2012 +  datahisto1->SetMarkerColor(kRed);
2013 +  TH1F *datahisto2 = allsamples.Draw("datahisto2",variable,binning, xlabel, "events",cut2,data,luminosity);
2014 +  datahisto2->SetLineColor(kBlue);
2015 +  datahisto2->SetMarkerColor(kBlue);
2016 +  
2017 +  datahisto2->SetMarkerSize(DataMarkerSize);
2018 +  datahisto1->DrawNormalized("e1");
2019 +  datahisto2->DrawNormalized("histo,same");
2020 +  datahisto1->DrawNormalized("same,e1");
2021 +  
2022 +  TLegend *leg = make_legend();
2023 +  leg->AddEntry(datahisto1,legentry1.c_str());
2024 +  leg->AddEntry(datahisto2,legentry2.c_str());
2025 +  leg->Draw();
2026 +  
2027 +  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
2028 +  
2029 +  datahisto1->Delete();
2030 +  datahisto2->Delete();
2031 + }
2032 +
2033 +
2034   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
2035    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
2036    float max=jzbHigh ;
# Line 1477 | Line 2044 | void jzb_plots(string mcjzb, string data
2044    for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
2045    for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
2046  
2047 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
2048 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
2049 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
2050 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
2051 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
2052 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
2053 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2054 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
2055 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
2047 >  if ( !PlottingSetup::Approved ) {
2048 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
2049 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
2050 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
2051 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
2052 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
2053 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
2054 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2055 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
2056 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
2057 >    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);
2058 >    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);
2059 >    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);
2060 >
2061 >  }
2062    
2063    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
2064 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
2065 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2066 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
2067 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
2068 <
2069 < //  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
2070 < //  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
1498 < //  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);
2064 >  if ( !PlottingSetup::Approved ) {
2065 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
2066 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
2067 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
2068 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
2069 >  }
2070 >  delete can;
2071   }
2072  
2073  
# Line 1552 | Line 2122 | void compute_MC_yields(string mcjzb,vect
2122    string posneg[] = {"pos","neg"};
2123    TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
2124  
2125 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
2125 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
2126      TCut jzbMC[]  = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
2127      dout << "_________________________________________________________" << endl;
2128      dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
2129 <    for(int isample=0;isample<(allsamples.collection).size();isample++) {
2129 >    for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
2130        if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << "  &  ";
2131        else dout << "Sample & ";
2132        for(int iregion=0;iregion<nRegions;iregion++) {
# Line 1815 | Line 2385 | void draw_ttbar_and_zjets_shape_for_one_
2385  
2386   void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
2387    int all_leptons=-1;
1818  int electrons_only=0;
1819  int mu_only=1;
1820  int twojetswith50gev=1;
2388    int threejetswith30gev=0;
2389   /*  
2390 +  int twojetswith50gev=1;
2391 +  int electrons_only=0;
2392 +  int mu_only=1;
2393 +
2394    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
2395    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
2396    
# Line 1833 | Line 2404 | void draw_ttbar_and_zjets_shape(string m
2404    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
2405   }
2406  
2407 < void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1837 <  //first: colorful plots
2407 > float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
2408    TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
2409    cancorr->SetLogz();
2410    cancorr->SetRightMargin(0.13);
2411 <  flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
2412 <  TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
2411 >  TCut zptforresponsepresentation(Restrmasscut&&SpecialCut&&passtrig);
2412 >
2413 >  if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
2414    TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
2415 <  (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
2415 >  niceresponseplotd->Sumw2();
2416 >  TH2F* emuResponse = (TH2F*)niceresponseplotd->Clone("emuResponse");
2417 >  vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
2418 >  for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
2419 >    if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
2420 >    if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
2421 >    
2422 >    dout << "   Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
2423 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",(zptforresponsepresentation&&cutOSSF)*cutWeight);
2424 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+emuResponse",(zptforresponsepresentation&&cutOSOF)*cutWeight);
2425 >  }
2426 >  niceresponseplotd->Add(emuResponse,-1);
2427 >  
2428    niceresponseplotd->SetStats(0);
2429    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2430    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 1849 | Line 2432 | void find_correction_factors(string &jzb
2432    niceresponseplotd->GetYaxis()->CenterTitle();
2433    niceresponseplotd->Draw("COLZ");
2434    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
2435 +  profd->Rebin(2);
2436    profd->SetMarkerSize(DataMarkerSize);
2437 <  profd->Fit("pol0","","same,e1",30,400);
2437 >  profd->Fit("pol0","","same,e1",100,400);
2438    DrawPrelim();
2439 <  TText* title = write_text(0.5,0.7,"Data");
2439 >  string stitle="Data";
2440 >  if(!Contains(FindKeyword,"Data")) stitle="MC";
2441 >  TText* title = write_text(0.5,0.7,stitle.c_str());
2442    title->SetTextAlign(12);
2443    title->Draw();
2444    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
2445 <  float datacorrection=datapol->GetParameter(0);
2446 <  stringstream dataresstring;
2447 <  dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
2448 <  TText* restitle = write_text(0.5,0.65,dataresstring.str());
2445 >  float correction=datapol->GetParameter(0);
2446 >  stringstream resstring;
2447 >  resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
2448 >  TText* restitle = write_text(0.5,0.65,resstring.str());
2449    restitle->SetTextAlign(12);
2450    restitle->SetTextSize(0.03);
2451    restitle->Draw();
2452 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
2453 <  
2454 <  TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
2455 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
2456 <  niceresponseplotm->SetStats(0);
2457 <  niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2458 <  niceresponseplotm->GetYaxis()->SetTitle("Response");
2459 <  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");
2452 >  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
2453 >  delete cancorr;
2454 >  delete niceresponseplotd;
2455 >  delete profd;
2456 >  return correction;
2457 > }
2458 >
2459 > void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
2460    
2461 +  dout << "Computing response corrections: " << endl;
2462 +  //Step 1 : Get results
2463 +  float datacorrection=find_one_correction_factor("Data",true,"","Data");
2464 +  float mccorrection=find_one_correction_factor("DY",false,"","MC");
2465 +  
2466 +  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
2467 +  float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
2468 +  
2469 +  float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
2470 +  float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
2471 +  
2472 +  cout << "Corrections : " << endl;
2473 +  cout << "   Data : " << datacorrection << endl;
2474 +  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
2475 +  cout << "   MC : " << mccorrection << endl;
2476 +  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
2477    
2478 <  //Step 2: Getting the result
1896 < //  TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
2478 >  //Step 2: Processing the result and making it into something useful :-)
2479    stringstream jzbvardatas;
2480 <  if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
2481 <  if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
2480 >  jzbvardatas << "(";
2481 >  
2482 >  if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
2483 >  if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
2484 >  
2485 >  if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
2486 >  if(dataMMcorrection<1)  jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
2487 >  
2488 >  float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
2489 >  
2490 >  if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
2491 >  if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
2492 >  
2493 >  jzbvardatas << ")";
2494    jzbvardata=jzbvardatas.str();
2495 +  
2496    stringstream jzbvarmcs;
2497 <  if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
2498 <  if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
2497 >  jzbvarmcs << "(";
2498 >  
2499 >  if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
2500 >  if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
2501 >  
2502 >  if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
2503 >  if(mcMMcorrection<1)  jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
2504 >  
2505 >  float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
2506 >  
2507 >  if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
2508 >  if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
2509 >  
2510 >  jzbvarmcs << ")";
2511    jzbvarmc=jzbvarmcs.str();
2512 +
2513    dout << "JZB Z pt correction summary : " << endl;
2514    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
2515    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
2516 +  
2517   }
2518  
2519   void pick_up_events(string cut) {
# Line 1912 | Line 2521 | void pick_up_events(string cut) {
2521    allsamples.PickUpEvents(cut);
2522   }
2523  
2524 < void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
2524 > void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
2525    dout << "Saving configuration template!" << endl;
2526    ofstream configfile;
2527    configfile.open("../DistributedModelCalculations/last_configuration.C");
# Line 1932 | Line 2541 | void save_template(string mcjzb, string
2541    configfile<<"string datajzb=\"datajzb_ERROR\";\n";
2542    configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
2543    configfile<<"vector<float>jzb_cuts;\n";
2544 +  configfile<<"vector<float>jzb_shape_limit_bins;\n";
2545    configfile<<"float MCPeakError=-999;\n";
2546 +  configfile<<"float DataPeakError=-999;\n";
2547    configfile<<"}\n\n";
2548  
2549    configfile<<"void read_config() {\n";
2550    configfile<<"datajzb=\""<<datajzb<<"\";\n";
2551    configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
2552 <  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
2553 <  for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2552 >  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
2553 >  configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
2554 >  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";
2555    configfile<<"\n\n";
2556 <  for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2557 <  for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2558 <  for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2556 >  for(int i=0;i<(int)Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2557 >  for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2558 >  for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2559 >  configfile<<"\n\n";
2560 >  for(int i=0;i<(int)flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2561 >  for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2562 >  for(int i=0;i<(int)flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2563 >  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";
2564    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";
2565    configfile<<"\n\n";
2566    configfile<<"luminosity="<<luminosity<<";\n";
2567 +  configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
2568    
2569    configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
2570    
# Line 1972 | Line 2587 | void draw_all_ttbar_histos(TCanvas *can,
2587    float max=histos[0]->GetMaximum();
2588    if(manualmin>=0) min=manualmin;
2589    else {
2590 <    for(int i=1;i<histos.size();i++) {
2590 >    for(int i=1;i<(int)histos.size();i++) {
2591        float curmin=get_nonzero_minimum(histos[i]);
2592        float curmax=histos[i]->GetMaximum();
2593        if(curmin<min) min=curmin;
# Line 1983 | Line 2598 | void draw_all_ttbar_histos(TCanvas *can,
2598    histos[0]->Draw(drawoption.c_str());
2599    stringstream drawopt;
2600    drawopt << drawoption << ",same";
2601 <  for(int i=1;i<histos.size();i++) {
2601 >  for(int i=1;i<(int)histos.size();i++) {
2602      histos[i]->Draw(drawopt.str().c_str());
2603    }
2604   }
# Line 1992 | Line 2607 | void ttbar_sidebands_comparison(string m
2607    //in the case of the on peak analysis, we compare the 3 control regions to the real value
2608    //in the case of the OFF peak analysis, we compare our control region to the real value
2609    TCut weightbackup=cutWeight;
1995  cutWeight="1.0";
1996  float simulatedlumi = luminosity; //in pb please - adjust to your likings
2610    
2611 +  bool doPURW=false;
2612 +  
2613 +  
2614 +  if(!doPURW) {
2615 +    dout << "Not doing PU reweighting for ttbar closure test" << endl;
2616 +    cutWeight="1.0";
2617 +    // Do it without PU re-weighting
2618 +    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2619 +    stringstream resultsNoPU;
2620 +    stringstream noPUdatajzb;
2621 +    stringstream noPUmcjzb;
2622 +    
2623 +    stringstream mcjzbnoPU;
2624 +    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
2625 +    mcjzb = noPUmcjzb.str();
2626 +  }
2627 +
2628 +      
2629 +  float simulatedlumi = luminosity; //in pb please - adjust to your likings
2630  
2631 <  TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2631 >  TH1F *TZem  = systsamples.Draw("TZem",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2632    TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2633    TH1F *TSem;
2634    TH1F *nTSem;
2635 <  TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2635 >  TH1F *TZeemm  = systsamples.Draw("TZeemm",     mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2636    TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2637    TH1F *TSeemm;
2638    TH1F *nTSeemm;
2639    
2640    if(PlottingSetup::RestrictToMassPeak) {
2641 <    TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2642 <    nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2643 <    TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2641 >    TSem    = systsamples.Draw("TSem",       mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2642 >    nTSem   = systsamples.Draw("nTSem",  "-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2643 >    TSeemm  = systsamples.Draw("TSeemm",     mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2644      nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2645    }
2646  
2647    TCanvas *tcan = new TCanvas("tcan","tcan");
2016  
2648    tcan->SetLogy(1);
2649    
2650    TZeemm->SetLineColor(kBlack);
# Line 2032 | Line 2663 | void ttbar_sidebands_comparison(string m
2663    }
2664    
2665    vector<TH1F*> histos;
2666 +  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2667 +  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2668    histos.push_back(TZem);
2669    histos.push_back(TZeemm);
2670    if(PlottingSetup::RestrictToMassPeak) {
2671 +    TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2672 +    TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2673      histos.push_back(TSem);
2674      histos.push_back(TSeemm);
2675    }
2676 <  draw_all_ttbar_histos(tcan,histos,"histo",0.04);
2676 >  draw_all_ttbar_histos(tcan,histos,"histo",1);
2677    
2678    TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
2679    leg->AddEntry(TZeemm,"SFZP","l");
# Line 2050 | Line 2685 | void ttbar_sidebands_comparison(string m
2685    leg->Draw("same");
2686    DrawMCPrelim(simulatedlumi);
2687    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
2053  
2688    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2689    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2690 <  TH1F *TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2691 <  TH1F *TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2690 >  TH1F *TSeemmcopy;
2691 >  TH1F *TSemcopy;
2692 >  if(PlottingSetup::RestrictToMassPeak) {
2693 >    TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2694 >    TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2695 >  }
2696  
2697    TZem->Divide(TZeemm);
2698    TZem->SetMarkerStyle(21);
# Line 2063 | Line 2701 | void ttbar_sidebands_comparison(string m
2701      TSeemm->Divide(TZeemm);
2702      TSem->SetMarkerStyle(24);
2703      TSeemm->SetMarkerStyle(32);
2704 < }
2704 >  }
2705  
2706    tcan->SetLogy(0);
2707    TZem->GetYaxis()->SetRangeUser(0,2.5);
# Line 2074 | Line 2712 | void ttbar_sidebands_comparison(string m
2712      TSeemm->Draw("same");
2713    }
2714    
2715 <  float linepos=0.25;
2716 <  if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
2715 >  float linepos=emuncertONPEAK;
2716 >  if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
2717 >  
2718    TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
2719    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2720    TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
2721    
2722 +  /*write_warning(__FUNCTION__,"These two lines are to be removed!");
2723 +  TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
2724 +  TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
2725 +  topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
2726 +  bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
2727 +  topalt->Draw("same");bottomalt->Draw("same");*/
2728 +  
2729 +  
2730    top->SetLineColor(kBlue);top->SetLineStyle(2);
2731    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2732    center->SetLineColor(kBlue);
# Line 2103 | Line 2750 | void ttbar_sidebands_comparison(string m
2750    DrawMCPrelim(simulatedlumi);
2751    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
2752    
2753 +  if (0) { // Turn this off: we don't need this
2754  
2755 +    ///-------------- second part: only look at the quantity we actually care about!
2756 +    TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
2757 +    TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
2758 +    rightsfzp->Add(leftsfzp,-1);
2759 +    TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
2760 +    TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
2761 +    rightofzp->Add(leftofzp,-1);
2762 +    TH1F *leftofsb;
2763 +    TH1F *rightofsb;
2764 +    TH1F *leftsfsb;
2765 +    TH1F *rightsfsb;
2766 +    if(PlottingSetup::RestrictToMassPeak) {
2767 +      leftofsb  = (TH1F*)nTSem->Clone("leftofsb");
2768 +      rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
2769 +      rightofsb->Add(leftofsb,-1);
2770 +      leftsfsb  = (TH1F*)nTSeemm->Clone("leftsfsb");
2771 +      rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
2772 +      rightsfsb->Add(leftsfsb,-1);
2773 +    }
2774  
2775 < ///-------------- second part: only look at the quantity we actually care about!
2776 <  TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
2777 <  TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
2778 <  rightsfzp->Add(leftsfzp,-1);
2779 <  TH1F *leftofzp  = (TH1F*)nTZem->Clone("leftofzp");
2780 <  TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
2781 <  rightofzp->Add(leftofzp,-1);
2782 <  TH1F *leftofsb;
2783 <  TH1F *rightofsb;
2784 <  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 <  }
2775 >    tcan->SetLogy(1);
2776 >    rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
2777 >    rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
2778 >    rightsfzp->Draw("histo");
2779 >    rightofzp->Draw("histo,same");
2780 >    if(PlottingSetup::RestrictToMassPeak) {
2781 >      rightofsb->Draw("histo,same");
2782 >      rightsfsb->Draw("histo,same");
2783 >    }
2784 >    DrawMCPrelim(simulatedlumi);
2785  
2786 <  tcan->SetLogy(1);
2787 <  rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
2788 <  rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
2789 <  rightsfzp->Draw("histo");
2790 <  rightofzp->Draw("histo,same");
2791 <  if(PlottingSetup::RestrictToMassPeak) {
2792 <    rightofsb->Draw("histo,same");
2793 <    rightsfsb->Draw("histo,same");
2136 <  }
2137 <  DrawMCPrelim(simulatedlumi);
2786 >    TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2787 >    legA->AddEntry(rightsfzp,"SFZP","l");
2788 >    legA->AddEntry(rightofzp,"OFZP","l");
2789 >    if(PlottingSetup::RestrictToMassPeak) {
2790 >      legA->AddEntry(rightofsb,"SFSB","l");
2791 >      legA->AddEntry(rightsfsb,"OFSB","l");
2792 >    }
2793 >    legA->Draw();
2794  
2795 <  TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2796 <  legA->AddEntry(rightsfzp,"SFZP","l");
2797 <  legA->AddEntry(rightofzp,"OFZP","l");
2798 <  if(PlottingSetup::RestrictToMassPeak) {
2799 <    legA->AddEntry(rightofsb,"SFSB","l");
2800 <    legA->AddEntry(rightsfsb,"OFSB","l");
2801 <  }
2802 <  legA->Draw();
2795 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
2796 >
2797 >    tcan->SetLogy(0);
2798 >    rightofzp->Divide(rightsfzp);
2799 >    rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2800 >    rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
2801 >    rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2802 >    rightofzp->Draw();
2803 >    if(PlottingSetup::RestrictToMassPeak) {
2804 >      rightofsb->Divide(rightsfzp);
2805 >      rightsfsb->Divide(rightsfzp);
2806 >      rightofsb->Draw("same");
2807 >      rightsfsb->Draw("same");
2808 >    }
2809  
2810 <  CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
2810 >    TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
2811 >    TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
2812 >    TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
2813 >  
2814 >    top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2815 >    bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2816 >    center2->SetLineColor(kBlue);
2817 >  
2818 >    top2->Draw("same");
2819 >    center2->Draw("same");
2820 >    bottom2->Draw("same");
2821  
2822 <  tcan->SetLogy(0);
2823 <  rightofzp->Divide(rightsfzp);
2824 <  rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2825 <  rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
2826 <  rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2155 <  rightofzp->Draw();
2156 <  if(PlottingSetup::RestrictToMassPeak) {
2157 <    rightofsb->Divide(rightsfzp);
2158 <    rightsfsb->Divide(rightsfzp);
2159 <    rightofsb->Draw("same");
2160 <    rightsfsb->Draw("same");
2161 <  }
2822 >    rightofzp->SetMarkerStyle(21);
2823 >    if(PlottingSetup::RestrictToMassPeak) {
2824 >      rightofsb->SetMarkerStyle(24);
2825 >      rightsfsb->SetMarkerStyle(32);
2826 >    }
2827  
2828 <  TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
2829 <  TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
2830 <  TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
2828 >    TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2829 >    leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2830 >    if(PlottingSetup::RestrictToMassPeak) {
2831 >      leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2832 >      leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
2833 >    }
2834 >    leg3->AddEntry(bottom,"syst. envelope","l");
2835 >    leg3->SetX1(0.25);leg3->SetX2(0.6);
2836 >    leg3->SetY1(0.65);
2837    
2838 <  top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2168 <  bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2169 <  center2->SetLineColor(kBlue);
2838 >    leg3->Draw("same");
2839    
2840 <  top2->Draw("same");
2841 <  center2->Draw("same");
2173 <  bottom2->Draw("same");
2840 >    DrawMCPrelim(simulatedlumi);
2841 >    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
2842  
2175  rightofzp->SetMarkerStyle(21);
2176  if(PlottingSetup::RestrictToMassPeak) {
2177    rightofsb->SetMarkerStyle(24);
2178    rightsfsb->SetMarkerStyle(32);
2179  }
2180
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");
2843    }
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");
2844  
2845    delete TZem;
2846    delete nTZem;
# Line 2210 | Line 2859 | void ttbar_sidebands_comparison(string m
2859  
2860   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
2861    vector<float> nicer_binning;
2862 <  nicer_binning.push_back(-125);
2862 >  
2863 > /*  nicer_binning.push_back(-400);
2864 >  nicer_binning.push_back(-250);
2865 >  nicer_binning.push_back(-200);
2866 >  nicer_binning.push_back(-150);
2867 >  nicer_binning.push_back(-100);
2868 >  nicer_binning.push_back(-50);
2869 >  nicer_binning.push_back(-20);
2870 >  
2871 >  nicer_binning.push_back(0);
2872 >  nicer_binning.push_back(20);
2873 >  nicer_binning.push_back(50);
2874 >  nicer_binning.push_back(100);
2875 >  nicer_binning.push_back(150);
2876 >  nicer_binning.push_back(200);
2877 >  nicer_binning.push_back(250);
2878 >  nicer_binning.push_back(400);*/
2879 >  
2880    nicer_binning.push_back(-100);
2215  nicer_binning.push_back(-75);
2881    nicer_binning.push_back(-50);
2882    nicer_binning.push_back(-25);
2883    nicer_binning.push_back(0);
# Line 2222 | Line 2887 | void ttbar_sidebands_comparison(string m
2887    nicer_binning.push_back(100);
2888    nicer_binning.push_back(125);
2889    nicer_binning.push_back(150);
2890 <  nicer_binning.push_back(175);
2890 >  //nicer_binning.push_back(175);
2891    nicer_binning.push_back(200);
2892 <  nicer_binning.push_back(230);
2893 <  nicer_binning.push_back(280);
2892 >  nicer_binning.push_back(250);
2893 >  nicer_binning.push_back(300);
2894    nicer_binning.push_back(400);
2895 +  
2896    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
2897   }
2898  
2899  
2900 < void zjets_prediction_comparison() {
2901 <  // Do it without PU re-weighting
2902 <  float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2903 <  stringstream resultsNoPU;
2904 <
2905 <  stringstream mcjzbnoPU;
2906 <  find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
2907 <  if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
2908 <  else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
2900 > void zjets_prediction_comparison(string mcjzbWithPUa) {
2901 >  TCanvas *zcan = new TCanvas("zcan","zcan");  
2902 > //  zcan->SetLogy(1);
2903 >  TCut weightbackup=cutWeight;
2904 >  
2905 >  bool UsePURW=false;
2906 >  
2907 >  
2908 >  string mcjzb;
2909 >  if(UsePURW) {
2910 >    mcjzb=mcjzbWithPUa;
2911 >  } else {
2912 >    // Do it without PU re-weighting
2913 >    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2914 >    stringstream resultsNoPU;
2915 >    stringstream noPUdatajzb;
2916 >    stringstream noPUmcjzb;
2917 >    
2918 >    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
2919 >    dout << "The peak corrected JZB expression for MC without pileup is : " <<  noPUmcjzb.str() << endl;
2920 >    
2921 >    mcjzb = noPUmcjzb.str();
2922 >    
2923 >    cutWeight="1.0";
2924 >  }
2925  
2926 <  string mcjzb = mcjzbnoPU.str();
2927 <  dout << "The peak corrected JZB expression for MC without pileup is : " <<  mcjzb << endl;
2926 >  
2927 >  vector<float> binning;
2928 >  binning.push_back(0);
2929 >  binning.push_back(10);
2930 >  binning.push_back(20);
2931 >  binning.push_back(40);
2932 >  binning.push_back(60);
2933 > //   binning.push_back(50);
2934 > //   binning.push_back(60);
2935 > //   binning.push_back(70);
2936 > //   binning.push_back(80);
2937 > //   binning.push_back(90);
2938 >  binning.push_back(100);
2939  
2247  TCut weightbackup=cutWeight;
2248  cutWeight="1.0";
2249  float sbg_min=0.;
2250  float sbg_max=100.;
2251  int sbg_nbins=5;
2940    float simulatedlumi = luminosity;//in pb please - adjust to your likings
2941    
2942    TCut kPos((mcjzb+">0").c_str());
2943    TCut kNeg((mcjzb+"<0").c_str());
2944    string var( "abs("+mcjzb+")" );
2945 +  
2946 +  TCut notTau("abs(genMID1)!=15");
2947 +  TCut ONLYTau("mll>20");
2948 +  
2949  
2950 <  TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
2951 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2952 <                                  kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("DYJets"));
2261 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2262 <                                  kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("DYJets"));
2950 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2951 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2952 >  
2953    hJZBpos->SetLineColor(kBlack);
2954    hJZBneg->SetLineColor(kRed);
2955    
2956 <  Int_t nbins = 5;
2267 <  Float_t xmax = 100.;
2268 <
2269 <  
2270 <  TCanvas *zcan = new TCanvas("zcan","zcan");  
2271 <  zcan->SetLogy(1);
2272 <
2956 >  hJZBpos->SetMinimum(1.0);
2957    hJZBpos->Draw("e1");
2958    hJZBneg->Draw("same,hist");
2959    hJZBpos->Draw("same,e1"); // So it's on top...
2960    
2961 <  TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
2961 >  TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
2962    leg->AddEntry(hJZBpos,"Observed","pe");
2963    leg->AddEntry(hJZBneg,"Predicted","l");
2964    leg->Draw("same");
2965    DrawMCPrelim(simulatedlumi);
2966 <  CompleteSave(zcan,"Systematics/zjets_prediction");
2966 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
2967    
2968    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
2969    hratio->Divide(hJZBneg);
2970    
2971 +  for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
2972 +    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
2973 +  }
2974 +  
2975    zcan->SetLogy(0);
2976 <  hratio->GetYaxis()->SetRangeUser(0,2.5);
2976 >  hratio->GetYaxis()->SetRangeUser(0,2.0);
2977    hratio->GetYaxis()->SetTitle("Observed/Predicted");
2978    hratio->Draw("e1");
2979    
2980 <  TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
2981 <  TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
2982 <  TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
2980 >  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
2981 >  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2982 >  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
2983    
2984  
2985    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 2302 | Line 2990 | void zjets_prediction_comparison() {
2990    center->Draw("same");
2991    bottom->Draw("same");
2992    
2993 <  TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
2993 >  TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
2994    leg2->AddEntry(hratio,"obs / pred","pe");
2995    leg2->AddEntry(bottom,"syst. envelope","l");
2996    leg2->Draw("same");
2997    DrawMCPrelim(simulatedlumi);
2998 <  CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
2998 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
2999 >  
3000 >  TCut reducedNJets(cutnJets);
3001 >  
3002 >  TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
3003 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
3004 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
3005 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
3006 >
3007 >  TH1F *RcorrJZBSBem;
3008 >  TH1F *LcorrJZBSBem;
3009 >  TH1F *RcorrJZBSBeemm;
3010 >  TH1F *LcorrJZBSBeemm;
3011 >
3012 >  if(PlottingSetup::RestrictToMassPeak) {
3013 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
3014 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
3015 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
3016 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
3017 >  }
3018 >  
3019 >  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
3020 >  if(PlottingSetup::RestrictToMassPeak) {
3021 >    Bpred->Add(RcorrJZBem,1.0/3.);
3022 >    Bpred->Add(LcorrJZBem,-1.0/3.);
3023 >    Bpred->Add(RcorrJZBSBem,1.0/3.);
3024 >    Bpred->Add(LcorrJZBSBem,-1.0/3.);
3025 >    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
3026 >    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
3027 >  } else {
3028 >    Bpred->Add(RcorrJZBem,1.0);
3029 >    Bpred->Add(LcorrJZBem,-1.0);
3030 >  }
3031 >  
3032 >  Bpred->SetLineColor(kRed);
3033 >
3034 >  TAUhJZBpos->SetLineColor(kBlack);
3035 >  Bpred->SetLineColor(kRed);
3036 >  
3037 >  TAUhJZBpos->SetMinimum(1.0);
3038 >  TAUhJZBpos->Draw("e1");
3039 >  Bpred->Draw("same,hist");
3040 >  TAUhJZBpos->Draw("same,e1");
3041 >  
3042 >  TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
3043 >  TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
3044 >  TAUleg->AddEntry(Bpred,"Predicted","l");
3045 >  TAUleg->Draw("same");
3046 >  DrawMCPrelim(simulatedlumi);
3047 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
3048 >  
3049 >  TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
3050 >  TAUhratio->Divide(Bpred);
3051 >  
3052 >  for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
3053 >    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
3054 >  }
3055 >  
3056 >  zcan->SetLogy(0);
3057 >  TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
3058 >  TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
3059 >  TAUhratio->Draw("e1");
3060 >  
3061 >  top->Draw("same");
3062 >  center->Draw("same");
3063 >  bottom->Draw("same");
3064 >  
3065 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
3066 >  TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
3067 >  TAUleg2->AddEntry(bottom,"syst. envelope","l");
3068 >  TAUleg2->Draw("same");
3069 >  DrawMCPrelim(simulatedlumi);
3070 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
3071 >  
3072 >  delete Bpred;
3073 >  delete TAUhJZBpos;
3074 >  delete LcorrJZBeemm;
3075 >  delete RcorrJZBem;
3076 >  delete LcorrJZBem;
3077 >  
3078 >  if(PlottingSetup::RestrictToMassPeak) {
3079 >    delete RcorrJZBSBem;
3080 >    delete LcorrJZBSBem;
3081 >    delete RcorrJZBSBeemm;
3082 >    delete LcorrJZBSBeemm;
3083 >  }
3084 >  
3085    
3086    delete zcan;
3087    cutWeight=weightbackup;
# Line 2333 | Line 3107 | void sideband_assessment(string datajzb,
3107    tout << "\\begin{tabular}{l|cc}" << endl;
3108    tout << "\\hline" << endl;
3109    tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
3110 <  tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
3110 >  tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
3111    tout << "\\end{tabular}" << endl;
3112    tout << "\\end{center}" << endl;
3113    tout << "\\end{table}" << endl;
# Line 2351 | Line 3125 | void make_table(samplecollection &coll,
3125    
3126    TCanvas *cannie = new TCanvas("cannie","cannie");
3127    
3128 <  for(int icut=0;icut<jzb_cuts.size();icut++) {
3128 >  for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
3129      float currcut=jzb_cuts[icut];
3130      int nbins=1;float low=currcut;
3131      vector<int> mysample;
# Line 2410 | Line 3184 | void make_table(samplecollection &coll,
3184    //prediction part
3185    if(is_data) cout << "Data prediction & ";
3186    if(subselection!="none") cout << subselection << " prediction &";
3187 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
3187 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
3188    
3189    cout << endl;
3190    //observation part
3191    if(is_data) cout << "Data observation & ";
3192    if(subselection!="none") cout << subselection << " observation &";
3193 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
3193 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
3194    cout << endl;
3195    cout << "_________________________________________________________________" << endl;
3196    delete cannie;
# Line 2451 | Line 3225 | void JZBSelEff(string mcjzb, TTree* even
3225    int nbins = sizeof(xbins)/sizeof(float)-1;
3226    int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
3227  
3228 <  TH1F* heff  = new TH1F("heff", "JZB eff ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3229 <  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3230 <  TH1F* hreco = new TH1F("hreco","JZB reco ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3228 >  
3229 >  TH1F* heff  = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
3230 >  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
3231 >  TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
3232  
3233    TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
3234    TCut kreco(cutmass);
# Line 2469 | Line 3244 | void JZBSelEff(string mcjzb, TTree* even
3244    TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
3245    can->SetGridx(1);
3246    can->SetGridy(1);
3247 +  can->SetLeftMargin(0.16);
3248 +  can->SetRightMargin(0.05);
3249    TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
3250 +  leg->SetBorderSize(1);
3251 +  leg->SetLineColor(kBlack);
3252 +  leg->SetTextFont(62);
3253  
3254 <  
2475 <
2476 <  for ( int icut=0; icut<jzb_bins.size(); ++icut ) {
3254 >  for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
3255  
3256      ostringstream selection;
3257      selection << mcjzb << ">" << jzb_bins[icut];
# Line 2489 | Line 3267 | void JZBSelEff(string mcjzb, TTree* even
3267      }
3268    
3269      heff->GetXaxis()->SetRangeUser(min, max);
3270 + //    heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
3271 + //    heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
3272 + //    heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
3273 + //    heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
3274      heff->SetMarkerStyle(markers[icut]);
3275      heff->Fit("func","Q+","same");
3276  
# Line 2500 | Line 3282 | void JZBSelEff(string mcjzb, TTree* even
3282  
3283      // Store plot
3284      TH1F* h = (TH1F*)heff->Clone(hname);
3285 +    h->SetNdivisions(505,"X");
3286      if ( icut) h->Draw("same");
3287      else h->Draw();
3288      char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
# Line 2520 | Line 3303 | void JZBSelEff(string mcjzb, TTree* even
3303   // Calls the above function for each signal sample
3304   void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
3305   {  
3306 <  for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
3306 >  for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
3307      dout << "JZB selection efficiency curve: " << std::endl;
3308      JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
3309    }
3310   }
3311 +
3312 + void qcd_plots(string datajzb, string mcjzb, vector<float> bins) {
3313 +  // What this function aims to do:
3314 +  // Illustrate cut flow for QCD (requiring only one lepton, requiring etc.)
3315 +  // Illustrate how little QCD is left over! i.e. make some pointless JZB plot with only QCD to visualize the fact that there's not much really.
3316 +  TCanvas *can = new TCanvas("can","can");
3317 +  TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
3318 +  kinpad->cd();
3319 +  
3320 +  string jzb=mcjzb;
3321 +  
3322 +  float hi=400;
3323 +  bool use_signal=false;
3324 +  bool use_data=false;
3325 +  
3326 +  bool is_data=false;
3327 +  int nbins=50;//100;
3328 +  float low=0;
3329 +  float high=500;
3330 +  int versok=false;
3331 +  if(gROOT->GetVersionInt()>=53000) versok=true;
3332 +
3333 +  TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
3334 +  TH1F *RcorrJZBeemm   = qcdsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3335 +  TH1F *LcorrJZBeemm   = qcdsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3336 +  TH1F *RcorrJZBem     = qcdsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3337 +  TH1F *LcorrJZBem     = qcdsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3338 +  blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
3339 +  blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
3340 +  blankback->GetXaxis()->CenterTitle();
3341 +  blankback->GetYaxis()->CenterTitle();
3342 +  
3343 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3344 +  TH1F *RcorrJZBSBem;
3345 +  TH1F *LcorrJZBSBem;
3346 +  TH1F *RcorrJZBSBeemm;
3347 +  TH1F *LcorrJZBSBeemm;
3348 +  
3349 + //  TH1F *RcorrJZBeemmNoS;
3350 +
3351 +    //these are for the ratio
3352 +  TH1F *JRcorrJZBeemm   = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3353 +  TH1F *JLcorrJZBeemm   = qcdsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3354 +  TH1F *JRcorrJZBem     = qcdsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3355 +  TH1F *JLcorrJZBem     = qcdsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3356 +  
3357 +  TH1F *JRcorrJZBSBem;
3358 +  TH1F *JLcorrJZBSBem;
3359 +  TH1F *JRcorrJZBSBeemm;
3360 +  TH1F *JLcorrJZBSBeemm;
3361 +  
3362 +  if(PlottingSetup::RestrictToMassPeak) {
3363 +    RcorrJZBSBem   = qcdsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3364 +    LcorrJZBSBem   = qcdsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3365 +    RcorrJZBSBeemm = qcdsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3366 +    LcorrJZBSBeemm = qcdsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3367 +
3368 +    //these are for the ratio
3369 +    JRcorrJZBSBem   = qcdsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3370 +    JLcorrJZBSBem   = qcdsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
3371 +    JRcorrJZBSBeemm = qcdsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3372 +    JLcorrJZBSBeemm = qcdsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
3373 +
3374 +  }
3375 +  
3376 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
3377 +  
3378 +  TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
3379 +  TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
3380 +    
3381 +  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
3382 +  TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
3383 +  if(PlottingSetup::RestrictToMassPeak) {
3384 +    Bpred->Add(RcorrJZBem,1.0/3.);
3385 +    Bpred->Add(LcorrJZBem,-1.0/3.);
3386 +    Bpred->Add(RcorrJZBSBem,1.0/3.);
3387 +    Bpred->Add(LcorrJZBSBem,-1.0/3.);
3388 +    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
3389 +    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
3390 +    
3391 +    TTbarpred->Scale(1.0/3);
3392 +    Zjetspred->Add(LcorrJZBem,-1.0/3.);
3393 +    Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
3394 +    TTbarpred->Add(RcorrJZBSBem,1.0/3.);
3395 +    Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
3396 +    TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
3397 +    
3398 +    //these are for the ratio
3399 +    JBpred->Add(JRcorrJZBem,1.0/3.);
3400 +    JBpred->Add(JLcorrJZBem,-1.0/3.);
3401 +    JBpred->Add(JRcorrJZBSBem,1.0/3.);
3402 +    JBpred->Add(JLcorrJZBSBem,-1.0/3.);
3403 +    JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
3404 +    JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
3405 +  } else {
3406 +    Bpred->Add(RcorrJZBem,1.0);
3407 +    Bpred->Add(LcorrJZBem,-1.0);
3408 +    
3409 +    Zjetspred->Add(LcorrJZBem,-1.0);
3410 +    
3411 +    //these are for the ratio
3412 +    JBpred->Add(JRcorrJZBem,1.0);
3413 +    JBpred->Add(JLcorrJZBem,-1.0);
3414 +  }
3415 +    
3416 +  
3417 +  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
3418    
3419 +  TLegend *legBpred = make_legend("",0.6,0.55,false);
3420 +  RcorrJZBeemm->Draw("e1x0,same");
3421 +  Bpred->Draw("hist,same");
3422 +  RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
3423 +  legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
3424 +  legBpred->AddEntry(Bpred,"MC predicted","l");
3425 +  if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
3426 +  if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
3427 +  legBpred->Draw();
3428 +  DrawMCPrelim();
3429 +
3430 +  //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3431 +  string ytitle("ratio");
3432 +  if ( use_data==1 ) ytitle = "data/pred";
3433 +  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
3434 +  
3435 +  TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
3436 +  TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
3437 +  TH1F *osof = qcdsamples.Draw("osof","pfJetGoodNum",1,0,100, "internal code", "events", cutOSOF ,mc, luminosity);
3438 +  TH1F *njossf = qcdsamples.Draw("njossf","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSSF ,mc, luminosity);
3439 +  TH1F *njosof = qcdsamples.Draw("njosof","pfJetGoodNum",1,0,100, "internal code", "events", cutnJets&&cutOSOF ,mc, luminosity);
3440 +  
3441 +  dout << "______________________________________________" << endl;
3442 +  dout << "QCD contribution: " << endl;
3443 +  dout << "Total number of events: " << allevents->Integral() << endl;
3444 +  dout << "OSSF events: " << ossf->Integral() << endl;
3445 +  dout << "OSOF events: " << osof->Integral() << endl;
3446 +  dout << "OSSF events with >=3 jets:" << njossf->Integral() << endl;
3447 +  dout << "OSOF events with >=3 jets:" << njosof->Integral() << endl;
3448 +  dout << "(note that no mass requirement has been imposed)" << endl;
3449 +  
3450 +  dout << "______________________________________________" << endl;
3451 +  dout << "How QCD shows up in the different regions: " << endl;
3452 +  dout << "OSSF: " << endl;
3453 +  if(PlottingSetup::RestrictToMassPeak) {
3454 +    dout << "     Z window: \t" << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
3455 +    dout << "     sideband: \t" << RcorrJZBSBeemm->Integral() << " (JZB>0) , " << LcorrJZBSBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBSBeemm->Integral() + LcorrJZBSBeemm->Integral() << endl;
3456 +  } else {
3457 +    dout << "     " << RcorrJZBeemm->Integral() << " (JZB>0) , " << LcorrJZBeemm->Integral() << " (JZB<0) --> total: " << RcorrJZBeemm->Integral() + LcorrJZBeemm->Integral() << endl;
3458 +  }
3459 +  dout << "OSOF: " << endl;
3460 +  if(PlottingSetup::RestrictToMassPeak) {
3461 +    dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
3462 +    dout << "     sideband: \t" << RcorrJZBSBem->Integral() << " (JZB>0) , " << LcorrJZBSBem->Integral() << " (JZB<0) --> total: " << RcorrJZBSBem->Integral() + LcorrJZBSBem->Integral() << endl;
3463 +  } else {
3464 +    dout << "     Z window: \t" << RcorrJZBem->Integral() << " (JZB>0) , " << LcorrJZBem->Integral() << " (JZB<0) --> total: " << RcorrJZBem->Integral() + LcorrJZBem->Integral() << endl;
3465 +  }
3466 +  dout << "Therefore: " << endl;
3467 +  if(PlottingSetup::RestrictToMassPeak) {
3468 +    dout << "    Prediction increases by : " << LcorrJZBeemm->Integral() << " + (1.0/3)*(" << RcorrJZBSBeemm->Integral() <<"-"<< LcorrJZBSBeemm->Integral() << ") (SFSB) ";
3469 +    dout << " + (1.0/3)*(" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
3470 +    dout << " + (1.0/3)*(" << RcorrJZBSBem->Integral() <<"-"<< LcorrJZBSBem->Integral() << ") (OFSB) ";
3471 +    dout << " = " << LcorrJZBeemm->Integral() + (1.0/3)*(RcorrJZBSBeemm->Integral() - LcorrJZBSBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() + RcorrJZBSBem->Integral() - LcorrJZBSBem->Integral()) << endl;
3472 +  } else {
3473 +    dout << "    Prediction increases by : " << LcorrJZBeemm->Integral();
3474 +    dout << " + (" << RcorrJZBem->Integral() <<"-"<< LcorrJZBem->Integral() << ") (OFZP) ";
3475 +    dout << " = " << LcorrJZBeemm->Integral() + RcorrJZBem->Integral() - LcorrJZBem->Integral() << endl;
3476 +  }
3477 +  dout << "    Observation increases by : " << RcorrJZBeemm->Integral() << endl;
3478 +  
3479 +  dout << endl;
3480 +  for(int i=0;i<(int)bins.size();i++) {
3481 +    dout << " JZB > " << bins[i] << " : " << endl;
3482 +    dout << "    Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
3483 +    if(PlottingSetup::RestrictToMassPeak) {
3484 +        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;
3485 +    } else {
3486 +        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;
3487 +    }
3488 +  }
3489 +      
3490 +  delete can;
3491 +  delete allevents;
3492 +  if(ossf) delete ossf;
3493 +  if(RcorrJZBem) delete RcorrJZBem;
3494 +  if(LcorrJZBem) delete LcorrJZBem;
3495 +  if(RcorrJZBeemm) delete RcorrJZBeemm;
3496 +  if(LcorrJZBeemm) delete LcorrJZBeemm;
3497 +  if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBem) delete RcorrJZBSBem;
3498 +  if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBem) delete LcorrJZBSBem;
3499 +  if(PlottingSetup::RestrictToMassPeak&&RcorrJZBSBeemm) delete RcorrJZBSBeemm;
3500 +  if(PlottingSetup::RestrictToMassPeak&&LcorrJZBSBeemm) delete LcorrJZBSBeemm;
3501 + }
3502 +
3503 + void check_ptsanity() {
3504 +  TCanvas *ptsancan = new TCanvas("ptsancan","ptsancan",600,1800);
3505 +  TH1F *individualpt1histos[allsamples.collection.size()];
3506 +  TH1F *individualpt2histos[allsamples.collection.size()];
3507 +  TH1F *fpt1 = new TH1F("fpt1","fpt1",50,0,50);
3508 +  fpt1->GetYaxis()->SetRangeUser(0,1);
3509 +  fpt1->GetXaxis()->SetTitle("p_{T,1}");
3510 +  fpt1->GetXaxis()->CenterTitle();
3511 +
3512 +  TH1F *fpt2 = new TH1F("fpt2","fpt2",50,0,50);
3513 +  fpt2->GetXaxis()->SetTitle("p_{T,2}");
3514 +  fpt2->GetXaxis()->CenterTitle();
3515 +  
3516 +  ptsancan->Divide(1,3);
3517 +  ptsancan->cd(1);
3518 +  float maxpt1entry=0;
3519 +  float maxpt2entry=0;
3520 +  
3521 +  TLegend *leg = make_legend();
3522 +  leg->SetX1(0.0);
3523 +  leg->SetY1(0.0);
3524 +  leg->SetX2(1.0);
3525 +  leg->SetY2(1.0);
3526 +  
3527 +  
3528 +  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3529 +    string nowname=(allsamples.collection)[isample].filename;
3530 +    cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
3531 +    individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3532 +    individualpt2histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt2",50,0,50, "p_{T,2}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
3533 +    individualpt1histos[isample]->SetLineColor(isample+1);
3534 +    individualpt2histos[isample]->SetLineColor(isample+1);
3535 +    float currmaxpt1entry=individualpt1histos[isample]->GetMaximum()/individualpt1histos[isample]->Integral();
3536 +    float currmaxpt2entry=individualpt2histos[isample]->GetMaximum()/individualpt2histos[isample]->Integral();
3537 +    cout << "      pt 1 histo contains; " << individualpt1histos[isample]->Integral() << endl;
3538 +    cout << "      pt 2 histo contains; " << individualpt2histos[isample]->Integral() << endl;
3539 +    if(currmaxpt1entry>maxpt1entry)maxpt1entry=currmaxpt1entry;
3540 +    if(currmaxpt2entry>maxpt2entry)maxpt2entry=currmaxpt2entry;
3541 +    leg->AddEntry(individualpt2histos[isample],((allsamples.collection)[isample].filename).c_str(),"f");
3542 +  }
3543 +
3544 +  fpt1->GetYaxis()->SetRangeUser(0,maxpt1entry);
3545 +  fpt2->GetYaxis()->SetRangeUser(0,maxpt2entry);
3546 +
3547 +  ptsancan->cd(1);
3548 +  fpt1->Draw();
3549 +  ptsancan->cd(2);
3550 +  fpt2->Draw();
3551 +
3552 +  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3553 +    ptsancan->cd(1);
3554 +    individualpt1histos[isample]->DrawNormalized("same,histo");
3555 +    ptsancan->cd(2);
3556 +    individualpt2histos[isample]->DrawNormalized("same,histo");
3557 +  }
3558 +  ptsancan->cd(3);
3559 +  leg->Draw();
3560 +  CompleteSave(ptsancan,"PtSanityCheck");
3561 +  
3562 +  delete ptsancan;
3563 + }
3564 +
3565 + void do_mlls_plot(string mcjzb) {
3566 +  cout << "At this point we'd plot the mll distribution" << endl;
3567 +  TCanvas *sigcan = new TCanvas("sigcan","sigcan");
3568 +  for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
3569 +    if(!(signalsamples.collection)[isig].events) continue;
3570 +    string nowname=(signalsamples.collection)[isig].filename;
3571 +    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
3572 + //    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
3573 +    mll->SetLineColor(TColor::GetColor("#04B404"));
3574 +    stringstream poscutS;
3575 +    poscutS << "((" << mcjzb <<")>50)";
3576 +    TCut poscut(poscutS.str().c_str());
3577 +    TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
3578 +    mllP->SetLineColor(TColor::GetColor("#0040FF"));
3579 +    mll->Draw("histo");
3580 +    mllP->Draw("histo,same");
3581 +    TLegend *leg = make_legend();
3582 +    leg->SetY1(0.8);
3583 +    leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
3584 +    leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
3585 +    leg->Draw();
3586 +    TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
3587 +    TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
3588 +    lin->Draw("same");
3589 +    lin2->Draw("same");
3590 +    
3591 +    CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
3592 +    delete mll;
3593 +    delete mllP;
3594 +  }
3595 + }
3596 +
3597 + void met_vs_jzb_plots() {
3598 +  
3599 +  TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
3600 +  canmetjzb->SetRightMargin(0.16);
3601 +  
3602 +  vector<string> findme;
3603 +  findme.push_back("DY");
3604 +  findme.push_back("TTJets");
3605 +  findme.push_back("LM");
3606 +  
3607 +  for(int ifind=0;ifind<(int)findme.size();ifind++) {
3608 +    vector<int> selsamples = allsamples.FindSample(findme[ifind]);
3609 +    TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
3610 +    for(int isel=0;isel<(int)selsamples.size();isel++) {
3611 +      cout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
3612 +      allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF);
3613 +    }
3614 +    metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
3615 +    metvsjzb->SetStats(0);
3616 +    metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
3617 +    metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
3618 +    metvsjzb->GetXaxis()->CenterTitle();
3619 +    metvsjzb->GetYaxis()->CenterTitle();
3620 +    metvsjzb->Draw("COLZ");
3621 +    TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
3622 +    title->SetTextAlign(12);
3623 +    title->Draw();
3624 +    CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
3625 +  }
3626 + }
3627 +    
3628  
3629   void test() {
3630    
3631    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
3632    testcanv->cd();
3633 <  switch_overunderflow(true);
3633 > //  switch_overunderflow(true);
3634    TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
3635    switch_overunderflow(false);
3636    ptdistr->Draw();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines