File indexing completed on 2025-09-18 09:31:15
0001
0002 #ifndef RIVET_SmearedMET_HH
0003 #define RIVET_SmearedMET_HH
0004
0005 #include "Rivet/Projection.hh"
0006 #include "Rivet/Projections/METFinder.hh"
0007 #include "Rivet/Projections/MissingMomentum.hh"
0008 #include "Rivet/Tools/SmearingFunctions.hh"
0009 #include <functional>
0010
0011 namespace Rivet {
0012
0013
0014
0015 class SmearedMET : public METFinder {
0016 public:
0017
0018
0019
0020
0021
0022
0023
0024 template<typename SMEARPARAMSFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
0025 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn)
0026 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(nullptr)
0027
0028
0029
0030
0031 {
0032 setName("SmearedMET");
0033 declare(mm, "TruthMET");
0034 }
0035
0036
0037
0038
0039 template<typename SMEARPARAMSFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
0040 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const Cut& cut=Cuts::OPEN)
0041 : SmearedMET(MissingMomentum(cut), metSmearParamsFn)
0042 { }
0043
0044
0045
0046
0047 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
0048 SmearedMET(const MissingMomentum& mm, const SMEARFN& metSmearFn)
0049 : _metSmearParamsFn(nullptr), _metSmearFn(metSmearFn)
0050 {
0051 setName("SmearedMET");
0052 declare(mm, "TruthMET");
0053 }
0054
0055
0056
0057
0058 template<typename SMEARFN, typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3>, int> = 0>
0059 SmearedMET(const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
0060 : SmearedMET(MissingMomentum(cut), metSmearFn)
0061 { }
0062
0063
0064
0065
0066
0067
0068 template <typename SMEARPARAMSFN, typename SMEARFN,
0069 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
0070 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
0071 SmearedMET(const MissingMomentum& mm, const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn)
0072 : _metSmearParamsFn(metSmearParamsFn), _metSmearFn(metSmearFn)
0073 {
0074 setName("SmearedMET");
0075 declare(mm, "TruthMET");
0076 }
0077
0078
0079
0080
0081
0082
0083 template <typename SMEARPARAMSFN, typename SMEARFN,
0084 typename std::enable_if_t<is_same_v<invoke_result_t<SMEARFN, Vector3, double>, Vector3> &&
0085 is_same_v<invoke_result_t<SMEARPARAMSFN, Vector3, double>, METSmearParams>, int> = 0>
0086 SmearedMET(const SMEARPARAMSFN& metSmearParamsFn, const SMEARFN& metSmearFn, const Cut& cut=Cuts::OPEN)
0087 : SmearedMET(MissingMomentum(cut), metSmearParamsFn, metSmearFn)
0088 { }
0089
0090
0091
0092 RIVET_DEFAULT_PROJ_CLONE(SmearedMET);
0093
0094
0095
0096
0097 using Projection::operator =;
0098
0099
0100
0101 CmpState compare(const Projection& p) const {
0102
0103
0104
0105
0106
0107
0108
0109
0110 return CmpState::UNDEF;
0111 }
0112
0113
0114
0115 void project(const Event& e) {
0116 const METFinder& mm = apply<MissingMomentum>(e, "TruthMET");
0117 _set = mm.scalarEt();
0118 _vet = mm.vectorEt();
0119 if (_metSmearFn) {
0120 _vet = _metSmearFn(_vet, mm.scalarEt());
0121 } else if (_metSmearParamsFn) {
0122 const METSmearParams msps = _metSmearParamsFn(_vet, mm.scalarEt());
0123 _vet = MET_SMEAR_NORM(msps);
0124 } else {
0125 throw SmearError("Attempt to smear MET with neither smearing function nor smearing-params function set");
0126 }
0127 }
0128
0129
0130
0131
0132
0133
0134
0135
0136 const Vector3& vectorPt() const { return vectorEt(); }
0137
0138 double scalarPt() const { return scalarEt(); }
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 const Vector3& vectorEt() const { return _vet; }
0152
0153
0154 double scalarEt() const { return _set; }
0155
0156
0157 double missingEtResolution() const {
0158 if (!_metSmearParamsFn)
0159 throw UserError("Trying to compute MET significance without a registered significance function");
0160 METSmearParams msps = _metSmearParamsFn(vectorEt(), scalarEt());
0161
0162 return msps.pResolution;
0163 }
0164
0165
0166 double missingEtSignf() const {
0167 return missingEt() / missingEtResolution();
0168 }
0169
0170
0171
0172
0173
0174 void reset() { }
0175
0176
0177 protected:
0178
0179 Vector3 _vet;
0180 double _set;
0181
0182
0183 METSmearParamsFn _metSmearParamsFn;
0184
0185
0186 METSmearFn _metSmearFn;
0187
0188 };
0189
0190
0191 }
0192
0193 #endif