Rivet API documentation

Rivet 4.1.3
JetUtils.hh
1#ifndef RIVET_JETUTILS_HH
2#define RIVET_JETUTILS_HH
3
4#include "Rivet/Jet.hh"
5#include "Rivet/Tools/ParticleBaseUtils.hh"
6
7namespace Rivet {
8
9
12
15
16 inline PseudoJets mkPseudoJets(const Particles& ps) {
17 PseudoJets rtn;
18 rtn.reserve(ps.size());
19 for (const Particle& p : ps) rtn.push_back(p.pseudojet());
20 return rtn;
21 }
22
23 inline PseudoJets mkPseudoJets(const Jets& js) {
24 PseudoJets rtn;
25 rtn.reserve(js.size());
26 for (const Jet& j : js) rtn.push_back(j.pseudojet());
27 return rtn;
28 }
29
30 inline Jets mkJets(const PseudoJets& pjs) {
31 Jets rtn;
32 rtn.reserve(pjs.size());
33 for (const PseudoJet& pj : pjs) rtn.push_back(pj);
34 return rtn;
35 }
36
38
39
42
44 using JetSelector = function<bool(const Jet&)>;
46 using JetSorter = function<bool(const Jet&, const Jet&)>;
47
48
51 virtual bool operator()(const Jet& p) const = 0;
52 virtual ~BoolJetFunctor() { }
53 };
54
55
57 struct BoolJetAND : public BoolJetFunctor {
58 BoolJetAND(const std::vector<JetSelector>& sels)
59 : selectors(sels) { }
60 BoolJetAND(const JetSelector& a, const JetSelector& b)
61 : selectors({a, b}) { }
62 BoolJetAND(const JetSelector& a, const JetSelector& b, const JetSelector& c)
63 : selectors({a, b, c}) { }
64 bool operator()(const Jet& j) const {
65 for (const JetSelector& sel : selectors)
66 if (!sel(j)) return false;
67 return true;
68 }
69 std::vector<JetSelector> selectors;
70 };
71
72 inline BoolJetAND operator&&(const JetSelector& a, const JetSelector& b) {
73 return BoolJetAND(a, b);
74 }
75
76
78 struct BoolJetOR : public BoolJetFunctor {
79 BoolJetOR(const std::vector<JetSelector>& sels)
80 : selectors(sels) { }
81 BoolJetOR(const JetSelector& a, const JetSelector& b)
82 : selectors({a, b}) { }
83 BoolJetOR(const JetSelector& a, const JetSelector& b, const JetSelector& c)
84 : selectors({a, b, c}) { }
85 bool operator()(const Jet& j) const {
86 for (const JetSelector& sel : selectors)
87 if (sel(j)) return true;
88 return false;
89 }
90 std::vector<JetSelector> selectors;
91 };
92
93 inline BoolJetOR operator||(const JetSelector& a, const JetSelector& b) {
94 return BoolJetOR(a, b);
95 }
96
97
99 struct BoolJetNOT : public BoolJetFunctor {
100 BoolJetNOT(const JetSelector& sel)
101 : selector(sel) { }
102 bool operator()(const Jet& j) const {
103 return !selector(j);
104 }
105 JetSelector selector;
106 };
107
109 return BoolJetNOT(a);
110 }
111
112
114 struct HasBTag : BoolJetFunctor {
115 HasBTag(const Cut& c = Cuts::open(), double dR = -1)
116 : cut(c), deltaR(dR) { }
117 // HasBTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
118 bool operator()(const Jet& j) const {
119 return j.bTagged(cut, deltaR);
120 }
121 // const std::function<bool(const Jet& j)> selector;
122 const Cut cut;
123 const double deltaR;
124 };
125 using hasBTag = HasBTag;
126
128 struct HasCTag : BoolJetFunctor {
129 HasCTag(const Cut& c = Cuts::open(), double dR = -1)
130 : cut(c), deltaR(dR) { }
131 // HasCTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
132 bool operator()(const Jet& j) const {
133 return j.cTagged(cut, deltaR);
134 }
135 // const std::function<bool(const Jet& j)> selector;
136 const Cut cut;
137 const double deltaR;
138 };
139 using hasCTag = HasCTag;
140
142 struct HasTauTag : BoolJetFunctor {
143 HasTauTag(const Cut& c = Cuts::open(), double dR = -1)
144 : cut(c), deltaR(dR) { }
145 // HasTauTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
146 bool operator()(const Jet& j) const {
147 return j.tauTagged(cut, deltaR);
148 }
149 // const std::function<bool(const Jet& j)> selector;
150 const Cut cut;
151 const double deltaR;
152 };
153 using hasTauTag = HasTauTag;
154
156 struct HasNoTag : BoolJetFunctor {
157 HasNoTag(const Cut& c = Cuts::open(), double dR = -1, bool quarktagsonly = false)
158 : cut(c), deltaR(dR), qtagsonly(quarktagsonly) { }
159 HasNoTag(const Cut& c = Cuts::open(), bool quarktagsonly = false)
160 : HasNoTag(c, -1, quarktagsonly) { }
161 // HasNoTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
162 bool operator()(const Jet& j) const {
163 return !j.bTagged(cut, deltaR) && !j.cTagged(cut, deltaR) && (qtagsonly || !j.tauTagged(cut, deltaR));
164 }
165 // const std::function<bool(const Jet& j)> selector;
166 const Cut cut;
167 const double deltaR;
168 bool qtagsonly;
169 };
170 using hasNoTag = HasNoTag;
171
173
174
177
179 Jets& iselect(Jets& jets, const Cut& c);
180
181
183 inline Jets select(const Jets& jets, const Cut& c) {
184 Jets rtn = jets;
185 return iselect(rtn, c);
186 }
187
188
190 inline Jets select(const Jets& jets, const Cut& c, Jets& out) {
191 out = select(jets, c);
192 return out;
193 }
194
195
197 Jets& idiscard(Jets& jets, const Cut& c);
198
199
201 inline Jets discard(const Jets& jets, const Cut& c) {
202 Jets rtn = jets;
203 return idiscard(rtn, c);
204 }
205
206
208 inline Jets discard(const Jets& jets, const Cut& c, Jets& out) {
209 out = discard(jets, c);
210 return out;
211 }
212
214
215
218
230 Jet& itrimJetsFrac(Jet& jet, const double frac);
231
232
243 template <typename CONTAINER, typename = std::enable_if_t<is_citerable_v<CONTAINER>, Jet>>
244 CONTAINER& itrimJetsFrac(CONTAINER& jets, const double frac, const JetSorter& sortFunc = cmpMomByPt) {
245 for (Jet& jet : jets) itrimJetsFrac(jet, frac);
246 isortBy(jets, sortFunc);
247 return jets;
248 }
249
260 template <typename T, typename U>
261 std::map<T, U>& itrimJetsFrac(std::map<T, U>& jetMap,
262 const double frac,
263 const JetSorter& sortFunc = cmpMomByPt) {
264 for (auto& item : jetMap) itrimJetsFrac(item.second, frac, sortFunc);
265 return jetMap;
266 }
267
278 inline Jet trimJetsFrac(const Jet& jet, double frac) {
279 Jet rtn = jet;
280 return itrimJetsFrac(rtn, frac);
281 }
282
292 template <typename... Args, typename CONTAINER, typename = std::enable_if_t<is_citerable_v<CONTAINER>, Jet>>
293 CONTAINER trimJetsFrac(const CONTAINER& jets, Args&&... args) {
294 CONTAINER rtn = jets;
295 return itrimJetsFrac(rtn, std::forward<Args>(args)...);
296 }
297
307 template <typename T, typename U, typename... Args>
308 std::map<T, U> trimJetsFrac(const std::map<T, U>& jetMap, Args&&... args) {
309 std::map<T, U> rtn = jetMap;
310 return itrimJetsFrac(rtn, std::forward<Args>(args)...);
311 }
312
314
315
318
325 PseudoJet& ifilterPseudoJets(PseudoJet& pj, const fastjet::Filter& filter);
326
334 template <typename CONTAINER, typename = std::enable_if_t<is_citerable_v<CONTAINER>, PseudoJet>>
335 CONTAINER& ifilterPseudoJets(CONTAINER& pjs,
336 const fastjet::Filter& filter,
337 const JetSorter& sortFunc = cmpMomByPt) {
338 for (PseudoJet& pj : pjs) ifilterPseudoJets(pj, filter);
339 isortBy(pjs, sortFunc);
340 return pjs;
341 }
342
346 template <typename T, typename U, typename... Args>
347 std::map<T, U>& ifilterPseudoJets(std::map<T, U>& pjMap, Args&&... args) {
348 for (auto& item : pjMap) ifilterPseudoJets(item.second, std::forward<Args>(args)...);
349 return pjMap;
350 }
351
353 inline PseudoJet filterPseudoJets(const PseudoJet& pj, const fastjet::Filter& filter) {
354 PseudoJet rtn = pj;
355 return ifilterPseudoJets(rtn, filter);
356 }
357
361 template <typename... Args,
362 typename CONTAINER,
363 typename = std::enable_if_t<is_citerable_v<CONTAINER>, PseudoJet>>
364 CONTAINER filterPseudoJets(const CONTAINER& pjs, Args&&... args) {
365 CONTAINER rtn = pjs;
366 return ifilterPseudoJets(rtn, std::forward<Args>(args)...);
367 }
368
372 template <typename T, typename U, typename... Args>
373 std::map<T, U> filterPseudoJets(const std::map<T, U>& pjMap, Args&&... args) {
374 std::map<T, U> rtn = pjMap;
375 return ifilterPseudoJets(rtn, std::forward<Args>(args)...);
376 }
377
378
379
380 // Import Kin namespace into Rivet
381 using namespace Kin;
382
384
385}
386
387#endif
Representation of a clustered jet of particles.
Definition Jet.hh:47
bool cTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one c-tag? (with optional Cut and dR restriction).
Definition Jet.hh:217
bool tauTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one tau-tag (with optional Cut and dR restriction).
Definition Jet.hh:246
bool bTagged(const Cut &c=Cuts::open(), double dRmax=-1) const
Does this jet have at least one b-tag? (with optional Cut and dR restriction).
Definition Jet.hh:188
Specialised vector of Jet objects.
Definition Jet.hh:21
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition Particle.hh:50
Specialised vector of Particle objects.
Definition Particle.hh:21
Jets & idiscard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Jets select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition JetUtils.hh:183
Jets & iselect(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Jets discard(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Definition JetUtils.hh:201
PseudoJet & ifilterPseudoJets(PseudoJet &pj, const fastjet::Filter &filter)
Apply given FastJet::Filter filter to PseudoJet pj in-place.
PseudoJet filterPseudoJets(const PseudoJet &pj, const fastjet::Filter &filter)
Apply given FastJet::Filter param filter to PseudoJet pj out-of-place.
Definition JetUtils.hh:353
function< bool(const Jet &, const Jet &)> JetSorter
std::function instantiation for functors taking two Jets and returning a bool
Definition JetUtils.hh:46
function< bool(const Jet &)> JetSelector
std::function instantiation for functors taking a Jet and returning a bool
Definition JetUtils.hh:44
Jet & itrimJetsFrac(Jet &jet, const double frac)
Trim subjets with insufficient pT fraction.
Jet trimJetsFrac(const Jet &jet, double frac)
Trim subjets with insufficient pT fraction.
Definition JetUtils.hh:278
MOMS & isortBy(MOMS &pbs, const CMP &cmp)
Sort a container of momenta by cmp and return by reference for non-const inputs.
Definition Vector4.hh:1422
bool cmpMomByPt(const FourMomentum &a, const FourMomentum &b)
Comparison to give a sorting by decreasing pT.
Definition Vector4.hh:1333
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
const Cut & open()
Fully open cut singleton, accepts everything.
Definition LHCbCommon.hh:9
Cut operator!(const Cut &cptr)
Logical NOT operation on a cut.
Cut operator&&(const Cut &aptr, const Cut &bptr)
std::vector< PseudoJet > PseudoJets
Definition RivetFastJet.hh:30
Cut operator||(const Cut &aptr, const Cut &bptr)
Functor for and-combination of selector logic.
Definition JetUtils.hh:57
Base type for Jet -> bool functors.
Definition JetUtils.hh:50
Functor for inverting selector logic.
Definition JetUtils.hh:99
Functor for or-combination of selector logic.
Definition JetUtils.hh:78
B-tagging functor, with a tag selection cut as the stored state.
Definition JetUtils.hh:114
C-tagging functor, with a tag selection cut as the stored state.
Definition JetUtils.hh:128
Anti-B/C-tagging functor, with a tag selection cut as the stored state.
Definition JetUtils.hh:156
Tau-tagging functor, with a tag selection cut as the stored state.
Definition JetUtils.hh:142