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.4 by buchmann, Fri Mar 2 08:37:03 2012 UTC vs.
Revision 1.36 by buchmann, Thu Jul 12 12:55:02 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 &DataSigma, 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,method,saveas);
56 >    DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method,saveas);
57 >    delete rawttbarjzbeemmMC;
58    }
59    else {
60      TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
# Line 54 | 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,method,saveas);
66 >    DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method,saveas);
67 >    delete reducedMC;
68 >    delete reducedData;
69    }
70  
71    // Revert to original PU reweighting
# Line 64 | 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 << " +/- ?? (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;
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, dataSigma;
102 +  
103 +  dout << "Finding global peak : " << endl;
104 +  find_one_peak_combination(TCut(""),mcpeak,mcpeakerr, datapeak,datapeakerr,mcSigma, dataSigma,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, dataSigma,result,doPUreweighting,"_ele");
109 +    dout << "Finding peak for muons : " << endl;
110 +    find_one_peak_combination(TCut("id1==1"),mcmmpeak,mcmmpeakerr, datammpeak,datammpeakerr,mcSigma, dataSigma,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) {
155 +  float min=70.0;
156 +  float max=115.0;
157 +  if(!PlottingSetup::RestrictToMassPeak) {
158 +    min=20;
159 +    max=200;
160 +  }
161 +  int nbins=int((max-min)/5);
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 +  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
199 +  if(PlottingSetup::RestrictToMassPeak) {
200 +    Bpred->Add(RcorrJZBem,1.0/3.);
201 +    Bpred->Add(LcorrJZBem,-1.0/3.);
202 +    Bpred->Add(RcorrJZBSBem,1.0/3.);
203 +    Bpred->Add(LcorrJZBSBem,-1.0/3.);
204 +    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
205 +    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
206 +  } else {
207 +    Bpred->Add(RcorrJZBem,1.0);
208 +    Bpred->Add(LcorrJZBem,-1.0);
209 +  }
210 +  
211 +  Bpred->SetLineColor(kRed);
212 +  
213 +  RcorrJZBeemm->Draw();
214 +  mcRcorrJZBeemm.Draw("same");
215 +  Bpred->Draw("histo,same");
216 +  RcorrJZBeemm->Draw("same");
217 +  
218 +  TLegend *leg = allsamples.allbglegend();
219 +  leg->SetX1(0.58);
220 +  leg->AddEntry(RcorrJZBeemm,"observed (data)","l");
221 +  leg->AddEntry(Bpred,"predicted (data)","l");
222 +  leg->Draw("same");
223 +  
224 +  stringstream saveas;
225 +  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold;
226 +  CompleteSave(ckin,saveas.str());
227 +  
228 +  
229 +  
230 +  RcorrJZBeemm->Draw();
231 +  Bpred->Draw("histo,same");
232 +  RcorrJZBeemm->Draw("same");
233 +  
234 +  TLegend *leg2 = make_legend();
235 +  leg2->SetX1(0.58);
236 +  leg2->AddEntry(RcorrJZBeemm,"observed (data)","l");
237 +  leg2->AddEntry(Bpred,"predicted (data)","l");
238 +  leg2->Draw("same");
239 +  
240 +  saveas.str("");
241 +  saveas << "kin/Mll_After_Cut/Cut_At" << jzbthreshold << "_nomc";
242 +  CompleteSave(ckin,saveas.str());
243 +  
244 +  
245 +
246 +  delete RcorrJZBeemm;
247 +  delete LcorrJZBeemm;
248 +  delete RcorrJZBem;
249 +  delete LcorrJZBem;
250 +  if(PlottingSetup::RestrictToMassPeak) {
251 +    delete RcorrJZBSBeemm;
252 +    delete LcorrJZBSBeemm;
253 +    delete RcorrJZBSBem;
254 +    delete LcorrJZBSBem;
255 +  }
256 +  delete Bpred;
257 +  delete ckin;
258 + }
259 +
260   void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
261    
262    TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
# Line 105 | Line 291 | void make_special_mll_plot(int nbins, fl
291    TIter next(bgleg->GetListOfPrimitives());
292    TObject* obj;
293    // Copy the nice bkgd legend skipping the "data"
294 <  while ( obj = next() )
294 >  while ( (obj = next()) )
295      if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
296        kinleg->GetListOfPrimitives()->Add(obj);
297  
# Line 124 | Line 310 | void draw_ratio_plot(TH1* hdata, THStack
310    TIter next(hmc.GetHists());
311    TObject* obj;
312    TH1* hratio = NULL;
313 <  while ( obj = next() ) {
313 >  while ( (obj = next()) ) {
314      if ( !hratio ) {
315        hratio = (TH1*)obj->Clone();
316        hratio->SetName("hratio");
# Line 185 | Line 371 | void make_kin_plot(string variable, stri
371    TCut cut;
372    cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
373    if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
374 +  if(filename=="nJets_osof") cut=cutmass&&cutOSOF&&ibasiccut;
375    if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
376    if(filename=="mll") {
377          cut=cutOSSF&&cutnJets&&ibasiccut;
# Line 196 | Line 383 | void make_kin_plot(string variable, stri
383          draw_separation_lines=true;
384    }
385    if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
386 <  if(filename=="mll_aboveJZB100") cut=cutOSSF&&cutnJets&&ibasiccut;
386 >  if(Contains(filename,"aboveJZB")) cut=cutOSSF&&cutnJets&&ibasiccut;
387 >  if(Contains(filename,"mll_ee_above")) cut=cut&&"id1==0";
388 >  if(Contains(filename,"mll_mm_above")) cut=cut&&"id1==1";
389 >  if(Contains(filename,"mll_osof_aboveJZB")) cut=cutOSOF&&cutnJets&&ibasiccut;
390    if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
391    if(filename=="mll_inclusive_osof") cut=cutOSOF;
392    if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
# Line 211 | Line 401 | void make_kin_plot(string variable, stri
401    THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
402    if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
403    if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
404 <  if(filename=="mll_inclusive") datahisto->SetMinimum(1);
404 >  if(filename=="mll_inclusive"||filename=="mll_inclusive_mm"||filename=="mll_inclusive_ee") datahisto->SetMinimum(1);
405    if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
406    if(filename=="mll_osof") datahisto->SetMinimum(9);
217
407    datahisto->SetMaximum(5.3*datahisto->GetMaximum());
408    datahisto->Draw("e1");
409    ckin->Update();
# Line 294 | Line 483 | void make_kin_plot(string variable, stri
483    delete ckin;
484   }
485  
297
486   void make_JES_plot() {
487  
488    int nbins=10;
# Line 309 | Line 497 | void make_JES_plot() {
497    TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
498    datahisto->SetMarkerSize(DataMarkerSize);
499    THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
500 <  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
501 <  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
500 >  TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNump1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
501 >  TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNumn1sigma",nbins,min,max, xlabel, "events",cut,mc,luminosity);
502  
503    datahisto->SetMinimum(1);
504    datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
# Line 346 | Line 534 | void do_kinematic_plots(string mcjzb, st
534    bool dolog=true;
535    bool nolog=false;
536    if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
537 <  float mll_low=40;
537 >  float mll_low=50;
538    float mll_hi=160;
539    if(!PlottingSetup::RestrictToMassPeak) {
540 <        mll_low=30;
541 <        mll_hi=180;
540 >        mll_low=20;
541 >        mll_hi=210;
542    }
543 +  
544 +  make_kin_plot("met[4]","",40,0,200,dolog,"MET [GeV]","met",doPF,true);
545    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll",doPF,true);
546    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
547    make_kin_plot("mll","",(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
# Line 359 | Line 549 | void do_kinematic_plots(string mcjzb, st
549    make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
550    make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
551    make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
552 <  make_kin_plot("mll","",(int)((mll_hi-mll_low)),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
552 >  make_kin_plot("mll","",(int)((mll_hi-mll_low))/2,mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
553    make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
554 <  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
555 <  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
554 >  make_kin_plot("numVtx","",(int)(30.5-(-0.5)),-0.5,30.5,nolog,"N(Vtx)","numVtx",doPF);
555 > //  make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
556 > //  make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
557    make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
558    make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
559    make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
560    make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
561    make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
562 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
563 <  make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
562 >  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets",doPF);
563 >  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_osof",doPF);
564 >  make_kin_plot("pfJetGoodNum40","",9,-0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
565    if(!doPF) make_special_mll_plot((int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]");
566    stringstream jzbcut;
567    jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
568 <  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
568 >  make_kin_plot("mll",jzbcut.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
569 >  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);
570 >  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);
571 >  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);
572 >  stringstream jzbcut2;
573 >  jzbcut2 << "((is_data&&("<<datajzb<<")>150)||(!is_data&&("<<mcjzb<<")>150))";
574 >  make_kin_plot("mll",jzbcut2.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB150",doPF,true);
575 >  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);
576 >  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);
577 >  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);
578 >  stringstream jzbcut3;
579 >  jzbcut3 << "((is_data&&("<<datajzb<<")>50)||(!is_data&&("<<mcjzb<<")>50))";
580 >  make_kin_plot("mll",jzbcut3.str(),(int)((mll_hi-mll_low)/5),mll_low,mll_hi,nolog,"m_{ll} [GeV]","mll_aboveJZB50",doPF,true);  
581 >  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);
582 >  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);  
583 >  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);  
584 >  
585 >  
586 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,0);
587 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,50);
588 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,100);
589 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,150);
590 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,200);
591 >  make_special_obs_pred_mll_plot(datajzb,mcjzb,250);
592 >  
593 >  make_JES_plot();
594   }
595  
596   void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
# Line 407 | Line 624 | void make_comp_plot( string var, string
624        TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
625        ccomp->SetLogy(log);
626        TH1F *datahisto = allsamples.Draw("datahisto",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
627 <      TH1F *lm4histo = signalsamples.Draw("lm4histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
627 >      TH1F *lm4histo = signalsamples.Draw("lm4histo",   var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM"));
628        THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb],  mc,  luminosity);
629        datahisto->SetMarkerSize(DataMarkerSize);
630        if (ymax>ymin) datahisto->SetMaximum(ymax);
# Line 441 | Line 658 | void region_comparison_plots(string mcjz
658    dout << "Creating comparison plots for signal and control regions" << endl;
659    // Compare a few quantities in the signal region and all 7 control regions
660  
661 <  switch_overunderflow(true);  // switching overflow/underflow bins on
661 > //  switch_overunderflow(true);  // switching overflow/underflow bins on
662      
663    
664      flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
665 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
665 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
666      float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
667      float mll_low=50;float mll_high=170;
668      if(!PlottingSetup::RestrictToMassPeak) {
# Line 483 | Line 700 | void signal_bg_comparison()
700    float simulatedlumi=luminosity;//in pb please - adjust to your likings
701    
702    TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("/DY"));
703 <  TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
703 >  TH1F *JZBplotLM4;
704 >  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"));
705 >  else JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM3"));
706    TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
707    
708    JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
# Line 507 | Line 726 | void signal_bg_comparison()
726    TLegend *signal_bg_comparison_leg2 =  make_legend("",0.55,0.75,false);
727    signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
728    signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
729 <  signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
729 >  if(PlottingSetup::RestrictToMassPeak) signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
730 >  else signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM3","f");
731    signal_bg_comparison_leg2->Draw();
732    DrawMCPrelim(simulatedlumi);
733    CompleteSave(can,"jzb_bg_vs_signal_distribution");
# Line 749 | Line 969 | if you want to start from scratch (witho
969    return return_functions;
970   }
971  
972 < void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false )
972 > void do_prediction_plot(string jzb, TCanvas *globalcanvas, float high, int use_data, bool overlay_signal = false,string subdir="" )
973   {
974 + //  switch_overunderflow(true);
975    bool is_data=false;
976    bool use_signal=false;
977    if(use_data==1) is_data=true;
# Line 759 | Line 980 | void do_prediction_plot(string jzb, TCan
980    if(is_data) nbins=50;
981    float low=0;
982    float hi=500;
983 +  
984    TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
985    TH1F *RcorrJZBeemm   = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
986    TH1F *LcorrJZBeemm   = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
987    TH1F *RcorrJZBem     = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
988    TH1F *LcorrJZBem     = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
989 +
990    blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
991    blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
992    blankback->GetXaxis()->CenterTitle();
# Line 778 | Line 1001 | void do_prediction_plot(string jzb, TCan
1001    TH1F *RcorrJZBeemmNoS;
1002  
1003      //these are for the ratio
1004 +  
1005    TH1F *JRcorrJZBeemm   = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1006    TH1F *JLcorrJZBeemm   = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1007    TH1F *JRcorrJZBem     = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
# Line 796 | Line 1020 | void do_prediction_plot(string jzb, TCan
1020      LcorrJZBSBem   = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1021      RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1022      LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1023 <
1023 >    
1024      //these are for the ratio
1025      JRcorrJZBSBem   = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1026      JLcorrJZBSBem   = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
1027      JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
1028      JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
805
1029    }
1030    
1031    TH1F *lm4RcorrJZBeemm;
1032 <  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"));
1032 >  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"));
1033    
1034    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
1035    
# Line 815 | Line 1038 | void do_prediction_plot(string jzb, TCan
1038      
1039    TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1040    TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
1041 +    
1042 +  TH1F *BpredSys = new TH1F("Bpredsys","Bpredsys",PlottingSetup::global_ratio_binning.size()-1,&PlottingSetup::global_ratio_binning[0]);
1043 +  ClearHisto(BpredSys);
1044 +    
1045    if(PlottingSetup::RestrictToMassPeak) {
1046      Bpred->Add(RcorrJZBem,1.0/3.);
1047      Bpred->Add(LcorrJZBem,-1.0/3.);
# Line 837 | Line 1064 | void do_prediction_plot(string jzb, TCan
1064      JBpred->Add(JLcorrJZBSBem,-1.0/3.);
1065      JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
1066      JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
1067 +      
1068 +    //Systematics:
1069 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertONPEAK*zjetsestimateuncertONPEAK);
1070 +    AddSquared(BpredSys,JRcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
1071 +    AddSquared(BpredSys,JLcorrJZBem,emuncertONPEAK*emuncertONPEAK*(1.0/9));
1072 +    AddSquared(BpredSys,JRcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
1073 +    AddSquared(BpredSys,JLcorrJZBSBem,emsidebanduncertONPEAK*emsidebanduncertONPEAK*(1.0/9));
1074 +    AddSquared(BpredSys,JRcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
1075 +    AddSquared(BpredSys,JLcorrJZBSBeemm,eemmsidebanduncertONPEAK*eemmsidebanduncertONPEAK*(1.0/9));
1076    } else {
1077      Bpred->Add(RcorrJZBem,1.0);
1078      Bpred->Add(LcorrJZBem,-1.0);
# Line 846 | Line 1082 | void do_prediction_plot(string jzb, TCan
1082      //these are for the ratio
1083      JBpred->Add(JRcorrJZBem,1.0);
1084      JBpred->Add(JLcorrJZBem,-1.0);
1085 +      
1086 +    //Systematics
1087 +    AddSquared(BpredSys,JLcorrJZBeemm,zjetsestimateuncertOFFPEAK*zjetsestimateuncertOFFPEAK);
1088 +    AddSquared(BpredSys,JRcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
1089 +    AddSquared(BpredSys,JLcorrJZBem,emuncertOFFPEAK*emuncertOFFPEAK);
1090 +
1091    }
1092      
1093 <  
1093 >  SQRT(BpredSys);
1094 >  BpredSys->Divide(JBpred);
1095 >
1096    
1097    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
1098    TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
# Line 893 | Line 1137 | void do_prediction_plot(string jzb, TCan
1137    blankback->Draw();
1138    if(use_data==1)
1139    {
1140 +    //Bpred->SetLineWidth(3); //paper style.overruled.
1141 +    //lm4RcorrJZBeemm->SetLineWidth(3); //paper style.overruled.
1142      analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
1143      kinpad->cd();//necessary because the extended fit function creates its own canvas
1144      RcorrJZBeemm->Draw("e1x0,same");
1145  
1146      Bpred->Draw("hist,same");
1147 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1147 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1148      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1149 +    lm4RcorrJZBeemm->Draw("hist,same");
1150      legBpred->AddEntry(RcorrJZBeemm,"observed","p");
1151      legBpred->AddEntry(Bpred,"predicted","l");
1152 <    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
1153 <    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
1154 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1152 > //    legBpred->AddEntry(analytical_function[1],"predicted fit","l");
1153 > //    legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
1154 >    legBpred->AddEntry(lm4RcorrJZBeemm,(allsamples.collection[allsamples.FindSample("LM")[0]].samplename).c_str(),"l");
1155      legBpred->Draw();
1156      DrawPrelim();
1157  
1158      //this plot shows what the prediction is composed of
1159 <    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
1160 <    specialcanv->SetLogy(1);
1161 <    Zjetspred->SetFillColor(kYellow);
1162 <    Zjetspred->SetLineColor(kYellow);
1163 <    TTbarpred->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1164 <    TTbarpred->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1159 >    TPad *predcomppad = new TPad("predcomppad","predcomppad",0,0,1,1);
1160 >    float CurrentBpredLineWidth=Bpred->GetLineWidth();
1161 >    Bpred->SetLineWidth(2);
1162 >    predcomppad->cd();
1163 >    predcomppad->SetLogy(1);
1164 >    
1165 >    TH1F *jzbnegative = (TH1F*)LcorrJZBeemm->Clone("jzbnegative");
1166 >    TH1F *sidebandsemu = (TH1F*)Bpred->Clone("sidebandsemu");
1167 >    sidebandsemu->Add(jzbnegative,-1);
1168 >    
1169 >    jzbnegative->SetFillColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1170 >    jzbnegative->SetLineColor(allsamples.GetColor((allsamples.FindSample("DY"))[0]));
1171 >    sidebandsemu->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1172 >    sidebandsemu->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
1173 >    
1174      THStack predcomposition("predcomposition","prediction composition");
1175 <    predcomposition.Add(TTbarpred);
1176 <    predcomposition.Add(Zjetspred);
1175 >    predcomposition.Add(sidebandsemu);
1176 >    predcomposition.Add(jzbnegative);
1177      blankback->Draw();
1178      RcorrJZBeemm->Draw("e1x0,same");
1179      predcomposition.Draw("histo,same");//
1180      Bpred->Draw("hist,same");
1181 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1181 > //    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1182      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1183 <    legBpred->Draw();
1183 > //    lm4RcorrJZBeemm->SetLineColor(kOrange+1);
1184 >    lm4RcorrJZBeemm->SetLineWidth(2);
1185 >    //lm4RcorrJZBeemm->SetLineWidth(2); // paper style. overruled.
1186 >    lm4RcorrJZBeemm->Draw("histo,same");
1187      DrawPrelim();
1188 <    TLegend *specialleg = new TLegend(0.6,0.4,0.89,0.55);
1189 <    specialleg->SetFillColor(kWhite);specialleg->SetLineColor(kWhite);
1190 <    specialleg->AddEntry(Zjetspred,"Z+Jets prediction","f");
1191 <    specialleg->AddEntry(TTbarpred,"t#bar{t} prediction","f");
1192 <    specialleg->Draw("same");
1193 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionComposition");
1194 <
1195 <    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
1188 >    TLegend *speciallegBpred = make_legend("",0.45,0.55);
1189 >    //TLegend *speciallegBpred = make_legend("",0.35,0.55); // paper style. overruled.
1190 >    speciallegBpred->AddEntry(RcorrJZBeemm,"Data","pl");
1191 >    speciallegBpred->AddEntry(Bpred,"Total background","l");
1192 >    speciallegBpred->AddEntry(jzbnegative,"JZB<0 (data)","f");
1193 >    if(PlottingSetup::RestrictToMassPeak) speciallegBpred->AddEntry(sidebandsemu,"Sidebands/e#mu (data)","f");
1194 >    else speciallegBpred->AddEntry(sidebandsemu,"e#mu (data)","f");
1195 > //    speciallegBpred->AddEntry(lm4RcorrJZBeemmC,"LM4","l");
1196 >    speciallegBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1197 >    speciallegBpred->Draw();
1198 >    save_with_ratio(JRcorrJZBeemm,JBpred,predcomppad,subdir+"Bpred_Data_____PredictionComposition",true,true,"data/pred",BpredSys);
1199 >    
1200 >    TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
1201 >    specialcanv->SetLogy(1);
1202 > //    THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
1203      blankback->Draw();
1204 <    kostack.Draw("same");
1204 > //    kostack.Draw("same");
1205 >    predcomposition.Draw();
1206      Bpred->Draw("hist,same");
1207 <    analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1207 >    //analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
1208      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1209      legBpred->Draw();
1210      DrawPrelim();
1211 <    CompleteSave(specialcanv,"Bpred_Data_____PredictionCompositioninMC");
1211 >    CompleteSave(specialcanv,subdir+"Bpred_Data_____PredictionCompositioninMC");
1212 >    Bpred->SetLineWidth((int)CurrentBpredLineWidth);
1213 >    
1214      
1215 <    delete specialcanv;
1216 <    delete specialleg;
1215 >    //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;
1216 >    
1217 >    delete speciallegBpred;
1218      delete Zjetspred;
1219      delete TTbarpred;
1220      
# Line 952 | Line 1222 | void do_prediction_plot(string jzb, TCan
1222    }
1223    if(use_data==0) {
1224      RcorrJZBeemm->Draw("e1x0,same");
1225 +    //Bpred->SetLineWidth(3); // paper style. overruled.
1226      Bpred->Draw("hist,same");
1227      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1228 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
1229 <    legBpred->AddEntry(Bpred,"MC predicted","l");
1228 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1229 >    legBpred->AddEntry(Bpred,"MC predicted","l");    
1230      if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
1231      if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
1232      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
# Line 966 | Line 1237 | void do_prediction_plot(string jzb, TCan
1237    }
1238    if(use_data==2) {
1239      RcorrJZBeemm->Draw("e1x0,same");
1240 +    //Bpred->SetLineWidth(3); // paper style. overruled.
1241      Bpred->Draw("hist,same");
1242      RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1243 <    legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
1243 >    legBpred->AddEntry(RcorrJZBeemm,"MC true","p");
1244      legBpred->AddEntry(Bpred,"MC predicted","l");
1245 <    legBpred2->AddEntry(RcorrJZBeemm,"MC observed","p");
1245 >    legBpred2->AddEntry(RcorrJZBeemm,"MC true","p");
1246      legBpred2->AddEntry(Bpred,"MC predicted","l");
1247      {
1248        if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
# Line 981 | Line 1253 | void do_prediction_plot(string jzb, TCan
1253   //      CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
1254      }
1255      {
1256 +      //lm4RcorrJZBeemm->SetLineWidth(3); //paper style. overruled.
1257 +      //RcorrJZBeemmNoS->SetLineWidth(3); //paper style. overruled.
1258 +      //lm4RcorrJZBeemm->SetLineStyle(2); //paper style. overruled.
1259 +      //RcorrJZBeemmNoS->SetLineStyle(3); //paper style. overruled.
1260 +      //lm4RcorrJZBeemm->SetLineColor(kOrange+1); //paper style. overruled.
1261 +      
1262        RcorrJZBeemmNoS->SetLineStyle(2);
1263        legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
1264        legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
# Line 999 | Line 1277 | void do_prediction_plot(string jzb, TCan
1277    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
1278    string ytitle("ratio");
1279    if ( use_data==1 ) ytitle = "data/pred";
1280 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
1280 >  //save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
1281 >  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,subdir+Bpredsaveas,true,true,ytitle,BpredSys);//not extending the y range anymore up to 4
1282  
1283    
1284    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1285 <  /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1286 <  if(!PlottingSetup::RestrictToMassPeak) return;
1287 <  TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1288 <  Bpredem->Add(RcorrJZBem);
1289 <  Bpredem->Add(LcorrJZBem,-1);
1290 <  TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1291 <  BpredSBem->Add(RcorrJZBSBem);
1292 <  Bpred->Add(LcorrJZBSBem,-1);
1293 <  TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
1294 <  BpredSBeemm->Add(RcorrJZBSBeemm);
1295 <  BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1296 <  globalcanvas->cd();
1297 <  globalcanvas->SetLogy(1);
1298 <
1299 <  RcorrJZBeemm->SetMarkerStyle(20);
1300 <  RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1301 <  blankback->Draw();
1302 <  RcorrJZBeemm->Draw("e1x0,same");
1303 <  RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1304 <  
1305 <  Bpredem->SetLineColor(kRed+1);
1306 <  Bpredem->SetStats(0);
1307 <  Bpredem->Draw("hist,same");
1308 <
1309 <  BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1310 <  BpredSBem->SetLineStyle(2);
1311 <  BpredSBem->Draw("hist,same");
1312 <
1313 <  BpredSBeemm->SetLineColor(kBlue+1);
1314 <  BpredSBeemm->SetLineStyle(3);
1315 <  BpredSBeemm->Draw("hist,same");
1316 <  RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1317 <
1318 <  TLegend *legBpredc = make_legend("",0.6,0.55);
1319 <  if(use_data==1)
1320 <  {
1321 <    legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1322 <    legBpredc->AddEntry(Bpredem,"OFZP","l");
1323 <    legBpredc->AddEntry(BpredSBem,"OFSB","l");
1324 <    legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1325 <    legBpredc->Draw();
1326 <    CompleteSave(globalcanvas,"Bpred_Data_comparison");
1327 <  }
1328 <  if(use_data==0) {
1329 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1330 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1331 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1332 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1333 <    legBpredc->Draw();
1334 <    CompleteSave(globalcanvas,"Bpred_MC_comparison");
1335 <  }
1336 <  if(use_data==2) {
1337 <    legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1338 <    legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1339 <    legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1340 <    legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1341 <    if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1342 <    legBpredc->Draw();
1343 <    CompleteSave(globalcanvas,"Bpred_MCwithS_comparison");
1285 >  // The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1286 >  if(PlottingSetup::RestrictToMassPeak) {
1287 >    TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1288 >    Bpredem->Add(RcorrJZBem);
1289 >    Bpredem->Add(LcorrJZBem,-1);
1290 >    TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1291 >    BpredSBem->Add(RcorrJZBSBem);
1292 >    Bpred->Add(LcorrJZBSBem,-1);
1293 >    TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");  
1294 >    BpredSBeemm->Add(RcorrJZBSBeemm);
1295 >    BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1296 >    globalcanvas->cd();
1297 >    globalcanvas->SetLogy(1);
1298 >    
1299 >    RcorrJZBeemm->SetMarkerStyle(20);
1300 >    RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1301 >    blankback->Draw();
1302 >    RcorrJZBeemm->Draw("e1x0,same");
1303 >    RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1304 >    
1305 >    Bpredem->SetLineColor(kRed+1);
1306 >    Bpredem->SetStats(0);
1307 >    Bpredem->Draw("hist,same");
1308 >    
1309 >    BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1310 >    BpredSBem->SetLineStyle(2);
1311 >    BpredSBem->Draw("hist,same");
1312 >    
1313 >    BpredSBeemm->SetLineColor(kBlue+1);
1314 >    BpredSBeemm->SetLineStyle(3);
1315 >    BpredSBeemm->Draw("hist,same");
1316 >    RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1317 >    
1318 >    TLegend *legBpredc = make_legend("",0.6,0.55);
1319 >    if(use_data==1)
1320 >    {
1321 >      legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1322 >      legBpredc->AddEntry(Bpredem,"OFZP","l");
1323 >      legBpredc->AddEntry(BpredSBem,"OFSB","l");
1324 >      legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1325 >      legBpredc->Draw();
1326 >      CompleteSave(globalcanvas,subdir+"Bpred_Data_comparison");
1327 >    }
1328 >    if(use_data==0) {
1329 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1330 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1331 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1332 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1333 >      legBpredc->Draw();
1334 >      CompleteSave(globalcanvas,subdir+"Bpred_MC_comparison");
1335 >    }
1336 >    if(use_data==2) {
1337 >      legBpredc->AddEntry(RcorrJZBeemm,"MC true","p");
1338 >      legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1339 >      legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1340 >      legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1341 >      if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1342 >      legBpredc->Draw();
1343 >      CompleteSave(globalcanvas,subdir+"Bpred_MCwithS_comparison");
1344 >    }
1345    }
1346 +  
1347 +  TFile *f = new TFile("tester.root","RECREATE");
1348 +  RcorrJZBeemm->Write();
1349 +  Bpred->Write();
1350 +  f->Close();
1351 +  
1352    delete RcorrJZBeemm;
1353    delete LcorrJZBeemm;
1354    delete RcorrJZBem;
# Line 1075 | Line 1361 | void do_prediction_plot(string jzb, TCan
1361  
1362    delete blankback;
1363    
1364 +  delete BpredSys;
1365    if(PlottingSetup::RestrictToMassPeak) {
1366      delete RcorrJZBSBem;
1367      delete LcorrJZBSBem;
# Line 1087 | Line 1374 | void do_prediction_plot(string jzb, TCan
1374      delete JLcorrJZBSBeemm;
1375    }
1376    if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1377 +  switch_overunderflow(false);
1378   }
1379  
1380   void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
1381    TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
1382 <  do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
1383 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
1384 <  do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
1382 >  do_prediction_plot(datajzb,globalcanvas,jzbHigh ,data,overlay_signal);
1383 >  if ( !PlottingSetup::Approved ) {
1384 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mc,overlay_signal);
1385 >    do_prediction_plot(mcjzb,globalcanvas,jzbHigh ,mcwithsignal,overlay_signal);
1386 >  } else {
1387 >    write_info(__FUNCTION__,"You set approved to true, therefore not producing prediction/observation plots for MC with and without signal.");
1388 >  }
1389   }
1390  
1391   void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
# Line 1443 | Line 1735 | void draw_pure_jzb_histo(TCut cut,string
1735    TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1736    writeline1->SetTextSize(0.035);
1737    writeline1->Draw();
1738 <  save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1738 >  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1739 >  else save_with_ratio(datahisto,mcstack,jzbpad->cd(),savename);
1740    TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
1741    jzbpad2->cd();
1742    jzbpad2->SetLogy(1);
# Line 1458 | Line 1751 | void draw_pure_jzb_histo(TCut cut,string
1751    writeline1->SetTextSize(0.035);
1752    writeline1->Draw();
1753    DrawPrelim();
1754 <  save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1754 >  if(!Contains(savename,"Dibosons")) save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1755 >  else save_with_ratio(datahisto,mcstack,jzbpad2->cd(),(savename+"__PosOnly"));
1756    datahisto->Delete();
1757    mcstack.Delete();
1758   }
# Line 1466 | Line 1760 | void draw_pure_jzb_histo(TCut cut,string
1760   Double_t GausR(Double_t *x, Double_t *par) {
1761    return gRandom->Gaus(x[0],par[0]);
1762   }
1763 +
1764 + void produce_stretched_jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1765 +  TCanvas *dican = new TCanvas("dican","JZB Plots Canvas");
1766 +  float max=jzbHigh ;
1767 +  float min=-120;
1768 +  int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
1769 +  int coarserbins=int(nbins/2.0);
1770 +  int rebinnedbins=int(nbins/4.0);
1771 +  
1772 +  vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1773 +  for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1774 +  for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1775 +  for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1776 +
1777 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP",dican,binning);
1778 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP",dican,binning);
1779 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_SFZP",dican,binning);
1780 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_SFZP",dican,binning);
1781 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"Dibosons/ee/jzb_OS_OFZP",dican,binning);
1782 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"Dibosons/mm/jzb_OS_OFZP",dican,binning);
1783 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB",dican,binning);
1784 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB",dican,binning);
1785    
1786 +  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_SFZP_coarse",dican,coarse_binning);
1787 +  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"Dibosons/jzb_OS_OFZP_coarse",dican,coarse_binning);
1788 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_SFSB_coarse",dican,coarse_binning);
1789 +  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"Dibosons/jzb_OS_OFSB_coarse",dican,coarse_binning);
1790 +  
1791 +  delete dican;
1792 + }
1793 +  
1794 +
1795 + void diboson_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1796 +  vector<int> SamplesToBeModified = allsamples.FindSampleBySampleName("WW/WZ/ZZ");
1797 +  
1798 +  if(SamplesToBeModified.size()==0 || SamplesToBeModified[0]==-1) {
1799 +    write_error(__FUNCTION__,"Could not find any diboson samples - aborting diboson plots");
1800 +    return;
1801 +  }
1802 +  
1803 +  float stretchfactor = 100.0;
1804 +  vector<string> labels;
1805 +  
1806 +  
1807 +  dout << "Going to increase the cross section for diboson samples ... " << endl;
1808 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1809 +    float origxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1810 +    (allsamples.collection)[SamplesToBeModified[i]].xs=origxs*stretchfactor;
1811 +    dout << "     Increased xs for sample " << (allsamples.collection)[SamplesToBeModified[i]].filename << " from " << origxs << " to " << (allsamples.collection)[SamplesToBeModified[i]].xs << " (by a factor of " << stretchfactor << ")" << endl;
1812 +    labels.push_back((allsamples.collection)[SamplesToBeModified[i]].samplename);
1813 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=any2string(int(stretchfactor))+" x "+(allsamples.collection)[SamplesToBeModified[i]].samplename;
1814 +    dout << "         (also renamed it to " << (allsamples.collection)[SamplesToBeModified[i]].samplename << " )" << endl;
1815 +  }
1816 +  
1817 +  dout << "Going to produce JZB plots" << endl;
1818 +  produce_stretched_jzb_plots(mcjzb,datajzb,ratio_binning);
1819 +  TCanvas *gloca = new TCanvas("gloca","gloca");
1820 +  
1821 +  dout << "Going to produce prediction plots" << endl;
1822 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do only MC plots, no signal
1823 +  do_prediction_plot(mcjzb, gloca, PlottingSetup::jzbHigh, 0, false,"Dibosons/Bpred/" ); // do MC plots with signal
1824 +  delete gloca;
1825 +
1826 +  dout << "Going to reset the cross section for diboson samples ... " << endl;
1827 +  for(int i=0;i<(int)SamplesToBeModified.size();i++) {
1828 +    float Upxs=(allsamples.collection)[SamplesToBeModified[i]].xs;
1829 +    (allsamples.collection)[SamplesToBeModified[i]].xs=(allsamples.collection)[SamplesToBeModified[i]].xs*(1.0/stretchfactor);
1830 +    string Upname=(allsamples.collection)[SamplesToBeModified[i]].samplename;
1831 +    (allsamples.collection)[SamplesToBeModified[i]].samplename=labels[i];
1832 +    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;
1833 +    
1834 +  }
1835 +  
1836 + }
1837 +
1838 +
1839 + void draw_normalized_data_vs_data_histo(TCut cut1, TCut cut2, string variable, string legentry1, string legentry2, string savename, TCanvas *can,vector<float> binning) {
1840 +  TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
1841 +  jzbpad->cd();
1842 +  jzbpad->SetLogy(1);
1843 +  string xlabel="JZB [GeV]";
1844 +
1845 +  TH1F *datahisto1 = allsamples.Draw("datahisto1",variable,binning, xlabel, "events",cut1,data,luminosity);
1846 +  datahisto1->SetLineColor(kRed);
1847 +  datahisto1->SetMarkerColor(kRed);
1848 +  TH1F *datahisto2 = allsamples.Draw("datahisto2",variable,binning, xlabel, "events",cut2,data,luminosity);
1849 +  datahisto2->SetLineColor(kBlue);
1850 +  datahisto2->SetMarkerColor(kBlue);
1851 +  
1852 +  datahisto2->SetMarkerSize(DataMarkerSize);
1853 +  datahisto1->DrawNormalized("e1");
1854 +  datahisto2->DrawNormalized("histo,same");
1855 +  datahisto1->DrawNormalized("same,e1");
1856 +  
1857 +  TLegend *leg = make_legend();
1858 +  leg->AddEntry(datahisto1,legentry1.c_str());
1859 +  leg->AddEntry(datahisto2,legentry2.c_str());
1860 +  leg->Draw();
1861 +  
1862 +  save_with_ratio(datahisto1,datahisto2,jzbpad->cd(),("jzb/"+savename));
1863 +  
1864 +  datahisto1->Delete();
1865 +  datahisto2->Delete();
1866 + }
1867 +
1868 +
1869   void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1870    TCanvas *can = new TCanvas("can","JZB Plots Canvas");
1871    float max=jzbHigh ;
# Line 1480 | Line 1879 | void jzb_plots(string mcjzb, string data
1879    for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1880    for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1881  
1882 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
1883 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
1884 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
1885 <  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
1886 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
1887 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
1888 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1889 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
1890 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
1882 >  if ( !PlottingSetup::Approved ) {
1883 >    /*
1884 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
1885 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
1886 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
1887 >    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
1888 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
1889 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
1890 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1891 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
1892 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
1893 > */
1894 >    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);
1895 >    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);
1896 >    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);
1897 >
1898 >  }
1899    
1900    draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1901 <  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1902 <  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1903 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1904 <  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1905 <
1906 < //  draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
1907 < //  draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
1501 < //  flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1502 < //  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarsest",can,coarsest_binning);
1503 < //  if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarsest",can,coarsest_binning);
1901 >  if ( !PlottingSetup::Approved ) {
1902 >    draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1903 >    flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1904 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1905 >    if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1906 >  }
1907 >  delete can;
1908   }
1909  
1910  
# Line 1555 | Line 1959 | void compute_MC_yields(string mcjzb,vect
1959    string posneg[] = {"pos","neg"};
1960    TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
1961  
1962 <  for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
1962 >  for(int ijzb=0;ijzb<(int)jzb_cuts.size();ijzb++) {
1963      TCut jzbMC[]  = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
1964      dout << "_________________________________________________________" << endl;
1965      dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
1966 <    for(int isample=0;isample<(allsamples.collection).size();isample++) {
1966 >    for(int isample=0;isample<(int)(allsamples.collection).size();isample++) {
1967        if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << "  &  ";
1968        else dout << "Sample & ";
1969        for(int iregion=0;iregion<nRegions;iregion++) {
# Line 1818 | Line 2222 | void draw_ttbar_and_zjets_shape_for_one_
2222  
2223   void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
2224    int all_leptons=-1;
1821  int electrons_only=0;
1822  int mu_only=1;
1823  int twojetswith50gev=1;
2225    int threejetswith30gev=0;
2226   /*  
2227 +  int twojetswith50gev=1;
2228 +  int electrons_only=0;
2229 +  int mu_only=1;
2230 +
2231    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
2232    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
2233    
# Line 1836 | Line 2241 | void draw_ttbar_and_zjets_shape(string m
2241    draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
2242   }
2243  
2244 < void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1840 <  //first: colorful plots
2244 > float find_one_correction_factor(string FindKeyword, bool dodata, TCut SpecialCut, string SaveAs) {
2245    TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
2246    cancorr->SetLogz();
2247    cancorr->SetRightMargin(0.13);
2248 <  flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
2249 <  TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
2248 >  TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)"&&SpecialCut&&passtrig);
2249 >  if(PlottingSetup::DoBTag) zptforresponsepresentation=zptforresponsepresentation&&PlottingSetup::bTagRequirement;
2250    TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
2251 <  (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
2251 >  vector<int> SampleIndices=allsamples.FindSample(FindKeyword);
2252 >  for(int iSample=0;iSample<(int)SampleIndices.size();iSample++) {
2253 >    if((allsamples.collection)[SampleIndices[iSample]].is_data && !dodata) continue;
2254 >    if((allsamples.collection)[SampleIndices[iSample]].is_data ==false && dodata) continue;
2255 >    
2256 >    dout << "   Response correction : Using sample " << (allsamples.collection)[SampleIndices[iSample]].filename << " for " << FindKeyword << endl;
2257 >    (allsamples.collection)[SampleIndices[iSample]].events->Draw("sumJetPt[1]/pt:pt>>+niceresponseplotd",zptforresponsepresentation*cutWeight);
2258 >  }
2259 >    
2260    niceresponseplotd->SetStats(0);
2261    niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2262    niceresponseplotd->GetYaxis()->SetTitle("Response");
# Line 1853 | Line 2265 | void find_correction_factors(string &jzb
2265    niceresponseplotd->Draw("COLZ");
2266    TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
2267    profd->SetMarkerSize(DataMarkerSize);
2268 <  profd->Fit("pol0","","same,e1",30,400);
2268 >  profd->Fit("pol0","","same,e1",100,400);
2269    DrawPrelim();
2270 <  TText* title = write_text(0.5,0.7,"Data");
2270 >  string stitle="Data";
2271 >  if(!Contains(FindKeyword,"Data")) stitle="MC";
2272 >  TText* title = write_text(0.5,0.7,stitle.c_str());
2273    title->SetTextAlign(12);
2274    title->Draw();
2275    TF1 *datapol=(TF1*)profd->GetFunction("pol0");
2276 <  float datacorrection=datapol->GetParameter(0);
2277 <  stringstream dataresstring;
2278 <  dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
2279 <  TText* restitle = write_text(0.5,0.65,dataresstring.str());
2276 >  float correction=datapol->GetParameter(0);
2277 >  stringstream resstring;
2278 >  resstring<<"Response: "<<std::setprecision(2)<<100*correction<<" %";
2279 >  TText* restitle = write_text(0.5,0.65,resstring.str());
2280    restitle->SetTextAlign(12);
2281    restitle->SetTextSize(0.03);
2282    restitle->Draw();
2283 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
2284 <  
2285 <  TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
2286 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
2287 <  niceresponseplotm->SetStats(0);
2288 <  niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
2289 <  niceresponseplotm->GetYaxis()->SetTitle("Response");
1876 <  niceresponseplotm->GetXaxis()->CenterTitle();
1877 <  niceresponseplotm->GetYaxis()->CenterTitle();
1878 <  niceresponseplotm->Draw("COLZ");
1879 <  (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
1880 <  TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
1881 <  profm->SetMarkerSize(DataMarkerSize);
1882 <  profm->Fit("pol0","","same,e1",30,400);
1883 <  DrawMCPrelim();
1884 <  title = write_text(0.5,0.7,"MC simulation");
1885 <  title->SetTextAlign(12);
1886 <  title->Draw();
1887 <  TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
1888 <  float mccorrection=mcpol->GetParameter(0);
1889 <  stringstream mcresstring;
1890 <  mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
1891 <  TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
1892 <  mcrestitle->SetTextAlign(12);
1893 <  mcrestitle->SetTextSize(0.03);
1894 <  mcrestitle->Draw();
1895 <  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
2283 >  CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_New_"+SaveAs);
2284 >  delete cancorr;
2285 >  delete niceresponseplotd;
2286 >  return correction;
2287 > }
2288 >
2289 > void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
2290    
2291 +  dout << "Computing response corrections: " << endl;
2292 +  //Step 1 : Get results
2293 +  float datacorrection=find_one_correction_factor("Data",true,"","Data");
2294 +  float mccorrection=find_one_correction_factor("DY",false,"","MC");
2295 +  
2296 +  float dataEEcorrection=find_one_correction_factor("Data",true,"id1==0","Data_ee");
2297 +  float mcEEcorrection=find_one_correction_factor("DY",false,"id1==0","MC_ee");
2298 +  
2299 +  float dataMMcorrection=find_one_correction_factor("Data",true,"id1==1","Data_mm");
2300 +  float mcMMcorrection=find_one_correction_factor("DY",false,"id1==1","MC_mm");
2301 +  
2302 +  cout << "Corrections : " << endl;
2303 +  cout << "   Data : " << datacorrection << endl;
2304 +  cout << "     ee (" << dataEEcorrection << ") , mm (" << dataMMcorrection << ")" << endl;
2305 +  cout << "   MC : " << mccorrection << endl;
2306 +  cout << "     ee (" << mcEEcorrection << ") , mm (" << mcMMcorrection << ")" << endl;
2307    
2308 <  //Step 2: Getting the result
1899 < //  TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
2308 >  //Step 2: Processing the result and making it into something useful :-)
2309    stringstream jzbvardatas;
2310 <  if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
2311 <  if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
2310 >  jzbvardatas << "(";
2311 >  
2312 >  if(dataEEcorrection>=1) jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]-" << dataEEcorrection-1 << "*pt))";
2313 >  if(dataEEcorrection<1)  jzbvardatas<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-dataEEcorrection << "*pt))";
2314 >  
2315 >  if(dataMMcorrection>=1) jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]-" << dataMMcorrection-1 << "*pt))";
2316 >  if(dataMMcorrection<1)  jzbvardatas<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-dataMMcorrection << "*pt))";
2317 >  
2318 >  float averagecorrection=(dataMMcorrection+dataEEcorrection)/2.0;
2319 >  
2320 >  if(datacorrection>=1) jzbvardatas<<"+((id1!=id2)*(jzb[1]-" << datacorrection-1 << "*pt))";
2321 >  if(datacorrection<1) jzbvardatas<<"+((id1!=id2)*(jzb[1]+" << 1-datacorrection << "*pt))";
2322 >  
2323 >  jzbvardatas << ")";
2324    jzbvardata=jzbvardatas.str();
2325 +  
2326    stringstream jzbvarmcs;
2327 <  if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
2328 <  if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
2327 >  jzbvarmcs << "(";
2328 >  
2329 >  if(mcEEcorrection>=1) jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]-" << mcEEcorrection-1 << "*pt))";
2330 >  if(mcEEcorrection<1)  jzbvarmcs<<"((id1==0&&id1==id2)*(jzb[1]+" << 1-mcEEcorrection << "*pt))";
2331 >  
2332 >  if(mcMMcorrection>=1) jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]-" << mcMMcorrection-1 << "*pt))";
2333 >  if(mcMMcorrection<1)  jzbvarmcs<<"+((id1==1&&id1==id2)*(jzb[1]+" << 1-mcMMcorrection << "*pt))";
2334 >  
2335 >  float averagemccorrection=(mcMMcorrection+mcEEcorrection)/2.0;
2336 >  
2337 >  if(mccorrection>=1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]-" << mccorrection-1 << "*pt))";
2338 >  if(mccorrection<1) jzbvarmcs<<"+((id1!=id2)*(jzb[1]+" << 1-mccorrection << "*pt))";
2339 >  
2340 >  jzbvarmcs << ")";
2341    jzbvarmc=jzbvarmcs.str();
2342 +
2343    dout << "JZB Z pt correction summary : " << endl;
2344    dout << "  Data: The response is " << datacorrection << "  --> jzb variable is now : " << jzbvardata << endl;
2345    dout << "  MC  : The response is " << mccorrection << "  --> jzb variable is now : " << jzbvarmc << endl;
2346 +  
2347   }
2348  
2349   void pick_up_events(string cut) {
# Line 1915 | Line 2351 | void pick_up_events(string cut) {
2351    allsamples.PickUpEvents(cut);
2352   }
2353  
2354 < void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
2354 > void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError,float DataPeakError, vector<float> jzb_shape_limit_bins) {
2355    dout << "Saving configuration template!" << endl;
2356    ofstream configfile;
2357    configfile.open("../DistributedModelCalculations/last_configuration.C");
# Line 1935 | Line 2371 | void save_template(string mcjzb, string
2371    configfile<<"string datajzb=\"datajzb_ERROR\";\n";
2372    configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
2373    configfile<<"vector<float>jzb_cuts;\n";
2374 +  configfile<<"vector<float>jzb_shape_limit_bins;\n";
2375    configfile<<"float MCPeakError=-999;\n";
2376 +  configfile<<"float DataPeakError=-999;\n";
2377    configfile<<"}\n\n";
2378  
2379    configfile<<"void read_config() {\n";
2380    configfile<<"datajzb=\""<<datajzb<<"\";\n";
2381    configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
2382 <  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
2383 <  for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2382 >  configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n";
2383 >  configfile<<"DataPeakError="<<DataPeakError<<";\n\n";
2384 >  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";
2385 >  configfile<<"\n\n";
2386 >  for(int i=0;i<(int)Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2387 >  for(int i=0;i<(int)Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2388 >  for(int i=0;i<(int)Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2389    configfile<<"\n\n";
2390 <  for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2391 <  for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2392 <  for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2390 >  for(int i=0;i<(int)flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2391 >  for(int i=0;i<(int)flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2392 >  for(int i=0;i<(int)flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2393 >  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";
2394    configfile<<"\n\n";
1951  for(int i=0;i<flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1952  for(int i=0;i<flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1953  for(int i=0;i<flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
2395    configfile<<"\n\n";
2396    configfile<<"luminosity="<<luminosity<<";\n";
2397 +  configfile<<"RestrictToMassPeak="<<RestrictToMassPeak<<";//defines the type of analysis we're running\n";
2398    
2399    configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
2400    
# Line 1975 | Line 2417 | void draw_all_ttbar_histos(TCanvas *can,
2417    float max=histos[0]->GetMaximum();
2418    if(manualmin>=0) min=manualmin;
2419    else {
2420 <    for(int i=1;i<histos.size();i++) {
2420 >    for(int i=1;i<(int)histos.size();i++) {
2421        float curmin=get_nonzero_minimum(histos[i]);
2422        float curmax=histos[i]->GetMaximum();
2423        if(curmin<min) min=curmin;
# Line 1986 | Line 2428 | void draw_all_ttbar_histos(TCanvas *can,
2428    histos[0]->Draw(drawoption.c_str());
2429    stringstream drawopt;
2430    drawopt << drawoption << ",same";
2431 <  for(int i=1;i<histos.size();i++) {
2431 >  for(int i=1;i<(int)histos.size();i++) {
2432      histos[i]->Draw(drawopt.str().c_str());
2433    }
2434   }
# Line 1995 | Line 2437 | void ttbar_sidebands_comparison(string m
2437    //in the case of the on peak analysis, we compare the 3 control regions to the real value
2438    //in the case of the OFF peak analysis, we compare our control region to the real value
2439    TCut weightbackup=cutWeight;
1998  cutWeight="1.0";
1999  float simulatedlumi = luminosity; //in pb please - adjust to your likings
2440    
2441 +  bool doPURW=false;
2442 +  
2443 +  
2444 +  if(!doPURW) {
2445 +    cutWeight="1.0";
2446 +    // Do it without PU re-weighting
2447 +    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2448 +    stringstream resultsNoPU;
2449 +    stringstream noPUdatajzb;
2450 +    stringstream noPUmcjzb;
2451 +    
2452 +    stringstream mcjzbnoPU;
2453 +    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,true,noPUdatajzb,noPUmcjzb);
2454 +    mcjzb = noPUmcjzb.str();
2455 +  }
2456 +
2457 +    
2458 +    
2459 +    
2460 +    
2461 +    
2462 +  float simulatedlumi = luminosity; //in pb please - adjust to your likings
2463  
2464    TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2465    TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
# Line 2035 | Line 2497 | void ttbar_sidebands_comparison(string m
2497    }
2498    
2499    vector<TH1F*> histos;
2500 +  TZem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2501 +  TZeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2502    histos.push_back(TZem);
2503    histos.push_back(TZeemm);
2504    if(PlottingSetup::RestrictToMassPeak) {
2505 +    TSeemm->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2506 +    TSem->GetXaxis()->SetRangeUser(-100,binning[binning.size()-1]);
2507      histos.push_back(TSem);
2508      histos.push_back(TSeemm);
2509    }
# Line 2053 | Line 2519 | void ttbar_sidebands_comparison(string m
2519    leg->Draw("same");
2520    DrawMCPrelim(simulatedlumi);
2521    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
2056  
2522    TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2523    TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2524 <  TH1F *TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2525 <  TH1F *TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2524 >  TH1F *TSeemmcopy;
2525 >  TH1F *TSemcopy;
2526 >  if(PlottingSetup::RestrictToMassPeak) {
2527 >    TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2528 >    TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2529 >  }
2530  
2531    TZem->Divide(TZeemm);
2532    TZem->SetMarkerStyle(21);
# Line 2077 | Line 2546 | void ttbar_sidebands_comparison(string m
2546      TSeemm->Draw("same");
2547    }
2548    
2549 <  float linepos=0.25;
2550 <  if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
2549 >  float linepos=emuncertONPEAK;
2550 >  if(!PlottingSetup::RestrictToMassPeak) linepos=emuncertOFFPEAK;
2551 >  
2552    TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
2553    TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2554    TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
2555    
2556 +  /*write_warning(__FUNCTION__,"These two lines are to be removed!");
2557 +  TLine *topalt = new TLine(binning[0],1.0+0.1,binning[binning.size()-1],1.0+0.1);
2558 +  TLine *bottomalt = new TLine(binning[0],1.0-0.1,binning[binning.size()-1],1.0-0.1);
2559 +  topalt->SetLineColor(kRed);topalt->SetLineStyle(3);
2560 +  bottomalt->SetLineColor(kRed);bottomalt->SetLineStyle(3);
2561 +  topalt->Draw("same");bottomalt->Draw("same");*/
2562 +  
2563 +  
2564    top->SetLineColor(kBlue);top->SetLineStyle(2);
2565    bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2566    center->SetLineColor(kBlue);
# Line 2107 | Line 2585 | void ttbar_sidebands_comparison(string m
2585    CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
2586    
2587  
2110
2588   ///-------------- second part: only look at the quantity we actually care about!
2589    TH1F *leftsfzp  = (TH1F*)nTZeemm->Clone("leftsfzp");
2590    TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
# Line 2153 | Line 2630 | void ttbar_sidebands_comparison(string m
2630    tcan->SetLogy(0);
2631    rightofzp->Divide(rightsfzp);
2632    rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2633 <  rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
2633 >  rightofzp->GetYaxis()->SetRangeUser(0.0,2.5);
2634    rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2635    rightofzp->Draw();
2636    if(PlottingSetup::RestrictToMassPeak) {
# Line 2213 | Line 2690 | void ttbar_sidebands_comparison(string m
2690  
2691   void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
2692    vector<float> nicer_binning;
2693 <  nicer_binning.push_back(-125);
2693 >  
2694 > /*  nicer_binning.push_back(-400);
2695 >  nicer_binning.push_back(-250);
2696 >  nicer_binning.push_back(-200);
2697 >  nicer_binning.push_back(-150);
2698 >  nicer_binning.push_back(-100);
2699 >  nicer_binning.push_back(-50);
2700 >  nicer_binning.push_back(-20);
2701 >  
2702 >  nicer_binning.push_back(0);
2703 >  nicer_binning.push_back(20);
2704 >  nicer_binning.push_back(50);
2705 >  nicer_binning.push_back(100);
2706 >  nicer_binning.push_back(150);
2707 >  nicer_binning.push_back(200);
2708 >  nicer_binning.push_back(250);
2709 >  nicer_binning.push_back(400);*/
2710 >  
2711    nicer_binning.push_back(-100);
2218  nicer_binning.push_back(-75);
2712    nicer_binning.push_back(-50);
2713    nicer_binning.push_back(-25);
2714    nicer_binning.push_back(0);
# Line 2230 | Line 2723 | void ttbar_sidebands_comparison(string m
2723    nicer_binning.push_back(230);
2724    nicer_binning.push_back(280);
2725    nicer_binning.push_back(400);
2726 +  
2727    ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
2728   }
2729  
2730  
2731 < void zjets_prediction_comparison() {
2732 <  // Do it without PU re-weighting
2733 <  float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2734 <  stringstream resultsNoPU;
2735 <
2736 <  stringstream mcjzbnoPU;
2737 <  find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
2738 <  if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
2739 <  else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
2731 > void zjets_prediction_comparison(string mcjzbWithPUa) {
2732 >  TCanvas *zcan = new TCanvas("zcan","zcan");  
2733 > //  zcan->SetLogy(1);
2734 >  TCut weightbackup=cutWeight;
2735 >  
2736 >  bool UsePURW=false;
2737 >  
2738 >  
2739 >  string mcjzb;
2740 >  if(UsePURW) {
2741 >    mcjzb=mcjzbWithPUa;
2742 >  } else {
2743 >    // Do it without PU re-weighting
2744 >    float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2745 >    stringstream resultsNoPU;
2746 >    stringstream noPUdatajzb;
2747 >    stringstream noPUmcjzb;
2748 >    
2749 >    find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,resultsNoPU,false,noPUdatajzb,noPUmcjzb);
2750 >    dout << "The peak corrected JZB expression for MC without pileup is : " <<  noPUmcjzb.str() << endl;
2751 >    
2752 >    mcjzb = noPUmcjzb.str();
2753 >    
2754 >    cutWeight="1.0";
2755 >  }
2756  
2757 <  string mcjzb = mcjzbnoPU.str();
2758 <  dout << "The peak corrected JZB expression for MC without pileup is : " <<  mcjzb << endl;
2757 >  
2758 >  vector<float> binning;
2759 >  binning.push_back(0);
2760 >  binning.push_back(10);
2761 >  binning.push_back(20);
2762 > //  binning.push_back(30);
2763 >  binning.push_back(40);
2764 > //   binning.push_back(50);
2765 > //   binning.push_back(60);
2766 > //   binning.push_back(70);
2767 > //   binning.push_back(80);
2768 > //   binning.push_back(90);
2769 >  binning.push_back(100);
2770  
2250  TCut weightbackup=cutWeight;
2251  cutWeight="1.0";
2252  float sbg_min=0.;
2253  float sbg_max=100.;
2254  int sbg_nbins=5;
2771    float simulatedlumi = luminosity;//in pb please - adjust to your likings
2772    
2773    TCut kPos((mcjzb+">0").c_str());
2774    TCut kNeg((mcjzb+"<0").c_str());
2775    string var( "abs("+mcjzb+")" );
2776 +  
2777 +  TCut notTau("abs(genMID1)!=15");
2778 +  TCut ONLYTau("mll>20");
2779 +  
2780  
2781 <  TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
2782 <  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2783 <                                  kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2264 <  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2265 <                                  kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2781 >  TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2782 >  TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&notTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2783 >  
2784    hJZBpos->SetLineColor(kBlack);
2785    hJZBneg->SetLineColor(kRed);
2786    
2787 <  Int_t nbins = 5;
2270 <  Float_t xmax = 100.;
2271 <
2272 <  
2273 <  TCanvas *zcan = new TCanvas("zcan","zcan");  
2274 <  zcan->SetLogy(1);
2275 <
2787 >  hJZBpos->SetMinimum(1.0);
2788    hJZBpos->Draw("e1");
2789    hJZBneg->Draw("same,hist");
2790    hJZBpos->Draw("same,e1"); // So it's on top...
2791    
2792 <  TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
2792 >  TLegend *leg = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.55,0.75,false);
2793    leg->AddEntry(hJZBpos,"Observed","pe");
2794    leg->AddEntry(hJZBneg,"Predicted","l");
2795    leg->Draw("same");
2796    DrawMCPrelim(simulatedlumi);
2797 <  CompleteSave(zcan,"Systematics/zjets_prediction");
2797 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction");
2798    
2799    TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
2800    hratio->Divide(hJZBneg);
2801    
2802 +  for(int i=1;i<=hJZBpos->GetNbinsX();i++) {
2803 +    cout << "Positive: " << hJZBpos->GetBinContent(i) << "   vs    Negative : " << hJZBneg->GetBinContent(i) << "   (ratio : " << hJZBpos->GetBinContent(i) / hJZBneg->GetBinContent(i) << endl;
2804 +  }
2805 +  
2806    zcan->SetLogy(0);
2807    hratio->GetYaxis()->SetRangeUser(0,2.5);
2808    hratio->GetYaxis()->SetTitle("Observed/Predicted");
2809    hratio->Draw("e1");
2810    
2811 <  TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
2812 <  TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
2813 <  TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
2811 >  TLine *top = new TLine(binning[0],1.25,binning[binning.size()-1],1.25);
2812 >  TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2813 >  TLine *bottom = new TLine(binning[0],0.75,binning[binning.size()-1],0.75);
2814    
2815  
2816    top->SetLineColor(kBlue);top->SetLineStyle(2);
# Line 2305 | Line 2821 | void zjets_prediction_comparison() {
2821    center->Draw("same");
2822    bottom->Draw("same");
2823    
2824 <  TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
2824 >  TLegend *leg2 = make_legend("MC Z+jets #rightarrow ee,#mu#mu",0.25,0.75,false);
2825    leg2->AddEntry(hratio,"obs / pred","pe");
2826    leg2->AddEntry(bottom,"syst. envelope","l");
2827    leg2->Draw("same");
2828    DrawMCPrelim(simulatedlumi);
2829 <  CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
2829 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemm_prediction_ratio");
2830 >  
2831 >  TCut reducedNJets(cutnJets);
2832 >  
2833 >  TH1F *TAUhJZBpos = systsamples.Draw("TAUhJZBpos",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2834 >  TH1F *LcorrJZBeemm     = systsamples.Draw("LcorrJZBeemm",var,binning, "JZB [GeV]", "events",cutmass&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2835 >  TH1F *RcorrJZBem       = systsamples.Draw("RcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2836 >  TH1F *LcorrJZBem       = systsamples.Draw("LcorrJZBem",var,binning, "JZB [GeV]", "events",cutmass&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2837 >
2838 >  TH1F *RcorrJZBSBem;
2839 >  TH1F *LcorrJZBSBem;
2840 >  TH1F *RcorrJZBSBeemm;
2841 >  TH1F *LcorrJZBSBeemm;
2842 >
2843 >  if(PlottingSetup::RestrictToMassPeak) {
2844 >    RcorrJZBSBem   = systsamples.Draw("RcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2845 >    LcorrJZBSBem   = systsamples.Draw("LcorrJZBSBem",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2846 >    RcorrJZBSBeemm = systsamples.Draw("RcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kPos,mc,simulatedlumi,systsamples.FindSample("/DY"));
2847 >    LcorrJZBSBeemm = systsamples.Draw("LcorrJZBSBeemm",var,binning, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&reducedNJets&&ONLYTau&&kNeg,mc,simulatedlumi,systsamples.FindSample("/DY"));
2848 >  }
2849 >  
2850 >  TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2851 >  if(PlottingSetup::RestrictToMassPeak) {
2852 >    Bpred->Add(RcorrJZBem,1.0/3.);
2853 >    Bpred->Add(LcorrJZBem,-1.0/3.);
2854 >    Bpred->Add(RcorrJZBSBem,1.0/3.);
2855 >    Bpred->Add(LcorrJZBSBem,-1.0/3.);
2856 >    Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2857 >    Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2858 >  } else {
2859 >    Bpred->Add(RcorrJZBem,1.0);
2860 >    Bpred->Add(LcorrJZBem,-1.0);
2861 >  }
2862 >  
2863 >  Bpred->SetLineColor(kRed);
2864 >
2865 >  TAUhJZBpos->SetLineColor(kBlack);
2866 >  Bpred->SetLineColor(kRed);
2867 >  
2868 >  TAUhJZBpos->SetMinimum(1.0);
2869 >  TAUhJZBpos->Draw("e1");
2870 >  Bpred->Draw("same,hist");
2871 >  TAUhJZBpos->Draw("same,e1");
2872 >  
2873 >  TLegend *TAUleg = make_legend("MC Z+jets #rightarrow ee,#mu#mu,#tau#tau",0.55,0.75,false);
2874 >  TAUleg->AddEntry(TAUhJZBpos,"Observed","pe");
2875 >  TAUleg->AddEntry(Bpred,"Predicted","l");
2876 >  TAUleg->Draw("same");
2877 >  DrawMCPrelim(simulatedlumi);
2878 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction");
2879 >  
2880 >  TH1F* TAUhratio = (TH1F*)TAUhJZBpos->Clone("TAUhratio");
2881 >  TAUhratio->Divide(Bpred);
2882 >  
2883 >  for(int i=1;i<=TAUhJZBpos->GetNbinsX();i++) {
2884 >    cout << "ee/mm/tautau observed: " << TAUhJZBpos->GetBinContent(i) << "   vs    predicted : " << Bpred->GetBinContent(i) << "   (ratio : " << TAUhJZBpos->GetBinContent(i) / Bpred->GetBinContent(i) << endl;
2885 >  }
2886 >  
2887 >  zcan->SetLogy(0);
2888 >  TAUhratio->GetYaxis()->SetRangeUser(0,2.5);
2889 >  TAUhratio->GetYaxis()->SetTitle("Observed/Predicted");
2890 >  TAUhratio->Draw("e1");
2891 >  
2892 >  top->Draw("same");
2893 >  center->Draw("same");
2894 >  bottom->Draw("same");
2895 >  
2896 >  TLegend *TAUleg2 = make_legend("MC Z+jets #rightarrow #tau#tau",0.25,0.75,false);
2897 >  TAUleg2->AddEntry(TAUhratio,"obs / pred","pe");
2898 >  TAUleg2->AddEntry(bottom,"syst. envelope","l");
2899 >  TAUleg2->Draw("same");
2900 >  DrawMCPrelim(simulatedlumi);
2901 >  CompleteSave(zcan,"Systematics/ZJets/zjets_eemumutautau_prediction_ratio");
2902 >  
2903 >  delete Bpred;
2904 >  delete TAUhJZBpos;
2905 >  delete LcorrJZBeemm;
2906 >  delete RcorrJZBem;
2907 >  delete LcorrJZBem;
2908 >  
2909 >  if(PlottingSetup::RestrictToMassPeak) {
2910 >    delete RcorrJZBSBem;
2911 >    delete LcorrJZBSBem;
2912 >    delete RcorrJZBSBeemm;
2913 >    delete LcorrJZBSBeemm;
2914 >  }
2915 >  
2916    
2917    delete zcan;
2918    cutWeight=weightbackup;
# Line 2336 | Line 2938 | void sideband_assessment(string datajzb,
2938    tout << "\\begin{tabular}{l|cc}" << endl;
2939    tout << "\\hline" << endl;
2940    tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
2941 <  tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
2941 >  tout << "\\#(events) & "<<OFZP<<" & "<<OFSB<<"\\\\ \\hline" << endl;
2942    tout << "\\end{tabular}" << endl;
2943    tout << "\\end{center}" << endl;
2944    tout << "\\end{table}" << endl;
# Line 2354 | Line 2956 | void make_table(samplecollection &coll,
2956    
2957    TCanvas *cannie = new TCanvas("cannie","cannie");
2958    
2959 <  for(int icut=0;icut<jzb_cuts.size();icut++) {
2959 >  for(int icut=0;icut<(int)jzb_cuts.size();icut++) {
2960      float currcut=jzb_cuts[icut];
2961      int nbins=1;float low=currcut;
2962      vector<int> mysample;
# Line 2413 | Line 3015 | void make_table(samplecollection &coll,
3015    //prediction part
3016    if(is_data) cout << "Data prediction & ";
3017    if(subselection!="none") cout << subselection << " prediction &";
3018 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
3018 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
3019    
3020    cout << endl;
3021    //observation part
3022    if(is_data) cout << "Data observation & ";
3023    if(subselection!="none") cout << subselection << " observation &";
3024 <  for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
3024 >  for(int ij=0;ij<(int)jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
3025    cout << endl;
3026    cout << "_________________________________________________________________" << endl;
3027    delete cannie;
# Line 2454 | Line 3056 | void JZBSelEff(string mcjzb, TTree* even
3056    int nbins = sizeof(xbins)/sizeof(float)-1;
3057    int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
3058  
3059 <  TH1F* heff  = new TH1F("heff", "JZB eff ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3060 <  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3061 <  TH1F* hreco = new TH1F("hreco","JZB reco ; generator-level JZB [GeV]; efficiency",nbins,xbins);
3059 >  
3060 >  TH1F* heff  = new TH1F("heff", "JZB eff ; generator JZB [GeV]; efficiency",nbins,xbins);
3061 >  TH1F* hgen  = new TH1F("hgen", "JZB gen ; generator JZB [GeV]; efficiency",nbins,xbins);
3062 >  TH1F* hreco = new TH1F("hreco","JZB reco ; generator JZB [GeV]; efficiency",nbins,xbins);
3063  
3064    TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
3065    TCut kreco(cutmass);
# Line 2472 | Line 3075 | void JZBSelEff(string mcjzb, TTree* even
3075    TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
3076    can->SetGridx(1);
3077    can->SetGridy(1);
3078 +  can->SetLeftMargin(0.16);
3079 +  can->SetRightMargin(0.05);
3080    TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
3081 +  leg->SetBorderSize(1);
3082 +  leg->SetLineColor(kBlack);
3083 +  leg->SetTextFont(62);
3084  
3085 <  
2478 <
2479 <  for ( int icut=0; icut<jzb_bins.size(); ++icut ) {
3085 >  for ( int icut=0; icut<(int)jzb_bins.size(); ++icut ) {
3086  
3087      ostringstream selection;
3088      selection << mcjzb << ">" << jzb_bins[icut];
# Line 2492 | Line 3098 | void JZBSelEff(string mcjzb, TTree* even
3098      }
3099    
3100      heff->GetXaxis()->SetRangeUser(min, max);
3101 + //    heff->GetXaxis()->SetLabelSize(0.05); // paper style. overruled.
3102 + //    heff->GetYaxis()->SetLabelSize(0.05); // paper style. overruled.
3103 + //    heff->GetXaxis()->SetTitleSize(0.06); // paper style. overruled.
3104 + //    heff->GetYaxis()->SetTitleSize(0.06); // paper style. overruled.
3105      heff->SetMarkerStyle(markers[icut]);
3106      heff->Fit("func","Q+","same");
3107  
# Line 2503 | Line 3113 | void JZBSelEff(string mcjzb, TTree* even
3113  
3114      // Store plot
3115      TH1F* h = (TH1F*)heff->Clone(hname);
3116 +    h->SetNdivisions(505,"X");
3117      if ( icut) h->Draw("same");
3118      else h->Draw();
3119      char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
# Line 2523 | Line 3134 | void JZBSelEff(string mcjzb, TTree* even
3134   // Calls the above function for each signal sample
3135   void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
3136   {  
3137 <  for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
3137 >  for (int isignal=0; isignal<(int)signalsamples.collection.size();isignal++) {
3138      dout << "JZB selection efficiency curve: " << std::endl;
3139      JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
3140    }
# Line 2566 | Line 3177 | void qcd_plots(string datajzb, string mc
3177    TH1F *RcorrJZBSBeemm;
3178    TH1F *LcorrJZBSBeemm;
3179    
3180 <  TH1F *RcorrJZBeemmNoS;
3180 > //  TH1F *RcorrJZBeemmNoS;
3181  
3182      //these are for the ratio
3183    TH1F *JRcorrJZBeemm   = qcdsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
# Line 2650 | Line 3261 | void qcd_plots(string datajzb, string mc
3261    //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
3262    string ytitle("ratio");
3263    if ( use_data==1 ) ytitle = "data/pred";
3264 <  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,use_data!=1,ytitle);
3264 >  save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,"QCD/Bpred",true,false,ytitle);
3265    
3266    TH1F *allevents = qcdsamples.Draw("allevents","pfJetGoodNum",1,0,100, "internal code", "events", "" ,mc, luminosity);
3267    TH1F *ossf = qcdsamples.Draw("ossf","pfJetGoodNum",1,0,100, "internal code", "events", cutOSSF ,mc, luminosity);
# Line 2697 | Line 3308 | void qcd_plots(string datajzb, string mc
3308    dout << "    Observation increases by : " << RcorrJZBeemm->Integral() << endl;
3309    
3310    dout << endl;
3311 <  for(int i=0;i<bins.size();i++) {
3311 >  for(int i=0;i<(int)bins.size();i++) {
3312      dout << " JZB > " << bins[i] << " : " << endl;
3313      dout << "    Observation increases by : " << RcorrJZBeemm->Integral(RcorrJZBeemm->FindBin(bins[i]),RcorrJZBeemm->GetNbinsX()) << endl;
3314      if(PlottingSetup::RestrictToMassPeak) {
# Line 2745 | Line 3356 | void check_ptsanity() {
3356    leg->SetY2(1.0);
3357    
3358    
3359 <  for(int isample=0;isample<allsamples.collection.size();isample++) {
3359 >  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3360      string nowname=(allsamples.collection)[isample].filename;
3361      cout << "Drawing: " << nowname << " (sample " << isample+1 << " / " << allsamples.collection.size() << ")" << endl;
3362      individualpt1histos[isample] = allsamples.Draw(GetNumericHistoName(),"pt1",50,0,50, "p_{T,1}", "events",cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample(nowname));
# Line 2769 | Line 3380 | void check_ptsanity() {
3380    ptsancan->cd(2);
3381    fpt2->Draw();
3382  
3383 <  for(int isample=0;isample<allsamples.collection.size();isample++) {
3383 >  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
3384      ptsancan->cd(1);
3385      individualpt1histos[isample]->DrawNormalized("same,histo");
3386      ptsancan->cd(2);
# Line 2782 | Line 3393 | void check_ptsanity() {
3393    delete ptsancan;
3394   }
3395  
3396 + void do_mlls_plot(string mcjzb) {
3397 +  cout << "At this point we'd plot the mll distribution" << endl;
3398 +  TCanvas *sigcan = new TCanvas("sigcan","sigcan");
3399 +  for(int isig=0;isig<(int)(signalsamples.collection).size();isig++) {
3400 +    if(!(signalsamples.collection)[isig].events) continue;
3401 +    string nowname=(signalsamples.collection)[isig].filename;
3402 +    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets,mc,luminosity,signalsamples.FindSample(nowname));
3403 + //    TH1F *mll = signalsamples.Draw("mllhisto","mll",150,0,150, "m_{ll}", "events","",mc,luminosity,signalsamples.FindSample(nowname));
3404 +    mll->SetLineColor(TColor::GetColor("#04B404"));
3405 +    stringstream poscutS;
3406 +    poscutS << "((" << mcjzb <<")>50)";
3407 +    TCut poscut(poscutS.str().c_str());
3408 +    TH1F *mllP = signalsamples.Draw("mllhistoP","mll",150,0,150, "m_{ll}", "events",cutOSSF&&cutnJets&&poscut,mc,luminosity,signalsamples.FindSample(nowname));
3409 +    mllP->SetLineColor(TColor::GetColor("#0040FF"));
3410 +    mll->Draw("histo");
3411 +    mllP->Draw("histo,same");
3412 +    TLegend *leg = make_legend();
3413 +    leg->SetY1(0.8);
3414 +    leg->AddEntry(mll,(signalsamples.collection)[isig].samplename.c_str(),"L");
3415 +    leg->AddEntry(mllP,((signalsamples.collection)[isig].samplename+", JZB>50").c_str(),"L");
3416 +    leg->Draw();
3417 +    TLine *lin = new TLine(71.2,0,71.2,mll->GetMaximum());
3418 +    TLine *lin2 = new TLine(111.2,0,111.2,mll->GetMaximum());
3419 +    lin->Draw("same");
3420 +    lin2->Draw("same");
3421 +    
3422 +    CompleteSave(sigcan,"MllShape/"+(signalsamples.collection)[isig].samplename);
3423 +    delete mll;
3424 +    delete mllP;
3425 +  }
3426 + }
3427 +
3428 + void met_vs_jzb_plots() {
3429 +  
3430 +  TCanvas *canmetjzb = new TCanvas("canmet","MET vs JZB canvas");
3431 +  canmetjzb->SetRightMargin(0.16);
3432 +  
3433 +  vector<string> findme;
3434 +  findme.push_back("DY");
3435 +  findme.push_back("TTJets");
3436 +  findme.push_back("LM");
3437 +  
3438 +  for(int ifind=0;ifind<(int)findme.size();ifind++) {
3439 +    vector<int> selsamples = allsamples.FindSample(findme[ifind]);
3440 +    TH2F *metvsjzb = new TH2F("metvsjzb","metvsjzb",200,0,100,400,-100,100);
3441 +    for(int isel=0;isel<(int)selsamples.size();isel++) {
3442 +      cout << "Producing MET:JZB plot ... working on sample: " << allsamples.collection[selsamples[isel]].filename << endl;
3443 +      allsamples.collection[selsamples[isel]].events->Draw("jzb[1]:met[4]>>+metvsjzb",cutmass&&cutOSSF);
3444 +    }
3445 +    metvsjzb->Scale(allsamples.collection[selsamples[0]].weight);
3446 +    metvsjzb->SetStats(0);
3447 +    metvsjzb->GetXaxis()->SetTitle("MET (GeV)");
3448 +    metvsjzb->GetYaxis()->SetTitle("JZB (GeV)");
3449 +    metvsjzb->GetXaxis()->CenterTitle();
3450 +    metvsjzb->GetYaxis()->CenterTitle();
3451 +    metvsjzb->Draw("COLZ");
3452 +    TText* title = write_text(0.5,0.95,allsamples.collection[selsamples[0]].samplename);
3453 +    title->SetTextAlign(12);
3454 +    title->Draw();
3455 +    CompleteSave(canmetjzb,(string)"METvsJZBplots/"+findme[ifind]);
3456 +  }
3457 + }
3458 +    
3459 +
3460   void test() {
3461    
3462    TCanvas *testcanv = new TCanvas("testcanv","testcanv");
3463    testcanv->cd();
3464 <  switch_overunderflow(true);
3464 > //  switch_overunderflow(true);
3465    TH1F *ptdistr   = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
3466    switch_overunderflow(false);
3467    ptdistr->Draw();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines