![]() |
|
|||
File indexing completed on 2025-09-17 08:53:45
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 private: 0049 int value_{0}; 0050 }; 0051 0052 //---------------------------------------------------------------------------// 0053 // INLINE DEFINITIONS 0054 //---------------------------------------------------------------------------// 0055 /*! 0056 * Get the PDG value. 0057 */ 0058 inline int PDGNumber::get() const 0059 { 0060 CELER_ENSURE(*this); 0061 return value_; 0062 } 0063 0064 //---------------------------------------------------------------------------// 0065 // COMPARATORS 0066 //---------------------------------------------------------------------------// 0067 //! Test equality 0068 inline constexpr bool operator==(PDGNumber lhs, PDGNumber rhs) 0069 { 0070 return lhs.unchecked_get() == rhs.unchecked_get(); 0071 } 0072 0073 //! Test inequality 0074 inline constexpr bool operator!=(PDGNumber lhs, PDGNumber rhs) 0075 { 0076 return !(lhs == rhs); 0077 } 0078 0079 //! Allow less-than comparison for sorting 0080 inline constexpr bool operator<(PDGNumber lhs, PDGNumber rhs) 0081 { 0082 return lhs.unchecked_get() < rhs.unchecked_get(); 0083 } 0084 0085 /*! 0086 * Unique standard model particle identifiers by the Particle Data Group. 0087 * 0088 * This namespace acts an enumeration for PDG codes that are used by the 0089 * various processes in Celeritas. (Unlike an enumeration, though, PDG codes 0090 * can be arbitary and aren't limited to the ones defined below.) They should 0091 * be extended as needed when new particle types are used by processes. 0092 * 0093 * PDG numbers between 81 and 100 are reserved for internal use. 0094 * The table shows which internal arbitrary numbers are currently defined: 0095 * 0096 * | Particle name | PDG | 0097 * | ------------- | --- | 0098 * | Generic ion | 90 | 0099 */ 0100 namespace pdg 0101 { 0102 //---------------------------------------------------------------------------// 0103 //! \todo replace with inline constexpr value. 0104 #define CELER_DEFINE_PDGNUMBER(NAME, VALUE) \ 0105 inline constexpr PDGNumber NAME() \ 0106 { \ 0107 return PDGNumber{VALUE}; \ 0108 } 0109 0110 //!@{ 0111 //! \name Particle Data Group Monte Carlo number codes 0112 //! Sorted by `(abs(val), val < 0)`. 0113 //! See https://pdg.lbl.gov/2007/reviews/montecarlorpp.pdf 0114 0115 // Leptons 0116 CELER_DEFINE_PDGNUMBER(electron, 11) 0117 CELER_DEFINE_PDGNUMBER(positron, -11) 0118 CELER_DEFINE_PDGNUMBER(mu_minus, 13) 0119 CELER_DEFINE_PDGNUMBER(mu_plus, -13) 0120 CELER_DEFINE_PDGNUMBER(tau_minus, 15) 0121 CELER_DEFINE_PDGNUMBER(tau_plus, -15) 0122 0123 // Gauge bosons 0124 CELER_DEFINE_PDGNUMBER(gamma, 22) 0125 0126 // Codes 81–100 are reserved for generator-specific pseudoparticles 0127 CELER_DEFINE_PDGNUMBER(ion, 90) 0128 0129 // Light mesons 0130 CELER_DEFINE_PDGNUMBER(pi_plus, 211) 0131 CELER_DEFINE_PDGNUMBER(pi_minus, -211) 0132 CELER_DEFINE_PDGNUMBER(kaon_plus, 321) 0133 CELER_DEFINE_PDGNUMBER(kaon_minus, -321) 0134 CELER_DEFINE_PDGNUMBER(neutron, 2112) 0135 CELER_DEFINE_PDGNUMBER(anti_neutron, -2112) 0136 CELER_DEFINE_PDGNUMBER(proton, 2212) 0137 CELER_DEFINE_PDGNUMBER(anti_proton, -2212) 0138 0139 // Ions 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 //!@} 0150 0151 #undef CELER_DEFINE_PDGNUMBER 0152 //---------------------------------------------------------------------------// 0153 } // namespace pdg 0154 } // namespace celeritas 0155 0156 //---------------------------------------------------------------------------// 0157 // STD::HASH SPECIALIZATION FOR HOST CODE 0158 //---------------------------------------------------------------------------// 0159 //! \cond 0160 namespace std 0161 { 0162 //! Specialization for std::hash for unordered storage. 0163 template<> 0164 struct hash<celeritas::PDGNumber> 0165 { 0166 using argument_type = celeritas::PDGNumber; 0167 using result_type = std::size_t; 0168 result_type operator()(argument_type const& pdg) const noexcept 0169 { 0170 return std::hash<int>()(pdg.unchecked_get()); 0171 } 0172 }; 0173 } // namespace std 0174 //! \endcond
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |