ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.108
Committed: Tue Dec 6 09:43:57 2011 UTC (13 years, 5 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.107: +46 -6 lines
Log Message:
Fixed lines for mll plot (showing the Z peak window); added a plot showing the composition of the background prediction (for data) in a colorful way; adapted lower boundary of Bpred plots (MC and MC w/ S)

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