Rivet API documentation

Rivet 4.1.5
ObjectBasedMET.hh
1// -*- C++ -*-
2#ifndef RIVET_TOOLS_OBJECTBASEDMET_HH
3#define RIVET_TOOLS_OBJECTBASEDMET_HH
4
5#include "Rivet/Tools/ExptResolutionFunctions.hh"
6
7namespace Rivet {
8
17 public:
18
21
23 ObjectBasedMET(ResolutionFunctorPtr<Jet> jet_pt_res,
24 ResolutionFunctorPtr<Jet> jet_phi_res,
25
26 ResolutionFunctorPtr<Particle> el_et_res,
27 ResolutionFunctorPtr<Particle> el_phi_res,
28
29 ResolutionFunctorPtr<Particle> mu_pt_res,
30 ResolutionFunctorPtr<Particle> mu_phi_res,
31
32 ResolutionFunctorPtr<Particle> photon_pt_res = nullptr,
33 ResolutionFunctorPtr<Particle> photon_phi_res = nullptr,
34
35 ResolutionFunctorPtr<Jet> hadtau_pt_res = nullptr,
36 ResolutionFunctorPtr<Jet> hadtau_phi_res = nullptr,
37
38 ResolutionFunctorPtr<ThreeMomentum> softterm_pt_res = nullptr,
39 ResolutionFunctorPtr<ThreeMomentum> softterm_phi_res = nullptr,
40
41 bool recalc_softterm = true)
42 : _jet_pt_res(std::move(jet_pt_res)),
43 _jet_phi_res(std::move(jet_phi_res)),
44 _el_et_res(std::move(el_et_res)),
45 _el_phi_res(std::move(el_phi_res)),
46 _mu_pt_res(std::move(mu_pt_res)),
47 _mu_phi_res(std::move(mu_phi_res)),
48 _photon_pt_res(std::move(photon_pt_res)),
49 _photon_phi_res(std::move(photon_phi_res)),
50 _hadtau_pt_res(std::move(hadtau_pt_res)),
51 _hadtau_phi_res(std::move(hadtau_phi_res)),
52 _softterm_pt_res(std::move(softterm_pt_res)),
53 _softterm_phi_res(std::move(softterm_phi_res)),
54 _recalc_softterm(recalc_softterm) { }
55
57 double sig(const ThreeMomentum& MET,
58 const Jets& js,
59 const Particles& es,
60 const Particles& mus,
61 const Particles& gammas = {},
62 const Jets& hadtaus = {},
63 const ThreeMomentum& override_softterm = ThreeMomentum()) {
64 // TODO: THE SOFT TERM TREATMENT COULD BE CLEANED UP -- at the moment we recalculate
65 // whether we need to, and then just decide whether or not to use the recalculated version.
66 ThreeMomentum softVec = MET;
67
68 // TODO: maybe Rivet should just have a Matrix2 class?
69 Matrix<2> cov_sum = Matrix<2>::mkZero();
70 for (const Jet& j : js) {
71 softVec += j.p3();
72 // TODO Working with rivet matrices is not fun
73 const double jptres = _jet_pt_res->resolution(j);
74 const double jphires = _jet_phi_res->resolution(j);
75 const double metangle = directionalDeltaPhi(MET, j.p3());
76
77 update_matrix(cov_sum, jptres, jphires, j.pT2(), metangle);
78 }
79
80 for (const Particle& e : es) {
81 softVec += e.p3();
82 const double etres = _el_et_res->resolution(e);
83 const double phires = _el_phi_res->resolution(e);
84 const double metangle = directionalDeltaPhi(MET, e.p3());
85 update_matrix(cov_sum, etres, phires, e.pt2(), metangle);
86 }
87 for (const Particle& mu : mus) {
88 softVec += mu.p3();
89 const double ptres = _mu_pt_res->resolution(mu);
90 const double phires = _mu_phi_res->resolution(mu);
91 const double metangle = directionalDeltaPhi(MET, mu.p3());
92 update_matrix(cov_sum, ptres, phires, mu.pt2(), metangle);
93 }
94
95 if (_photon_phi_res != nullptr && _photon_pt_res != nullptr) {
96 for (const Particle& gamma : gammas) {
97 softVec += gamma.p3();
98 const double ptres = _photon_pt_res->resolution(gamma);
99 const double phires = _photon_phi_res->resolution(gamma);
100 const double metangle = directionalDeltaPhi(MET, gamma.p3());
101 update_matrix(cov_sum, ptres, phires, gamma.pt2(), metangle);
102 }
103 }
104 // If user provides photons, but not photon resolution functors,
105 // something unintended may be happening.
106 else if (gammas.size() > 0) {
107 // TODO: do we have a way of triggering warnings only once? This will be hit on every event
109 "You have passed photons to a ObjectBasedMET calculator without a photon resolution functor."
110 "\n\tThis is probably NOT what you intended to do. Photons will NOT count towards MET "
111 "significance.");
112 }
113
114
115 if (_hadtau_phi_res != nullptr && _hadtau_pt_res != nullptr) {
116 for (const Jet& hadtau : hadtaus) {
117 softVec += hadtau.p3();
118 const double ptres = _hadtau_pt_res->resolution(hadtau);
119 const double phires = _hadtau_phi_res->resolution(hadtau);
120 const double metangle = directionalDeltaPhi(MET, hadtau.p3());
121 update_matrix(cov_sum, ptres, phires, hadtau.pt2(), metangle);
122 }
123 }
124 // If user provides taus, but not tau resolution functors,
125 // something unintended may be happening.
126 else if (hadtaus.size() > 0) {
127 // TODO: do we have a way of triggering warnings only once? This will be hit on every event
128 MSG_WARNING("You have passed taus to a ObjectBasedMET calculator without a tau resolution functor."
129 "\n\tThis is probably NOT what you intended to do. Taus will NOT count towards MET "
130 "significance.");
131 }
132
133
134 if (!_recalc_softterm) {
135 softVec = override_softterm;
136 }
137 if (_softterm_pt_res != nullptr && _softterm_phi_res != nullptr) {
138 const double softterm_pt_res = _softterm_pt_res->resolution(softVec);
139 const double softterm_phi_res = _softterm_phi_res->resolution(softVec);
140 update_matrix_absolute(cov_sum, softterm_pt_res, softterm_phi_res, directionalDeltaPhi(MET, softVec));
141 }
142 // Otherwise assume 10 GeV resolution from soft term, as in SA
143 else {
144 update_matrix_absolute(cov_sum, 10., 10., directionalDeltaPhi(MET, softVec));
145 }
146
147
148 if (cov_sum.get(0, 0) == 0) return 0;
149 // Simple analysis includes a check to exclude unphysically? large rho.
150 double rho = cov_sum.get(0, 1) / sqrt(cov_sum.get(0, 0) * cov_sum.get(1, 1));
151 if (abs(rho) >= 0.9) rho = 0.;
152 // TODO: The SA code uses a variable called Et, but from my attempts to look inside, Et = pt?
153 const double significance = MET.pT() / sqrt(cov_sum.get(0, 0) * (1 - rho * rho));
154
155 // TODO: it would be nice to be able to also return the actual (2D) met resolution to use for smearing?
156 // However, to get a "consistent" smear, we would need both the "true" objects and the "smeared ones"
157 // -- which gets pretty messy pretty fast
158
159 return significance;
160 }
161
162 protected:
163
166
170 const double ptres,
171 const double phires,
172 const double angle) const {
173 Matrix<2> particle_uncert = Matrix<2>::mkZero();
174 particle_uncert.set(0, 0, ptres * ptres);
175 particle_uncert.set(1, 1, phires * phires);
176 rotateMatrix2(particle_uncert, angle);
177 mat += particle_uncert;
178 }
179
183 const double ptres,
184 const double phires,
185 const double pt2,
186 const double angle) const {
187 const double pt = sqrt(pt2);
188 update_matrix_absolute(mat, ptres * pt, phires * pt, angle);
189 }
190
192 void rotateMatrix2(Matrix<2>& in, const double phi) const {
193 const double c = cos(phi);
194 const double s = sin(phi);
195 const double cc = c * c;
196 const double ss = s * s;
197 const double cs = c * s;
198
199 const double _00 = in.get(0, 0) * cc + in.get(1, 1) * ss - cs * (in.get(1, 0) + in.get(0, 1));
200 const double _01 = in.get(0, 1) * cc - in.get(1, 0) * ss + cs * (in.get(0, 0) - in.get(1, 1));
201 const double _10 = in.get(1, 0) * cc - in.get(0, 1) * ss + cs * (in.get(0, 0) - in.get(1, 1));
202 const double _11 = in.get(0, 0) * ss + in.get(1, 1) * cc + cs * (in.get(1, 0) + in.get(0, 1));
203
204 in.set(0, 0, _00);
205 in.set(1, 0, _10);
206 in.set(0, 1, _01);
207 in.set(1, 1, _11);
208 }
209
212 double directionalDeltaPhi(const ThreeMomentum& first, const ThreeMomentum& second) const {
213 double dPhi = first.phi() - second.phi();
214 if (dPhi > PI / 2.) return dPhi - PI;
215 if (dPhi < -PI / 2.) return dPhi + PI;
216 return dPhi;
217 }
218
219
220
223 ResolutionFunctorPtr<Jet> _jet_pt_res;
224 ResolutionFunctorPtr<Jet> _jet_phi_res;
225
226 ResolutionFunctorPtr<Particle> _el_et_res;
227 ResolutionFunctorPtr<Particle> _el_phi_res;
228
229 ResolutionFunctorPtr<Particle> _mu_pt_res;
230 ResolutionFunctorPtr<Particle> _mu_phi_res;
231
232 ResolutionFunctorPtr<Particle> _photon_pt_res;
233 ResolutionFunctorPtr<Particle> _photon_phi_res;
234
235 ResolutionFunctorPtr<Jet> _hadtau_pt_res;
236 ResolutionFunctorPtr<Jet> _hadtau_phi_res;
237
238 ResolutionFunctorPtr<ThreeMomentum> _softterm_pt_res;
239 ResolutionFunctorPtr<ThreeMomentum> _softterm_phi_res;
240
241 bool _recalc_softterm;
242
244
247 return Rivet::Log::getLog("Rivet.ObjectBaseMET");
248 }
249 };
250
252 template <typename jet_pt_res,
253 typename jet_phi_res,
254 typename el_pt_res,
255 typename el_phi_res,
256 typename mu_pt_res,
257 typename mu_phi_res,
258 typename photon_pt_res = void,
259 typename photon_phi_res = void,
260 typename tau_pt_res = void,
261 typename tau_phi_res = void,
262 typename softterm_pt_res = void,
263 typename softterm_phi_res = void>
264 ObjectBasedMET makeObjectBasedMET(const bool recalc_softterm = true) {
265
266 // Deal with possible default arguments
267 ResolutionFunctorPtr<Particle> photon_pt_ptr = nullptr;
268 ResolutionFunctorPtr<Particle> photon_phi_ptr = nullptr;
269 ResolutionFunctorPtr<Jet> tau_pt_ptr = nullptr;
270 ResolutionFunctorPtr<Jet> tau_phi_ptr = nullptr;
271 ResolutionFunctorPtr<ThreeMomentum> softterm_pt_ptr = nullptr;
272 ResolutionFunctorPtr<ThreeMomentum> softterm_phi_ptr = nullptr;
273
274 if constexpr (!std::is_void_v<photon_pt_res>) {
275 photon_pt_ptr = std::make_unique<photon_pt_res>();
276 if constexpr (!std::is_void_v<photon_phi_res>) {
277 photon_phi_ptr = std::make_unique<photon_phi_res>();
278 }
279 }
280 if constexpr (!std::is_void_v<tau_pt_res>) {
281 tau_pt_ptr = std::make_unique<tau_pt_res>();
282 if constexpr (!std::is_void_v<tau_phi_res>) {
283 tau_phi_ptr = std::make_unique<tau_phi_res>();
284 }
285 }
286 if constexpr (!std::is_void_v<softterm_pt_res>) {
287 softterm_pt_ptr = std::make_unique<softterm_pt_res>();
288 if constexpr (!std::is_void_v<softterm_phi_res>) {
289 softterm_phi_ptr = std::make_unique<softterm_phi_res>();
290 }
291 }
292
293 return ObjectBasedMET(std::make_unique<jet_pt_res>(), std::make_unique<jet_phi_res>(),
294 std::make_unique<el_pt_res>(), std::make_unique<el_phi_res>(),
295 std::make_unique<mu_pt_res>(), std::make_unique<mu_phi_res>(),
296 std::move(photon_pt_ptr), std::move(photon_phi_ptr), std::move(tau_pt_ptr),
297 std::move(tau_phi_ptr), std::move(softterm_pt_ptr), std::move(softterm_phi_ptr),
298 recalc_softterm);
299 }
300
304
306
308 // Photons and Taus deliberately excluded because unvalidated.
309 // If you need either of them, you can add them by manually
310 // constructing the ObjectBasedMET object.
311 // Check them carefully (and let us know if they work!)
312 }
313
314}
315
316#endif
Definition ExptResolutionFunctions.hh:110
Returns 0.004 as in SimpleAnalysisFramework/src/ObjectResolutions.cxx.
Definition ExptResolutionFunctions.hh:329
Definition ExptResolutionFunctions.hh:13
Definition ExptResolutionFunctions.hh:58
Returns 0.001 as in SimpleAnalysisFramework/src/ObjectResolutions.cxx.
Definition ExptResolutionFunctions.hh:316
Definition ExptResolutionFunctions.hh:165
Specialised vector of Jet objects.
Definition Jet.hh:21
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
static Log & getLog(const std::string &name)
General -dimensional mathematical matrix object.
Definition MatrixN.hh:30
Definition ObjectBasedMET.hh:16
ObjectBasedMET()
Nullary constructor.
Definition ObjectBasedMET.hh:20
double sig(const ThreeMomentum &MET, const Jets &js, const Particles &es, const Particles &mus, const Particles &gammas={}, const Jets &hadtaus={}, const ThreeMomentum &override_softterm=ThreeMomentum())
Calculate MET significance given the MET and other objects from event.
Definition ObjectBasedMET.hh:57
ObjectBasedMET(ResolutionFunctorPtr< Jet > jet_pt_res, ResolutionFunctorPtr< Jet > jet_phi_res, ResolutionFunctorPtr< Particle > el_et_res, ResolutionFunctorPtr< Particle > el_phi_res, ResolutionFunctorPtr< Particle > mu_pt_res, ResolutionFunctorPtr< Particle > mu_phi_res, ResolutionFunctorPtr< Particle > photon_pt_res=nullptr, ResolutionFunctorPtr< Particle > photon_phi_res=nullptr, ResolutionFunctorPtr< Jet > hadtau_pt_res=nullptr, ResolutionFunctorPtr< Jet > hadtau_phi_res=nullptr, ResolutionFunctorPtr< ThreeMomentum > softterm_pt_res=nullptr, ResolutionFunctorPtr< ThreeMomentum > softterm_phi_res=nullptr, bool recalc_softterm=true)
Primary constructor.
Definition ObjectBasedMET.hh:23
Rivet::Log & getLog() const
Get Logger object.
Definition ObjectBasedMET.hh:246
Specialised vector of Particle objects.
Definition Particle.hh:21
Specialized version of the ThreeVector with momentum functionality.
Definition Vector3.hh:377
double pT() const
Calculate the transverse momentum $p_T$.
Definition Vector3.hh:487
double phi(const PhiMapping mapping=ZERO_2PI) const
Synonym for azimuthalAngle.
Definition Vector3.hh:212
#define MSG_WARNING(x)
Warning messages for non-fatal bad things, using MSG_LVL.
Definition Logging.hh:200
void update_matrix(Matrix< 2 > &mat, const double ptres, const double phires, const double pt2, const double angle) const
Definition ObjectBasedMET.hh:182
double directionalDeltaPhi(const ThreeMomentum &first, const ThreeMomentum &second) const
Definition ObjectBasedMET.hh:212
void rotateMatrix2(Matrix< 2 > &in, const double phi) const
Rotate the (pt, phi) 2D matrix in in (x,y) space by phi.
Definition ObjectBasedMET.hh:192
void update_matrix_absolute(Matrix< 2 > &mat, const double ptres, const double phires, const double angle) const
Definition ObjectBasedMET.hh:169
Definition LHCbCommon.hh:9
ObjectBasedMET ATLAS_RUN2_DEFAULT_METSIG()
ObjectBasedMET object using ATLAS Run 2 defaults.
Definition ObjectBasedMET.hh:302
constexpr double PI
Definition MathConstants.hh:13
ObjectBasedMET makeObjectBasedMET(const bool recalc_softterm=true)
Factory function to avoid the need for make_unique<> unpleasantness.
Definition ObjectBasedMET.hh:264
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:194
STL namespace.