ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.47
Committed: Thu Aug 25 14:24:00 2011 UTC (13 years, 8 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.46: +11 -60 lines
Log Message:
Removed unnecessary lines in PlottingFunctions, removed potential memory leaks, added new kind of header for MC

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