ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ZbTools.C
Revision: 1.19
Committed: Mon Jan 7 14:42:35 2013 UTC (12 years, 4 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.18: +504 -433 lines
Log Message:
Applied Z momentum cut (at 30 GeV) consistently; updated scenario comparison; updated fitting procedure (now possible to switch it off); added possibility of several variations

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