Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:29

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