Rivet API documentation

Rivet 4.1.5
MomentumSmearingFunctions.hh
1// -*- C++ -*-
2#ifndef RIVET_MomentumSmearingFunctions_HH
3#define RIVET_MomentumSmearingFunctions_HH
4
5#include "Rivet/Math/Vector4.hh"
6#include "Rivet/Tools/Random.hh"
7
8namespace Rivet {
9
10
13
16
22 struct P4SmearParams {
23 P4SmearParams(const FourMomentum& p4nom,
24 double pres = 0.0,
25 double eres = 0.0,
26 double phires = 0.0,
27 double etares = 0.0)
28 : p4Nominal(p4nom),
29 pResolution(pres),
30 eResolution(eres),
31 phiResolution(phires),
32 etaResolution(etares) { }
33 FourMomentum p4Nominal;
34 double pResolution{0.0}, eResolution{0.0}, phiResolution{0.0}, etaResolution{0.0};
35 };
36
38 typedef std::function<FourMomentum(const FourMomentum&)> P4SmearFn;
39
41 typedef std::function<double(const FourMomentum&)> P4EffFn;
42
43
45 inline double P4_EFF_ZERO(const FourMomentum&) {
46 return 0;
47 }
48
50 inline double P4_EFF_ONE(const FourMomentum&) {
51 return 1;
52 }
53
55 struct P4_EFF_CONST {
56 P4_EFF_CONST(double x)
57 : _x(x) { }
58 double operator()(const FourMomentum&) const {
59 return _x;
60 }
61 double _x;
62 };
63
64
67 return p;
68 }
69
71 return p;
72 }
73
76 inline FourMomentum P4_SMEAR_E_GAUSS(const FourMomentum& p, double resolution) {
77 const double mass = p.mass2() > 0 ? p.mass() : 0; //< numerical carefulness...
78 const double smeared_E = max(randnorm(p.E(), resolution),
79 mass); //< can't let the energy go below the mass!
80 return FourMomentum::mkEtaPhiME(p.eta(), p.phi(), mass, smeared_E);
81 }
82
84 inline FourMomentum P4_SMEAR_PT_GAUSS(const FourMomentum& p, double resolution) {
85 const double smeared_pt = max(randnorm(p.pT(), resolution), 0.);
86 const double mass = p.mass2() > 0 ? p.mass() : 0; //< numerical carefulness...
87 return FourMomentum::mkEtaPhiMPt(p.eta(), p.phi(), mass, smeared_pt);
88 }
89
91 inline FourMomentum P4_SMEAR_MASS_GAUSS(const FourMomentum& p, double resolution) {
92 const double smeared_mass = max(randnorm(p.mass(), resolution), 0.);
93 return FourMomentum::mkEtaPhiMPt(p.eta(), p.phi(), smeared_mass, p.pT());
94 }
95
97
99
100
103
105 inline double P3_EFF_ZERO(const Vector3&) {
106 return 0;
107 }
108
110 inline double P3_EFF_ONE(const Vector3&) {
111 return 1;
112 }
113
115 struct P3_EFF_CONST {
116 P3_EFF_CONST(double x)
117 : _x(x) { }
118 double operator()(const Vector3&) const {
119 return _x;
120 }
121 double _x;
122 };
123
124
127 return p;
128 }
129
131 return p;
132 }
133
135 inline Vector3 P3_SMEAR_LEN_GAUSS(const Vector3& p, double resolution) {
136 const double smeared_mod = max(randnorm(p.mod(), resolution),
137 0.); //< can't let the energy go below the mass!
138 return smeared_mod * p.unit();
139 }
140
142
143
146
152 struct METSmearParams {
153 METSmearParams(const Vector3& vmetnom, double pres = 0.0, double phires = 0.0)
154 : vmetNominal(vmetnom), pResolution(pres), phiResolution(phires) { }
155 Vector3 vmetNominal;
156 double pResolution{0.0}, phiResolution{0.0};
157 };
158
165 typedef function<METSmearParams(const Vector3&, double)> METSmearParamsFn;
166
170 typedef function<Vector3(const Vector3&, double)> METSmearFn;
171
172
188 const Vector3& vmet = msps.vmetNominal;
189 // MET magnitude smear
190 // const double metsmear = max(randnorm(vmet.mod(), resolution), 0.); //< make peak at 0
191 const double metsmear = (msps.pResolution > 0) ? fabs(randnorm(vmet.mod(), msps.pResolution))
192 : vmet.mod(); //< "reflect" at 0
193 // MET phi-angle smearing matrix
194 const double dphi = (msps.phiResolution > 0) ? randnorm(0.0, msps.phiResolution) : 0.0;
195 const Matrix3 phismear = Matrix3::mkZRotation(dphi);
196 // Apply smearings
197 return metsmear * phismear * vmet.unit();
198 }
199
200
206 return METSmearParams(met, 0.0, 0.0);
207 }
208
210 inline Vector3 MET_SMEAR_IDENTITY(const Vector3& met, double) {
211 return met;
212 }
213
215
217
218}
219
220#endif
Specialized version of the FourVector with momentum/energy functionality.
Definition Vector4.hh:363
static FourMomentum mkEtaPhiME(double eta, double phi, double mass, double E)
Make a vector from (eta,phi,energy) coordinates and the mass.
Definition Vector4.hh:814
static FourMomentum mkEtaPhiMPt(double eta, double phi, double mass, double pt)
Make a vector from (eta,phi,pT) coordinates and the mass.
Definition Vector4.hh:819
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition Matrix3.hh:13
Three-dimensional specialisation of Vector.
Definition Vector3.hh:39
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:154
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:99
double mass(const FourMomentum &a, const FourMomentum &b)
Calculate mass of two 4-vectors.
Definition Vector4.hh:1474
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
Vector3 MET_SMEAR_IDENTITY(const Vector3 &met, double)
Identity MET smearing just returns the input.
Definition MomentumSmearingFunctions.hh:210
METSmearParams MET_SMEARPARAMS_IDENTITY(const Vector3 &met, double)
Identity resolution is 0 (perfect delta function, no offset).
Definition MomentumSmearingFunctions.hh:205
function< Vector3(const Vector3 &, double)> METSmearFn
Definition MomentumSmearingFunctions.hh:170
function< METSmearParams(const Vector3 &, double)> METSmearParamsFn
Definition MomentumSmearingFunctions.hh:165
Vector3 MET_SMEAR_NORM(const METSmearParams &msps)
Smear a nominal vector magnitude by Gaussian with the given absolute resolutions.
Definition MomentumSmearingFunctions.hh:187
std::function< double(const FourMomentum &)> P4EffFn
Typedef for FourMomentum efficiency functions/functors.
Definition MomentumSmearingFunctions.hh:41
double P4_EFF_ONE(const FourMomentum &)
Take a FourMomentum and return 1.
Definition MomentumSmearingFunctions.hh:50
FourMomentum P4_SMEAR_IDENTITY(const FourMomentum &p)
Take a FourMomentum and return it unmodified.
Definition MomentumSmearingFunctions.hh:66
FourMomentum P4_SMEAR_E_GAUSS(const FourMomentum &p, double resolution)
Definition MomentumSmearingFunctions.hh:76
Vector3 P3_SMEAR_PERFECT(const Vector3 &p)
Alias for P3_SMEAR_IDENTITY.
Definition MomentumSmearingFunctions.hh:130
FourMomentum P4_SMEAR_PERFECT(const FourMomentum &p)
Alias for P4_SMEAR_IDENTITY.
Definition MomentumSmearingFunctions.hh:70
Vector3 P3_SMEAR_IDENTITY(const Vector3 &p)
Take a Vector3 and return it unmodified.
Definition MomentumSmearingFunctions.hh:126
double P3_EFF_ZERO(const Vector3 &)
Take a Vector3 and return 0.
Definition MomentumSmearingFunctions.hh:105
FourMomentum P4_SMEAR_MASS_GAUSS(const FourMomentum &p, double resolution)
Smear a FourMomentum's mass using a Gaussian of absolute width resolution.
Definition MomentumSmearingFunctions.hh:91
std::function< FourMomentum(const FourMomentum &)> P4SmearFn
Typedef for FourMomentum smearing functions/functors.
Definition MomentumSmearingFunctions.hh:38
double P4_EFF_ZERO(const FourMomentum &)
Take a FourMomentum and return 0.
Definition MomentumSmearingFunctions.hh:45
Vector3 P3_SMEAR_LEN_GAUSS(const Vector3 &p, double resolution)
Smear a Vector3's length using a Gaussian of absolute width resolution.
Definition MomentumSmearingFunctions.hh:135
double P3_EFF_ONE(const Vector3 &)
Take a Vector3 and return 1.
Definition MomentumSmearingFunctions.hh:110
FourMomentum P4_SMEAR_PT_GAUSS(const FourMomentum &p, double resolution)
Smear a FourMomentum's transverse momentum using a Gaussian of absolute width resolution.
Definition MomentumSmearingFunctions.hh:84
Definition LHCbCommon.hh:9
std::enable_if_t< std::is_arithmetic_v< N1 > &&std::is_arithmetic_v< N2 >, signed_if_mixed_t< N1, N2 > > max(N1 a, N2 b)
Get the maximum of two numbers.
Definition MathUtils.hh:124
double randnorm(double loc, double scale)
Return a random number sampled from a Gaussian/normal distribution.
Struct for holding MET-smearing parameters.
Definition MomentumSmearingFunctions.hh:152