ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.121
Committed: Wed Apr 18 12:29:07 2012 UTC (13 years ago) by fronga
Content type: text/plain
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, HEAD
Changes since 1.120: +48 -32 lines
Log Message:
Changes for the paper (merged with HEAD).

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