rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
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& iselect(Jets& jets, const Cut& c);
149
150
152 inline Jets select(const Jets& jets, const Cut& c) {
153 Jets rtn = jets;
154 return iselect(rtn, c);
155 }
156
157
159 inline Jets select(const Jets& jets, const Cut& c, Jets& out) {
160 out = select(jets, c);
161 return out;
162 }
163
164
165
167 Jets& idiscard(Jets& jets, const Cut& c);
168
169
171 inline Jets discard(const Jets& jets, const Cut& c) {
172 Jets rtn = jets;
173 return idiscard(rtn, c);
174 }
175
176
178 inline Jets discard(const Jets& jets, const Cut& c, Jets& out) {
179 out = discard(jets, c);
180 return out;
181 }
182
184
185
188
192 Jets trimJetsFrac(const PseudoJets& jetsIn, const double frac=0.1);
193
195
196
197
201 namespace Kin {
202
204 inline double pT(const Jet& j) {
205 return j.pT();
206 }
207
208 inline double sumPt(const Jets& js) {
209 return sum(js, Kin::pT, 0.0);
210 }
211
212 inline FourMomentum sumP4(const Jets& js) {
213 return sum(js, Kin::p4, FourMomentum());
214 }
215
216 inline Vector3 sumP3(const Jets& js) {
217 return sum(js, Kin::p3, Vector3());
218 }
219
222
223 }
225
226
227 // Import Kin namespace into Rivet
228 using namespace Kin;
229
230
232
233}
234
235#endif
Representation of a clustered jet of particles.
Definition Jet.hh:42
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:147
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:134
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:160
Specialised vector of Jet objects.
Definition Jet.hh:21
double pT() const
Get the directly (alias).
Definition ParticleBase.hh:63
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:152
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:171
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
Jets trimJetsFrac(const PseudoJets &jetsIn, const double frac=0.1)
const Cut & open()
Fully open cut singleton, accepts everything.
Definition MC_CENT_PPB_Projections.hh:10
Cut operator!(const Cut &cptr)
Logical NOT operation on a cut.
Cut operator&&(const Cut &aptr, const Cut &bptr)
T sum(const DressedLeptons &c, FN &&fn, const T &start=T())
Generic sum function, adding fn(x) for all x in container c, starting with start.
Definition DressedLepton.hh:60
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