ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/Plotting_Functions.C
Revision: 1.20
Committed: Tue Jul 19 08:15:45 2011 UTC (13 years, 9 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.19: +1 -361 lines
Log Message:
Moved different limit calculation functions to separate module to unclutter Plotting_Functions; moved unneeded functions to the dusty module

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 buchmann 1.1
18 buchmann 1.9 //#include "TTbar_stuff.C"
19 buchmann 1.1 using namespace std;
20    
21     using namespace PlottingSetup;
22    
23 buchmann 1.20
24 buchmann 1.1 void find_peaks(float &MCPeak,float &MCPeakError, float &DataPeak, float &DataPeakError, float &MCSigma, float &DataSigma, stringstream &result)
25     {
26 buchmann 1.17 TH1F *rawJZBeemmMC = allsamples.Draw("rawJZBeemmMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc, luminosity);
27     TH1F *rawJZBeemmData = allsamples.Draw("rawJZBeemmData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
28     TH1F *rawJZBemMC = allsamples.Draw("rawJZBemMC",jzbvariablemc,100,-50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,mc, luminosity);
29     TH1F *rawJZBemData = allsamples.Draw("rawJZBemData",jzbvariabledata,100, -50,50, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
30 buchmann 1.1 TH1F *rawttbarjzbeemmMC;
31    
32     if(method==doKM) {
33     //we only need this histo for the KM fitting...
34 buchmann 1.17 rawttbarjzbeemmMC = allsamples.Draw("rawttbarjzbeemmMC",jzbvariablemc,100, -50,50, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJet"));
35 buchmann 1.1 MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
36     DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
37     }
38     else {
39     TH1F *reducedMC = (TH1F*)rawJZBeemmMC->Clone();
40     TH1F *reducedData = (TH1F*)rawJZBeemmData->Clone();
41     reducedMC->Add(rawJZBemMC,-1);
42     reducedData->Add(rawJZBemData,-1);
43     //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)
44     MCPeak=find_peak(reducedMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
45     DataPeak=find_peak(reducedData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
46 buchmann 1.11
47 buchmann 1.1 }
48 buchmann 1.11
49 buchmann 1.1
50     // MCPeak=find_peak(rawJZBeemmMC, rawttbarjzbeemmMC, -40, 40, mc, MCPeakError,MCSigma,method);
51     // DataPeak=find_peak(rawJZBeemmData, rawJZBeemmData, -40, 40, data, DataPeakError,DataSigma,method);
52     cout << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
53     result << "We have found the peak in Data at " << DataPeak << " +/- " << DataPeakError << " with sigma=" << DataSigma << " +/- ?? (not impl.)" << endl;
54     cout << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
55     result << "We have found the peak in MC at " << MCPeak << " +/- " << MCPeakError << " with sigma=" << MCSigma << " +/- ?? (not impl.)" << endl;
56     }
57    
58     void make_special_mll_plot(int nbins, float min, float max, bool logscale,string xlabel) {
59    
60     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
61    
62     TH1F *datahistoOSSF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,data,luminosity);
63     THStack mcstackOSSF = allsamples.DrawStack("mcstackOSSF","mll",nbins,min,max, xlabel, "events",cutOSSF&&cutnJets&&basiccut,mc,luminosity);
64     TH1F *datahistoOSOF = allsamples.Draw("datahistoOSSF","mll",nbins,min,max, xlabel, "events",cutOSOF&&cutnJets&&basiccut,data,luminosity);
65    
66     if(logscale) ckin->SetLogy(1);
67 buchmann 1.17 datahistoOSSF->SetMarkerSize(DataMarkerSize);
68 buchmann 1.1 datahistoOSSF->GetXaxis()->SetTitle(xlabel.c_str());
69     datahistoOSSF->GetXaxis()->CenterTitle();
70     datahistoOSSF->GetYaxis()->SetTitle("events");
71     datahistoOSSF->GetYaxis()->CenterTitle();
72    
73 buchmann 1.17 datahistoOSOF->SetMarkerSize(DataMarkerSize);
74     datahistoOSSF->SetMarkerSize(DataMarkerSize);
75 buchmann 1.1 datahistoOSSF->Draw();
76     mcstackOSSF.Draw("same");
77     datahistoOSSF->Draw("same");
78 buchmann 1.19 //datahistoOSOF->SetMarkerColor(TColor::GetColor("#FF4000"));
79     //datahistoOSOF->SetLineColor(TColor::GetColor("#FF4000"));
80 buchmann 1.17 datahistoOSOF->SetMarkerStyle(21);
81 buchmann 1.1 datahistoOSOF->Draw("same");
82 buchmann 1.17 TLegend *kinleg = allsamples.allbglegend("",datahistoOSSF);
83 buchmann 1.1 kinleg->AddEntry(datahistoOSOF,"OSOF (data)","p");
84     kinleg->Draw();
85     CompleteSave(ckin,"kin/mll_ossf_osof_distribution");
86 buchmann 1.18
87     delete datahistoOSOF;
88     delete datahistoOSSF;
89 buchmann 1.1 }
90    
91    
92     void make_plot(string variable, int nbins, float min, float max, bool logscale,string xlabel, string filename,bool isPF=true) {
93     // TCut basiccut("(pfJetGoodNum>=2&&pfJetGoodID[0])&&(pfJetGoodNum>=2&&pfJetGoodID[1])&&(passed_triggers||!is_data)");
94     TCut ibasiccut=basiccut;
95    
96     if(isPF) ibasiccut=basiccut&&"pfjzb[0]>-998";
97     //Step 1: Adapt the variable (if we're dealing with PF we need to adapt the variable!)
98     if(isPF) {
99     if(variable=="mll") variable="pfmll[0]";
100     if(variable=="jetpt[0]") variable="pfJetGoodPt[0]";
101     if(variable=="jeteta[0]") variable="pfJetGoodEta[0]";
102     if(variable=="pt") variable="pfpt[0]";
103     if(variable=="pt1") variable="pfpt1[0]";
104 buchmann 1.19 if(variable=="pt2") variable="pfpt2[0]";
105 buchmann 1.1 if(variable=="eta1") variable="pfeta1[0]";
106     if(variable=="jzb[1]") variable="pfjzb[0]";
107     //if(variable=="pfJetGoodNum") variable="pfJetGoodNum"; // pointless.
108     }
109    
110     //Step 2: Refine the cut
111     TCanvas *ckin = new TCanvas("ckin","Kinematic Plots (in the making)",600,600);
112     ckin->SetLogy(logscale);
113     TCut cut;
114     cut=cutmass&&cutOSSF&&cutnJets&&ibasiccut;
115     if(filename=="nJets") cut=cutmass&&cutOSSF&&ibasiccut;
116     if(filename=="nJets_nocuts_except_mll_ossf") cut=cutmass&&cutOSSF;
117     if(filename=="mll") cut=cutOSSF&&cutnJets&&ibasiccut;
118 buchmann 1.18 if(filename=="mll_ee") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==0";
119     if(filename=="mll_mm") cut=cutOSSF&&cutnJets&&ibasiccut&&"id1==1";
120 buchmann 1.17 if(filename=="mll_inclusive"||filename=="mll_inclusive_highrange") cut=cutOSSF;
121 buchmann 1.18 if(filename=="mll_inclusive_ee") cut=cutOSSF&&"id1==0";
122     if(filename=="mll_inclusive_mm") cut=cutOSSF&&"id1==1";
123 buchmann 1.1 if(filename=="pfJetGoodEta_0") cut=cutOSSF&&cutmass&&ibasiccut;
124    
125     TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
126 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
127 buchmann 1.1 THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
128     if(variable=="pfJetGoodPt[0]") datahisto->SetMaximum(10*datahisto->GetMaximum());
129     if(variable=="pt") datahisto->SetMaximum(10*datahisto->GetMaximum());
130     if(filename=="mll_inclusive") datahisto->SetMinimum(1);
131     datahisto->Draw("e1");
132     mcstack.Draw("same");
133     datahisto->Draw("same,e1");
134     TLegend *kinleg = allsamples.allbglegend();
135     kinleg->Draw();
136 buchmann 1.16 TText* write_cut = write_cut_on_canvas(decipher_cut(cut,basicqualitycut));
137 buchmann 1.1 write_cut->Draw();
138     TText* write_variable = write_text(0.99,0.01,variable);
139     write_variable->SetTextAlign(31);
140     write_variable->SetTextSize(0.02);
141 buchmann 1.17 // write_variable->Draw();
142 buchmann 1.1 if(isPF) CompleteSave(ckin,"kin/"+filename+"__PF");
143     else CompleteSave(ckin,"kin/"+filename);
144     datahisto->Delete();
145     }
146    
147     void do_kinematic_plots(bool doPF=false)
148     {
149     bool dolog=true;
150     bool nolog=false;
151 buchmann 1.17 make_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll",doPF);
152 buchmann 1.18 make_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll_ee",doPF);
153     make_plot("mll",50,50,150,dolog,"m_{ll} [GeV]","mll_mm",doPF);
154 buchmann 1.17 make_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive",doPF);
155 buchmann 1.18 make_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive_ee",doPF);
156     make_plot("mll",100,50,150,dolog,"m_{ll} [GeV]","mll_inclusive_mm",doPF);
157 buchmann 1.17 make_plot("mll",300,50,350,dolog,"m_{ll} [GeV]","mll_inclusive_highrange",doPF);
158     make_plot("jetpt[0]",40,0,200,dolog,"leading jet p_{T} [GeV]","pfJetGoodPt_0",doPF);
159 buchmann 1.1 make_plot("jeteta[0]",40,-5,5,nolog,"leading jet #eta","pfJetGoodEta_0",doPF);
160 buchmann 1.17 make_plot("pt",50,0,200,dolog,"Z p_{T} [GeV]","Zpt",doPF);
161 buchmann 1.19 make_plot("pt1",50,0,100,nolog,"p_{T} [GeV]","pt1",doPF);
162     make_plot("pt2",50,0,100,nolog,"p_{T} [GeV]","pt2",doPF);
163 buchmann 1.1 make_plot("eta1",40,-5,5,nolog,"#eta_{l}","eta",doPF);
164 buchmann 1.17 make_plot("jzb[1]",100,-150,150,dolog,"JZB [GeV]","jzb_ossf",doPF);
165 buchmann 1.1 make_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets",doPF);
166     make_plot("pfJetGoodNum",8,0.5,8.5,dolog,"nJets","nJets_nocuts_except_mll_ossf",doPF);
167 buchmann 1.17 make_special_mll_plot(30,50,150,dolog,"m_{ll} [GeV]");
168 buchmann 1.1 }
169    
170     void do_kinematic_PF_plots()
171     {
172     do_kinematic_plots(true);
173     }
174    
175 buchmann 1.11 void signal_bg_comparison()
176 buchmann 1.1 {
177 buchmann 1.11 TCanvas *can = new TCanvas("can","Signal Background Comparison Canvas");
178 buchmann 1.1 int sbg_nbins=100;
179     float sbg_min=-200;
180     float sbg_max=400;
181     can->SetLogy(1);
182 buchmann 1.17 TH1F *JZBplotZJETs = allsamples.Draw("JZBplotZJETs",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("DYJetsToLL"));
183     TH1F *JZBplotLM4 = allsamples.Draw("JZBplotLM4",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("LM4"));
184     TH1F *JZBplotTtbar = allsamples.Draw("JZBplotTtbar",jzbvariablemc,sbg_nbins,sbg_min,sbg_max, "JZB [GeV]", "events",cutmass&&cutOSSF&&cutnJets,mc,luminosity,allsamples.FindSample("TTJets"));
185 buchmann 1.1
186     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
187     JZBplotTtbar->SetLineColor(allsamples.GetColor("TTJet"));
188     JZBplotTtbar->SetLineWidth(2);
189     JZBplotZJETs->SetFillColor(allsamples.GetColor("DY"));
190     JZBplotZJETs->SetLineColor(kBlack);
191     JZBplotLM4->SetLineWidth(2);
192     JZBplotLM4->SetLineStyle(2);
193     JZBplotZJETs->SetMinimum(0.05);
194     JZBplotLM4->Scale(20.0);
195     JZBplotZJETs->Draw("histo");
196     JZBplotLM4->Draw("histo,same");
197     JZBplotTtbar->Draw("histo,same");
198     TLegend *signal_bg_comparison_leg = make_legend("MC:");
199     signal_bg_comparison_leg->AddEntry(JZBplotZJETs,"Z+Jets","f");
200     signal_bg_comparison_leg->AddEntry(JZBplotTtbar,"t#bar{t}","f");
201     signal_bg_comparison_leg->AddEntry(JZBplotLM4,"20xLM4","f");
202     signal_bg_comparison_leg->Draw();
203     CompleteSave(can,"jzb_bg_vs_signal_distribution");
204     JZBplotLM4->Scale(1.0/20);
205     JZBplotZJETs->SetMinimum(0.004);
206     JZBplotZJETs->Draw("histo");
207     JZBplotLM4->Draw("histo,same");
208     JZBplotTtbar->Draw("histo,same");
209     TLegend *signal_bg_comparison_leg2 = make_legend("MC:");
210     signal_bg_comparison_leg2->AddEntry(JZBplotZJETs,"Z+Jets","f");
211     signal_bg_comparison_leg2->AddEntry(JZBplotTtbar,"t#bar{t}","f");
212     signal_bg_comparison_leg2->AddEntry(JZBplotLM4,"LM4","f");
213     signal_bg_comparison_leg2->Draw();
214     CompleteSave(can,"jzb_bg_vs_signal_distribution_unscaled_LM4");
215     }
216    
217 buchmann 1.9 //TF1 *BpredFunc,*BpredFuncP,*BpredFuncN;
218 buchmann 1.1
219 buchmann 1.9 vector<TF1*> do_cb_fit_to_plot(TH1F *histo, float Sigma, float doingfitacrosstheboard=false) {
220 buchmann 1.1
221     // BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
222 buchmann 1.9 TF1 *BpredFunc = new TF1("BpredFunc",InvCrystalBall,0,1000,5);
223 buchmann 1.1 BpredFunc->SetParameter(0,histo->GetBinContent(1));
224 buchmann 1.6 if(doingfitacrosstheboard) BpredFunc->SetParameter(0,histo->GetMaximum());
225 buchmann 1.1 BpredFunc->SetParameter(1,0.);
226     if(method==1) BpredFunc->SetParameter(2,10*Sigma);//KM
227     else BpredFunc->SetParameter(2,Sigma);//Gaussian based methods
228     if(method==-99) BpredFunc->SetParameter(2,2.0*Sigma);//Kostas
229     BpredFunc->SetParameter(3,1.8);
230     BpredFunc->SetParameter(4,2.5);
231 buchmann 1.11 histo->Fit(BpredFunc,"QN0");
232 buchmann 1.1 BpredFunc->SetLineColor(kBlue);
233     BpredFunc->SetLineWidth(1);
234    
235 buchmann 1.9 TF1 *BpredFuncP = new TF1("BpredFuncP",InvCrystalBallP,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
236     TF1 *BpredFuncN = new TF1("BpredFuncN",InvCrystalBallN,-1000,histo->GetBinLowEdge(histo->GetNbinsX())+histo->GetBinWidth(histo->GetNbinsX()),5);
237 buchmann 1.1
238     BpredFuncP->SetParameters(BpredFunc->GetParameters());
239     BpredFuncP->SetLineColor(kBlue);
240     BpredFuncP->SetLineWidth(1);
241     BpredFuncP->SetLineStyle(2);
242    
243     BpredFuncN->SetParameters(BpredFunc->GetParameters());
244     BpredFuncN->SetLineColor(kBlue);
245     BpredFuncN->SetLineWidth(1);
246     BpredFuncN->SetLineStyle(2);
247 buchmann 1.9
248     vector<TF1*> functions;
249     functions.push_back(BpredFuncN);
250     functions.push_back(BpredFunc);
251     functions.push_back(BpredFuncP);
252     return functions;
253 buchmann 1.1 }
254     void do_prediction_plot(string jzb, TCanvas *globalcanvas, float sigma, float high, bool is_data, bool do_fit=true)
255     {
256     int nbins=100;
257     if(is_data) nbins=50;
258     float low=0;
259     float hi=500;
260    
261 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
262     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,is_data, luminosity);
263     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
264     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,is_data, luminosity);
265 buchmann 1.1
266 buchmann 1.17 TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSBem",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
267     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSBem",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,is_data, luminosity);
268 buchmann 1.13
269 buchmann 1.17 TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSBeemm",jzb.c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
270     TH1F *LcorrJZBSBeemm = allsamples.Draw("LcorrJZBSBeemm",("-"+jzb).c_str(),nbins,low,hi, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,is_data, luminosity);
271 buchmann 1.13
272 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"));
273 buchmann 1.13
274 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
275 buchmann 1.13 Bpred->Add(RcorrJZBem,1.0/3);
276     Bpred->Add(LcorrJZBem,-1.0/3);
277     Bpred->Add(RcorrJZBSBem,1.0/3);
278     Bpred->Add(LcorrJZBSBem,-1.0/3);
279     Bpred->Add(RcorrJZBSBeemm,1.0/3);
280     Bpred->Add(LcorrJZBSBeemm,-1.0/3);
281 buchmann 1.1 globalcanvas->cd();
282     globalcanvas->SetLogy(1);
283     Bpred->SetLineColor(kRed);
284     Bpred->SetStats(0);
285     Bpred->GetXaxis()->SetRangeUser(0,high);
286     Bpred->Draw("hist");
287     RcorrJZBeemm->SetMarkerStyle(20);
288     RcorrJZBeemm->Draw("e1x0,same");
289 buchmann 1.13 lm4RcorrJZBeemm->SetLineColor(TColor::GetColor("#088A08"));
290     lm4RcorrJZBeemm->Draw("histo,same");
291 buchmann 1.17 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
292 buchmann 1.13
293 buchmann 1.12 TLegend *legBpred = make_legend("",0.6,0.5);
294 buchmann 1.1 if(is_data)
295     {
296 buchmann 1.9 vector<TF1*> functions = do_cb_fit_to_plot(Bpred,sigma);
297     functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
298 buchmann 1.12 legBpred->AddEntry(RcorrJZBeemm,"observed (data)","p");
299 buchmann 1.1 legBpred->AddEntry(Bpred,"predicted (data)","l");
300 buchmann 1.9 legBpred->AddEntry(functions[0],"predicted fit (data)","l");
301     legBpred->AddEntry(functions[1],"stat. uncert.","l");
302 buchmann 1.13 legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
303 buchmann 1.1 legBpred->Draw();
304     CompleteSave(globalcanvas,"Bpred_Data");
305     }
306     else {
307     legBpred->AddEntry(RcorrJZBeemm,"MC true B","l");
308     legBpred->AddEntry(Bpred,"data-driven B","l");
309 buchmann 1.13 legBpred->AddEntry(lm4RcorrJZBeemm,"LM4","l");
310     legBpred->SetY1(0.65);
311 buchmann 1.1 legBpred->Draw();
312 buchmann 1.13
313 buchmann 1.1 CompleteSave(globalcanvas,"Bpred_MC");
314     }
315 buchmann 1.13
316     cout << "Splitting up the different estimates ... " << endl;
317    
318     TH1F *Bpredem = (TH1F*)LcorrJZBeemm->Clone();
319     Bpredem->Add(RcorrJZBem);
320     Bpredem->Add(LcorrJZBem,-1);
321     TH1F *BpredSBem = (TH1F*)LcorrJZBeemm->Clone();
322     BpredSBem->Add(RcorrJZBSBem);
323     Bpred->Add(LcorrJZBSBem,-1);
324     TH1F *BpredSBeemm = (TH1F*)LcorrJZBeemm->Clone();
325 buchmann 1.17 BpredSBeemm->Add(RcorrJZBSBeemm);
326     BpredSBeemm->Add(LcorrJZBSBeemm,-1.0);
327 buchmann 1.13 globalcanvas->cd();
328     globalcanvas->SetLogy(1);
329     Bpredem->SetLineColor(kRed);
330     Bpredem->SetStats(0);
331     Bpredem->GetXaxis()->SetRangeUser(0,high);
332     Bpredem->Draw("hist");
333     BpredSBem->SetLineColor(TColor::GetColor("#0B6138"));
334     BpredSBem->Draw("hist,same");
335     BpredSBeemm->SetLineColor(kBlue);
336     BpredSBeemm->Draw("hist,same");
337     RcorrJZBeemm->SetMarkerStyle(20);
338     RcorrJZBeemm->Draw("e1x0,same");
339 buchmann 1.17 RcorrJZBeemm->SetMarkerSize(DataMarkerSize);
340 buchmann 1.13
341     TLegend *legBpredc = make_legend("",0.6,0.5);
342     if(is_data)
343     {
344     legBpredc->AddEntry(RcorrJZBeemm,"observed (data)","p");
345     legBpredc->AddEntry(Bpredem,"predicted (e#mu method)","l");
346     legBpredc->AddEntry(BpredSBem,"predicted (OF sidebands)","l");
347     legBpredc->AddEntry(BpredSBeemm,"predicted (SF sidebands)","l");
348     legBpredc->Draw();
349     CompleteSave(globalcanvas,"Bpred_Data_comparison");
350     }
351     else {
352     legBpredc->AddEntry(RcorrJZBeemm,"observed (MC)","p");
353     legBpredc->AddEntry(Bpredem,"predicted (e#mu method)","l");
354     legBpredc->AddEntry(BpredSBem,"predicted (OF sidebands)","l");
355     legBpredc->AddEntry(BpredSBeemm,"predicted (SF sidebands)","l");
356     legBpredc->Draw();
357     legBpredc->Draw();
358     CompleteSave(globalcanvas,"Bpred_MC_comparison");
359     }
360     delete RcorrJZBeemm;
361     delete LcorrJZBeemm;
362     delete RcorrJZBem;
363     delete LcorrJZBem;
364     delete RcorrJZBSBem;
365     delete LcorrJZBSBem;
366     delete RcorrJZBSBeemm;
367     delete LcorrJZBSBeemm;
368     delete lm4RcorrJZBeemm;
369 buchmann 1.1 }
370    
371 buchmann 1.11 void do_prediction_plots(string mcjzb, string datajzb, float DataSigma, float MCSigma) {
372     TCanvas *globalcanvas = new TCanvas("globalcanvas","Prediction Canvas");
373 buchmann 1.1 do_prediction_plot(datajzb,globalcanvas,DataSigma,350,data);
374     do_prediction_plot(mcjzb,globalcanvas,MCSigma,300,mc);
375     }
376    
377     void do_ratio_plot(int is_data,vector<float> binning, string jzb, TCanvas *can, float high=-9999) {
378     bool do_data=0;
379     bool dosignal=0;
380     if(is_data==1) do_data=1;
381     if(is_data==2) dosignal=1;
382 buchmann 1.17 TH1F *RcorrJZBeemm = allsamples.Draw("RcorrJZBeemm",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
383     TH1F *LcorrJZBeemm = allsamples.Draw("LcorrJZBeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
384     TH1F *RcorrJZBem = allsamples.Draw("RcorrJZBem",jzb.c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
385     TH1F *LcorrJZBem = allsamples.Draw("LcorrJZBem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
386    
387     TH1F *RcorrJZBSBem = allsamples.Draw("RcorrJZBSbem",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
388     TH1F *LcorrJZBSBem = allsamples.Draw("LcorrJZBSbem",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSOF&&cutnJets,do_data, luminosity,dosignal);
389     TH1F *RcorrJZBSBeemm = allsamples.Draw("RcorrJZBSbeemm",jzb.c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
390     TH1F *LcorrJZBSbeemm = allsamples.Draw("LcorrJZBSbeemm",("-"+jzb).c_str(),binning, "JZB [GeV]", "events", sidebandcut&&cutOSSF&&cutnJets,do_data, luminosity,dosignal);
391 buchmann 1.13
392 buchmann 1.17 TH1F *Bpred = (TH1F*)LcorrJZBeemm->Clone("Bpred");
393 buchmann 1.13 Bpred->Add(RcorrJZBem,1.0/3);
394     Bpred->Add(LcorrJZBem,-1.0/3);
395     Bpred->Add(RcorrJZBSBem,1.0/3);
396     Bpred->Add(LcorrJZBSBem,-1.0/3);
397     Bpred->Add(RcorrJZBSBeemm,1.0/3);
398     Bpred->Add(LcorrJZBSbeemm,-1.0/3);
399 buchmann 1.1 can->cd();
400     can->SetLogy(0);
401     Bpred->SetLineColor(kRed);
402     Bpred->SetStats(0);
403     if(high>0) Bpred->GetXaxis()->SetRangeUser(0,high);
404 buchmann 1.17 TH1F *JZBratioforfitting=(TH1F*)RcorrJZBeemm->Clone("JZBratioforfitting");
405     JZBratioforfitting->Divide(Bpred);
406 buchmann 1.1 TGraphAsymmErrors *JZBratio = histRatio(RcorrJZBeemm,Bpred,is_data,binning);
407 buchmann 1.17
408 buchmann 1.1
409     JZBratio->SetTitle("");
410     JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
411 buchmann 1.17 // if(is_data==1) JZBratio->GetXaxis()->SetRangeUser(0,350);
412 buchmann 1.1
413     TF1 *pol0 = new TF1("pol0","[0]",0,1000);
414     TF1 *pol0d = new TF1("pol0","[0]",0,1000);
415     // straightline_fit->SetParameter(0,1);
416     JZBratioforfitting->Fit(pol0,"Q0R","",0,30);
417     pol0d->SetParameter(0,pol0->GetParameter(0));
418    
419     JZBratio->GetYaxis()->SetTitle("Observed/Predicted");
420 buchmann 1.17 JZBratio->GetXaxis()->SetTitle("JZB [GeV]");
421 buchmann 1.1 JZBratio->GetYaxis()->SetNdivisions(519);
422     JZBratio->GetYaxis()->SetRangeUser(0.0,9.0);
423 buchmann 1.17 JZBratio->GetYaxis()->CenterTitle();
424     JZBratio->GetXaxis()->CenterTitle();
425     JZBratio->SetMarkerSize(DataMarkerSize);
426 buchmann 1.1 JZBratio->Draw("AP");
427     /////----------------------------
428     TPaveText *writeresult = new TPaveText(0.2,0.78,0.49,0.91,"blNDC");
429     writeresult->SetFillStyle(4000);
430     writeresult->SetFillColor(kWhite);
431     writeresult->SetTextFont(42);
432     ostringstream jzb_agreement_data_text;
433     jzb_agreement_data_text<< setprecision(2) << "mean =" << pol0->GetParameter(0) << " #pm " << setprecision(1) << pol0->GetParError(0);
434     if(is_data==1) fitresultconstdata=pol0->GetParameter(0);// data
435     if(is_data==0) fitresultconstmc=pol0->GetParameter(0); // monte carlo, no signal
436     /* if(is_data) writeresult->AddText("Data closure test");
437     else writeresult->AddText("MC closure test");
438     */
439     writeresult->AddText(jzb_agreement_data_text.str().c_str());
440     writeresult->Draw("same");
441     pol0d->Draw("same");
442     TF1 *topline = new TF1("","1.2",0,1000);
443     TF1 *bottomline = new TF1("","0.6",0,1000);
444     topline->SetLineColor(kBlue);
445     topline->SetLineStyle(2);
446     bottomline->SetLineColor(kBlue);
447     bottomline->SetLineStyle(2);
448     topline->Draw("same");
449     bottomline->Draw("same");
450     TF1 *oneline = new TF1("","1.0",0,1000);
451     oneline->SetLineColor(kBlue);
452     oneline->SetLineStyle(1);
453     oneline->Draw("same");
454 buchmann 1.17 TLegend *phony_leg = make_legend("ratio");//this line is just to have the default CMS Preliminary (...) on the canvas as well.
455     TLegend *leg = new TLegend(0.60,0.5,0.94,0.89);
456 buchmann 1.1 leg->SetTextFont(42);
457 buchmann 1.17 if(is_data==1) leg->SetHeader("Ratio (data)");
458     else leg->SetHeader("Ratio (MC)");
459 buchmann 1.1
460     leg->SetFillStyle(4000);
461     leg->SetFillColor(kWhite);
462     leg->SetTextFont(42);
463     // leg->AddEntry(topline,"+20\% sys envelope","l");
464     leg->AddEntry(JZBratio,"obs/pred","p");
465     leg->AddEntry(oneline,"ratio = 1","l");
466     leg->AddEntry(pol0d,"fit in [0,30] GeV","l");
467     leg->AddEntry(bottomline,"sys. envelope","l");
468     leg->Draw("same");
469     if(is_data==1) CompleteSave(can, "jzb_ratio_data");
470     if(is_data==0) CompleteSave(can, "jzb_ratio_mc");
471     if(is_data==2) CompleteSave(can, "jzb_ratio_mc_BandS");//special case, MC with signal!
472 buchmann 1.17
473 buchmann 1.1 delete RcorrJZBeemm;
474     delete LcorrJZBeemm;
475     delete RcorrJZBem;
476     delete LcorrJZBem;
477 buchmann 1.17
478     delete RcorrJZBSBem;
479     delete LcorrJZBSBem;
480     delete RcorrJZBSBeemm;
481     delete LcorrJZBSbeemm;
482 buchmann 1.1 }
483    
484 buchmann 1.11 void do_ratio_plots(string mcjzb,string datajzb) {
485     TCanvas *globalc = new TCanvas("globalc","Ratio Plot Canvas");
486 buchmann 1.1 globalc->SetLogy(0);
487     vector<float> ratio_binning;
488     ratio_binning.push_back(0);
489     ratio_binning.push_back(5);
490     ratio_binning.push_back(10);
491     ratio_binning.push_back(20);
492     ratio_binning.push_back(50);
493     ratio_binning.push_back(100);
494 buchmann 1.17 //ratio_binning.push_back(350);
495     ratio_binning.push_back(200);
496 buchmann 1.1 ratio_binning.push_back(500);
497    
498     do_ratio_plot(mc,ratio_binning,mcjzb,globalc);
499     do_ratio_plot(data,ratio_binning,datajzb,globalc);
500     do_ratio_plot(mcwithsignal,ratio_binning,mcjzb,globalc);
501     }
502    
503 buchmann 1.8 string give_jzb_expression(float peak, int type) {
504 buchmann 1.1 stringstream val;
505 buchmann 1.8 if(type==data) {
506     if(peak<0) val << jzbvariabledata << "+" << TMath::Abs(peak);
507     if(peak>0) val << jzbvariabledata << "-" << TMath::Abs(peak);
508     if(peak==0) val << jzbvariabledata;
509     }
510     if(type==mc) {
511     if(peak<0) val << jzbvariablemc << "+" << TMath::Abs(peak);
512     if(peak>0) val << jzbvariablemc << "-" << TMath::Abs(peak);
513     if(peak==0) val << jzbvariablemc;
514     }
515 buchmann 1.1 return val.str();
516     }
517    
518    
519 buchmann 1.11 void lepton_comparison_plots() {
520     TCanvas *can = new TCanvas("can","Lepton Comparison Canvas");
521 buchmann 1.1 can->SetLogy(1);
522 buchmann 1.17 TH1F *eemc = allsamples.Draw("eemc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
523     TH1F *mmmc = allsamples.Draw("mmmc","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL"));
524 buchmann 1.1 eemc->SetLineColor(kBlue);
525     mmmc->SetLineColor(kRed);
526     eemc->SetMinimum(0.1);
527     eemc->SetMaximum(10*eemc->GetMaximum());
528     eemc->Draw("histo");
529     mmmc->Draw("histo,same");
530     TLegend *leg = make_legend();
531 buchmann 1.17 leg->AddEntry(eemc,"ZJets->ee (MC)","l");
532     leg->AddEntry(mmmc,"ZJets->#mu#mu (MC)","l");
533 buchmann 1.11 leg->Draw("same");
534 buchmann 1.1 CompleteSave(can, "mll_effratio_mc");
535    
536 buchmann 1.17 TH1F *eed = allsamples.Draw("eed","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
537     TH1F *mmd = allsamples.Draw("mmd","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
538 buchmann 1.1 eed->SetLineColor(kBlue);
539     mmd->SetLineColor(kRed);
540     eed->SetMinimum(0.1);
541     eed->SetMaximum(10*eed->GetMaximum());
542     eed->Draw("histo");
543     mmd->Draw("histo,same");
544     TLegend *leg2 = make_legend();
545 buchmann 1.17 leg2->AddEntry(eed,"ZJets->ee (data)","l");
546     leg2->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
547 buchmann 1.1 leg2->Draw();
548     CompleteSave(can, "mll_effratio_data");
549    
550 buchmann 1.17 TH1F *jeed = allsamples.Draw("jeed",jzbvariabledata, 90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",data, luminosity);
551     TH1F *jmmd = allsamples.Draw("jmmd",jzbvariabledata, 90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",data, luminosity);
552     TH1F *jeemmd = allsamples.Draw("jeemmd",jzbvariabledata,90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
553 buchmann 1.11 cout << "ee : " << jeed->GetMean() << "+/-" << jeed->GetMeanError() << endl;
554     cout << "ee : " << jmmd->GetMean() << "+/-" << jmmd->GetMeanError() << endl;
555     cout << "eemd : " << jeemmd->GetMean() << "+/-" << jeemmd->GetMeanError() << endl;
556 buchmann 1.1 jeemmd->SetLineColor(kBlack);
557     jeemmd->SetMarkerStyle(25);
558     jeed->SetLineColor(kBlue);
559     jmmd->SetLineColor(kRed);
560     jeed->SetMinimum(0.1);
561     jeed->SetMaximum(10*eed->GetMaximum());
562     jeemmd->DrawNormalized();
563     jeed->DrawNormalized("histo,same");
564     jmmd->DrawNormalized("histo,same");
565     jeemmd->DrawNormalized("same");
566     TLegend *jleg2 = make_legend("Data");
567     jleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
568     jleg2->AddEntry(jeed,"ee","l");
569     jleg2->AddEntry(jmmd,"#mu#mu","l");
570     jleg2->Draw();
571     CompleteSave(can,"jzb_effratio_data");
572    
573 buchmann 1.17 TH1F *zjeed = allsamples.Draw("zjeed",jzbvariabledata, 90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==0)",mc, luminosity,allsamples.FindSample("DYJetsToLL_TuneZ2"));
574     TH1F *zjmmd = allsamples.Draw("zjmmd",jzbvariabledata, 90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets&&"(id1==1)",mc, luminosity,allsamples.FindSample("DYJetsToLL_TuneZ2"));
575     TH1F *zjeemmd = allsamples.Draw("zjeemmd",jzbvariabledata,90,-100,350, "JZB [GeV]", "events", cutOSSF&&cutnJets,mc, luminosity,allsamples.FindSample("DYJetsToLL_TuneZ2"));
576 buchmann 1.11 cout << "Z+Jets ee : " << zjeed->GetMean() << "+/-" << zjeed->GetMeanError() << endl;
577     cout << "Z+Jets ee : " << zjmmd->GetMean() << "+/-" << zjmmd->GetMeanError() << endl;
578     cout << "Z+Jets eemd : " << zjeemmd->GetMean() << "+/-" << zjeemmd->GetMeanError() << endl;
579     zjeemmd->SetLineColor(kBlack);
580     zjeemmd->SetMarkerStyle(25);
581     zjeed->SetLineColor(kBlue);
582     zjmmd->SetLineColor(kRed);
583     zjeed->SetMinimum(0.1);
584     zjeed->SetMaximum(10*eed->GetMaximum());
585     zjeemmd->DrawNormalized();
586     zjeed->DrawNormalized("histo,same");
587     zjmmd->DrawNormalized("histo,same");
588     zjeemmd->DrawNormalized("same");
589     TLegend *zjleg2 = make_legend("Data");
590     zjleg2->AddEntry(jeemmd,"ee and #mu#mu","p");
591     zjleg2->AddEntry(jeed,"ee","l");
592     zjleg2->AddEntry(jmmd,"#mu#mu","l");
593     zjleg2->Draw();
594     CompleteSave(can,"jzb_effratio_ZJets");
595    
596 buchmann 1.17 TH1F *ld = allsamples.Draw("ld","mll",50,50,150, "mll [GeV]", "events", cutOSSF&&cutnJets,data, luminosity);
597 buchmann 1.1 ld->DrawNormalized("e1");
598     eed->DrawNormalized("histo,same");
599     mmd->DrawNormalized("histo,same");
600     TLegend *leg3 = make_legend();
601     leg3->AddEntry(ld,"ZJets->ll (data)","p");
602 buchmann 1.17 leg3->AddEntry(eed,"ZJets->ee (data)","l");
603     leg3->AddEntry(mmd,"ZJets->#mu#mu (data)","l");
604 buchmann 1.1 leg3->Draw();
605     CompleteSave(can,"mll_effratio_data__all_compared");
606     /*
607 buchmann 1.17 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
608     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariable,75,-150,150, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
609 buchmann 1.1 */
610 buchmann 1.17 TH1F *jzbld = allsamples.Draw("jzbld",jzbvariabledata,92,-110,350, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity);
611     TH1F *jzbemd = allsamples.Draw("jzbemd",jzbvariabledata,92,-110,350, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity);
612 buchmann 1.1 jzbld->SetMarkerColor(kBlack);
613     jzbld->SetMarkerStyle(26);
614     jzbemd->SetMarkerStyle(25);
615     jzbemd->SetMarkerColor(kRed);
616     jzbemd->SetLineColor(kRed);
617     jzbld->SetMinimum(0.35);
618     jzbld->Draw("e1");
619     jzbemd->Draw("e1,same");
620     TLegend *leg4 = make_legend("Data");
621     leg4->AddEntry(jzbld,"ee or #mu#mu","p");
622     leg4->AddEntry(jzbemd,"e#mu","p");
623     leg4->Draw();
624     CompleteSave(can,"jzb_eemumu_emu_data");
625    
626 buchmann 1.17 TH1F *ttbarjzbld = allsamples.Draw("ttbarjzbld",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
627     TH1F *ttbarjzbemd = allsamples.Draw("ttbarjzbemd",jzbvariablemc,110,-150,400, "JZB [GeV]", "events", cutmass&&cutOSOF&&cutnJets,data, luminosity,allsamples.FindSample("TTJet"));
628 buchmann 1.1 ttbarjzbld->SetLineColor(allsamples.GetColor("TTJet"));
629     ttbarjzbemd->SetLineColor(allsamples.GetColor("TTJet"));
630     ttbarjzbld->SetLineWidth(2);
631     ttbarjzbemd->SetLineWidth(2);
632     ttbarjzbld->Draw("histo");
633     ttbarjzbemd->SetLineStyle(2);
634     ttbarjzbemd->Draw("histo,same");
635     TLegend *leg5 = make_legend();
636 buchmann 1.17 leg5->AddEntry(ttbarjzbld,"t#bar{t}->(ee or #mu#mu)","l");
637     leg5->AddEntry(ttbarjzbemd,"t#bar{t}->e#mu","l");
638 buchmann 1.1 leg5->Draw();
639     CompleteSave(can,"ttbar_emu_mc");
640    
641    
642    
643     }
644    
645     bool is_OF(TCut cut) {
646     string scut = (const char*) cut;
647     if((int)scut.find("id1!=id2")>-1) return true;
648     if((int)scut.find("id1==id2")>-1) return false;
649     return false;
650     }
651    
652     void draw_pure_jzb_histo(TCut cut,string variable,string savename, TCanvas *can,float min,float max,int nbins) {
653     can->cd();
654     can->SetLogy(1);
655 buchmann 1.17 string xlabel="JZB [GeV]";
656 buchmann 1.1
657     TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
658     THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
659    
660     datahisto->SetMinimum(0.1);
661 buchmann 1.12 //if(savename=="jzb_OSOF") datahisto->SetMaximum(10);
662 buchmann 1.17 datahisto->SetMarkerSize(DataMarkerSize);
663 buchmann 1.1 datahisto->Draw("e1");
664     mcstack.Draw("same");
665     datahisto->Draw("same,e1");
666    
667     TLegend *leg;
668     if(is_OF(cut)) leg = allsamples.allbglegend("Opposite Flavor",datahisto);
669     else leg = allsamples.allbglegend("Same Flavor",datahisto);
670     leg->Draw();
671     string write_cut = decipher_cut(cut,"");
672 buchmann 1.16 TText *writeline1 = write_cut_on_canvas(write_cut.c_str());
673 buchmann 1.1 writeline1->SetTextSize(0.035);
674     writeline1->Draw();
675     CompleteSave(can, ("jzb/"+savename));
676    
677     datahisto->Delete();
678     mcstack.Delete();
679     }
680    
681     Double_t GausR(Double_t *x, Double_t *par) {
682     return gRandom->Gaus(x[0],par[0]);
683     }
684    
685 buchmann 1.11 void jzb_plots(string mcjzb, string datajzb) {
686     TCanvas *can = new TCanvas("can","JZB Plots Canvas");
687 buchmann 1.1 float max=350;
688     float min=-120;
689     int nbins=(max-min)/5.0; // we want 5 GeV/bin
690    
691     stringstream ss;
692     // ss << "GausRandom(" << datajzb << ",0)";
693     draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OSSF",can,min,max,nbins);
694     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OSOF",can,min,max,nbins);
695 buchmann 1.12 draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OSSF_SB",can,min,max,nbins);
696     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OSOF_SB",can,min,max,nbins);
697 buchmann 1.1 draw_pure_jzb_histo(cutOSSF&&cutnJets&&cutmass,datajzb,"jzb_OSSF_rebin",can,min,max,nbins/4.0);
698     draw_pure_jzb_histo(cutOSOF&&cutnJets&&cutmass,datajzb,"jzb_OSOF_rebin",can,min,max,nbins/4.0);
699 buchmann 1.12 draw_pure_jzb_histo(cutOSSF&&cutnJets&&sidebandcut,datajzb,"jzb_OSSF_SB_rebin",can,min,max,nbins/4.0);
700     draw_pure_jzb_histo(cutOSOF&&cutnJets&&sidebandcut,datajzb,"jzb_OSOF_SB_rebin",can,min,max,nbins/4.0);
701 buchmann 1.1 }
702    
703     void calculate_all_yields(string mcdrawcommand,vector<float> jzb_cuts) {
704     cout << "Calculating background yields in MC:" << endl;
705     jzb_cuts.push_back(14000);
706 buchmann 1.17 TH1F *allbgs = allsamples.Draw("allbgs",jzbvariablemc,jzb_cuts, "JZB [GeV]", "events", cutmass&&cutOSSF&&cutnJets,mc,luminosity);
707 buchmann 1.1 float cumulative=0;
708     for(int i=allbgs->GetNbinsX();i>=1;i--) {
709     cumulative+=allbgs->GetBinContent(i);
710     cout << "Above " << allbgs->GetBinLowEdge(i) << " GeV/c : " << cumulative << endl;
711     }
712     }
713    
714 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) {
715 buchmann 1.10 //Step 1: Establishing cuts
716 buchmann 1.3 stringstream jetcutstring;
717 buchmann 1.10 string writescenario="";
718    
719 buchmann 1.3 if(scenario==0) jetcutstring << "(pfJetGoodNum>=3)&&"<<(const char*) basicqualitycut;
720     if(scenario==1) jetcutstring << "(pfJetPt[0]>50&&pfJetPt[1]>50)&&"<<(const char*)basicqualitycut;
721     TCut jetcut(jetcutstring.str().c_str());
722     string leptoncut="mll>0";
723     if(leptontype==0||leptontype==1) {
724 buchmann 1.10 if(leptontype==0) {
725     leptoncut="id1==0";
726     writescenario="__ee";
727     }
728     else {
729     leptoncut="id1==1";
730     writescenario="__ee";
731     }
732 buchmann 1.3 }
733     TCut lepcut(leptoncut.c_str());
734    
735 buchmann 1.6 TCanvas *c5 = new TCanvas("c5","c5",1500,500);
736 buchmann 1.10 TCanvas *c6 = new TCanvas("c6","c6");
737 buchmann 1.3 c5->Divide(3,1);
738 buchmann 1.10
739     //STEP 2: Extract Zjets shape in data
740     c5->cd(1);
741 buchmann 1.3 c5->cd(1)->SetLogy(1);
742     TCut massat40("mll>40");
743 buchmann 1.17 TH1F *ossfleft = allsamples.Draw("ossfleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
744     TH1F *osofleft = allsamples.Draw("osofleft", "-"+datajzb,40,0,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
745 buchmann 1.3 ossfleft->SetLineColor(kRed);
746     ossfleft->SetMarkerColor(kRed);
747     ossfleft->Add(osofleft,-1);
748 buchmann 1.9 vector<TF1*> functions = do_cb_fit_to_plot(ossfleft,10);
749 buchmann 1.17 ossfleft->SetMarkerSize(DataMarkerSize);
750 buchmann 1.3 ossfleft->Draw();
751 buchmann 1.9 functions[0]->Draw("same");functions[1]->Draw("same");functions[2]->Draw("same");
752     TF1 *zjetsfunc = (TF1*) functions[1]->Clone();
753     TF1 *zjetsfuncN = (TF1*) functions[0]->Clone();
754     TF1 *zjetsfuncP = (TF1*) functions[2]->Clone();
755 buchmann 1.6 zjetsfunc->Draw("same");zjetsfuncN->Draw("same");zjetsfuncP->Draw("same");
756 buchmann 1.3 TLegend *leg1 = new TLegend(0.6,0.6,0.89,0.80);
757     leg1->SetFillColor(kWhite);
758     leg1->SetLineColor(kWhite);
759     leg1->AddEntry(ossfleft,"OSSF (sub),JZB<peak","p");
760 buchmann 1.6 leg1->AddEntry(zjetsfunc,"OSSF fit ('zjets')","l");
761 buchmann 1.3 leg1->Draw("same");
762     TText *titleleft = write_title("Extracting Z+Jets shape");
763     titleleft->Draw();
764    
765 buchmann 1.10 //Step 3: Extract ttbar shape (in data or MC?)
766     c5->cd(2);
767 buchmann 1.3 c5->cd(2)->SetLogy(1);
768 buchmann 1.4 TH1F *osof;
769     TText *titlecenter;
770 buchmann 1.10 bool frommc=false;
771     if(frommc) {
772 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,mc,luminosity,allsamples.FindSample("TTJets"));
773 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from ossf MC)");
774     }
775     else {
776 buchmann 1.17 osof = allsamples.Draw("osof",datajzb,40,-200,200, "JZB [GeV]", "events", massat40&&cutOSOF&&jetcut&&lepcut,data,luminosity);
777 buchmann 1.4 titlecenter = write_title("Extracting ttbar shape (from osof data)");
778     }
779 buchmann 1.17 osof->SetMarkerSize(DataMarkerSize);
780 buchmann 1.3 osof->Draw();
781 buchmann 1.10 vector<TF1*> ttbarfunctions = do_cb_fit_to_plot(osof,35,true);
782     ttbarfunctions[0]->SetLineColor(kRed); ttbarfunctions[0]->SetLineStyle(2); ttbarfunctions[0]->Draw("same");
783     ttbarfunctions[1]->SetLineColor(kRed); ttbarfunctions[1]->Draw("same");
784     ttbarfunctions[2]->SetLineColor(kRed); ttbarfunctions[2]->SetLineStyle(2); ttbarfunctions[2]->Draw("same");
785    
786 buchmann 1.3 TLegend *leg2 = new TLegend(0.15,0.8,0.4,0.89);
787     leg2->SetFillColor(kWhite);
788     leg2->SetLineColor(kWhite);
789 buchmann 1.10 if(frommc) {
790 buchmann 1.4 leg2->AddEntry(osof,"t#bar{t} OSSF, MC","p");
791 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to t#bar{t} OSSF,MC","l");
792 buchmann 1.4 } else {
793     leg2->AddEntry(osof,"OSOF","p");
794 buchmann 1.10 leg2->AddEntry(ttbarfunctions[1],"Fit to OSOF","l");
795 buchmann 1.4 }
796 buchmann 1.3 leg2->Draw("same");
797     titlecenter->Draw();
798 buchmann 1.10
799     //--------------------------------------------------------------------------------------------------------------------------------
800 buchmann 1.4 //STEP 4: Present it!
801     // actually: if we wanna let it float we need to do that first :-)
802 buchmann 1.3 c5->cd(3);
803     c5->cd(3)->SetLogy(1);
804 buchmann 1.17 TH1F *observed = allsamples.Draw("observed",datajzb,100,0,500, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
805     observed->SetMarkerSize(DataMarkerSize);
806 buchmann 1.4
807 buchmann 1.6 TF1 *logparc = new TF1("logparc",InvCrystalBall,0,1000,5); logparc->SetLineColor(kRed);
808 buchmann 1.8 TF1 *logparcn = new TF1("logparcn",InvCrystalBallN,0,1000,5); logparcn->SetLineColor(kRed); logparcn->SetLineStyle(2);
809     TF1 *logparcp = new TF1("logparcp",InvCrystalBallP,0,1000,5); logparcp->SetLineColor(kRed); logparcp->SetLineStyle(2);
810 buchmann 1.6
811     TF1 *zjetsc = new TF1("zjetsc",InvCrystalBall,0,1000,5); zjetsc->SetLineColor(kBlue);
812     TF1 *zjetscn = new TF1("zjetscn",InvCrystalBallN,0,1000,5); zjetscn->SetLineColor(kBlue); zjetscn->SetLineStyle(2);
813     TF1 *zjetscp = new TF1("zjetscp",InvCrystalBallP,0,1000,5); zjetscp->SetLineColor(kBlue); zjetscp->SetLineStyle(2);
814    
815 buchmann 1.10 TF1 *ZplusJetsplusTTbar = new TF1("ZplusJetsplusTTbar", DoubleInvCrystalBall,0,1000,10); ZplusJetsplusTTbar->SetLineColor(kBlue);
816     TF1 *ZplusJetsplusTTbarP= new TF1("ZplusJetsplusTTbarP",DoubleInvCrystalBallP,0,1000,10); ZplusJetsplusTTbarP->SetLineColor(kBlue); ZplusJetsplusTTbarP->SetLineStyle(2);
817     TF1 *ZplusJetsplusTTbarN= new TF1("ZplusJetsplusTTbarN",DoubleInvCrystalBallN,0,1000,10); ZplusJetsplusTTbarN->SetLineColor(kBlue); ZplusJetsplusTTbarN->SetLineStyle(2);
818    
819 buchmann 1.6 zjetsc->SetParameters(zjetsfunc->GetParameters());
820     zjetscp->SetParameters(zjetsfunc->GetParameters());
821     zjetscn->SetParameters(zjetsfunc->GetParameters());
822 buchmann 1.10
823 buchmann 1.17 TH1F *observeda = allsamples.Draw("observeda",datajzb,53,80,350, "JZB [GeV]", "events", massat40&&cutOSSF&&jetcut&&lepcut,data,luminosity);
824 buchmann 1.7 //blublu
825 buchmann 1.10 logparc->SetParameters(ttbarfunctions[1]->GetParameters());
826     logparcn->SetParameters(ttbarfunctions[1]->GetParameters());
827     logparcp->SetParameters(ttbarfunctions[1]->GetParameters());
828 buchmann 1.4 if(floating) {
829 buchmann 1.10 cout << "TTbar contribution assumed (before fitting) : " << logparc->GetParameter(0) << endl;
830     logparc->SetParameters(ttbarfunctions[1]->GetParameters());
831 buchmann 1.7 for(int i=0;i<10;i++) {
832     if(i<5) ZplusJetsplusTTbar->FixParameter(i,zjetsfunc->GetParameter(i));
833     if(i>=5) {
834     if (i>5) ZplusJetsplusTTbar->FixParameter(i,logparc->GetParameter(i-5));
835     if (i==5) ZplusJetsplusTTbar->SetParameter(i,logparc->GetParameter(i-5));
836     }
837     }//end of setting parameters
838     observeda->Draw("same");
839     ZplusJetsplusTTbar->Draw("same");
840     observeda->Fit(ZplusJetsplusTTbar);
841     cout << "--> Quality of Z+Jets / TTbar fit : chi2/ndf = " << ZplusJetsplusTTbar->GetChisquare() << "/" << ZplusJetsplusTTbar->GetNDF() << endl;
842     ZplusJetsplusTTbar->Draw("same");
843 buchmann 1.8 ZplusJetsplusTTbarP->SetParameters(ZplusJetsplusTTbar->GetParameters());
844     ZplusJetsplusTTbarN->SetParameters(ZplusJetsplusTTbar->GetParameters());
845 buchmann 1.10 cout << "TTbar contribution found (after fitting) : " << ZplusJetsplusTTbar->GetParameter(5) << endl;
846 buchmann 1.7 float factor = ZplusJetsplusTTbar->GetParameter(5) / logparc->GetParameter(0);
847     cout << "FACTOR: " << factor << endl;
848 buchmann 1.10 logparc->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
849     logparcn->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
850     logparcp->SetParameter(0,factor*ttbarfunctions[1]->GetParameter(0));
851 buchmann 1.4 }
852 buchmann 1.6
853 buchmann 1.4 c5->cd(3);
854 buchmann 1.6 c5->cd(3)->SetLogy(1);
855     observed->Draw();
856     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
857 buchmann 1.3 logparc->Draw("same");
858 buchmann 1.6 logparcn->Draw("same");
859     logparcp->Draw("same");
860    
861 buchmann 1.3 TLegend *leg3 = new TLegend(0.6,0.6,0.89,0.80);
862     leg3->SetFillColor(kWhite);
863     leg3->SetLineColor(kWhite);
864     leg3->AddEntry(observed,"OSSF,JZB>peak","p");
865 buchmann 1.10 leg3->AddEntry(ttbarfunctions[1],"OSOF fit ('ttbar')","l");
866 buchmann 1.6 leg3->AddEntry(zjetsfunc,"OSSF,JZB<0 fit ('zjets')","l");
867 buchmann 1.3 leg3->Draw("same");
868     TText *titleright = write_title("Summary of shapes and observed shape");
869     titleright->Draw();
870    
871     c6->cd()->SetLogy(1);
872 buchmann 1.6 observed->Draw();
873     zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
874 buchmann 1.3 logparc->Draw("same");
875 buchmann 1.6 logparcn->Draw("same");
876     logparcp->Draw("same");
877 buchmann 1.3 leg3->Draw("same");
878     titleright->Draw();
879    
880     if(scenario==0) {
881     CompleteSave(c5,"Shapes2/Making_of___3jetsabove30"+writescenario);
882 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd1");
883     CompleteSave(c5->cd(2),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd2");
884     CompleteSave(c5->cd(3),"Shapes2/Making_of___3jetsabove30"+writescenario+"__cd3");
885 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30"+writescenario);
886     } else {
887     CompleteSave(c5,"Shapes2/Making_of___2jetsabove50"+writescenario);
888 buchmann 1.6 CompleteSave(c5->cd(1),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd1");
889     CompleteSave(c5->cd(2),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd2");
890     CompleteSave(c5->cd(3),"Shapes2/Making_of___2jetsabove50"+writescenario+"__cd3");
891 buchmann 1.3 CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50"+writescenario);
892     }
893 buchmann 1.6 cout << "Statistics about our fits: " << endl;
894 buchmann 1.7 cout << "Z+Jets shape: Chi2/ndf = " << zjetsfunc->GetChisquare() << "/" << ossfleft->GetNbinsX() << endl;
895 buchmann 1.10 cout << "ttbar shape: Chi2/ndf = " << ttbarfunctions[1]->GetChisquare() << "/" << osof->GetNbinsX() << endl;
896 buchmann 1.4
897 buchmann 1.7 c6->cd();
898 buchmann 1.8 TLegend *additionallegend = new TLegend(0.6,0.6,0.89,0.89);
899     additionallegend->SetFillColor(kWhite);
900     additionallegend->SetLineColor(kWhite);
901     additionallegend->AddEntry(observed,"Data","p");
902     additionallegend->AddEntry(ZplusJetsplusTTbar,"Fitted Z+jets & TTbar","l");
903     additionallegend->AddEntry(zjetsc,"Z+jets","l");
904     additionallegend->AddEntry(logparc,"TTbar","l");
905 buchmann 1.7 observed->Draw();
906     ZplusJetsplusTTbar->SetLineColor(kGreen);
907 buchmann 1.8 ZplusJetsplusTTbarP->SetLineColor(kGreen);
908     ZplusJetsplusTTbarN->SetLineColor(kGreen);
909     ZplusJetsplusTTbarP->SetLineStyle(2);
910     ZplusJetsplusTTbarN->SetLineStyle(2);
911     TF1 *ZplusJetsplusTTbar2 = new TF1("ZplusJetsplusTTbar2",DoubleInvCrystalBall,0,1000,10);
912     ZplusJetsplusTTbar2->SetParameters(ZplusJetsplusTTbar->GetParameters());
913     ZplusJetsplusTTbar2->SetLineColor(kGreen);
914     ZplusJetsplusTTbarP->SetFillColor(TColor::GetColor("#81F781"));
915     ZplusJetsplusTTbarN->SetFillColor(kWhite);
916     ZplusJetsplusTTbarP->Draw("fcsame");
917     ZplusJetsplusTTbarN->Draw("fcsame");
918     TH1F *hZplusJetsplusTTbar = (TH1F*)ZplusJetsplusTTbar2->GetHistogram();
919     TH1F *hZplusJetsplusTTbarN = (TH1F*)ZplusJetsplusTTbarN->GetHistogram();
920     TH1F *hZplusJetsplusTTbarP = (TH1F*)ZplusJetsplusTTbarP->GetHistogram();
921     hZplusJetsplusTTbar->SetMarkerSize(0);
922     hZplusJetsplusTTbarP->SetMarkerSize(0);
923     hZplusJetsplusTTbarN->SetMarkerSize(0);
924     for (int i=1;i<=hZplusJetsplusTTbar->GetNbinsX();i++) {
925     float newerror=hZplusJetsplusTTbarP->GetBinContent(i)-hZplusJetsplusTTbar->GetBinContent(i);
926     hZplusJetsplusTTbar->SetBinError(i,newerror);
927     if(hZplusJetsplusTTbar->GetBinContent(i)<0.05) hZplusJetsplusTTbar->SetBinContent(i,0); //avoiding a displaying probolem
928     }
929     hZplusJetsplusTTbarP->SetFillColor(kGreen);
930     hZplusJetsplusTTbarN->SetFillColor(kWhite);
931     hZplusJetsplusTTbarN->Draw("same");
932    
933     ZplusJetsplusTTbar2->SetMarkerSize(0);
934     ZplusJetsplusTTbar2->Draw("same");
935    
936 buchmann 1.7 zjetsc->Draw("same");zjetscn->Draw("same");zjetscp->Draw("same");
937     logparc->Draw("same");
938     logparcn->Draw("same");
939     logparcp->Draw("same");
940 buchmann 1.8 additionallegend->Draw("same");
941     if(scenario==0) {
942     CompleteSave(c6,"Shapes2/Background_Shapes___3jetsabove30__allfits__"+writescenario);
943     } else {
944     CompleteSave(c6,"Shapes2/Background_Shapes___2jetsabove50__allfits__"+writescenario);
945     }
946 buchmann 1.10 //--------------------------------------------------------------------------------------------------------------------------------
947 buchmann 1.3 }
948    
949 buchmann 1.2 void draw_ttbar_and_zjets_shape(string mcjzb, string datajzb) {
950 buchmann 1.3 int all_leptons=-1;
951     int electrons_only=0;
952     int mu_only=1;
953     int twojetswith50gev=1;
954     int threejetswith30gev=0;
955 buchmann 1.4 /*
956 buchmann 1.3 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,twojetswith50gev);
957     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev);
958    
959     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,twojetswith50gev);
960     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,electrons_only,threejetswith30gev);
961    
962     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,twojetswith50gev);
963     draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,mu_only,threejetswith30gev);
964 buchmann 1.4 */
965 buchmann 1.2
966 buchmann 1.10 draw_ttbar_and_zjets_shape_for_one_configuration(mcjzb,datajzb,all_leptons,threejetswith30gev,true);
967 buchmann 1.2 }
968 buchmann 1.6
969 buchmann 1.8 void find_correction_factors(string &jzbvardata,string &jzbvarmc) {
970 buchmann 1.13 //first: colorful plots
971     TCanvas *cancorr = new TCanvas("cancorr","Canvas for Response Correction");
972 buchmann 1.14 cancorr->SetLogz();
973 buchmann 1.13 gStyle->SetPalette(1);
974     TCut zptforresponsepresentation("pt<600&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)&&((sumJetPt[1]/pt)<5.0)");
975     TH2F *niceresponseplotd = new TH2F("niceresponseplotd","",400,0,600,400,0,5);
976     (allsamples.collection)[allsamples.FindSample("AllData")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
977     niceresponseplotd->SetStats(0);
978 buchmann 1.17 niceresponseplotd->GetXaxis()->SetTitle("Z pt [GeV]");
979 buchmann 1.13 niceresponseplotd->GetYaxis()->SetTitle("Response");
980     niceresponseplotd->GetXaxis()->CenterTitle();
981     niceresponseplotd->GetYaxis()->CenterTitle();
982     niceresponseplotd->Draw("COLZ");
983     TProfile * pro = (TProfile*)niceresponseplotd->ProfileX();
984     pro->Rebin(4);
985 buchmann 1.17 pro->SetMarkerSize(DataMarkerSize);
986 buchmann 1.13 pro->Draw("same,e1");
987     DrawPrelim();
988     CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_Data");
989    
990     (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt>>niceresponseplotd",zptforresponsepresentation);
991     niceresponseplotd->SetStats(0);
992 buchmann 1.17 niceresponseplotd->GetXaxis()->SetTitle("Z pt [GeV]");
993 buchmann 1.13 niceresponseplotd->GetYaxis()->SetTitle("Response");
994     niceresponseplotd->Draw("COLZ");
995     (allsamples.collection)[allsamples.FindSample("DY")[0]].events->Draw("sumJetPt[1]/pt:pt",zptforresponsepresentation,"PROF,same");
996     TProfile * prof = (TProfile*)niceresponseplotd->ProfileX();
997     // prof->Rebin(4);
998 buchmann 1.17 prof->SetMarkerSize(DataMarkerSize);
999 buchmann 1.13 prof->Draw("same,e1");
1000     DrawPrelim();
1001     CompleteSave(cancorr,"ResponseCorrection/Response_Correction_Illustration_MC");
1002    
1003     //Step 2: Getting the result
1004 buchmann 1.9 TCut zptcutforresponse("pt>30&&pt<300&&TMath::Abs(91.2-mll)<20&&id1==id2&&(ch1*ch2<0)");
1005 buchmann 1.17 TH1F *dresponse = allsamples.Draw("dresponse","sumJetPt[1]/pt",100,0,5, "JZB [GeV]", "events", zptcutforresponse,data,luminosity);
1006 buchmann 1.8 float datacorrection=dresponse->GetMean();
1007     stringstream jzbvardatas;
1008 buchmann 1.9 if(datacorrection>1) jzbvardatas<<"(jzb[1]-"<<datacorrection-1<<"*pt)";
1009     if(datacorrection<1) jzbvardatas<<"(jzb[1]+"<<1-datacorrection<<"*pt)";
1010 buchmann 1.8 jzbvardata=jzbvardatas.str();
1011 buchmann 1.17 TH1F *mcresponse = allsamples.Draw("mcresponse","sumJetPt[1]/pt",100,0,5, "JZB [GeV]", "events", zptcutforresponse,mc,luminosity,allsamples.FindSample("DYJetsToLL_TuneZ2_M"));
1012 buchmann 1.8 float mccorrection=mcresponse->GetMean();
1013     stringstream jzbvarmcs;
1014 buchmann 1.9 if(mccorrection>1) jzbvarmcs<<"(jzb[1]-"<<mccorrection-1<<"*pt)";
1015     if(mccorrection<1) jzbvarmcs<<"(jzb[1]+"<<1-mccorrection<<"*pt)";
1016 buchmann 1.8 jzbvarmc=jzbvarmcs.str();
1017     cout << "JZB Z pt correction summary : " << endl;
1018     cout << " Data: The response is " << dresponse->GetMean() << " --> jzb variable is now : " << jzbvardata << endl;
1019     cout << " MC : The response is " << mcresponse->GetMean() << " --> jzb variable is now : " << jzbvarmc << endl;
1020     }
1021 buchmann 1.11
1022 buchmann 1.12 void pick_up_events(string cut) {
1023     cout << "Picking up events with cut " << cut << endl;
1024     allsamples.PickUpEvents(cut);
1025 buchmann 1.11 }
1026    
1027     void test() {
1028 buchmann 1.19
1029 buchmann 1.11 TCanvas *testcanv = new TCanvas("testcanv","testcanv");
1030     testcanv->cd();
1031     switch_overunderflow(true);
1032 buchmann 1.17 TH1F *ptdistr = allsamples.Draw("ptdistr","pt1",100,30,200, "p_{T} [GeV]", "events", cutOSSF,data,luminosity);
1033 buchmann 1.11 switch_overunderflow(false);
1034     ptdistr->Draw();
1035     testcanv->SaveAs("test.png");
1036     cout << "HELLO there!" << endl;
1037 buchmann 1.19
1038 buchmann 1.11 }