ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.56
Committed: Mon Sep 5 16:12:01 2011 UTC (13 years, 8 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.55: +5 -0 lines
Log Message:
Now also drawing LM4 on comparison plots

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