Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-21 07:46:20

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <cmath>
0012 #include <cstdint>
0013 #include <iosfwd>
0014 #include <stdexcept>
0015 #include <string>
0016 #include <utility>
0017 
0018 namespace Acts {
0019 
0020 /// Symbolic values for commonly used PDG particle numbers.
0021 enum PdgParticle : std::int32_t {
0022   eInvalid = 0,
0023   eElectron = 11,
0024   eAntiElectron = -eElectron,
0025   ePositron = -eElectron,
0026   eMuon = 13,
0027   eAntiMuon = -eMuon,
0028   eTau = 15,
0029   eAntiTau = -eTau,
0030   eGamma = 22,
0031   ePionZero = 111,
0032   ePionPlus = 211,
0033   ePionMinus = -ePionPlus,
0034   eKaonPlus = 321,
0035   eKaonMinus = -eKaonPlus,
0036   eNeutron = 2112,
0037   eAntiNeutron = -eNeutron,
0038   eProton = 2212,
0039   eAntiProton = -eProton,
0040   eLead = 1000822080,
0041   eKaon0Short = 310,
0042   eLambda0 = 3122,
0043   eJPsi = 443,   // J/ψ
0044   eB0 = 511,     // B0 meson (bd)
0045   eBPlus = 521,  // B+ meson (bu)
0046   eD0 = 421,     // D0 meson (cu)
0047   eDPlus = 411,  // D+ meson (cd)
0048   eAntiB0 = -eB0,
0049   eAntiD0 = -eD0,
0050   eNeutrinoE = 12,    // electron neutrino
0051   eNeutrinoMu = 14,   // muon neutrino
0052   eNeutrinoTau = 16,  // tau neutrino
0053   eAntiNeutrinoE = -eNeutrinoE,
0054   eAntiNeutrinoMu = -eNeutrinoMu,
0055   eAntiNeutrinoTau = -eNeutrinoTau
0056 };
0057 
0058 /// Convert an anti-particle to its particle and leave particles as-is.
0059 /// @param pdg The PDG particle code
0060 /// @return The absolute PDG particle code
0061 static constexpr PdgParticle makeAbsolutePdgParticle(PdgParticle pdg) {
0062   const auto value = static_cast<std::int32_t>(pdg);
0063   return static_cast<PdgParticle>((0 <= value) ? value : -value);
0064 }
0065 
0066 /// Check if the PDG belongs to a nucleus, i.e. if it has 10 digits.
0067 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0068 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0069 /// @param pdg The PDG particle code
0070 /// @return True if the PDG code represents a nucleus
0071 static constexpr bool isNucleus(PdgParticle pdg) {
0072   const auto value = static_cast<std::int32_t>(pdg);
0073   return std::abs(value) > 1e9;
0074 }
0075 
0076 /// Convert an excited nucleus to its ground state. PDG number of a nucleus has
0077 /// a form 10LZZZAAAI, where I is isomer level; I=0 is the ground state.
0078 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0079 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0080 /// @param pdg The PDG particle code of the nucleus
0081 /// @return The PDG particle code of the nucleus in its ground state
0082 static constexpr PdgParticle makeNucleusGroundState(PdgParticle pdg) {
0083   if (!isNucleus(pdg)) {
0084     throw std::invalid_argument("PDG must represent a nucleus");
0085   }
0086   // set isomer level to zero
0087   const auto value = static_cast<std::int32_t>(pdg);
0088   return static_cast<PdgParticle>((value / 10) * 10);
0089 }
0090 
0091 /// Extract Z and A for a given nucleus. PDG number of a nucleus has a form
0092 /// 10LZZZAAAI, where L is number of lambdas, ZZZ is proton number, AAA is
0093 /// atomic number, I is isomer level. See PDG section "Monte Carlo Particle
0094 /// Numbering Scheme" , point 16:
0095 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0096 /// @param pdg The PDG particle code of the nucleus
0097 /// @return A pair containing the proton number (Z) and atomic number (A)
0098 static constexpr std::pair<std::int32_t, std::int32_t> extractNucleusZandA(
0099     PdgParticle pdg) {
0100   if (!isNucleus(pdg)) {
0101     throw std::invalid_argument("PDG must represent a nucleus");
0102   }
0103   const auto value = static_cast<std::int32_t>(pdg);
0104   // proton number respects the charge
0105   int Z = (value / 10000) % 1000;
0106   // atomic number is always positive
0107   int A = std::abs((value / 10) % 1000);
0108   return std::make_pair(Z, A);
0109 }
0110 
0111 /// Hadron type classification for B, C, strange and light hadrons.
0112 enum class HadronType {
0113   Hadron = 1,
0114   BBbarMeson = 2,
0115   CCbarMeson = 3,
0116   BottomMeson = 4,
0117   BottomBaryon = 5,
0118   CharmedMeson = 6,
0119   CharmedBaryon = 7,
0120   StrangeMeson = 8,
0121   StrangeBaryon = 9,
0122   LightMeson = 10,
0123   LightBaryon = 11,
0124   Unknown = 12
0125 };
0126 
0127 /// Stream operator for HadronType
0128 /// @param os Output stream
0129 /// @param hadron The hadron type to output
0130 /// @return Reference to output stream
0131 std::ostream& operator<<(std::ostream& os, HadronType hadron);
0132 
0133 /// Parse a PdgParticle from a particle name string.
0134 /// Supports common particle names like "e-", "e+", "mu-", "mu+", "tau-",
0135 /// "tau+", "gamma", "pi0", "pi+", "pi-", "K+", "K-", "n", "n~", "p", "p~",
0136 /// "Pb".
0137 /// @param name The particle name string
0138 /// @return The corresponding PdgParticle enum value
0139 /// @throws std::invalid_argument if the name is not recognized
0140 PdgParticle parsePdgParticle(const std::string& name);
0141 
0142 }  // namespace Acts