ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ZbTools.C
Revision: 1.26
Committed: Mon Mar 18 16:05:04 2013 UTC (12 years, 1 month ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.25: +163 -105 lines
Log Message:
Replaced cout's by dout's (i.e. writing a lot more information to the log file); Changed the way the fit error band is computed (PandiTools); added possibility to define global lower and upper range boundaries; improved printing of results; improved roofit plots (so they're similar to the standard ones); added a lot more bins for roofit so the fit has more information

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