rivet is hosted by Hepforge, IPPP Durham
Rivet 4.1.0
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 }
35
39 template<typename SMEARPARAMSFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
40 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const Cut& cut=Cuts::OPEN)
41 : SmearedMET(MissingMomentum(cut), metSmearParamsFn)
42 { }
43
47 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
48 SmearedMET(const MissingMomentum& mm, const SMEARFN& metSmearFn)
49 : _metSmearParamsFn(nullptr), _metSmearFn(metSmearFn)
50 {
51 setName("SmearedMET");
52 declare(mm, "TruthMET");
53 }
54
58 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
59 SmearedMET(const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
60 : SmearedMET(MissingMomentum(cut), metSmearFn)
61 { }
62
68 template <typename SMEARPARAMSFN, typename SMEARFN,
69 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
70 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
71 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn)
72 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(metSmearFn)
73 {
74 setName("SmearedMET");
75 declare(mm, "TruthMET");
76 }
77
83 template <typename SMEARPARAMSFN, typename SMEARFN,
84 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
85 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
86 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
87 : SmearedMET(MissingMomentum(cut), metSmearParamsFn, metSmearFn)
88 { }
89
90
93
95
97 using Projection::operator =;
98
99
101 CmpState compare(const Projection& p) const {
102 // const SmearedMET& other = dynamic_cast<const SmearedMET&>(p);
103 // if (get_address(_metSmearParamsFn) == 0) return cmp((size_t)this, (size_t)&p);
104 // if (get_address(_metSmearFn) == 0) return cmp((size_t)this, (size_t)&p);
105 // MSG_TRACE("Smear hashes (params) = " << get_address(_metSmearParamsFn) << "," << get_address(other._metSmearParamsFn));
106 // MSG_TRACE("Smear hashes (smear) = " << get_address(_metSmearFn) << "," << get_address(other._metSmearFn));
107 // return mkPCmp(other, "TruthMET") ||
108 // cmp(get_address(_metSmearParamsFn), get_address(other._metSmearParamsFn));
109 // cmp(get_address(_metSmearFn), get_address(other._metSmearFn));
110 return CmpState::UNDEF;
111 }
112
113
115 void project(const Event& e) {
116 const METFinder& mm = apply<MissingMomentum>(e, "TruthMET");
117 _set = mm.scalarEt();
118 _vet = mm.vectorEt();
119 if (_metSmearFn) {
120 _vet = _metSmearFn(_vet, mm.scalarEt()); //< custom smearing
121 } else if (_metSmearParamsFn) {
122 const METSmearParams msps = _metSmearParamsFn(_vet, mm.scalarEt()); //< custom smear params
123 _vet = MET_SMEAR_NORM(msps); //< normal-distribution smearing from custom params
124 } else {
125 throw SmearError("Attempt to smear MET with neither smearing function nor smearing-params function set");
126 }
127 }
128
129
134
136 const Vector3& vectorPt() const { return vectorEt(); }
138 double scalarPt() const { return scalarEt(); }
139
141
142
147
151 const Vector3& vectorEt() const { return _vet; }
152
154 double scalarEt() const { return _set; }
155
157 double missingEtResolution() const {
158 if (!_metSmearParamsFn)
159 throw UserError("Trying to compute MET significance without a registered significance function");
160 METSmearParams msps = _metSmearParamsFn(vectorEt(), scalarEt());
161 //return max(msps.eResolution, msps.pResolution);
162 return msps.pResolution;
163 }
164
166 double missingEtSignf() const {
167 return missingEt() / missingEtResolution();
168 }
169
171
172
174 void reset() { }
175
176
177 protected:
178
179 Vector3 _vet;
180 double _set;
181
183 METSmearParamsFn _metSmearParamsFn;
184
186 METSmearFn _metSmearFn;
187
188 };
189
190
191}
192
193#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 missingEt() const
The vector-summed missing transverse energy in the event.
Definition METFinder.hh:60
Calculate missing , etc. as complements to the total visible momentum.
Definition MissingMomentum.hh:22
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
Wrapper projection for smearing missing (transverse) energy/momentum with detector resolutions.
Definition SmearedMET.hh:15
void reset()
Reset the projection. Smearing functions will be unchanged.
Definition SmearedMET.hh:174
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:86
SmearedMET(const MissingMomentum &mm, const SMEARFN &metSmearFn)
Constructor from a MissingMomentum projection and a smearing function.
Definition SmearedMET.hh:48
const Vector3 & vectorPt() const
The vector-summed visible transverse momentum in the event, as a 3-vector with z=0.
Definition SmearedMET.hh:136
const Vector3 & vectorEt() const
Definition SmearedMET.hh:151
double scalarEt() const
The scalar-summed visible transverse energy in the event, as a 3-vector with z=0.
Definition SmearedMET.hh:154
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:71
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:40
void project(const Event &e)
Perform the MET finding & smearing calculation.
Definition SmearedMET.hh:115
double missingEtResolution() const
Obtain an approximation to the MET resolution for this event.
Definition SmearedMET.hh:157
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:59
double missingEtSignf() const
Obtain an approximation to the MET significant (value/resolution) for this event.
Definition SmearedMET.hh:166
CmpState compare(const Projection &p) const
Compare to another SmearedMET.
Definition SmearedMET.hh:101
double scalarPt() const
The scalar-summed visible transverse momentum in the event.
Definition SmearedMET.hh:138
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
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
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