Rivet API documentation

Rivet 4.1.3
SmearedMET.hh
1// -*- C++ -*-
2#ifndef RIVET_SmearedMET_HH
3#define RIVET_SmearedMET_HH
4
5#include "Rivet/Projection.hh"
6#include "Rivet/Projections/METFinder.hh"
7#include "Rivet/Projections/MissingMomentum.hh"
8#include "Rivet/Tools/SmearingFunctions.hh"
9#include <functional>
10
11namespace Rivet {
12
13
15 class SmearedMET : public METFinder {
16 public:
17
20
24 template <
25 typename SMEARPARAMSFN,
26 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>,
27 int> = 0>
28 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn)
29 : _metSmearParamsFn(metSmearParamsFn),
30 _metSmearFn(nullptr)
31 // _metSmearFn([&](const Vector3& met, double set) -> Vector3 {
32 // const METSmearParams msps = metSmearParamsFn(met, set);
33 // return MET_SMEAR_NORM(msps);
34 // })
35 {
36 setName("SmearedMET");
37 declare(mm, "TruthMET");
38 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
39 }
40
44 template <
45 typename SMEARPARAMSFN,
46 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>,
47 int> = 0>
48 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const Cut& cut = Cuts::OPEN)
49 : SmearedMET(MissingMomentum(cut), metSmearParamsFn) { }
50
54 template <
55 typename SMEARFN,
56 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
57 SmearedMET(const MissingMomentum& mm, const SMEARFN& metSmearFn)
58 : _metSmearParamsFn(nullptr), _metSmearFn(metSmearFn) {
59 setName("SmearedMET");
60 declare(mm, "TruthMET");
61 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
62 }
63
67 template <
68 typename SMEARFN,
69 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
70 SmearedMET(const SMEARFN& metSmearFn, const Cut& cut = Cuts::OPEN)
71 : SmearedMET(MissingMomentum(cut), metSmearFn) { }
72
78 template <typename SMEARPARAMSFN,
79 typename SMEARFN,
80 typename std::enable_if_t<
81 is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>
82 && is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>,
83 int> = 0>
84 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn)
85 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(metSmearFn) {
86 setName("SmearedMET");
87 declare(mm, "TruthMET");
88 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
89 }
90
96 template <typename SMEARPARAMSFN,
97 typename SMEARFN,
98 typename std::enable_if_t<
99 is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>
100 && is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>,
101 int> = 0>
102 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn, const Cut& cut = Cuts::OPEN)
103 : SmearedMET(MissingMomentum(cut), metSmearParamsFn, metSmearFn) { }
104
105
108
110
112 using Projection::operator=;
113
114
116 CmpState compare(const Projection& p) const {
117 // const SmearedMET& other = dynamic_cast<const SmearedMET&>(p);
118 // if (get_address(_metSmearParamsFn) == 0) return cmp((size_t)this, (size_t)&p);
119 // if (get_address(_metSmearFn) == 0) return cmp((size_t)this, (size_t)&p);
120 // MSG_TRACE("Smear hashes (params) = " << get_address(_metSmearParamsFn) << "," << get_address(other._metSmearParamsFn));
121 // MSG_TRACE("Smear hashes (smear) = " << get_address(_metSmearFn) << "," << get_address(other._metSmearFn));
122 // return mkPCmp(other, "TruthMET") ||
123 // cmp(get_address(_metSmearParamsFn), get_address(other._metSmearParamsFn));
124 // cmp(get_address(_metSmearFn), get_address(other._metSmearFn));
125 if (_noSmear) return CmpState::EQ;
126 return CmpState::UNDEF;
127 }
128
129
131 void project(const Event& e) {
132 const METFinder& mm = apply<MissingMomentum>(e, "TruthMET");
133 _spt = mm.scalarPt();
134 _set = mm.scalarEt();
135 _vpt = mm.vectorPt();
136 _vet = mm.vectorEt();
137
138 // Short-circuit if smearing is disabled
139 if (_noSmear) return;
140
141 if (_metSmearFn) {
142 _vpt = _metSmearFn(_vpt, _spt); //< custom smearing
143 _vet = _metSmearFn(_vet, _set); //< custom smearing
144 }
145 else if (_metSmearParamsFn) {
146 const METSmearParams msps_p = _metSmearParamsFn(
147 _vpt,
148 _set); //< custom smear params: note still calibrated wrt SET, not SPT
149 _vpt = MET_SMEAR_NORM(msps_p); //< normal-distribution smearing from custom params
150 const METSmearParams msps_e = _metSmearParamsFn(_vet, _set); //< custom smear params
151 _vet = MET_SMEAR_NORM(msps_e); //< normal-distribution smearing from custom params
152 }
153 else {
154 throw SmearError("Attempt to smear MPT and MET with neither a smearing function nor a "
155 "smearing-params function set");
156 }
157 }
158
159
167
169 const Vector3& vectorSumPt() const {
170 return _vpt;
171 }
172
174 double scalarSumPt() const {
175 return _spt;
176 }
177
179 double missingPtResolution() const {
180 if (!_metSmearParamsFn)
181 throw UserError("Trying to compute MPT significance without a registered significance function");
182 METSmearParams msps = _metSmearParamsFn(vectorPt(), scalarPt());
183 return msps.pResolution;
184 }
185
187 double missingPtSignf() const {
188 return missingPt() / missingPtResolution();
189 }
190
192
193
201
205 const Vector3& vectorSumEt() const {
206 return _vet;
207 }
208
210 double scalarSumEt() const {
211 return _set;
212 }
213
215 double missingEtResolution() const {
216 if (!_metSmearParamsFn)
217 throw UserError("Trying to compute MET significance without a registered significance function");
218 METSmearParams msps = _metSmearParamsFn(vectorEt(), scalarEt());
219 //return max(msps.eResolution, msps.pResolution);
220 return msps.pResolution; //< @todo Check?
221 }
222
224 double missingEtSignf() const {
225 return missingEt() / missingEtResolution();
226 }
227
229
230
232 void reset() { }
233
234
235 protected:
236
237 Vector3 _vpt, _vet;
238 double _spt, _set;
239
241 METSmearParamsFn _metSmearParamsFn;
242
244 METSmearFn _metSmearFn;
245
249 bool _noSmear{false};
250 };
251
252
253}
254
255#endif
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Interface for projections that find missing transverse energy/momentum.
Definition METFinder.hh:11
double missingPt() const
The vector-summed missing transverse momentum in the event.
Definition METFinder.hh:46
double scalarPt() const
Alias for scalarSumPt.
Definition METFinder.hh:65
virtual const Vector3 & vectorEt() const
Alias for vectorSumEt.
Definition METFinder.hh:86
double scalarEt() const
Alias for scalarSumEt.
Definition METFinder.hh:123
virtual const Vector3 & vectorPt() const
Alias for vectorSumPt.
Definition METFinder.hh:28
double missingEt() const
The vector-summed missing transverse energy in the event.
Definition METFinder.hh:104
Calculate missing , etc. as complements to the total visible momentum.
Definition MissingMomentum.hh:22
std::enable_if_t< std::is_base_of< Projection, PROJ >::value, const PROJ & > apply(const Event &evt, const Projection &proj) const
Apply the supplied projection on event evt.
Definition ProjectionApplier.hh:124
const PROJ & declare(const PROJ &proj, const std::string &name) const
Register a contained projection (user-facing version).
Definition ProjectionApplier.hh:205
Base class for all Rivet projections.
Definition Projection.hh:29
void setName(const std::string &name)
Used by derived classes to set their name.
Definition Projection.hh:146
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedMET.hh:232
SmearedMET(const SMEARPARAMSFN &metSmearParamsFn, const SMEARFN &metSmearFn, const Cut &cut=Cuts::OPEN)
Constructor from a Cut (on the particles used to determine missing momentum) and a pair of smearing (...
Definition SmearedMET.hh:102
double missingPtSignf() const
Obtain an approximation to the MPT significance (value/resolution) for this event.
Definition SmearedMET.hh:187
double scalarSumEt() const
The scalar-summed visible transverse energy in the event.
Definition SmearedMET.hh:210
double missingPtResolution() const
Obtain an approximation to the MPT resolution for this event.
Definition SmearedMET.hh:179
SmearedMET(const MissingMomentum &mm, const SMEARFN &metSmearFn)
Constructor from a MissingMomentum projection and a smearing function.
Definition SmearedMET.hh:57
SmearedMET(const MissingMomentum &mm, const SMEARPARAMSFN &metSmearParamsFn)
Constructor from a MissingMomentum projection and a smearing-params function.
Definition SmearedMET.hh:28
SmearedMET(const MissingMomentum &mm, const SMEARPARAMSFN &metSmearParamsFn, const SMEARFN &metSmearFn)
Constructor from a MissingMomentum projection and a pair of smearing-params and smearing functions.
Definition SmearedMET.hh:84
RIVET_DEFAULT_PROJ_CLONE(SmearedMET)
Clone on the heap.
SmearedMET(const SMEARPARAMSFN &metSmearParamsFn, const Cut &cut=Cuts::OPEN)
Constructor from a Cut (on the particles used to determine missing momentum) and a smearing-params fu...
Definition SmearedMET.hh:48
void project(const Event &e)
Perform the MET finding & smearing calculation.
Definition SmearedMET.hh:131
double missingEtResolution() const
Obtain an approximation to the MET resolution for this event.
Definition SmearedMET.hh:215
SmearedMET(const SMEARFN &metSmearFn, const Cut &cut=Cuts::OPEN)
Constructor from a Cut (on the particles used to determine missing momentum) and a smearing function.
Definition SmearedMET.hh:70
const Vector3 & vectorSumPt() const
The vector-summed visible transverse momentum in the event, as a 3-vector with z=0.
Definition SmearedMET.hh:169
const Vector3 & vectorSumEt() const
Definition SmearedMET.hh:205
double missingEtSignf() const
Obtain an approximation to the MET significance (value/resolution) for this event.
Definition SmearedMET.hh:224
CmpState compare(const Projection &p) const
Compare to another SmearedMET.
Definition SmearedMET.hh:116
double scalarSumPt() const
The scalar-summed visible transverse momentum in the event.
Definition SmearedMET.hh:174
Three-dimensional specialisation of Vector.
Definition Vector3.hh:39
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
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
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:921
Definition LHCbCommon.hh:9
Struct for holding MET-smearing parameters.
Definition MomentumSmearingFunctions.hh:150
Error specialisation for failures relating to event smearing.
Definition Exceptions.hh:58
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:75