Rivet API documentation

Rivet 4.1.5
JetSmearingFunctions.hh
1// -*- C++ -*-
2#ifndef RIVET_JetSmearingFunctions_HH
3#define RIVET_JetSmearingFunctions_HH
4
5#include "Rivet/Jet.hh"
6#include "Rivet/Tools/MomentumSmearingFunctions.hh"
7#include "Rivet/Tools/ParticleSmearingFunctions.hh"
8#include "Rivet/Tools/Random.hh"
9
10namespace Rivet {
11
12
15
18
20 typedef function<Jet(const Jet&)> JetSmearFn;
21
23 typedef function<double(const Jet&)> JetEffFn;
24
25
27 inline double JET_EFF_ZERO(const Jet&) {
28 return 0;
29 }
30
31 inline double JET_EFF_0(const Jet&) {
32 return 0;
33 }
34
35 inline double JET_FN0(const Jet&) {
36 return 0;
37 }
38
40 inline double JET_EFF_ONE(const Jet&) {
41 return 1;
42 }
43
44 inline double JET_EFF_1(const Jet&) {
45 return 1;
46 }
47
48 inline double JET_EFF_PERFECT(const Jet&) {
49 return 1;
50 }
51
52 inline double JET_EFF_IDENTITY(const Jet&) {
53 return 1;
54 }
55
56 inline double JET_FN1(const Jet&) {
57 return 1;
58 }
59
61 struct JET_EFF_CONST {
62 JET_EFF_CONST(double eff)
63 : _eff(eff) { }
64 double operator()(const Jet&) const {
65 return _eff;
66 }
67 double _eff;
68 };
69
71 struct JET_EFF_PRODUCT {
72 template <typename... FNS>
73 JET_EFF_PRODUCT(const FNS&... fns)
74 : _fns{JetEffFn(fns)...} { }
75 double operator()(const Jet& j) const {
76 double eff = 1;
77 for (const JetEffFn& fn : _fns) eff *= fn(j);
78 return eff;
79 }
80 vector<JetEffFn> _fns;
81 };
82
83
87 inline double JET_BTAG_PERFECT(const Jet& j) {
88 return j.bTagged() ? 1 : 0;
89 }
90
91 inline double JET_BTAG_IDENTITY(const Jet& j) {
92 return JET_BTAG_PERFECT(j);
93 }
94
98 inline double JET_CTAG_PERFECT(const Jet& j) {
99 return j.cTagged() ? 1 : 0;
100 }
101
102 inline double JET_CTAG_IDENTITY(const Jet& j) {
103 return JET_CTAG_PERFECT(j);
104 }
105
109 inline double JET_TAUTAG_PERFECT(const Jet& j) {
110 return j.tauTagged() ? 1 : 0;
111 }
112
113 inline double JET_TAUTAG_IDENTITY(const Jet& j) {
114 return JET_TAUTAG_PERFECT(j);
115 }
116
117
121 struct JET_BTAG_EFFS {
122 JET_BTAG_EFFS(double eff_b, double eff_light = 0)
123 : _eff_b(eff_b), _eff_c(-1), _eff_t(-1), _eff_l(eff_light) { }
124 JET_BTAG_EFFS(double eff_b, double eff_c, double eff_light)
125 : _eff_b(eff_b), _eff_c(eff_c), _eff_t(-1), _eff_l(eff_light) { }
126 JET_BTAG_EFFS(double eff_b, double eff_c, double eff_tau, double eff_light)
127 : _eff_b(eff_b), _eff_c(eff_c), _eff_t(eff_tau), _eff_l(eff_light) { }
128 inline double operator()(const Jet& j) {
129 if (j.bTagged()) return _eff_b;
130 if (_eff_c >= 0 && j.cTagged()) return _eff_c;
131 if (_eff_t >= 0 && j.tauTagged()) return _eff_t;
132 return _eff_l;
133 }
134 double _eff_b, _eff_c, _eff_t, _eff_l;
135 };
136
137
141 inline Jet JET_SMEAR_IDENTITY(const Jet& j) {
142 return j;
143 }
144
145 inline Jet JET_SMEAR_PERFECT(const Jet& j) {
146 return j;
147 }
148
152
153
159 struct JetEffSmearFn {
160 JetEffSmearFn(const JetSmearFn& s, const JetEffFn& e)
161 : sfn(s), efn(e) { }
162
163 JetEffSmearFn(const JetEffFn& e, const JetSmearFn& s)
164 : sfn(s), efn(e) { }
165
166 JetEffSmearFn(const JetSmearFn& s)
167 : sfn(s), efn(JET_EFF_ONE) { }
168
169 JetEffSmearFn(const JetEffFn& e)
170 : sfn(JET_SMEAR_IDENTITY), efn(e) { }
171
172 JetEffSmearFn(double eff)
173 : JetEffSmearFn(JET_EFF_CONST(eff)) { }
174
176 pair<Jet, double> operator()(const Jet& j) const {
177 return make_pair(sfn(j), efn(j));
178 }
179
181 CmpState cmp(const JetEffSmearFn& other) const {
182 // cout << "Eff hashes = " << get_address(efn) << "," << get_address(other.efn) << "; "
183 // << "smear hashes = " << get_address(sfn) << "," << get_address(other.sfn) << '\n';
184 if (get_address(sfn) == 0 || get_address(other.sfn) == 0) return CmpState::NEQ;
185 if (get_address(efn) == 0 || get_address(other.efn) == 0) return CmpState::NEQ;
186 return Rivet::cmp(get_address(sfn), get_address(other.sfn))
187 || Rivet::cmp(get_address(efn), get_address(other.efn));
188 }
189
191 operator JetSmearFn() {
192 return sfn;
193 }
194
196 // operator JetEffFn () { return efn; }
197
198 // Stored functions/functors
200 JetEffFn efn;
201 };
202
203
205 template <typename FN>
206 inline bool efffilt(const Jet& j, FN& feff) {
207 return rand01() < feff(j);
208 }
209
211 struct JetEffFilter {
212 template <typename FN>
213 JetEffFilter(const FN& feff)
214 : _feff(feff) { }
215 JetEffFilter(double eff)
216 : JetEffFilter([&](const Jet&) { return eff; }) { }
217 bool operator()(const Jet& j) const {
218 return efffilt(j, _feff);
219 }
220
221 private:
222
223 const JetEffFn _feff;
224 };
225 using jetEffFilter = JetEffFilter;
226
228
230
231}
232
233#endif
Representation of a clustered jet of particles.
Definition Jet.hh:47
bool cTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one c-tag? (with optional Cut and dR restriction).
Definition Jet.hh:217
bool tauTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one tau-tag (with optional Cut and dR restriction).
Definition Jet.hh:246
bool bTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one b-tag? (with optional Cut and dR restriction).
Definition Jet.hh:188
double JET_CTAG_PERFECT(const Jet &j)
Return 1 if the given Jet contains a c, otherwise 0.
Definition JetSmearingFunctions.hh:98
double JET_EFF_ONE(const Jet &)
Take a jet and return a constant 1.
Definition JetSmearingFunctions.hh:40
double JET_EFF_0(const Jet &)
Alias for JET_EFF_ZERO.
Definition JetSmearingFunctions.hh:31
double JET_EFF_1(const Jet &)
Alias for JET_EFF_ONE.
Definition JetSmearingFunctions.hh:44
double JET_TAUTAG_IDENTITY(const Jet &j)
Alias for JET_TAUTAG_PERFECT.
Definition JetSmearingFunctions.hh:113
double JET_TAUTAG_PERFECT(const Jet &j)
Return 1 if the given Jet contains a c, otherwise 0.
Definition JetSmearingFunctions.hh:109
double JET_BTAG_PERFECT(const Jet &j)
Return 1 if the given Jet contains a b, otherwise 0.
Definition JetSmearingFunctions.hh:87
Jet JET_SMEAR_PERFECT(const Jet &j)
Alias for JET_SMEAR_IDENTITY.
Definition JetSmearingFunctions.hh:145
double JET_CTAG_IDENTITY(const Jet &j)
Alias for JET_CTAG_PERFECT.
Definition JetSmearingFunctions.hh:102
double JET_BTAG_IDENTITY(const Jet &j)
Alias for JET_BTAG_PERFECT.
Definition JetSmearingFunctions.hh:91
double JET_FN1(const Jet &)
Alias for JET_EFF_ONE.
Definition JetSmearingFunctions.hh:56
Jet JET_SMEAR_IDENTITY(const Jet &j)
Definition JetSmearingFunctions.hh:141
function< Jet(const Jet &)> JetSmearFn
Typedef for Jet smearing functions/functors.
Definition JetSmearingFunctions.hh:20
double JET_FN0(const Jet &)
Alias for JET_EFF_ZERO.
Definition JetSmearingFunctions.hh:35
double JET_EFF_IDENTITY(const Jet &)
Alias for JET_EFF_ONE.
Definition JetSmearingFunctions.hh:52
bool efffilt(const Jet &j, FN &feff)
Return true if Jet j is chosen to survive a random efficiency selection.
Definition JetSmearingFunctions.hh:206
double JET_EFF_ZERO(const Jet &)
Take a jet and return a constant 0.
Definition JetSmearingFunctions.hh:27
function< double(const Jet &)> JetEffFn
Typedef for Jet efficiency functions/functors.
Definition JetSmearingFunctions.hh:23
double JET_EFF_PERFECT(const Jet &)
Alias for JET_EFF_ONE.
Definition JetSmearingFunctions.hh:48
Definition LHCbCommon.hh:9
double rand01()
Return a uniformly sampled random number between 0 and 1.
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition Cmp.hh:253
uintptr_t get_address(std::function< T(U...)> f)
Get a function pointer / hash integer from an std::function.
Definition RivetSTL.hh:338
Take a Jet and return a constant efficiency.
Definition JetSmearingFunctions.hh:61
A functor to return true if Jet j survives a random efficiency selection.
Definition JetSmearingFunctions.hh:211
CmpState cmp(const JetEffSmearFn &other) const
Compare to another, for use in the projection system.
Definition JetSmearingFunctions.hh:181
JetSmearFn sfn
Definition JetSmearingFunctions.hh:199
pair< Jet, double > operator()(const Jet &j) const
Smear and calculate an efficiency for the given jet.
Definition JetSmearingFunctions.hh:176