Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:11:44

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 <stdexcept>
0014 #include <utility>
0015 
0016 namespace Acts {
0017 
0018 /// Symbolic values for commonly used PDG particle numbers.
0019 enum PdgParticle : std::int32_t {
0020   eInvalid = 0,
0021   eElectron = 11,
0022   eAntiElectron = -eElectron,
0023   ePositron = -eElectron,
0024   eMuon = 13,
0025   eAntiMuon = -eMuon,
0026   eTau = 15,
0027   eAntiTau = -eTau,
0028   eGamma = 22,
0029   ePionZero = 111,
0030   ePionPlus = 211,
0031   ePionMinus = -ePionPlus,
0032   eKaonPlus = 321,
0033   eKaonMinus = -eKaonPlus,
0034   eNeutron = 2112,
0035   eAntiNeutron = -eNeutron,
0036   eProton = 2212,
0037   eAntiProton = -eProton,
0038   eLead = 1000822080
0039 };
0040 
0041 /// Convert an anti-particle to its particle and leave particles as-is.
0042 static constexpr PdgParticle makeAbsolutePdgParticle(PdgParticle pdg) {
0043   const auto value = static_cast<std::int32_t>(pdg);
0044   return static_cast<PdgParticle>((0 <= value) ? value : -value);
0045 }
0046 
0047 /// Check if the PDG belongs to a nucleus, i.e. if it has 10 digits.
0048 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0049 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0050 static constexpr bool isNucleus(PdgParticle pdg) {
0051   const auto pdgNum = static_cast<std::int32_t>(pdg);
0052   return std::abs(pdgNum) > 1e9;
0053 }
0054 
0055 /// Convert an excited nucleus to its ground state. PDG number of a nucleus has
0056 /// a form 10LZZZAAAI, where I is isomer level; I=0 is the ground state.
0057 /// See PDG section "Monte Carlo Particle Numbering Scheme", point 16:
0058 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0059 static constexpr PdgParticle makeNucleusGroundState(PdgParticle pdg) {
0060   if (!isNucleus(pdg)) {
0061     throw std::invalid_argument("PDG must represent a nucleus");
0062   }
0063   const auto pdgNum = static_cast<std::int32_t>(pdg);
0064   // set isomer level to zero
0065   return static_cast<PdgParticle>((pdgNum / 10) * 10);
0066 }
0067 
0068 /// Extract Z and A for a given nucleus. PDG number of a nucleus has a form
0069 /// 10LZZZAAAI, where L is number of lambdas, ZZZ is proton number, AAA is
0070 /// atomic number, I is isomer level. See PDG section "Monte Carlo Particle
0071 /// Numbering Scheme" , point 16:
0072 /// https://pdg.lbl.gov/2025/reviews/rpp2024-rev-monte-carlo-numbering.pdf
0073 static constexpr std::pair<std::int32_t, std::int32_t> extractNucleusZandA(
0074     PdgParticle pdg) {
0075   if (!isNucleus(pdg)) {
0076     throw std::invalid_argument("PDG must represent a nucleus");
0077   }
0078   const auto pdgNum = static_cast<std::int32_t>(pdg);
0079   // proton number respects the charge
0080   int Z = (pdgNum / 10000) % 1000;
0081   // atomic number is always positive
0082   int A = std::abs((pdgNum / 10) % 1000);
0083   return std::make_pair(Z, A);
0084 }
0085 
0086 }  // namespace Acts