The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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
21namespace Gaudi {
43 class GAUDI_API ParticleID final {
44 public:
46 enum Location { nj = 1, nq3, nq2, nq1, nl, nr, n, n8, n9, n10 };
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 ); }
162 inline std::ostream& operator<<( std::ostream& s, Gaudi::ParticleID::Location l ) {
164 }
165
166 inline std::ostream& operator<<( std::ostream& s, Gaudi::ParticleID::Quark q ) {
167 return Gaudi::ParticleID::printQuark( q, s );
168 }
169} // namespace Gaudi
170
171namespace GaudiUtils {
172 template <>
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 <>
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
189namespace std {
191 inline Gaudi::ParticleID abs( const Gaudi::ParticleID& p ) { return Gaudi::ParticleID( p.abspid() ); }
192} // namespace std
#define GAUDI_API
Definition Kernel.h:49
Holds PDG + LHCb extension particle code, following the PDG particle numbering scheme (pdg....
Definition ParticleID.h:43
bool hasTop() const
Return if the PID is a particle with a top quark.
Definition ParticleID.h:94
bool hasTopPrime() const
Return if the PID is a particle with a top' quark.
Definition ParticleID.h:98
Location
PDG ID digits (base 10) are: n nr nl nq1 ne2 nq3 nj.
Definition ParticleID.h:46
bool hasBottom() const
Return if the PID is a particle with a bottom quark.
Definition ParticleID.h:92
static std::ostream & printLocation(const long l, std::ostream &s)
Fill a stream with the PID digit enumeration.
bool hasUp() const
Return if the PID is a particle with an up quark.
Definition ParticleID.h:86
bool hasStrange() const
Return if the PID is a particle with a down quark.
Definition ParticleID.h:88
static std::ostream & printQuark(const long q, std::ostream &s)
Fill a stream with the PID quark enumeration.
bool operator<(const ParticleID &o) const
Comparison operator.
Definition ParticleID.h:135
constexpr unsigned int abspid() const
Absolute value of the PDG ID.
Definition ParticleID.h:56
bool operator!=(const ParticleID &o) const
Non-equality operator.
Definition ParticleID.h:133
ParticleID(const int pid=0)
Constructor with PDG code.
Definition ParticleID.h:51
void setPid(const int pid)
Update the PDG ID.
Definition ParticleID.h:58
bool hasQuark(const Quark &q) const
Return if the PID is a particle containing a specified quark flavor.
int pid() const
Retrieve the PDG ID.
Definition ParticleID.h:54
bool operator==(const ParticleID &o) const
Equality operator.
Definition ParticleID.h:131
int m_pid
PDG ID.
Definition ParticleID.h:155
bool hasBottomPrime() const
Return if the PID is a particle with a bottom' quark.
Definition ParticleID.h:96
constexpr unsigned short digit(const Location &loc) const
Return the digit for a given PDG ID digit location.
Definition ParticleID.h:125
bool hasCharm() const
Return if the PID is a particle with a charm quark.
Definition ParticleID.h:90
bool hasDown() const
Return if the PID is a particle with a down quark.
Definition ParticleID.h:84
std::ostream & fillStream(std::ostream &s) const
Fill a stream with the PID.
Quark
Quark PDG IDs.
Definition ParticleID.h:48
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
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:176
STL namespace.
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition ParticleID.h:191
Simple hash function.
Definition Hash.h:93
size_t operator()(const Gaudi::ParticleID &s) const
Definition ParticleID.h:182
size_t operator()(const Gaudi::ParticleID &s) const
Definition ParticleID.h:178
size_t operator()(const Gaudi::ParticleID &s) const
Definition ParticleID.h:174
size_t operator()(const Gaudi::ParticleID &s) const
Definition ParticleID.h:186