ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/Plotting_Functions.C
Revision: 1.1
Committed: Mon Jan 30 14:46:25 2012 UTC (13 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Log Message:
Initial commit of Ice Cream versions

File Contents

# Content
1 #include <iostream>
2 #include <vector>
3 #include <sys/stat.h>
4
5 #include <TCut.h>
6 #include <TROOT.h>
7 #include <TCanvas.h>
8 #include <TMath.h>
9 #include <TColor.h>
10 #include <TPaveText.h>
11 #include <TRandom.h>
12 #include <TH1.h>
13 #include <TH2.h>
14 #include <TF1.h>
15 #include <TSQLResult.h>
16 #include <TProfile.h>
17 #include <TLegendEntry.h>
18
19 using namespace std;
20
21 using namespace PlottingSetup;
22
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 << "Info : The trigger requirement is currently set to " << (const char*) passtrig << endl;
27 }
28
29 void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result, bool doPUreweighting = true )
30 {
31 // Temporarily switch off PU reweighting, if asked
32 TCut weightbackup=cutWeight;
33 if ( !doPUreweighting ) cutWeight="1.0";
34
35 TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
36 TH1F *rawJZBeemmMC = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
37 TH1F *rawJZBeemmData = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
38 TH1F *rawJZBemMC = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
39 TH1F *rawJZBemData = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
40 TH1F *rawttbarjzbeemmMC;
41
42 if(method==doKM) {
43 //we only need this histo for the KM fitting...
44 rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
45 MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
46 DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
47 }
48 else {
49 TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
50 TH1F *reducedData = (TH1F*)rawJZBeemmData->Clone();
51 reducedMC->Add(rawJZBemMC,-1);
52 reducedData->Add(rawJZBemData,-1);
53 //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)
54 MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
55 DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
56
57 }
58
59 // Revert to original PU reweighting
60 if ( !doPUreweighting ) cutWeight = weightbackup;
61
62 // MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
63 // DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
64 dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
65 result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
66 dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
67 result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
68 delete tempcan;
69 }
70
71 void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
72
73 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
74
75 TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
76 THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
77 TH1F *datahistoOSOF = allsamples.Draw("datahistoOSOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
78
79 if(logscale) ckin->SetLogy(1);
80 datahistoOSSF->SetMarkerSize(DataMarkerSize);
81 datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
82 datahistoOSSF->GetXaxis()->CenterTitle();
83 datahistoOSSF->GetYaxis()->SetTitle("events");
84 datahistoOSSF->GetYaxis()->CenterTitle();
85 datahistoOSOF->SetMarkerSize(DataMarkerSize);
86 datahistoOSSF->SetMarkerSize(DataMarkerSize);
87 datahistoOSSF->Draw();
88
89 mcstackOSSF.Draw("same");
90 datahistoOSSF->Draw("same");
91
92 datahistoOSOF->SetMarkerColor(TColor::GetColor("#FE642E"));
93 datahistoOSOF->SetLineColor(kRed);
94 datahistoOSOF->SetMarkerStyle(21);
95 datahistoOSOF->Draw("same");
96
97 // Try to re-arrange legend...
98 TLegend *bgleg = allsamples.allbglegend("",datahistoOSSF);
99 TLegend *kinleg = make_legend();
100 kinleg->AddEntry(datahistoOSSF,"SF (data)","p");
101 kinleg->AddEntry(datahistoOSOF,"OF (data)","p");
102 TIter next(bgleg->GetListOfPrimitives());
103 TObject* obj;
104 // Copy the nice bkgd legend skipping the "data"
105 while ( obj = next() )
106 if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
107 kinleg->GetListOfPrimitives()->Add(obj);
108
109 kinleg->Draw();
110 CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
111
112 delete datahistoOSOF;
113 delete datahistoOSSF;
114 delete ckin;
115 }
116
117
118 void draw_ratio_plot(TH1* hdata, THStack& hmc, float ymin=0.5, float ymax=1.5) {
119
120 // Make a histogram from stack
121 TIter next(hmc.GetHists());
122 TObject* obj;
123 TH1* hratio = NULL;
124 while ( obj = next() ) {
125 if ( !hratio ) {
126 hratio = (TH1*)obj->Clone();
127 hratio->SetName("hratio");
128 } else hratio->Add( (TH1*)obj );
129 }
130 hratio->Divide(hdata);
131 hratio->SetMaximum(ymax);
132 hratio->SetMinimum(ymin);
133 hratio->SetMarkerStyle(2);
134 hratio->SetLineWidth(1);
135 hratio->GetYaxis()->SetLabelSize(0.08);
136 hratio->GetXaxis()->SetLabelSize(0.0);
137
138 TPad* rpad = new TPad("rpad","",0.15,0.73,0.4,0.88);
139 rpad->SetTopMargin(0.0);
140 rpad->SetBottomMargin(0.0);
141 rpad->SetRightMargin(0.0);
142 rpad->Draw();
143 rpad->cd();
144 // hratio->GetXaxis()->SetNdivisions(0);
145 hratio->GetYaxis()->SetNdivisions(502,false);
146 hratio->Draw("e1x0");
147
148 TF1* oneline = new TF1("","1.0",0,1000);
149 oneline->SetLineColor(kBlue);
150 oneline->SetLineStyle(1);
151 oneline->SetLineWidth(1);
152 oneline->Draw("same");
153 }
154
155 float lastrange_min=0;
156 float lastrange_max=0;
157
158 void make_kin_plot(string variable, string addcut, int nbins, float min, float max, bool logscale,
159 string xlabel, string filename, bool isPF=true, bool plotratio=true, bool loadlastminmax=false ) {
160 // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
161 TCut ibasiccut=basiccut;
162 bool draw_separation_lines=false;
163
164 if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
165
166 if(addcut != "") ibasiccut = ibasiccut && addcut.c_str();
167
168 //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
169 if(isPF) {
170 if(variable=="mll") variable="pfmll[0]";
171 if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
172 if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
173 if(variable=="pt") variable="pfpt[0]";
174 if(variable=="pt1") variable="pfpt1[0]";
175 if(variable=="pt2") variable="pfpt2[0]";
176 if(variable=="eta1") variable="pfeta1[0]";
177 if(variable=="jzb[1]") variable="pfjzb[0]";
178 //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
179 }
180
181 //Step 2: Refine the cut
182 TCut cut;
183 cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
184 if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
185 if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
186 if(filename=="mll") {
187 cut=cutOSSF&&cutnJets&&ibasiccut;
188 draw_separation_lines=true;
189 }
190 if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
191 if(filename=="mll_osof") {
192 cut=cutOSOF&&cutnJets&&ibasiccut;
193 draw_separation_lines=true;
194 }
195 if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
196 if(filename=="mll_aboveJZB100") cut=cutOSSF&&cutnJets&&ibasiccut;
197 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
198 if(filename=="mll_inclusive_osof") cut=cutOSOF;
199 if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
200 if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
201 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
202 if(filename=="pfJetGoodPt_0") cut=cutOSSF&&cutmass&&ibasiccut&&cutnJets;
203
204 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
205 ckin->SetLogy(logscale);
206 TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
207 datahisto->SetMarkerSize(DataMarkerSize);
208 THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
209 if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
210 if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
211 if(filename=="mll_inclusive") datahisto->SetMinimum(1);
212 if(filename=="mll_osof") datahisto->SetMaximum(10*datahisto->GetMaximum());
213 if(filename=="mll_osof") datahisto->SetMinimum(9);
214
215 datahisto->SetMaximum(5.3*datahisto->GetMaximum());
216 datahisto->Draw("e1");
217 ckin->Update();
218 if(loadlastminmax) {
219 datahisto->SetMinimum(lastrange_min);
220 datahisto->SetMaximum(lastrange_max);
221 if(logscale) {
222 datahisto->SetMinimum(pow(10,lastrange_min));
223 datahisto->SetMaximum(pow(10,lastrange_max));
224 }
225 }
226
227 mcstack.Draw("same");
228 datahisto->Draw("same,e1");
229 TLegend *kinleg = allsamples.allbglegend();
230 kinleg->Draw();
231 if(filename=="mll_osof") {
232 kinleg->SetHeader("Opposite flavor");
233 kinleg->SetX1(0.58);
234 }
235 if(filename=="mll") {
236 kinleg->SetHeader("Same flavor");
237 kinleg->SetX1(0.58);
238 }
239 TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
240 write_cut->Draw();
241 TText* write_variable = write_text(0.99,0.01,variable);
242 write_variable->SetTextAlign(31);
243 write_variable->SetTextSize(0.02);
244
245 TLine *lowerboundary;
246 TLine *upperboundary;
247
248 if(RestrictToMassPeak&&draw_separation_lines) {
249 Color_t linecolor=kBlue;
250 float linemin=pow(10,ckin->GetUymin());
251 if(filename=="mll_osof") linemin=pow(10,lastrange_min);
252 lowerboundary = new TLine(71,linemin,71,datahisto->GetMaximum());
253 upperboundary = new TLine(111,linemin,111,datahisto->GetMaximum());
254 lowerboundary->SetLineColor(linecolor);
255 lowerboundary->SetLineStyle(2);
256 upperboundary->SetLineColor(linecolor);
257 upperboundary->SetLineStyle(2);
258 }
259
260 lastrange_min=ckin->GetUymin();
261 lastrange_max=ckin->GetUymax();
262
263
264 if ( plotratio ) {
265 TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
266 kinpad->cd();
267 kinpad->SetLogy(logscale);
268 datahisto->Draw("e1");
269 mcstack.Draw("same");
270 datahisto->Draw("same,e1");
271 datahisto->Draw("same,axis");
272 if(RestrictToMassPeak&&draw_separation_lines) {
273 lowerboundary->Draw("same");
274 upperboundary->Draw("same");
275 }
276
277 kinleg->Draw();
278 write_cut->Draw();
279 DrawPrelim();
280 string saveas="kin/"+filename;
281 if(isPF) saveas="kin/"+filename+"__PF";
282 save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
283 // if(isPF) CompleteSave(with_ratio,"kin/"+filename+"__PF_withratio");
284 // else CompleteSave(with_ratio,"kin/"+filename+"_withratio");
285 // delete with_ratio;
286 } else {
287 if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
288 else CompleteSave(ckin,"kin/"+filename);
289 }
290 datahisto->Delete();
291 delete ckin;
292 }
293
294
295 void make_JES_plot() {
296
297 int nbins=10;
298 float min=-0.5;
299 float max = 9.5;
300 bool logscale=true;
301 string xlabel="nJets";
302 TCut cut=cutmass&&cutOSSF&&basiccut;
303
304 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
305 ckin->SetLogy(logscale);
306 TH1F *datahisto = allsamples.Draw("datahisto","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,data,luminosity);
307 datahisto->SetMarkerSize(DataMarkerSize);
308 THStack mcstack = allsamples.DrawStack("mcstack","pfJetGoodNum",nbins,min,max, xlabel, "events",cut,mc,luminosity);
309 TH1F *JESup = allsamples.Draw("JESup","pfJetGoodNum315",nbins,min,max, xlabel, "events",cut,mc,luminosity);
310 TH1F *JESdn = allsamples.Draw("JESdn","pfJetGoodNum285",nbins,min,max, xlabel, "events",cut,mc,luminosity);
311
312 datahisto->SetMinimum(1);
313 datahisto->SetMaximum(5.3*datahisto->GetMaximum()); // in line with kinematic plots style
314
315 float xs[nbins],ys[nbins],exs[nbins],eys[nbins];
316 for(int i=1;i<JESup->GetNbinsX();i++) {
317 float up=JESup->GetBinContent(i);
318 float dn=JESdn->GetBinContent(i);
319 xs[i]=JESup->GetBinCenter(i);
320 ys[i]=0.5*(up+dn);
321 exs[i]=0.5*JESup->GetBinWidth(i);
322 eys[i]=0.5*TMath::Abs(up-dn);
323 }
324
325 TGraphAsymmErrors *JESunc = new TGraphAsymmErrors(nbins, xs,ys,exs,exs,eys,eys);
326 JESunc->SetFillColor(TColor::GetColor("#00ADE1"));
327 JESunc->SetFillStyle(3002);
328 datahisto->Draw("e1");
329 mcstack.Draw("same");
330 JESunc->Draw("2");
331 datahisto->Draw("same,e1");
332 TLegend *kinleg = allsamples.allbglegend();
333 kinleg->AddEntry(JESunc,"JES uncertainty","f");
334 kinleg->Draw();
335 CompleteSave(ckin,"Systematics/JES");
336 datahisto->Delete();
337 delete ckin;
338
339 }
340
341 void do_kinematic_plots(string mcjzb, string datajzb, bool doPF=false)
342 {
343 bool dolog=true;
344 bool nolog=false;
345 if(doPF) write_warning(__FUNCTION__,"Please use caution when trying to produce PF plots; not all versions of the JZB trees have these variables!");
346 float mll_low=40;
347 if(PlottingSetup::RestrictToMassPeak) mll_low=55;
348 make_kin_plot("mll","",(int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]","mll",doPF,true);
349 make_kin_plot("mll","",(int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]","mll_osof",doPF,true,true);
350 make_kin_plot("mll","",(int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]","mll_ee",doPF,true);
351 make_kin_plot("mll","",(int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]","mll_mm",doPF,true);
352 make_kin_plot("mll","",(int)((160-mll_low)),mll_low,160,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
353 make_kin_plot("mll","",(int)((160-mll_low)),mll_low,160,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
354 make_kin_plot("mll","",(int)((160-mll_low)),mll_low,160,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
355 make_kin_plot("mll","",(int)((160-mll_low)),mll_low,160,dolog,"m_{ll} [GeV]","mll_inclusive_osof",doPF,true);
356 make_kin_plot("mll","",(int)((350-mll_low)),mll_low,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
357 make_kin_plot("jetpt[0]","",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
358 make_kin_plot("jeteta[0]","",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
359 make_kin_plot("pt","",50,0,400,dolog,"Z p_{T} [GeV]","Zpt",doPF);
360 make_kin_plot("pt1","",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
361 make_kin_plot("pt2","",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
362 make_kin_plot("eta1","",40,-5,5,nolog,"#eta_{l}","eta",doPF);
363 make_kin_plot("jzb[1]","",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
364 make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets",doPF);
365 make_kin_plot("pfJetGoodNum","",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
366 if(!doPF) make_special_mll_plot((int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]");
367 stringstream jzbcut;
368 jzbcut << "((is_data&&("<<datajzb<<")>100)||(!is_data&&("<<mcjzb<<")>100))";
369 make_kin_plot("mll",jzbcut.str(),(int)((160-mll_low)/5),mll_low,160,dolog,"m_{ll} [GeV]","mll_aboveJZB100",doPF,true);
370 }
371
372 void make_comp_plot( string var, string xlabel, string filename, float jzbcut, string mcjzb, string datajzb,
373 int nbins, float xmin, float xmax, bool log,
374 float ymin=0, float ymax=0, bool leftJustified=false ) {
375 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- WATCH OUT: the argument in the function changed!
376
377 TCut weightbackup=cutWeight;//backing up the correct weight (restoring below!)
378 if(weightbackup==TCut("1.0")||weightbackup==TCut("1")) write_warning(__FUNCTION__,"WATCH OUT THE WEIGHT HAS POSSIBLY NOT BEEN RESET!!!! PLEASE CHANGE LINE "+any2string(__LINE__));
379 if(var=="numVtx") cutWeight=TCut("1.0");
380 TCut jzbData[]= { TCut(TString(datajzb+">"+any2string(jzbcut))),TCut(TString(datajzb+"<-"+any2string(jzbcut))) };
381 TCut jzbMC[] = { TCut(TString(mcjzb+">"+any2string(jzbcut))),TCut(TString(mcjzb+"<-"+any2string(jzbcut))) };
382
383 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- below: the next ~20 lines changed!
384 int nRegions=4;
385 if(!PlottingSetup::RestrictToMassPeak) {
386 nRegions=2;
387 }
388
389 string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
390 TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass, cutOSOF&&cutnJets&&cutmass,
391 cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
392
393 //find ymax
394 TH1F *Refdatahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[0]&&jzbData[0],data,luminosity);
395 ymax=int((Refdatahisto->GetMaximum()+2*TMath::Sqrt(Refdatahisto->GetMaximum()))*1.2+0.5);
396 delete Refdatahisto;
397
398 for ( int iregion=0; iregion<nRegions; ++iregion )
399 for ( int ijzb=0; ijzb<2; ++ijzb ) {
400 TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
401 ccomp->SetLogy(log);
402 TH1F *datahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
403 TH1F *lm4histo = signalsamples.Draw("lm4histo", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity,signalsamples.FindSample("LM4"));
404 THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb], mc, luminosity);
405 datahisto->SetMarkerSize(DataMarkerSize);
406 if (ymax>ymin) datahisto->SetMaximum(ymax);
407 lm4histo->SetLineStyle(2);
408 datahisto->Draw("e1");
409 mcstack.Draw("same");
410 datahisto->Draw("same,e1");
411 // lm4histo->Draw("hist,same");
412 TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
413 if ( leftJustified ) {
414 Float_t w = kinleg->GetX2()-kinleg->GetX1();
415 kinleg->SetX1(0.2);
416 kinleg->SetX2(0.2+w);
417 }
418 // kinleg->AddEntry(lm4histo,"LM4","l");
419 kinleg->Draw();
420 TText* write_variable = write_text(0.99,0.01,var);
421 write_variable->SetTextAlign(31);
422 write_variable->SetTextSize(0.02);
423 ccomp->RedrawAxis();
424 CompleteSave(ccomp,"compare/JZBcut_at_"+any2string(jzbcut)+"/"+filename+"/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
425 delete datahisto;
426 delete ccomp;
427 delete lm4histo;
428 }
429 cutWeight=weightbackup;
430 }
431
432
433 void region_comparison_plots(string mcjzb, string datajzb, vector<float> jzb_cuts) {
434 dout << "Creating comparison plots for signal and control regions" << endl;
435 // Compare a few quantities in the signal region and all 7 control regions
436
437 switch_overunderflow(true); // switching overflow/underflow bins on
438
439
440 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- the arguments changed
441 for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
442 float jzbcut=jzb_cuts[ijzb]; // Comparison plots are done for this JZB cut
443 float mll_low=50;float mll_high=170;
444 if(!PlottingSetup::RestrictToMassPeak) {
445 mll_high=200;
446 mll_low=50;
447 }
448 make_comp_plot("mll","m_{ll} [GeV]","mll",jzbcut,mcjzb,datajzb,30,mll_low,mll_high,false,0,16.);
449 make_comp_plot("met[4]","pfMET [GeV]","pfmet",jzbcut,mcjzb,datajzb,18,0,360,false,0,16.);
450 make_comp_plot("pfJetGoodNum","#(jets)","njets",jzbcut,mcjzb,datajzb,10,0,10, false,0,35.);
451 make_comp_plot("pt","Z p_{T} [GeV]","Zpt",jzbcut,mcjzb,datajzb,26,0,525,false,0.,21.);
452 make_comp_plot("numVtx","#(prim. vertices)","nvtx",jzbcut,mcjzb,datajzb,20,0.,20.,false,0,16.);
453 make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
454 make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",jzbcut,mcjzb,datajzb,10,0.,3.1415,false,0,16.,true);
455 }
456
457 switch_overunderflow(false); // switching overflow/underflow bins off
458 }
459
460
461
462 void do_kinematic_PF_plots(string mcjzb, string datajzb)
463 {
464 do_kinematic_plots(mcjzb,datajzb,true);
465 }
466
467 void signal_bg_comparison()
468 {
469 TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
470 can->SetLogy(1);
471
472 int sbg_nbins=130;
473 float sbg_min=-500; //-110;
474 float sbg_max=800; //jzbHigh;
475
476 float simulatedlumi=luminosity;//in pb please - adjust to your likings
477
478 TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("DYJetsToLL"));
479 TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("LM4"));
480 TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,allsamples.FindSample("TTJets"));
481
482 JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
483 JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
484 JZBplotZJETs->SetLineColor(kBlack);
485 JZBplotLM4->SetLineStyle(2);
486 JZBplotZJETs->SetMaximum(JZBplotZJETs->GetMaximum()*5);
487 JZBplotZJETs->SetMinimum(1);
488
489 JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
490 JZBplotTtbar->SetMinimum(0.01);
491 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
492 JZBplotTtbar->DrawClone("histo");
493 JZBplotZJETs->Draw("histo,same");
494 JZBplotTtbar->SetFillColor(0);
495 JZBplotTtbar->DrawClone("histo,same");
496 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
497 JZBplotLM4->Draw("histo,same");
498
499
500 TLegend *signal_bg_comparison_leg2 = make_legend("",0.55,0.75,false);
501 signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
502 signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
503 signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
504 signal_bg_comparison_leg2->Draw();
505 DrawMCPrelim(simulatedlumi);
506 CompleteSave(can,"jzb_bg_vs_signal_distribution");
507
508 // Define illustrative set of SMS points
509 TCut kSMS1("MassGlu==250&&MassLSP==75");
510 TCut kSMS2("MassGlu==800&&MassLSP==200");
511 TCut kSMS3("MassGlu==1050&&MassLSP==850");
512 TCut kSMS4("MassGlu==1200&&MassLSP==100");
513
514 //If the scan samples haven't been loaded yet, this is a good point to load them (all of them!)
515 if((scansample.collection).size()<2) define_SMS_sample(false, allsamples, signalsamples, scansample, true); // loading ALL zones for the scans, not only the basic one.
516
517
518 TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS1,mc,simulatedlumi,scansample.FindSample("t"));
519 JZBplotSMS1->Scale(JZBplotLM4->Integral()/JZBplotSMS1->Integral());
520
521 TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS2,mc,simulatedlumi,scansample.FindSample("t"));
522 JZBplotSMS2->Scale(JZBplotLM4->Integral()/JZBplotSMS2->Integral());
523
524 TH1F *JZBplotSMS3 = scansample.Draw("JZBplotSMS3",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS3,mc,simulatedlumi,scansample.FindSample("t"));
525 JZBplotSMS3->Scale(JZBplotLM4->Integral()/JZBplotSMS3->Integral());
526
527 TH1F *JZBplotSMS4 = scansample.Draw("JZBplotSMS4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&kSMS4,mc,simulatedlumi,scansample.FindSample("t"));
528 JZBplotSMS4->Scale(JZBplotLM4->Integral()/JZBplotSMS4->Integral());
529
530 // Draw all plots overlaid
531 JZBplotTtbar->SetMaximum(JZBplotZJETs->GetMaximum());
532 JZBplotTtbar->SetMinimum(0.01);
533 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
534 JZBplotTtbar->DrawClone("histo");
535 JZBplotZJETs->Draw("histo,same");
536 JZBplotTtbar->SetFillColor(0);
537 JZBplotTtbar->DrawClone("histo,same");
538 JZBplotTtbar->SetFillColor(allsamples.GetColor("TTJets"));
539
540 JZBplotSMS1->SetLineColor(kRed+1);
541 JZBplotSMS2->SetLineColor(kBlue+1);
542 JZBplotSMS3->SetLineColor(kRed+1);
543 JZBplotSMS4->SetLineColor(kBlue+1);
544 JZBplotSMS3->SetLineStyle(2);
545 JZBplotSMS4->SetLineStyle(2);
546
547 JZBplotSMS1->Draw("histo,same");
548 JZBplotSMS2->Draw("histo,same");
549 JZBplotSMS3->Draw("histo,same");
550 JZBplotSMS4->Draw("histo,same");
551 JZBplotLM4->SetLineColor(kGreen);JZBplotLM4->Draw("histo,same");
552 TLegend *signal_bg_comparison_leg6 = make_legend("",0.55,0.55,false);
553 signal_bg_comparison_leg6->AddEntry(JZBplotZJETs,"Z+Jets","f");
554 signal_bg_comparison_leg6->AddEntry(JZBplotTtbar,"t#bar{t}","f");
555 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
556 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"SMS parameters","");
557 signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"(250,75) [GeV]","f");
558 signal_bg_comparison_leg6->AddEntry(JZBplotSMS2,"(800,200) [GeV]","f");
559 signal_bg_comparison_leg6->AddEntry(JZBplotSMS3,"(1050,850) [GeV]","f");
560 signal_bg_comparison_leg6->AddEntry(JZBplotSMS4,"(1200,100) [GeV]","f");
561 signal_bg_comparison_leg6->AddEntry(JZBplotLM4,"LM4","f");
562 signal_bg_comparison_leg6->Draw();
563 DrawMCPrelim(simulatedlumi);
564 CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__summary");
565
566 while((scansample.collection).size() > 1) scansample.RemoveLastSample();
567
568 }
569
570 vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
571 TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
572 BpredFunc->SetParameter(0,histo->GetBinContent(1));
573 if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
574 BpredFunc->SetParameter(1,0.);
575 if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
576 else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
577 if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
578 BpredFunc->SetParameter(3,1.8);
579 BpredFunc->SetParameter(4,2.5);
580 histo->Fit(BpredFunc,"QN0");
581 BpredFunc->SetLineColor(kBlue);
582
583 TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
584 TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
585
586 BpredFuncP->SetParameters(BpredFunc->GetParameters());
587 BpredFuncP->SetLineColor(kBlue);
588 BpredFuncP->SetLineStyle(2);
589
590 BpredFuncN->SetParameters(BpredFunc->GetParameters());
591 BpredFuncN->SetLineColor(kBlue);
592 BpredFuncN->SetLineStyle(2);
593
594 vector<TF1*> functions;
595 functions.push_back(BpredFuncN);
596 functions.push_back(BpredFunc);
597 functions.push_back(BpredFuncP);
598 return functions;
599 }
600
601
602 TF1* do_logpar_fit_to_plot(TH1F *osof) {
603 TCanvas *logpar_fit_can = new TCanvas("logpar_fit_can","Fit canvas for LogPar");
604 TF1 *logparfunc = new TF1("logparfunc",LogParabola,0,300,3);
605 TF1 *logparfunc2 = new TF1("logparfunc2",LogParabola,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
606 TF1 *logparfuncN = new TF1("logparfuncN",LogParabolaN,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
607 TF1 *logparfuncP = new TF1("logparfuncP",LogParabolaP,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
608 osof->SetMinimum(0);
609 osof->Fit(logparfunc,"QR");
610 osof->Draw();
611 logparfunc->SetLineWidth(2);
612 logparfunc2->SetParameters(logparfunc->GetParameters());
613 logparfuncN->SetParameters(logparfunc->GetParameters());
614 logparfuncP->SetParameters(logparfunc->GetParameters());
615 stringstream fitinfo;
616 fitinfo << "#Chi^{2} / NDF : " << logparfunc->GetChisquare() << " / " << logparfunc->GetNDF();
617 TText *writefitinfo = write_text(0.8,0.8,fitinfo.str());
618 writefitinfo->SetTextSize(0.03);
619 DrawPrelim();
620 writefitinfo->Draw();
621 logparfunc->Draw("same");
622 logparfunc2->Draw("same");
623 logparfuncN->SetLineStyle(2);
624 logparfuncP->SetLineStyle(2);
625 logparfuncN->Draw("same");
626 logparfuncP->Draw("same");
627 CompleteSave(logpar_fit_can,"MakingOfBpredFunction/Bpred_Data_LogPar_Fit_To_TTbarPred");
628 delete logpar_fit_can;
629 return logparfunc2;
630 }
631
632 vector<TF1*> do_extended_fit_to_plot(TH1F *prediction, TH1F *Tprediction, TH1F *ossf, TH1F *osof,int isdata) {
633 /* there are mainly two background contributions: Z+Jets (a) and ttbar (b). So:
634 a) The case is clear - we take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it. We then extract the CB parameters.
635 b) For ttbar, we use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola. We then extract the LP parameters.
636 Once we have these two components, we use the combined parameters to get the final function and we're done.
637 */
638 //Step 1: take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it
639 TH1F *step1cb = (TH1F*)ossf->Clone("step1cb");
640 step1cb->Add(osof,-1);
641 vector<TF1*> functions = do_cb_fit_to_plot(step1cb,PlottingSetup::JZBPeakWidthData);
642 TF1 *zjetscrystalball = functions[1];
643
644 //Step 2: use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola
645 // TH1F *ttbarprediction=(TH1F*)prediction->Clone("ttbarprediction");
646 // ttbarprediction->Add(ossf,-1);//without the Z+Jets estimate, this is really just the ttbar estimate!
647 // the line above is not necessary anymore as we're now looking at a prediction without Z+Jets, and not multiplied with (1.0/3)
648 TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
649 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
650 if(PlottingSetup::RestrictToMassPeak) ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
651
652
653 TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
654 TF1 *ttbarlogparN = new TF1("ttbarlogparN",LogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
655
656 //and now fuse the two!
657 TF1 *kmlp = new TF1("kmlp", CrystalBallPlusLogParabola, 0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
658 TF1 *kmlpP= new TF1("kmlpP",CrystalBallPlusLogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
659 TF1 *kmlpN= new TF1("kmlpN",CrystalBallPlusLogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
660 double kmlp_pars[10];
661 for(int i=0;i<5;i++) kmlp_pars[i]=zjetscrystalball->GetParameter(i);
662 for(int i=0;i<3;i++) kmlp_pars[5+i]=ttbarlogpar->GetParameter(i);
663 ttbarlogparP->SetParameters(ttbarlogpar->GetParameters());
664 ttbarlogparN->SetParameters(ttbarlogpar->GetParameters());
665 kmlp->SetParameters(kmlp_pars);
666 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
667 /*
668 if you want to start from scratch (without the partial fitting and only fitting the whole thing, some good start values could be :
669 */
670 kmlp_pars[0]=kmlp->GetParameter(0);
671 kmlp_pars[1]=3.6198;
672 kmlp_pars[2]=16.4664;
673 kmlp_pars[3]=1.92253;
674 kmlp_pars[4]=3.56099;
675 kmlp_pars[5]=5.83;
676 kmlp_pars[6]=0.000757479;
677 kmlp_pars[7]=95.6157;
678 kmlp_pars[8]=0;
679 kmlp_pars[9]=0;
680 kmlp->SetParameters(kmlp_pars);
681 /**/
682 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
683
684 kmlpP->SetParameters(kmlp->GetParameters());
685 kmlpN->SetParameters(kmlp->GetParameters());
686
687 // now that we're done, let's save all of this so we can have a look at it afterwards.
688 TCanvas *can = new TCanvas("can","Prediction Fit Canvas");
689 can->SetLogy(1);
690 prediction->SetMarkerColor(kRed);
691 prediction->Draw();
692
693 kmlp->SetLineColor(TColor::GetColor("#04B404"));
694 kmlpP->SetLineColor(TColor::GetColor("#04B404"));
695 kmlpN->SetLineColor(TColor::GetColor("#04B404"));
696 kmlp->Draw("same");
697 kmlpN->SetLineStyle(2);
698 kmlpP->SetLineStyle(2);
699 kmlpN->Draw("same");
700 kmlpP->Draw("same");
701
702 ttbarlogpar->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
703 ttbarlogpar->Draw("same");
704 ttbarlogparP->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
705 ttbarlogparN->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
706 ttbarlogparP->SetLineStyle(2);
707 ttbarlogparN->SetLineStyle(2);
708 ttbarlogparP->Draw("same");
709 ttbarlogparN->Draw("same");
710
711 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
712
713 TLegend *analyticalBpredLEG = make_legend("",0.5,0.55);
714 analyticalBpredLEG->AddEntry(prediction,"predicted","p");
715 analyticalBpredLEG->AddEntry(functions[1],"Crystal Ball fit","l");
716 analyticalBpredLEG->AddEntry(functions[0],"1#sigma Crystal Ball fit","l");
717 analyticalBpredLEG->AddEntry(ttbarlogparN,"TTbar fit","l");
718 analyticalBpredLEG->AddEntry(ttbarlogpar,"1#sigma TTbar fit","l");
719 analyticalBpredLEG->AddEntry(kmlp,"Combined function","l");
720 analyticalBpredLEG->AddEntry(kmlpN,"1#sigma combined function","l");
721 analyticalBpredLEG->Draw("same");
722
723 if(isdata==0) CompleteSave(can,"MakingOfBpredFunction/Bpred_MC_Analytical_Function_Composition");
724 if(isdata==1) CompleteSave(can,"MakingOfBpredFunction/Bpred_data_Analytical_Function_Composition");
725 if(isdata==2) CompleteSave(can,"MakingOfBpredFunction/Bpred_MCBnS_Analytical_Function_Composition");
726 delete can;
727
728 //and finally: prep return functions
729 vector<TF1*> return_functions;
730 return_functions.push_back(kmlpN);
731 return_functions.push_back(kmlp);
732 return_functions.push_back(kmlpP);
733
734 return_functions.push_back(ttbarlogparN);
735 return_functions.push_back(ttbarlogpar);
736 return_functions.push_back(ttbarlogparP);
737
738 return_functions.push_back(functions[0]);
739 return_functions.push_back(functions[1]);
740 return_functions.push_back(functions[2]);
741
742 return return_functions;
743 }
744
745 void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, int use_data, bool overlay_signal = false )
746 {
747 bool is_data=false;
748 bool use_signal=false;
749 if(use_data==1) is_data=true;
750 if(use_data==2) use_signal=true;
751 int nbins=50;//100;
752 if(is_data) nbins=50;
753 float low=0;
754 float hi=500;
755 TH1F *blankback = new TH1F("blankback","blankback",int(high/10),0,high);
756 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
757 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
758 TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
759 TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
760 blankback->GetXaxis()->SetTitle(RcorrJZBeemm->GetXaxis()->GetTitle());
761 blankback->GetYaxis()->SetTitle(RcorrJZBeemm->GetYaxis()->GetTitle());
762 blankback->GetXaxis()->CenterTitle();
763 blankback->GetYaxis()->CenterTitle();
764
765 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
766 TH1F *RcorrJZBSBem;
767 TH1F *LcorrJZBSBem;
768 TH1F *RcorrJZBSBeemm;
769 TH1F *LcorrJZBSBeemm;
770
771 TH1F *RcorrJZBeemmNoS;
772
773 //these are for the ratio
774 TH1F *JRcorrJZBeemm = allsamples.Draw("JRcorrJZBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
775 TH1F *JLcorrJZBeemm = allsamples.Draw("JLcorrJZBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
776 TH1F *JRcorrJZBem = allsamples.Draw("JRcorrJZBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
777 TH1F *JLcorrJZBem = allsamples.Draw("JLcorrJZBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
778
779 TH1F *JRcorrJZBSBem;
780 TH1F *JLcorrJZBSBem;
781 TH1F *JRcorrJZBSBeemm;
782 TH1F *JLcorrJZBSBeemm;
783
784 if(use_data==2 || overlay_signal) RcorrJZBeemmNoS = allsamples.Draw("RcorrJZBeemmNoS",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,false);
785
786
787 if(PlottingSetup::RestrictToMassPeak) {
788 RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
789 LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
790 RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
791 LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
792
793 //these are for the ratio
794 JRcorrJZBSBem = allsamples.Draw("JRcorrJZBSBem",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
795 JLcorrJZBSBem = allsamples.Draw("JLcorrJZBSBem",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity,use_signal);
796 JRcorrJZBSBeemm = allsamples.Draw("JRcorrJZBSBeemm",jzb.c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
797 JLcorrJZBSBeemm = allsamples.Draw("JLcorrJZBSBeemm",("-"+jzb).c_str(),PlottingSetup::global_ratio_binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity,use_signal);
798
799 }
800
801 TH1F *lm4RcorrJZBeemm;
802 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"));
803
804 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed.
805
806 TH1F *Zjetspred = (TH1F*)LcorrJZBeemm->Clone("Zjetspred");
807 TH1F *TTbarpred = (TH1F*)RcorrJZBem->Clone("TTbarpred");
808
809 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
810 TH1F *JBpred = (TH1F*)JLcorrJZBeemm->Clone("Bpred");
811 if(PlottingSetup::RestrictToMassPeak) {
812 Bpred->Add(RcorrJZBem,1.0/3.);
813 Bpred->Add(LcorrJZBem,-1.0/3.);
814 Bpred->Add(RcorrJZBSBem,1.0/3.);
815 Bpred->Add(LcorrJZBSBem,-1.0/3.);
816 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
817 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
818
819 TTbarpred->Scale(1.0/3);
820 Zjetspred->Add(LcorrJZBem,-1.0/3.);
821 Zjetspred->Add(LcorrJZBSBem,-1.0/3.);
822 TTbarpred->Add(RcorrJZBSBem,1.0/3.);
823 Zjetspred->Add(LcorrJZBSBeemm,-1.0/3.);
824 TTbarpred->Add(RcorrJZBSBeemm,1.0/3.);
825
826 //these are for the ratio
827 JBpred->Add(JRcorrJZBem,1.0/3.);
828 JBpred->Add(JLcorrJZBem,-1.0/3.);
829 JBpred->Add(JRcorrJZBSBem,1.0/3.);
830 JBpred->Add(JLcorrJZBSBem,-1.0/3.);
831 JBpred->Add(JRcorrJZBSBeemm,1.0/3.);
832 JBpred->Add(JLcorrJZBSBeemm,-1.0/3.);
833 } else {
834 Bpred->Add(RcorrJZBem,1.0);
835 Bpred->Add(LcorrJZBem,-1.0);
836
837 Zjetspred->Add(LcorrJZBem,-1.0);
838
839 //these are for the ratio
840 JBpred->Add(JRcorrJZBem,1.0);
841 JBpred->Add(JLcorrJZBem,-1.0);
842 }
843
844
845
846 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak ---- prediction changed
847 TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
848 Tpred->Add(LcorrJZBem,-1.0);
849 if(PlottingSetup::RestrictToMassPeak) {
850 Tpred->Add(RcorrJZBSBem,1.0);
851 Tpred->Add(LcorrJZBSBem,-1.0);
852 Tpred->Add(RcorrJZBSBeemm,1.0);
853 Tpred->Add(LcorrJZBSBeemm,-1.0);
854 }
855
856 globalcanvas->cd();
857 globalcanvas->SetLogy(1);
858
859 RcorrJZBeemm->SetMarkerStyle(20);
860 RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
861 RcorrJZBeemm->SetMinimum(0.1);
862
863 Bpred->SetLineColor(kRed);
864 Bpred->SetStats(0);
865
866 int versok=false;
867 if(gROOT->GetVersionInt()>=53000) versok=true;
868
869
870 if ( overlay_signal || use_data==2 ) lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
871 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
872
873 TLegend *legBpred = make_legend("",0.6,0.55);
874 TLegend *legBpred2 = make_legend("",0.6,0.55);
875
876
877 vector<TF1*> analytical_function;
878 TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
879 kinpad->cd();
880 kinpad->SetLogy(1);
881
882 string Bpredsaveas="Bpred_Data";
883 blankback->SetMaximum(5*RcorrJZBeemm->GetMaximum());
884 blankback->SetMinimum(0.1);
885 if(use_data!=1) blankback->SetMinimum(0.1);
886 blankback->Draw();
887 if(use_data==1)
888 {
889 analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
890 kinpad->cd();//necessary because the extended fit function creates its own canvas
891 RcorrJZBeemm->Draw("e1x0,same");
892
893 Bpred->Draw("hist,same");
894 analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
895 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
896 legBpred->AddEntry(RcorrJZBeemm,"observed","p");
897 legBpred->AddEntry(Bpred,"predicted","l");
898 legBpred->AddEntry(analytical_function[1],"predicted fit","l");
899 legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
900 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
901 legBpred->Draw();
902 DrawPrelim();
903
904 //this plot shows what the prediction is composed of
905 TCanvas *specialcanv = new TCanvas("specialcanv","specialcanv");
906 specialcanv->SetLogy(1);
907 Zjetspred->SetFillColor(kYellow);
908 Zjetspred->SetLineColor(kYellow);
909 TTbarpred->SetFillColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
910 TTbarpred->SetLineColor(allsamples.GetColor((allsamples.FindSample("TTJets"))[0]));
911 THStack predcomposition("predcomposition","prediction composition");
912 predcomposition.Add(TTbarpred);
913 predcomposition.Add(Zjetspred);
914 blankback->Draw();
915 RcorrJZBeemm->Draw("e1x0,same");
916 predcomposition.Draw("histo,same");//
917 Bpred->Draw("hist,same");
918 analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
919 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
920 legBpred->Draw();
921 DrawPrelim();
922 TLegend *specialleg = new TLegend(0.6,0.4,0.89,0.55);
923 specialleg->SetFillColor(kWhite);specialleg->SetLineColor(kWhite);
924 specialleg->AddEntry(Zjetspred,"Z+Jets prediction","f");
925 specialleg->AddEntry(TTbarpred,"t#bar{t} prediction","f");
926 specialleg->Draw("same");
927 CompleteSave(specialcanv,"Bpred_Data_____PredictionComposition");
928
929 THStack kostack = allsamples.DrawStack("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,!is_data, luminosity,use_signal);
930 blankback->Draw();
931 kostack.Draw("same");
932 Bpred->Draw("hist,same");
933 analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
934 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
935 legBpred->Draw();
936 DrawPrelim();
937 CompleteSave(specialcanv,"Bpred_Data_____PredictionCompositioninMC");
938
939 delete specialcanv;
940 delete specialleg;
941 delete Zjetspred;
942 delete TTbarpred;
943
944 kinpad->cd();
945 }
946 if(use_data==0) {
947 RcorrJZBeemm->Draw("e1x0,same");
948 Bpred->Draw("hist,same");
949 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
950 legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
951 legBpred->AddEntry(Bpred,"MC predicted","l");
952 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
953 if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
954 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
955 legBpred->Draw();
956 DrawMCPrelim();
957 Bpredsaveas="Bpred_MC";
958 // CompleteSave(globalcanvas,"Bpred_MC"); // done below in save_with_ratio
959 }
960 if(use_data==2) {
961 RcorrJZBeemm->Draw("e1x0,same");
962 Bpred->Draw("hist,same");
963 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
964 legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
965 legBpred->AddEntry(Bpred,"MC predicted","l");
966 legBpred2->AddEntry(RcorrJZBeemm,"MC observed","p");
967 legBpred2->AddEntry(Bpred,"MC predicted","l");
968 {
969 if(versok) legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
970 if(versok) legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18 --> now only allowed for root >=v5.30
971 legBpred->Draw();
972 DrawMCPrelim();
973 Bpredsaveas="Bpred_MCwithS";
974 // CompleteSave(globalcanvas,"Bpred_MCwithS"); // done below in save_with_ratio
975 }
976 {
977 RcorrJZBeemmNoS->SetLineStyle(2);
978 legBpred2->AddEntry(RcorrJZBeemmNoS,"MC B","l");
979 legBpred2->AddEntry(lm4RcorrJZBeemm,"MC S","l");
980 legBpred2->Draw();
981 RcorrJZBeemmNoS->SetLineColor(TColor::GetColor("#61210B"));
982 RcorrJZBeemmNoS->Draw("histo,same");
983 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
984 lm4RcorrJZBeemm->Draw("histo,same");
985 DrawMCPrelim();
986 Bpredsaveas="Bpred_MCwithS__plus";
987 // CompleteSave(globalcanvas,"Bpred_MCwithS__plus"); // done below in save_with_ratio
988 }
989 }
990
991
992 //3rd last argument: do special bpred ratio, 2nd last argument: extended range!, last: y-axis title
993 string ytitle("ratio");
994 if ( use_data==1 ) ytitle = "data/pred";
995 save_with_ratio(JRcorrJZBeemm,JBpred,kinpad,Bpredsaveas,true,use_data!=1,ytitle);
996
997
998 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
999 /// The part below is meaningless for the offpeak analysis (it's a comparison of the different estimates but there is but one estimate!)
1000 if(!PlottingSetup::RestrictToMassPeak) return;
1001 TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
1002 Bpredem->Add(RcorrJZBem);
1003 Bpredem->Add(LcorrJZBem,-1);
1004 TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
1005 BpredSBem->Add(RcorrJZBSBem);
1006 Bpred->Add(LcorrJZBSBem,-1);
1007 TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");
1008 BpredSBeemm->Add(RcorrJZBSBeemm);
1009 BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
1010 globalcanvas->cd();
1011 globalcanvas->SetLogy(1);
1012
1013 RcorrJZBeemm->SetMarkerStyle(20);
1014 RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
1015 blankback->Draw();
1016 RcorrJZBeemm->Draw("e1x0,same");
1017 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
1018
1019 Bpredem->SetLineColor(kRed+1);
1020 Bpredem->SetStats(0);
1021 Bpredem->Draw("hist,same");
1022
1023 BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
1024 BpredSBem->SetLineStyle(2);
1025 BpredSBem->Draw("hist,same");
1026
1027 BpredSBeemm->SetLineColor(kBlue+1);
1028 BpredSBeemm->SetLineStyle(3);
1029 BpredSBeemm->Draw("hist,same");
1030 RcorrJZBeemm->Draw("e1x0,same");//HAVE IT ON TOP!
1031
1032 TLegend *legBpredc = make_legend("",0.6,0.55);
1033 if(use_data==1)
1034 {
1035 legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
1036 legBpredc->AddEntry(Bpredem,"OFZP","l");
1037 legBpredc->AddEntry(BpredSBem,"OFSB","l");
1038 legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
1039 legBpredc->Draw();
1040 CompleteSave(globalcanvas,"Bpred_Data_comparison");
1041 }
1042 if(use_data==0) {
1043 legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1044 legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1045 legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1046 legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1047 legBpredc->Draw();
1048 CompleteSave(globalcanvas,"Bpred_MC_comparison");
1049 }
1050 if(use_data==2) {
1051 legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
1052 legBpredc->AddEntry(Bpredem,"MC OFZP","l");
1053 legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
1054 legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
1055 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
1056 legBpredc->Draw();
1057 CompleteSave(globalcanvas,"Bpred_MCwithS_comparison");
1058 }
1059 delete RcorrJZBeemm;
1060 delete LcorrJZBeemm;
1061 delete RcorrJZBem;
1062 delete LcorrJZBem;
1063
1064 delete JRcorrJZBeemm;
1065 delete JLcorrJZBeemm;
1066 delete JRcorrJZBem;
1067 delete JLcorrJZBem;
1068
1069 delete blankback;
1070
1071 if(PlottingSetup::RestrictToMassPeak) {
1072 delete RcorrJZBSBem;
1073 delete LcorrJZBSBem;
1074 delete RcorrJZBSBeemm;
1075 delete LcorrJZBSBeemm;
1076
1077 delete JRcorrJZBSBem;
1078 delete JLcorrJZBSBem;
1079 delete JRcorrJZBSBeemm;
1080 delete JLcorrJZBSBeemm;
1081 }
1082 if(overlay_signal || use_data==2) delete lm4RcorrJZBeemm;
1083 }
1084
1085 void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
1086 TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
1087 do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
1088 do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
1089 do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mcwithsignal,overlay_signal);
1090 }
1091
1092 void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
1093 bool do_data=0;
1094 bool dosignal=0;
1095 if(is_data==1) do_data=1;
1096 if(is_data==2) dosignal=1;
1097 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1098 TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1099 TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1100 TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1101
1102 TH1F *RcorrJZBSBem;
1103 TH1F *LcorrJZBSBem;
1104 TH1F *RcorrJZBSBeemm;
1105 TH1F *LcorrJZBSbeemm;
1106
1107 if(PlottingSetup::RestrictToMassPeak) {
1108 RcorrJZBSBem = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1109 LcorrJZBSBem = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
1110 RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1111 LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
1112 }
1113
1114
1115
1116
1117 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1118 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
1119 if(PlottingSetup::RestrictToMassPeak) {
1120 Bpred->Add(RcorrJZBem,1.0/3);
1121 Bpred->Add(LcorrJZBem,-1.0/3);
1122 Bpred->Add(RcorrJZBSBem,1.0/3);
1123 Bpred->Add(LcorrJZBSBem,-1.0/3);
1124 Bpred->Add(RcorrJZBSBeemm,1.0/3);
1125 Bpred->Add(LcorrJZBSbeemm,-1.0/3);
1126 } else {
1127 Bpred->Add(RcorrJZBem,1.0);
1128 Bpred->Add(LcorrJZBem,-1.0);
1129 }
1130
1131 can->cd();
1132 can->SetLogy(0);
1133 Bpred->SetLineColor(kRed);
1134 Bpred->SetStats(0);
1135 if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
1136 TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
1137 JZBratioforfitting->Divide(Bpred);
1138 TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
1139
1140
1141 JZBratio->SetTitle("");
1142 JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
1143 // if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
1144
1145 TF1 *pol0 = new TF1("pol0","[0]",0,1000);
1146 TF1 *pol0d = new TF1("pol0","[0]",0,1000);
1147 // straightline_fit->SetParameter(0,1);
1148 JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
1149 pol0d->SetParameter(0,pol0->GetParameter(0));
1150
1151 JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
1152 JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
1153 if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
1154 JZBratio->GetYaxis()->SetNdivisions(519);
1155 JZBratio->GetYaxis()->SetRangeUser(0.0,4.0);
1156 JZBratio->GetYaxis()->CenterTitle();
1157 JZBratio->GetXaxis()->CenterTitle();
1158 JZBratio->SetMarkerSize(DataMarkerSize);
1159 JZBratio->Draw("AP");
1160 /////----------------------------
1161 TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
1162 writeresult->SetFillStyle(4000);
1163 writeresult->SetFillColor(kWhite);
1164 writeresult->SetTextFont(42);
1165 writeresult->SetTextSize(0.03);
1166 writeresult->SetTextAlign(12);
1167 ostringstream jzb_agreement_data_text;
1168 jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) << pol0->GetParError(0);
1169 if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
1170 if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
1171 /* if(is_data) writeresult->AddText("Data closure test");
1172 else writeresult->AddText("MC closure test");
1173 */
1174 writeresult->AddText(jzb_agreement_data_text.str().c_str());
1175 // writeresult->Draw("same");
1176 // pol0d->Draw("same");
1177 TF1 *topline = new TF1("","1.5",0,1000);
1178 TF1 *bottomline = new TF1("","0.5",0,1000);
1179 topline->SetLineColor(kBlue);
1180 topline->SetLineStyle(2);
1181 bottomline->SetLineColor(kBlue);
1182 bottomline->SetLineStyle(2);
1183 // topline->Draw("same");
1184 // bottomline->Draw("same");
1185 TF1 *oneline = new TF1("","1.0",0,1000);
1186 oneline->SetLineColor(kBlue);
1187 oneline->SetLineStyle(1);
1188 oneline->Draw("same");
1189 TLegend *phony_leg = make_legend("ratio",0.6,0.55,false);//this line is just to have the default CMS Preliminary (...) on the canvas as well.
1190 if(is_data==1) DrawPrelim();
1191 else DrawMCPrelim();
1192 TLegend *leg = new TLegend(0.55,0.75,0.89,0.89);
1193 leg->SetTextFont(42);
1194 leg->SetTextSize(0.04);
1195 // if(is_data==1) leg->SetHeader("Ratio (data)");
1196 // else leg->SetHeader("Ratio (MC)");
1197
1198 TString MCtitle("MC ");
1199 if (is_data==1) MCtitle = "";
1200
1201 leg->SetFillStyle(4000);
1202 leg->SetFillColor(kWhite);
1203 leg->SetTextFont(42);
1204 // leg->AddEntry(topline,"+20\% sys envelope","l");
1205 leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
1206 leg->AddEntry(oneline,"ratio = 1","l");
1207 // leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
1208 // leg->AddEntry(bottomline,"#pm50% envelope","l");
1209
1210
1211 //leg->Draw("same"); // no longer drawing legend
1212
1213 if(is_data==1) CompleteSave(can, "jzb_ratio_data");
1214 if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
1215 if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
1216
1217 delete RcorrJZBeemm;
1218 delete LcorrJZBeemm;
1219 delete RcorrJZBem;
1220 delete LcorrJZBem;
1221
1222 delete RcorrJZBSBem;
1223 delete LcorrJZBSBem;
1224 delete RcorrJZBSBeemm;
1225 delete LcorrJZBSbeemm;
1226 }
1227
1228 void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
1229 TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
1230 globalc->SetLogy(0);
1231
1232 do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh );
1233 do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh );
1234 do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh );
1235 }
1236
1237 string give_jzb_expression(float peak, int type) {
1238 stringstream val;
1239 if(type==data) {
1240 if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
1241 if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
1242 if(peak==0) val << jzbvariabledata;
1243 }
1244 if(type==mc) {
1245 if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
1246 if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
1247 if(peak==0) val << jzbvariablemc;
1248 }
1249 return val.str();
1250 }
1251
1252
1253 void lepton_comparison_plots() {
1254 Float_t ymin = 1.e-5, ymax = 0.25;
1255 TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
1256 can->SetLogy(1);
1257 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
1258 TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
1259 eemc->SetLineColor(kBlue);
1260 mmmc->SetLineColor(kRed);
1261 eemc->SetMinimum(0.1);
1262 eemc->SetMaximum(10*eemc->GetMaximum());
1263 eemc->Draw("histo");
1264 mmmc->Draw("histo,same");
1265 TLegend *leg = make_legend();
1266 leg->AddEntry(eemc,"ZJets->ee (MC)","l");
1267 leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
1268 leg->Draw("same");
1269 CompleteSave(can, "lepton_comparison/mll_effratio_mc");
1270
1271 TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
1272 TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
1273 eed->SetLineColor(kBlue);
1274 mmd->SetLineColor(kRed);
1275 eed->SetMinimum(0.1);
1276 eed->SetMaximum(10*eed->GetMaximum());
1277 eed->Draw("histo");
1278 mmd->Draw("histo,same");
1279 TLegend *leg2 = make_legend();
1280 leg2->AddEntry(eed,"ZJets->ee (data)","l");
1281 leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
1282 leg2->Draw();
1283 CompleteSave(can, "lepton_comparison/mll_effratio_data");
1284
1285 TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
1286 TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
1287 TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
1288 dout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
1289 dout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
1290 dout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
1291 jeemmd->SetLineColor(kBlack);
1292 jeemmd->SetMarkerStyle(25);
1293 jeed->SetLineColor(kBlue);
1294 jmmd->SetLineColor(kRed);
1295 jeed->SetMinimum(0.1);
1296 jeed->SetMaximum(10*eed->GetMaximum());
1297 TH1* njeemmd = jeemmd->DrawNormalized();
1298 njeemmd->SetMinimum(ymin);
1299 njeemmd->SetMaximum(ymax);
1300
1301 jeed->DrawNormalized("histo,same");
1302 jmmd->DrawNormalized("histo,same");
1303 jeemmd->DrawNormalized("same");
1304 TLegend *jleg2 = make_legend(" ");
1305 jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
1306 jleg2->AddEntry(jeed,"ee","l");
1307 jleg2->AddEntry(jmmd,"#mu#mu","l");
1308 jleg2->Draw();
1309 CompleteSave(can,"lepton_comparison/jzb_effratio_data");
1310
1311 TPad *eemmpad = new TPad("eemmpad","eemmpad",0,0,1,1);
1312 eemmpad->cd();
1313 eemmpad->SetLogy(1);
1314 jeed->Draw("histo");
1315 jmmd->Draw("histo,same");
1316 TLegend *eemmlegend = make_legend(" ");
1317 eemmlegend->AddEntry(jeed,"ee","l");
1318 eemmlegend->AddEntry(jmmd,"#mu#mu","l");
1319 eemmlegend->Draw();
1320 DrawPrelim();
1321 save_with_ratio(jeed,jmmd,eemmpad->cd(),"lepton_comparison/jzb_Comparing_ee_mm_data");
1322
1323 TH1F *zjeed = allsamples.Draw("zjeed",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJets"));
1324 TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc, int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJets"));
1325 TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets, mc, luminosity,allsamples.FindSample("DYJets"));
1326 dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
1327 dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
1328 dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
1329 zjeemmd->SetLineColor(kBlack);
1330 zjeemmd->SetMarkerStyle(25);
1331 zjeed->SetLineColor(kBlue);
1332 zjmmd->SetLineColor(kRed);
1333 zjeed->SetMinimum(0.1);
1334 zjeed->SetMaximum(10*eed->GetMaximum());
1335
1336 TH1* nzjeemmd = zjeemmd->DrawNormalized();
1337 nzjeemmd->SetMinimum(ymin);
1338 nzjeemmd->SetMaximum(ymax);
1339 zjeed->DrawNormalized("histo,same");
1340 zjmmd->DrawNormalized("histo,same");
1341 zjeemmd->DrawNormalized("same");
1342 TLegend *zjleg2 = make_legend("Z+jets MC");
1343 zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
1344 zjleg2->AddEntry(jeed,"ee","l");
1345 zjleg2->AddEntry(jmmd,"#mu#mu","l");
1346 zjleg2->Draw();
1347 CompleteSave(can,"lepton_comparison/jzb_effratio_ZJets");
1348
1349 TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
1350 ld->DrawNormalized("e1");
1351 eed->DrawNormalized("histo,same");
1352 mmd->DrawNormalized("histo,same");
1353 TLegend *leg3 = make_legend();
1354 leg3->AddEntry(ld,"ZJets->ll (data)","p");
1355 leg3->AddEntry(eed,"ZJets->ee (data)","l");
1356 leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
1357 leg3->Draw();
1358 CompleteSave(can,"lepton_comparison/mll_effratio_data__all_compared");
1359 /*
1360 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1361 TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1362 */
1363 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
1364 TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,int((jzbHigh+110)/5),-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
1365 jzbld->SetMarkerColor(kBlack);
1366 jzbld->SetMarkerStyle(26);
1367 jzbemd->SetMarkerStyle(25);
1368 jzbemd->SetMarkerColor(kRed);
1369 jzbemd->SetLineColor(kRed);
1370 jzbld->SetMinimum(0.35);
1371 jzbld->Draw("e1");
1372 jzbemd->Draw("e1,same");
1373 TLegend *leg4 = make_legend();
1374 leg4->AddEntry(jzbld,"SFZP","p");
1375 leg4->AddEntry(jzbemd,"OFZP","p");
1376 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
1377 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
1378 leg4->Draw();
1379 CompleteSave(can,"lepton_comparison/jzb_eemumu_emu_data");
1380
1381 TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
1382 TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,int((jzbHigh+150)/5),-150,jzbHigh, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
1383 ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
1384 ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
1385 ttbarjzbld->Draw("histo");
1386 ttbarjzbemd->SetLineStyle(2);
1387 ttbarjzbemd->Draw("histo,same");
1388 TLegend *leg5 = make_legend();
1389 leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
1390 leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
1391 leg5->Draw();
1392 CompleteSave(can,"lepton_comparison/ttbar_emu_mc");
1393
1394 }
1395
1396 bool is_OF(TCut cut) {
1397 string scut = (const char*) cut;
1398 if((int)scut.find("id1!=id2")>-1) return true;
1399 if((int)scut.find("id1==id2")>-1) return false;
1400 return false;
1401 }
1402
1403 bool is_ZP(TCut cut) {
1404 string scut = (const char*) cut;
1405 if((int)scut.find("91")>-1) return true;
1406 return false;
1407 }
1408
1409
1410 void draw_pure_jzb_histo(TCut cut,string datavariable, string mcvariable, string savename, TCanvas *can,vector<float> binning) {
1411 TPad *jzbpad = new TPad("jzbpad","jzbpad",0,0,1,1);
1412 jzbpad->cd();
1413 jzbpad->SetLogy(1);
1414 string xlabel="JZB [GeV]";
1415
1416 TH1F *datahisto = allsamples.Draw("datahisto",datavariable,binning, xlabel, "events",cut,data,luminosity);
1417 THStack mcstack = allsamples.DrawStack("mcstack",mcvariable,binning, xlabel, "events",cut,mc,luminosity);
1418
1419 datahisto->SetMinimum(0.1);
1420 datahisto->SetMarkerSize(DataMarkerSize);
1421 datahisto->Draw("e1");
1422 mcstack.Draw("same");
1423 datahisto->Draw("same,e1");
1424
1425 TLegend *leg;
1426 if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
1427 else if(!is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1428 else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1429 else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1430 else {
1431 std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1432 exit(-1);
1433 }
1434 leg->Draw();
1435 string write_cut = decipher_cut(cut,"");
1436 TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1437 writeline1->SetTextSize(0.035);
1438 writeline1->Draw();
1439 save_with_ratio(datahisto,mcstack,jzbpad->cd(),("jzb/"+savename));
1440 TPad *jzbpad2 = new TPad("jzbpad2","jzbpad2",0,0,1,1);
1441 jzbpad2->cd();
1442 jzbpad2->SetLogy(1);
1443 datahisto->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
1444 datahisto->SetMinimum(0.1);
1445 datahisto->SetMarkerSize(DataMarkerSize);
1446 datahisto->Draw("e1");
1447 mcstack.Draw("same");
1448 datahisto->Draw("same,e1");
1449 leg->SetHeader("");
1450 leg->Draw();
1451 writeline1->SetTextSize(0.035);
1452 writeline1->Draw();
1453 DrawPrelim();
1454 save_with_ratio(datahisto,mcstack,jzbpad2->cd(),("jzb/PositiveSideOnly/"+savename+""));
1455 datahisto->Delete();
1456 mcstack.Delete();
1457 }
1458
1459 Double_t GausR(Double_t *x, Double_t *par) {
1460 return gRandom->Gaus(x[0],par[0]);
1461 }
1462
1463 void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1464 TCanvas *can = new TCanvas("can","JZB Plots Canvas");
1465 float max=jzbHigh ;
1466 float min=-120;
1467 int nbins=(int)((max-min)/5.0); // we want 5 GeV/bin
1468 int coarserbins=int(nbins/2.0);
1469 int rebinnedbins=int(nbins/4.0);
1470
1471 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1472 for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1473 for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1474 for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1475
1476 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP",can,binning);
1477 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP",can,binning);
1478 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_SFZP",can,binning);
1479 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_SFZP",can,binning);
1480 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==0",datajzb,mcjzb,"ee/jzb_OS_OFZP",can,binning);
1481 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass&&"id1==1",datajzb,mcjzb,"mm/jzb_OS_OFZP",can,binning);
1482 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1483 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB",can,binning);
1484 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB",can,binning);
1485
1486 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1487 draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1488 flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1489 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1490 if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1491
1492 // draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
1493 // draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,mcjzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
1494 // flag_this_change(__FUNCTION__,__LINE__,true);//PlottingSetup::RestrictToMassPeak
1495 // if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_SFSB_coarsest",can,coarsest_binning);
1496 // if(PlottingSetup::RestrictToMassPeak) draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,mcjzb,"jzb_OS_OFSB_coarsest",can,coarsest_binning);
1497 }
1498
1499
1500 void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
1501 dout << "Calculating background yields in MC:" << endl;
1502 jzb_cuts.push_back(14000);
1503 TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
1504 float cumulative=0;
1505 for(int i=allbgs->GetNbinsX();i>=1;i--) {
1506 cumulative+=allbgs->GetBinContent(i);
1507 dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
1508 }
1509 }
1510
1511
1512 TCut give_jzb_expression(string mcjzb, float jzbcut, string posneg="pos") {
1513 stringstream res;
1514 res << "(" << mcjzb;
1515 if(posneg=="pos") res << ">";
1516 else res << "<-";
1517 res << jzbcut << ")";
1518 return TCut(res.str().c_str());
1519 }
1520
1521 string sigdig(float number, int nsigdig=3, float min=0) {
1522 //this function tries to extract n significant digits, and if the number is below (min), it returns "<min"
1523 if(number<min) return "< "+any2string(min);
1524 stringstream sol;
1525 sol << setprecision(nsigdig) << number;
1526
1527 return sol.str();
1528 }
1529
1530 string jzb_tex_command(string region, string posneg) {
1531 if(posneg=="pos") posneg="POS";
1532 else posneg="NEG";
1533 stringstream texcommand;
1534 texcommand<<"\\"<<region <<"JZB"<<posneg;
1535 return texcommand.str();
1536 }
1537 // \SFZPJZBPOS
1538 // Sample & \OFZPJZBPOS & \OFZPJZBNEG & \SFZPJZBPOS & \SFZPJZBNEG & \OFSBJZBPOS & \OFSBJZBNEG & \SFSBJZBPOS & \SFSBJZBNEG \\\hline
1539
1540 void compute_MC_yields(string mcjzb,vector<float> jzb_cuts) {
1541 dout << "Calculating background yields in MC:" << endl;
1542
1543 TCanvas *yica = new TCanvas("yica","yield canvas");
1544
1545 int nRegions=4;
1546 if(!PlottingSetup::RestrictToMassPeak) nRegions=2;
1547 string tsRegions[] = {"SFZP","OFZP","SFSB","OFSB"};
1548 string posneg[] = {"pos","neg"};
1549 TCut tkRegions[] = {cutOSSF&&cutnJets&&cutmass,cutOSOF&&cutnJets&&cutmass,cutOSSF&&cutnJets&&sidebandcut,cutOSOF&&cutnJets&&sidebandcut};
1550
1551 for(int ijzb=0;ijzb<jzb_cuts.size();ijzb++) {
1552 TCut jzbMC[] = { give_jzb_expression(mcjzb,jzb_cuts[ijzb],"pos"), give_jzb_expression(mcjzb,jzb_cuts[ijzb],"neg") };
1553 dout << "_________________________________________________________" << endl;
1554 dout << "Table for JZB> " << jzb_cuts[ijzb] << endl;
1555 for(int isample=0;isample<(allsamples.collection).size();isample++) {
1556 if(!(allsamples.collection)[isample].is_data) dout << (allsamples.collection)[isample].samplename << " & ";
1557 else dout << "Sample & ";
1558 for(int iregion=0;iregion<nRegions;iregion++) {
1559 for(int ipos=0;ipos<2;ipos++) {
1560 if((allsamples.collection)[isample].is_data) dout << jzb_tex_command(tsRegions[iregion],posneg[ipos]) << " & ";
1561 else {
1562 vector<int> specific;specific.push_back(isample);
1563 TH1F *shisto = allsamples.Draw("shisto","mll",1,0,500,"tester","events",tkRegions[iregion]&&jzbMC[ipos],mc,luminosity,specific);
1564 dout << sigdig(shisto->Integral(),3,0.05) <<" & ";
1565 delete shisto;
1566 }
1567 }//end of ipos
1568 }//end of iregion
1569 dout << " \\\\" << endl;
1570 }//end of isample
1571 }//end of ijzb
1572 dout << " \\hline" << endl;
1573
1574 delete yica;
1575 }
1576
1577 void draw_ttbar_and_zjets_shape_for_one_configuration(string mcjzb, string datajzb, int leptontype=-1, int scenario=0,bool floating=false) {
1578 //Step 1: Establishing cuts
1579 stringstream jetcutstring;
1580 string writescenario="";
1581
1582 if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
1583 if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
1584 TCut jetcut(jetcutstring.str().c_str());
1585 string leptoncut="mll>0";
1586 if(leptontype==0||leptontype==1) {
1587 if(leptontype==0) {
1588 leptoncut="id1==0";
1589 writescenario="__ee";
1590 }
1591 else {
1592 leptoncut="id1==1";
1593 writescenario="__ee";
1594 }
1595 }
1596 TCut lepcut(leptoncut.c_str());
1597
1598 TCanvas *c5 = new TCanvas("c5","c5",1500,500);
1599 TCanvas *c6 = new TCanvas("c6","c6");
1600 c5->Divide(3,1);
1601
1602 //STEP 2: Extract Zjets shape in data
1603 c5->cd(1);
1604 c5->cd(1)->SetLogy(1);
1605 TCut massat40("mll>40");
1606 TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1607 TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1608 ossfleft->SetLineColor(kRed);
1609 ossfleft->SetMarkerColor(kRed);
1610 ossfleft->Add(osofleft,-1);
1611 vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
1612 ossfleft->SetMarkerSize(DataMarkerSize);
1613 ossfleft->Draw();
1614 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
1615 TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
1616 TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
1617 TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
1618 zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
1619 TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
1620 leg1->SetFillColor(kWhite);
1621 leg1->SetLineColor(kWhite);
1622 leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
1623 leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
1624 leg1->Draw("same");
1625 TText *titleleft = write_title("Extracting Z+Jets shape");
1626 titleleft->Draw();
1627
1628 //Step 3: Extract ttbar shape (in data or MC?)
1629 c5->cd(2);
1630 c5->cd(2)->SetLogy(1);
1631 TH1F *osof;
1632 TText *titlecenter;
1633 bool frommc=false;
1634 if(frommc) {
1635 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
1636 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
1637 }
1638 else {
1639 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1640 titlecenter = write_title("Extracting ttbar shape (from osof data)");
1641 }
1642 osof->SetMarkerSize(DataMarkerSize);
1643 osof->Draw();
1644 vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
1645 ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
1646 ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
1647 ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
1648
1649 TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
1650 leg2->SetFillColor(kWhite);
1651 leg2->SetLineColor(kWhite);
1652 if(frommc) {
1653 leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
1654 leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
1655 } else {
1656 leg2->AddEntry(osof,"OSOF","p");
1657 leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
1658 }
1659 leg2->Draw("same");
1660 titlecenter->Draw();
1661
1662 //--------------------------------------------------------------------------------------------------------------------------------
1663 //STEP 4: Present it!
1664 // actually: if we wanna let it float we need to do that first :-)
1665 c5->cd(3);
1666 c5->cd(3)->SetLogy(1);
1667 TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1668 observed->SetMarkerSize(DataMarkerSize);
1669
1670 TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
1671 TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
1672 TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
1673
1674 TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
1675 TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
1676 TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
1677
1678 TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
1679 TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
1680 TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
1681
1682 zjetsc->SetParameters(zjetsfunc->GetParameters());
1683 zjetscp->SetParameters(zjetsfunc->GetParameters());
1684 zjetscn->SetParameters(zjetsfunc->GetParameters());
1685
1686 TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1687 //blublu
1688 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1689 logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
1690 logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
1691 if(floating) {
1692 dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
1693 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1694 for(int i=0;i<10;i++) {
1695 if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
1696 if(i>=5) {
1697 if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
1698 if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
1699 }
1700 }//end of setting parameters
1701 observeda->Draw("same");
1702 ZplusJetsplusTTbar->Draw("same");
1703 observeda->Fit(ZplusJetsplusTTbar);
1704 dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
1705 ZplusJetsplusTTbar->Draw("same");
1706 ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
1707 ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
1708 dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
1709 float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
1710 dout << "FACTOR: " << factor << endl;
1711 logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1712 logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1713 logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1714 }
1715
1716 c5->cd(3);
1717 c5->cd(3)->SetLogy(1);
1718 observed->Draw();
1719 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1720 logparc->Draw("same");
1721 logparcn->Draw("same");
1722 logparcp->Draw("same");
1723
1724 TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
1725 leg3->SetFillColor(kWhite);
1726 leg3->SetLineColor(kWhite);
1727 leg3->AddEntry(observed,"OSSF,JZB>peak","p");
1728 leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
1729 leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
1730 leg3->Draw("same");
1731 TText *titleright = write_title("Summary of shapes and observed shape");
1732 titleright->Draw();
1733
1734 c6->cd()->SetLogy(1);
1735 observed->Draw();
1736 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1737 logparc->Draw("same");
1738 logparcn->Draw("same");
1739 logparcp->Draw("same");
1740 leg3->Draw("same");
1741 titleright->Draw();
1742
1743 if(scenario==0) {
1744 CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
1745 CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
1746 CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
1747 CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
1748 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
1749 } else {
1750 CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
1751 CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
1752 CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
1753 CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
1754 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
1755 }
1756 dout << "Statistics about our fits: " << endl;
1757 dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
1758 dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
1759
1760 c6->cd();
1761 TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
1762 additionallegend->SetFillColor(kWhite);
1763 additionallegend->SetLineColor(kWhite);
1764 additionallegend->AddEntry(observed,"Data","p");
1765 additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
1766 additionallegend->AddEntry(zjetsc,"Z+jets","l");
1767 additionallegend->AddEntry(logparc,"TTbar","l");
1768 observed->Draw();
1769 ZplusJetsplusTTbar->SetLineColor(kGreen);
1770 ZplusJetsplusTTbarP->SetLineColor(kGreen);
1771 ZplusJetsplusTTbarN->SetLineColor(kGreen);
1772 ZplusJetsplusTTbarP->SetLineStyle(2);
1773 ZplusJetsplusTTbarN->SetLineStyle(2);
1774 TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
1775 ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
1776 ZplusJetsplusTTbar2->SetLineColor(kGreen);
1777 ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
1778 ZplusJetsplusTTbarN->SetFillColor(kWhite);
1779 ZplusJetsplusTTbarP->Draw("fcsame");
1780 ZplusJetsplusTTbarN->Draw("fcsame");
1781 TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
1782 TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
1783 TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
1784 hZplusJetsplusTTbar->SetMarkerSize(0);
1785 hZplusJetsplusTTbarP->SetMarkerSize(0);
1786 hZplusJetsplusTTbarN->SetMarkerSize(0);
1787 for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
1788 float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
1789 hZplusJetsplusTTbar->SetBinError(i,newerror);
1790 if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
1791 }
1792 hZplusJetsplusTTbarP->SetFillColor(kGreen);
1793 hZplusJetsplusTTbarN->SetFillColor(kWhite);
1794 hZplusJetsplusTTbarN->Draw("same");
1795
1796 ZplusJetsplusTTbar2->SetMarkerSize(0);
1797 ZplusJetsplusTTbar2->Draw("same");
1798
1799 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1800 logparc->Draw("same");
1801 logparcn->Draw("same");
1802 logparcp->Draw("same");
1803 additionallegend->Draw("same");
1804 if(scenario==0) {
1805 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
1806 } else {
1807 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
1808 }
1809 //--------------------------------------------------------------------------------------------------------------------------------
1810 }
1811
1812 void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
1813 int all_leptons=-1;
1814 int electrons_only=0;
1815 int mu_only=1;
1816 int twojetswith50gev=1;
1817 int threejetswith30gev=0;
1818 /*
1819 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
1820 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
1821
1822 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
1823 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
1824
1825 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
1826 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
1827 */
1828
1829 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
1830 }
1831
1832 void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1833 //first: colorful plots
1834 TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
1835 cancorr->SetLogz();
1836 cancorr->SetRightMargin(0.13);
1837 flag_this_change(__FUNCTION__,__LINE__,false);//PlottingSetup::RestrictToMassPeak
1838 TCut zptforresponsepresentation("pt<600"&&cutmass&&cutOSSF&&"((sumJetPt[1]/pt)<5.0)");
1839 TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
1840 (allsamples.collection)[allsamples.FindSample("Data")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
1841 niceresponseplotd->SetStats(0);
1842 niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1843 niceresponseplotd->GetYaxis()->SetTitle("Response");
1844 niceresponseplotd->GetXaxis()->CenterTitle();
1845 niceresponseplotd->GetYaxis()->CenterTitle();
1846 niceresponseplotd->Draw("COLZ");
1847 TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
1848 profd->SetMarkerSize(DataMarkerSize);
1849 profd->Fit("pol0","","same,e1",30,400);
1850 DrawPrelim();
1851 TText* title = write_text(0.5,0.7,"Data");
1852 title->SetTextAlign(12);
1853 title->Draw();
1854 TF1 *datapol=(TF1*)profd->GetFunction("pol0");
1855 float datacorrection=datapol->GetParameter(0);
1856 stringstream dataresstring;
1857 dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
1858 TText* restitle = write_text(0.5,0.65,dataresstring.str());
1859 restitle->SetTextAlign(12);
1860 restitle->SetTextSize(0.03);
1861 restitle->Draw();
1862 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
1863
1864 TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
1865 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
1866 niceresponseplotm->SetStats(0);
1867 niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1868 niceresponseplotm->GetYaxis()->SetTitle("Response");
1869 niceresponseplotm->GetXaxis()->CenterTitle();
1870 niceresponseplotm->GetYaxis()->CenterTitle();
1871 niceresponseplotm->Draw("COLZ");
1872 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
1873 TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
1874 profm->SetMarkerSize(DataMarkerSize);
1875 profm->Fit("pol0","","same,e1",30,400);
1876 DrawMCPrelim();
1877 title = write_text(0.5,0.7,"MC simulation");
1878 title->SetTextAlign(12);
1879 title->Draw();
1880 TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
1881 float mccorrection=mcpol->GetParameter(0);
1882 stringstream mcresstring;
1883 mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
1884 TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
1885 mcrestitle->SetTextAlign(12);
1886 mcrestitle->SetTextSize(0.03);
1887 mcrestitle->Draw();
1888 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
1889
1890
1891 //Step 2: Getting the result
1892 // TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
1893 stringstream jzbvardatas;
1894 if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
1895 if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
1896 jzbvardata=jzbvardatas.str();
1897 stringstream jzbvarmcs;
1898 if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
1899 if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
1900 jzbvarmc=jzbvarmcs.str();
1901 dout << "JZB Z pt correction summary : " << endl;
1902 dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
1903 dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
1904 }
1905
1906 void pick_up_events(string cut) {
1907 dout << "Picking up events with cut " << cut << endl;
1908 allsamples.PickUpEvents(cut);
1909 }
1910
1911 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
1912 dout << "Saving configuration template!" << endl;
1913 ofstream configfile;
1914 configfile.open("../DistributedModelCalculations/last_configuration.C");
1915 configfile<<"#include <iostream>\n";
1916 configfile<<"#include <vector>\n";
1917 configfile<<"#ifndef SampleClassLoaded\n";
1918 configfile<<"#include \"SampleClass.C\"\n";
1919 configfile<<"#endif\n";
1920 configfile<<"#define SetupLoaded\n";
1921 configfile<<"#ifndef ResultLibraryClassLoaded\n";
1922 configfile<<"#include \"ResultLibraryClass.C\"\n";
1923 configfile<<"#endif\n";
1924
1925 configfile<<"\nusing namespace std;\n\n";
1926
1927 configfile<<"namespace PlottingSetup { \n";
1928 configfile<<"string datajzb=\"datajzb_ERROR\";\n";
1929 configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
1930 configfile<<"vector<float>jzb_cuts;\n";
1931 configfile<<"float MCPeakError=-999;\n";
1932 configfile<<"}\n\n";
1933
1934 configfile<<"void read_config() {\n";
1935 configfile<<"datajzb=\""<<datajzb<<"\";\n";
1936 configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
1937 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
1938 for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1939 configfile<<"\n\n";
1940 for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1941 for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1942 for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1943 configfile<<"\n\n";
1944 for(int i=0;i<flippedNobs.size();i++) configfile<<"flippedNobs.push_back("<<flippedNobs[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1945 for(int i=0;i<flippedNpred.size();i++) configfile<<"flippedNpred.push_back("<<flippedNpred[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1946 for(int i=0;i<flippedNprederr.size();i++) configfile<<"flippedNprederr.push_back("<<flippedNprederr[i]<<"); // JZB cut at " << jzb_cuts[i] << "\n";
1947 configfile<<"\n\n";
1948 configfile<<"luminosity="<<luminosity<<";\n";
1949
1950 configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
1951
1952 configfile.close();
1953
1954 }
1955
1956 float get_nonzero_minimum(TH1F *histo) {
1957 float min=histo->GetMaximum();
1958 for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
1959 float curcont=histo->GetBinContent(ibin);
1960 if(curcont<min&&curcont>0) min=curcont;
1961 }
1962 return min;
1963 }
1964
1965 void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
1966 can->cd();
1967 float min=1;
1968 float max=histos[0]->GetMaximum();
1969 if(manualmin>=0) min=manualmin;
1970 else {
1971 for(int i=1;i<histos.size();i++) {
1972 float curmin=get_nonzero_minimum(histos[i]);
1973 float curmax=histos[i]->GetMaximum();
1974 if(curmin<min) min=curmin;
1975 if(curmax>max) max=curmax;
1976 }
1977 }
1978 histos[0]->GetYaxis()->SetRangeUser(min,4*max);
1979 histos[0]->Draw(drawoption.c_str());
1980 stringstream drawopt;
1981 drawopt << drawoption << ",same";
1982 for(int i=1;i<histos.size();i++) {
1983 histos[i]->Draw(drawopt.str().c_str());
1984 }
1985 }
1986
1987 void ttbar_sidebands_comparison(string mcjzb, vector<float> binning, string prestring) {
1988 //in the case of the on peak analysis, we compare the 3 control regions to the real value
1989 //in the case of the OFF peak analysis, we compare our control region to the real value
1990 TCut weightbackup=cutWeight;
1991 cutWeight="1.0";
1992 float simulatedlumi = luminosity; //in pb please - adjust to your likings
1993
1994
1995 TH1F *TZem = systsamples.Draw("TZem",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
1996 TH1F *nTZem = systsamples.Draw("nTZem","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
1997 TH1F *TSem;
1998 TH1F *nTSem;
1999 TH1F *TZeemm = systsamples.Draw("TZeemm",mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2000 TH1F *nTZeemm = systsamples.Draw("nTZeemm","-"+mcjzb,binning,"JZB [GeV]","events",cutmass&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2001 TH1F *TSeemm;
2002 TH1F *nTSeemm;
2003
2004 if(PlottingSetup::RestrictToMassPeak) {
2005 TSem = systsamples.Draw("TSem",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2006 nTSem = systsamples.Draw("nTSem","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSOF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2007 TSeemm = systsamples.Draw("TSeemm",mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2008 nTSeemm = systsamples.Draw("nTSeemm","-"+mcjzb,binning,"JZB [GeV]","events",sidebandcut&&cutOSSF&&cutnJets,mc,simulatedlumi,systsamples.FindSample("TTJets"));
2009 }
2010
2011 TCanvas *tcan = new TCanvas("tcan","tcan");
2012
2013 tcan->SetLogy(1);
2014
2015 TZeemm->SetLineColor(kBlack);
2016 TZem->SetLineColor(kRed);
2017 TZeemm->SetMarkerColor(kBlack);
2018 TZem->SetMarkerColor(kRed);
2019
2020
2021 if(PlottingSetup::RestrictToMassPeak) {
2022 TSem->SetLineColor(TColor::GetColor("#00A616"));
2023 TSeemm->SetLineColor(kMagenta+2);
2024 TSem->SetMarkerColor(TColor::GetColor("#00A616"));
2025 TSeemm->SetMarkerColor(kMagenta+2);
2026 TSem->SetLineStyle(2);
2027 TSeemm->SetLineStyle(3);
2028 }
2029
2030 vector<TH1F*> histos;
2031 histos.push_back(TZem);
2032 histos.push_back(TZeemm);
2033 if(PlottingSetup::RestrictToMassPeak) {
2034 histos.push_back(TSem);
2035 histos.push_back(TSeemm);
2036 }
2037 draw_all_ttbar_histos(tcan,histos,"histo",0.04);
2038
2039 TLegend *leg = make_legend("MC t#bar{t}",0.6,0.65,false);
2040 leg->AddEntry(TZeemm,"SFZP","l");
2041 leg->AddEntry(TZem,"OFZP","l");
2042 if(PlottingSetup::RestrictToMassPeak) {
2043 leg->AddEntry(TSeemm,"SFSB","l");
2044 leg->AddEntry(TSem,"OFSB","l");
2045 }
2046 leg->Draw("same");
2047 DrawMCPrelim(simulatedlumi);
2048 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison");
2049
2050 TH1F *TZemcopy = (TH1F*)TZem->Clone("TZemcopy");
2051 TH1F *TZeemmcopy = (TH1F*)TZeemm->Clone("TZeemmcopy");
2052 TH1F *TSeemmcopy = (TH1F*)TSeemm->Clone("TSeemmcopy");
2053 TH1F *TSemcopy = (TH1F*)TSem->Clone("TSemcopy");
2054
2055 TZem->Divide(TZeemm);
2056 TZem->SetMarkerStyle(21);
2057 if(PlottingSetup::RestrictToMassPeak) {
2058 TSem->Divide(TZeemm);
2059 TSeemm->Divide(TZeemm);
2060 TSem->SetMarkerStyle(24);
2061 TSeemm->SetMarkerStyle(32);
2062 }
2063
2064 tcan->SetLogy(0);
2065 TZem->GetYaxis()->SetRangeUser(0,2.5);
2066 TZem->GetYaxis()->SetTitle("ratio");
2067 TZem->Draw();
2068 if(PlottingSetup::RestrictToMassPeak) {
2069 TSem->Draw("same");
2070 TSeemm->Draw("same");
2071 }
2072
2073 float linepos=0.25;
2074 if(PlottingSetup::RestrictToMassPeak) linepos=0.25;
2075 TLine *top = new TLine(binning[0],1.0+linepos,binning[binning.size()-1],1.0+linepos);
2076 TLine *center = new TLine(binning[0],1.0,binning[binning.size()-1],1.0);
2077 TLine *bottom = new TLine(binning[0],1.0-linepos,binning[binning.size()-1],1.0-linepos);
2078
2079 top->SetLineColor(kBlue);top->SetLineStyle(2);
2080 bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2081 center->SetLineColor(kBlue);
2082
2083 top->Draw("same");
2084 center->Draw("same");
2085 bottom->Draw("same");
2086
2087 TLegend *leg2 = make_legend("MC t#bar{t}",0.55,0.75,false);
2088 leg2->AddEntry(TZem,"OFZP / SFZP","ple");
2089 if(PlottingSetup::RestrictToMassPeak) {
2090 leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
2091 leg2->AddEntry(TSem,"OFSB / SFZP","ple");
2092 }
2093 leg2->AddEntry(bottom,"syst. envelope","l");
2094 leg2->SetX1(0.25);leg2->SetX2(0.6);
2095 leg2->SetY1(0.65);
2096
2097 leg2->Draw("same");
2098
2099 DrawMCPrelim(simulatedlumi);
2100 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_shape_comparison_ratio");
2101
2102
2103
2104 ///-------------- second part: only look at the quantity we actually care about!
2105 TH1F *leftsfzp = (TH1F*)nTZeemm->Clone("leftsfzp");
2106 TH1F *rightsfzp = (TH1F*)TZeemmcopy->Clone("rightsfzp");
2107 rightsfzp->Add(leftsfzp,-1);
2108 TH1F *leftofzp = (TH1F*)nTZem->Clone("leftofzp");
2109 TH1F *rightofzp = (TH1F*)TZemcopy->Clone("rightofzp");
2110 rightofzp->Add(leftofzp,-1);
2111 TH1F *leftofsb;
2112 TH1F *rightofsb;
2113 TH1F *leftsfsb;
2114 TH1F *rightsfsb;
2115 if(PlottingSetup::RestrictToMassPeak) {
2116 leftofsb = (TH1F*)nTSem->Clone("leftofsb");
2117 rightofsb = (TH1F*)TSemcopy->Clone("rightofsb");
2118 rightofsb->Add(leftofsb,-1);
2119 leftsfsb = (TH1F*)nTSeemm->Clone("leftsfsb");
2120 rightsfsb = (TH1F*)TSeemmcopy->Clone("rightsfsb");
2121 rightsfsb->Add(leftsfsb,-1);
2122 }
2123
2124 tcan->SetLogy(1);
2125 rightsfzp->GetXaxis()->SetRangeUser(0,binning[binning.size()-1]);
2126 rightsfzp->GetYaxis()->SetTitle("#deltaJZB / 25 GeV");
2127 rightsfzp->Draw("histo");
2128 rightofzp->Draw("histo,same");
2129 if(PlottingSetup::RestrictToMassPeak) {
2130 rightofsb->Draw("histo,same");
2131 rightsfsb->Draw("histo,same");
2132 }
2133 DrawMCPrelim(simulatedlumi);
2134
2135 TLegend *legA = make_legend("MC t#bar{t}",0.6,0.65,false);
2136 legA->AddEntry(rightsfzp,"SFZP","l");
2137 legA->AddEntry(rightofzp,"OFZP","l");
2138 if(PlottingSetup::RestrictToMassPeak) {
2139 legA->AddEntry(rightofsb,"SFSB","l");
2140 legA->AddEntry(rightsfsb,"OFSB","l");
2141 }
2142 legA->Draw();
2143
2144 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison");
2145
2146 tcan->SetLogy(0);
2147 rightofzp->Divide(rightsfzp);
2148 rightofzp->GetXaxis()->SetRangeUser(0.0,binning[binning.size()-1]);
2149 rightofzp->GetYaxis()->SetRangeUser(0.0,2.0);
2150 rightofzp->GetYaxis()->SetTitle("#deltaJZB ratio");
2151 rightofzp->Draw();
2152 if(PlottingSetup::RestrictToMassPeak) {
2153 rightofsb->Divide(rightsfzp);
2154 rightsfsb->Divide(rightsfzp);
2155 rightofsb->Draw("same");
2156 rightsfsb->Draw("same");
2157 }
2158
2159 TLine *top2 = new TLine(0.0,1.0+linepos,binning[binning.size()-1],1.0+linepos);
2160 TLine *center2 = new TLine(0.0,1.0,binning[binning.size()-1],1.0);
2161 TLine *bottom2 = new TLine(0.0,1.0-linepos,binning[binning.size()-1],1.0-linepos);
2162
2163 top2->SetLineColor(kBlue);top2->SetLineStyle(2);
2164 bottom2->SetLineColor(kBlue);bottom2->SetLineStyle(2);
2165 center2->SetLineColor(kBlue);
2166
2167 top2->Draw("same");
2168 center2->Draw("same");
2169 bottom2->Draw("same");
2170
2171 rightofzp->SetMarkerStyle(21);
2172 if(PlottingSetup::RestrictToMassPeak) {
2173 rightofsb->SetMarkerStyle(24);
2174 rightsfsb->SetMarkerStyle(32);
2175 }
2176
2177 TLegend *leg3 = make_legend("MC t#bar{t}",0.55,0.75,false);
2178 leg3->AddEntry(rightofzp,"OFZP / SFZP","ple");
2179 if(PlottingSetup::RestrictToMassPeak) {
2180 leg3->AddEntry(rightsfsb,"SFSB / SFZP","ple");
2181 leg3->AddEntry(rightofsb,"OFSB / SFZP","ple");
2182 }
2183 leg3->AddEntry(bottom,"syst. envelope","l");
2184 leg3->SetX1(0.25);leg3->SetX2(0.6);
2185 leg3->SetY1(0.65);
2186
2187 leg3->Draw("same");
2188
2189 DrawMCPrelim(simulatedlumi);
2190 CompleteSave(tcan,"Systematics/"+prestring+"/ttbar_deltajzb_comparison_ratio");
2191
2192 delete TZem;
2193 delete nTZem;
2194 delete TZeemm;
2195 delete nTZeemm;
2196 if(PlottingSetup::RestrictToMassPeak) {
2197 delete TSem;
2198 delete nTSem;
2199 delete TSeemm;
2200 delete nTSeemm;
2201 }
2202
2203 delete tcan;
2204 cutWeight=weightbackup;
2205 }
2206
2207 void ttbar_sidebands_comparison(string mcjzb, vector<float> jzb_binning) {
2208 vector<float> nicer_binning;
2209 nicer_binning.push_back(-125);
2210 nicer_binning.push_back(-100);
2211 nicer_binning.push_back(-75);
2212 nicer_binning.push_back(-50);
2213 nicer_binning.push_back(-25);
2214 nicer_binning.push_back(0);
2215 nicer_binning.push_back(25);
2216 nicer_binning.push_back(50);
2217 nicer_binning.push_back(75);
2218 nicer_binning.push_back(100);
2219 nicer_binning.push_back(125);
2220 nicer_binning.push_back(150);
2221 nicer_binning.push_back(175);
2222 nicer_binning.push_back(200);
2223 nicer_binning.push_back(230);
2224 nicer_binning.push_back(280);
2225 nicer_binning.push_back(400);
2226 ttbar_sidebands_comparison(mcjzb,nicer_binning, "ttbar/");
2227 }
2228
2229
2230 void zjets_prediction_comparison() {
2231 // Do it without PU re-weighting
2232 float MCPeakNoPU=0,MCPeakErrorNoPU=0,DataPeakNoPU=0,DataPeakErrorNoPU=0,MCSigma=0,DataSigma=0;
2233 stringstream resultsNoPU;
2234
2235 stringstream mcjzbnoPU;
2236 find_peaks(MCPeakNoPU,MCPeakErrorNoPU, DataPeakNoPU, DataPeakErrorNoPU,MCSigma,DataSigma,resultsNoPU,false);
2237 if(MCPeakNoPU>0) mcjzbnoPU<<"("<<jzbvariablemc<<"-"<<TMath::Abs(MCPeakNoPU)<<")";
2238 else mcjzbnoPU<<"("<<jzbvariablemc<<"+"<<TMath::Abs(MCPeakNoPU)<<")";
2239
2240 string mcjzb = mcjzbnoPU.str();
2241 dout << "The peak corrected JZB expression for MC without pileup is : " << mcjzb << endl;
2242
2243 TCut weightbackup=cutWeight;
2244 cutWeight="1.0";
2245 float sbg_min=0.;
2246 float sbg_max=100.;
2247 int sbg_nbins=5;
2248 float simulatedlumi = luminosity;//in pb please - adjust to your likings
2249
2250 TCut kPos((mcjzb+">0").c_str());
2251 TCut kNeg((mcjzb+"<0").c_str());
2252 string var( "abs("+mcjzb+")" );
2253
2254 TCut kcut(cutmass&&cutOSSF&&"pfJetGoodNum>2");
2255 TH1F *hJZBpos = systsamples.Draw("hJZBpos",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2256 kcut&&kPos,mc,simulatedlumi,systsamples.FindSample("DYJets"));
2257 TH1F *hJZBneg = systsamples.Draw("hJZBneg",var,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",
2258 kcut&&kNeg,mc,simulatedlumi,systsamples.FindSample("DYJets"));
2259 hJZBpos->SetLineColor(kBlack);
2260 hJZBneg->SetLineColor(kRed);
2261
2262 Int_t nbins = 5;
2263 Float_t xmax = 100.;
2264
2265
2266 TCanvas *zcan = new TCanvas("zcan","zcan");
2267 zcan->SetLogy(1);
2268
2269 hJZBpos->Draw("e1");
2270 hJZBneg->Draw("same,hist");
2271 hJZBpos->Draw("same,e1"); // So it's on top...
2272
2273 TLegend *leg = make_legend("MC Z+jets",0.55,0.75,false);
2274 leg->AddEntry(hJZBpos,"Observed","pe");
2275 leg->AddEntry(hJZBneg,"Predicted","l");
2276 leg->Draw("same");
2277 DrawMCPrelim(simulatedlumi);
2278 CompleteSave(zcan,"Systematics/zjets_prediction");
2279
2280 TH1F* hratio = (TH1F*)hJZBpos->Clone("hratio");
2281 hratio->Divide(hJZBneg);
2282
2283 zcan->SetLogy(0);
2284 hratio->GetYaxis()->SetRangeUser(0,2.5);
2285 hratio->GetYaxis()->SetTitle("Observed/Predicted");
2286 hratio->Draw("e1");
2287
2288 TLine *top = new TLine(sbg_min,1.25,sbg_max,1.25);
2289 TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
2290 TLine *bottom = new TLine(sbg_min,0.75,sbg_max,0.75);
2291
2292
2293 top->SetLineColor(kBlue);top->SetLineStyle(2);
2294 bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
2295 center->SetLineColor(kBlue);
2296
2297 top->Draw("same");
2298 center->Draw("same");
2299 bottom->Draw("same");
2300
2301 TLegend *leg2 = make_legend("MC Z+jets",0.25,0.75,false);
2302 leg2->AddEntry(hratio,"obs / pred","pe");
2303 leg2->AddEntry(bottom,"syst. envelope","l");
2304 leg2->Draw("same");
2305 DrawMCPrelim(simulatedlumi);
2306 CompleteSave(zcan,"Systematics/zjets_prediction_ratio");
2307
2308 delete zcan;
2309 cutWeight=weightbackup;
2310
2311 }
2312
2313
2314
2315 void sideband_assessment(string datajzb, float min=30.0, float max=50.0) {
2316 tout << endl << endl;
2317 stringstream bordercut;
2318 bordercut << "(TMath::Abs(" << datajzb << ")<" << max << ")&&(TMath::Abs(" << datajzb << ")>" << min << ")";
2319 tout << bordercut.str().c_str() << endl;
2320 TH1F *ofsb = allsamples.Draw("ofsb",datajzb,100, 0,100, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2321 TH1F *ofzp = allsamples.Draw("ofzp",datajzb,100, 0,100, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets&&bordercut.str().c_str(),data, luminosity);
2322 float OFSB = ofsb->Integral();
2323 float OFZP = ofzp->Integral();
2324
2325 tout << "\\begin{table}[hbtp]" << endl;
2326 tout << "\\renewcommand{\\arraystretch}{1.3}" << endl;
2327 tout << "\\begin{center}" << endl;
2328 tout << "\\caption{Total number of events observed in the auxiliary region $|JZB|>"<<min<<"\\GeV \\cup |JZB|<"<<max<<"\\GeV$ for the {\\OFZP} and {\\OFSB}.}\\label{tab:auxcounts}" << endl;
2329 tout << "\\begin{tabular}{l|cc}" << endl;
2330 tout << "\\hline" << endl;
2331 tout << "& {\\OFZP} & {\\OFSB} \\\\\\hline" << endl;
2332 tout << "\\#(events) & "<<OFSB<<" & "<<OFZP<<"\\\\ \\hline" << endl;
2333 tout << "\\end{tabular}" << endl;
2334 tout << "\\end{center}" << endl;
2335 tout << "\\end{table}" << endl;
2336
2337
2338 }
2339
2340 void make_table(samplecollection &coll, string jzbexpr, bool is_data, vector<float> jzb_cuts, string subselection="none") {
2341
2342 vector<float> jzbcutprediction;
2343 vector<float> metcutprediction;
2344
2345 vector<float> jzbcutobservation;
2346 vector<float> metcutobservation;
2347
2348 TCanvas *cannie = new TCanvas("cannie","cannie");
2349
2350 for(int icut=0;icut<jzb_cuts.size();icut++) {
2351 float currcut=jzb_cuts[icut];
2352 int nbins=1;float low=currcut;
2353 vector<int> mysample;
2354 if(subselection!="none") mysample=coll.FindSample(subselection);
2355 TH1F *RcorrJZBeemm = coll.Draw("RcorrJZBeemm",jzbexpr,1,currcut,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2356 TH1F *LcorrJZBeemm = coll.Draw("LcorrJZBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2357 TH1F *RcorrJZBem = coll.Draw("RcorrJZBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2358 TH1F *LcorrJZBem = coll.Draw("LcorrJZBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2359
2360 TH1F *RcorrJZBSBem;
2361 TH1F *LcorrJZBSBem;
2362 TH1F *RcorrJZBSBeemm;
2363 TH1F *LcorrJZBSBeemm;
2364
2365 if(PlottingSetup::RestrictToMassPeak) {
2366 RcorrJZBSBem = coll.Draw("RcorrJZBSBem",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2367 LcorrJZBSBem = coll.Draw("LcorrJZBSBem",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2368 RcorrJZBSBeemm = coll.Draw("RcorrJZBSBeemm",jzbexpr.c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2369 LcorrJZBSBeemm = coll.Draw("LcorrJZBSBeemm",("-("+jzbexpr+")").c_str(),nbins,low,14000, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2370 }
2371
2372 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
2373 if(PlottingSetup::RestrictToMassPeak) {
2374 Bpred->Add(RcorrJZBem,1.0/3.);
2375 Bpred->Add(LcorrJZBem,-1.0/3.);
2376 Bpred->Add(RcorrJZBSBem,1.0/3.);
2377 Bpred->Add(LcorrJZBSBem,-1.0/3.);
2378 Bpred->Add(RcorrJZBSBeemm,1.0/3.);
2379 Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
2380 } else {
2381 Bpred->Add(RcorrJZBem,1.0);
2382 Bpred->Add(LcorrJZBem,-1.0);
2383 }
2384
2385 jzbcutobservation.push_back(RcorrJZBeemm->Integral());
2386 jzbcutprediction.push_back(Bpred->Integral());
2387
2388 delete RcorrJZBeemm;
2389 delete LcorrJZBeemm;
2390 delete RcorrJZBem;
2391 delete LcorrJZBem;
2392 delete RcorrJZBSBem;
2393 delete LcorrJZBSBem;
2394 delete RcorrJZBSBeemm;
2395 delete LcorrJZBSBeemm;
2396
2397 TH1F *MetObs = coll.Draw("MetObs",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity, mysample);
2398 TH1F *MetPred = coll.Draw("MetPred",("met[4]"),nbins,low,14000, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity, mysample);
2399
2400 metcutobservation.push_back(MetObs->Integral());
2401 metcutprediction.push_back(MetPred->Integral());
2402 delete MetObs;
2403 delete MetPred;
2404 }//end of cut loop
2405
2406 //prediction part
2407 if(is_data) cout << "Data prediction & ";
2408 if(subselection!="none") cout << subselection << " prediction &";
2409 for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutprediction[ij] << " vs " << metcutprediction[ij] << " & ";
2410
2411 cout << endl;
2412 //observation part
2413 if(is_data) cout << "Data observation & ";
2414 if(subselection!="none") cout << subselection << " observation &";
2415 for(int ij=0;ij<jzb_cuts.size();ij++) cout << jzbcutobservation[ij] << " vs " << metcutobservation[ij] << " & ";
2416 cout << endl;
2417 cout << "_________________________________________________________________" << endl;
2418 delete cannie;
2419 }
2420
2421 void met_jzb_cut(string datajzb, string mcjzb, vector<float> jzb_cut) {
2422 /*we want a table like this:
2423 __________________ 50 | 100 | ...
2424 | Data prediction | a vs b | a vs b | ...
2425 | Data observed | a vs b | a vs b | ...
2426 --------------------------------------
2427 --------------------------------------
2428 | LM4 prediction | a vs b | a vs b | ...
2429 | LM4 observed | a vs b | a vs b | ...
2430 | LM8 prediction | a vs b | a vs b | ...
2431 | LM8 observed | a vs b | a vs b | ...
2432
2433 where a is the result for a jzb cut at X, and b is the result for a met cut at X
2434 */
2435 make_table(allsamples,datajzb, true,jzb_cut,"none");
2436 make_table(signalsamples,mcjzb, false,jzb_cut,"LM4");
2437 make_table(signalsamples,mcjzb, false,jzb_cut,"LM8");
2438 }
2439
2440
2441 //________________________________________________________________________________________
2442 // JZB Efficiency plot (efficiency of passing reco. JZB cut as function of generator JZB cut)
2443 void JZBSelEff(string mcjzb, TTree* events, string informalname, vector<float> jzb_bins) {
2444
2445 float min = 0, max = 400;
2446 float xbins[] = {min,10,20,30,40,50,60,70,80,90,100,110,120,140,150,160,170,180,190,200,210,220,250,300,max,max+100};
2447 int nbins = sizeof(xbins)/sizeof(float)-1;
2448 int markers[] = { 20, 26, 21, 24, 22, 25, 28 };
2449
2450 TH1F* heff = new TH1F("heff", "JZB eff ; generator-level JZB [GeV]; efficiency",nbins,xbins);
2451 TH1F* hgen = new TH1F("hgen", "JZB gen ; generator-level JZB [GeV]; efficiency",nbins,xbins);
2452 TH1F* hreco = new TH1F("hreco","JZB reco ; generator-level JZB [GeV]; efficiency",nbins,xbins);
2453
2454 TCut kgen(genMassCut&&"genZPt>0&&genNjets>2&&abs(genMID)==23"&&cutOSSF);
2455 TCut kreco(cutmass);
2456
2457 TF1* func = new TF1("func","0.5*[2]*(TMath::Erf((x-[1])/[0])+1)",min,max);
2458 func->SetParNames("epsilon","x_{1/2}","sigma");
2459 func->SetParameter(0,50.);
2460 func->SetParameter(1,0.);
2461 func->SetParameter(2,1.);
2462 gStyle->SetOptStat(0);
2463 gStyle->SetOptFit(0);
2464
2465 TCanvas *can = new TCanvas("can","Canvas for JZB Efficiency",600,600);
2466 can->SetGridx(1);
2467 can->SetGridy(1);
2468 TLegend *leg = make_legend("",0.6,0.2,false,0.89,0.5);
2469
2470
2471
2472 for ( int icut=0; icut<jzb_bins.size(); ++icut ) {
2473
2474 ostringstream selection;
2475 selection << mcjzb << ">" << jzb_bins[icut];
2476 TCut ksel(selection.str().c_str());
2477 events->Draw("genJZB>>hgen", kgen&&kreco, "goff");
2478 events->Draw("genJZB>>hreco",kgen&&kreco&&ksel,"goff");
2479
2480 // Loop over steps to get efficiency curve
2481 for ( Int_t iBin = 0; iBin<nbins-1; ++iBin ) {
2482 Float_t eff = hreco->GetBinContent(iBin+1)/hgen->GetBinContent(iBin+1);
2483 heff->SetBinContent(iBin+1,eff);
2484 heff->SetBinError(iBin+1,TMath::Sqrt(eff*(1-eff)/hgen->GetBinContent(iBin+1)));
2485 }
2486
2487 heff->GetXaxis()->SetRangeUser(min, max);
2488 heff->SetMarkerStyle(markers[icut]);
2489 heff->Fit("func","Q+","same");
2490
2491 // Print values
2492 dout << "+++ For " << selection.str() << std::endl;
2493 for ( int i=0; i<func->GetNpar(); ++i )
2494 dout << " " << func->GetParName(i) << " " << func->GetParameter(i) << " \\pm " << func->GetParError(i) << std::endl;
2495 char hname[256]; sprintf(hname,"heff%d",icut);
2496
2497 // Store plot
2498 TH1F* h = (TH1F*)heff->Clone(hname);
2499 if ( icut) h->Draw("same");
2500 else h->Draw();
2501 char htitle[256]; sprintf(htitle,"JZB > %3.0f GeV", jzb_bins[icut]);
2502 leg->AddEntry(h,htitle,"p");
2503
2504 }
2505
2506 leg->Draw();
2507 DrawMCPrelim(0.0);
2508 CompleteSave(can, "Systematics/jzb_efficiency_curve"+informalname );
2509
2510 delete hgen;
2511 delete hreco;
2512 delete heff;
2513 }
2514
2515 //________________________________________________________________________________________
2516 // Calls the above function for each signal sample
2517 void plot_jzb_sel_eff(string mcjzb, samplecollection &signalsamples, vector<float> bins )
2518 {
2519 for (int isignal=0; isignal<signalsamples.collection.size();isignal++) {
2520 dout << "JZB selection efficiency curve: " << std::endl;
2521 JZBSelEff(mcjzb,(signalsamples.collection)[isignal].events,(signalsamples.collection)[isignal].samplename,bins); // Only for some selected samples
2522 }
2523 }
2524
2525
2526 void test() {
2527
2528 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
2529 testcanv->cd();
2530 switch_overunderflow(true);
2531 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
2532 switch_overunderflow(false);
2533 ptdistr->Draw();
2534 testcanv->SaveAs("test.png");
2535 dout << "HELLO there!" << endl;
2536
2537 }