ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.43
Committed: Thu Aug 25 10:30:44 2011 UTC (13 years, 8 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.42: +3 -3 lines
Log Message:
Adapted ttbar ratio plot as well to conform with official notation

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4    
5     #include <TCut.h>
6     #include <TROOT.h>
7     #include <TCanvas.h>
8     #include <TMath.h>
9     #include <TColor.h>
10     #include <TPaveText.h>
11     #include <TRandom.h>
12     #include <TH1.h>
13     #include <TH2.h>
14     #include <TF1.h>
15     #include <TSQLResult.h>
16 buchmann 1.13 #include <TProfile.h>
17 fronga 1.24 #include <TLegendEntry.h>
18 buchmann 1.1
19 buchmann 1.9 //#include "TTbar_stuff.C"
20 buchmann 1.1 using namespace std;
21    
22     using namespace PlottingSetup;
23    
24 buchmann 1.22 void todo() {
25     dout << "My to do list: " << endl;
26 buchmann 1.38 dout << " - ExperimentalModule::Poisson_ratio_plot : Get the second part to work!" << endl;
27 buchmann 1.22 dout << " - update script for limits " << endl;
28     dout << " - get expected and observed limits, get sigma (edit the current table)" << endl;
29     }
30    
31 buchmann 1.1 void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result)
32     {
33 buchmann 1.21 TCanvas *tempcan = new TCanvas("tempcan","Temporary canvas for peak finding preparations");
34 buchmann 1.17 TH1F *rawJZBeemmMC = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
35     TH1F *rawJZBeemmData = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
36     TH1F *rawJZBemMC = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
37     TH1F *rawJZBemData = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
38 buchmann 1.1 TH1F *rawttbarjzbeemmMC;
39    
40     if(method==doKM) {
41     //we only need this histo for the KM fitting...
42 buchmann 1.17 rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
43 buchmann 1.1 MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
44     DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
45     }
46     else {
47     TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
48     TH1F *reducedData = (TH1F*)rawJZBeemmData->Clone();
49     reducedMC->Add(rawJZBemMC,-1);
50     reducedData->Add(rawJZBemData,-1);
51     //this is Kostas' way of doing it - we subtract em to get rid of some of the ttbar contribution (in reality, of flavor-symmetric contribution)
52     MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
53     DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
54 buchmann 1.11
55 buchmann 1.1 }
56 buchmann 1.11
57 buchmann 1.1
58     // MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
59     // DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
60 buchmann 1.21 dout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
61 buchmann 1.1 result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
62 buchmann 1.21 dout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
63 buchmann 1.1 result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
64     }
65    
66     void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
67    
68     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
69    
70     TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
71     THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
72 fronga 1.24 TH1F *datahistoOSOF = allsamples.Draw("datahistoOSOF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
73 buchmann 1.1
74     if(logscale) ckin->SetLogy(1);
75 buchmann 1.17 datahistoOSSF->SetMarkerSize(DataMarkerSize);
76 buchmann 1.1 datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
77     datahistoOSSF->GetXaxis()->CenterTitle();
78     datahistoOSSF->GetYaxis()->SetTitle("events");
79     datahistoOSSF->GetYaxis()->CenterTitle();
80 buchmann 1.17 datahistoOSOF->SetMarkerSize(DataMarkerSize);
81     datahistoOSSF->SetMarkerSize(DataMarkerSize);
82 buchmann 1.1 datahistoOSSF->Draw();
83 fronga 1.24
84 buchmann 1.1 mcstackOSSF.Draw("same");
85     datahistoOSSF->Draw("same");
86 fronga 1.24
87     datahistoOSOF->SetMarkerColor(kRed);
88     datahistoOSOF->SetLineColor(kRed);
89 buchmann 1.17 datahistoOSOF->SetMarkerStyle(21);
90 buchmann 1.1 datahistoOSOF->Draw("same");
91 fronga 1.24
92     // Try to re-arrange legend...
93     TLegend *bgleg = allsamples.allbglegend("",datahistoOSSF);
94     TLegend *kinleg = make_legend();
95 fronga 1.41 kinleg->AddEntry(datahistoOSSF,"SF (data)","p");
96     kinleg->AddEntry(datahistoOSOF,"OF (data)","p");\
97 fronga 1.24 TIter next(bgleg->GetListOfPrimitives());
98     TObject* obj;
99     // Copy the nice bkgd legend skipping the "data"
100     while ( obj = next() )
101     if ( strcmp(((TLegendEntry*)obj)->GetObject()->GetName(),"datahistoOSSF") )
102     kinleg->GetListOfPrimitives()->Add(obj);
103    
104 buchmann 1.1 kinleg->Draw();
105     CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
106 buchmann 1.18
107     delete datahistoOSOF;
108     delete datahistoOSSF;
109 buchmann 1.34 delete ckin;
110 buchmann 1.1 }
111    
112    
113 fronga 1.35 void draw_ratio_plot(TH1* hdata, THStack& hmc, float ymin=0.5, float ymax=1.5) {
114    
115     // Make a histogram from stack
116     TIter next(hmc.GetHists());
117     TObject* obj;
118     TH1* hratio = NULL;
119     while ( obj = next() ) {
120     if ( !hratio ) {
121     hratio = (TH1*)obj->Clone();
122     hratio->SetName("hratio");
123     } else hratio->Add( (TH1*)obj );
124     }
125     hratio->Divide(hdata);
126     hratio->SetMaximum(ymax);
127     hratio->SetMinimum(ymin);
128     hratio->SetMarkerStyle(2);
129     hratio->SetLineWidth(1);
130    
131     TPad* rpad = new TPad("rpad","",0.15,0.7,0.4,0.9);
132     rpad->Draw();
133     rpad->cd();
134     hratio->Draw("e1x0");
135    
136     TF1* oneline = new TF1("","1.0",0,1000);
137     oneline->SetLineColor(kBlue);
138     oneline->SetLineStyle(1);
139     oneline->SetLineWidth(1);
140     oneline->Draw("same");
141    
142     }
143    
144 fronga 1.25 void make_kin_plot(string variable, int nbins, float min, float max, bool logscale,
145 fronga 1.35 string xlabel, string filename, bool isPF=true, bool plotratio=false ) {
146 buchmann 1.1 // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
147     TCut ibasiccut=basiccut;
148    
149     if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
150     //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
151     if(isPF) {
152     if(variable=="mll") variable="pfmll[0]";
153     if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
154     if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
155     if(variable=="pt") variable="pfpt[0]";
156     if(variable=="pt1") variable="pfpt1[0]";
157 buchmann 1.19 if(variable=="pt2") variable="pfpt2[0]";
158 buchmann 1.1 if(variable=="eta1") variable="pfeta1[0]";
159     if(variable=="jzb[1]") variable="pfjzb[0]";
160     //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
161     }
162    
163     //Step 2: Refine the cut
164     TCut cut;
165     cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
166     if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
167     if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
168     if(filename=="mll") cut=cutOSSF&&cutnJets&&ibasiccut;
169 buchmann 1.18 if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
170     if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
171 buchmann 1.17 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
172 buchmann 1.18 if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
173     if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
174 buchmann 1.1 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut;
175    
176 fronga 1.25 TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
177     ckin->SetLogy(logscale);
178 buchmann 1.1 TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
179 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
180 buchmann 1.1 THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
181     if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
182     if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
183     if(filename=="mll_inclusive") datahisto->SetMinimum(1);
184     datahisto->Draw("e1");
185     mcstack.Draw("same");
186     datahisto->Draw("same,e1");
187     TLegend *kinleg = allsamples.allbglegend();
188     kinleg->Draw();
189 buchmann 1.16 TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
190 buchmann 1.1 write_cut->Draw();
191     TText* write_variable = write_text(0.99,0.01,variable);
192     write_variable->SetTextAlign(31);
193     write_variable->SetTextSize(0.02);
194 fronga 1.35
195     if ( plotratio ) draw_ratio_plot( datahisto, mcstack );
196    
197 buchmann 1.17 // write_variable->Draw();
198 buchmann 1.1 if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
199     else CompleteSave(ckin,"kin/"+filename);
200     datahisto->Delete();
201     }
202    
203     void do_kinematic_plots(bool doPF=false)
204     {
205     bool dolog=true;
206     bool nolog=false;
207 fronga 1.35 make_kin_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll",doPF,true);
208 fronga 1.25 make_kin_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll_ee",doPF);
209     make_kin_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll_mm",doPF);
210 fronga 1.35 make_kin_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive",doPF,true);
211     make_kin_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF,true);
212     make_kin_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF,true);
213 fronga 1.25 make_kin_plot("mll",300,50,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
214     make_kin_plot("jetpt[0]",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
215     make_kin_plot("jeteta[0]",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
216     make_kin_plot("pt",50,0,200,dolog,"Z p_{T} [GeV]","Zpt",doPF);
217     make_kin_plot("pt1",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
218     make_kin_plot("pt2",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
219     make_kin_plot("eta1",40,-5,5,nolog,"#eta_{l}","eta",doPF);
220     make_kin_plot("jzb[1]",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
221     make_kin_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets",doPF);
222     make_kin_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
223 buchmann 1.17 make_special_mll_plot(30,50,150,dolog,"m_{ll} [GeV]");
224 buchmann 1.1 }
225    
226 fronga 1.25 void make_comp_plot( string var, string xlabel, string filename, string mcjzb, string datajzb,
227     int nbins, float xmin, float xmax, bool log,
228 fronga 1.26 float ymin=0, float ymax=0, bool leftJustified=false ) {
229 fronga 1.25
230     TCut jzbData[]= { TCut(TString(datajzb+">100")),TCut(TString(datajzb+"<-100")) };
231     TCut jzbMC[] = { TCut(TString(mcjzb+">100")),TCut(TString(mcjzb+"<-100")) };
232    
233     string sRegions[] = { "SFZP","OFZP","SFSB","OFSB" };
234     TCut kRegions[] = { cutOSSF&&cutnJets&&cutmass, cutOSOF&&cutnJets&&cutmass,
235     cutOSSF&&cutnJets&&sidebandcut, cutOSOF&&cutnJets&&sidebandcut };
236    
237     for ( int iregion=0; iregion<4; ++iregion )
238     for ( int ijzb=0; ijzb<2; ++ijzb ) {
239     TCanvas *ccomp = new TCanvas("ccomp","Comparison plot",600,400);
240     ccomp->SetLogy(log);
241     TH1F *datahisto = allsamples.Draw("datahisto", var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbData[ijzb],data,luminosity);
242     THStack mcstack = allsamples.DrawStack("mcstack",var,nbins,xmin,xmax,xlabel,"events",kRegions[iregion]&&jzbMC[ijzb], mc, luminosity);
243     datahisto->SetMarkerSize(DataMarkerSize);
244     if (ymax>ymin) datahisto->SetMaximum(ymax);
245     datahisto->Draw("e1");
246     mcstack.Draw("same");
247     datahisto->Draw("same,e1");
248     TLegend *kinleg = allsamples.allbglegend((sRegions[iregion]+(ijzb?"neg":"pos")).c_str());
249 fronga 1.26 if ( leftJustified ) {
250     Float_t w = kinleg->GetX2()-kinleg->GetX1();
251     kinleg->SetX1(0.2);
252     kinleg->SetX2(0.2+w);
253     }
254 fronga 1.25 kinleg->Draw();
255     TText* write_variable = write_text(0.99,0.01,var);
256     write_variable->SetTextAlign(31);
257     write_variable->SetTextSize(0.02);
258     ccomp->RedrawAxis();
259     CompleteSave(ccomp,"compare/"+filename+sRegions[iregion]+(ijzb?"neg":"pos"));
260 buchmann 1.27 delete datahisto;
261 buchmann 1.34 delete ccomp;
262 fronga 1.25 }
263     }
264    
265    
266     void region_comparison_plots(string mcjzb, string datajzb) {
267     dout << "Creating comparison plots for signal and control regions" << endl;
268     // Compare a few quantities in the signal region and all 7 control regions
269     make_comp_plot("mll","m_{ll} [GeV]","mll",mcjzb,datajzb,30,50,170,false,0,10.);
270 fronga 1.26 make_comp_plot("met[4]","pfMET [GeV]","pfmet",mcjzb,datajzb,18,0,360,false,0,10.);
271 fronga 1.35 make_comp_plot("pfJetGoodNum","#(jets)","njets",mcjzb,datajzb,10,0,10, false,0,25.);
272     make_comp_plot("pt","Z p_{T} [GeV]","Zpt",mcjzb,datajzb,26,0,525,false,0.,12.);
273     make_comp_plot("numVtx","#(prim. vertices)","nvtx",mcjzb,datajzb,15,0.,15.,false,0,12.);
274     make_comp_plot("TMath::Abs(dphi)","#Delta#phi(leptons)","dphilep",mcjzb,datajzb,10,0.,3.1415,false,0,12.,true);
275     make_comp_plot("TMath::Abs(dphi_sumJetVSZ[1])","#Delta#phi(Z,jets)","dphiZjets",mcjzb,datajzb,10,0.,3.1415,false,0,12.,true);
276 fronga 1.25
277     }
278    
279 buchmann 1.1 void do_kinematic_PF_plots()
280     {
281     do_kinematic_plots(true);
282     }
283    
284 buchmann 1.11 void signal_bg_comparison()
285 buchmann 1.1 {
286 buchmann 1.11 TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
287 buchmann 1.1 int sbg_nbins=100;
288 fronga 1.35 float sbg_min=-110;
289     float sbg_max=jzbHigh;
290 buchmann 1.1 can->SetLogy(1);
291 buchmann 1.17 TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("DYJetsToLL"));
292     TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("LM4"));
293     TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
294 buchmann 1.1
295     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
296     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
297     JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
298     JZBplotZJETs->SetLineColor(kBlack);
299     JZBplotLM4->SetLineStyle(2);
300 buchmann 1.39 JZBplotZJETs->SetMaximum(JZBplotZJETs->GetMaximum()*5);
301     JZBplotZJETs->SetMinimum(1);
302     JZBplotZJETs->DrawNormalized("histo");
303     JZBplotLM4->DrawNormalized("histo,same");
304     JZBplotTtbar->DrawNormalized("histo,same");
305     TLegend *signal_bg_comparison_leg2 = make_legend("MC (unit normalized):");
306 buchmann 1.1 signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
307     signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
308     signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
309     signal_bg_comparison_leg2->Draw();
310 buchmann 1.39 CompleteSave(can,"jzb_bg_vs_signal_distribution");
311 buchmann 1.31
312     //TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-200)<5)&&(TMath::Abs(MassLSP-175)<5))",mc,luminosity,scansample.FindSample("t"));
313     TH1F *JZBplotSMS1 = scansample.Draw("JZBplotSMS1",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-200)<5)&&(TMath::Abs(MassLSP-100)<5))",mc,luminosity,scansample.FindSample("t"));
314     JZBplotZJETs->SetMinimum(0.004);
315     JZBplotZJETs->Draw("histo");
316     JZBplotSMS1->Scale(2*JZBplotLM4->Integral()/JZBplotSMS1->Integral());
317     JZBplotSMS1->Draw("histo,same");
318     JZBplotTtbar->Draw("histo,same");
319     TLegend *signal_bg_comparison_leg3 = make_legend("MC:");
320     signal_bg_comparison_leg3->SetX1(0.55);
321     signal_bg_comparison_leg3->AddEntry(JZBplotZJETs,"Z+Jets","f");
322     signal_bg_comparison_leg3->AddEntry(JZBplotTtbar,"t#bar{t}","f");
323     // signal_bg_comparison_leg3->AddEntry(JZBplotSMS1,"SMS,m_{gluon}=200,m_{lsp}=175 GeV","f");
324     signal_bg_comparison_leg3->AddEntry(JZBplotSMS1,"SMS,#Deltam=100 GeV","f");
325     signal_bg_comparison_leg3->AddEntry(JZBplotSMS1,"","");
326     signal_bg_comparison_leg3->AddEntry(JZBplotSMS1,"","");
327    
328     signal_bg_comparison_leg3->Draw();
329     CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__mglu200_mlsp100");
330    
331     TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-425)<5)&&(TMath::Abs(MassLSP-225)<5))",mc,luminosity,scansample.FindSample("t"));
332     // TH1F *JZBplotSMS2 = scansample.Draw("JZBplotSMS2",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-425)<5)&&(TMath::Abs(MassLSP-225)<5))",mc,luminosity);
333     JZBplotZJETs->SetMinimum(0.004);
334     JZBplotZJETs->Draw("histo");
335     JZBplotSMS2->Scale(JZBplotLM4->Integral()/JZBplotSMS2->Integral());
336     JZBplotSMS2->Draw("histo,same");
337     JZBplotTtbar->Draw("histo,same");
338     TLegend *signal_bg_comparison_leg4 = make_legend("MC:");
339     signal_bg_comparison_leg4->SetX1(0.55);
340     signal_bg_comparison_leg4->AddEntry(JZBplotZJETs,"Z+Jets","f");
341     signal_bg_comparison_leg4->AddEntry(JZBplotTtbar,"t#bar{t}","f");
342     // signal_bg_comparison_leg4->AddEntry(JZBplotSMS1,"SMS,m_{gluon}=600,m_{lsp}=400 GeV","f");
343     signal_bg_comparison_leg4->AddEntry(JZBplotSMS1,"SMS,#Deltam=200 GeV","f");
344     signal_bg_comparison_leg4->AddEntry(JZBplotSMS1,"","");
345     signal_bg_comparison_leg4->AddEntry(JZBplotSMS1,"","");
346     signal_bg_comparison_leg4->Draw();
347     CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__mglu425_mlsp225");
348    
349     TH1F *JZBplotSMS3 = scansample.Draw("JZBplotSMS3",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-950)<5)&&(TMath::Abs(MassLSP-150)<5))",mc,luminosity,scansample.FindSample("t"));
350     JZBplotZJETs->SetMinimum(0.004);
351     JZBplotZJETs->Draw("histo");
352     JZBplotSMS3->Scale(JZBplotLM4->Integral()/JZBplotSMS3->Integral());
353     JZBplotSMS3->Draw("histo,same");
354     JZBplotTtbar->Draw("histo,same");
355     TLegend *signal_bg_comparison_leg5 = make_legend("MC:");
356     signal_bg_comparison_leg5->SetX1(0.55);
357     signal_bg_comparison_leg5->AddEntry(JZBplotZJETs,"Z+Jets","f");
358     signal_bg_comparison_leg5->AddEntry(JZBplotTtbar,"t#bar{t}","f");
359     signal_bg_comparison_leg5->AddEntry(JZBplotSMS1,"SMS,#Deltam=800 GeV","f");
360     signal_bg_comparison_leg5->AddEntry(JZBplotSMS1,"","");
361     signal_bg_comparison_leg5->AddEntry(JZBplotSMS1,"","");
362     // signal_bg_comparison_leg5->AddEntry(JZBplotSMS1,"SMS,m_{gluon}=900,m_{lsp}=100 GeV","f");
363     signal_bg_comparison_leg5->Draw();
364     CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__mglu950_mlsp150");
365    
366     TH1F *JZBplotSMS4 = scansample.Draw("JZBplotSMS4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets&&"((TMath::Abs(MassGlu-750)<5)&&(TMath::Abs(MassLSP-350)<5))",mc,luminosity,scansample.FindSample("t"));
367     JZBplotSMS4->Scale(JZBplotLM4->Integral()/JZBplotSMS4->Integral());
368     JZBplotZJETs->SetMinimum(0.004);
369     JZBplotZJETs->Draw("histo");
370     JZBplotSMS1->SetLineColor(kRed);
371     JZBplotSMS2->SetLineColor(kBlue);
372     JZBplotSMS3->SetLineColor(kRed);
373     JZBplotSMS4->SetLineColor(kBlue);
374     JZBplotSMS3->SetLineStyle(2);
375     JZBplotSMS4->SetLineStyle(2);
376    
377     JZBplotSMS1->Draw("histo,same");
378     JZBplotSMS2->Draw("histo,same");
379     JZBplotSMS3->Draw("histo,same");
380     JZBplotSMS4->Draw("histo,same");
381     JZBplotTtbar->Draw("histo,same");
382     TLegend *signal_bg_comparison_leg6 = make_legend("MC:");
383     signal_bg_comparison_leg6->SetX1(0.55);
384     signal_bg_comparison_leg6->AddEntry(JZBplotZJETs,"Z+Jets","f");
385     signal_bg_comparison_leg6->AddEntry(JZBplotTtbar,"t#bar{t}","f");
386     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"SMS,#Deltam=100 GeV","f");
387     signal_bg_comparison_leg6->AddEntry(JZBplotSMS2,"SMS,#Deltam=200 GeV","f");
388     signal_bg_comparison_leg6->AddEntry(JZBplotSMS4,"SMS,#Deltam=400 GeV","f");
389     signal_bg_comparison_leg6->AddEntry(JZBplotSMS3,"SMS,#Deltam=800 GeV","f");
390     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
391     signal_bg_comparison_leg6->AddEntry(JZBplotSMS1,"","");
392     signal_bg_comparison_leg6->Draw();
393     CompleteSave(can,"jzb_bg_vs_signal_distribution_SMS__summary");
394    
395    
396 buchmann 1.1 }
397    
398 buchmann 1.9 vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
399     TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
400 buchmann 1.1 BpredFunc->SetParameter(0,histo->GetBinContent(1));
401 buchmann 1.6 if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
402 buchmann 1.1 BpredFunc->SetParameter(1,0.);
403     if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
404     else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
405     if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
406     BpredFunc->SetParameter(3,1.8);
407     BpredFunc->SetParameter(4,2.5);
408 buchmann 1.11 histo->Fit(BpredFunc,"QN0");
409 buchmann 1.1 BpredFunc->SetLineColor(kBlue);
410    
411 buchmann 1.9 TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
412     TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
413 buchmann 1.1
414     BpredFuncP->SetParameters(BpredFunc->GetParameters());
415     BpredFuncP->SetLineColor(kBlue);
416     BpredFuncP->SetLineStyle(2);
417    
418     BpredFuncN->SetParameters(BpredFunc->GetParameters());
419     BpredFuncN->SetLineColor(kBlue);
420     BpredFuncN->SetLineStyle(2);
421 buchmann 1.9
422     vector<TF1*> functions;
423     functions.push_back(BpredFuncN);
424     functions.push_back(BpredFunc);
425     functions.push_back(BpredFuncP);
426     return functions;
427 buchmann 1.1 }
428 buchmann 1.38
429    
430     TF1* do_logpar_fit_to_plot(TH1F *osof) {
431     TCanvas *logpar_fit_can = new TCanvas("logpar_fit_can","Fit canvas for LogPar");
432 buchmann 1.39 TF1 *logparfunc = new TF1("logparfunc",LogParabola,0,300,3);
433 buchmann 1.38 TF1 *logparfunc2 = new TF1("logparfunc2",LogParabola,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
434     TF1 *logparfuncN = new TF1("logparfuncN",LogParabolaN,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
435     TF1 *logparfuncP = new TF1("logparfuncP",LogParabolaP,0,(osof->GetXaxis()->GetBinLowEdge(osof->GetNbinsX())+osof->GetXaxis()->GetBinWidth(osof->GetNbinsX())),3);
436     osof->SetMinimum(0);
437     osof->Fit(logparfunc,"QR");
438     osof->Draw();
439     logparfunc->SetLineWidth(2);
440     logparfunc2->SetParameters(logparfunc->GetParameters());
441     logparfuncN->SetParameters(logparfunc->GetParameters());
442     logparfuncP->SetParameters(logparfunc->GetParameters());
443     stringstream fitinfo;
444     fitinfo << "#Chi^{2} / NDF : " << logparfunc->GetChisquare() << " / " << logparfunc->GetNDF();
445     TText *writefitinfo = write_text(0.8,0.8,fitinfo.str());
446     writefitinfo->SetTextSize(0.03);
447     DrawPrelim();
448     writefitinfo->Draw();
449     logparfunc->Draw("same");
450     logparfunc2->Draw("same");
451     logparfuncN->SetLineStyle(2);
452     logparfuncP->SetLineStyle(2);
453     logparfuncN->Draw("same");
454     logparfuncP->Draw("same");
455 buchmann 1.39 CompleteSave(logpar_fit_can,"Bpred_Data_LogPar_Fit_To_TTbarPred");
456 buchmann 1.38 delete logpar_fit_can;
457     return logparfunc2;
458     }
459    
460 buchmann 1.42 vector<TF1*> do_extended_fit_to_plot(TH1F *prediction, TH1F *Tprediction, TH1F *ossf, TH1F *osof,int isdata) {
461 buchmann 1.38 /* there are mainly two background contributions: Z+Jets (a) and ttbar (b). So:
462     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.
463     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.
464     Once we have these two components, we use the combined parameters to get the final function and we're done.
465     */
466     //Step 1: take the OSSF prediction - OSOF prediction, and fit a crystal ball function to it
467     TH1F *step1cb = (TH1F*)ossf->Clone("step1cb");
468     step1cb->Add(osof,-1);
469     vector<TF1*> functions = do_cb_fit_to_plot(step1cb,PlottingSetup::JZBPeakWidthData);
470     TF1 *zjetscrystalball = functions[1];
471    
472     //Step 2: use the OSOF distribution and look at the [10,100] GeV JZB range, and fit our log parabola
473 buchmann 1.39 // TH1F *ttbarprediction=(TH1F*)prediction->Clone("ttbarprediction");
474     // ttbarprediction->Add(ossf,-1);//without the Z+Jets estimate, this is really just the ttbar estimate!
475     // 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)
476     TF1 *ttbarlogpar = do_logpar_fit_to_plot(Tprediction);
477     ttbarlogpar->SetParameter(0,1.0/3*ttbarlogpar->GetParameter(0));//correcting for the fact that we didn't multiply with (1.0/3);
478    
479 buchmann 1.38 TF1 *ttbarlogparP = new TF1("ttbarlogparP",LogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
480     TF1 *ttbarlogparN = new TF1("ttbarlogparN",LogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
481    
482     //and now fuse the two!
483     TF1 *kmlp = new TF1("kmlp", CrystalBallPlusLogParabola, 0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
484     TF1 *kmlpP= new TF1("kmlpP",CrystalBallPlusLogParabolaP,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
485     TF1 *kmlpN= new TF1("kmlpN",CrystalBallPlusLogParabolaN,0,(prediction->GetXaxis()->GetBinLowEdge(prediction->GetNbinsX())+prediction->GetXaxis()->GetBinWidth(prediction->GetNbinsX())),8);
486     double kmlp_pars[10];
487     for(int i=0;i<5;i++) kmlp_pars[i]=zjetscrystalball->GetParameter(i);
488     for(int i=0;i<3;i++) kmlp_pars[5+i]=ttbarlogpar->GetParameter(i);
489     ttbarlogparP->SetParameters(ttbarlogpar->GetParameters());
490     ttbarlogparN->SetParameters(ttbarlogpar->GetParameters());
491     kmlp->SetParameters(kmlp_pars);
492 buchmann 1.39 prediction->Fit(kmlp,"Q");//fitting the final result (done this in the past but kicked it)
493     kmlpP->SetParameters(kmlp->GetParameters());
494     kmlpN->SetParameters(kmlp->GetParameters());
495 buchmann 1.38
496     // now that we're done, let's save all of this so we can have a look at it afterwards.
497     TCanvas *can = new TCanvas("can","Prediction Fit Canvas");
498     can->SetLogy(1);
499     prediction->SetMarkerColor(kRed);
500     prediction->Draw();
501    
502     kmlp->SetLineColor(TColor::GetColor("#04B404"));
503     kmlpP->SetLineColor(TColor::GetColor("#04B404"));
504     kmlpN->SetLineColor(TColor::GetColor("#04B404"));
505     kmlp->Draw("same");
506     kmlpN->SetLineStyle(2);
507     kmlpP->SetLineStyle(2);
508     kmlpN->Draw("same");
509     kmlpP->Draw("same");
510    
511     ttbarlogpar->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
512     ttbarlogpar->Draw("same");
513     ttbarlogparP->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
514     ttbarlogparN->SetLineColor(TColor::GetColor("#CC2EFA"));//purple
515     ttbarlogparP->SetLineStyle(2);
516     ttbarlogparN->SetLineStyle(2);
517     ttbarlogparP->Draw("same");
518     ttbarlogparN->Draw("same");
519    
520     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
521    
522     TLegend *analyticalBpredLEG = make_legend("",0.5,0.55);
523     analyticalBpredLEG->AddEntry(prediction,"predicted","p");
524     analyticalBpredLEG->AddEntry(functions[1],"Crystal Ball fit","l");
525     analyticalBpredLEG->AddEntry(functions[0],"1#sigma Crystal Ball fit","l");
526     analyticalBpredLEG->AddEntry(ttbarlogparN,"TTbar fit","l");
527     analyticalBpredLEG->AddEntry(ttbarlogpar,"1#sigma TTbar fit","l");
528     analyticalBpredLEG->AddEntry(kmlp,"Combined function","l");
529     analyticalBpredLEG->AddEntry(kmlpN,"1#sigma combined function","l");
530     analyticalBpredLEG->Draw("same");
531    
532 buchmann 1.42 if(isdata==0) CompleteSave(can,"MakingOfBpredFunction/Bpred_MC_Analytical_Function_Composition");
533     if(isdata==1) CompleteSave(can,"MakingOfBpredFunction/Bpred_data_Analytical_Function_Composition");
534     if(isdata==2) CompleteSave(can,"MakingOfBpredFunction/Bpred_MCBnS_Analytical_Function_Composition");
535 buchmann 1.38 delete can;
536    
537     //and finally: prep return functions
538     vector<TF1*> return_functions;
539     return_functions.push_back(kmlpN);
540     return_functions.push_back(kmlp);
541     return_functions.push_back(kmlpP);
542    
543     return_functions.push_back(ttbarlogparN);
544     return_functions.push_back(ttbarlogpar);
545     return_functions.push_back(ttbarlogparP);
546    
547     return_functions.push_back(functions[0]);
548     return_functions.push_back(functions[1]);
549     return_functions.push_back(functions[2]);
550    
551     return return_functions;
552     }
553    
554 fronga 1.24 void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, bool is_data, bool overlay_signal = false )
555 buchmann 1.1 {
556     int nbins=100;
557     if(is_data) nbins=50;
558     float low=0;
559     float hi=500;
560    
561 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
562     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
563     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
564     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
565 buchmann 1.1
566 buchmann 1.17 TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
567     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
568 buchmann 1.13
569 buchmann 1.17 TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
570     TH1F *LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
571 buchmann 1.13
572 buchmann 1.17 TH1F *lm4RcorrJZBeemm = allsamples.Draw("lm4RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity,allsamples.FindSample("LM4"));
573 buchmann 1.13
574 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
575 fronga 1.24 Bpred->Add(RcorrJZBem,1.0/3.);
576     Bpred->Add(LcorrJZBem,-1.0/3.);
577     Bpred->Add(RcorrJZBSBem,1.0/3.);
578     Bpred->Add(LcorrJZBSBem,-1.0/3.);
579     Bpred->Add(RcorrJZBSBeemm,1.0/3.);
580     Bpred->Add(LcorrJZBSBeemm,-1.0/3.);
581 buchmann 1.39
582     TH1F *Tpred = (TH1F*)RcorrJZBem->Clone("Bpred");
583     Tpred->Add(LcorrJZBem,-1.0);
584     Tpred->Add(RcorrJZBSBem,1.0);
585     Tpred->Add(LcorrJZBSBem,-1.0);
586     Tpred->Add(RcorrJZBSBeemm,1.0);
587     Tpred->Add(LcorrJZBSBeemm,-1.0);
588    
589 buchmann 1.1 globalcanvas->cd();
590     globalcanvas->SetLogy(1);
591 fronga 1.24
592     RcorrJZBeemm->SetMarkerStyle(20);
593     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
594     RcorrJZBeemm->Draw("e1x0");
595    
596 buchmann 1.1 Bpred->SetLineColor(kRed);
597     Bpred->SetStats(0);
598 fronga 1.24 Bpred->Draw("hist,same");
599    
600     if ( overlay_signal ) {
601     lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
602     lm4RcorrJZBeemm->Draw("histo,same");
603     }
604 buchmann 1.17 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
605 buchmann 1.13
606 fronga 1.24 TLegend *legBpred = make_legend("",0.6,0.55);
607 buchmann 1.1 if(is_data)
608     {
609 buchmann 1.42 vector<TF1*> analytical_function = do_extended_fit_to_plot(Bpred,Tpred,LcorrJZBeemm,LcorrJZBem,is_data);
610 buchmann 1.38 globalcanvas->cd();
611     analytical_function[0]->Draw("same"); analytical_function[1]->Draw("same");analytical_function[2]->Draw("same");
612 fronga 1.24 legBpred->AddEntry(RcorrJZBeemm,"observed","p");
613     legBpred->AddEntry(Bpred,"predicted","l");
614 buchmann 1.38 legBpred->AddEntry(analytical_function[1],"predicted fit","l");
615     legBpred->AddEntry(analytical_function[2],"stat. uncert.","l");
616 fronga 1.24 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
617 buchmann 1.1 legBpred->Draw();
618     CompleteSave(globalcanvas,"Bpred_Data");
619     }
620     else {
621 fronga 1.24 legBpred->AddEntry(RcorrJZBeemm,"MC observed","p");
622     legBpred->AddEntry(Bpred,"MC predicted","l");
623 buchmann 1.29 legBpred->AddEntry((TObject*)0,"",""); // Just for alignment // causes seg fault on root v5.18
624 buchmann 1.28 // legBpred->AddEntry((TObject*)0,"",""); // causes seg fault on root v5.18
625 fronga 1.24 if ( overlay_signal ) legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
626 buchmann 1.1 legBpred->Draw();
627 buchmann 1.13
628 buchmann 1.1 CompleteSave(globalcanvas,"Bpred_MC");
629     }
630 buchmann 1.13
631 buchmann 1.28 TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone("Bpredem");
632 buchmann 1.13 Bpredem->Add(RcorrJZBem);
633     Bpredem->Add(LcorrJZBem,-1);
634 buchmann 1.28 TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone("BpredSBem");
635 buchmann 1.13 BpredSBem->Add(RcorrJZBSBem);
636     Bpred->Add(LcorrJZBSBem,-1);
637 buchmann 1.28 TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone("BpredSBeemm");
638 buchmann 1.17 BpredSBeemm->Add(RcorrJZBSBeemm);
639     BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
640 buchmann 1.13 globalcanvas->cd();
641     globalcanvas->SetLogy(1);
642 fronga 1.24
643     RcorrJZBeemm->SetMarkerStyle(20);
644     RcorrJZBeemm->GetXaxis()->SetRangeUser(0,high);
645     RcorrJZBeemm->Draw("e1x0");
646     RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
647    
648     Bpredem->SetLineColor(kRed+1);
649 buchmann 1.13 Bpredem->SetStats(0);
650 fronga 1.24 Bpredem->Draw("hist,same");
651    
652     BpredSBem->SetLineColor(kGreen+2);//TColor::GetColor("#0B6138"));
653     BpredSBem->SetLineStyle(2);
654 buchmann 1.13 BpredSBem->Draw("hist,same");
655 fronga 1.24
656     BpredSBeemm->SetLineColor(kBlue+1);
657     BpredSBeemm->SetLineStyle(3);
658 buchmann 1.13 BpredSBeemm->Draw("hist,same");
659 fronga 1.24
660     TLegend *legBpredc = make_legend("",0.6,0.55);
661 buchmann 1.13 if(is_data)
662     {
663 fronga 1.24 legBpredc->AddEntry(RcorrJZBeemm,"observed","p");
664     legBpredc->AddEntry(Bpredem,"OFZP","l");
665     legBpredc->AddEntry(BpredSBem,"OFSB","l");
666     legBpredc->AddEntry(BpredSBeemm,"SFSB","l");
667 buchmann 1.13 legBpredc->Draw();
668     CompleteSave(globalcanvas,"Bpred_Data_comparison");
669     }
670     else {
671 fronga 1.24 legBpredc->AddEntry(RcorrJZBeemm,"MC observed","p");
672     legBpredc->AddEntry(Bpredem,"MC OFZP","l");
673     legBpredc->AddEntry(BpredSBem,"MC OFSB","l");
674     legBpredc->AddEntry(BpredSBeemm,"MC SFSB","l");
675 buchmann 1.13 legBpredc->Draw();
676     legBpredc->Draw();
677     CompleteSave(globalcanvas,"Bpred_MC_comparison");
678     }
679     delete RcorrJZBeemm;
680     delete LcorrJZBeemm;
681     delete RcorrJZBem;
682     delete LcorrJZBem;
683     delete RcorrJZBSBem;
684     delete LcorrJZBSBem;
685     delete RcorrJZBSBeemm;
686     delete LcorrJZBSBeemm;
687     delete lm4RcorrJZBeemm;
688 buchmann 1.1 }
689    
690 fronga 1.24 void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma, bool overlay_signal ) {
691 buchmann 1.11 TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
692 fronga 1.24 do_prediction_plot(datajzb,globalcanvas,DataSigma,jzbHigh ,data,overlay_signal);
693     do_prediction_plot(mcjzb,globalcanvas,MCSigma,jzbHigh ,mc,overlay_signal);
694 buchmann 1.1 }
695    
696     void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
697     bool do_data=0;
698     bool dosignal=0;
699     if(is_data==1) do_data=1;
700     if(is_data==2) dosignal=1;
701 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
702     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
703     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
704     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
705    
706     TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
707     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
708     TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
709     TH1F *LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
710 buchmann 1.13
711 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
712 buchmann 1.13 Bpred->Add(RcorrJZBem,1.0/3);
713     Bpred->Add(LcorrJZBem,-1.0/3);
714     Bpred->Add(RcorrJZBSBem,1.0/3);
715     Bpred->Add(LcorrJZBSBem,-1.0/3);
716     Bpred->Add(RcorrJZBSBeemm,1.0/3);
717     Bpred->Add(LcorrJZBSbeemm,-1.0/3);
718 buchmann 1.1 can->cd();
719     can->SetLogy(0);
720     Bpred->SetLineColor(kRed);
721     Bpred->SetStats(0);
722     if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
723 buchmann 1.17 TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
724     JZBratioforfitting->Divide(Bpred);
725 buchmann 1.36 TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning,false);
726 buchmann 1.17
727 buchmann 1.1
728     JZBratio->SetTitle("");
729     JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
730 fronga 1.24 // if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,jzbHigh );
731 buchmann 1.1
732     TF1 *pol0 = new TF1("pol0","[0]",0,1000);
733     TF1 *pol0d = new TF1("pol0","[0]",0,1000);
734     // straightline_fit->SetParameter(0,1);
735     JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
736     pol0d->SetParameter(0,pol0->GetParameter(0));
737    
738     JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
739 buchmann 1.17 JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
740 fronga 1.24 if ( high>0 ) JZBratio->GetXaxis()->SetRangeUser(0.0,high);
741 buchmann 1.1 JZBratio->GetYaxis()->SetNdivisions(519);
742     JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
743 buchmann 1.17 JZBratio->GetYaxis()->CenterTitle();
744     JZBratio->GetXaxis()->CenterTitle();
745     JZBratio->SetMarkerSize(DataMarkerSize);
746 buchmann 1.1 JZBratio->Draw("AP");
747     /////----------------------------
748 fronga 1.24 TPaveText *writeresult = new TPaveText(0.15,0.78,0.49,0.91,"blNDC");
749 buchmann 1.1 writeresult->SetFillStyle(4000);
750     writeresult->SetFillColor(kWhite);
751     writeresult->SetTextFont(42);
752 fronga 1.24 writeresult->SetTextSize(0.03);
753     writeresult->SetTextAlign(12);
754 buchmann 1.1 ostringstream jzb_agreement_data_text;
755     jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) << pol0->GetParError(0);
756     if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
757     if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
758     /* if(is_data) writeresult->AddText("Data closure test");
759     else writeresult->AddText("MC closure test");
760     */
761     writeresult->AddText(jzb_agreement_data_text.str().c_str());
762     writeresult->Draw("same");
763     pol0d->Draw("same");
764 fronga 1.24 TF1 *topline = new TF1("","1.5",0,1000);
765     TF1 *bottomline = new TF1("","0.5",0,1000);
766 buchmann 1.1 topline->SetLineColor(kBlue);
767     topline->SetLineStyle(2);
768     bottomline->SetLineColor(kBlue);
769     bottomline->SetLineStyle(2);
770     topline->Draw("same");
771     bottomline->Draw("same");
772     TF1 *oneline = new TF1("","1.0",0,1000);
773     oneline->SetLineColor(kBlue);
774     oneline->SetLineStyle(1);
775     oneline->Draw("same");
776 buchmann 1.17 TLegend *phony_leg = make_legend("ratio");//this line is just to have the default CMS Preliminary (...) on the canvas as well.
777 fronga 1.24 TLegend *leg = new TLegend(0.5,0.55,0.94,0.89);
778 buchmann 1.1 leg->SetTextFont(42);
779 fronga 1.24 leg->SetTextSize(0.04);
780     // if(is_data==1) leg->SetHeader("Ratio (data)");
781     // else leg->SetHeader("Ratio (MC)");
782    
783     TString MCtitle("MC ");
784     if (is_data==1) MCtitle = "";
785    
786 buchmann 1.1 leg->SetFillStyle(4000);
787     leg->SetFillColor(kWhite);
788     leg->SetTextFont(42);
789     // leg->AddEntry(topline,"+20\% sys envelope","l");
790 fronga 1.24 leg->AddEntry(JZBratio,MCtitle+"obs / "+MCtitle+"pred","p");
791 buchmann 1.1 leg->AddEntry(oneline,"ratio = 1","l");
792     leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
793 fronga 1.24 leg->AddEntry(bottomline,"#pm50% envelope","l");
794 buchmann 1.1 leg->Draw("same");
795     if(is_data==1) CompleteSave(can, "jzb_ratio_data");
796     if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
797     if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
798 buchmann 1.17
799 buchmann 1.1 delete RcorrJZBeemm;
800     delete LcorrJZBeemm;
801     delete RcorrJZBem;
802     delete LcorrJZBem;
803 buchmann 1.17
804     delete RcorrJZBSBem;
805     delete LcorrJZBSBem;
806     delete RcorrJZBSBeemm;
807     delete LcorrJZBSbeemm;
808 buchmann 1.1 }
809    
810 buchmann 1.23 void do_ratio_plots(string mcjzb,string datajzb,vector<float> ratio_binning) {
811 buchmann 1.11 TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
812 buchmann 1.1 globalc->SetLogy(0);
813    
814 fronga 1.24 do_ratio_plot(mc,ratio_binning,mcjzb,globalc, jzbHigh );
815     do_ratio_plot(data,ratio_binning,datajzb,globalc, jzbHigh );
816     do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc, jzbHigh );
817 buchmann 1.1 }
818    
819 buchmann 1.8 string give_jzb_expression(float peak, int type) {
820 buchmann 1.1 stringstream val;
821 buchmann 1.8 if(type==data) {
822     if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
823     if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
824     if(peak==0) val << jzbvariabledata;
825     }
826     if(type==mc) {
827     if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
828     if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
829     if(peak==0) val << jzbvariablemc;
830     }
831 buchmann 1.1 return val.str();
832     }
833    
834    
835 buchmann 1.11 void lepton_comparison_plots() {
836 fronga 1.24 Float_t ymin = 1.e-5, ymax = 0.25;
837 buchmann 1.11 TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
838 buchmann 1.1 can->SetLogy(1);
839 buchmann 1.17 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
840     TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
841 buchmann 1.1 eemc->SetLineColor(kBlue);
842     mmmc->SetLineColor(kRed);
843     eemc->SetMinimum(0.1);
844     eemc->SetMaximum(10*eemc->GetMaximum());
845     eemc->Draw("histo");
846     mmmc->Draw("histo,same");
847     TLegend *leg = make_legend();
848 buchmann 1.17 leg->AddEntry(eemc,"ZJets->ee (MC)","l");
849     leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
850 buchmann 1.11 leg->Draw("same");
851 buchmann 1.1 CompleteSave(can, "mll_effratio_mc");
852    
853 buchmann 1.17 TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
854     TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
855 buchmann 1.1 eed->SetLineColor(kBlue);
856     mmd->SetLineColor(kRed);
857     eed->SetMinimum(0.1);
858     eed->SetMaximum(10*eed->GetMaximum());
859     eed->Draw("histo");
860     mmd->Draw("histo,same");
861     TLegend *leg2 = make_legend();
862 buchmann 1.17 leg2->AddEntry(eed,"ZJets->ee (data)","l");
863     leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
864 buchmann 1.1 leg2->Draw();
865     CompleteSave(can, "mll_effratio_data");
866    
867 fronga 1.24 TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, 100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
868     TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, 100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
869     TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,100,-150,jzbHigh , "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
870 buchmann 1.21 dout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
871     dout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
872     dout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
873 buchmann 1.1 jeemmd->SetLineColor(kBlack);
874     jeemmd->SetMarkerStyle(25);
875     jeed->SetLineColor(kBlue);
876     jmmd->SetLineColor(kRed);
877     jeed->SetMinimum(0.1);
878     jeed->SetMaximum(10*eed->GetMaximum());
879 fronga 1.24 TH1* njeemmd = jeemmd->DrawNormalized();
880     njeemmd->SetMinimum(ymin);
881     njeemmd->SetMaximum(ymax);
882    
883 buchmann 1.1 jeed->DrawNormalized("histo,same");
884     jmmd->DrawNormalized("histo,same");
885     jeemmd->DrawNormalized("same");
886 fronga 1.24 TLegend *jleg2 = make_legend(" ");
887 buchmann 1.1 jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
888     jleg2->AddEntry(jeed,"ee","l");
889     jleg2->AddEntry(jmmd,"#mu#mu","l");
890     jleg2->Draw();
891     CompleteSave(can,"jzb_effratio_data");
892    
893 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"));
894     TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariablemc, 100,-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJets"));
895     TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariablemc,100,-150,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets, mc, luminosity,allsamples.FindSample("DYJets"));
896 buchmann 1.21 dout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
897     dout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
898     dout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
899 buchmann 1.11 zjeemmd->SetLineColor(kBlack);
900     zjeemmd->SetMarkerStyle(25);
901     zjeed->SetLineColor(kBlue);
902     zjmmd->SetLineColor(kRed);
903     zjeed->SetMinimum(0.1);
904     zjeed->SetMaximum(10*eed->GetMaximum());
905 fronga 1.24
906     TH1* nzjeemmd = zjeemmd->DrawNormalized();
907     nzjeemmd->SetMinimum(ymin);
908     nzjeemmd->SetMaximum(ymax);
909 buchmann 1.11 zjeed->DrawNormalized("histo,same");
910     zjmmd->DrawNormalized("histo,same");
911     zjeemmd->DrawNormalized("same");
912 fronga 1.24 TLegend *zjleg2 = make_legend("Z+jets MC");
913 buchmann 1.11 zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
914     zjleg2->AddEntry(jeed,"ee","l");
915     zjleg2->AddEntry(jmmd,"#mu#mu","l");
916     zjleg2->Draw();
917     CompleteSave(can,"jzb_effratio_ZJets");
918    
919 buchmann 1.17 TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
920 buchmann 1.1 ld->DrawNormalized("e1");
921     eed->DrawNormalized("histo,same");
922     mmd->DrawNormalized("histo,same");
923     TLegend *leg3 = make_legend();
924     leg3->AddEntry(ld,"ZJets->ll (data)","p");
925 buchmann 1.17 leg3->AddEntry(eed,"ZJets->ee (data)","l");
926     leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
927 buchmann 1.1 leg3->Draw();
928     CompleteSave(can,"mll_effratio_data__all_compared");
929     /*
930 buchmann 1.17 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
931     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
932 buchmann 1.1 */
933 fronga 1.24 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,92,-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
934     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,92,-110,jzbHigh , "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
935 buchmann 1.1 jzbld->SetMarkerColor(kBlack);
936     jzbld->SetMarkerStyle(26);
937     jzbemd->SetMarkerStyle(25);
938     jzbemd->SetMarkerColor(kRed);
939     jzbemd->SetLineColor(kRed);
940     jzbld->SetMinimum(0.35);
941     jzbld->Draw("e1");
942     jzbemd->Draw("e1,same");
943 fronga 1.24 TLegend *leg4 = make_legend();
944     leg4->AddEntry(jzbld,"SFZP","p");
945     leg4->AddEntry(jzbemd,"OFZP","p");
946 buchmann 1.29 leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
947     leg4->AddEntry((TObject*)0,"",""); //causes segmentation violation
948 buchmann 1.1 leg4->Draw();
949     CompleteSave(can,"jzb_eemumu_emu_data");
950    
951 buchmann 1.17 TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
952     TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
953 buchmann 1.1 ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
954     ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
955     ttbarjzbld->Draw("histo");
956     ttbarjzbemd->SetLineStyle(2);
957     ttbarjzbemd->Draw("histo,same");
958     TLegend *leg5 = make_legend();
959 buchmann 1.17 leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
960     leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
961 buchmann 1.1 leg5->Draw();
962     CompleteSave(can,"ttbar_emu_mc");
963    
964    
965    
966     }
967    
968     bool is_OF(TCut cut) {
969     string scut = (const char*) cut;
970     if((int)scut.find("id1!=id2")>-1) return true;
971     if((int)scut.find("id1==id2")>-1) return false;
972     return false;
973     }
974    
975 fronga 1.24 bool is_ZP(TCut cut) {
976     string scut = (const char*) cut;
977     if((int)scut.find("91")>-1) return true;
978     return false;
979     }
980    
981    
982 buchmann 1.23 void draw_pure_jzb_histo(TCut cut,string variable,string savename, TCanvas *can,vector<float> binning) {
983 buchmann 1.1 can->cd();
984     can->SetLogy(1);
985 buchmann 1.17 string xlabel="JZB [GeV]";
986 buchmann 1.1
987 buchmann 1.23 TH1F *datahisto = allsamples.Draw("datahisto",variable,binning, xlabel, "events",cut,data,luminosity);
988     THStack mcstack = allsamples.DrawStack("mcstack",variable,binning, xlabel, "events",cut,mc,luminosity);
989 buchmann 1.1
990     datahisto->SetMinimum(0.1);
991 buchmann 1.12 //if(savename=="jzb_OSOF") datahisto->SetMaximum(10);
992 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
993 buchmann 1.1 datahisto->Draw("e1");
994     mcstack.Draw("same");
995     datahisto->Draw("same,e1");
996    
997     TLegend *leg;
998 fronga 1.24 if(is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("OFZP",datahisto);
999     else if(!is_OF(cut) && is_ZP(cut)) leg = allsamples.allbglegend("SFZP",datahisto);
1000     else if( is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("OFSB",datahisto);
1001     else if(!is_OF(cut) && !is_ZP(cut)) leg = allsamples.allbglegend("SFSB",datahisto);
1002     else {
1003     std::cerr << "Unable to decode cut: " << cut.GetTitle() << std::endl;
1004     exit(-1);
1005     }
1006 buchmann 1.1 leg->Draw();
1007     string write_cut = decipher_cut(cut,"");
1008 buchmann 1.16 TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
1009 buchmann 1.1 writeline1->SetTextSize(0.035);
1010     writeline1->Draw();
1011     CompleteSave(can, ("jzb/"+savename));
1012    
1013     datahisto->Delete();
1014     mcstack.Delete();
1015     }
1016    
1017     Double_t GausR(Double_t *x, Double_t *par) {
1018     return gRandom->Gaus(x[0],par[0]);
1019     }
1020    
1021 buchmann 1.23 void jzb_plots(string mcjzb, string datajzb,vector<float> ratio_binning) {
1022 buchmann 1.11 TCanvas *can = new TCanvas("can","JZB Plots Canvas");
1023 fronga 1.24 float max=jzbHigh ;
1024 buchmann 1.1 float min=-120;
1025     int nbins=(max-min)/5.0; // we want 5 GeV/bin
1026 buchmann 1.23 int coarserbins=int(nbins/2.0);
1027     int rebinnedbins=int(nbins/4.0);
1028 buchmann 1.1
1029 buchmann 1.23 // stringstream ss;
1030 buchmann 1.1 // ss << "GausRandom(" << datajzb << ",0)";
1031 buchmann 1.23 vector<float>binning;vector<float>coarse_binning;vector<float>coarsest_binning;
1032     for(int i=0;i<=nbins;i++)binning.push_back(min+i*(max-min)/((float)nbins));
1033     for(int i=0;i<=coarserbins;i++)coarse_binning.push_back(min+i*(max-min)/((float)coarserbins));
1034     for(int i=0;i<=rebinnedbins;i++)coarsest_binning.push_back(min+i*(max-min)/((float)rebinnedbins));
1035    
1036     /* draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OSSF_altbins",can,ratio_binning);
1037     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OSOF_altbins",can,ratio_binning);
1038     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OSSF_SB_altbins",can,ratio_binning);
1039     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OSOF_SB_altbins",can,ratio_binning);*/
1040 fronga 1.24 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP",can,binning);
1041     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP",can,binning);
1042     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB",can,binning);
1043     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB",can,binning);
1044    
1045     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP_coarse",can,coarse_binning);
1046     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP_coarse",can,coarse_binning);
1047     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB_coarse",can,coarse_binning);
1048     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB_coarse",can,coarse_binning);
1049    
1050     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OS_SFZP_coarsest",can,coarsest_binning);
1051     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OS_OFZP_coarsest",can,coarsest_binning);
1052     draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_SFSB_coarsest",can,coarsest_binning);
1053     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OS_OFSB_coarsest",can,coarsest_binning);
1054 buchmann 1.1 }
1055    
1056     void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
1057 buchmann 1.21 dout << "Calculating background yields in MC:" << endl;
1058 buchmann 1.1 jzb_cuts.push_back(14000);
1059 buchmann 1.17 TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
1060 buchmann 1.1 float cumulative=0;
1061     for(int i=allbgs->GetNbinsX();i>=1;i--) {
1062     cumulative+=allbgs->GetBinContent(i);
1063 buchmann 1.21 dout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
1064 buchmann 1.1 }
1065     }
1066    
1067 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) {
1068 buchmann 1.10 //Step 1: Establishing cuts
1069 buchmann 1.3 stringstream jetcutstring;
1070 buchmann 1.10 string writescenario="";
1071    
1072 buchmann 1.3 if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
1073     if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
1074     TCut jetcut(jetcutstring.str().c_str());
1075     string leptoncut="mll>0";
1076     if(leptontype==0||leptontype==1) {
1077 buchmann 1.10 if(leptontype==0) {
1078     leptoncut="id1==0";
1079     writescenario="__ee";
1080     }
1081     else {
1082     leptoncut="id1==1";
1083     writescenario="__ee";
1084     }
1085 buchmann 1.3 }
1086     TCut lepcut(leptoncut.c_str());
1087    
1088 buchmann 1.6 TCanvas *c5 = new TCanvas("c5","c5",1500,500);
1089 buchmann 1.10 TCanvas *c6 = new TCanvas("c6","c6");
1090 buchmann 1.3 c5->Divide(3,1);
1091 buchmann 1.10
1092     //STEP 2: Extract Zjets shape in data
1093     c5->cd(1);
1094 buchmann 1.3 c5->cd(1)->SetLogy(1);
1095     TCut massat40("mll>40");
1096 buchmann 1.17 TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1097     TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1098 buchmann 1.3 ossfleft->SetLineColor(kRed);
1099     ossfleft->SetMarkerColor(kRed);
1100     ossfleft->Add(osofleft,-1);
1101 buchmann 1.9 vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
1102 buchmann 1.17 ossfleft->SetMarkerSize(DataMarkerSize);
1103 buchmann 1.3 ossfleft->Draw();
1104 buchmann 1.9 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
1105     TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
1106     TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
1107     TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
1108 buchmann 1.6 zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
1109 buchmann 1.3 TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
1110     leg1->SetFillColor(kWhite);
1111     leg1->SetLineColor(kWhite);
1112     leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
1113 buchmann 1.6 leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
1114 buchmann 1.3 leg1->Draw("same");
1115     TText *titleleft = write_title("Extracting Z+Jets shape");
1116     titleleft->Draw();
1117    
1118 buchmann 1.10 //Step 3: Extract ttbar shape (in data or MC?)
1119     c5->cd(2);
1120 buchmann 1.3 c5->cd(2)->SetLogy(1);
1121 buchmann 1.4 TH1F *osof;
1122     TText *titlecenter;
1123 buchmann 1.10 bool frommc=false;
1124     if(frommc) {
1125 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
1126 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
1127     }
1128     else {
1129 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
1130 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from osof data)");
1131     }
1132 buchmann 1.17 osof->SetMarkerSize(DataMarkerSize);
1133 buchmann 1.3 osof->Draw();
1134 buchmann 1.10 vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
1135     ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
1136     ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
1137     ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
1138    
1139 buchmann 1.3 TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
1140     leg2->SetFillColor(kWhite);
1141     leg2->SetLineColor(kWhite);
1142 buchmann 1.10 if(frommc) {
1143 buchmann 1.4 leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
1144 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
1145 buchmann 1.4 } else {
1146     leg2->AddEntry(osof,"OSOF","p");
1147 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
1148 buchmann 1.4 }
1149 buchmann 1.3 leg2->Draw("same");
1150     titlecenter->Draw();
1151 buchmann 1.10
1152     //--------------------------------------------------------------------------------------------------------------------------------
1153 buchmann 1.4 //STEP 4: Present it!
1154     // actually: if we wanna let it float we need to do that first :-)
1155 buchmann 1.3 c5->cd(3);
1156     c5->cd(3)->SetLogy(1);
1157 buchmann 1.17 TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1158     observed->SetMarkerSize(DataMarkerSize);
1159 buchmann 1.4
1160 buchmann 1.6 TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
1161 buchmann 1.8 TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
1162     TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
1163 buchmann 1.6
1164     TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
1165     TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
1166     TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
1167    
1168 buchmann 1.10 TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
1169     TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
1170     TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
1171    
1172 buchmann 1.6 zjetsc->SetParameters(zjetsfunc->GetParameters());
1173     zjetscp->SetParameters(zjetsfunc->GetParameters());
1174     zjetscn->SetParameters(zjetsfunc->GetParameters());
1175 buchmann 1.10
1176 fronga 1.24 TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,jzbHigh, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
1177 buchmann 1.7 //blublu
1178 buchmann 1.10 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1179     logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
1180     logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
1181 buchmann 1.4 if(floating) {
1182 buchmann 1.21 dout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
1183 buchmann 1.10 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
1184 buchmann 1.7 for(int i=0;i<10;i++) {
1185     if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
1186     if(i>=5) {
1187     if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
1188     if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
1189     }
1190     }//end of setting parameters
1191     observeda->Draw("same");
1192     ZplusJetsplusTTbar->Draw("same");
1193     observeda->Fit(ZplusJetsplusTTbar);
1194 buchmann 1.21 dout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
1195 buchmann 1.7 ZplusJetsplusTTbar->Draw("same");
1196 buchmann 1.8 ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
1197     ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
1198 buchmann 1.21 dout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
1199 buchmann 1.7 float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
1200 buchmann 1.21 dout << "FACTOR: " << factor << endl;
1201 buchmann 1.10 logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1202     logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1203     logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
1204 buchmann 1.4 }
1205 buchmann 1.6
1206 buchmann 1.4 c5->cd(3);
1207 buchmann 1.6 c5->cd(3)->SetLogy(1);
1208     observed->Draw();
1209     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1210 buchmann 1.3 logparc->Draw("same");
1211 buchmann 1.6 logparcn->Draw("same");
1212     logparcp->Draw("same");
1213    
1214 buchmann 1.3 TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
1215     leg3->SetFillColor(kWhite);
1216     leg3->SetLineColor(kWhite);
1217     leg3->AddEntry(observed,"OSSF,JZB>peak","p");
1218 buchmann 1.10 leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
1219 buchmann 1.6 leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
1220 buchmann 1.3 leg3->Draw("same");
1221     TText *titleright = write_title("Summary of shapes and observed shape");
1222     titleright->Draw();
1223    
1224     c6->cd()->SetLogy(1);
1225 buchmann 1.6 observed->Draw();
1226     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1227 buchmann 1.3 logparc->Draw("same");
1228 buchmann 1.6 logparcn->Draw("same");
1229     logparcp->Draw("same");
1230 buchmann 1.3 leg3->Draw("same");
1231     titleright->Draw();
1232    
1233     if(scenario==0) {
1234     CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
1235 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
1236     CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
1237     CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
1238 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
1239     } else {
1240     CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
1241 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
1242     CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
1243     CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
1244 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
1245     }
1246 buchmann 1.21 dout << "Statistics about our fits: " << endl;
1247     dout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
1248     dout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
1249 buchmann 1.4
1250 buchmann 1.7 c6->cd();
1251 buchmann 1.8 TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
1252     additionallegend->SetFillColor(kWhite);
1253     additionallegend->SetLineColor(kWhite);
1254     additionallegend->AddEntry(observed,"Data","p");
1255     additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
1256     additionallegend->AddEntry(zjetsc,"Z+jets","l");
1257     additionallegend->AddEntry(logparc,"TTbar","l");
1258 buchmann 1.7 observed->Draw();
1259     ZplusJetsplusTTbar->SetLineColor(kGreen);
1260 buchmann 1.8 ZplusJetsplusTTbarP->SetLineColor(kGreen);
1261     ZplusJetsplusTTbarN->SetLineColor(kGreen);
1262     ZplusJetsplusTTbarP->SetLineStyle(2);
1263     ZplusJetsplusTTbarN->SetLineStyle(2);
1264     TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
1265     ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
1266     ZplusJetsplusTTbar2->SetLineColor(kGreen);
1267     ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
1268     ZplusJetsplusTTbarN->SetFillColor(kWhite);
1269     ZplusJetsplusTTbarP->Draw("fcsame");
1270     ZplusJetsplusTTbarN->Draw("fcsame");
1271     TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
1272     TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
1273     TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
1274     hZplusJetsplusTTbar->SetMarkerSize(0);
1275     hZplusJetsplusTTbarP->SetMarkerSize(0);
1276     hZplusJetsplusTTbarN->SetMarkerSize(0);
1277     for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
1278     float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
1279     hZplusJetsplusTTbar->SetBinError(i,newerror);
1280     if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
1281     }
1282     hZplusJetsplusTTbarP->SetFillColor(kGreen);
1283     hZplusJetsplusTTbarN->SetFillColor(kWhite);
1284     hZplusJetsplusTTbarN->Draw("same");
1285    
1286     ZplusJetsplusTTbar2->SetMarkerSize(0);
1287     ZplusJetsplusTTbar2->Draw("same");
1288    
1289 buchmann 1.7 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
1290     logparc->Draw("same");
1291     logparcn->Draw("same");
1292     logparcp->Draw("same");
1293 buchmann 1.8 additionallegend->Draw("same");
1294     if(scenario==0) {
1295     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
1296     } else {
1297     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
1298     }
1299 buchmann 1.10 //--------------------------------------------------------------------------------------------------------------------------------
1300 buchmann 1.3 }
1301    
1302 buchmann 1.2 void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
1303 buchmann 1.3 int all_leptons=-1;
1304     int electrons_only=0;
1305     int mu_only=1;
1306     int twojetswith50gev=1;
1307     int threejetswith30gev=0;
1308 buchmann 1.4 /*
1309 buchmann 1.3 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
1310     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
1311    
1312     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
1313     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
1314    
1315     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
1316     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
1317 buchmann 1.4 */
1318 buchmann 1.2
1319 buchmann 1.10 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
1320 buchmann 1.2 }
1321 buchmann 1.6
1322 buchmann 1.8 void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
1323 buchmann 1.13 //first: colorful plots
1324     TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
1325 buchmann 1.14 cancorr->SetLogz();
1326 fronga 1.26 cancorr->SetRightMargin(0.13);
1327 buchmann 1.13 TCut zptforresponsepresentation("pt<600&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)&&((sumJetPt[1]/pt)<5.0)");
1328 fronga 1.26 TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",100,0,600,100,0,5);
1329 buchmann 1.13 (allsamples.collection)[allsamples.FindSample("AllData")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
1330     niceresponseplotd->SetStats(0);
1331 fronga 1.26 niceresponseplotd->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1332 buchmann 1.13 niceresponseplotd->GetYaxis()->SetTitle("Response");
1333     niceresponseplotd->GetXaxis()->CenterTitle();
1334     niceresponseplotd->GetYaxis()->CenterTitle();
1335     niceresponseplotd->Draw("COLZ");
1336 fronga 1.26 TProfile * profd = (TProfile*)niceresponseplotd->ProfileX();
1337     profd->SetMarkerSize(DataMarkerSize);
1338     profd->Fit("pol0","","same,e1",30,400);
1339 buchmann 1.13 DrawPrelim();
1340 buchmann 1.32 TText* title = write_text(0.5,0.7,"Data");
1341     title->SetTextAlign(12);
1342 fronga 1.26 title->Draw();
1343 buchmann 1.32 TF1 *datapol=(TF1*)profd->GetFunction("pol0");
1344     float datacorrection=datapol->GetParameter(0);
1345     stringstream dataresstring;
1346     dataresstring<<"Response: "<<std::setprecision(2)<<100*datacorrection<<" %";
1347     TText* restitle = write_text(0.5,0.65,dataresstring.str());
1348     restitle->SetTextAlign(12);
1349     restitle->SetTextSize(0.03);
1350     restitle->Draw();
1351 buchmann 1.13 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
1352    
1353 fronga 1.26 TH2F *niceresponseplotm = new TH2F("niceresponseplotm","",100,0,600,100,0,5);
1354     (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotm",zptforresponsepresentation);
1355     niceresponseplotm->SetStats(0);
1356     niceresponseplotm->GetXaxis()->SetTitle("Z p_{T} [GeV]");
1357     niceresponseplotm->GetYaxis()->SetTitle("Response");
1358     niceresponseplotm->GetXaxis()->CenterTitle();
1359     niceresponseplotm->GetYaxis()->CenterTitle();
1360     niceresponseplotm->Draw("COLZ");
1361 buchmann 1.13 (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
1362 fronga 1.26 TProfile * profm = (TProfile*)niceresponseplotm->ProfileX();
1363     profm->SetMarkerSize(DataMarkerSize);
1364     profm->Fit("pol0","","same,e1",30,400);
1365 buchmann 1.13 DrawPrelim();
1366 buchmann 1.32 title = write_text(0.5,0.7,"MC simulation");
1367     title->SetTextAlign(12);
1368 fronga 1.26 title->Draw();
1369 buchmann 1.32 TF1 *mcpol=(TF1*)profm->GetFunction("pol0");
1370     float mccorrection=mcpol->GetParameter(0);
1371     stringstream mcresstring;
1372     mcresstring<<"Response: "<<std::setprecision(2)<<100*mccorrection<<" %";
1373     TText* mcrestitle = write_text(0.5,0.65,mcresstring.str());
1374     mcrestitle->SetTextAlign(12);
1375     mcrestitle->SetTextSize(0.03);
1376     mcrestitle->Draw();
1377 buchmann 1.13 CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
1378    
1379 buchmann 1.32
1380 buchmann 1.13 //Step 2: Getting the result
1381 buchmann 1.32 // TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
1382 buchmann 1.8 stringstream jzbvardatas;
1383 buchmann 1.9 if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
1384     if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
1385 buchmann 1.8 jzbvardata=jzbvardatas.str();
1386     stringstream jzbvarmcs;
1387 buchmann 1.33 if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
1388 buchmann 1.9 if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
1389 buchmann 1.8 jzbvarmc=jzbvarmcs.str();
1390 buchmann 1.21 dout << "JZB Z pt correction summary : " << endl;
1391 buchmann 1.32 dout << " Data: The response is " << datacorrection << " --> jzb variable is now : " << jzbvardata << endl;
1392     dout << " MC : The response is " << mccorrection << " --> jzb variable is now : " << jzbvarmc << endl;
1393 buchmann 1.8 }
1394 buchmann 1.11
1395 buchmann 1.12 void pick_up_events(string cut) {
1396 buchmann 1.21 dout << "Picking up events with cut " << cut << endl;
1397 buchmann 1.12 allsamples.PickUpEvents(cut);
1398 buchmann 1.11 }
1399    
1400 buchmann 1.38 void save_template(string mcjzb, string datajzb,vector<float> jzb_cuts,float MCPeakError) {
1401     cout << "Saving configuration template!" << endl;
1402 buchmann 1.30 ofstream configfile;
1403 buchmann 1.31 configfile.open("../DistributedModelCalculations/last_configuration.C");
1404 buchmann 1.30 configfile<<"#include <iostream>\n";
1405     configfile<<"#include <vector>\n";
1406     configfile<<"\nusing namespace std;\n\n";
1407 buchmann 1.31
1408     configfile<<"namespace PlottingSetup { \n";
1409     configfile<<"string datajzb=\"datajzb_ERROR\";\n";
1410     configfile<<"string mcjzb=\"mcjzb_ERROR\";\n";
1411     configfile<<"vector<float>jzb_cuts;\n";
1412     configfile<<"float MCPeakError=-999;\n";
1413     configfile<<"}\n\n";
1414    
1415    
1416    
1417 buchmann 1.30 configfile<<"void read_config() {\n";
1418     configfile<<"datajzb=\""<<datajzb<<"\";\n";
1419     configfile<<"mcjzb=\""<<mcjzb<<"\";\n\n";
1420 buchmann 1.31 configfile<<"\n\nMCPeakError="<<MCPeakError<<";\n\n";
1421 buchmann 1.30 for(int i=0;i<jzb_cuts.size();i++) configfile<<"jzb_cuts.push_back("<<jzb_cuts[i]<<");\n";
1422     configfile<<"\n\n";
1423     for(int i=0;i<Nobs.size();i++) configfile<<"Nobs.push_back("<<Nobs[i]<<");\n";
1424     for(int i=0;i<Npred.size();i++) configfile<<"Npred.push_back("<<Npred[i]<<");\n";
1425     for(int i=0;i<Nprederr.size();i++) configfile<<"Nprederr.push_back("<<Nprederr[i]<<");\n";
1426 buchmann 1.37 configfile<<"\n\n";
1427 buchmann 1.38 configfile<<"luminosity="<<luminosity<<";\n";
1428 buchmann 1.30
1429     configfile<<"\n\ncout << \"Configuration successfully loaded!\" << endl; \n \n } \n \n";
1430    
1431     configfile.close();
1432    
1433     }
1434    
1435 buchmann 1.40 float get_nonzero_minimum(TH1F *histo) {
1436     float min=histo->GetMaximum();
1437     for(int ibin=1;ibin<=histo->GetNbinsX();ibin++) {
1438     float curcont=histo->GetBinContent(ibin);
1439     if(curcont<min&&curcont>0) min=curcont;
1440     }
1441     return min;
1442     }
1443    
1444     void draw_all_ttbar_histos(TCanvas *can, vector<TH1F*> histos, string drawoption="", float manualmin=-9) {
1445     can->cd();
1446     float min=1;
1447     float max=histos[0]->GetMaximum();
1448     if(manualmin>=0) min=manualmin;
1449     else {
1450     for(int i=1;i<histos.size();i++) {
1451     float curmin=get_nonzero_minimum(histos[i]);
1452     float curmax=histos[i]->GetMaximum();
1453     if(curmin<min) min=curmin;
1454     if(curmax>max) max=curmax;
1455     }
1456     }
1457     histos[0]->GetYaxis()->SetRangeUser(min,4*max);
1458     histos[0]->Draw(drawoption.c_str());
1459     stringstream drawopt;
1460     drawopt << drawoption << ",same";
1461     for(int i=1;i<histos.size();i++) {
1462     histos[i]->Draw(drawopt.str().c_str());
1463     }
1464     }
1465    
1466     void ttbar_sidebands_comparison(string mcjzb) {
1467     float sbg_min=-110;
1468     float sbg_max=jzbHigh;
1469     int sbg_nbins=(sbg_max-sbg_min)/10.0;
1470    
1471     TH1F *TZem = allsamples.Draw("TZem",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
1472     TH1F *TSem = allsamples.Draw("TSem",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",sidebandcut&&cutOSOF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
1473     TH1F *TZeemm = allsamples.Draw("TZeemm",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
1474     TH1F *TSeemm = allsamples.Draw("TSeemm",mcjzb,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",sidebandcut&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
1475    
1476     TCanvas *tcan = new TCanvas("tcan","tcan");
1477    
1478     tcan->SetLogy(1);
1479    
1480     TZeemm->SetLineColor(kBlack);
1481     TZem->SetLineColor(kRed);
1482     TSem->SetLineColor(kGreen);
1483     TSeemm->SetLineColor(kBlue);
1484    
1485     TZeemm->SetMarkerColor(kBlack);
1486     TZem->SetMarkerColor(kRed);
1487     TSem->SetMarkerColor(kGreen);
1488     TSeemm->SetMarkerColor(kBlue);
1489    
1490     TSem->SetLineStyle(2);
1491     TSeemm->SetLineStyle(2);
1492    
1493     vector<TH1F*> histos;
1494     histos.push_back(TZem);
1495     histos.push_back(TZeemm);
1496     histos.push_back(TSem);
1497     histos.push_back(TSeemm);
1498     draw_all_ttbar_histos(tcan,histos,"histo",0.04);
1499    
1500     TLegend *leg = make_legend("MC ttbar");
1501 buchmann 1.42 leg->AddEntry(TZeemm,"SFZP","l");
1502     leg->AddEntry(TZem,"OFZP","l");
1503     leg->AddEntry(TSeemm,"SFSB","l");
1504     leg->AddEntry(TSem,"OFSB","l");
1505 buchmann 1.40 leg->Draw("same");
1506     CompleteSave(tcan,"ttbar_comparison");
1507    
1508     TZem->Divide(TZeemm);
1509     TSem->Divide(TZeemm);
1510     TSeemm->Divide(TZeemm);
1511    
1512     tcan->SetLogy(0);
1513     TZem->GetYaxis()->SetRangeUser(0,2.5);
1514     TZem->GetYaxis()->SetTitle("predicted/MC truth");
1515     TZem->Draw();
1516     TSem->Draw("same");
1517     TSeemm->Draw("same");
1518    
1519     TLine *top = new TLine(sbg_min,1.5,sbg_max,1.5);
1520     TLine *center = new TLine(sbg_min,1.0,sbg_max,1.0);
1521     TLine *bottom = new TLine(sbg_min,0.5,sbg_max,0.5);
1522    
1523     top->SetLineColor(kBlue);top->SetLineStyle(2);
1524     bottom->SetLineColor(kBlue);bottom->SetLineStyle(2);
1525     center->SetLineColor(kBlue);
1526    
1527     top->Draw("same");
1528     center->Draw("same");
1529     bottom->Draw("same");
1530    
1531     TLegend *leg2 = make_legend("MC ttbar");
1532 buchmann 1.43 leg2->AddEntry(TZem,"OFZP / SFZP","ple");
1533     leg2->AddEntry(TSeemm,"SFSB / SFZP","ple");
1534     leg2->AddEntry(TSem,"OFSB / SFZP","ple");
1535 buchmann 1.40 leg2->AddEntry(bottom,"syst. envelope","l");
1536     leg2->SetX1(0.25);leg2->SetX2(0.7);
1537     leg2->SetY1(0.65);
1538    
1539     leg2->Draw("same");
1540    
1541     CompleteSave(tcan,"ttbar_comparison_ratio");
1542    
1543     delete tcan;
1544     }
1545    
1546 buchmann 1.30
1547 buchmann 1.11 void test() {
1548 buchmann 1.19
1549 buchmann 1.11 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
1550     testcanv->cd();
1551     switch_overunderflow(true);
1552 buchmann 1.17 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
1553 buchmann 1.11 switch_overunderflow(false);
1554     ptdistr->Draw();
1555     testcanv->SaveAs("test.png");
1556 buchmann 1.21 dout << "HELLO there!" << endl;
1557 buchmann 1.19
1558 buchmann 1.11 }