ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ZbTools.C
Revision: 1.22
Committed: Mon Jan 21 14:43:36 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.21: +18 -5 lines
Log Message:
rebinned mpf/response plots to make them more comprehensible; changed the way mpf/response plots are stored

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4 buchmann 1.22 #include <math.h>
5 buchmann 1.1
6     #include <TCut.h>
7     #include <TROOT.h>
8     #include <TCanvas.h>
9     #include <TMath.h>
10     #include <TColor.h>
11     #include <TPaveText.h>
12     #include <TRandom.h>
13     #include <TH1.h>
14     #include <TH2.h>
15     #include <TF1.h>
16     #include <TSQLResult.h>
17     #include <TProfile.h>
18     #include <TLegendEntry.h>
19    
20     using namespace std;
21    
22     using namespace PlottingSetup;
23    
24     namespace ZbData {
25 buchmann 1.10 TCut ZplusBsel("pt1>20&&pt2>20&&mll>60&&mll<120&&id1==id2");
26 buchmann 1.19 TCut LeadingB("ZbCHS3010_bTagProbCSVBP[0]>0.898");
27     TCut EtaB("abs(ZbCHS3010_pfJetGoodEta[0])<1.3");
28     TCut PhiZcut("abs(ZbCHS3010_pfJetDphiZ[0])>2.7");
29 buchmann 1.1
30     }
31    
32 buchmann 1.19 TCut STDWEIGHT;
33    
34 buchmann 1.15 class ZbPointResult {
35     public:
36     ZbPointResult(string var, float ptlow, float pthigh, float alphalow, float alphahigh, Value Data, Value MC);
37     float PtLow;
38     float PtHigh;
39     float AlphaLow;
40     float AlphaHigh;
41     string variable;
42     Value Data;
43     Value MC;
44     Value Ratio;
45     };
46    
47     ZbPointResult::ZbPointResult(string var, float ptlow, float pthigh, float alphalow, float alphahigh, Value data, Value mc) :
48     variable(var), PtLow(ptlow), PtHigh(pthigh), AlphaLow(alphalow), AlphaHigh(alphahigh), Data(data), MC(mc) {
49     Ratio = data/mc;
50     }
51    
52     std::ostream &operator<<(std::ostream &ostr, ZbPointResult &b)
53     {
54     ostr << b.PtLow << ";" << b.PtHigh << ";" << b.AlphaLow << ";" << b.AlphaHigh << ";" << b.Data.getValue() << ";" << b.Data.getError() << ";" << b.MC.getValue() << ";" << b.MC.getError() << ";" << b.Ratio.getValue() << ";" << b.Ratio.getError();
55     return ostr;
56     }
57    
58    
59     class ZbResultContainer {
60     public:
61     string name;
62     vector<ZbPointResult> MPF_Rabs_location;
63     Value MPF_Result_FaceValue;
64     Value Rabs_Result_FaceValue;
65     Value MPF_Result_Extrapolated;
66     Value Rabs_Result_Extrapolated;
67    
68     ZbResultContainer(string name);
69     ZbResultContainer(const ZbResultContainer &old);
70     };
71    
72    
73     ZbResultContainer::ZbResultContainer(string _name) {
74     name=_name;
75     cout<< "Result Container for \"" << name << "\" has been initialized" << endl;
76    
77     }
78    
79     std::ostream &operator<<(std::ostream &ostr, ZbResultContainer &b)
80     {
81     ostr << "Results for " << b.name << endl;
82     ostr << " MPF and Rabs locations: " << endl;
83     for(int i=0;i<b.MPF_Rabs_location.size();i++) ostr << " " << b.MPF_Rabs_location[i] << endl;
84     ostr << " Results: " << endl;
85     ostr << " Face Value: " << endl;
86     ostr << " MPF " << b.MPF_Result_FaceValue << endl;
87     ostr << " Rabs " << b.Rabs_Result_FaceValue << endl;
88     ostr << " Extrapolated: " << endl;
89     ostr << " MPF " << b.MPF_Result_Extrapolated << endl;
90     ostr << " Rabs " << b.Rabs_Result_Extrapolated << endl;
91    
92     return ostr;
93     }
94    
95    
96    
97 buchmann 1.1 using namespace ZbData;
98    
99 buchmann 1.7
100     //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* DELETE EVERYTHING BETWEEN THIS LINE /*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*//
101     void SpecialCutFlow(string identifier);
102    
103     //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* AND THIS LINE /*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*//
104    
105    
106 buchmann 1.20 class CutYields{
107     public:
108     float data;
109     float Zb;
110     float Zc;
111     float Zl;
112     float tt;
113     float SiTo;
114     float Dibosons;
115     float WJets;
116     float Other;
117    
118     CutYields();
119     };
120    
121     CutYields::CutYields() {
122     this->data=0;
123     this->Zb=0;
124     this->Zc=0;
125     this->Zl=0;
126     this->tt=0;
127     this->SiTo=0;
128     this->Dibosons=0;
129     this->WJets=0;
130     this->Other=0;
131     }
132    
133     std::ostream &operator<<(std::ostream &ostr, CutYields y)
134     {
135     return ostr << y.data << ";" << y.Zb << ";" << y.Zc << ";" << y.Zl << ";" << y.tt << ";" << y.SiTo << ";" << y.Dibosons << ";" << y.WJets << ";" << endl;
136     }
137    
138    
139     CutYields print_yield(TCut cut) {
140    
141     CutYields Yield;
142 buchmann 1.1 TH1F *data = allsamples.Draw("data", "mll",1,0,10000000, "m_{ll} [GeV]", "events", cut,data,luminosity);
143 buchmann 1.7 dout << " Yields for " << (const char*) cut << endl;
144 buchmann 1.20 // dout << " data: " << data->Integral() << endl;
145    
146     Yield.data=data->Integral();
147 buchmann 1.9 THStack mcm = allsamples.DrawStack("mc", "mll",1,0,10000000, "m_{ll} [GeV]", "events", cut,mc,luminosity);
148 buchmann 1.1 int nhists = mcm.GetHists()->GetEntries();
149     TFile *test = new TFile("test.root","RECREATE");
150     mcm.Write();
151     test->Close();
152     for (int i = 0; i < nhists; i++) {
153     TH1* hist = static_cast<TH1*>(mcm.GetHists()->At(i));
154 buchmann 1.20 string name=hist->GetName();
155     if(Contains(name,"t_bar_t")) Yield.tt+=hist->Integral();
156     if(Contains(name,"W_Jets")) Yield.WJets+=hist->Integral();
157     if(Contains(name,"Single_top")) Yield.SiTo+=hist->Integral();
158     if(Contains(name,"Dibosons")) Yield.Dibosons+=hist->Integral();
159     if(Contains(name,"Z_l_")) Yield.Zl+=hist->Integral();
160     if(Contains(name,"Z_c_")) Yield.Zc+=hist->Integral();
161     if(Contains(name,"Z_b_")) Yield.Zb+=hist->Integral();
162     }
163    
164     cout << Yield << endl;
165 buchmann 1.1 cout << endl << endl;
166 buchmann 1.9
167 buchmann 1.1 delete data;
168 buchmann 1.20 CleanLegends();
169     DeleteStack(mcm);
170    
171     return Yield;
172 buchmann 1.1 }
173    
174 buchmann 1.2 void draw_kin_variable(string variable, TCut cut, int nbins, float min, float max, string xlabel, string saveas, bool dologscale, string speciallabel="") {
175 buchmann 1.1 TCanvas *ckin = new TCanvas("ckin","kin variable canvas");
176 buchmann 1.20 if(dologscale) ckin->SetLogy(1);
177 buchmann 1.1 TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
178     datahisto->SetMarkerSize(DataMarkerSize);
179     THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
180 buchmann 1.2 if(dologscale) datahisto->SetMaximum(3*datahisto->GetMaximum());
181     else datahisto->SetMaximum(1.5*datahisto->GetMaximum());
182 buchmann 1.20
183     float SumMC=0.0;
184     TIter nextH(mcstack.GetHists());
185     TH1F* h;
186     while ( h = (TH1F*)nextH() ) {
187     SumMC += h->Integral();
188     }
189     float scale = datahisto->Integral()/SumMC;
190    
191     // Re-scale stack to data integral
192     nextH = TIter(mcstack.GetHists());
193    
194     while ( h = (TH1F*)nextH() ) {
195     h->Scale(scale);
196     }
197    
198 buchmann 1.2 TText *speciall;
199 buchmann 1.1 datahisto->Draw("e1");
200     ckin->Update();
201 buchmann 1.19 mcstack.Draw("histo,same");
202 buchmann 1.1 datahisto->Draw("same,e1");
203     TLegend *kinleg = allsamples.allbglegend();
204 buchmann 1.20
205 buchmann 1.1 kinleg->Draw();
206    
207     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
208     kinpad->cd();
209 buchmann 1.20 if(dologscale) kinpad->SetLogy(1);
210 buchmann 1.1 datahisto->Draw("e1");
211 buchmann 1.19 mcstack.Draw("histo,same");
212 buchmann 1.1 datahisto->Draw("same,e1");
213     datahisto->Draw("same,axis");
214     kinleg->Draw();
215     DrawPrelim();
216     saveas="kin/"+saveas;
217 buchmann 1.20 kinpad->cd();
218    
219 buchmann 1.19 if(speciallabel!="") {
220 buchmann 1.20 speciall = write_title(speciallabel);
221     speciall->SetX(0.18);
222     speciall->SetTextAlign(11);
223     speciall->SetTextSize(0.03);
224     speciall->SetY(0.85);
225 buchmann 1.19 speciall->Draw();
226     }
227 buchmann 1.20
228 buchmann 1.1 save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
229    
230     datahisto->Delete();
231 buchmann 1.20 delete kinleg;
232 buchmann 1.1 delete ckin;
233 buchmann 1.20 CleanLegends();
234     DeleteStack(mcstack);
235 buchmann 1.1 }
236 buchmann 1.20
237 buchmann 1.1 void print_all_b_yields() {
238 buchmann 1.20 vector<CutYields> yields;
239 buchmann 1.1 cout << "Basic selection with a b jet" << endl;
240 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&"ZbCHS3010_pfJetGoodNumBtag>0"));
241 buchmann 1.2 cout << "Leading jet is a b-jet " << endl;
242 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB));
243 buchmann 1.1 cout << "|#eta_{b}|<1.3 " << endl;
244 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB));
245 buchmann 1.1 cout << "|#delta#phi(b<Z)|>2.7" << endl;
246 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut));
247 buchmann 1.19 cout << "30<ptZ<1000 GeV" << endl;
248 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"));
249 buchmann 1.13 cout << "#alpha < 0.35" << endl;
250 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"&&"(ZbCHS3010_alpha)<0.35"));
251 buchmann 1.1 cout << "#alpha < 0.3" << endl;
252 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"&&"(ZbCHS3010_alpha)<0.3"));
253     /* cout << "#alpha < 0.2" << endl;
254     yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"&&"(ZbCHS3010_alpha)<0.2"));
255 buchmann 1.1 cout << "#alpha < 0.15" << endl;
256 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"&&"(ZbCHS3010_alpha)<0.15"));
257 buchmann 1.1 cout << "#alpha < 0.1" << endl;
258 buchmann 1.20 yields.push_back(print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000"&&"(ZbCHS3010_alpha)<0.1"));*/
259    
260     for(int iy=0;iy<yields.size();iy++) {
261     cout << yields[iy] << endl;
262     }
263 buchmann 1.1 }
264    
265 buchmann 1.19 void DrawEvilCutFlow() {
266 buchmann 1.7 stringstream MegaCut;
267    
268 buchmann 1.19 MegaCut << " 1*(" << (const char*) (ZplusBsel&&TCut("ZbCHS3010_pfJetGoodNumBtag>0")) << ")";
269 buchmann 1.7 MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB) << ")";
270     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB) << ")";
271     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut) << ")";
272 buchmann 1.19 MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000")) << ")";
273     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.3")) << ")";
274     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.2")) << ")";
275     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.15")) << ")";
276     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.1")) << ")";
277     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.05")) << ")";
278 buchmann 1.7 MegaCut << " ";
279    
280     TCanvas *can = new TCanvas("can","can");
281     can->SetLogy(1);
282     TCut basecut("mll>6||mll<10");
283    
284    
285    
286     TLegend *leg = allsamples.allbglegend();
287    
288    
289     TH1F *data = allsamples.Draw("data", MegaCut.str(),11,-0.5,10.5, "", "events", basecut,data,luminosity);
290 buchmann 1.20 THStack mcm = allsamples.DrawStack("mc", MegaCut.str(),11,-0.5,10.5, "", "events", basecut,mc,luminosity);
291 buchmann 1.7
292     float runningsum=0;
293     for(int i=data->GetNbinsX();i>0;i--) {
294     runningsum+=data->GetBinContent(i);
295     data->SetBinContent(i,runningsum);
296     }
297    
298     float minimum=data->GetMaximum();
299    
300     TH1F* h;
301     TIter nextOF(mcm.GetHists());
302     while ( h = (TH1F*)nextOF() ) {
303     float runningsum=0;
304     minimum=data->GetMaximum();//done deliberately at each step so get the minimum of the last (!) contribution
305     for(int i=h->GetNbinsX();i>0;i--) {
306     runningsum+=h->GetBinContent(i);
307     h->SetBinContent(i,runningsum);
308     if(runningsum<minimum&&runningsum>0) minimum=runningsum;
309     }
310     }
311    
312    
313    
314     data->SetMinimum(0.05*minimum);
315     can->cd(1)->SetBottomMargin(0.25);
316     data->GetXaxis()->SetBinLabel(1,"Pre-selection");
317     data->GetXaxis()->SetBinLabel(2,"Contains b jet");
318     data->GetXaxis()->SetBinLabel(3,"Leading jet is b-jet");
319     data->GetXaxis()->SetBinLabel(4,"|#eta_{b}|<1.3 ");
320     data->GetXaxis()->SetBinLabel(5,"|#delta#phi(b,Z)|>2.7");
321 buchmann 1.19 data->GetXaxis()->SetBinLabel(6,"30<p_{T}^{Z}<1000 GeV");
322 buchmann 1.7 data->GetXaxis()->SetBinLabel(7,"#alpha < 0.3");
323     data->GetXaxis()->SetBinLabel(8,"#alpha < 0.2");
324     data->GetXaxis()->SetBinLabel(9,"#alpha < 0.15");
325     data->GetXaxis()->SetBinLabel(10,"#alpha < 0.1");
326     data->GetXaxis()->SetBinLabel(11,"#alpha < 0.05");
327     data->GetXaxis()->LabelsOption("v");
328    
329     data->Draw("e1");
330 buchmann 1.18 mcm.Draw("histo,same");
331 buchmann 1.7 data->Draw("same,e1,axis");
332     data->Draw("same,e1");
333     // data->Draw("same,TEXT");
334    
335     leg->Draw();
336    
337     DrawPrelim();
338    
339     CompleteSave(can,"CutFlow");
340 buchmann 1.20 CleanLegends();
341     DeleteStack(mcm);
342    
343 buchmann 1.7 }
344    
345 buchmann 1.1 void draw_Zb_kin_vars() {
346 buchmann 1.20
347     draw_kin_variable("pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000"),25,0,200,"Z p_{T}","Official/Zpt",1);
348     draw_kin_variable("ZbCHS3010_pfJetGoodPt[1]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000"),25,0,200,"Sub-Leading Jet Pt","Official/Jet2Pt",1);
349     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000"),25,0,200,"Leading Jet Pt (B)","Official/LeadingJetPt",1);
350     draw_kin_variable("ZbCHS3010_pfJetGoodPt[1]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000"),20,0,2,"p_{T}^{J2} / p_{T}^{Z}","Official/SubLeadingJetPt_Over_ZPt",1);
351     draw_kin_variable("ZbCHS3010_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<50"), 40,0,2,"#alpha","Official/alpha_pt_30_to_50",1);
352     draw_kin_variable("ZbCHS3010_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>50&&pt<75"), 40,0,2,"#alpha","Official/alpha_50_to_75",1);
353     draw_kin_variable("ZbCHS3010_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>75&&pt<125"), 40,0,2,"#alpha","Official/alpha_pt_75_to_125",1);
354     draw_kin_variable("ZbCHS3010_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>125&&pt<1000"),40,0,2,"#alpha","Official/alpha_pt_125_to_1000",1);
355     draw_kin_variable("ZbCHS3010_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000"),40,0,2,"#alpha","Official/alpha_pt_30_to_1000",1);
356    
357     draw_kin_variable("ZbCHS3010_pfBJetDphiZ[0]",ZplusBsel&&LeadingB&&TCut("pt>30&&pt<1000&&pfBJetDphiZ[0]>0"),30,0,3.2,"#delta#phi (Z,b lead)","DeltaPhiZBlead",0);
358 buchmann 1.1 }
359    
360     void draw_mpf_vars() {
361 buchmann 1.20 draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.3"), 20,0.0,2.0,"Z+b MPF","mpf_alpha_smaller_0p3",0,"#alpha<0.3, 30 GeV < p_{T}^{Z} < 1000 GeV");
362     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.2"), 20,0.0,2.0,"Z+b MPF","mpf_alpha_smaller_0p2",0,"#alpha<0.2, 30 GeV < p_{T}^{Z} < 1000 GeV");
363     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.15"),20,0.0,2.0,"Z+b MPF","mpf_alpha_smaller_0p15",0,"#alpha<0.15, 30 GeV < p_{T}^{Z} < 1000 GeV");
364     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.1"), 20,0.0,2.0,"Z+b MPF","mpf_alpha_smaller_0p1",0,"#alpha<0.1, 30 GeV < p_{T}^{Z} < 1000 GeV");
365     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.05"),20,0.0,2.0,"Z+b MPF","mpf_alpha_smaller_0p05",0,"#alpha<0.05, 30 GeV < p_{T}^{Z} < 1000 GeV");
366    
367     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.3"), 20,0.0,2.0,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p3", 0,"#alpha<0.3, 30 GeV < p_{T}^{Z} < 1000 GeV");
368     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.2"), 20,0.0,2.0,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p2", 0,"#alpha<0.2, 30 GeV < p_{T}^{Z} < 1000 GeV");
369     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.15"),20,0.0,2.0,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p15", 0,"#alpha<0.15, 30 GeV < p_{T}^{Z} < 1000 GeV");
370     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.1"), 20,0.0,2.0,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p1", 0,"#alpha<0.1, 30 GeV < p_{T}^{Z} < 1000 GeV");
371     draw_kin_variable("ZbCHS3010_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<1000&&ZbCHS3010_alpha<0.05"),20,0.0,2.0,"p_{T} b-jet / p_{T} Z","ptb_over_ptz__mpf_alpha_smaller_0p05",0,"#alpha<0.05, 30 GeV < p_{T}^{Z} < 1000 GeV");
372 buchmann 1.1 }
373    
374 buchmann 1.16 Value get_Zb_data_over_mc(string ContainerName, ZbResultContainer &res, string variable, string variable2, TCut cut, string saveas, float pt1, float pt2, float a1, float a2) {
375 buchmann 1.2 // write_warning(__FUNCTION__,"Debugging this function, therefore always returning 3.1415+/-1.010101"); return Value(3.1415,1.010101);
376 buchmann 1.12 TCanvas *cn = new TCanvas("cn","cn");
377     string varname="MPF";
378 buchmann 1.19
379     bool DoFit=false;
380     bool UseFit=false;
381    
382    
383 buchmann 1.12 if(Contains(variable,"pfJetGood")) varname="R_{abs}";
384 buchmann 1.20 // TH1F *hdata = allsamples.Draw("hdata",variable,1200,0,30, varname, "events", cut,data,luminosity);
385     // TH1F *hmc = allsamples.Draw("hmc" , variable,1200,0,30, varname, "events", cut, mc, luminosity);
386     TH1F *hdata = allsamples.Draw("hdata",variable,1200,0.5,1.5, varname, "events", cut,data,luminosity); // making it more precise
387     TH1F *hmc = allsamples.Draw("hmc" , variable,1200,0.5,1.5, varname, "events", cut, mc, luminosity); // making it more precise
388 buchmann 1.14 hmc->SetLineColor(kBlue);
389    
390 buchmann 1.10 float a=hdata->GetMean();
391 buchmann 1.2 float b=hmc->GetMean();
392     float da=hdata->GetMeanError();
393 buchmann 1.10 float db=hmc->GetMeanError();
394 buchmann 1.2 float factor = a / b;
395     float error = TMath::Sqrt( (1/(b*b)) * (da*da) + ((a*a)/(b*b))*db*db);
396 buchmann 1.12
397 buchmann 1.14 TF1 *gaus_data = new TF1("gaus_data","gaus",0.7,1.3);
398     TF1 *gaus_mc = new TF1("gaus_mc","gaus",0.7,1.3);
399 buchmann 1.19 if(DoFit) {
400     gaus_data->SetParameter(0,hdata->GetMaximum());
401     gaus_data->SetParameter(2,hdata->GetMean());
402     gaus_data->SetParameter(1,hdata->GetRMS());
403     hdata->Fit(gaus_data);
404    
405     gaus_mc->SetParameter(0,hmc->GetMaximum());
406     gaus_mc->SetParameter(1,hmc->GetMean());
407     gaus_mc->SetParameter(2,hmc->GetRMS());
408     hmc->Fit(gaus_mc);
409     }
410 buchmann 1.14
411 buchmann 1.12 cn->cd();
412 buchmann 1.22 hdata->Rebin(0.05*1200/(1.5-0.5));
413     hmc->Rebin(0.05*1200/(1.5-0.5));
414     hdata->GetYaxis()->SetTitle("events / 0.05");
415 buchmann 1.14 hdata->SetMarkerColor(kRed);
416 buchmann 1.19 if(DoFit) {
417     gaus_mc->SetLineColor(kBlue);
418     gaus_data->SetLineColor(kRed);
419     }
420 buchmann 1.14
421 buchmann 1.12 hdata->GetXaxis()->SetRangeUser(0,2);
422 buchmann 1.16 hdata->GetYaxis()->SetTitleOffset(1.3);
423 buchmann 1.12 hdata->Draw("e1");
424 buchmann 1.22
425     hmc->Scale(hdata->Integral()/hmc->Integral());
426     if(hmc->GetMaximum()>hdata->GetMaximum()) hdata->SetMaximum((hmc->GetMaximum()+sqrt((double)hmc->GetMaximum()))*1.2);
427    
428 buchmann 1.12 hmc->Draw("histo,same");
429     hdata->Draw("e1,same");
430 buchmann 1.19 if(DoFit) {
431     gaus_data->Draw("same");
432     gaus_mc->Draw("same");
433     }
434    
435 buchmann 1.12 stringstream summary;
436 buchmann 1.16 summary << "#splitline{#bf{" << varname << "}}{#splitline{" << pt1 << " < p_{T}^{Z} < " << pt2 << ", " << a1 << " #leq #alpha < " << a2 << "}{#splitline{data: " << std::setprecision(4) << a << " #pm " << std::setprecision(4) << da << "}{";
437 buchmann 1.14 summary << "#splitline{mc: " << std::setprecision(4) << b << " #pm " << std::setprecision(4) << db << "}{#splitline{ratio: " << factor;
438 buchmann 1.19 summary << " #pm " << error;
439     if(DoFit) {
440     summary << "}{#splitline{}{#splitline{data fit: " << std::setprecision(4) << gaus_data->GetParameter(1) << "+/-";
441     summary << std::setprecision(4) << gaus_data->GetParError(1) << "}{#splitline{";
442     summary << "mc fit:" << std::setprecision(4) << gaus_mc->GetParameter(1) << "#pm" << std::setprecision(4) << gaus_mc->GetParError(1) << "}{ratio: ";
443     summary << gaus_data->GetParameter(1)/gaus_mc->GetParameter(1) << "#pm" << gaus_data->GetParameter(1)/gaus_mc->GetParameter(1) * sqrt((gaus_data->GetParError(1) * gaus_data->GetParError(1))/(gaus_data->GetParameter(1)*gaus_data->GetParameter(1)) + (gaus_mc->GetParError(1) * gaus_mc->GetParError(1))/(gaus_mc->GetParameter(1)*gaus_mc->GetParameter(1)) ) << "}}}}";
444     summary << "}}}}";
445     } else {
446     summary << "}{}}}}}";
447     }
448    
449     if(UseFit) {
450     write_error(__FUNCTION__,"Requested using fit result for final result - not implemented yet!");
451     assert(0);
452     }
453    
454 buchmann 1.16
455 buchmann 1.12 TText *infobox = write_title(summary.str());
456     infobox->SetX(0.75);
457     infobox->SetTextSize(0.03);
458     infobox->SetY(0.75);
459     infobox->Draw();
460    
461    
462     DrawPrelim();
463 buchmann 1.16 CompleteSave(cn,ContainerName+"/ResponsePlots/"+saveas);
464 buchmann 1.12
465 buchmann 1.15 res.MPF_Rabs_location.push_back(ZbPointResult(variable,pt1,pt2,a1,a2,Value(a,da),Value(b,db)));
466 buchmann 1.19 cout << "Data;" << a << ";"<<da<<";MC;"<<b<<";"<<db<<endl;
467 buchmann 1.12 delete cn;
468 buchmann 1.2 delete hdata;
469     delete hmc;
470 buchmann 1.9
471 buchmann 1.2 return Value(factor,error);
472     }
473    
474 buchmann 1.17 int nFakes=1;
475 buchmann 1.20
476     float PurityInclusive=0.05;
477     float PurityLoose=0.20;
478     float PurityMedium=0.54;
479     float PurityTight=0.82;
480    
481    
482     void DeterminePurity(TCut basecut, int nptcuts, float ptcuts[], string AlphaVariable, string ContainerName, float FaceValueToBeTakenAt) {
483    
484     bool ComputePurity=false;
485    
486     if(ContainerName=="inclusive") ComputePurity=true;
487     if(ContainerName=="loose") ComputePurity=true;
488     if(ContainerName=="medium") ComputePurity=true;
489     if(ContainerName=="reference") ComputePurity=true;
490    
491     if(!ComputePurity) return;
492    
493     stringstream specialcut;
494     specialcut << "((pt>30&& pt< 1000) && (" << AlphaVariable << "<" << FaceValueToBeTakenAt << "))";
495    
496     THStack mcm = allsamples.DrawStack("mcm" , "mpf",1200,0,30, "MPF", "events", TCut(basecut && specialcut.str().c_str()), mc, luminosity);
497     int nhists = mcm.GetHists()->GetEntries();
498    
499     float total=0;
500     float Zb=0;
501    
502     for (int i = 0; i < nhists; i++) {
503     TH1* hist = static_cast<TH1*>(mcm.GetHists()->At(i));
504     string name=hist->GetName();
505     if(Contains(name,"t_bar_t")) total+=hist->Integral();
506     if(Contains(name,"W_Jets")) total+=hist->Integral();
507     if(Contains(name,"Single_top")) total+=hist->Integral();
508     if(Contains(name,"Dibosons")) total+=hist->Integral();
509     if(Contains(name,"Z_l_")) total+=hist->Integral();
510     if(Contains(name,"Z_c_")) total+=hist->Integral();
511     if(Contains(name,"Z_b_")) {
512     total+=hist->Integral();
513     Zb+=hist->Integral();
514     }
515     }
516 buchmann 1.17
517 buchmann 1.20 float purity=Zb/total;
518     dout << "Determined a purity of " << 100*purity << " % for the container " << ContainerName << endl;
519    
520     if(ContainerName=="inclusive") PurityInclusive=purity;
521     if(ContainerName=="loose") PurityLoose=purity;
522     if(ContainerName=="medium") PurityMedium=purity;
523     if(ContainerName=="reference") PurityTight=purity;
524 buchmann 1.17
525 buchmann 1.20 DeleteStack(mcm);
526 buchmann 1.17 }
527 buchmann 1.19
528 buchmann 1.22 string NiceAlphaPrint(float alpha) {
529     //get in : 0.3, return 0p3 ...
530     stringstream res;
531     res << int(alpha) << "p" << int(100*alpha);
532     return res.str();
533     }
534 buchmann 1.19
535     ZbResultContainer new_data_mc_agreement_2d(bool gofast, string AlphaVariable, string ContainerName, TCut BTagCut, TCut BTagWgt, float FaceValueToBeTakenAt) {
536 buchmann 1.17
537 buchmann 1.20
538 buchmann 1.19 if(gofast) write_info(__FUNCTION__,"Fast mode activated for "+ContainerName);
539 buchmann 1.15 ZbResultContainer results(ContainerName);
540 buchmann 1.2
541 buchmann 1.19 cutWeight=STDWEIGHT*BTagWgt;
542 buchmann 1.15 LeadingB=BTagCut;
543 buchmann 1.13
544 buchmann 1.20
545 buchmann 1.3 gStyle->SetOptFit(0);
546 buchmann 1.2 TCut basecut(ZplusBsel&&LeadingB&&EtaB&&PhiZcut);
547 buchmann 1.17 const int nalphacuts=6;
548     float alphacuts[nalphacuts] = {0.1,0.15,0.2,0.25,0.3,0.35};
549 buchmann 1.15
550 buchmann 1.20
551 buchmann 1.17 const int nptcuts=5;
552     float ptcuts[nptcuts]={30,50,75,125,1000};
553 buchmann 1.15
554 buchmann 1.20 DeterminePurity(basecut, nptcuts,ptcuts, AlphaVariable, ContainerName, FaceValueToBeTakenAt);
555 buchmann 1.2
556     float MPF_Results[nalphacuts][nptcuts];
557     float MPF_Errors[nalphacuts][nptcuts];
558     float RABS_Results[nalphacuts][nptcuts];
559     float RABS_Errors[nalphacuts][nptcuts];
560    
561    
562 buchmann 1.19 for(int ia=0;ia<nalphacuts && !gofast;ia++) {
563 buchmann 1.2 for(int ipt=0;ipt<nptcuts-1;ipt++) {
564     stringstream specialcut;
565 buchmann 1.15 float alow,ahigh;
566     if(ia>0) {
567     specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<" << alphacuts[ia] << " && " << AlphaVariable << ">" << alphacuts[ia-1] << "))";
568     alow=alphacuts[ia-1];
569     ahigh=alphacuts[ia];
570     } else {
571     specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<" << alphacuts[ia] << "))";
572     alow=0;
573     ahigh=alphacuts[ia];
574     }
575 buchmann 1.9 cout << specialcut.str() << endl;
576 buchmann 1.22 Value MPF_data_over_mc = get_Zb_data_over_mc(ContainerName,results,"mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(NiceAlphaPrint(alphacuts[ia])), ptcuts[ipt], ptcuts[ipt+1],alow,ahigh);
577     Value RABS_data_over_mc = get_Zb_data_over_mc(ContainerName,results,"ZbCHS3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__alpha_"+any2string(NiceAlphaPrint(alphacuts[ia])), ptcuts[ipt], ptcuts[ipt+1],alow,ahigh);
578 buchmann 1.2
579     MPF_Results[ia][ipt]=MPF_data_over_mc.getValue();
580     MPF_Errors[ia][ipt]=MPF_data_over_mc.getError();
581    
582     RABS_Results[ia][ipt]=RABS_data_over_mc.getValue();
583     RABS_Errors[ia][ipt]=RABS_data_over_mc.getError();
584    
585 buchmann 1.9 cout << "alpha cut at " << alphacuts[ia+1] << " and pt range " << ptcuts[ipt] << " , " << ptcuts[ipt+1] << " \t : \t" << specialcut.str() << " \t \t --> " << MPF_data_over_mc << " (MPF) " << RABS_data_over_mc << " (RABS)" << endl;
586 buchmann 1.2 }
587     }
588    
589     float MPF_ExtraPolatedResults[nptcuts];
590     float RABS_ExtraPolatedResults[nptcuts];
591    
592     TCanvas *can = new TCanvas("can");
593 buchmann 1.14 can->cd(1)->SetLeftMargin(0.15);
594 buchmann 1.2
595     TGraphErrors *MPF_FinalGraph = new TGraphErrors();
596     TGraphErrors *RABS_FinalGraph = new TGraphErrors();
597 buchmann 1.13 TGraphErrors *MPF_FaceValueAtPoint3 = new TGraphErrors();
598     TGraphErrors *RABS_FaceValueAtPoint3 = new TGraphErrors();
599 buchmann 1.2
600     for(int ipt=0;ipt<nptcuts-1;ipt++) {
601    
602     stringstream filename;
603     filename << "Extrapolation/Zplusb_data_over_mc___" << ptcuts[ipt] << "_to_" << ptcuts[ipt+1];
604     cout << "Going to create histo for " << filename.str() << endl;
605     TGraphErrors *mpf_gr =new TGraphErrors();
606     TGraphErrors *rabs_gr =new TGraphErrors();
607 buchmann 1.13
608     int rabs_counter=0;
609     int mpf_counter=0;
610    
611 buchmann 1.19 for(int ia=0;ia<nalphacuts && !gofast;ia++) {
612 buchmann 1.9 cout << "Setting a point for an alpha cut at " << alphacuts[ia] << " with value " << MPF_Results[ia][ipt] << " (MPF) and " << RABS_Results[ia][ipt] << " (RABS)" << endl;
613 buchmann 1.13 if(MPF_Results[ia][ipt]==MPF_Results[ia][ipt] && MPF_Errors[ia][ipt]==MPF_Errors[ia][ipt]) { // remove nan's
614     mpf_gr->SetPoint(mpf_counter,alphacuts[ia],MPF_Results[ia][ipt]);
615     mpf_gr->SetPointError(mpf_counter,0,MPF_Errors[ia][ipt]);
616     mpf_counter++;
617     } else {
618     dout << "Detected BS for MPF method (bin ignored) : " << endl;
619     dout << " alpha: " << alphacuts[ia] << " , pt range: " << ptcuts[ipt] << " < pt < " << ptcuts[ipt+1] << endl;
620     cout << " value (MPF) : " << MPF_Results[ia][ipt] << " +/- " << MPF_Errors[ia][ipt] << endl;
621     }
622     if(RABS_Results[ia][ipt]==RABS_Results[ia][ipt] && RABS_Errors[ia][ipt]==RABS_Errors[ia][ipt]) {
623     rabs_gr->SetPoint(rabs_counter,alphacuts[ia],RABS_Results[ia][ipt]);
624     rabs_gr->SetPointError(rabs_counter,0,RABS_Errors[ia][ipt]);
625     rabs_counter++;
626     } else {
627     dout << "Detected BS for RABS method (bin ignored) : " << endl;
628     dout << " alpha: " << alphacuts[ia] << " , pt range: " << ptcuts[ipt] << " < pt < " << ptcuts[ipt+1] << endl;
629     cout << " value (RABS) : " << RABS_Results[ia][ipt] << " +/- " << RABS_Errors[ia][ipt] << endl;
630     }
631     }
632    
633     stringstream specialcut;
634 buchmann 1.19 specialcut << "((pt>" << ptcuts[ipt] << " && pt< " << ptcuts[ipt+1] << ") && (" << AlphaVariable << "<" << FaceValueToBeTakenAt << "))";
635     Value MPF_data_over_mc = get_Zb_data_over_mc(ContainerName,results,"mpf","",TCut(basecut && specialcut.str().c_str()),"MPF___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_"+any2string(FaceValueToBeTakenAt),ptcuts[ipt],ptcuts[ipt+1],0,FaceValueToBeTakenAt);
636     Value RABS_data_over_mc = get_Zb_data_over_mc(ContainerName,results,"ZbCHS3010_pfJetGoodPt[0]/pt","",TCut(basecut && specialcut.str().c_str()),"Rabs___pt_"+any2string(ptcuts[ipt])+"_"+any2string(ptcuts[ipt+1])+"__INCLUSIVEalpha_"+any2string(FaceValueToBeTakenAt),ptcuts[ipt],ptcuts[ipt+1],0,FaceValueToBeTakenAt);
637 buchmann 1.14 cout << "About to add a point in pt (" << (ptcuts[ipt]+ptcuts[ipt+1])/2 << " ) to face value : " << MPF_data_over_mc << " (MPF) , " << RABS_data_over_mc << "(RABS)" << endl;
638 buchmann 1.13 MPF_FaceValueAtPoint3->SetPoint(ipt,(ptcuts[ipt]+ptcuts[ipt+1])/2,MPF_data_over_mc.getValue());
639     MPF_FaceValueAtPoint3->SetPointError(ipt,0,MPF_data_over_mc.getError());
640     RABS_FaceValueAtPoint3->SetPoint(ipt,(ptcuts[ipt]+ptcuts[ipt+1])/2,RABS_data_over_mc.getValue());
641     RABS_FaceValueAtPoint3->SetPointError(ipt,0,RABS_data_over_mc.getError());
642 buchmann 1.2
643    
644 buchmann 1.19
645     if(!gofast) {
646     can->cd();
647     mpf_gr->SetMarkerStyle(21);
648     mpf_gr->SetMarkerColor(kBlue);
649     mpf_gr->Draw("AP");
650     mpf_gr->Fit("pol1","");
651     mpf_gr->GetXaxis()->SetTitle("#alpha");
652     mpf_gr->GetXaxis()->CenterTitle();
653     mpf_gr->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
654     mpf_gr->GetYaxis()->CenterTitle();
655     TF1 *mpf_pol=(TF1*)mpf_gr->GetFunction("pol1");
656     mpf_pol->SetLineWidth(0);
657     TF1 *mpf_pol_complete = new TF1("mpf_pol_complete","[0]+[1]*x");
658     mpf_pol_complete->SetParameters(mpf_pol->GetParameters());
659     mpf_pol_complete->SetLineWidth(1);
660     mpf_pol_complete->SetLineColor(kBlue);
661    
662     float min,max;
663     FindMinMax(mpf_gr,min,max);
664     TH1F *histo = new TH1F("histo","histo",1,0,0.4);
665     histo->GetXaxis()->SetTitle("#alpha");
666     histo->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
667     histo->GetXaxis()->CenterTitle();
668     histo->GetYaxis()->CenterTitle();
669     histo->GetYaxis()->SetTitleOffset(1.3);
670     histo->SetStats(0);
671     histo->GetXaxis()->SetRangeUser(0,0.4);
672     histo->GetYaxis()->SetRangeUser(min,max);
673     mpf_gr->GetYaxis()->SetRangeUser(min,max);
674    
675     TPolyLine *mpf_fit_uncert = GetFitUncertaintyShape(mpf_gr, "pol1", min, max,0.0,0.4);
676     mpf_pol->SetLineColor(TColor::GetColor("#0101DF"));
677     mpf_fit_uncert->SetFillColor(TColor::GetColor("#5353FC"));
678     histo->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
679     histo->Draw();
680     mpf_fit_uncert->Draw("F");
681     mpf_fit_uncert->Draw("");
682     mpf_gr->Draw("P");
683     mpf_pol_complete->Draw("same");
684    
685     float mpf_a=mpf_pol->GetParameter(0);
686     float mpf_b=mpf_pol->GetParameter(1);
687     MPF_FinalGraph->SetPoint(ipt,0.5*(ptcuts[ipt]+ptcuts[ipt+1]),mpf_a);
688     MPF_FinalGraph->SetPointError(ipt,0,mpf_pol->GetParError(0));
689    
690     MPF_ExtraPolatedResults[ipt]=mpf_a;
691    
692     stringstream mpf_info;
693     mpf_info << "#splitline{#splitline{#splitline{" << ptcuts[ipt] << " GeV < p_{T}^{Z} < " << ptcuts[ipt+1] << " GeV }{ (MPF) }}{Extrapolated value: " << std::setprecision(4) << mpf_a << "}}{#chi^{2}/NDF : " << mpf_pol->GetChisquare() << " / " << mpf_pol->GetNDF() << "}";
694    
695     TText *mpf_mark = write_title(mpf_info.str());
696     mpf_mark->SetX(0.75);
697     mpf_mark->SetTextSize(0.03);
698     mpf_mark->SetY(0.75);
699     mpf_mark->Draw();
700    
701     string filenamebkp=filename.str();
702     filename << "__MPF";
703     DrawPrelim();
704     CompleteSave(can,ContainerName+"/"+filename.str());
705     cout << "MPF : " << mpf_a << " + " << mpf_b << " * alpha " << endl;
706    
707     filename.str("");
708    
709     rabs_gr->SetMarkerStyle(21);
710     rabs_gr->SetMarkerColor(kRed);
711     rabs_gr->Draw("AP");
712     rabs_gr->Fit("pol1","");
713     rabs_gr->GetXaxis()->SetTitle("#alpha");
714     rabs_gr->GetXaxis()->CenterTitle();
715     rabs_gr->GetYaxis()->SetTitle("<R_{abs}>_{data}/<R_{abs}>_{mc}");
716     rabs_gr->GetYaxis()->CenterTitle();
717     TF1 *rabs_pol=(TF1*)rabs_gr->GetFunction("pol1");
718     rabs_pol->SetLineWidth(0);
719     TF1 *rabs_pol_complete = new TF1("rabs_pol_complete","[0]+[1]*x");
720     rabs_pol_complete->SetParameters(rabs_pol->GetParameters());
721     rabs_pol_complete->SetLineColor(kRed);
722     rabs_pol_complete->SetLineWidth(1);
723     FindMinMax(rabs_gr,min,max);
724     rabs_gr->GetYaxis()->SetRangeUser(min,max);
725     histo->GetYaxis()->SetRangeUser(min,max);
726     TPolyLine *rabs_fit_uncert = GetFitUncertaintyShape(rabs_gr, "pol1", min, max,0.0,0.4);
727     rabs_pol->SetLineColor(TColor::GetColor("#FA5858"));
728     rabs_pol->SetFillColor(TColor::GetColor("#FA5858"));
729     rabs_fit_uncert->SetLineColor(TColor::GetColor("#FA5858"));
730     rabs_fit_uncert->SetFillColor(TColor::GetColor("#FA5858"));
731     histo->GetYaxis()->SetTitle("<R_{abs}>_{data}/<R_{abs}>_{mc}");
732     histo->Draw();
733     rabs_fit_uncert->Draw("F");
734     rabs_fit_uncert->Draw("");
735     rabs_gr->Draw("P");
736     rabs_pol_complete->Draw("same");
737    
738     float rabs_a=rabs_pol->GetParameter(0);
739     float rabs_b=rabs_pol->GetParameter(1);
740     RABS_FinalGraph->SetPoint(ipt,0.5*(ptcuts[ipt]+ptcuts[ipt+1]),rabs_a);
741     RABS_FinalGraph->SetPointError(ipt,0,rabs_pol->GetParError(0));
742    
743     cout << "!+!+!+!+!+!+!+!+!+ Just added a point to the final plot : " << rabs_a << " +/- " << rabs_pol->GetParError(0) << endl;
744    
745     stringstream rabs_info;
746     rabs_info << "#splitline{#splitline{#splitline{" << ptcuts[ipt] << " GeV < p_{T}^{Z} < " << ptcuts[ipt+1] << " GeV }{ (R_{abs}) }}{Extrapolated value: " << std::setprecision(4) << rabs_a << "}}{#chi^{2}/NDF : " << rabs_pol->GetChisquare() << " / " << rabs_pol->GetNDF() << "}";
747     TText *rabs_mark = write_title(rabs_info.str());
748     rabs_mark->SetX(0.75);
749     rabs_mark->SetTextSize(0.03);
750     rabs_mark->SetY(0.75);
751     rabs_mark->Draw();
752    
753     RABS_ExtraPolatedResults[ipt]=rabs_a;
754     filename << filenamebkp << "__RABS";
755     DrawPrelim();
756     CompleteSave(can,ContainerName+"/"+filename.str());
757     cout << "RABS : " << rabs_a << " + " << rabs_b << " * alpha " << endl;
758     }
759     }
760    
761     float MPFResult;
762     float MPFResultError;
763    
764     float RabsResult;
765     float RabsResultError;
766    
767     if(!gofast) {
768     MPF_FinalGraph->SetMarkerStyle(21);
769     MPF_FinalGraph->SetMarkerColor(kBlue);
770     MPF_FinalGraph->Fit("pol0",""); // quiet, use minos
771    
772     TF1 *mpf_pol0=(TF1*)MPF_FinalGraph->GetFunction("pol0");
773     TF1 *mpf_pol0_complete = new TF1("mpf_pol0_complete","[0]+[1]*x");
774     mpf_pol0_complete->SetLineWidth(1);
775     mpf_pol0_complete->SetLineColor(kBlue);
776     mpf_pol0->SetLineColor(kBlue);
777     MPF_FinalGraph->Draw("AP");
778     MPF_FinalGraph->GetXaxis()->SetTitle("p_{T}^{Z}");
779     MPF_FinalGraph->GetXaxis()->CenterTitle();
780     MPF_FinalGraph->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
781     MPF_FinalGraph->GetYaxis()->CenterTitle();
782     MPF_FinalGraph->Draw("AP");
783     mpf_pol0_complete->Draw("same");
784    
785     stringstream mpf_result;
786     mpf_result << "#splitline{C_{abs}= " << std::setprecision(5) << 1/mpf_pol0->GetParameter(0) << " #pm " << std::setprecision(2) << mpf_pol0->GetParError(0)/(mpf_pol0->GetParameter(0)*mpf_pol0->GetParameter(0)) << "}{ (MPF)}";
787     TText *rmpf_final_mark = write_title(mpf_result.str());
788     rmpf_final_mark->SetX(0.75);
789     rmpf_final_mark->SetY(0.75);
790     rmpf_final_mark->SetTextSize(0.03);
791     rmpf_final_mark->Draw();
792 buchmann 1.3 DrawPrelim();
793 buchmann 1.19 MPFResult=1/mpf_pol0->GetParameter(0);
794     MPFResultError=mpf_pol0->GetParError(0)/(mpf_pol0->GetParameter(0)*mpf_pol0->GetParameter(0));
795 buchmann 1.2
796 buchmann 1.19 stringstream filename2;
797     filename2 << "Extrapolation/FINAL_RESULT_MPF";
798     CompleteSave(can,ContainerName+"/"+filename2.str());
799    
800     RABS_FinalGraph->SetMarkerStyle(21);
801     RABS_FinalGraph->SetMarkerStyle(21);
802     RABS_FinalGraph->SetMarkerColor(kRed);
803     RABS_FinalGraph->Fit("pol0","QE"); // quiet, use minos
804     RABS_FinalGraph->Draw("AP");
805     RABS_FinalGraph->GetXaxis()->SetTitle("p_{T}^{Z}");
806     RABS_FinalGraph->GetXaxis()->CenterTitle();
807     RABS_FinalGraph->GetYaxis()->SetTitle("<R_{abs}>_{data}/<R_{abs}>_{mc}");
808     RABS_FinalGraph->GetYaxis()->CenterTitle();
809     RABS_FinalGraph->Draw("AP");
810     TF1 *rabs_pol0=(TF1*)RABS_FinalGraph->GetFunction("pol0");
811     stringstream rabs_result;
812     rabs_result << "#splitline{C_{abs}= " << std::setprecision(5) << 1/rabs_pol0->GetParameter(0) << " #pm " << std::setprecision(2) << rabs_pol0->GetParError(0)/(rabs_pol0->GetParameter(0)*rabs_pol0->GetParameter(0)) << "}{ (R_{abs})}";;
813     TText *rabs_final_mark = write_title(rabs_result.str());
814     rabs_final_mark->SetX(0.75);
815     rabs_final_mark->SetY(0.75);
816     rabs_final_mark->SetTextSize(0.03);
817     rabs_final_mark->Draw();
818     DrawPrelim();
819 buchmann 1.2
820 buchmann 1.19 RabsResult=1/rabs_pol0->GetParameter(0);
821     RabsResultError=rabs_pol0->GetParError(0)/(rabs_pol0->GetParameter(0)*rabs_pol0->GetParameter(0));
822 buchmann 1.3
823 buchmann 1.19 filename2.str("");
824     filename2 << "Extrapolation/FINAL_RESULT_RABS";
825     CompleteSave(can,ContainerName+"/"+filename2.str());
826 buchmann 1.2 }
827 buchmann 1.19
828 buchmann 1.9 can->cd();
829 buchmann 1.13 MPF_FaceValueAtPoint3->SetMarkerStyle(21);
830     MPF_FaceValueAtPoint3->SetMarkerColor(kBlue);
831     MPF_FaceValueAtPoint3->Fit("pol0","QE"); // quiet, use minos
832     MPF_FaceValueAtPoint3->Draw("AP");
833     MPF_FaceValueAtPoint3->GetXaxis()->SetTitle("p_{T}^{Z}");
834     MPF_FaceValueAtPoint3->GetXaxis()->CenterTitle();
835 buchmann 1.19 MPF_FaceValueAtPoint3->GetYaxis()->SetTitle(((string)"<MPF>__{data}/<MPF>_{mc} for #alpha<"+any2string(FaceValueToBeTakenAt)).c_str());
836 buchmann 1.13 MPF_FaceValueAtPoint3->GetYaxis()->CenterTitle();
837     MPF_FaceValueAtPoint3->Draw("AP");
838     TF1 *faceval_pol0=(TF1*)MPF_FaceValueAtPoint3->GetFunction("pol0");
839     faceval_pol0->SetLineColor(kBlue);
840     faceval_pol0->SetLineWidth(1);
841     faceval_pol0->Draw("same");
842     TF1 *faceval_pol0_complete = new TF1("faceval_pol0_complete","[0]+[1]*x");
843     faceval_pol0_complete->SetParameters(faceval_pol0->GetParameters());
844 buchmann 1.5 stringstream faceval_result;
845 buchmann 1.19 faceval_result << "#splitline{C_{abs}= " << std::setprecision(5) << 1/faceval_pol0->GetParameter(0) << " #pm " << std::setprecision(2) << faceval_pol0->GetParError(0)/(faceval_pol0->GetParameter(0)*faceval_pol0->GetParameter(0)) << "}{ (MPF at #alpha<" << FaceValueToBeTakenAt << ")}";;
846 buchmann 1.5 TText *faceval_final_mark = write_title(faceval_result.str());
847     faceval_final_mark->SetX(0.75);
848     faceval_final_mark->SetY(0.75);
849     faceval_final_mark->SetTextSize(0.03);
850     faceval_final_mark->Draw();
851     DrawPrelim();
852    
853     float FaceValResult=1/faceval_pol0->GetParameter(0);
854     float FaceValResultError=faceval_pol0->GetParError(0)/(faceval_pol0->GetParameter(0)*faceval_pol0->GetParameter(0));
855    
856 buchmann 1.19 stringstream filename2;
857 buchmann 1.2 filename2.str("");
858 buchmann 1.9 filename2 << "Extrapolation/FINAL_RESULT_MPF_FaceValp3";
859 buchmann 1.15 CompleteSave(can,ContainerName+"/"+filename2.str());
860 buchmann 1.2
861 buchmann 1.13 can->cd();
862     RABS_FaceValueAtPoint3->SetMarkerStyle(21);
863     RABS_FaceValueAtPoint3->SetMarkerColor(kRed);
864     RABS_FaceValueAtPoint3->Fit("pol0","QE"); // quiet, use minos
865     RABS_FaceValueAtPoint3->Draw("AP");
866     RABS_FaceValueAtPoint3->GetXaxis()->SetTitle("p_{T}^{Z}");
867     RABS_FaceValueAtPoint3->GetXaxis()->CenterTitle();
868 buchmann 1.19 RABS_FaceValueAtPoint3->GetYaxis()->SetTitle(((string)"<R_{abs}>_{data}/<R_{abs}>_{mc} for #alpha<"+any2string(FaceValueToBeTakenAt)).c_str());
869 buchmann 1.13 RABS_FaceValueAtPoint3->GetYaxis()->CenterTitle();
870     RABS_FaceValueAtPoint3->Draw("AP");
871     TF1 *faceval_pol0RABS=(TF1*)RABS_FaceValueAtPoint3->GetFunction("pol0");
872     TF1 *faceval_pol0RABS_complete = new TF1("faceval_pol0_complete","[0]+[1]*x");
873     faceval_pol0RABS_complete->SetParameters(faceval_pol0RABS->GetParameters());
874     faceval_pol0RABS->SetLineWidth(1);
875     faceval_pol0RABS->SetLineColor(kRed);
876     faceval_pol0RABS_complete->Draw("same");
877     stringstream RABSfaceval_result;
878 buchmann 1.19 RABSfaceval_result << "#splitline{C_{abs}= " << std::setprecision(5) << 1/faceval_pol0RABS->GetParameter(0) << " #pm " << std::setprecision(2) << faceval_pol0RABS->GetParError(0)/(faceval_pol0RABS->GetParameter(0)*faceval_pol0RABS->GetParameter(0)) << "}{ (R_{abs} at #alpha<" << FaceValueToBeTakenAt << ")}";;
879 buchmann 1.13 TText *RABSfaceval_final_mark = write_title(RABSfaceval_result.str());
880     RABSfaceval_final_mark->SetX(0.75);
881     RABSfaceval_final_mark->SetY(0.75);
882     RABSfaceval_final_mark->SetTextSize(0.03);
883     RABSfaceval_final_mark->Draw();
884     DrawPrelim();
885    
886     float RABSFaceValResult=1/faceval_pol0RABS->GetParameter(0);
887     float RABSFaceValResultError=faceval_pol0RABS->GetParError(0)/(faceval_pol0RABS->GetParameter(0)*faceval_pol0RABS->GetParameter(0));
888    
889     filename2.str("");
890     filename2 << "Extrapolation/FINAL_RESULT_RABS_FaceValp3";
891 buchmann 1.15 CompleteSave(can,ContainerName+"/"+filename2.str());
892 buchmann 1.13
893 buchmann 1.5 cout << "FINAL RESULTS: " << endl;
894 buchmann 1.19 if(!gofast) cout << "MPF : " << MPFResult << " +/- " << MPFResultError << endl;
895     if(!gofast) cout << "Rabs: " << RabsResult << " +/- " << RabsResultError << endl;
896     cout << "Face value at " << FaceValueToBeTakenAt << " :" << FaceValResult << " +/- " << FaceValResultError << " (MPF) " << endl;
897     cout << "Face value at " << FaceValueToBeTakenAt << " :" << RABSFaceValResult << " +/- " << RABSFaceValResultError << " (RABS) " << endl;
898 buchmann 1.2
899     delete can;
900    
901 buchmann 1.15 results.MPF_Result_FaceValue=Value(FaceValResult,FaceValResultError);
902     results.Rabs_Result_FaceValue=Value(RABSFaceValResult,RABSFaceValResultError);
903 buchmann 1.19 if(!gofast) results.MPF_Result_Extrapolated=Value(MPFResult,MPFResultError);
904     if(!gofast) results.Rabs_Result_Extrapolated=Value(RabsResult,RabsResultError);
905 buchmann 1.15 cout << results << endl;
906     return results;
907 buchmann 1.2 }
908    
909    
910 buchmann 1.19 void DoPUStudy(string identifier) {
911 buchmann 1.9
912     float numVtxcuts[7]={0,10,15,20};
913    
914     TCanvas *can = new TCanvas("can","can");
915     TH1F *malpha[8];
916     TH1F *dalpha[8];
917     cout << identifier << ";";
918     cout << endl;
919     for(int i=1;i<5;i++) {
920     stringstream sSpecialCut;
921     if(i<4) {
922     sSpecialCut << "numVtx>" << numVtxcuts[i-1] << " && numVtx<" << numVtxcuts[i];
923     cout << numVtxcuts[i-1] << " < nVtx < " << numVtxcuts[i] << ";";
924     } else {
925     sSpecialCut << "numVtx>" << numVtxcuts[i-1];
926     cout << numVtxcuts[i-1] << ";";
927     }
928    
929 buchmann 1.19 sSpecialCut << " && " << identifier << "_alpha<0.3";
930 buchmann 1.9 TCut SpecialCut(sSpecialCut.str().c_str());
931    
932    
933 buchmann 1.19 malpha[i] = allsamples.Draw("malpha"+any2string(i),"mpf",1000,0,2,"MPF","events",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&SpecialCut,mc,luminosity);
934     dalpha[i] = allsamples.Draw("dalpha"+any2string(i),"mpf",1000,0,2,"MPF","events",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&SpecialCut,data,luminosity);
935 buchmann 1.9
936    
937     float a=dalpha[i]->GetMean();
938     float b=malpha[i]->GetMean();
939     float da=dalpha[i]->GetMeanError();
940     float db=malpha[i]->GetMeanError();
941     float factor = a / b;
942     float error = TMath::Sqrt( (1/(b*b)) * (da*da) + ((a*a)/(b*b))*db*db);
943    
944     cout << malpha[i]->GetMean() << ";" << malpha[i]->GetMeanError() << ";" << dalpha[i]->GetMean() << ";" << dalpha[i]->GetMeanError() << ";" << malpha[i]->Integral()<<";"<<dalpha[i]->Integral() << ";"<<factor << ";" << error << endl;
945 buchmann 1.19 delete malpha[i];
946     delete dalpha[i];
947 buchmann 1.9 }
948    
949     delete can;
950    
951     }
952    
953 buchmann 1.19 void ScenarioComparison() {
954 buchmann 1.13 //very dumb way to do this.
955 buchmann 1.19
956 buchmann 1.9 TGraphAsymmErrors *gr[5];
957     TF1 *fit[5];
958 buchmann 1.19 bool dofit=true;
959 buchmann 1.9
960     TCanvas *can = new TCanvas("can","can",500,500);
961    
962     TLegend *leg = new TLegend(0.2,0.2,0.5,0.45);
963     leg->SetBorderSize(0);
964     leg->SetFillColor(kWhite);
965    
966 buchmann 1.19 for(int i=0;i<6;i++) {
967 buchmann 1.9 gr[i] = new TGraphAsymmErrors();
968 buchmann 1.19 double x[4] = {5,12.5,17.5,25};
969     double dxl[4] = {5,2.5,2.5,5};
970 buchmann 1.9 double dxh[4] = {5,2.5,2.5,10};
971    
972     string name="";
973     string color="";
974    
975     if(i==0) {
976 buchmann 1.19 double y[4] = {1.01935,1.01558,0.996438,1.01901};
977     double dyl[4] = {0.0132973,0.0131661,0.017629,0.0319767};
978     double dyh[4] = {0.0132973,0.0131661,0.017629,0.0319767};
979 buchmann 1.9 name="30/30";
980     gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
981     color="#a01d99";
982     }
983     if(i==1) {
984 buchmann 1.19 double y[4] = {1.00577,1.00706,0.991029,0.954098};
985     double dyl[4] = {0.0135575,0.0136548,0.0170778,0.0263919};
986     double dyh[4] = {0.0135575,0.0136548,0.0170778,0.0263919};
987 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
988 buchmann 1.13 name="30/15";
989 buchmann 1.9 color="#2464bc";
990     }
991     if(i==2) {
992 buchmann 1.19 double y[4] = {1.023,1.00648,1.02217,1.03181};
993     double dyl[4] = {0.0157372,0.0187778,0.0261512,0.0422295};
994     double dyh[4] = {0.0157372,0.0187778,0.0261512,0.0422295};
995 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
996     name="15/15";
997     color="#f49230";
998     }
999     if(i==3) {
1000 buchmann 1.19 double y[4] = {1.02029,1.01338,0.999769,1.00357};
1001     double dyl[4] = {0.0129509,0.0120127,0.0160537,0.0268972};
1002     double dyh[4] = {0.0129509,0.0120127,0.0160537,0.0268972};
1003 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1004 buchmann 1.19 name="CHS 30/30";
1005 buchmann 1.9 color="#c72f3c";
1006     }
1007     if(i==4) {
1008 buchmann 1.19 double y[4] = {1.00274,1.01056,0.993214,0.997963};
1009     double dyl[4] = {0.0127179,0.0140344,0.0162814,0.0278914};
1010     double dyh[4] = {0.0127179,0.0140344,0.0162814,0.0278914};
1011 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1012 buchmann 1.19 name="CHS 30/15";
1013 buchmann 1.9 color="#7cb433";
1014     }
1015 buchmann 1.19 if(i==5) {
1016     double y[4] = {1.04103,1.03726,1.04649,1.05383};
1017     double dyl[4] = {0.0156465,0.0168194,0.0231982,0.0376114};
1018     double dyh[4] = {0.0156465,0.0168194,0.0231982,0.0376114};
1019     gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1020     name="CHS 15/15";
1021     color="#DF013A";
1022     }
1023    
1024    
1025 buchmann 1.9 gr[i]->SetTitle();
1026     gr[i]->GetXaxis()->SetTitle("N(Vtx)");
1027     gr[i]->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
1028     gr[i]->GetXaxis()->CenterTitle();
1029     gr[i]->GetYaxis()->CenterTitle();
1030     gr[i]->SetName(name.c_str());
1031     gr[i]->SetMarkerSize(0.00001);
1032     gr[i]->GetYaxis()->SetRangeUser(0.90,1.10);
1033     gr[i]->SetLineColor(TColor::GetColor(color.c_str()));
1034     gr[i]->SetMarkerColor(TColor::GetColor(color.c_str()));
1035     if(dofit) {
1036     gr[i]->Fit("pol1");
1037     fit[i] = (TF1*)gr[i]->GetFunction("pol1");
1038     fit[i]->SetLineColor(TColor::GetColor(color.c_str()));
1039     }
1040     leg->AddEntry(gr[i],name.c_str(),"l");
1041     if(i==0) gr[i]->Draw("AP*");
1042     else gr[i]->Draw("P");
1043     }
1044     leg->Draw();
1045     DrawPrelim();
1046    
1047     CompleteSave(can,"ScenarioComparison");
1048     delete can;
1049    
1050     }
1051    
1052 buchmann 1.19 void ScenarioComparisonInclusive() {
1053 buchmann 1.13 //dumbest way ever to do this. but ok we only need to do it once.
1054 buchmann 1.9 TGraphAsymmErrors *gr[5];
1055     TF1 *fit[5];
1056     bool dofit=true;
1057    
1058     TCanvas *can = new TCanvas("can","can",500,500);
1059    
1060 buchmann 1.19 TLegend *leg = new TLegend(0.2,0.2,0.65,0.45);
1061 buchmann 1.9 leg->SetBorderSize(0);
1062     leg->SetFillColor(kWhite);
1063    
1064 buchmann 1.19 for(int i=0;i<6;i++) {
1065 buchmann 1.9 gr[i] = new TGraphAsymmErrors();
1066 buchmann 1.19 double x[4] = {5,12.5,17.5,25};
1067     double dxl[4] = {5,2.5,2.5,5};
1068     double dxh[4] = {5,2.5,2.5,5};
1069 buchmann 1.9
1070     string name="";
1071     string color="";
1072    
1073     if(i==0) {
1074 buchmann 1.19 double y[4] = {1.01093,1.01379,1.0147,1.02766};
1075     double dyl[4] = {0.00243596,0.00242534,0.00341941,0.00600663};
1076     double dyh[4] = {0.00243596,0.00242534,0.00341941,0.00600663};
1077 buchmann 1.9 name="30/30";
1078     gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1079     color="#a01d99";
1080     }
1081     if(i==1) {
1082 buchmann 1.19 double y[4] = {1.0068,1.00779,0.999692,0.994484};
1083     double dyl[4] = {0.00249233,0.00257169,0.00371399,0.00631138};
1084     double dyh[4] = {0.00249233,0.00257169,0.00371399,0.00631138};
1085 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1086 buchmann 1.13 name="30/15";
1087 buchmann 1.9 color="#2464bc";
1088     }
1089     if(i==2) {
1090 buchmann 1.19 double y[4] = {1.01208,1.01991,1.02185,1.03479};
1091     double dyl[4] = {0.00366745,0.00400001,0.00584054,0.0104661};
1092     double dyh[4] = {0.00366745,0.00400001,0.00584054,0.0104661};
1093 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1094     name="15/15";
1095     color="#f49230";
1096     }
1097     if(i==3) {
1098 buchmann 1.19 double y[4] = {1.01177,1.01568,1.01616,1.03211};
1099     double dyl[4] = {0.00217317,0.00203014,0.00276838,0.00465643};
1100     double dyh[4] = {0.00217317,0.00203014,0.00276838,0.00465643};
1101 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1102 buchmann 1.19 name="CHS 30/30";
1103 buchmann 1.9 color="#c72f3c";
1104     }
1105     if(i==4) {
1106 buchmann 1.19 double y[4] = {1.00751,1.00964,1.00804,1.01073};
1107     double dyl[4] = {0.00224851,0.00215563,0.0029592,0.00499805};
1108     double dyh[4] = {0.00224851,0.00215563,0.0029592,0.00499805};
1109 buchmann 1.9 gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1110 buchmann 1.19 name="CHS 30/15";
1111 buchmann 1.9 color="#7cb433";
1112     }
1113 buchmann 1.19 if(i==5) {
1114     double y[4] = {1.01557,1.0318,1.03535,1.06331};
1115     double dyl[4] = {0.00300783,0.00302486,0.00421064,0.00739416};
1116     double dyh[4] = {0.00300783,0.00302486,0.00421064,0.00739416};
1117     gr[i] = new TGraphAsymmErrors(4,x,y,dxl,dxh,dyl,dyh);
1118     name="CHS 15/15";
1119     color="#DF013A";
1120     }
1121 buchmann 1.9
1122 buchmann 1.19 gStyle->SetOptFit(0);
1123 buchmann 1.9 gr[i]->SetTitle();
1124     gr[i]->GetXaxis()->SetTitle("N(Vtx)");
1125     gr[i]->GetYaxis()->SetTitle("<MPF>_{data}/<MPF>_{mc}");
1126     gr[i]->GetXaxis()->CenterTitle();
1127     gr[i]->GetYaxis()->CenterTitle();
1128     gr[i]->SetName(name.c_str());
1129     gr[i]->SetMarkerSize(0.00001);
1130     gr[i]->GetYaxis()->SetRangeUser(0.90,1.10);
1131     gr[i]->SetLineColor(TColor::GetColor(color.c_str()));
1132     gr[i]->SetMarkerColor(TColor::GetColor(color.c_str()));
1133     if(dofit) {
1134     gr[i]->Fit("pol1");
1135     fit[i] = (TF1*)gr[i]->GetFunction("pol1");
1136     fit[i]->SetLineColor(TColor::GetColor(color.c_str()));
1137     }
1138 buchmann 1.19
1139     stringstream nameplus;
1140     nameplus << name << " (slope: " << std::setprecision(3) << fit[i]->GetParameter(1) << ")";
1141    
1142     leg->AddEntry(gr[i],nameplus.str().c_str(),"l");
1143 buchmann 1.9 if(i==0) gr[i]->Draw("AP*");
1144     else gr[i]->Draw("P");
1145     }
1146     leg->Draw();
1147     DrawPrelim();
1148    
1149     CompleteSave(can,"ScenarioComparisonInclusive");
1150     delete can;
1151    
1152     }
1153 buchmann 1.2
1154 buchmann 1.19 void compare_selection(string identifier) {
1155 buchmann 1.7 bool recognized_scenario=false;
1156    
1157     cout << "Running with identifier " << identifier << endl;
1158 buchmann 1.19 if(identifier=="Zb30") {
1159     LeadingB=TCut ("Zb30_bTagProbCSVBP[0]>0.898");
1160     EtaB=TCut("abs(Zb30_pfJetGoodEta[0])<1.3");
1161     PhiZcut=TCut("abs(Zb30_pfJetDphiZ[0])>2.7");
1162     recognized_scenario=true;
1163     }
1164 buchmann 1.9 if(identifier=="Zb3010") {
1165     LeadingB=TCut ("Zb3010_bTagProbCSVBP[0]>0.898");
1166     EtaB=TCut("abs(Zb3010_pfJetGoodEta[0])<1.3");
1167     PhiZcut=TCut("abs(Zb3010_pfJetDphiZ[0])>2.7");
1168     recognized_scenario=true;
1169     }
1170    
1171 buchmann 1.19 if(identifier=="ZbCHS3010") {
1172     LeadingB=TCut ("ZbCHS1510_bTagProbCSVBP[0]>0.898");
1173     EtaB=TCut("abs(ZbCHS1510_pfJetGoodEta[0])<1.3");
1174     PhiZcut=TCut("abs(ZbCHS1510_pfJetDphiZ[0])>2.7");
1175 buchmann 1.7 recognized_scenario=true;
1176     }
1177    
1178 buchmann 1.9 if(identifier=="Zb40") {
1179     LeadingB=TCut ("Zb40_bTagProbCSVBP[0]>0.898");
1180     EtaB=TCut("abs(Zb40_pfJetGoodEta[0])<1.3");
1181     PhiZcut=TCut("abs(Zb40_pfJetDphiZ[0])>2.7");
1182     recognized_scenario=true;
1183     }
1184    
1185 buchmann 1.19 if(identifier=="ZbCHS301030") {
1186     LeadingB=TCut ("ZbCHS301030_bTagProbCSVBP[0]>0.898");
1187     EtaB=TCut("abs(ZbCHS301030_pfJetGoodEta[0])<1.3");
1188     PhiZcut=TCut("abs(ZbCHS301030_pfJetDphiZ[0])>2.7");
1189 buchmann 1.7 recognized_scenario=true;
1190     }
1191    
1192     if(identifier=="Zb1530") {
1193 buchmann 1.9 LeadingB=TCut ("Zb1530_bTagProbCSVBP[0]>0.898");
1194 buchmann 1.7 EtaB=TCut("abs(Zb1530_pfJetGoodEta[0])<1.3");
1195     PhiZcut=TCut("abs(Zb1530_pfJetDphiZ[0])>2.7");
1196     recognized_scenario=true;
1197     }
1198    
1199 buchmann 1.19 if(identifier=="ZbCHS301010") {
1200     LeadingB=TCut ("ZbCHS301010_bTagProbCSVBP[0]>0.898");
1201     EtaB=TCut("abs(ZbCHS301010_pfJetGoodEta[0])<1.3");
1202     PhiZcut=TCut("abs(ZbCHS301010_pfJetDphiZ[0])>2.7");
1203 buchmann 1.9 recognized_scenario=true;
1204     }
1205    
1206     if(identifier=="Zb1510") {
1207     LeadingB=TCut ("Zb1510_bTagProbCSVBP[0]>0.898");
1208     EtaB=TCut("abs(Zb1510_pfJetGoodEta[0])<1.3");
1209     PhiZcut=TCut("abs(Zb1510_pfJetDphiZ[0])>2.7");
1210     recognized_scenario=true;
1211     }
1212    
1213 buchmann 1.19 if(identifier=="ZbCHS301010") {
1214     LeadingB=TCut ("ZbCHS301010_bTagProbCSVBP[0]>0.898");
1215     EtaB=TCut("abs(ZbCHS301010_pfJetGoodEta[0])<1.3");
1216     PhiZcut=TCut("abs(ZbCHS301010_pfJetDphiZ[0])>2.7");
1217 buchmann 1.9 recognized_scenario=true;
1218     }
1219    
1220     if(identifier=="ZbMikko") {
1221     LeadingB=TCut ("ZbMikko_bTagProbCSVBP[0]>0.898 && ZbMikko__IsClean");
1222     EtaB=TCut("abs(ZbMikko_pfJetGoodEta[0])<1.3 && ZbMikko__IsClean");
1223     PhiZcut=TCut("abs(ZbMikko_pfJetDphiZ[0])>2.7 && ZbMikko__IsClean");
1224 buchmann 1.7 recognized_scenario=true;
1225     }
1226    
1227 buchmann 1.19 if(identifier=="ZbCHS3010_SecEta3") {
1228     LeadingB=TCut ("ZbCHS3010_SecEta3_bTagProbCSVBP[0]>0.898");
1229     EtaB=TCut("abs(ZbCHS3010_SecEta3_pfJetGoodEta[0])<1.3");
1230     PhiZcut=TCut("abs(ZbCHS3010_SecEta3_pfJetDphiZ[0])>2.7");
1231 buchmann 1.7 recognized_scenario=true;
1232     }
1233    
1234 buchmann 1.19 if(identifier=="ZbCHS3010_SecEta5") {
1235     LeadingB=TCut ("ZbCHS3010_SecEta5_bTagProbCSVBP[0]>0.898");
1236     EtaB=TCut("abs(ZbCHS3010_SecEta5_pfJetGoodEta[0])<1.3");
1237     PhiZcut=TCut("abs(ZbCHS3010_SecEta5_pfJetDphiZ[0])>2.7");
1238 buchmann 1.7 recognized_scenario=true;
1239     }
1240    
1241 buchmann 1.19 if(identifier=="ZbCHS3010_p5Clean") {
1242     LeadingB=TCut ("ZbCHS3010_p5Clean_bTagProbCSVBP[0]>0.898 && ZbCHS3010_p5Clean_IsClean");
1243     EtaB=TCut("abs(ZbCHS3010_p5Clean_pfJetGoodEta[0])<1.3 && ZbCHS3010_p5Clean_IsClean");
1244     PhiZcut=TCut("abs(ZbCHS3010_p5Clean_pfJetDphiZ[0])>2.7 && ZbCHS3010_p5Clean_IsClean");
1245 buchmann 1.7 recognized_scenario=true;
1246     }
1247    
1248 buchmann 1.19 if(identifier=="ZbCHS3010") {
1249     LeadingB=TCut ("ZbCHS3010_bTagProbCSVBP[0]>0.898");
1250     EtaB=TCut("abs(ZbCHS3010_pfJetGoodEta[0])<1.3");
1251     PhiZcut=TCut("abs(ZbCHS3010_pfJetDphiZ[0])>2.7");
1252     recognized_scenario=true;
1253     }
1254     if(identifier=="ZbCHS3010") {
1255     LeadingB=TCut ("ZbCHS3010_bTagProbCSVBP[0]>0.898");
1256     EtaB=TCut("abs(ZbCHS3010_pfJetGoodEta[0])<1.3");
1257     PhiZcut=TCut("abs(ZbCHS3010_pfJetDphiZ[0])>2.7");
1258     recognized_scenario=true;
1259     }
1260     if(identifier=="ZbCHS30") {
1261     LeadingB=TCut ("ZbCHS30_bTagProbCSVBP[0]>0.898");
1262     EtaB=TCut("abs(ZbCHS30_pfJetGoodEta[0])<1.3");
1263     PhiZcut=TCut("abs(ZbCHS30_pfJetDphiZ[0])>2.7");
1264 buchmann 1.7 recognized_scenario=true;
1265     }
1266    
1267     assert(recognized_scenario);
1268    
1269     cout << "Cuts: " << endl;
1270     cout << " " << (const char*) LeadingB << endl;
1271     cout << " " << (const char*) EtaB << endl;
1272     cout << " " << (const char*) PhiZcut << endl;
1273    
1274     cout << endl << endl;
1275 buchmann 1.19
1276     // ScenarioComparison();
1277     // ScenarioComparisonInclusive();
1278    
1279     // DoPUStudy(identifier);
1280     // SpecialCutFlow(identifier);
1281 buchmann 1.7
1282 buchmann 1.19 // draw_kin_variable("pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000",17000,30,200,"Z p_{T}","Official/"+identifier+"/Zpt__"+identifier,1);
1283     // draw_kin_variable(identifier+"_pfJetGoodPt[0]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000",40,0,200,"Leading Jet Pt (B)","Official/"+identifier+"/LeadingJetPt__"+identifier,1);
1284     // draw_kin_variable(identifier+"_pfJetGoodPt[1]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000",40,0,200,"Sub-Leading Jet Pt [GeV]","Official/"+identifier+"/Jet2Pt__"+identifier,1);
1285     // draw_kin_variable(identifier+"_pfJetGoodPt[1]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>30&&pt<1000",20,0,2,"p_{T}^{J2} / p_{T}^{Z}","Official/"+identifier+"/SubLeadingJetPt_Over_ZPt__"+identifier,1);
1286 buchmann 1.9 draw_kin_variable(identifier+"_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>30&&pt<50"),20,0,2,"#alpha","Official/"+identifier+"/alpha_pt_30_to_50__"+identifier,1);
1287     draw_kin_variable(identifier+"_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>50&&pt<75"),20,0,2,"#alpha","Official/"+identifier+"/alpha_50_to_75__"+identifier,1);
1288     draw_kin_variable(identifier+"_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>75&&pt<125"),20,0,2,"#alpha","Official/"+identifier+"/alpha_pt_75_to_125__"+identifier,1);
1289     draw_kin_variable(identifier+"_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut("pt>125&&pt<1000"),20,0,2,"#alpha","Official/"+identifier+"/alpha_pt_125_to_1000__"+identifier,1);
1290     draw_kin_variable(identifier+"_alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut,20,0,2,"#alpha","Official/"+identifier+"/alpha_full__"+identifier,1);
1291 buchmann 1.19 draw_kin_variable(identifier+"_pfBJetDphiZ[0]",ZplusBsel&&LeadingB&&"pt>30&&pt<1000&&pfBJetDphiZ[0]>0",30,0,3.2,"#delta#phi (Z,b lead)","Official/"+identifier+"/DeltaPhiZBlead__"+identifier,0);
1292 buchmann 1.7
1293 buchmann 1.19 draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.3").c_str()),20,0,2,"Z+b MPF","Official/"+identifier+"/mpf_alpha_smaller_0p3___"+identifier,0,"#alpha<0.3, 30 GeV < p_{T}^{Z} < 1000 GeV");
1294     draw_kin_variable(identifier+"_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.3").c_str()),20,0,2,"p_{T} b-jet / p_{T} Z","Official/"+identifier+"/ptb_over_ptz___alpha_smaller_0p3______"+identifier,0,"#alpha<0.3, 30 GeV < p_{T}^{Z} < 1000 GeV");
1295     draw_kin_variable(identifier+"_pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<50&&"+identifier+"_alpha<0.3").c_str()),20,0,2,"p_{T} b-jet / p_{T} Z","Official/"+identifier+"/ptb_over_ptz___alpha_smaller_0p3___pt3050___"+identifier,0,"#alpha<0.3, 30 GeV < p_{T}^{Z} < 1000 GeV}{30<p_{T}^{Z}<50 GeV}");
1296 buchmann 1.7
1297     }
1298    
1299 buchmann 1.14 void GetNumberEventsInsideOutsideAlphaWindow(TCut specialcut, string title) {
1300 buchmann 1.13
1301 buchmann 1.19 // TCut cut = ZplusBsel&&LeadingB&&PhiZcut&&specialcut&&TCut("ZbCHS3010_alpha<0.3");
1302 buchmann 1.14 TCut cut = specialcut;
1303     TCut in = EtaB;
1304 buchmann 1.19 TCut out = TCut("abs(ZbCHS3010_pfJetGoodEta[0])>1.3");
1305 buchmann 1.13
1306     TH1F *data_IN = allsamples.Draw("data_IN", "mll",1,0,150, "nothing [GeV]", "events", cut&&in, data,luminosity);
1307     TH1F *data_OUT = allsamples.Draw("data_OUT", "mll",1,0,150, "nothing [GeV]", "events", cut&&out,data,luminosity);
1308     TH1F *mc_IN = allsamples.Draw("mc_IN", "mll",1,0,150, "nothing [GeV]", "events", cut&&in, mc ,luminosity);
1309     TH1F *mc_OUT = allsamples.Draw("mc_OUT", "mll",1,0,150, "nothing [GeV]", "events", cut&&out,mc ,luminosity);
1310    
1311 buchmann 1.14 dout << title << " : " << endl;
1312 buchmann 1.13 dout << " Data: In " << data_IN->Integral() << " vs out " << data_OUT->Integral() << endl;
1313     dout << " MC : In " << mc_IN->Integral() << " vs out " << mc_OUT->Integral() << endl;
1314 buchmann 1.14 dout << " ratio in : " << data_IN->Integral()/mc_IN->Integral() << " +/- " << (data_IN->Integral()/mc_IN->Integral()) * sqrt(1.0/mc_IN->Integral()+ 1.0/data_IN->Integral()) << endl;
1315     dout << " ratio out : " << data_OUT->Integral()/mc_OUT->Integral() << " +/- " << (data_OUT->Integral()/mc_OUT->Integral()) * sqrt(1.0/mc_OUT->Integral()+ 1.0/data_OUT->Integral()) << endl;
1316    
1317     delete data_IN;
1318     delete data_OUT;
1319     delete mc_IN;
1320     delete mc_OUT;
1321 buchmann 1.13 }
1322    
1323 buchmann 1.15 void TEST_GetNumberEventsInsideOutsideAlphaWindow() {
1324 buchmann 1.14 TCanvas *ca = new TCanvas("ca","ca");
1325     // GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==0"), "ee");
1326     // GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==1"), "mm");
1327     // GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2"), "ee/mm");
1328    
1329     cout << "BASE SELECTION" << endl;
1330     GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==0"), "ee");
1331     GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2&&id1==1"), "mm");
1332     GetNumberEventsInsideOutsideAlphaWindow(TCut("id1==id2"), "ee/mm");
1333    
1334     cout << "BASE SELECTION: Z+b" << endl;
1335     GetNumberEventsInsideOutsideAlphaWindow(ZplusBsel&&TCut("id1==id2&&id1==0"), "ee");
1336     GetNumberEventsInsideOutsideAlphaWindow(ZplusBsel&&TCut("id1==id2&&id1==1"), "mm");
1337     GetNumberEventsInsideOutsideAlphaWindow(ZplusBsel&&TCut("id1==id2"), "ee/mm");
1338    
1339     cout << "Leading B" << endl;
1340     GetNumberEventsInsideOutsideAlphaWindow(LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==0"), "ee");
1341     GetNumberEventsInsideOutsideAlphaWindow(LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==1"), "mm");
1342     GetNumberEventsInsideOutsideAlphaWindow(LeadingB&&ZplusBsel&&TCut("id1==id2"), "ee/mm");
1343    
1344     cout << "PhiZcut" << endl;
1345     GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==0"), "ee");
1346     GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==1"), "mm");
1347     GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2"), "ee/mm");
1348    
1349     cout << "alpha cut" << endl;
1350 buchmann 1.19 GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==0")&&TCut("ZbCHS3010_alpha<0.3"), "ee");
1351     GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2&&id1==1")&&TCut("ZbCHS3010_alpha<0.3"), "mm");
1352     GetNumberEventsInsideOutsideAlphaWindow(PhiZcut&&LeadingB&&ZplusBsel&&TCut("id1==id2")&&TCut("ZbCHS3010_alpha<0.3"), "ee/mm");
1353 buchmann 1.14
1354     delete ca;
1355    
1356    
1357     }
1358    
1359    
1360    
1361 buchmann 1.13
1362 buchmann 1.15 void do_basic_ZB_analysis(bool DoCompleteAnalysis) {
1363 buchmann 1.19 STDWEIGHT=TCut(cutWeight);
1364     cutWeight=TCut(STDWEIGHT*TCut("ZbCHS3010_BTagWgtT"));
1365 buchmann 1.14 cout << "The lepton requirement is " << (const char*) leptoncut << endl;
1366 buchmann 1.19 bool doquick=false;
1367 buchmann 1.9
1368 buchmann 1.19 TCanvas *zbcanvas = new TCanvas("zbcanvas","zbcanvas");
1369 buchmann 1.1
1370 buchmann 1.19 // ScenarioComparison();
1371     // ScenarioComparisonInclusive();
1372    
1373     // compare_selection("ZbCHS3010_p5Clean");
1374     // compare_selection("ZbCHS3010");
1375     // compare_selection("Zb30");
1376     // compare_selection("Zb3010");
1377     // compare_selection("Zb1510");
1378     // compare_selection("ZbCHS30");
1379     // compare_selection("ZbCHS3010");
1380     // compare_selection("ZbCHS3010");
1381     // compare_selection("ZbCHS301010");
1382     // compare_selection("ZbCHS3010_SecEta3");
1383     // compare_selection("ZbCHS3010_SecEta5");
1384     // compare_selection("Zb1510");
1385     // compare_selection("ZbCHS301010");
1386     // compare_selection("ZbMikko");
1387     // compare_selection("ZbCHS3010");
1388     // compare_selection("Zb40");
1389 buchmann 1.8
1390 buchmann 1.11 if(!doquick) {
1391 buchmann 1.20 //draw_kin_variable("mll","",28,60.0,200.0,"m_{ll}","mll",1,"");//nice and quick test to see if the normalization is ok (i.e. all data is processed etc.)
1392     //print_all_b_yields();
1393 buchmann 1.22 // draw_mpf_vars();
1394 buchmann 1.20 //DrawEvilCutFlow();
1395 buchmann 1.11
1396 buchmann 1.22 // draw_Zb_kin_vars();
1397 buchmann 1.11
1398     }
1399 buchmann 1.7
1400 buchmann 1.14 // GetNumberEventsInsideOutsideAlphaWindow();
1401 buchmann 1.15
1402     if(DoCompleteAnalysis) {
1403     /* need to run the following scenarios:
1404     * - normal
1405     * - inclusive
1406     * - medium WP
1407     * - alpha up
1408     * - alpha down
1409     */
1410    
1411 buchmann 1.19 bool fast=true;bool slow=false;//don't change these
1412 buchmann 1.16
1413 buchmann 1.19 ZbResultContainer inclusive = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","inclusive",TCut("mll>0"),TCut("1.0"),0.3);
1414     ZbResultContainer Reference = new_data_mc_agreement_2d(slow,"ZbCHS3010_alpha","reference",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtT"),0.3);
1415 buchmann 1.20
1416     ZbResultContainer NeutrinoQ = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","NeutrinoQ",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtTUp*(1.0*softMuon)"),0.3);
1417     ZbResultContainer ANeutrinoQ = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","ANeutrinoQ",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtTUp*(1.0*(1.0-softMuon))"),0.3);
1418    
1419 buchmann 1.19 ZbResultContainer effmistagUp = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","effmistagUp",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtTUp"),0.3);
1420     ZbResultContainer effmistagDown = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","effmistagDown",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtTDown"),0.3);
1421     ZbResultContainer medium = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","medium",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.679"),TCut("ZbCHS3010_BTagWgtM"),0.3);
1422     ZbResultContainer loose = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","loose",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.244"),TCut("ZbCHS3010_BTagWgtL"),0.3);
1423     ZbResultContainer AlphaUp = new_data_mc_agreement_2d(fast,"ZbCHS3010_alphaUp","AlphaUp",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtT"),0.3);
1424     ZbResultContainer AlphaDown = new_data_mc_agreement_2d(fast,"ZbCHS3010_alphaDown","AlphaDown",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtT"),0.3);
1425    
1426 buchmann 1.20 ZbResultContainer L5inclusive = new_data_mc_agreement_2d(fast,"ZbCHS3010_alphaL5","L5inclusive",TCut("mll>0"),TCut("1.0"),0.3);
1427     ZbResultContainer L5Reference = new_data_mc_agreement_2d(fast,"ZbCHS3010_alphaL5","L5reference",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtT"),0.3);
1428    
1429     ZbResultContainer AlphaThresholdVariationDown10 = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationDown10", TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"), TCut("ZbCHS3010_BTagWgtT"),0.3-0.1*0.3);
1430     ZbResultContainer AlphaThresholdVariationUp10 = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationUp10", TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"), TCut("ZbCHS3010_BTagWgtT"),0.3+0.1*0.3);
1431     ZbResultContainer AlphaThresholdVariationDown30 = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationDown30", TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"), TCut("ZbCHS3010_BTagWgtT"),0.3-0.3*0.3);
1432     ZbResultContainer AlphaThresholdVariationUp30 = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationUp30", TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"), TCut("ZbCHS3010_BTagWgtT"),0.3+0.3*0.3);
1433     ZbResultContainer AlphaThresholdVariationDown10inc = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationDown10inc",TCut("mll>0"), TCut("1.0"),0.3-0.1*0.3);
1434     ZbResultContainer AlphaThresholdVariationUp10inc = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationUp10inc", TCut("mll>0"), TCut("1.0"),0.3+0.1*0.3);
1435     ZbResultContainer AlphaThresholdVariationDown30inc = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationDown30inc",TCut("mll>0"), TCut("1.0"),0.3-0.3*0.3);
1436     ZbResultContainer AlphaThresholdVariationUp30inc = new_data_mc_agreement_2d(fast,"ZbCHS3010_alpha","AlphaThresholdVariationUp30inc", TCut("mll>0"), TCut("1.0"),0.3+0.3*0.3);
1437 buchmann 1.19
1438 buchmann 1.16 //and now let's compute some systematics!
1439     //1 alpha variation
1440     float SysMPF_Alpha_down = Reference.MPF_Result_FaceValue.getValue()-AlphaDown.MPF_Result_FaceValue.getValue();
1441     float SysMPF_Alpha_up = Reference.MPF_Result_FaceValue.getValue()-AlphaUp.MPF_Result_FaceValue.getValue();
1442    
1443     //2 btagging efficiency/mistag correction
1444     float SysMPF_EFF_down = Reference.MPF_Result_FaceValue.getValue()-effmistagDown.MPF_Result_FaceValue.getValue();
1445     float SysMPF_EFF_up = Reference.MPF_Result_FaceValue.getValue()-effmistagUp.MPF_Result_FaceValue.getValue();
1446    
1447 buchmann 1.20 //3 Presence of soft muons (->neutrino question)
1448     float SysMPF_Neutrino_up = Reference.MPF_Result_FaceValue.getValue()-NeutrinoQ.MPF_Result_FaceValue.getValue();
1449     float SysMPF_Neutrino_down = Reference.MPF_Result_FaceValue.getValue()-ANeutrinoQ.MPF_Result_FaceValue.getValue();
1450    
1451     //4 purity
1452 buchmann 1.16 zbcanvas->cd();
1453 buchmann 1.17 gStyle->SetOptFit(0);
1454 buchmann 1.16 write_info(__FUNCTION__,"Don't know the exact purity at the moment, still needs to be determined!");
1455 buchmann 1.17 TH1F *purityhisto = new TH1F("purityhisto","purityhisto",1,0,1);
1456     purityhisto->GetXaxis()->SetTitle("Purity");
1457     purityhisto->GetYaxis()->SetTitle("C_{abs}");
1458     purityhisto->GetXaxis()->CenterTitle();
1459     purityhisto->GetYaxis()->CenterTitle();
1460    
1461 buchmann 1.16 TGraphErrors *gSysMPF_Purity = new TGraphErrors();
1462 buchmann 1.20
1463     gSysMPF_Purity->SetPoint(0,PurityInclusive,inclusive.MPF_Result_FaceValue.getValue());
1464 buchmann 1.16 gSysMPF_Purity->SetPointError(0,0.0,inclusive.MPF_Result_FaceValue.getError());
1465 buchmann 1.17
1466 buchmann 1.20 gSysMPF_Purity->SetPoint(1,PurityLoose,loose.MPF_Result_FaceValue.getValue());//x value?
1467 buchmann 1.16 gSysMPF_Purity->SetPointError(1,0.0,loose.MPF_Result_FaceValue.getError());
1468 buchmann 1.20 gSysMPF_Purity->SetPoint(2,PurityMedium,medium.MPF_Result_FaceValue.getValue());//x value?
1469 buchmann 1.16 gSysMPF_Purity->SetPointError(2,0.0,medium.MPF_Result_FaceValue.getError());
1470 buchmann 1.20 gSysMPF_Purity->SetPoint(3,PurityTight,Reference.MPF_Result_FaceValue.getValue());//x value?
1471 buchmann 1.16 gSysMPF_Purity->SetPointError(3,0.0,Reference.MPF_Result_FaceValue.getError());
1472    
1473 buchmann 1.17
1474     float min,max;
1475     FindMinMax(gSysMPF_Purity,min,max);
1476     purityhisto->SetStats(0);
1477     purityhisto->GetYaxis()->SetRangeUser(min,max);
1478 buchmann 1.16
1479     gSysMPF_Purity->Fit("pol1");
1480 buchmann 1.17 TPolyLine *purity_fit_uncert = GetFitUncertaintyShape(gSysMPF_Purity, "pol1", min, max,0.0,1.0);
1481     TF1* pufit = (TF1*)gSysMPF_Purity->GetFunction("pol1");
1482    
1483     TF1* pufit_c = new TF1("pufit_c","[0]+[1]*x");
1484     pufit_c->SetParameters(pufit->GetParameters());
1485     pufit_c->SetLineColor(TColor::GetColor("#0101DF"));
1486     purity_fit_uncert->SetFillColor(TColor::GetColor("#5353FC"));
1487     pufit->SetLineColor(TColor::GetColor("#5353FC"));
1488    
1489     purityhisto->Draw();
1490     purity_fit_uncert->Draw("f");
1491     gSysMPF_Purity->Draw("P*");
1492     pufit_c->Draw("same");
1493     DrawPrelim();
1494    
1495     float ExtrapolatedResult=pufit->GetParameter(0)+1.0*pufit->GetParameter(1);
1496     float dExtrapolatedResult=sqrt(pufit->GetParError(0)*pufit->GetParError(0)+1.0*1.0*pufit->GetParError(1)*pufit->GetParError(1));
1497    
1498     stringstream summary;
1499     summary << "#splitline{Reference: " << std::setprecision(4) << Reference.MPF_Result_FaceValue.getValue() << "+/-" << std::setprecision(4) << Reference.MPF_Result_FaceValue.getError() << "}{";
1500     summary << "Extrapolation: " << std::setprecision(4) << ExtrapolatedResult << " +/- " << std::setprecision(4) << dExtrapolatedResult << "}";
1501    
1502     dout << "Have found an extrapolated result at 1.0 of " << ExtrapolatedResult << " ; will use the difference between this result and the face value as ";
1503     dout << "purity-related systematic uncertainty" << endl;
1504    
1505     TText *infobox = write_title(summary.str());
1506     infobox->SetX(0.75);
1507     infobox->SetTextSize(0.03);
1508     infobox->SetY(0.75);
1509     infobox->Draw();
1510    
1511 buchmann 1.16 CompleteSave(zbcanvas,"Systematics/Purity");
1512    
1513    
1514 buchmann 1.17
1515 buchmann 1.16 float SysMPF_Purity = abs(ExtrapolatedResult-Reference.MPF_Result_FaceValue.getValue());
1516    
1517 buchmann 1.20 float sys_alpha = abs(SysMPF_Alpha_down)>abs(SysMPF_Alpha_up)?abs(SysMPF_Alpha_down):abs(SysMPF_Alpha_up);
1518     float sys_eff = abs(SysMPF_EFF_down)>abs(SysMPF_EFF_up)?abs(SysMPF_EFF_down):abs(SysMPF_EFF_up);
1519     float sys_purity = abs(SysMPF_Purity);
1520     float sys_neutrino = abs(SysMPF_Neutrino_down)>abs(SysMPF_Neutrino_up)?abs(SysMPF_Neutrino_down):abs(SysMPF_Neutrino_up);
1521     float sys = sqrt(sys_alpha*sys_alpha+sys_eff*sys_eff+sys_purity*sys_purity+sys_neutrino*sys_neutrino);
1522 buchmann 1.16
1523     dout << "MPF METHOD:" << endl;
1524 buchmann 1.17 dout << " Systematics : down up (selected)" << endl;
1525 buchmann 1.20 dout << " Oversmearing : " << SysMPF_Alpha_down << " , " << SysMPF_Alpha_up << " ( " << sys_alpha << ") " << endl;
1526 buchmann 1.16 dout << " eff/mistag variation : " << SysMPF_EFF_down << " , " << SysMPF_EFF_up << " ( " << sys_eff << ") " << endl;
1527     dout << " purity : " << SysMPF_Purity << " ( " << sys_purity << " )" << endl;
1528 buchmann 1.20 dout << " neutrino : " << SysMPF_Neutrino_down << " , " << SysMPF_Neutrino_up << " ( " << sys_neutrino << ") " << endl;
1529     dout << " total : " << sys << " (note that this is the sys on C_{abs}^{b}, not yet on C_{corr} - there will also be an additional source!)" << endl;
1530 buchmann 1.16 dout << endl << endl;
1531 buchmann 1.17 dout << " FINAL RESULTS : " << endl;
1532     dout << " C_{abs}^{b} = " << Reference.MPF_Result_FaceValue << " (stat) +/- " << sys << " (sys) " << endl;
1533     dout << " C_{abs}^{inc} = " << inclusive.MPF_Result_FaceValue << " (stat) " << endl;
1534    
1535     float sysfinal = Reference.MPF_Result_FaceValue.getValue()/inclusive.MPF_Result_FaceValue.getValue();
1536     sysfinal *= sqrt(sys*sys/(Reference.MPF_Result_FaceValue.getValue()*Reference.MPF_Result_FaceValue.getValue()));
1537     //yes, this could be simplified but it would look like a bug.
1538    
1539 buchmann 1.20
1540    
1541    
1542     dout << "Note: Varying the alpha cut (->face value) we get the following results: " << endl;
1543     dout << "-30%: " << AlphaThresholdVariationDown30.MPF_Result_FaceValue/AlphaThresholdVariationDown30inc.MPF_Result_FaceValue << " (stat)" << endl;
1544     dout << "-10%: " << AlphaThresholdVariationDown10.MPF_Result_FaceValue/AlphaThresholdVariationDown10inc.MPF_Result_FaceValue << " (stat)" << endl;
1545     dout << " 0%: " << Reference.MPF_Result_FaceValue/inclusive.MPF_Result_FaceValue << " (stat) +/- " << endl;
1546     dout << "+10%: " << AlphaThresholdVariationUp10.MPF_Result_FaceValue/AlphaThresholdVariationUp10inc.MPF_Result_FaceValue << " (stat)" << endl;
1547     dout << "+30%: " << AlphaThresholdVariationUp30.MPF_Result_FaceValue/AlphaThresholdVariationUp30inc.MPF_Result_FaceValue << " (stat)" << endl;
1548    
1549     dout << " XCheck for Rabs, varying the alpha cut (->face value) we get the following results: " << endl;
1550     dout << " -30%: " << AlphaThresholdVariationDown30.Rabs_Result_FaceValue/AlphaThresholdVariationDown30inc.Rabs_Result_FaceValue << " (stat)" << endl;
1551     dout << " -10%: " << AlphaThresholdVariationDown10.Rabs_Result_FaceValue/AlphaThresholdVariationDown10inc.Rabs_Result_FaceValue << " (stat)" << endl;
1552     dout << " 0%: " << Reference.Rabs_Result_FaceValue/inclusive.Rabs_Result_FaceValue << " (stat) +/- " << endl;
1553     dout << " +10%: " << AlphaThresholdVariationUp10.Rabs_Result_FaceValue/AlphaThresholdVariationUp10inc.Rabs_Result_FaceValue << " (stat)" << endl;
1554     dout << " +30%: " << AlphaThresholdVariationUp30.Rabs_Result_FaceValue/AlphaThresholdVariationUp30inc.Rabs_Result_FaceValue << " (stat)" << endl;
1555    
1556    
1557     float sys_alphavar_up = abs(AlphaThresholdVariationUp30.MPF_Result_FaceValue.getValue()/AlphaThresholdVariationUp30inc.MPF_Result_FaceValue.getValue() - Reference.MPF_Result_FaceValue.getValue()/inclusive.MPF_Result_FaceValue.getValue());
1558     float sys_alphavar_down = abs(AlphaThresholdVariationDown30.MPF_Result_FaceValue.getValue()/AlphaThresholdVariationDown30inc.MPF_Result_FaceValue.getValue() - Reference.MPF_Result_FaceValue.getValue()/inclusive.MPF_Result_FaceValue.getValue());
1559     float sys_alphavar = sys_alphavar_up>sys_alphavar_down?sys_alphavar_up:sys_alphavar_down;
1560    
1561     dout << " -> Additional systematic (from 30%) : " << sys_alphavar << endl;
1562     sysfinal=sqrt(sysfinal*sysfinal+sys_alphavar*sys_alphavar);
1563     dout << "Final systematic is : " << sysfinal << endl;
1564    
1565     dout << " ******************************************** < FINAL RESULT > ******************************************** " << endl;
1566 buchmann 1.17 dout << " C_{corr} = " << Reference.MPF_Result_FaceValue/inclusive.MPF_Result_FaceValue << " (stat) +/- " << sysfinal << " (sys) " << endl;
1567 buchmann 1.20 dout << " ******************************************** < /FINAL RESULT > ******************************************** " << endl;
1568    
1569     dout << "Note that if L5 corrections are applied, we get " << L5Reference.MPF_Result_FaceValue/L5inclusive.MPF_Result_FaceValue << " (stat) " << endl;
1570 buchmann 1.16
1571 buchmann 1.19 LeadingB=TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898");
1572 buchmann 1.16
1573 buchmann 1.15 } else {
1574 buchmann 1.19 ZbResultContainer Reference = new_data_mc_agreement_2d(false,"ZbCHS3010_alpha","reference",TCut("ZbCHS3010_bTagProbCSVBP[0]>0.898"),TCut("ZbCHS3010_BTagWgtT"),0.3);
1575 buchmann 1.15 }
1576    
1577 buchmann 1.1
1578 buchmann 1.2 delete zbcanvas;
1579 buchmann 1.1 }
1580 buchmann 1.7
1581    
1582    
1583    
1584     //*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* DELETE EVERYTHING BELOW THIS LINE /*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*//
1585    
1586    
1587     const char* concatenate(string bla1, string bla2) {
1588     stringstream bla;
1589     bla << bla1 << bla2;
1590     return bla.str().c_str();
1591     }
1592    
1593     void SpecialCutFlow(string identifier) {
1594     stringstream MegaCut;
1595    
1596    
1597    
1598     MegaCut << " 1*(" << (const char*) (ZplusBsel&&TCut(concatenate(identifier,"_pfJetGoodNumBtag>0"))) << ")";
1599     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB) << ")";
1600     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB) << ")";
1601     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut) << ")";
1602 buchmann 1.19 MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000").c_str())) << ")";
1603     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.3").c_str())) << ")";
1604     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.2").c_str())) << ")";
1605     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.15").c_str())) << ")";
1606     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.1").c_str())) << ")";
1607     MegaCut << " + 1*(" << (const char*) (ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&TCut(((string)"pt>30&&pt<1000&&"+identifier+"_alpha<0.05").c_str())) << ")";
1608 buchmann 1.7 MegaCut << " ";
1609    
1610     TCanvas *can = new TCanvas("can","can");
1611     can->SetLogy(1);
1612 buchmann 1.9 TCut basecut(ZplusBsel);
1613 buchmann 1.7
1614    
1615    
1616     TLegend *leg = allsamples.allbglegend();
1617    
1618    
1619     TH1F *data = allsamples.Draw("data", MegaCut.str(),11,-0.5,10.5, "", "events", basecut,data,luminosity);
1620 buchmann 1.20 THStack mcm = allsamples.DrawStack("mc", MegaCut.str(),11,-0.5,10.5, "", "events", basecut,mc,luminosity);
1621 buchmann 1.7
1622     float runningsum=0;
1623     for(int i=data->GetNbinsX();i>0;i--) {
1624     runningsum+=data->GetBinContent(i);
1625     data->SetBinContent(i,runningsum);
1626     }
1627    
1628     float minimum=data->GetMaximum();
1629    
1630     TH1F* h;
1631     TIter nextOF(mcm.GetHists());
1632    
1633     float mcsum=0;
1634     float zb=0;
1635     while ( h = (TH1F*)nextOF() ) {
1636     float runningsum=0;
1637     minimum=data->GetMaximum();//done deliberately at each step so get the minimum of the last (!) contribution
1638     for(int i=h->GetNbinsX();i>0;i--) {
1639     runningsum+=h->GetBinContent(i);
1640     h->SetBinContent(i,runningsum);
1641     if(runningsum<minimum&&runningsum>0) minimum=runningsum;
1642     }
1643     if(Contains(h->GetName(),"Z_b_")) {
1644     zb=h->GetBinContent(h->GetNbinsX());
1645     }
1646     mcsum+=h->GetBinContent(h->GetNbinsX());
1647     }
1648    
1649    
1650    
1651     data->SetMinimum(0.05*minimum);
1652     can->cd(1)->SetBottomMargin(0.25);
1653     data->GetXaxis()->SetBinLabel(1,"Pre-selection");
1654     data->GetXaxis()->SetBinLabel(2,"Contains b jet");
1655     data->GetXaxis()->SetBinLabel(3,"Leading jet is b-jet");
1656     data->GetXaxis()->SetBinLabel(4,"|#eta_{b}|<1.3 ");
1657     data->GetXaxis()->SetBinLabel(5,"|#delta#phi(b,Z)|>2.7");
1658 buchmann 1.19 data->GetXaxis()->SetBinLabel(6,"30<p_{T}^{Z}<1000 GeV");
1659 buchmann 1.7 data->GetXaxis()->SetBinLabel(7,"#alpha < 0.3");
1660     data->GetXaxis()->SetBinLabel(8,"#alpha < 0.2");
1661     data->GetXaxis()->SetBinLabel(9,"#alpha < 0.15");
1662     data->GetXaxis()->SetBinLabel(10,"#alpha < 0.1");
1663     data->GetXaxis()->SetBinLabel(11,"#alpha < 0.05");
1664     data->GetXaxis()->LabelsOption("v");
1665    
1666     stringstream purityinfo;
1667     purityinfo << "Purity: " << std::setprecision(3) << 100*zb/mcsum << " %";
1668     stringstream neventsinfo;
1669     neventsinfo << "Nevents: " << data->GetBinContent(data->GetNbinsX());
1670     TH1F *crap = new TH1F("crap","",1,0,1);
1671     crap->SetLineColor(kWhite);
1672     leg->AddEntry(crap,purityinfo.str().c_str(),"l");
1673     leg->AddEntry(crap,neventsinfo.str().c_str(),"l");
1674    
1675     data->Draw("e1");
1676 buchmann 1.19 mcm.Draw("histo,same");
1677 buchmann 1.7 data->Draw("same,e1,axis");
1678     data->Draw("same,e1");
1679     // data->Draw("same,TEXT");
1680    
1681     leg->Draw();
1682    
1683     DrawPrelim();
1684    
1685     CompleteSave(can,"CutFlow___"+identifier);
1686    
1687     delete crap;
1688     delete data;
1689 buchmann 1.20 CleanLegends();
1690     DeleteStack(mcm);
1691    
1692 buchmann 1.7
1693     }