CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
ParticleConversion.hpp
1 /*
2  * (c) Copyright 2020 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 
12 
13 #include <string>
14 
15 namespace corsika::qgsjetII {
16 
20  enum class QgsjetIICode : int8_t;
21  using QgsjetIICodeIntType = std::underlying_type<QgsjetIICode>::type;
22 
26  enum class QgsjetIIXSClass : int8_t {
27  CannotInteract = 0,
28  LightMesons = 1,
29  Baryons = 2,
30  Kaons = 3,
31  };
32  using QgsjetIIXSClassIntType = std::underlying_type<QgsjetIIXSClass>::type;
33 
37  enum class QgsjetIIHadronType : int8_t {
38  UndefinedType = 0,
39  PiPlusType = +1,
40  PiMinusType = -1,
41  ProtonType = +2,
42  AntiProtonType = -2,
43  NeutronType = +3,
44  AntiNeutronType = -3,
45  KaonPlusType = +4,
46  KaonMinusType = -4,
47  Kaon0LType = +5,
48  Kaon0SType = -5,
49  // special codes, not in QGSJetII
50  NucleusType = 100,
51  NeutralLightMesonType = 101,
52  };
53  using QgsjetIIHadronTypeIntType = std::underlying_type<QgsjetIIHadronType>::type;
54 } // namespace corsika::qgsjetII
55 
56 // include automatically generated code:
57 #include <corsika/modules/qgsjetII/Generated.inc>
58 
59 namespace corsika::qgsjetII {
60 
61  QgsjetIICode constexpr convertToQgsjetII(Code const pCode) {
62  return corsika2qgsjetII[static_cast<CodeIntType>(pCode)];
63  }
64 
65  Code constexpr convertFromQgsjetII(QgsjetIICode const code) {
66  auto const codeInt = static_cast<QgsjetIICodeIntType>(code);
67  auto const corsikaCode = qgsjetII2corsika[codeInt - minQgsjetII];
68  if (corsikaCode == Code::Unknown) {
69  throw std::runtime_error(std::string("QGSJETII/CORSIKA conversion of pCodeInt=")
70  .append(std::to_string(codeInt))
71  .append(" impossible"));
72  }
73  return corsikaCode;
74  }
75 
76  QgsjetIICodeIntType constexpr convertToQgsjetIIRaw(Code const code) {
77  return static_cast<QgsjetIICodeIntType>(convertToQgsjetII(code));
78  }
79 
80  QgsjetIIXSClass constexpr getQgsjetIIXSCode(Code const code) {
81  return is_nucleus(code) ? QgsjetIIXSClass::Baryons
82  : corsika2qgsjetIIXStype[static_cast<CodeIntType>(code)];
83  }
84 
85  QgsjetIIXSClassIntType constexpr getQgsjetIIXSCodeRaw(Code const code) {
86  return is_nucleus(code)
87  ? static_cast<QgsjetIIXSClassIntType>(QgsjetIIXSClass::Baryons)
88  : static_cast<QgsjetIIXSClassIntType>(getQgsjetIIXSCode(code));
89  }
90 
91  bool constexpr canInteract(Code const code) {
92  if (is_nucleus(code)) return true;
93  return getQgsjetIIXSCode(code) != QgsjetIIXSClass::CannotInteract;
94  }
95 
96  QgsjetIIHadronType constexpr getQgsjetIIHadronType(Code const code) {
97  if (is_nucleus(code)) return QgsjetIIHadronType::NucleusType;
98  return corsika2qgsjetIIHadronType[static_cast<CodeIntType>(code)];
99  }
100 
101 } // namespace corsika::qgsjetII
std::string to_string(long double const value)
string representation of value.
bool constexpr is_nucleus(Code const)
Checks if Code corresponds to a nucleus.
Interface to particle properties.