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<typename SMEARPARAMSFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
25 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn)
26 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(nullptr)
27 // _metSmearFn([&](const Vector3& met, double set) -> Vector3 {
28 // const METSmearParams msps = metSmearParamsFn(met, set);
29 // return MET_SMEAR_NORM(msps);
30 // })
31 {
32 setName("SmearedMET");
33 declare(mm, "TruthMET");
34 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
35 }
36
40 template<typename SMEARPARAMSFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
41 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const Cut& cut=Cuts::OPEN)
42 : SmearedMET(MissingMomentum(cut), metSmearParamsFn)
43 { }
44
48 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
49 SmearedMET(const MissingMomentum& mm, const SMEARFN& metSmearFn)
50 : _metSmearParamsFn(nullptr), _metSmearFn(metSmearFn)
51 {
52 setName("SmearedMET");
53 declare(mm, "TruthMET");
54 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
55 }
56
60 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
61 SmearedMET(const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
62 : SmearedMET(MissingMomentum(cut), metSmearFn)
63 { }
64
70 template <typename SMEARPARAMSFN, typename SMEARFN,
71 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
72 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
73 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn)
74 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(metSmearFn)
75 {
76 setName("SmearedMET");
77 declare(mm, "TruthMET");
78 _noSmear = getEnvParam<bool>("RIVET_DISABLE_SMEARING", false);
79 }
80
86 template <typename SMEARPARAMSFN, typename SMEARFN,
87 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
88 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
89 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
90 : SmearedMET(MissingMomentum(cut), metSmearParamsFn, metSmearFn)
91 { }
92
93
96
98
100 using Projection::operator =;
101
102
104 CmpState compare(const Projection& p) const {
105 // const SmearedMET& other = dynamic_cast<const SmearedMET&>(p);
106 // if (get_address(_metSmearParamsFn) == 0) return cmp((size_t)this, (size_t)&p);
107 // if (get_address(_metSmearFn) == 0) return cmp((size_t)this, (size_t)&p);
108 // MSG_TRACE("Smear hashes (params) = " << get_address(_metSmearParamsFn) << "," << get_address(other._metSmearParamsFn));
109 // MSG_TRACE("Smear hashes (smear) = " << get_address(_metSmearFn) << "," << get_address(other._metSmearFn));
110 // return mkPCmp(other, "TruthMET") ||
111 // cmp(get_address(_metSmearParamsFn), get_address(other._metSmearParamsFn));
112 // cmp(get_address(_metSmearFn), get_address(other._metSmearFn));
113 if (_noSmear) return CmpState::EQ;
114 return CmpState::UNDEF;
115 }
116
117
119 void project(const Event& e) {
120 const METFinder& mm = apply<MissingMomentum>(e, "TruthMET");
121 _spt = mm.scalarPt();
122 _set = mm.scalarEt();
123 _vpt = mm.vectorPt();
124 _vet = mm.vectorEt();
125
126 // Short-circuit if smearing is disabled
127 if (_noSmear) return;
128
129 if (_metSmearFn) {
130 _vpt = _metSmearFn(_vpt, _spt); //< custom smearing
131 _vet = _metSmearFn(_vet, _set); //< custom smearing
132 } else if (_metSmearParamsFn) {
133 const METSmearParams msps_p = _metSmearParamsFn(_vpt, _set); //< custom smear params: note still calibrated wrt SET, not SPT
134 _vpt = MET_SMEAR_NORM(msps_p); //< normal-distribution smearing from custom params
135 const METSmearParams msps_e = _metSmearParamsFn(_vet, _set); //< custom smear params
136 _vet = MET_SMEAR_NORM(msps_e); //< normal-distribution smearing from custom params
137 } else {
138 throw SmearError("Attempt to smear MPT and MET with neither a smearing function nor a smearing-params function set");
139 }
140 }
141
142
150
152 const Vector3& vectorSumPt() const { return _vpt; }
153
155 double scalarSumPt() const { return _spt; }
156
158 double missingPtResolution() const {
159 if (!_metSmearParamsFn)
160 throw UserError("Trying to compute MPT significance without a registered significance function");
161 METSmearParams msps = _metSmearParamsFn(vectorPt(), scalarPt());
162 return msps.pResolution;
163 }
164
166 double missingPtSignf() const {
167 return missingPt() / missingPtResolution();
168 }
169
171
172
180
184 const Vector3& vectorSumEt() const { return _vet; }
185
187 double scalarSumEt() const { return _set; }
188
190 double missingEtResolution() const {
191 if (!_metSmearParamsFn)
192 throw UserError("Trying to compute MET significance without a registered significance function");
193 METSmearParams msps = _metSmearParamsFn(vectorEt(), scalarEt());
194 //return max(msps.eResolution, msps.pResolution);
195 return msps.pResolution; //< @todo Check?
196 }
197
199 double missingEtSignf() const {
200 return missingEt() / missingEtResolution();
201 }
202
204
205
207 void reset() { }
208
209
210 protected:
211
212 Vector3 _vpt, _vet;
213 double _spt, _set;
214
216 METSmearParamsFn _metSmearParamsFn;
217
219 METSmearFn _metSmearFn;
220
224 bool _noSmear{false};
225
226 };
227
228
229}
230
231#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:38
double scalarPt() const
Alias for scalarSumPt.
Definition METFinder.hh:49
virtual const Vector3 & vectorEt() const
Alias for vectorSumEt.
Definition METFinder.hh:66
double scalarEt() const
Alias for scalarSumEt.
Definition METFinder.hh:87
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:76
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:119
const PROJ & declare(const PROJ &proj, const std::string &name) const
Register a contained projection (user-facing version).
Definition ProjectionApplier.hh:184
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:148
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedMET.hh:207
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:89
double missingPtSignf() const
Obtain an approximation to the MPT significance (value/resolution) for this event.
Definition SmearedMET.hh:166
double scalarSumEt() const
The scalar-summed visible transverse energy in the event.
Definition SmearedMET.hh:187
double missingPtResolution() const
Obtain an approximation to the MPT resolution for this event.
Definition SmearedMET.hh:158
SmearedMET(const MissingMomentum &mm, const SMEARFN &metSmearFn)
Constructor from a MissingMomentum projection and a smearing function.
Definition SmearedMET.hh:49
SmearedMET(const MissingMomentum &mm, const SMEARPARAMSFN &metSmearParamsFn)
Constructor from a MissingMomentum projection and a smearing-params function.
Definition SmearedMET.hh:25
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:73
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:41
void project(const Event &e)
Perform the MET finding & smearing calculation.
Definition SmearedMET.hh:119
double missingEtResolution() const
Obtain an approximation to the MET resolution for this event.
Definition SmearedMET.hh:190
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:61
const Vector3 & vectorSumPt() const
The vector-summed visible transverse momentum in the event, as a 3-vector with z=0.
Definition SmearedMET.hh:152
const Vector3 & vectorSumEt() const
Definition SmearedMET.hh:184
double missingEtSignf() const
Obtain an approximation to the MET significance (value/resolution) for this event.
Definition SmearedMET.hh:199
CmpState compare(const Projection &p) const
Compare to another SmearedMET.
Definition SmearedMET.hh:104
double scalarSumPt() const
The scalar-summed visible transverse momentum in the event.
Definition SmearedMET.hh:155
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:653
function< Vector3(const Vector3 &, double)> METSmearFn
Definition MomentumSmearingFunctions.hh:139
function< METSmearParams(const Vector3 &, double)> METSmearParamsFn
Definition MomentumSmearingFunctions.hh:134
Vector3 MET_SMEAR_NORM(const METSmearParams &msps)
Smear a nominal vector magnitude by Gaussian with the given absolute resolutions.
Definition MomentumSmearingFunctions.hh:156
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:874
Definition MC_CENT_PPB_Projections.hh:10
Struct for holding MET-smearing parameters.
Definition MomentumSmearingFunctions.hh:121
Error specialisation for failures relating to event smearing.
Definition Exceptions.hh:52
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:67