rivet is hosted by Hepforge, IPPP Durham
Rivet 3.1.6
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; rtn.reserve(ps.size());
18 for (const Particle& p : ps) rtn.push_back(p.pseudojet());
19 return rtn;
20 }
21
22 inline PseudoJets mkPseudoJets(const Jets& js) {
23 PseudoJets rtn; rtn.reserve(js.size());
24 for (const Jet& j : js) rtn.push_back(j.pseudojet());
25 return rtn;
26 }
27
28 inline Jets mkJets(const PseudoJets& pjs) {
29 Jets rtn; rtn.reserve(pjs.size());
30 for (const PseudoJet& pj : pjs) rtn.push_back(pj);
31 return rtn;
32 }
33
35
36
39
41 using JetSelector = function<bool(const Jet&)>;
43 using JetSorter = function<bool(const Jet&, const Jet&)>;
44
45
48 virtual bool operator()(const Jet& p) const = 0;
49 virtual ~BoolJetFunctor() {}
50 };
51
52
54 struct BoolJetAND : public BoolJetFunctor {
55 BoolJetAND(const std::vector<JetSelector>& sels) : selectors(sels) {}
56 BoolJetAND(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
57 BoolJetAND(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
58 bool operator()(const Jet& j) const {
59 for (const JetSelector& sel : selectors) if (!sel(j)) return false;
60 return true;
61 }
62 std::vector<JetSelector> selectors;
63 };
65 inline BoolJetAND operator && (const JetSelector& a, const JetSelector& b) {
66 return BoolJetAND(a, b);
67 }
68
69
71 struct BoolJetOR : public BoolJetFunctor {
72 BoolJetOR(const std::vector<JetSelector>& sels) : selectors(sels) {}
73 BoolJetOR(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
74 BoolJetOR(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
75 bool operator()(const Jet& j) const {
76 for (const JetSelector& sel : selectors) if (sel(j)) return true;
77 return false;
78 }
79 std::vector<JetSelector> selectors;
80 };
82 inline BoolJetOR operator || (const JetSelector& a, const JetSelector& b) {
83 return BoolJetOR(a, b);
84 }
85
86
88 struct BoolJetNOT : public BoolJetFunctor {
89 BoolJetNOT(const JetSelector& sel) : selector(sel) {}
90 bool operator()(const Jet& j) const { return !selector(j); }
91 JetSelector selector;
92 };
95 return BoolJetNOT(a);
96 }
97
98
99
102 HasBTag(const Cut& c=Cuts::open()) : cut(c) {}
103 // HasBTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
104 bool operator() (const Jet& j) const { return j.bTagged(cut); }
105 // const std::function<bool(const Jet& j)> selector;
106 const Cut cut;
107 };
108 using hasBTag = HasBTag;
109
112 HasCTag(const Cut& c=Cuts::open()) : cut(c) {}
113 // HasCTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
114 bool operator() (const Jet& j) const { return j.cTagged(cut); }
115 // const std::function<bool(const Jet& j)> selector;
116 const Cut cut;
117 };
118 using hasCTag = HasCTag;
119
122 HasTauTag(const Cut& c=Cuts::open()) : cut(c) {}
123 // HasTauTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
124 bool operator() (const Jet& j) const { return j.tauTagged(cut); }
125 // const std::function<bool(const Jet& j)> selector;
126 const Cut cut;
127 };
128 using hasTauTag = HasTauTag;
129
132 HasNoTag(const Cut& c=Cuts::open(), bool quarktagsonly=false) : cut(c), qtagsonly(quarktagsonly) {}
133 // HasNoTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
134 bool operator() (const Jet& j) const { return !j.bTagged(cut) && !j.cTagged(cut) && (qtagsonly || !j.tauTagged(cut)); }
135 // const std::function<bool(const Jet& j)> selector;
136 const Cut cut;
137 bool qtagsonly;
138 };
139 using hasNoTag = HasNoTag;
140
142
143
146
148 Jets& ifilter_select(Jets& jets, const Cut& c);
151 inline Jets& ifilterBy(Jets& jets, const Cut& c) { return ifilter_select(jets, c); }
153 inline Jets& iselect(Jets& jets, const Cut& c) { return ifilter_select(jets, c); }
154
155
157 inline Jets filter_select(const Jets& jets, const Cut& c) {
158 Jets rtn = jets;
159 return ifilter_select(rtn, c);
160 }
163 inline Jets filterBy(const Jets& jets, const Cut& c) { return filter_select(jets, c); }
165 inline Jets select(const Jets& jets, const Cut& c) { return filter_select(jets, c); }
166
167
169 inline Jets filter_select(const Jets& jets, const Cut& c, Jets& out) {
170 out = filter_select(jets, c);
171 return out;
172 }
175 inline Jets filterBy(const Jets& jets, const Cut& c, Jets& out) { return filter_select(jets, c, out); }
177 inline Jets select(const Jets& jets, const Cut& c, Jets& out) { return filter_select(jets, c, out); }
178
179
180
182 Jets& ifilter_discard(Jets& jets, const Cut& c);
184 inline Jets& idiscard(Jets& jets, const Cut& c) { return ifilter_discard(jets, c); }
185
186
188 inline Jets filter_discard(const Jets& jets, const Cut& c) {
189 Jets rtn = jets;
190 return ifilter_discard(rtn, c);
191 }
193 inline Jets discard(const Jets& jets, const Cut& c) { return filter_discard(jets, c); }
194
195
197 inline Jets filter_discard(const Jets& jets, const Cut& c, Jets& out) {
198 out = filter_discard(jets, c);
199 return out;
200 }
202 inline Jets discard(const Jets& jets, const Cut& c, Jets& out) { return filter_discard(jets, c, out); }
203
205
206
207
211 namespace Kin {
212
213 inline double sumPt(const Jets& js) {
214 return sum(js, pT, 0.0);
215 }
216
217 inline FourMomentum sumP4(const Jets& js) {
218 return sum(js, p4, FourMomentum());
219 }
220
221 inline Vector3 sumP3(const Jets& js) {
222 return sum(js, p3, Vector3());
223 }
224
227
228 }
230
231
232 // Import Kin namespace into Rivet
233 using namespace Kin;
234
235
237
238}
239
240#endif
Representation of a clustered jet of particles.
Definition: Jet.hh:48
bool cTagged(const Cut &c=Cuts::open()) const
Does this jet have at least one c-tag (that passes an optional Cut)?
Definition: Jet.hh:153
bool bTagged(const Cut &c=Cuts::open()) const
Does this jet have at least one b-tag (that passes an optional Cut)?
Definition: Jet.hh:140
bool tauTagged(const Cut &c=Cuts::open()) const
Does this jet have at least one tau-tag (that passes an optional Cut)?
Definition: Jet.hh:166
Specialised vector of Jet objects.
Definition: Jet.hh:23
CONTAINER::value_type sum(const CONTAINER &c)
Generic sum function, adding x for all x in container c.
Definition: Utils.hh:445
Jets & idiscard(Jets &jets, const Cut &c)
New alias for ifilter_discard.
Definition: JetUtils.hh:184
Jets select(const Jets &jets, const Cut &c)
New alias for filter_select.
Definition: JetUtils.hh:165
Jets & iselect(Jets &jets, const Cut &c)
New alias for ifilter_select.
Definition: JetUtils.hh:153
Jets filterBy(const Jets &jets, const Cut &c)
Definition: JetUtils.hh:163
Jets filter_discard(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Definition: JetUtils.hh:188
Jets discard(const Jets &jets, const Cut &c)
New alias for filter_discard.
Definition: JetUtils.hh:193
Jets filter_select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition: JetUtils.hh:157
Jets & ifilter_select(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Jets & ifilter_discard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Jets & ifilterBy(Jets &jets, const Cut &c)
Definition: JetUtils.hh:151
function< bool(const Jet &)> JetSelector
std::function instantiation for functors taking a Jet and returning a bool
Definition: JetUtils.hh:41
function< bool(const Jet &, const Jet &)> JetSorter
std::function instantiation for functors taking two Jets and returning a bool
Definition: JetUtils.hh:43
double pT(const ParticleBase &p)
Unbound function access to pT.
Definition: ParticleBaseUtils.hh:656
FourMomentum p4(const ParticleBase &p)
Unbound function access to momentum.
Definition: ParticleBaseUtils.hh:644
Vector3 p3(const ParticleBase &p)
Unbound function access to p3.
Definition: ParticleBaseUtils.hh:647
double p(const ParticleBase &p)
Unbound function access to p.
Definition: ParticleBaseUtils.hh:653
const Cut & open()
Fully open cut singleton, accepts everything.
Definition: MC_Cent_pPb.hh:10
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:54
Base type for Jet -> bool functors.
Definition: JetUtils.hh:47
Functor for inverting selector logic.
Definition: JetUtils.hh:88
Functor for or-combination of selector logic.
Definition: JetUtils.hh:71
B-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:101
C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:111
Anti-B/C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:131
Tau-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:121