1#ifndef RIVET_PARTICLEBASEUTILS_HH
2#define RIVET_PARTICLEBASEUTILS_HH
4#include "Rivet/ParticleBase.hh"
33 PtGtr(
double pt) : ptcut(pt) { }
35 bool operator()(
const ParticleBase&
p)
const {
return p.pT() > ptcut; }
44 PtLess(
double pt) : ptcut(pt) { }
45 bool operator()(
const ParticleBase&
p)
const {
return p.pT() < ptcut; }
53 PtInRange(pair<double, double> ptcuts) : ptcut(ptcuts) { }
56 bool operator()(
const ParticleBase&
p)
const {
return p.pT() >= ptcut.first &&
p.pT() < ptcut.second; }
57 pair<double,double> ptcut;
67 bool operator()(
const ParticleBase&
p)
const {
return p.eta() > etacut; }
76 bool operator()(
const ParticleBase&
p)
const {
return p.eta() < etacut; }
83 EtaInRange(pair<double, double> etacuts) : etacut(etacuts) { }
86 bool operator()(
const ParticleBase&
p)
const {
return p.eta() >= etacut.first &&
p.eta() < etacut.second; }
87 pair<double,double> etacut;
96 bool operator()(
const ParticleBase&
p)
const {
return p.abseta() > absetacut; }
106 bool operator()(
const ParticleBase&
p)
const {
return p.abseta() < absetacut; }
114 AbsEtaInRange(
const pair<double, double>& absetacuts) : absetacut(absetacuts) { }
117 bool operator()(
const ParticleBase&
p)
const {
return p.abseta() >= absetacut.first &&
p.abseta() < absetacut.second; }
118 pair<double,double> absetacut;
128 bool operator()(
const ParticleBase&
p)
const {
return p.rap() > rapcut; }
137 bool operator()(
const ParticleBase&
p)
const {
return p.rap() < rapcut; }
144 RapInRange(
const pair<double, double>& rapcuts) : rapcut(rapcuts) { }
147 bool operator()(
const ParticleBase&
p)
const {
return p.rap() >= rapcut.first &&
p.rap() < rapcut.second; }
148 pair<double,double> rapcut;
157 bool operator()(
const ParticleBase&
p)
const {
return p.absrap() > absrapcut; }
167 bool operator()(
const ParticleBase&
p)
const {
return p.absrap() < absrapcut; }
175 AbsRapInRange(
const pair<double, double>& absrapcuts) : absrapcut(absrapcuts) { }
178 bool operator()(
const ParticleBase&
p)
const {
return p.absrap() >= absrapcut.first &&
p.absrap() < absrapcut.second; }
179 pair<double,double> absrapcut;
191 : refvec(vec.
mom()), drcut(dr), rapscheme(scheme) { }
193 : refvec(vec), drcut(dr), rapscheme(scheme) { }
195 : drcut(dr), rapscheme(PSEUDORAPIDITY) { refvec.
setPx(vec.x()); refvec.
setPy(vec.y()); refvec.
setPz(vec.z()); }
206 : refvec(vec.
mom()), drcut(dr), rapscheme(scheme) { }
208 : refvec(vec), drcut(dr), rapscheme(scheme) { }
210 : drcut(dr), rapscheme(PSEUDORAPIDITY) { refvec.
setPx(vec.x()); refvec.
setPy(vec.y()); refvec.
setPz(vec.z()); }
221 : refvec(vec.
mom()), drcut(dr), rapscheme(scheme) { }
225 : refvec(vec), drcut(dr), rapscheme(scheme) { }
229 : drcut(dr), rapscheme(PSEUDORAPIDITY) { refvec.
setPx(vec.x()); refvec.
setPy(vec.y()); refvec.
setPz(vec.z()); }
233 const double dR =
deltaR(
p, refvec, rapscheme);
234 return dR >= drcut.first && dR < drcut.second;
237 pair<double,double> drcut;
246 : refvec(vec.
p3()), dphicut(dphi) { }
248 : refvec(vec.
p3()), dphicut(dphi) { }
250 : refvec(vec), dphicut(dphi) { }
260 : refvec(vec.
p3()), dphicut(dphi) { }
262 : refvec(vec.
p3()), dphicut(dphi) { }
264 : refvec(vec), dphicut(dphi) { }
274 : refvec(vec.
mom()), dphicut(dphi) { }
278 : refvec(vec), dphicut(dphi) { }
282 : refvec(vec), dphicut(dphi) { }
287 return dphi >= dphicut.first && dphi < dphicut.second;
290 pair<double,double> dphicut;
298 : refvec(vec.
p3()), detacut(deta) { }
300 : refvec(vec.
p3()), detacut(deta) { }
302 : refvec(vec), detacut(deta) { }
312 : refvec(vec.
p3()), detacut(deta) { }
314 : refvec(vec.
p3()), detacut(deta) { }
316 : refvec(vec), detacut(deta) { }
326 : refvec(vec.
mom()), detacut(deta) { }
330 : refvec(vec), detacut(deta) { }
334 : refvec(vec), detacut(deta) { }
339 return deta >= detacut.first && deta < detacut.second;
342 pair<double,double> detacut;
350 : refvec(vec.
mom()), drapcut(drap) { }
352 : refvec(vec), drapcut(drap) { }
362 : refvec(vec.
mom()), drapcut(drap) { }
364 : refvec(vec), drapcut(drap) { }
374 : refvec(vec.
mom()), drapcut(drap) { }
378 : refvec(vec), drapcut(drap) { }
383 return drap >= drapcut.first && drap < drapcut.second;
386 pair<double,double> drapcut;
480 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
481 inline void idiscardIfAny(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
482 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
483 const typename PBCONTAINER2::value_type&)> fn) {
484 for (
const auto& pbcmp : tocompare) {
485 ifilter_discard(tofilter, [&](
const typename PBCONTAINER1::value_type& pbfilt){
return fn(pbfilt, pbcmp); });
489 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
490 inline PBCONTAINER1 discardIfAny(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
491 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
492 const typename PBCONTAINER2::value_type&)> fn) {
493 PBCONTAINER1 tmp{tofilter};
494 idiscardIfAny(tmp, tocompare, fn);
499 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
500 inline PBCONTAINER1 selectIfAny(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
501 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
502 const typename PBCONTAINER2::value_type&)> fn) {
503 PBCONTAINER1 selected;
504 for (
const auto& pbfilt : tofilter) {
505 if (
any(tocompare, [&](
const typename PBCONTAINER2::value_type& pbcmp){
return fn(pbfilt, pbcmp); })) {
512 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
513 inline void iselectIfAny(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
514 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
515 const typename PBCONTAINER2::value_type&)> fn) {
516 tofilter = selectIfAny(tofilter, tocompare, fn);
521 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
522 inline PBCONTAINER1 discardIfAll(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
523 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
524 const typename PBCONTAINER2::value_type&)> fn) {
525 PBCONTAINER1 selected;
526 for (
const auto& pbfilt : tofilter) {
527 if (!
all(tocompare, [&](
const typename PBCONTAINER2::value_type& pbcmp){
return fn(pbfilt, pbcmp); })) {
534 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
535 inline void idiscardIfAll(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
536 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
537 const typename PBCONTAINER2::value_type&)> fn) {
538 tofilter = discardIfAll(tofilter, tocompare, fn);
542 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
543 inline PBCONTAINER1 selectIfAll(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
544 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
545 const typename PBCONTAINER2::value_type&)> fn) {
546 PBCONTAINER1 selected;
547 for (
const auto& pbfilt : tofilter) {
548 if (
all(tocompare, [&](
const typename PBCONTAINER2::value_type& pbcmp){
return fn(pbfilt, pbcmp); })) {
555 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
556 inline void iselectIfAll(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
557 typename std::function<
bool(
const typename PBCONTAINER1::value_type&,
558 const typename PBCONTAINER2::value_type&)> fn) {
559 tofilter = selectIfAll(tofilter, tocompare, fn);
568 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
569 inline void idiscardIfAnyDeltaRLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dR,
RapScheme scheme=PSEUDORAPIDITY) {
570 for (
const typename PBCONTAINER2::value_type& pb : tocompare) {
575 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
576 inline PBCONTAINER1 discardIfAnyDeltaRLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dR) {
577 PBCONTAINER1 tmp{tofilter};
578 idiscardIfAnyDeltaRLess(tmp, tocompare, dR);
582 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
583 inline void idiscardIfAnyDeltaPhiLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dphi) {
584 for (
const typename PBCONTAINER2::value_type& pb : tocompare) {
589 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
590 inline PBCONTAINER1 discardIfAnyDeltaEtaLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double deta) {
591 PBCONTAINER1 tmp{tofilter};
592 idiscardIfAnyDeltaEtaLess(tmp, tocompare, deta);
596 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
597 inline void idiscardIfAnyDeltaEtaLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double deta) {
598 for (
const typename PBCONTAINER2::value_type& pb : tocompare) {
603 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
604 inline PBCONTAINER1 discardIfAnyDeltaPhiLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dphi) {
605 PBCONTAINER1 tmp{tofilter};
606 idiscardIfAnyDeltaPhiLess(tmp, tocompare, dphi);
612 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
613 inline PBCONTAINER1 selectIfAnyDeltaRLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
614 double dR,
RapScheme scheme=PSEUDORAPIDITY) {
615 PBCONTAINER1 selected;
616 for (
const typename PBCONTAINER1::value_type& f : tofilter) {
617 if (
any(tocompare, deltaRLess(f, dR, scheme))) selected.push_back(f);
622 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
623 inline void iselectIfAnyDeltaRLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dR) {
624 tofilter = selectIfAnyDeltaRLess(tofilter, tocompare, dR);
628 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
629 inline PBCONTAINER1 selectIfAnyDeltaPhiLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dphi) {
630 PBCONTAINER1 selected;
631 for (
const typename PBCONTAINER1::value_type& f : tofilter) {
632 if (
any(tocompare, deltaPhiLess(f, dphi))) selected.push_back(f);
637 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
638 inline void iselectIfAnyDeltaPhiLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double dphi) {
639 tofilter = selectIfAnyDeltaPhiLess(tofilter, tocompare, dphi);
643 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
644 inline PBCONTAINER1 selectIfAnyDeltaEtaLess(
const PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double deta) {
645 PBCONTAINER1 selected;
646 for (
const typename PBCONTAINER1::value_type& f : tofilter) {
647 if (
any(tocompare, deltaEtaLess(f, deta))) selected.push_back(f);
652 template<
typename PBCONTAINER1,
typename PBCONTAINER2>
653 inline void iselectIfAnyDeltaEtaLess(PBCONTAINER1& tofilter,
const PBCONTAINER2& tocompare,
double deta) {
654 tofilter = selectIfAnyDeltaEtaLess(tofilter, tocompare, deta);
Specialized version of the FourVector with momentum/energy functionality.
Definition Vector4.hh:316
Base class for particle-like things like Particle and Jet.
Definition ParticleBase.hh:13
const FourMomentum & mom() const
Get equivalent single momentum four-vector (const) (alias).
Definition ParticleBase.hh:39
ThreeMomentum p3() const
Get the 3-momentum directly.
Definition ParticleBase.hh:108
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
double mod() const
Calculate the modulus of a vector. .
Definition VectorN.hh:95
bool all(const CONTAINER &c)
Return true if x is true for all x in container c, otherwise false.
Definition Utils.hh:347
bool any(const CONTAINER &c)
Return true if x is true for any x in container c, otherwise false.
Definition Utils.hh:325
Jets & ifilter_discard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
FourMomentum & setPz(double pz)
Set z-component of momentum .
Definition Vector4.hh:370
Vector3 vector3() const
Get the spatial part of the 4-vector as a 3-vector.
Definition Vector4.hh:177
double abseta() const
Get the directly (alias).
Definition Vector4.hh:174
FourMomentum & setPy(double py)
Set y-component of momentum .
Definition Vector4.hh:364
double rap() const
Alias for rapidity.
Definition Vector4.hh:611
FourMomentum & setPx(double px)
Set x-component of momentum .
Definition Vector4.hh:358
double eta() const
Synonym for pseudorapidity.
Definition Vector4.hh:167
double absrap() const
Absolute rapidity.
Definition Vector4.hh:620
double pT() const
Calculate the transverse momentum .
Definition Vector4.hh:643
function< bool(const ParticleBase &)> ParticleBaseSelector
std::function instantiation for functors taking a ParticleBase and returning a bool
Definition ParticleBaseUtils.hh:19
function< bool(const ParticleBase &, const ParticleBase &)> ParticleBaseSorter
std::function instantiation for functors taking two ParticleBase and returning a bool
Definition ParticleBaseUtils.hh:21
double pT(const ParticleBase &p)
Unbound function access to pT.
Definition ParticleBaseUtils.hh:687
FourMomentum p4(const ParticleBase &p)
Unbound function access to momentum.
Definition ParticleBaseUtils.hh:675
Vector3 pTvec(const ParticleBase &p)
Unbound function access to pTvec.
Definition ParticleBaseUtils.hh:681
Vector3 p3(const ParticleBase &p)
Unbound function access to p3.
Definition ParticleBaseUtils.hh:678
FourMomentum mom(const ParticleBase &p)
Unbound function access to momentum.
Definition ParticleBaseUtils.hh:673
double absrap(const ParticleBase &p)
Unbound function access to abs rapidity.
Definition ParticleBaseUtils.hh:702
double eta(const ParticleBase &p)
Unbound function access to eta.
Definition ParticleBaseUtils.hh:693
double mass(const ParticleBase &p)
Unbound function access to mass.
Definition ParticleBaseUtils.hh:705
double pairPt(const ParticleBase &p1, const ParticleBase &p2)
Unbound function access to pair pT.
Definition ParticleBaseUtils.hh:709
double rap(const ParticleBase &p)
Unbound function access to rapidity.
Definition ParticleBaseUtils.hh:699
double Et(const ParticleBase &p)
Unbound function access to ET.
Definition ParticleBaseUtils.hh:690
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:684
double abseta(const ParticleBase &p)
Unbound function access to abseta.
Definition ParticleBaseUtils.hh:696
double pairMass(const ParticleBase &p1, const ParticleBase &p2)
Unbound function access to pair mass.
Definition ParticleBaseUtils.hh:712
Definition MC_Cent_pPb.hh:10
double deltaR(double rap1, double phi1, double rap2, double phi2)
Definition MathUtils.hh:699
double deltaPhi(double phi1, double phi2, bool sign=false)
Calculate the difference between two angles in radians.
Definition MathUtils.hh:669
double deltaEta(double eta1, double eta2, bool sign=false)
Definition MathUtils.hh:677
RapScheme
Enum for rapidity variable to be used in calculating , applying rapidity cuts, etc.
Definition MathConstants.hh:46
double deltaRap(double y1, double y2, bool sign=false)
Definition MathUtils.hh:685
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:443
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:465
Abs pseudorapidity greater-than functor.
Definition ParticleBaseUtils.hh:93
Abs pseudorapidity in-range functor.
Definition ParticleBaseUtils.hh:113
Abs pseudorapidity momentum less-than functor.
Definition ParticleBaseUtils.hh:103
Abs rapidity greater-than functor.
Definition ParticleBaseUtils.hh:154
Abs rapidity in-range functor.
Definition ParticleBaseUtils.hh:174
Abs rapidity momentum less-than functor.
Definition ParticleBaseUtils.hh:164
Base type for Particle -> bool functors.
Definition ParticleBaseUtils.hh:25
(with respect to another momentum, vec) greater-than functor
Definition ParticleBaseUtils.hh:296
(with respect to another 4-momentum, vec) in-range functor
Definition ParticleBaseUtils.hh:324
(with respect to another momentum, vec) less-than functor
Definition ParticleBaseUtils.hh:310
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:431
(with respect to another momentum, vec) greater-than functor
Definition ParticleBaseUtils.hh:244
(with respect to another 4-momentum, vec) in-range functor
Definition ParticleBaseUtils.hh:272
(with respect to another momentum, vec) less-than functor
Definition ParticleBaseUtils.hh:258
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:419
(with respect to another 4-momentum, vec) greater-than functor
Definition ParticleBaseUtils.hh:189
(with respect to another 4-momentum, vec) in-range functor
Definition ParticleBaseUtils.hh:219
(with respect to another 4-momentum, vec) less-than functor
Definition ParticleBaseUtils.hh:204
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:406
(with respect to another momentum, vec) greater-than functor
Definition ParticleBaseUtils.hh:348
(with respect to another 4-momentum, vec) in-range functor
Definition ParticleBaseUtils.hh:372
(with respect to another momentum, vec) less-than functor
Definition ParticleBaseUtils.hh:360
Calculator of with respect to a given momentum.
Definition ParticleBaseUtils.hh:455
Base type for Particle -> double functors.
Definition ParticleBaseUtils.hh:400
Pseudorapidity greater-than functor.
Definition ParticleBaseUtils.hh:64
Pseudorapidity in-range functor.
Definition ParticleBaseUtils.hh:82
Pseudorapidity less-than functor.
Definition ParticleBaseUtils.hh:73
Transverse momentum greater-than functor.
Definition ParticleBaseUtils.hh:32
Transverse momentum in-range functor.
Definition ParticleBaseUtils.hh:52
Transverse momentum less-than functor.
Definition ParticleBaseUtils.hh:42
Rapidity greater-than functor.
Definition ParticleBaseUtils.hh:125
Rapidity in-range functor.
Definition ParticleBaseUtils.hh:143
Rapidity momentum less-than functor.
Definition ParticleBaseUtils.hh:134