rivet is hosted by Hepforge, IPPP Durham
Rivet  2.7.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 
11 
12 
13  inline PseudoJets mkPseudoJets(const Particles& ps) {
14  PseudoJets rtn; rtn.reserve(ps.size());
15  for (const Particle& p : ps)
16  rtn.push_back(p);
17  return rtn;
18  }
19 
20  inline PseudoJets mkPseudoJets(const Jets& js) {
21  PseudoJets rtn; rtn.reserve(js.size());
22  for (const Jet& j : js)
23  rtn.push_back(j);
24  return rtn;
25  }
26 
27  inline Jets mkJets(const PseudoJets& pjs) {
28  Jets rtn; rtn.reserve(pjs.size());
29  for (const PseudoJet& pj : pjs)
30  rtn.push_back(pj);
31  return rtn;
32  }
33 
35 
36 
38 
39 
41  using JetSelector = function<bool(const Jet&)>;
43  using JetSorter = function<bool(const Jet&, const Jet&)>;
44 
45 
47  struct BoolJetFunctor {
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  };
94  inline BoolJetNOT operator ! (const JetSelector& a) {
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  HasNoTag(const Cut& c=Cuts::open()) : cut(c) {}
123  // HasNoTag(const std::function<bool(const Jet& j)>& f) : selector(f) {}
124  bool operator() (const Jet& j) const { return !j.bTagged(cut) && j.cTagged(cut); }
125  // const std::function<bool(const Jet& j)> selector;
126  const Cut cut;
127  };
128  using hasNoTag = HasNoTag;
129 
131 
132 
134 
135 
137  Jets& ifilter_select(Jets& jets, const Cut& c);
140  inline Jets& ifilterBy(Jets& jets, const Cut& c) { return ifilter_select(jets, c); }
141 
143  inline Jets filter_select(const Jets& jets, const Cut& c) {
144  Jets rtn = jets;
145  return ifilter_select(rtn, c);
146  }
149  inline Jets filterBy(const Jets& jets, const Cut& c) { return filter_select(jets, c); }
150 
152  inline Jets filter_select(const Jets& jets, const Cut& c, Jets& out) {
153  out = filter_select(jets, c);
154  return out;
155  }
158  inline Jets filterBy(const Jets& jets, const Cut& c, Jets& out) { return filter_select(jets, c, out); }
159 
160 
162  Jets& ifilter_discard(Jets& jets, const Cut& c);
163 
165  inline Jets filter_discard(const Jets& jets, const Cut& c) {
166  Jets rtn = jets;
167  return ifilter_discard(rtn, c);
168  }
169 
171  inline Jets filter_discard(const Jets& jets, const Cut& c, Jets& out) {
172  out = filter_discard(jets, c);
173  return out;
174  }
175 
177 
178 
179 
182 
183  namespace Kin {
184 
185  inline double sumPt(const Jets& js) {
186  return sum(js, pT, 0.0);
187  }
188 
189  inline FourMomentum sumP4(const Jets& js) {
190  return sum(js, p4, FourMomentum());
191  }
192 
193  inline Vector3 sumP3(const Jets& js) {
194  return sum(js, p3, Vector3());
195  }
196 
199 
200  }
202 
203 
204  // Import Kin namespace into Rivet
205  using namespace Kin;
206 
207 
208 }
209 
210 #endif
Definition: ALICE_2010_I880049.cc:13
Functor for or-combination of selector logic.
Definition: JetUtils.hh:71
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.
Definition: Cuts.cc:324
C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:111
Jets & ifilter_discard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
Definition: JetUtils.cc:14
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:165
B-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:101
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:143
Cut operator||(const Cut &aptr, const Cut &bptr)
Definition: Cuts.cc:320
Cut operator&&(const Cut &aptr, const Cut &bptr)
Operators.
Definition: Cuts.cc:316
const Cut & open()
Fully open cut singleton, accepts everything.
Definition: Cuts.cc:81
Anti-B/C-tagging functor, with a tag selection cut as the stored state.
Definition: JetUtils.hh:121
T sum(const CONTAINER &c, const T &start=T())
Generic sum function, adding x for all x in container c, starting with start.
Definition: Utils.hh:345
Jets filterBy(const Jets &jets, const Cut &c)
Definition: JetUtils.hh:149
Functor for and-combination of selector logic.
Definition: JetUtils.hh:54
std::vector< PseudoJet > PseudoJets
Definition: RivetFastJet.hh:24
Base type for Jet -> bool functors.
Definition: JetUtils.hh:47
Representation of a clustered jet of particles.
Definition: Jet.hh:18
Jets & ifilterBy(Jets &jets, const Cut &c)
Definition: JetUtils.hh:140
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
function< bool(const Jet &)> JetSelector
std::function instantiation for functors taking a Jet and returning a bool
Definition: JetUtils.hh:41
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
Functor for inverting selector logic.
Definition: JetUtils.hh:88
Jets & ifilter_select(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition: JetUtils.cc:7
function< bool(const Jet &, const Jet &)> JetSorter
std::function instantiation for functors taking two Jets and returning a bool
Definition: JetUtils.hh:43