Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:22:14

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   eJPsi = 443,   // J/ψ
0042   eB0 = 511,     // B0 meson (bd)
0043   eBPlus = 521,  // B+ meson (bu)
0044   eD0 = 421,     // D0 meson (cu)
0045   eDPlus = 411,  // D+ meson (cd)
0046   eAntiB0 = -eB0,
0047   eAntiD0 = -eD0,
0048   eNeutrinoE = 12,    // electron neutrino
0049   eNeutrinoMu = 14,   // muon neutrino
0050   eNeutrinoTau = 16,  // tau neutrino
0051   eAntiNeutrinoE = -eNeutrinoE,
0052   eAntiNeutrinoMu = -eNeutrinoMu,
0053   eAntiNeutrinoTau = -eNeutrinoTau
0054 };
0055 
0056 /// Convert an anti-particle to its particle and leave particles as-is.
0057 static constexpr PdgParticle makeAbsolutePdgParticle(PdgParticle pdg) {
0058   const auto value = static_cast<std::int32_t>(pdg);
0059   return static_cast<PdgParticle>((0 <= value) ? value : -value);
0060 }
0061 
0062 /// Check if the PDG belongs to a nucleus, i.e. if it has 10 digits.
0063 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0064 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0065 static constexpr bool isNucleus(PdgParticle pdg) {
0066   const auto value = static_cast<std::int32_t>(pdg);
0067   return std::abs(value) > 1e9;
0068 }
0069 
0070 /// Convert an excited nucleus to its ground state. PDG number of a nucleus has
0071 /// a form 10LZZZAAAI, where I is isomer level; I=0 is the ground state.
0072 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0073 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0074 static constexpr PdgParticle makeNucleusGroundState(PdgParticle pdg) {
0075   if (!isNucleus(pdg)) {
0076     throw std::invalid_argument("PDG must represent a nucleus");
0077   }
0078   // set isomer level to zero
0079   const auto value = static_cast<std::int32_t>(pdg);
0080   return static_cast<PdgParticle>((value / 10) * 10);
0081 }
0082 
0083 /// Extract Z and A for a given nucleus. PDG number of a nucleus has a form
0084 /// 10LZZZAAAI, where L is number of lambdas, ZZZ is proton number, AAA is
0085 /// atomic number, I is isomer level. See PDG section "Monte Carlo Particle
0086 /// Numbering Scheme" , point 16:
0087 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0088 static constexpr std::pair<std::int32_t, std::int32_t> extractNucleusZandA(
0089     PdgParticle pdg) {
0090   if (!isNucleus(pdg)) {
0091     throw std::invalid_argument("PDG must represent a nucleus");
0092   }
0093   const auto value = static_cast<std::int32_t>(pdg);
0094   // proton number respects the charge
0095   int Z = (value / 10000) % 1000;
0096   // atomic number is always positive
0097   int A = std::abs((value / 10) % 1000);
0098   return std::make_pair(Z, A);
0099 }
0100 
0101 /// Hadron type classification for B, C, strange and light hadrons.
0102 enum class HadronType {
0103   Hadron = 1,
0104   BBbarMeson = 2,
0105   CCbarMeson = 3,
0106   BottomMeson = 4,
0107   BottomBaryon = 5,
0108   CharmedMeson = 6,
0109   CharmedBaryon = 7,
0110   StrangeMeson = 8,
0111   StrangeBaryon = 9,
0112   LightMeson = 10,
0113   LightBaryon = 11,
0114   Unknown = 12
0115 };
0116 
0117 std::ostream& operator<<(std::ostream& os, HadronType hadron);
0118 
0119 /// Parse a PdgParticle from a particle name string.
0120 /// Supports common particle names like "e-", "e+", "mu-", "mu+", "tau-",
0121 /// "tau+", "gamma", "pi0", "pi+", "pi-", "K+", "K-", "n", "n~", "p", "p~",
0122 /// "Pb".
0123 /// @param name The particle name string
0124 /// @return The corresponding PdgParticle enum value
0125 /// @throws std::invalid_argument if the name is not recognized
0126 PdgParticle parsePdgParticle(const std::string& name);
0127 
0128 }  // namespace Acts