Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-08 10:11:25

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file celeritas/phys/PDGNumber.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cstddef>
0010 #include <functional>
0011 
0012 #include "corecel/Assert.hh"
0013 
0014 namespace celeritas
0015 {
0016 //---------------------------------------------------------------------------//
0017 /*!
0018  * Type-safe particle identifier.
0019  *
0020  * The Particle Data Group specifies a coding to uniquely identify
0021  * standard-model particle
0022  * types in "Monte Carlo Particle Numbering Scheme" section of \citep{pdg,
0023  * https://link.aps.org/doi/10.1103/PhysRevD.98.030001}.
0024  * These coded identifiers should generally not be treated like numbers: this
0025  * class prevents unintentional arithmetic and conversion.
0026  *
0027  * PDG numbers should only be used in host setup code (they should be converted
0028  * to ParticleId for use during runtime).
0029  */
0030 class PDGNumber
0031 {
0032   public:
0033     //! Construct with an invalid/unassigned value of zero
0034     constexpr PDGNumber() = default;
0035 
0036     //! Construct with the PDG value
0037     explicit constexpr PDGNumber(int val) : value_(val) {}
0038 
0039     //! True if value is nonzero
0040     explicit constexpr operator bool() const { return value_ != 0; }
0041 
0042     //! Get the PDG value
0043     constexpr int unchecked_get() const { return value_; }
0044 
0045     // Get the PDG value
0046     inline int get() const;
0047 
0048     //// FRIENDLY OPERATORS ////
0049 
0050     //! Test equality
0051     constexpr friend bool operator==(PDGNumber lhs, PDGNumber rhs)
0052     {
0053         return lhs.unchecked_get() == rhs.unchecked_get();
0054     }
0055 
0056     //! Test inequality
0057     constexpr friend bool operator!=(PDGNumber lhs, PDGNumber rhs)
0058     {
0059         return !(lhs == rhs);
0060     }
0061 
0062     //! Allow less-than comparison for sorting
0063     constexpr friend bool operator<(PDGNumber lhs, PDGNumber rhs)
0064     {
0065         return lhs.unchecked_get() < rhs.unchecked_get();
0066     }
0067 
0068   private:
0069     int value_{0};
0070 };
0071 
0072 //---------------------------------------------------------------------------//
0073 // INLINE DEFINITIONS
0074 //---------------------------------------------------------------------------//
0075 /*!
0076  * Get the PDG value.
0077  */
0078 inline int PDGNumber::get() const
0079 {
0080     CELER_ENSURE(*this);
0081     return value_;
0082 }
0083 
0084 /*!
0085  * Unique standard model particle identifiers by the Particle Data Group.
0086  *
0087  * This namespace acts an enumeration for PDG codes that are used by the
0088  * various processes in Celeritas. (Unlike an enumeration, though, PDG codes
0089  * can be arbitrary and aren't limited to the ones defined below.) They should
0090  * be extended as needed when new particle types are used by processes.
0091  *
0092  * PDG numbers between 81 and 100 are reserved for internal use.
0093  * The table shows which internal arbitrary numbers are currently defined:
0094  *
0095  * | Particle name | PDG |
0096  * | ------------- | --- |
0097  * | Generic ion   | 90  |
0098  */
0099 namespace pdg
0100 {
0101 //---------------------------------------------------------------------------//
0102 //! \todo replace with inline constexpr value.
0103 #define CELER_DEFINE_PDGNUMBER(NAME, VALUE) \
0104     inline constexpr PDGNumber NAME() \
0105     { \
0106         return PDGNumber{VALUE}; \
0107     }
0108 
0109 //!@{
0110 //! \name Particle Data Group Monte Carlo number codes
0111 //! Sorted by `(abs(val), val < 0)`.
0112 //! See https://pdg.lbl.gov/2007/reviews/montecarlorpp.pdf
0113 
0114 // Leptons
0115 CELER_DEFINE_PDGNUMBER(electron, 11)
0116 CELER_DEFINE_PDGNUMBER(positron, -11)
0117 CELER_DEFINE_PDGNUMBER(mu_minus, 13)
0118 CELER_DEFINE_PDGNUMBER(mu_plus, -13)
0119 CELER_DEFINE_PDGNUMBER(tau_minus, 15)
0120 CELER_DEFINE_PDGNUMBER(tau_plus, -15)
0121 
0122 // Gauge bosons
0123 CELER_DEFINE_PDGNUMBER(gamma, 22)
0124 
0125 // Codes 81-100 are reserved for generator-specific pseudoparticles
0126 CELER_DEFINE_PDGNUMBER(ion, 90)
0127 
0128 // Light mesons
0129 CELER_DEFINE_PDGNUMBER(pi_plus, 211)
0130 CELER_DEFINE_PDGNUMBER(pi_minus, -211)
0131 CELER_DEFINE_PDGNUMBER(kaon_plus, 321)
0132 CELER_DEFINE_PDGNUMBER(kaon_minus, -321)
0133 CELER_DEFINE_PDGNUMBER(neutron, 2112)
0134 CELER_DEFINE_PDGNUMBER(anti_neutron, -2112)
0135 CELER_DEFINE_PDGNUMBER(proton, 2212)
0136 CELER_DEFINE_PDGNUMBER(anti_proton, -2212)
0137 
0138 // Ions
0139 CELER_DEFINE_PDGNUMBER(hydrogen, 1000010010)
0140 CELER_DEFINE_PDGNUMBER(deuteron, 1000010020)
0141 CELER_DEFINE_PDGNUMBER(anti_deuteron, -1000010020)
0142 CELER_DEFINE_PDGNUMBER(triton, 1000010030)
0143 CELER_DEFINE_PDGNUMBER(anti_triton, -1000010030)
0144 CELER_DEFINE_PDGNUMBER(he3, 1000020030)
0145 CELER_DEFINE_PDGNUMBER(anti_he3, -1000020030)
0146 CELER_DEFINE_PDGNUMBER(alpha, 1000020040)
0147 CELER_DEFINE_PDGNUMBER(anti_alpha, -1000020040)
0148 
0149 // Muonic nuclei
0150 CELER_DEFINE_PDGNUMBER(muonic_hydrogen, 2000010010)
0151 CELER_DEFINE_PDGNUMBER(muonic_deuteron, 2000010020)
0152 CELER_DEFINE_PDGNUMBER(muonic_triton, 2000010030)
0153 CELER_DEFINE_PDGNUMBER(muonic_alpha, 2000020040)
0154 CELER_DEFINE_PDGNUMBER(muonic_he3, 2000020030)
0155 
0156 //!@}
0157 
0158 #undef CELER_DEFINE_PDGNUMBER
0159 //---------------------------------------------------------------------------//
0160 }  // namespace pdg
0161 }  // namespace celeritas
0162 
0163 //---------------------------------------------------------------------------//
0164 // STD::HASH SPECIALIZATION FOR HOST CODE
0165 //---------------------------------------------------------------------------//
0166 //! \cond
0167 namespace std
0168 {
0169 //! Specialization for std::hash for unordered storage.
0170 template<>
0171 struct hash<celeritas::PDGNumber>
0172 {
0173     using argument_type = celeritas::PDGNumber;
0174     using result_type = std::size_t;
0175     result_type operator()(argument_type const& pdg) const noexcept
0176     {
0177         return std::hash<int>()(pdg.unchecked_get());
0178     }
0179 };
0180 }  // namespace std
0181 //! \endcond