ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.94
Committed: Tue Nov 8 08:42:06 2011 UTC (13 years, 6 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.93: +7 -8 lines
Log Message:
Saving to template updated for BZJ

File Contents

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