CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
ParticleConversion.hpp
1 /*
2  * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
9 #pragma once
10 
11 #include <array>
12 #include <cstdint>
13 #include <type_traits>
14 
17 
18 #include <epos.hpp>
19 
20 #include <string>
21 
22 namespace corsika::epos {
23 
24  enum class EposCode : int32_t;
25  using EposCodeIntType = std::underlying_type<EposCode>::type;
26 
30  enum class EposXSClass : int8_t {
31  CannotInteract = 0,
32  Baryon = 2,
33  Pion = 1,
34  Kaon = 3,
35  Charm = 4,
36  };
37  using EposXSClassIntType = std::underlying_type<EposXSClass>::type;
38 
39 #include <corsika/modules/epos/Generated.inc>
40 
41  unsigned int constexpr get_nucleus_A(EposCode const eposId) {
42  // 100ZZZAAA0 -> std. pdg code
43  EposCodeIntType const eposPdg = static_cast<EposCodeIntType>(eposId);
44  return int(eposPdg / 10) % 1000;
45  }
46  unsigned int constexpr get_nucleus_Z(EposCode const eposId) {
47  // 100ZZZAAA0 -> std. pdg code
48  EposCodeIntType const eposPdg = static_cast<EposCodeIntType>(eposId);
49  return int(eposPdg / 10000) % 1000;
50  }
51 
52  EposCode constexpr convertToEpos(Code const code) {
53  return corsika2epos[static_cast<CodeIntType>(code)];
54  }
55 
56  Code constexpr convertFromEpos(EposCode const eposId) {
57  EposCodeIntType const s = static_cast<EposCodeIntType>(eposId);
58  // if nucleus (pdg-id)
59  if (s >= 1000000000) {
60  return get_nucleus_code(get_nucleus_A(eposId), get_nucleus_Z(eposId));
61  }
62  auto const corsikaCode = epos2corsika[s - minEpos];
63  if (corsikaCode == Code::Unknown) {
64  throw std::runtime_error(std::string("EPOS/CORSIKA conversion of ")
65  .append(std::to_string(s))
66  .append(" impossible"));
67  }
68  return corsikaCode;
69  }
70 
71  int constexpr convertToEposRaw(Code const code) {
72  return static_cast<int>(convertToEpos(code));
73  }
74 
75  int constexpr getEposXSCode(Code const code) {
76  if (is_nucleus(code)) { return static_cast<EposXSClassIntType>(EposXSClass::Baryon); }
77  return static_cast<EposXSClassIntType>(
78  corsika2eposXStype[static_cast<CodeIntType>(code)]);
79  }
80 
81  bool constexpr canInteract(Code const code) {
82  return is_nucleus(code) || getEposXSCode(code) > 0;
83  }
84 
85  HEPMassType getEposMass(Code const);
86 
87  PDGCode getEposPDGId(Code const);
88 
89 } // namespace corsika::epos
90 
91 #include <corsika/detail/modules/epos/ParticleConversion.inl>
Import and extend the phys::units package.
Code constexpr get_nucleus_code(size_t const A, size_t const Z)
Creates the Code for a nucleus of type 10LZZZAAAI.
size_t constexpr get_nucleus_A(Code const)
Get the mass number A for nucleus.
std::string to_string(long double const value)
string representation of value.
size_t constexpr get_nucleus_Z(Code const)
Get the charge number Z for nucleus.
bool constexpr is_nucleus(Code const)
Checks if Code corresponds to a nucleus.
Interface to particle properties.