CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
heppy::BTagSF Class Reference

#include <BTagSF.h>

Inheritance diagram for heppy::BTagSF:
BTagSF.BTagSF

Public Types

enum  { kNo, kDown, kUp }
 

Public Member Functions

 BTagSF (int seed=0)
 
Double_t getMistag (Float_t pt, Float_t eta)
 
Double_t getSFb (Float_t pt, UInt_t btagsys, Bool_t is2012)
 
Double_t getSFc (Float_t pt, UInt_t btagsys, Bool_t is2012)
 
Double_t getSFl (Float_t pt, Float_t eta, UInt_t mistagsys, Bool_t is2012)
 
Bool_t isbtagged (Float_t pt, Float_t eta, Float_t csv, Int_t jetflavor, Bool_t isdata, UInt_t btagsys, UInt_t mistagsys, Bool_t is2012)
 
 ~BTagSF ()
 

Private Attributes

TRandom3 * randm
 

Detailed Description

Definition at line 9 of file BTagSF.h.

Member Enumeration Documentation

anonymous enum
Enumerator
kNo 
kDown 
kUp 

Definition at line 22 of file BTagSF.h.

22 { kNo, kDown, kUp }; // systematic variations

Constructor & Destructor Documentation

heppy::BTagSF::BTagSF ( int  seed = 0)

Definition at line 6 of file BTagSF.cc.

References randm.

6  {
7 
8  randm = new TRandom3(seed);
9 
10 }
TRandom3 * randm
Definition: BTagSF.h:27
heppy::BTagSF::~BTagSF ( )

Definition at line 12 of file BTagSF.cc.

References randm.

12  {
13 
14  delete randm;
15 
16 }
TRandom3 * randm
Definition: BTagSF.h:27

Member Function Documentation

Double_t heppy::BTagSF::getMistag ( Float_t  pt,
Float_t  eta 
)

Definition at line 252 of file BTagSF.cc.

References min(), and x().

Referenced by isbtagged().

253 {
254 
255  Float_t x = std::min(double(pt), 670.0);
256 
257  Double_t eff_l = 0.0;
258 
259  if(fabs(eta) >= 0.0 && fabs(eta) < 0.8) {
260  eff_l = ((0.00967751+(2.54564e-05*x))+(-6.92256e-10*(x*x)));
261  } else if(fabs(eta) >= 0.8 && fabs(eta) < 1.6) {
262  eff_l = ((0.00974141+(5.09503e-05*x))+(2.0641e-08*(x*x)));
263  } else if(fabs(eta) >= 1.6 && fabs(eta) < 2.4) {
264  eff_l = ((0.013595+(0.000104538*x))+(-1.36087e-08*(x*x)));
265  }
266 
267  return eff_l;
268 
269 }
T min(T a, T b)
Definition: MathUtil.h:58
Double_t heppy::BTagSF::getSFb ( Float_t  pt,
UInt_t  btagsys,
Bool_t  is2012 
)

Definition at line 96 of file BTagSF.cc.

References kDown, kNo, kUp, pileupCalc::nbins, EnergyCorrector::pt, and x().

Referenced by isbtagged().

97 {
98 
99  // pT dependent scale factors
100  // Tagger: CSVM within 30 < pt < 670 GeV, abs(eta) < 2.4, x = pt
101  // SFb = 0.6981*((1.+(0.414063*x))/(1.+(0.300155*x))); (2011)
102  // SFb = (0.938887+(0.00017124*x))+(-2.76366e-07*(x*x)); (2012)
103  // for pt > 670 (800) GeV: use the SFb value at 670 (800) GeV with twice the quoted uncertainty for 2011 (2012)
104  // for pt < 30 (20) GeV: use the SFb value at 30 (20) GeV with a +/-0.12 absolute uncertainty (twice the quoted uncertainty) for 2011 (2012)
105  // i.e SFb(pt<30) = SFb(pt=30) +/- 0.12, so the relative uncertainty is 0.12/SFb(pt=30) for 2011
106 
107  Float_t x = pt;
108  if(!is2012 && pt >= 670.0) x = 669.9;
109  if(!is2012 && pt < 30.0) x = 30.0;
110  if(is2012 && pt >= 800.0) x = 799.9;
111  if(is2012 && pt < 20.0) x = 20.0;
112 
113  Double_t SFb = 1.0;
114  if(!is2012) {
115  SFb = 0.6981*((1.+(0.414063*x))/(1.+(0.300155*x)));
116  } else {
117  SFb = (0.938887+(0.00017124*x))+(-2.76366e-07*(x*x));
118  }
119  if(btagsys == kNo) return SFb;
120 
121  Double_t SFb_error_2011[] = {0.0295675, 0.0295095, 0.0210867, 0.0219349, 0.0227033, 0.0204062, 0.0185857, 0.0256242, 0.0383341, 0.0409675, 0.0420284, 0.0541299, 0.0578761, 0.0655432};
122  Float_t ptmin_2011[] = {30, 40, 50, 60, 70, 80, 100, 120, 160, 210, 260, 320, 400, 500};
123  Float_t ptmax_2011[] = {40, 50, 60, 70, 80,100, 120, 160, 210, 260, 320, 400, 500, 670};
124  Double_t SFb_error_2012[] = {0.0415707, 0.0204209, 0.0223227, 0.0206655, 0.0199325, 0.0174121, 0.0202332, 0.0182446, 0.0159777, 0.0218531, 0.0204688, 0.0265191, 0.0313175, 0.0415417, 0.0740446, 0.0596716};
125  Float_t ptmin_2012[] = {20, 30, 40, 50, 60, 70, 80, 100, 120, 160, 210, 260, 320, 400, 500, 600};
126  Float_t ptmax_2012[] = {30, 40, 50, 60, 70, 80,100, 120, 160, 210, 260, 320, 400, 500, 600, 800};
127 
128  Double_t SFb_error_x = 0.0;
129 
130  UInt_t nbins = is2012 ? 16: 14;
131 
132  for (UInt_t ibin=0; ibin<nbins; ibin++) {
133  if(!is2012) {
134  if(x >= ptmin_2011[ibin] && x < ptmax_2011[ibin]) SFb_error_x = SFb_error_2011[ibin];
135  } else {
136  if(x >= ptmin_2012[ibin] && x < ptmax_2012[ibin]) SFb_error_x = SFb_error_2012[ibin];
137  }
138  }
139  if(!is2012) {
140  if(pt >= 670.0) SFb_error_x = 2.0*0.0655432;
141  if(pt < 30.0) SFb_error_x = 0.12;
142  } else {
143  if(pt >= 800.0) SFb_error_x = 2.0*0.0717567;
144  if(pt < 20.0) SFb_error_x = 2.0*0.0554504;
145  }
146 
147  Double_t scalefactor = SFb;
148 
149  if(btagsys == kDown) scalefactor = (SFb - SFb_error_x);
150  if(btagsys == kUp) scalefactor = (SFb + SFb_error_x);
151 
152  return scalefactor;
153 
154 }
Double_t heppy::BTagSF::getSFc ( Float_t  pt,
UInt_t  btagsys,
Bool_t  is2012 
)

Definition at line 156 of file BTagSF.cc.

References kDown, kNo, kUp, pileupCalc::nbins, EnergyCorrector::pt, and x().

Referenced by isbtagged().

157 {
158 
159  // SFc = SFb with twice the quoted uncertainty
160 
161  Float_t x = pt;
162  if(!is2012 && pt >= 670.0) x = 669.9;
163  if(!is2012 && pt < 30.0) x = 30.0;
164  if(is2012 && pt >= 800.0) x = 799.9;
165  if(is2012 && pt < 20.0) x = 20.0;
166 
167  Double_t SFc = 1.0;
168  if(!is2012) {
169  SFc = 0.6981*((1.+(0.414063*x))/(1.+(0.300155*x)));
170  } else {
171  SFc = (0.938887+(0.00017124*x))+(-2.76366e-07*(x*x));
172  }
173  if(btagsys == kNo) return SFc;
174 
175  Double_t SFb_error_2011[] = {0.0295675, 0.0295095, 0.0210867, 0.0219349, 0.0227033, 0.0204062, 0.0185857, 0.0256242, 0.0383341, 0.0409675, 0.0420284, 0.0541299, 0.0578761, 0.0655432};
176  Float_t ptmin_2011[] = {30, 40, 50, 60, 70, 80, 100, 120, 160, 210, 260, 320, 400, 500};
177  Float_t ptmax_2011[] = {40, 50, 60, 70, 80,100, 120, 160, 210, 260, 320, 400, 500, 670};
178  Double_t SFb_error_2012[] = {0.0415707, 0.0204209, 0.0223227, 0.0206655, 0.0199325, 0.0174121, 0.0202332, 0.0182446, 0.0159777, 0.0218531, 0.0204688, 0.0265191, 0.0313175, 0.0415417, 0.0740446, 0.0596716};
179  Float_t ptmin_2012[] = {20, 30, 40, 50, 60, 70, 80, 100, 120, 160, 210, 260, 320, 400, 500, 600};
180  Float_t ptmax_2012[] = {30, 40, 50, 60, 70, 80,100, 120, 160, 210, 260, 320, 400, 500, 600, 800};
181 
182  Double_t SFc_error_x = 0.0;
183 
184  UInt_t nbins = is2012 ? 16: 14;
185 
186  for (UInt_t ibin=0; ibin<nbins; ibin++) {
187  if(!is2012) {
188  if(x >= ptmin_2011[ibin] && x < ptmax_2011[ibin]) SFc_error_x = 2.0*SFb_error_2011[ibin];
189  } else {
190  if(x >= ptmin_2012[ibin] && x < ptmax_2012[ibin]) SFc_error_x = 2.0*SFb_error_2012[ibin];
191  }
192 
193  }
194  if(!is2012) {
195  if(pt >= 670.0) SFc_error_x = 2.0*2.0*0.0655432;
196  if(pt < 30.0) SFc_error_x = 2.0*0.12;
197  } else {
198  if(pt >= 800.0) SFc_error_x = 2.0*2.0*0.0717567;
199  if(pt < 20.0) SFc_error_x = 2.0*2.0*0.0554504;
200  }
201 
202  Double_t scalefactor = SFc;
203 
204  if(btagsys == kDown) scalefactor = (SFc - SFc_error_x);
205  if(btagsys == kUp) scalefactor = (SFc + SFc_error_x);
206 
207  return scalefactor;
208 
209 }
Double_t heppy::BTagSF::getSFl ( Float_t  pt,
Float_t  eta,
UInt_t  mistagsys,
Bool_t  is2012 
)

Definition at line 211 of file BTagSF.cc.

References alignCSCRings::e, kDown, kNo, kUp, min(), and x().

Referenced by isbtagged().

212 {
213 
214  Float_t x = std::min(double(pt), is2012 ? 670.0 : 800.0);
215 
216  Double_t SFl = 0;
217 
218  if(!is2012) {
219  if(fabs(eta) >= 0.0 && fabs(eta) < 0.8) {
220  if(mistagsys == kNo) SFl = ((1.06182+(0.000617034*x))+(-1.5732e-06*(x*x)))+(3.02909e-10*(x*(x*x)));
221  else if(mistagsys == kDown) SFl = ((0.972455+(7.51396e-06*x))+(4.91857e-07*(x*x)))+(-1.47661e-09*(x*(x*x)));
222  else if(mistagsys == kUp) SFl = ((1.15116+(0.00122657*x))+(-3.63826e-06*(x*x)))+(2.08242e-09*(x*(x*x)));
223  } else if(fabs(eta) >= 0.8 && fabs(eta) < 1.6) {
224  if(mistagsys == kNo) SFl = ((1.111+(-9.64191e-06*x))+(1.80811e-07*(x*x)))+(-5.44868e-10*(x*(x*x)));
225  else if(mistagsys == kDown) SFl = ((1.02055+(-0.000378856*x))+(1.49029e-06*(x*x)))+(-1.74966e-09*(x*(x*x)));
226  else if(mistagsys == kUp) SFl = ((1.20146+(0.000359543*x))+(-1.12866e-06*(x*x)))+(6.59918e-10*(x*(x*x)));
227  } else if(fabs(eta) >= 1.6 && fabs(eta) < 2.4) {
228  if(mistagsys == kNo) SFl = ((1.08498+(-0.000701422*x))+(3.43612e-06*(x*x)))+(-4.11794e-09*(x*(x*x)));
229  else if(mistagsys == kDown) SFl = ((0.983476+(-0.000607242*x))+(3.17997e-06*(x*x)))+(-4.01242e-09*(x*(x*x)));
230  else if(mistagsys == kUp) SFl = ((1.18654+(-0.000795808*x))+(3.69226e-06*(x*x)))+(-4.22347e-09*(x*(x*x)));
231  }
232  } else {
233  if(fabs(eta) >= 0.0 && fabs(eta) < 0.8) {
234  if(mistagsys == kNo) SFl = ((1.07541+(0.00231827*x))+(-4.74249e-06*(x*x)))+(2.70862e-09*(x*(x*x)));
235  else if(mistagsys == kDown) SFl = ((0.964527+(0.00149055*x))+(-2.78338e-06*(x*x)))+(1.51771e-09*(x*(x*x)));
236  else if(mistagsys == kUp) SFl = ((1.18638+(0.00314148*x))+(-6.68993e-06*(x*x)))+(3.89288e-09*(x*(x*x)));
237  } else if(fabs(eta) >= 0.8 && fabs(eta) < 1.6) {
238  if(mistagsys == kNo) SFl = ((1.05613+(0.00114031*x))+(-2.56066e-06*(x*x)))+(1.67792e-09*(x*(x*x)));
239  else if(mistagsys == kDown) SFl = ((0.946051+(0.000759584*x))+(-1.52491e-06*(x*x)))+(9.65822e-10*(x*(x*x)));
240  else if(mistagsys == kUp) SFl = ((1.16624+(0.00151884*x))+(-3.59041e-06*(x*x)))+(2.38681e-09*(x*(x*x)));
241  } else if(fabs(eta) >= 1.6 && fabs(eta) < 2.4) {
242  if(mistagsys == kNo) SFl = ((1.05625+(0.000487231*x))+(-2.22792e-06*(x*x)))+(1.70262e-09*(x*(x*x)));
243  else if(mistagsys == kDown) SFl = ((0.956736+(0.000280197*x))+(-1.42739e-06*(x*x)))+(1.0085e-09*(x*(x*x)));
244  else if(mistagsys == kUp) SFl = ((1.15575+(0.000693344*x))+(-3.02661e-06*(x*x)))+(2.39752e-09*(x*(x*x)));
245  }
246  }
247 
248  return SFl;
249 
250 }
T min(T a, T b)
Definition: MathUtil.h:58
Bool_t heppy::BTagSF::isbtagged ( Float_t  pt,
Float_t  eta,
Float_t  csv,
Int_t  jetflavor,
Bool_t  isdata,
UInt_t  btagsys,
UInt_t  mistagsys,
Bool_t  is2012 
)

Definition at line 19 of file BTagSF.cc.

References getMistag(), getSFb(), getSFc(), getSFl(), and randm.

20 {
21  randm->SetSeed((int)((eta+5)*100000));
22 
23  Bool_t btagged = kFALSE;
24 
25  if(isdata) {
26  if(csv>0.679) btagged = kTRUE;
27  else btagged = kFALSE;
28  return btagged;
29  }
30 
31  Double_t SFb = 0.0;
32  Double_t eff_b = 0.719;
33 
34  SFb = getSFb(pt, btagsys, is2012);
35 
36  Double_t promoteProb_btag=0; // ~probability to promote to tagged
37  Double_t demoteProb_btag=0; // ~probability to demote from tagged
38 
39  if(SFb < 1) {
40  demoteProb_btag = fabs(1.0 - SFb);
41  } else {
42  promoteProb_btag = fabs(SFb - 1.0)/((SFb/eff_b) - 1.0);
43  }
44 
45  if(fabs(jetflavor) == 5) { // real b-jet
46  if(csv > 0.679) { // if tagged
47  btagged = kTRUE;
48  if(demoteProb_btag > 0 && randm->Uniform() > demoteProb_btag) btagged = kTRUE; // leave it tagged
49  else btagged = kFALSE; // demote it to untagged
50  } else {
51  btagged = kFALSE;
52  if(promoteProb_btag > 0 && randm->Uniform() < promoteProb_btag) btagged = kTRUE; // promote it to tagged
53  else btagged = kFALSE; // leave it untagged
54  }
55  return btagged;
56  }
57 
58  // not a real b-jet, apply mistag
59 
60  Double_t SFl = 0, eff_l = 0;
61 
62  // c or light
63  if(fabs(jetflavor) == 4) {
64  // SFc = SFb with twice the quoted uncertainty
65  SFl = getSFc(pt, btagsys, is2012);
66  eff_l = 0.192*SFl; // eff_c in MC for CSVM = (-1.5734604211*x*x*x*x + 1.52798999269*x*x*x + 0.866697059943*x*x + -1.66657942274*x + 0.780639301724), x = 0.679
67  } else {
68  SFl = getSFl(pt, eta, mistagsys, is2012);
69  eff_l = getMistag(pt, eta);
70  }
71 
72  Double_t promoteProb_mistag=0; // ~probability to promote to tagged
73  Double_t demoteProb_mistag=0; // ~probability to demote from tagged
74 
75  if(SFl > 1) {
76  promoteProb_mistag = fabs(SFl - 1.0)/((SFl/eff_l) - 1.0);
77  }
78  else {
79  demoteProb_mistag = SFl;
80  }
81 
82  if(csv > 0.679) { // if tagged
83  btagged = kTRUE;
84  if(demoteProb_mistag > 0 && randm->Uniform() > demoteProb_mistag) btagged = kFALSE; // demote it to untagged
85  else btagged = kTRUE; // leave it tagged
86  }
87  else { // not tagged
88  btagged = kFALSE;
89  if(promoteProb_mistag > 0 && randm->Uniform() < promoteProb_mistag) btagged = kTRUE; // promote it to tagged
90  else btagged = kFALSE; // leave it untagged
91  }
92 
93  return btagged;
94 }
Double_t getSFc(Float_t pt, UInt_t btagsys, Bool_t is2012)
Definition: BTagSF.cc:156
Double_t getSFl(Float_t pt, Float_t eta, UInt_t mistagsys, Bool_t is2012)
Definition: BTagSF.cc:211
TRandom3 * randm
Definition: BTagSF.h:27
Double_t getMistag(Float_t pt, Float_t eta)
Definition: BTagSF.cc:252
Double_t getSFb(Float_t pt, UInt_t btagsys, Bool_t is2012)
Definition: BTagSF.cc:96

Member Data Documentation

TRandom3* heppy::BTagSF::randm
private

Definition at line 27 of file BTagSF.h.

Referenced by BTagSF(), isbtagged(), and ~BTagSF().