Rivet  3.1.0
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 
7 namespace 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)
19  rtn.push_back(p);
20  return rtn;
21  }
22 
23  inline PseudoJets mkPseudoJets(const Jets& js) {
24  PseudoJets rtn; rtn.reserve(js.size());
25  for (const Jet& j : js)
26  rtn.push_back(j);
27  return rtn;
28  }
29 
30  inline Jets mkJets(const PseudoJets& pjs) {
31  Jets rtn; rtn.reserve(pjs.size());
32  for (const PseudoJet& pj : pjs)
33  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 
50  struct BoolJetFunctor {
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) : selectors(sels) {}
59  BoolJetAND(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
60  BoolJetAND(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
61  bool operator()(const Jet& j) const {
62  for (const JetSelector& sel : selectors) if (!sel(j)) return false;
63  return true;
64  }
65  std::vector<JetSelector> selectors;
66  };
68  inline BoolJetAND operator && (const JetSelector& a, const JetSelector& b) {
69  return BoolJetAND(a, b);
70  }
71 
72 
74  struct BoolJetOR : public BoolJetFunctor {
75  BoolJetOR(const std::vector<JetSelector>& sels) : selectors(sels) {}
76  BoolJetOR(const JetSelector& a, const JetSelector& b) : selectors({a,b}) {}
77  BoolJetOR(const JetSelector& a, const JetSelector& b, const JetSelector& c) : selectors({a,b,c}) {}
78  bool operator()(const Jet& j) const {
79  for (const JetSelector& sel : selectors) if (sel(j)) return true;
80  return false;
81  }
82  std::vector<JetSelector> selectors;
83  };
85  inline BoolJetOR operator || (const JetSelector& a, const JetSelector& b) {
86  return BoolJetOR(a, b);
87  }
88 
89 
91  struct BoolJetNOT : public BoolJetFunctor {
92  BoolJetNOT(const JetSelector& sel) : selector(sel) {}
93  bool operator()(const Jet& j) const { return !selector(j); }
94  JetSelector selector;
95  };
97  inline BoolJetNOT operator ! (const JetSelector& a) {
98  return BoolJetNOT(a);
99  }
100 
101 
102 
105  HasBTag(const Cut& c=Cuts::open()) : cut(c) {}
106  // HasBTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
107  bool operator() (const Jet& j) const { return j.bTagged(cut); }
108  // const std::function<bool(const Jet& j)> selector;
109  const Cut cut;
110  };
111  using hasBTag = HasBTag;
112 
115  HasCTag(const Cut& c=Cuts::open()) : cut(c) {}
116  // HasCTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
117  bool operator() (const Jet& j) const { return j.cTagged(cut); }
118  // const std::function<bool(const Jet& j)> selector;
119  const Cut cut;
120  };
121  using hasCTag = HasCTag;
122 
125  HasTauTag(const Cut& c=Cuts::open()) : cut(c) {}
126  // HasTauTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
127  bool operator() (const Jet& j) const { return j.tauTagged(cut); }
128  // const std::function<bool(const Jet& j)> selector;
129  const Cut cut;
130  };
131  using hasTauTag = HasTauTag;
132 
135  HasNoTag(const Cut& c=Cuts::open(), bool quarktagsonly=false) : cut(c), qtagsonly(quarktagsonly) {}
136  // HasNoTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
137  bool operator() (const Jet& j) const { return !j.bTagged(cut) && !j.cTagged(cut) && (qtagsonly || !j.tauTagged(cut)); }
138  // const std::function<bool(const Jet& j)> selector;
139  const Cut cut;
140  bool qtagsonly;
141  };
142  using hasNoTag = HasNoTag;
143 
145 
146 
149 
151  Jets& ifilter_select(Jets& jets, const Cut& c);
154  inline Jets& ifilterBy(Jets& jets, const Cut& c) { return ifilter_select(jets, c); }
156  inline Jets& iselect(Jets& jets, const Cut& c) { return ifilter_select(jets, c); }
157 
158 
160  inline Jets filter_select(const Jets& jets, const Cut& c) {
161  Jets rtn = jets;
162  return ifilter_select(rtn, c);
163  }
166  inline Jets filterBy(const Jets& jets, const Cut& c) { return filter_select(jets, c); }
168  inline Jets select(const Jets& jets, const Cut& c) { return filter_select(jets, c); }
169 
170 
172  inline Jets filter_select(const Jets& jets, const Cut& c, Jets& out) {
173  out = filter_select(jets, c);
174  return out;
175  }
178  inline Jets filterBy(const Jets& jets, const Cut& c, Jets& out) { return filter_select(jets, c, out); }
180  inline Jets select(const Jets& jets, const Cut& c, Jets& out) { return filter_select(jets, c, out); }
181 
182 
183 
185  Jets& ifilter_discard(Jets& jets, const Cut& c);
187  inline Jets& idiscard(Jets& jets, const Cut& c) { return ifilter_discard(jets, c); }
188 
189 
191  inline Jets filter_discard(const Jets& jets, const Cut& c) {
192  Jets rtn = jets;
193  return ifilter_discard(rtn, c);
194  }
196  inline Jets discard(const Jets& jets, const Cut& c) { return filter_discard(jets, c); }
197 
198 
200  inline Jets filter_discard(const Jets& jets, const Cut& c, Jets& out) {
201  out = filter_discard(jets, c);
202  return out;
203  }
205  inline Jets discard(const Jets& jets, const Cut& c, Jets& out) { return filter_discard(jets, c, out); }
206 
208 
209 
210 
214  namespace Kin {
215 
216  inline double sumPt(const Jets& js) {
217  return sum(js, pT, 0.0);
218  }
219 
220  inline FourMomentum sumP4(const Jets& js) {
221  return sum(js, p4, FourMomentum());
222  }
223 
224  inline Vector3 sumP3(const Jets& js) {
225  return sum(js, p3, Vector3());
226  }
227 
230 
231  }
233 
234 
235  // Import Kin namespace into Rivet
236  using namespace Kin;
237 
238 
240 
241 }
242 
243 #endif
Definition: MC_Cent_pPb.hh:10
Functor for or-combination of selector logic.
Definition: JetUtils.hh:74
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:110
Cut operator!(const Cut &cptr)
Logical NOT operation on a cut.
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:160
function< bool(const Jet &)> JetSelector
std::function instantiation for functors taking a Jet and returning a bool
Definition: JetUtils.hh:44
C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:114
const Cut & open()
Fully open cut singleton, accepts everything.
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:136
B-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:104
Cut operator||(const Cut &aptr, const Cut &bptr)
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:191
Cut operator&&(const Cut &aptr, const Cut &bptr)
Anti-B/C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:134
Jets & ifilterBy(Jets &jets, const Cut &c)
Definition: JetUtils.hh:154
Jets discard(const Jets &jets, const Cut &c)
New alias for filter_discard.
Definition: JetUtils.hh:196
CONTAINER::value_type sum(const CONTAINER &c)
Generic sum function, adding x for all x in container c.
Definition: Utils.hh:422
Jets select(const Jets &jets, const Cut &c)
New alias for filter_select.
Definition: JetUtils.hh:168
function< bool(const Jet &, const Jet &)> JetSorter
std::function instantiation for functors taking two Jets and returning a bool
Definition: JetUtils.hh:46
Functor for and-combination of selector logic.
Definition: JetUtils.hh:57
std::vector< PseudoJet > PseudoJets
Definition: RivetFastJet.hh:29
Base type for Jet -> bool functors.
Definition: JetUtils.hh:50
Jets & ifilter_select(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Tau-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:124
Representation of a clustered jet of particles.
Definition: Jet.hh:18
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
Jets & iselect(Jets &jets, const Cut &c)
New alias for ifilter_select.
Definition: JetUtils.hh:156
Jets filterBy(const Jets &jets, const Cut &c)
Definition: JetUtils.hh:166
Specialized version of the FourVector with momentum/energy functionality.
Definition: Vector4.hh:301
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:123
Jets & ifilter_discard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Jets & idiscard(Jets &jets, const Cut &c)
New alias for ifilter_discard.
Definition: JetUtils.hh:187
Functor for inverting selector logic.
Definition: JetUtils.hh:91