The Gaudi Framework  master (37c0b60a)
ParticleID.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <GaudiKernel/HashMap.h>
14 #include <GaudiKernel/Kernel.h>
15 #include <cmath>
16 #include <cstdint>
17 #include <iosfwd>
18 #include <string>
19 #include <tuple>
20 
21 namespace Gaudi {
43  class GAUDI_API ParticleID final {
44  public:
46  enum Location { nj = 1, nq3, nq2, nq1, nl, nr, n, n8, n9, n10 };
48  enum Quark { down = 1, up, strange, charm, bottom, top, bottom_prime, top_prime, first = down, last = top_prime };
49 
51  explicit ParticleID( const int pid = 0 ) { setPid( pid ); }
52 
54  int pid() const { return m_pid; }
56  constexpr unsigned int abspid() const { return 0 > m_pid ? -m_pid : m_pid; }
58  void setPid( const int pid ) { m_pid = pid; }
59 
61  bool isValid() const;
63  bool isSM() const;
65  bool isMeson() const;
67  bool isBaryon() const;
69  bool isDiQuark() const;
71  bool isHadron() const;
73  bool isLepton() const;
75  bool isNucleus() const;
77  bool isQuark() const;
78 
80  bool hasQuarks() const;
82  bool hasQuark( const Quark& q ) const;
84  bool hasDown() const { return hasQuark( down ); }
86  bool hasUp() const { return hasQuark( up ); }
88  bool hasStrange() const { return hasQuark( strange ); }
90  bool hasCharm() const { return hasQuark( charm ); }
92  bool hasBottom() const { return hasQuark( bottom ); }
94  bool hasTop() const { return hasQuark( top ); }
96  bool hasBottomPrime() const { return hasQuark( bottom_prime ); }
98  bool hasTopPrime() const { return hasQuark( top_prime ); }
99 
101  int threeCharge() const;
103  int jSpin() const;
105  int sSpin() const;
107  int lSpin() const;
108 
110  int Z() const;
112  int A() const;
114  int nLambda() const;
115 
120  int fundamentalID() const;
121 
123  int extraBits() const;
125  constexpr unsigned short digit( const Location& loc ) const {
126  constexpr std::uint32_t pows[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
127  return ( abspid() / pows[loc - 1] ) % 10;
128  }
129 
131  bool operator==( const ParticleID& o ) const { return m_pid == o.m_pid; }
133  bool operator!=( const ParticleID& o ) const { return m_pid != o.m_pid; }
135  bool operator<( const ParticleID& o ) const {
136  const unsigned int i1( abspid() ), i2( o.abspid() );
137  return std::tie( i1, m_pid ) < std::tie( i2, o.m_pid );
138  }
139 
141  std::ostream& fillStream( std::ostream& s ) const;
143  std::string toString() const;
145  static std::ostream& printLocation( const long l, std::ostream& s );
147  static std::string printLocation( const long l );
149  static std::ostream& printQuark( const long q, std::ostream& s );
151  static std::string printQuark( const long q );
152 
153  private:
155  int m_pid{ 0 };
156  };
157 
158  // Inline stream operators.
160  inline std::ostream& operator<<( std::ostream& s, const Gaudi::ParticleID& o ) { return o.fillStream( s ); }
164  }
167  return Gaudi::ParticleID::printQuark( q, s );
168  }
169 } // namespace Gaudi
170 
171 namespace GaudiUtils {
172  template <>
173  struct Hash<Gaudi::ParticleID> {
174  inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
175  };
176  template <>
177  struct Hash<const Gaudi::ParticleID> {
178  inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
179  };
180  template <>
181  struct Hash<Gaudi::ParticleID&> {
182  inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
183  };
184  template <>
185  struct Hash<const Gaudi::ParticleID&> {
186  inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
187  };
188 } // namespace GaudiUtils
189 namespace std {
191  inline Gaudi::ParticleID abs( const Gaudi::ParticleID& p ) { return Gaudi::ParticleID( p.abspid() ); }
192 } // namespace std
Gaudi::ParticleID::operator!=
bool operator!=(const ParticleID &o) const
Non-equality operator.
Definition: ParticleID.h:133
GaudiUtils::Hash< const Gaudi::ParticleID >::operator()
size_t operator()(const Gaudi::ParticleID &s) const
Definition: ParticleID.h:178
Gaudi::ParticleID::Quark
Quark
Quark PDG IDs.
Definition: ParticleID.h:48
Gaudi::ParticleID::digit
constexpr unsigned short digit(const Location &loc) const
Return the digit for a given PDG ID digit location.
Definition: ParticleID.h:125
std::string
STL class.
ParticleID
Definition: ParticleID.py:1
Gaudi::ParticleID::setPid
void setPid(const int pid)
Update the PDG ID.
Definition: ParticleID.h:58
gaudirun.s
string s
Definition: gaudirun.py:346
Gaudi::ParticleID::nr
@ nr
Definition: ParticleID.h:46
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
Gaudi::ParticleID::printLocation
static std::ostream & printLocation(const long l, std::ostream &s)
Fill a stream with the PID digit enumeration.
Definition: ParticleID.cpp:443
Gaudi::ParticleID::up
@ up
Definition: ParticleID.h:48
GaudiUtils::Hash< const Gaudi::ParticleID & >::operator()
size_t operator()(const Gaudi::ParticleID &s) const
Definition: ParticleID.h:186
HashMap.h
Gaudi::ParticleID::fillStream
std::ostream & fillStream(std::ostream &s) const
Fill a stream with the PID.
Definition: ParticleID.cpp:432
std::tie
T tie(T... args)
Gaudi::ParticleID::operator==
bool operator==(const ParticleID &o) const
Equality operator.
Definition: ParticleID.h:131
Gaudi::ParticleID::m_pid
int m_pid
PDG ID.
Definition: ParticleID.h:155
Gaudi::ParticleID::ParticleID
ParticleID(const int pid=0)
Constructor with PDG code.
Definition: ParticleID.h:51
Gaudi::ParticleID::hasTop
bool hasTop() const
Return if the PID is a particle with a top quark.
Definition: ParticleID.h:94
Gaudi::ParticleID::operator<
bool operator<(const ParticleID &o) const
Comparison operator.
Definition: ParticleID.h:135
std::ostream
STL class.
Gaudi::ParticleID::hasBottom
bool hasBottom() const
Return if the PID is a particle with a bottom quark.
Definition: ParticleID.h:92
Gaudi::ParticleID::hasUp
bool hasUp() const
Return if the PID is a particle with an up quark.
Definition: ParticleID.h:86
std::uint32_t
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::ParticleID::hasStrange
bool hasStrange() const
Return if the PID is a particle with a down quark.
Definition: ParticleID.h:88
GaudiUtils::Hash
Definition: Hash.h:103
Gaudi::ParticleID::hasCharm
bool hasCharm() const
Return if the PID is a particle with a charm quark.
Definition: ParticleID.h:90
Gaudi::ParticleID::abspid
constexpr unsigned int abspid() const
Absolute value of the PDG ID.
Definition: ParticleID.h:56
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
Gaudi::ParticleID::printQuark
static std::ostream & printQuark(const long q, std::ostream &s)
Fill a stream with the PID quark enumeration.
Definition: ParticleID.cpp:478
Gaudi::ParticleID::pid
int pid() const
Retrieve the PDG ID.
Definition: ParticleID.h:54
gaudirun.l
dictionary l
Definition: gaudirun.py:583
std
STL namespace.
Kernel.h
Gaudi::ParticleID
Definition: ParticleID.h:43
Gaudi::operator<<
std::ostream & operator<<(std::ostream &o, const Gaudi::StringKey &key)
printout of the object reply on the native printout for the string
Definition: StringKey.h:208
Gaudi::ParticleID::Location
Location
PDG ID digits (base 10) are: n nr nl nq1 ne2 nq3 nj.
Definition: ParticleID.h:46
Gaudi::ParticleID::hasBottomPrime
bool hasBottomPrime() const
Return if the PID is a particle with a bottom' quark.
Definition: ParticleID.h:96
GaudiUtils
Definition: Allocator.h:72
GaudiUtils::Hash< Gaudi::ParticleID & >::operator()
size_t operator()(const Gaudi::ParticleID &s) const
Definition: ParticleID.h:182
AlgSequencer.top
top
Definition: AlgSequencer.py:37
GaudiUtils::Hash< Gaudi::ParticleID >::operator()
size_t operator()(const Gaudi::ParticleID &s) const
Definition: ParticleID.h:174
Gaudi::ParticleID::hasTopPrime
bool hasTopPrime() const
Return if the PID is a particle with a top' quark.
Definition: ParticleID.h:98
Gaudi::ParticleID::hasDown
bool hasDown() const
Return if the PID is a particle with a down quark.
Definition: ParticleID.h:84
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81