Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:38:23

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 #include <GaudiKernel/HashMap.h>
0014 #include <GaudiKernel/Kernel.h>
0015 #include <cmath>
0016 #include <cstdint>
0017 #include <iosfwd>
0018 #include <string>
0019 #include <tuple>
0020 
0021 namespace Gaudi {
0022   /** @class ParticleID ParticleID.h
0023    *
0024    * Holds PDG + LHCb extension particle code, following the PDG
0025    * particle numbering scheme
0026    * (pdg.lbl.gov/2017/reviews/rpp2017-rev-monte-carlo-numbering.pdf). Specific
0027    * conventions followed by Pythia 8 for beyond the standard model
0028    * physics and color-octet quarkonia have been introduced.
0029    *
0030    * Nuclei with the PDG 2017 convention (following the 2006 Monte
0031    * Carlo nuclear code scheme) have the numbering +/- 10LZZZAAAI. Where
0032    * AAA is A - the total baryon number,
0033    * ZZZ is Z - the total number of protons,
0034    * L is the total number of strange quarks, and
0035    * I is the isomer number where I = 0 corresponds to the ground state.
0036    * Backwards compatibility with the old heavy ion scheme has also been kept.
0037    *
0038    * @date 19/02/2002
0039    * @author Gloria Corti
0040    * @date 22/03/2018
0041    * @author Philip Ilten
0042    */
0043   class GAUDI_API ParticleID final {
0044   public:
0045     /// PDG ID digits (base 10) are: n nr nl nq1 ne2 nq3 nj.
0046     enum Location { nj = 1, nq3, nq2, nq1, nl, nr, n, n8, n9, n10 };
0047     /// Quark PDG IDs.
0048     enum Quark { down = 1, up, strange, charm, bottom, top, bottom_prime, top_prime, first = down, last = top_prime };
0049 
0050     /// Constructor with PDG code.
0051     explicit ParticleID( const int pid = 0 ) { setPid( pid ); }
0052 
0053     /// Retrieve the PDG ID.
0054     int pid() const { return m_pid; }
0055     /// Absolute value of the PDG ID.
0056     constexpr unsigned int abspid() const { return 0 > m_pid ? -m_pid : m_pid; }
0057     /// Update the PDG ID.
0058     void setPid( const int pid ) { m_pid = pid; }
0059 
0060     /// Return if the PID is valid.
0061     bool isValid() const;
0062     /// Return if the PID is from the standard model.
0063     bool isSM() const;
0064     /// Return if the PID is for a meson.
0065     bool isMeson() const;
0066     /// Return if the PID is for a baryon.
0067     bool isBaryon() const;
0068     /// Return if the PID is for a di-quark.
0069     bool isDiQuark() const;
0070     /// Return if the PID is for a hadron.
0071     bool isHadron() const;
0072     /// Return if the PID is for a lepton.
0073     bool isLepton() const;
0074     /// Return if the PID is for a nucleus.
0075     bool isNucleus() const;
0076     /// Return if the PID is for a bare quark.
0077     bool isQuark() const;
0078 
0079     /// Return if the PID is a particle with quarks, but not a nucleus.
0080     bool hasQuarks() const;
0081     /// Return if the PID is a particle containing a specified quark flavor.
0082     bool hasQuark( const Quark& q ) const;
0083     /// Return if the PID is a particle with a down quark.
0084     bool hasDown() const { return hasQuark( down ); }
0085     /// Return if the PID is a particle with an up quark.
0086     bool hasUp() const { return hasQuark( up ); }
0087     /// Return if the PID is a particle with a down quark.
0088     bool hasStrange() const { return hasQuark( strange ); }
0089     /// Return if the PID is a particle with a charm quark.
0090     bool hasCharm() const { return hasQuark( charm ); }
0091     /// Return if the PID is a particle with a bottom quark.
0092     bool hasBottom() const { return hasQuark( bottom ); }
0093     /// Return if the PID is a particle with a top quark.
0094     bool hasTop() const { return hasQuark( top ); }
0095     /// Return if the PID is a particle with a bottom' quark.
0096     bool hasBottomPrime() const { return hasQuark( bottom_prime ); }
0097     /// Return if the PID is a particle with a top' quark.
0098     bool hasTopPrime() const { return hasQuark( top_prime ); }
0099 
0100     /// Return three times the charge, in units of e+, valid for all particles.
0101     int threeCharge() const;
0102     /// Return 2J+1, where J is the total spin, valid for all particles.
0103     int jSpin() const;
0104     /// Return 2S+1, where S is the spin, valid only for mesons.
0105     int sSpin() const;
0106     /// Return 2L+1, where L is the orbital angular momentum, valid only for mesons.
0107     int lSpin() const;
0108 
0109     /// Return the atomic number for a nucleus.
0110     int Z() const;
0111     /// Return the nucleon number for a nucleus.
0112     int A() const;
0113     /// Return the number of strange quarks for a nucleus.
0114     int nLambda() const;
0115 
0116     /** Return the fundamental ID.
0117      *  This is 0 for nuclei, mesons, baryons, and di-quarks.
0118      *  Otherwise, this is the first two digits of the PDG ID
0119      */
0120     int fundamentalID() const;
0121 
0122     /// Return everything beyond the 7th PDG ID digit.
0123     int extraBits() const;
0124     /// Return the digit for a given PDG ID digit location.
0125     constexpr unsigned short digit( const Location& loc ) const {
0126       constexpr std::uint32_t pows[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
0127       return ( abspid() / pows[loc - 1] ) % 10;
0128     }
0129 
0130     /// Equality operator.
0131     bool operator==( const ParticleID& o ) const { return m_pid == o.m_pid; }
0132     /// Non-equality operator.
0133     bool operator!=( const ParticleID& o ) const { return m_pid != o.m_pid; }
0134     /// Comparison operator.
0135     bool operator<( const ParticleID& o ) const {
0136       const unsigned int i1( abspid() ), i2( o.abspid() );
0137       return std::tie( i1, m_pid ) < std::tie( i2, o.m_pid );
0138     }
0139 
0140     /// Fill a stream with the PID.
0141     std::ostream& fillStream( std::ostream& s ) const;
0142     /// Return the PID stream representation as a string.
0143     std::string toString() const;
0144     /// Fill a stream with the PID digit enumeration.
0145     static std::ostream& printLocation( const long l, std::ostream& s );
0146     /// Return the PID digit enumeration stream representation as a string.
0147     static std::string printLocation( const long l );
0148     /// Fill a stream with the PID quark enumeration.
0149     static std::ostream& printQuark( const long q, std::ostream& s );
0150     /// Return the PID quark enumeration stream representation as a string.
0151     static std::string printQuark( const long q );
0152 
0153   private:
0154     /// PDG ID.
0155     int m_pid{ 0 };
0156   };
0157 
0158   // Inline stream operators.
0159   /// Stream operator for the PID.
0160   inline std::ostream& operator<<( std::ostream& s, const Gaudi::ParticleID& o ) { return o.fillStream( s ); }
0161   /// Stream operator for the PDG digit enumeration.
0162   inline std::ostream& operator<<( std::ostream& s, Gaudi::ParticleID::Location l ) {
0163     return Gaudi::ParticleID::printLocation( l, s );
0164   }
0165   /// Stream operator for the PDG quark enumeration.
0166   inline std::ostream& operator<<( std::ostream& s, Gaudi::ParticleID::Quark q ) {
0167     return Gaudi::ParticleID::printQuark( q, s );
0168   }
0169 } // namespace Gaudi
0170 
0171 namespace GaudiUtils {
0172   template <>
0173   struct Hash<Gaudi::ParticleID> {
0174     inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
0175   };
0176   template <>
0177   struct Hash<const Gaudi::ParticleID> {
0178     inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
0179   };
0180   template <>
0181   struct Hash<Gaudi::ParticleID&> {
0182     inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
0183   };
0184   template <>
0185   struct Hash<const Gaudi::ParticleID&> {
0186     inline size_t operator()( const Gaudi::ParticleID& s ) const { return (size_t)s.pid(); }
0187   };
0188 } // namespace GaudiUtils
0189 namespace std {
0190   /// Return the absolute value for a PID.
0191   inline Gaudi::ParticleID abs( const Gaudi::ParticleID& p ) { return Gaudi::ParticleID( p.abspid() ); }
0192 } // namespace std