1 #ifndef RIVET_PARTICLEUTILS_HH 2 #define RIVET_PARTICLEUTILS_HH 4 #include "Rivet/Particle.hh" 5 #include "Rivet/Tools/ParticleBaseUtils.hh" 6 #include "Rivet/Tools/ParticleIdUtils.hh" 9 #define PARTICLE_TO_PID_BOOLFN(fname) inline bool fname (const Particle& p) { return PID:: fname (p.pid()); } 10 #define PARTICLE_TO_PID_INTFN(fname) inline int fname (const Particle& p) { return PID:: fname (p.pid()); } 11 #define PARTICLE_TO_PID_DBLFN(fname) inline double fname (const Particle& p) { return PID:: fname (p.pid()); } 30 PARTICLE_TO_PID_BOOLFN(isCharged)
33 PARTICLE_TO_PID_BOOLFN(isNeutral)
37 PARTICLE_TO_PID_BOOLFN(isNeutrino)
40 PARTICLE_TO_PID_BOOLFN(isChargedLepton)
41 PARTICLE_TO_PID_BOOLFN(isChLepton)
44 PARTICLE_TO_PID_BOOLFN(isLepton)
47 PARTICLE_TO_PID_BOOLFN(isPhoton)
50 PARTICLE_TO_PID_BOOLFN(isElectron)
53 PARTICLE_TO_PID_BOOLFN(isMuon)
56 PARTICLE_TO_PID_BOOLFN(isTau)
59 PARTICLE_TO_PID_BOOLFN(isHadron)
62 PARTICLE_TO_PID_BOOLFN(isMeson)
65 PARTICLE_TO_PID_BOOLFN(isBaryon)
68 PARTICLE_TO_PID_BOOLFN(isQuark)
71 PARTICLE_TO_PID_BOOLFN(isParton)
76 PARTICLE_TO_PID_BOOLFN(isWplus)
79 PARTICLE_TO_PID_BOOLFN(isWminus)
82 PARTICLE_TO_PID_BOOLFN(isW)
85 PARTICLE_TO_PID_BOOLFN(isZ)
88 PARTICLE_TO_PID_BOOLFN(isHiggs)
91 PARTICLE_TO_PID_BOOLFN(isStrange)
94 PARTICLE_TO_PID_BOOLFN(isCharm)
97 PARTICLE_TO_PID_BOOLFN(isBottom)
100 PARTICLE_TO_PID_BOOLFN(isTop)
104 PARTICLE_TO_PID_BOOLFN(isHeavyFlavour)
107 PARTICLE_TO_PID_BOOLFN(isHeavyParton)
110 PARTICLE_TO_PID_BOOLFN(isLightParton)
114 PARTICLE_TO_PID_BOOLFN(isHeavyMeson)
117 PARTICLE_TO_PID_BOOLFN(isHeavyBaryon)
120 PARTICLE_TO_PID_BOOLFN(isHeavyHadron)
124 PARTICLE_TO_PID_BOOLFN(isLightMeson)
127 PARTICLE_TO_PID_BOOLFN(isLightBaryon)
130 PARTICLE_TO_PID_BOOLFN(isLightHadron)
134 PARTICLE_TO_PID_BOOLFN(isBottomMeson)
137 PARTICLE_TO_PID_BOOLFN(isBottomBaryon)
140 PARTICLE_TO_PID_BOOLFN(isBottomHadron)
144 PARTICLE_TO_PID_BOOLFN(isCharmMeson)
150 PARTICLE_TO_PID_BOOLFN(isCharmBaryon)
157 PARTICLE_TO_PID_BOOLFN(isCharmHadron)
172 PARTICLE_TO_PID_BOOLFN(isReggeon)
175 PARTICLE_TO_PID_BOOLFN(isDiquark)
178 PARTICLE_TO_PID_BOOLFN(isPentaquark)
181 PARTICLE_TO_PID_BOOLFN(isSUSY)
184 PARTICLE_TO_PID_BOOLFN(isRhadron)
187 PARTICLE_TO_PID_BOOLFN(isTechnicolor)
190 PARTICLE_TO_PID_BOOLFN(isExcited)
193 PARTICLE_TO_PID_BOOLFN(isKK)
196 PARTICLE_TO_PID_BOOLFN(isGraviton)
199 PARTICLE_TO_PID_BOOLFN(isBSM)
204 PARTICLE_TO_PID_BOOLFN(isGenSpecific)
207 PARTICLE_TO_PID_BOOLFN(isResonance)
210 PARTICLE_TO_PID_BOOLFN(isTransportable)
215 PARTICLE_TO_PID_BOOLFN(hasUp)
218 PARTICLE_TO_PID_BOOLFN(hasDown)
221 PARTICLE_TO_PID_BOOLFN(hasStrange)
224 PARTICLE_TO_PID_BOOLFN(hasCharm)
227 PARTICLE_TO_PID_BOOLFN(hasBottom)
230 PARTICLE_TO_PID_BOOLFN(hasTop)
235 PARTICLE_TO_PID_INTFN(jSpin)
238 PARTICLE_TO_PID_INTFN(sSpin)
241 PARTICLE_TO_PID_INTFN(lSpin)
245 PARTICLE_TO_PID_DBLFN(charge)
248 PARTICLE_TO_PID_INTFN(charge3)
251 PARTICLE_TO_PID_DBLFN(abscharge)
254 PARTICLE_TO_PID_INTFN(abscharge3)
257 PARTICLE_TO_PID_INTFN(nuclZ)
260 PARTICLE_TO_PID_INTFN(nuclA)
263 PARTICLE_TO_PID_INTFN(nuclNlambda)
273 inline bool isSameSign(
const Particle& a,
const Particle& b) {
return PID::isSameSign(a.
pid(), b.
pid()); }
275 inline bool isSameFlav(
const Particle& a,
const Particle& b) {
return PID::isSameFlav(a.
pid(), b.
pid()); }
419 inline bool isDirect(
const Particle& p,
bool allow_from_direct_tau=
false,
bool allow_from_direct_mu=
false) {
420 return p.
isDirect(allow_from_direct_tau, allow_from_direct_mu);
427 inline bool isPrompt(
const Particle& p,
bool allow_from_prompt_tau=
false,
bool allow_from_prompt_mu=
false) {
428 return p.
isPrompt(allow_from_prompt_tau, allow_from_prompt_mu);
465 return p.
fromTau(prompt_taus_only);
485 virtual bool operator()(
const Particle& p)
const = 0;
491 BoolParticleAND(
const std::vector<ParticleSelector>& sels) : selectors(sels) {}
492 BoolParticleAND(
const ParticleSelector& a,
const ParticleSelector& b) : selectors({a,b}) {}
493 BoolParticleAND(
const ParticleSelector& a,
const ParticleSelector& b,
const ParticleSelector& c) : selectors({a,b,c}) {}
494 bool operator()(
const Particle& p)
const {
495 for (
const ParticleSelector& sel : selectors)
if (!sel(p))
return false;
498 std::vector<ParticleSelector> selectors;
508 BoolParticleOR(
const std::vector<ParticleSelector>& sels) : selectors(sels) {}
509 BoolParticleOR(
const ParticleSelector& a,
const ParticleSelector& b) : selectors({a,b}) {}
510 BoolParticleOR(
const ParticleSelector& a,
const ParticleSelector& b,
const ParticleSelector& c) : selectors({a,b,c}) {}
511 bool operator()(
const Particle& p)
const {
512 for (
const ParticleSelector& sel : selectors)
if (sel(p))
return true;
515 std::vector<ParticleSelector> selectors;
525 bool operator()(
const Particle& p)
const {
return !selector(p); }
526 ParticleSelector selector;
537 HasPID(vector<PdgId>
pids) : targetpids{pids} { }
538 HasPID(initializer_list<PdgId> pids) : targetpids{pids} { }
540 vector<PdgId> targetpids;
547 HasAbsPID(vector<PdgId>
pids) {
for (PdgId pid : pids) targetapids.push_back(abs(pid)); }
548 HasAbsPID(initializer_list<PdgId> pids) {
for (PdgId pid : pids) targetapids.push_back(abs(pid)); }
550 vector<PdgId> targetapids;
576 template <
typename FN>
580 std::function<bool(const Particle&)> fn;
596 HasParticleAncestorWith(
const ParticleSelector& f,
bool only_physical=
true) : fn(f), onlyphysical(only_physical) { }
655 HasParticleDescendantWith(
const ParticleSelector& f,
bool remove_duplicates=
true) : fn(f), rmduplicates(remove_duplicates) { }
689 Particles rtn = particles;
699 inline Particles
filter_select(
const Particles& particles,
const Cut& c, Particles& out) {
705 inline Particles
filterBy(
const Particles& particles,
const Cut& c, Particles& out) {
return filter_select(particles, c, out); }
707 inline Particles
select(
const Particles& particles,
const Cut& c, Particles& out) {
return filter_select(particles, c, out); }
717 Particles rtn = particles;
724 inline Particles
filter_discard(
const Particles& particles,
const Cut& c, Particles& out) {
729 inline Particles
discard(
const Particles& particles,
const Cut& c, Particles& out) {
return filter_discard(particles, c, out); }
749 inline PdgIdPair
pids(
const ParticlePair& pp) {
750 return make_pair(pp.first.pid(), pp.second.pid());
763 inline double sumPt(
const Particles& ps) {
764 return sum(ps, pT, 0.0);
771 inline Vector3 sumP3(
const Particles& ps) {
Definition: MC_Cent_pPb.hh:10
bool diffCharge(const Particle &a, const Particle &b)
Return true if Particles a and b have a different (not necessarily opposite) charge.
Definition: ParticleUtils.hh:314
bool hasAncestor(const Particle &p, PdgId pid)
Definition: ParticleUtils.hh:452
bool hasDescendantWith(const Particle &p, const ParticleSelector &f, bool remove_duplicates=true)
Determine whether a particle has a descendant which meets the function requirement.
Definition: ParticleUtils.hh:386
bool fromHadron() const
Determine whether the particle is from a hadron decay.
bool sameCharge(const Particle &a, const Particle &b)
Definition: ParticleUtils.hh:309
Cut operator!(const Cut &cptr)
Logical NOT operation on a cut.
Base type for Particle -> bool functors.
Definition: ParticleUtils.hh:484
bool hasAncestorWithout(const Particle &p, const ParticleSelector &f, bool only_physical=true)
Determine whether a particle has an ancestor which doesn't meet the function requirement.
Definition: ParticleUtils.hh:358
bool fromCharm() const
Determine whether the particle is from a c-hadron decay.
bool hasStableDescendantWith(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a stable descendant which meets the function requirement.
Definition: ParticleUtils.hh:397
bool isFirstWithout(const Particle &p, const ParticleSelector &f)
Determine whether a particle is the first in a decay chain not to meet the function requirement...
Definition: ParticleUtils.hh:335
bool isFirstWithout(const ParticleSelector &f) const
Determine whether a particle is the first in a decay chain not to meet the function requirement...
Definition: Particle.hh:671
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
bool hasDescendantWith(const ParticleSelector &f, bool remove_duplicates=true) const
Definition: Particle.hh:586
bool isStable() const
Whether this particle is stable according to the generator.
bool oppCharge(const Particle &a, const Particle &b)
Definition: ParticleUtils.hh:303
Determine whether a particle is the last in a decay chain not to meet the cut/function.
Definition: ParticleUtils.hh:585
bool fromTau(const Particle &p, bool prompt_taus_only=false)
Determine whether the particle is from a tau decay.
Definition: ParticleUtils.hh:464
PID matching functor.
Definition: ParticleUtils.hh:535
PdgId pid() const
This Particle's PDG ID code.
Definition: Particle.hh:162
bool hasAncestorWith(const ParticleSelector &f, bool only_physical=true) const
Definition: Particle.hh:403
Particle representation, either from a HepMC::GenEvent or reconstructed.
Definition: Particle.hh:18
Functor for and-combination of selector logic.
Definition: ParticleUtils.hh:490
int pid(const Particle &p)
Unbound function access to PID code.
Definition: ParticleUtils.hh:23
bool isVisible(const Particle &p)
Is this particle potentially visible in a detector?
Definition: ParticleUtils.hh:409
|PID| matching functor
Definition: ParticleUtils.hh:545
bool hasStableDescendantWith(const ParticleSelector &f) const
Definition: Particle.hh:628
bool isStable(const Particle &p)
Decide if a given particle is stable, via Particle::isStable()
Definition: ParticleUtils.hh:433
bool hasChildWith(const ParticleSelector &f) const
Definition: Particle.hh:547
bool oppSign(const Particle &a, const Particle &b)
Return true if Particles a and b have the opposite charge sign.
Definition: ParticleUtils.hh:291
bool hasStableDescendantWithout(const ParticleSelector &f) const
Definition: Particle.hh:643
Functor for inverting selector logic.
Definition: ParticleUtils.hh:523
bool isLastWith(const Particle &p, const ParticleSelector &f)
Determine whether a particle is the last in a decay chain to meet the function requirement.
Definition: ParticleUtils.hh:341
Cut operator||(const Cut &aptr, const Cut &bptr)
Determine whether a particle has an ancestor which doesn't meet the cut/function. ...
Definition: ParticleUtils.hh:605
bool fromPromptTau() const
Determine whether the particle is from a prompt tau decay.
Definition: Particle.hh:484
Determine whether a particle is the first in a decay chain to meet the cut/function.
Definition: ParticleUtils.hh:556
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
Determine whether a particle is the first in a decay chain not to meet the cut/function.
Definition: ParticleUtils.hh:565
bool hasChildWithout(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a child which doesn't meet the function requirement.
Definition: ParticleUtils.hh:380
Cut operator&&(const Cut &aptr, const Cut &bptr)
Jets & ifilterBy(Jets &jets, const Cut &c)
Definition: JetUtils.hh:154
int abspid(const Particle &p)
Unbound function access to abs PID code.
Definition: ParticleUtils.hh:26
Determine whether a particle has a child which meets the cut/function.
Definition: ParticleUtils.hh:635
bool isVisible() const
Is this particle potentially visible in a detector?
bool fromBottom(const Particle &p)
Determine whether the particle is from a b-hadron decay.
Definition: ParticleUtils.hh:455
bool isSame(const Particle &other) const
Definition: Particle.hh:696
Jets discard(const Jets &jets, const Cut &c)
New alias for filter_discard.
Definition: JetUtils.hh:196
Determine whether a particle has a descendant which meets the cut/function.
Definition: ParticleUtils.hh:654
bool hasAncestorWith(const Particle &p, const ParticleSelector &f, bool only_physical=true)
Determine whether a particle has an ancestor which meets the function requirement.
Definition: ParticleUtils.hh:353
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
PdgIdPair pids(const ParticlePair &pp)
Definition: ParticleUtils.hh:749
bool isSame(const Particle &a, const Particle &b)
Check Particle equivalence.
Definition: ParticleUtils.hh:787
Determine whether a particle has a descendant which doesn't meet the cut/function.
Definition: ParticleUtils.hh:664
bool isDirect(const Particle &p, bool allow_from_direct_tau=false, bool allow_from_direct_mu=false)
Decide if a given particle is direct, via Particle::isDirect()
Definition: ParticleUtils.hh:419
bool hasLeptonicDecay(const Particle &p)
Decide if a given particle decays leptonically (decays, and no hadrons)
Definition: ParticleUtils.hh:443
Determine whether a particle has an parent which meets the cut/function.
Definition: ParticleUtils.hh:616
bool isLastWith(const ParticleSelector &f) const
Determine whether a particle is the last in a decay chain to meet the function requirement.
Definition: Particle.hh:676
bool hasDescendantWithout(const ParticleSelector &f, bool remove_duplicates=true) const
Definition: Particle.hh:601
bool hasStableDescendantWithout(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a stable descendant which doesn't meet the function requirement...
Definition: ParticleUtils.hh:402
Determine whether a particle has an ancestor which meets the cut/function.
Definition: ParticleUtils.hh:595
int charge3() const
Three times the charge of this Particle (i.e. integer multiple of smallest quark charge).
Definition: Particle.hh:179
bool contains(const std::string &s, const std::string &sub)
Does s contain sub as a substring?
Definition: RivetSTL.hh:93
bool hasHadronicDecay(const Particle &p)
Decide if a given particle decays hadronically.
Definition: ParticleUtils.hh:436
bool hasChildWith(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a child which meets the function requirement.
Definition: ParticleUtils.hh:375
bool isFirstWith(const Particle &p, const ParticleSelector &f)
Determine whether a particle is the first in a decay chain to meet the function requirement.
Definition: ParticleUtils.hh:330
bool hasAncestorWithout(const ParticleSelector &f, bool only_physical=true) const
Definition: Particle.hh:418
bool isLastWithout(const ParticleSelector &f) const
Determine whether a particle is the last in a decay chain not to meet the function requirement...
Definition: Particle.hh:683
Jets & ifilter_select(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
bool isLastWithout(const Particle &p, const ParticleSelector &f)
Determine whether a particle is the last in a decay chain not to meet the function requirement...
Definition: ParticleUtils.hh:346
Determine whether a particle has a child which doesn't meet the cut/function.
Definition: ParticleUtils.hh:644
bool fromCharm(const Particle &p)
Determine whether the particle is from a c-hadron decay.
Definition: ParticleUtils.hh:458
bool isFirstWith(const ParticleSelector &f) const
Determine whether a particle is the first in a decay chain to meet the function requirement.
Definition: Particle.hh:664
Determine whether a particle is the last in a decay chain to meet the cut/function.
Definition: ParticleUtils.hh:575
bool fromHadron(const Particle &p)
Determine whether the particle is from a hadron decay.
Definition: ParticleUtils.hh:461
bool hasChildWithout(const ParticleSelector &f) const
Definition: Particle.hh:562
Determine whether a particle has an parent which doesn't meet the cut/function.
Definition: ParticleUtils.hh:625
bool fromPromptTau(const Particle &p)
Determine whether the particle is from a prompt tau decay.
Definition: ParticleUtils.hh:469
PdgId abspid() const
Absolute value of the PDG ID code.
Definition: Particle.hh:164
bool fromTau(bool prompt_taus_only=false) const
Determine whether the particle is from a tau decay.
bool sameSign(const Particle &a, const Particle &b)
Definition: ParticleUtils.hh:297
Three-dimensional specialisation of Vector.
Definition: Vector3.hh:26
bool isDirect(bool allow_from_direct_tau=false, bool allow_from_direct_mu=false) const
Shorthand definition of 'promptness' based on set definition flags.
Jets & iselect(Jets &jets, const Cut &c)
New alias for ifilter_select.
Definition: JetUtils.hh:156
Functor for or-combination of selector logic.
Definition: ParticleUtils.hh:507
bool hasParentWithout(const ParticleSelector &f) const
Definition: Particle.hh:359
bool hasParentWithout(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a parent which doesn't meet the function requirement.
Definition: ParticleUtils.hh:369
bool isPrompt(const Particle &p, bool allow_from_prompt_tau=false, bool allow_from_prompt_mu=false)
Decide if a given particle is prompt, via Particle::isPrompt()
Definition: ParticleUtils.hh:427
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
Jets & ifilter_discard(Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that fails the supplied Cut.
bool isPrompt(bool allow_from_prompt_tau=false, bool allow_from_prompt_mu=false) const
Alias for isDirect.
Definition: Particle.hh:518
Jets & idiscard(Jets &jets, const Cut &c)
New alias for ifilter_discard.
Definition: JetUtils.hh:187
bool hasAncestor(PdgId pid, bool only_physical=true) const
bool hasParentWith(const ParticleSelector &f) const
Definition: Particle.hh:344
std::enable_if< std::is_arithmetic< NUM >::value, int >::type sign(NUM val)
Find the sign of a number.
Definition: MathUtils.hh:245
bool hasDescendantWithout(const Particle &p, const ParticleSelector &f, bool remove_duplicates=true)
Determine whether a particle has a descendant which doesn't meet the function requirement.
Definition: ParticleUtils.hh:391
bool fromBottom() const
Determine whether the particle is from a b-hadron decay.
bool hasParentWith(const Particle &p, const ParticleSelector &f)
Determine whether a particle has a parent which meets the function requirement.
Definition: ParticleUtils.hh:364