diff --git a/Kernel/PartProp/include/Kernel/ParticleID.h b/Kernel/PartProp/include/Kernel/ParticleID.h index 97d03e1186c402ee888852537a18e9209425e5b3..c15c56d8d6070fa7c5f77239bdd249f80ec89b04 100644 --- a/Kernel/PartProp/include/Kernel/ParticleID.h +++ b/Kernel/PartProp/include/Kernel/ParticleID.h @@ -64,80 +64,83 @@ namespace LHCb { public: // Constructors and destructors. // ======================================================================== /// Constructor with PDG code. - explicit ParticleID( const int pid = 0 ) { setPid( pid ); } + constexpr explicit ParticleID( const int pid = 0 ) { setPid( pid ); } // ======================================================================== public: // Access the raw PID. // ======================================================================== /// Retrieve the PDG ID. - int pid() const { return m_pid; } + [[nodiscard]] constexpr int pid() const { return m_pid; } /// Absolute value of the PDG ID. - unsigned int abspid() const { return 0 > m_pid ? -m_pid : m_pid; } + [[nodiscard]] constexpr unsigned int abspid() const { return 0 > m_pid ? -m_pid : m_pid; } /// Update the PDG ID. - void setPid( const int pid ) { m_pid = pid; } + constexpr ParticleID& setPid( const int pid ) { + m_pid = pid; + return *this; + } // ======================================================================== public: // Methods to return particle type properties. // ======================================================================== /// Return if the PID is valid. - bool isValid() const; + [[nodiscard]] bool isValid() const; /// Return if the PID is from the standard model. - bool isSM() const; + [[nodiscard]] bool isSM() const; /// Return if the PID is for a meson. - bool isMeson() const; + [[nodiscard]] bool isMeson() const; /// Return if the PID is for a baryon. - bool isBaryon() const; + [[nodiscard]] bool isBaryon() const; /// Return if the PID is for a di-quark. - bool isDiQuark() const; + [[nodiscard]] bool isDiQuark() const; /// Return if the PID is for a hadron. - bool isHadron() const; + [[nodiscard]] bool isHadron() const; /// Return if the PID is for a lepton. - bool isLepton() const; + [[nodiscard]] bool isLepton() const; /// Return if the PID is for a nucleus. - bool isNucleus() const; + [[nodiscard]] bool isNucleus() const; /// Return if the PID is for a bare quark. - bool isQuark() const; + [[nodiscard]] bool isQuark() const; // ======================================================================== public: // quark content // ======================================================================== /// Return if the PID is a particle with quarks, but not a nucleus. - bool hasQuarks() const; + [[nodiscard]] bool hasQuarks() const; /// Return if the PID is a particle containing a specified quark flavor. - bool hasQuark( const Quark& q ) const; + [[nodiscard]] bool hasQuark( const Quark& q ) const; /// Return if the PID is a particle with a down quark. - bool hasDown() const { return hasQuark( down ); } + [[nodiscard]] bool hasDown() const { return hasQuark( down ); } /// Return if the PID is a particle with an up quark. - bool hasUp() const { return hasQuark( up ); } + [[nodiscard]] bool hasUp() const { return hasQuark( up ); } /// Return if the PID is a particle with a down quark. - bool hasStrange() const { return hasQuark( strange ); } + [[nodiscard]] bool hasStrange() const { return hasQuark( strange ); } /// Return if the PID is a particle with a charm quark. - bool hasCharm() const { return hasQuark( charm ); } + [[nodiscard]] bool hasCharm() const { return hasQuark( charm ); } /// Return if the PID is a particle with a bottom quark. - bool hasBottom() const { return hasQuark( bottom ); } + [[nodiscard]] bool hasBottom() const { return hasQuark( bottom ); } /// Return if the PID is a particle with a top quark. - bool hasTop() const { return hasQuark( top ); } + [[nodiscard]] bool hasTop() const { return hasQuark( top ); } /// Return if the PID is a particle with a bottom' quark. - bool hasBottomPrime() const { return hasQuark( bottom_prime ); } + [[nodiscard]] bool hasBottomPrime() const { return hasQuark( bottom_prime ); } /// Return if the PID is a particle with a top' quark. - bool hasTopPrime() const { return hasQuark( top_prime ); } + [[nodiscard]] bool hasTopPrime() const { return hasQuark( top_prime ); } // ======================================================================== public: // Methods to return particle spin and charge properties. // ======================================================================== /// Return three times the charge, in units of e+, valid for all particles. - int threeCharge() const; + [[nodiscard]] int threeCharge() const; /// Return 2J+1, where J is the total spin, valid for all particles. - int jSpin() const; + [[nodiscard]] int jSpin() const; /// Return 2S+1, where S is the spin, valid only for mesons. - int sSpin() const; + [[nodiscard]] int sSpin() const; /// Return 2L+1, where L is the orbital angular momentum, valid only for mesons. - int lSpin() const; + [[nodiscard]] int lSpin() const; // ======================================================================== public: // nuclea // ======================================================================== /// Return the atomic number for a nucleus. - int Z() const; + [[nodiscard]] int Z() const; /// Return the nucleon number for a nucleus. - int A() const; + [[nodiscard]] int A() const; /// Return the number of strange quarks for a nucleus. - int nLambda() const; + [[nodiscard]] int nLambda() const; // ======================================================================== public: // fundamental particle ? // ======================================================================== @@ -145,12 +148,12 @@ namespace LHCb { * This is 0 for nuclie, mesons, baryons, and di-quarks. * Otherwise, this is the first two digits of the PDG ID */ - int fundamentalID() const; + [[nodiscard]] int fundamentalID() const; // ======================================================================== public: // technical methods // ======================================================================== /// Return everything beyond the 7th PDG ID digit. - int extraBits() const; + [[nodiscard]] int extraBits() const; /// Return the digit for a given PDG ID digit location. unsigned short digit( const Location& loc ) const { return Gaudi::Math::digit( abspid(), loc - 1 ); } /// Return the digit for a given PDG ID digit location. @@ -169,11 +172,9 @@ namespace LHCb { public: // comparisons (needed e.g. to be used as keys for maps and sets // ======================================================================== /// Equality operator. - bool operator==( const ParticleID& o ) const { return m_pid == o.m_pid; } - /// Non-equality operator. - bool operator!=( const ParticleID& o ) const { return m_pid != o.m_pid; } + [[nodiscard]] constexpr bool operator==( const ParticleID& o ) const { return m_pid == o.m_pid; } /// Comparison operator. - bool operator<( const ParticleID& o ) const { + [[nodiscard]] constexpr bool operator<( const ParticleID& o ) const { const unsigned int i1( abspid() ), i2( o.abspid() ); return std::tie( i1, m_pid ) < std::tie( i2, o.m_pid ); } @@ -182,36 +183,33 @@ namespace LHCb { // ====================================================================== /// Fill a stream with the PID. std::ostream& fillStream( std::ostream& s ) const; + /// Stream operator for the PID. + friend std::ostream& operator<<( std::ostream& s, const LHCb::ParticleID& o ) { return o.fillStream( s ); } /// Return the PID stream representation as a string. std::string toString() const; /// Fill a stream with the PID digit enumeration. static std::ostream& printLocation( const long l, std::ostream& s ); /// Return the PID digit enumeration stream representation as a string. static std::string printLocation( const long l ); + /// Stream operator for the PDG digit enumeration. + friend std::ostream& operator<<( std::ostream& s, LHCb::ParticleID::Location l ) { + return LHCb::ParticleID::printLocation( l, s ); + } /// Fill a stream with the PID quark enumeration. static std::ostream& printQuark( const long q, std::ostream& s ); /// Return the PID quark enumeration stream representation as a string. static std::string printQuark( const long q ); + /// Stream operator for the PDG quark enumeration. + friend std::ostream& operator<<( std::ostream& s, LHCb::ParticleID::Quark q ) { + return LHCb::ParticleID::printQuark( q, s ); + } // ======================================================================== private: // Internal data members. // ======================================================================== /// PDG ID. - int m_pid{0}; + int m_pid{ 0 }; // ======================================================================== }; - // ========================================================================== - // Inline stream operators. - /// Stream operator for the PID. - inline std::ostream& operator<<( std::ostream& s, const LHCb::ParticleID& o ) { return o.fillStream( s ); } - /// Stream operator for the PDG digit enumeration. - inline std::ostream& operator<<( std::ostream& s, LHCb::ParticleID::Location l ) { - return LHCb::ParticleID::printLocation( l, s ); - } - /// Stream operator for the PDG quark enumeration. - inline std::ostream& operator<<( std::ostream& s, LHCb::ParticleID::Quark q ) { - return LHCb::ParticleID::printQuark( q, s ); - } - // ========================================================================== } // namespace LHCb // ============================================================================ // Hash functions for maps of ParticleIDs. diff --git a/Kernel/PartProp/include/Kernel/ParticleIDs.h b/Kernel/PartProp/include/Kernel/ParticleIDs.h new file mode 100644 index 0000000000000000000000000000000000000000..e0a36727841d1f3203787e47c6f3c1872c51d3a2 --- /dev/null +++ b/Kernel/PartProp/include/Kernel/ParticleIDs.h @@ -0,0 +1,99 @@ +/*****************************************************************************\ +* (c) Copyright 2025 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, CERN does not waive the privileges and immunities * +* granted to it by virtue of its status as an Intergovernmental Organization * +* or submit itself to any jurisdiction. * +\*****************************************************************************/ +// ============================================================================ +#ifndef LHCbKernel_ParticleIDs_H +#define LHCbKernel_ParticleIDs_H 1 +// ============================================================================ +// Include files +// ============================================================================ +#include "Kernel/ParticleID.h" +/** + * @file ParticleIDs.h + * @brief Particle IDs as consexpr values for common particles from PDG + * + */ +namespace LHCb { + namespace ParticleIDs { + // Leptons + constexpr auto electron = ParticleID{ 11 }; + constexpr auto positron = ParticleID{ -11 }; + constexpr auto muon_minus = ParticleID{ 13 }; + constexpr auto muon_plus = ParticleID{ -13 }; + constexpr auto tau_minus = ParticleID{ 15 }; + constexpr auto tau_plus = ParticleID{ -15 }; + constexpr auto electron_neutrino = ParticleID{ 12 }; + constexpr auto electron_antineutrino = ParticleID{ -12 }; + constexpr auto muon_neutrino = ParticleID{ 14 }; + constexpr auto muon_antineutrino = ParticleID{ -14 }; + constexpr auto tau_neutrino = ParticleID{ 16 }; + constexpr auto tau_antineutrino = ParticleID{ -16 }; + + // Mesons + constexpr auto pion_plus = ParticleID{ 211 }; + constexpr auto pion_minus = ParticleID{ -211 }; + constexpr auto pion_neutral = ParticleID{ 111 }; + constexpr auto kaon_plus = ParticleID{ 321 }; + constexpr auto kaon_minus = ParticleID{ -321 }; + constexpr auto kaon_short = ParticleID{ 310 }; + constexpr auto kaon_long = ParticleID{ 130 }; + constexpr auto kaon_star = ParticleID{ 323 }; + constexpr auto phi = ParticleID{ 333 }; + constexpr auto rho = ParticleID{ 113 }; + constexpr auto eta = ParticleID{ 221 }; + constexpr auto eta_prime = ParticleID{ 331 }; + + // Charm Mesons + constexpr auto d_zero = ParticleID{ 421 }; + constexpr auto anti_d_zero = ParticleID{ -421 }; + constexpr auto d_plus = ParticleID{ 411 }; + constexpr auto d_minus = ParticleID{ -411 }; + constexpr auto d_s_plus = ParticleID{ 431 }; + constexpr auto d_s_minus = ParticleID{ -431 }; + + // Bottom Mesons + constexpr auto b_zero = ParticleID{ 511 }; + constexpr auto anti_b_zero = ParticleID{ -511 }; + constexpr auto b_plus = ParticleID{ 521 }; + constexpr auto b_minus = ParticleID{ -521 }; + constexpr auto b_s_zero = ParticleID{ 531 }; + constexpr auto anti_b_s_zero = ParticleID{ -531 }; + + // Baryons + constexpr auto proton = ParticleID{ 2212 }; + constexpr auto antiproton = ParticleID{ -2212 }; + constexpr auto neutron = ParticleID{ 2112 }; + constexpr auto antineutron = ParticleID{ -2112 }; + constexpr auto lambda = ParticleID{ 3122 }; + constexpr auto anti_lambda = ParticleID{ -3122 }; + constexpr auto lambda_b = ParticleID{ 5122 }; + constexpr auto anti_lambda_b = ParticleID{ -5122 }; + constexpr auto sigma_plus = ParticleID{ 3222 }; + constexpr auto sigma_zero = ParticleID{ 3212 }; + constexpr auto sigma_minus = ParticleID{ 3112 }; + constexpr auto xi_zero = ParticleID{ 3322 }; + constexpr auto xi_minus = ParticleID{ 3312 }; + constexpr auto omega_minus = ParticleID{ 3334 }; + + // Photons and Bosons + constexpr auto photon = ParticleID{ 22 }; + constexpr auto z_boson = ParticleID{ 23 }; + constexpr auto w_plus = ParticleID{ 24 }; + constexpr auto w_minus = ParticleID{ -24 }; + constexpr auto higgs_boson = ParticleID{ 25 }; + + // ========================================================================== + } // namespace ParticleIDs + // ============================================================================ + + // ========================================================================== +} // namespace LHCb +// ============================================================================ +#endif /// LHCbKernel_ParticleIDs_H diff --git a/Kernel/PartProp/include/Kernel/ParticleProperty.h b/Kernel/PartProp/include/Kernel/ParticleProperty.h old mode 100755 new mode 100644 index 73b97d2297e4b8bfa57ec33962735e1ca7af5cc1..c51b44c7226f877aeb936bd2e6c2016a5f6e78a7 --- a/Kernel/PartProp/include/Kernel/ParticleProperty.h +++ b/Kernel/PartProp/include/Kernel/ParticleProperty.h @@ -162,11 +162,18 @@ namespace LHCb { /// simple method for conversion into the string std::string toString() const; // ======================================================================== - private: - // ======================================================================== - /// The default constructor is disabled - ParticleProperty(); // no default constructor - // ======================================================================== + // ============================================================================ + /** standard output operator to the stream + * @param stream the stream + * @param pp the particle property object + * @return the stream + * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl + * @date 2008-08-03 + */ + friend std::ostream& operator<<( std::ostream& stream, const LHCb::ParticleProperty& pp ) { + return pp.fillStream( stream ); + } + private: // data members // ======================================================================== /// the name for the particle @@ -192,15 +199,6 @@ namespace LHCb { // ========================================================================== } // end of namespace LHCb // ============================================================================ -/** standard output operator to the stream - * @param stream the stream - * @param pp the particle property object - * @return the stream - * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl - * @date 2008-08-03 - */ -std::ostream& operator<<( std::ostream& stream, const LHCb::ParticleProperty& pp ); -// ============================================================================ /// forward declaration // ============================================================================ class MsgStream; // forward declaration diff --git a/Kernel/PartProp/src/ParticleProperty.cpp b/Kernel/PartProp/src/ParticleProperty.cpp index e77728492323aefe4d1c88dcf968308759368a58..0d9d356635cf7626f8c6bdb14960e46c013088cc 100755 --- a/Kernel/PartProp/src/ParticleProperty.cpp +++ b/Kernel/PartProp/src/ParticleProperty.cpp @@ -28,14 +28,6 @@ * @date 2008-08-03 */ // ============================================================================ -/* standard output operator to the stream - * @param stream the stream - * @param pp the particle property object - * @return the stream - */ -// ============================================================================ -std::ostream& operator<<( std::ostream& stream, const LHCb::ParticleProperty& pp ) { return pp.fillStream( stream ); } -// ============================================================================ /* full constructor, from all data (except the antiparticle ) * @param name the name for the particle * @param pid the PID for the particle