Rivet API documentation

Rivet 4.1.3
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(pres),
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
98
101
103 inline double P3_EFF_ZERO(const Vector3&) {
104 return 0;
105 }
106
108 inline double P3_EFF_ONE(const Vector3&) {
109 return 1;
110 }
111
113 struct P3_EFF_CONST {
114 P3_EFF_CONST(double x)
115 : _x(x) { }
116 double operator()(const Vector3&) const {
117 return _x;
118 }
119 double _x;
120 };
121
122
125 return p;
126 }
127
129 return p;
130 }
131
133 inline Vector3 P3_SMEAR_LEN_GAUSS(const Vector3& p, double resolution) {
134 const double smeared_mod = max(randnorm(p.mod(), resolution),
135 0.); //< can't let the energy go below the mass!
136 return smeared_mod * p.unit();
137 }
138
140
141
144
150 struct METSmearParams {
151 METSmearParams(const Vector3& vmetnom, double pres = 0.0, double phires = 0.0)
152 : vmetNominal(vmetnom), pResolution(pres), phiResolution(phires) { }
153 Vector3 vmetNominal;
154 double pResolution{0.0}, phiResolution{0.0};
155 };
156
163 typedef function<METSmearParams(const Vector3&, double)> METSmearParamsFn;
164
168 typedef function<Vector3(const Vector3&, double)> METSmearFn;
169
170
186 const Vector3& vmet = msps.vmetNominal;
187 // MET magnitude smear
188 // const double metsmear = max(randnorm(vmet.mod(), resolution), 0.); //< make peak at 0
189 const double metsmear = fabs(randnorm(vmet.mod(), msps.pResolution)); //< "reflect" at 0
190 // MET phi-angle smearing matrix
191 const Matrix3 phismear = Matrix3::mkZRotation(randnorm(0.0, msps.phiResolution));
192 // Apply smearings
193 return metsmear * phismear * vmet.unit();
194 }
195
196
202 return METSmearParams(met, 0.0, 0.0);
203 }
204
206 inline Vector3 MET_SMEAR_IDENTITY(const Vector3& met, double) {
207 return met;
208 }
209
211
213
214}
215
216#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:206
METSmearParams MET_SMEARPARAMS_IDENTITY(const Vector3 &met, double)
Identity resolution is 0 (perfect delta function, no offset).
Definition MomentumSmearingFunctions.hh:201
function< Vector3(const Vector3 &, double)> METSmearFn
Definition MomentumSmearingFunctions.hh:168
function< METSmearParams(const Vector3 &, double)> METSmearParamsFn
Definition MomentumSmearingFunctions.hh:163
Vector3 MET_SMEAR_NORM(const METSmearParams &msps)
Smear a nominal vector magnitude by Gaussian with the given absolute resolutions.
Definition MomentumSmearingFunctions.hh:185
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:128
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:124
double P3_EFF_ZERO(const Vector3 &)
Take a Vector3 and return 0.
Definition MomentumSmearingFunctions.hh:103
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:133
double P3_EFF_ONE(const Vector3 &)
Take a Vector3 and return 1.
Definition MomentumSmearingFunctions.hh:108
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:150