CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
EposStack.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 
12 #include <corsika/framework/geometry/RootCoordinateSystem.hpp>
13 #include <corsika/framework/geometry/Vector.hpp>
15 #include <corsika/modules/epos/ParticleConversion.hpp>
16 
17 #include <epos.hpp>
18 
19 namespace corsika::epos {
20 
22 
23  class EposStackData {
24 
25  public:
26  void dump() const {}
27 
28  void clear() { ::epos::cptl_.nptl = 0; }
29  unsigned int getSize() const { return ::epos::cptl_.nptl; }
30  unsigned int getCapacity() const { return ::epos::mxptl; }
31 
32  void setId(const unsigned int i, const int v) { ::epos::cptl_.idptl[i] = v; }
33  void setEnergy(const unsigned int i, const HEPEnergyType v) {
34  ::epos::cptl_.pptl[i][3] = v / 1_GeV;
35  }
36  void setMass(const unsigned int i, const HEPMassType v) {
37  ::epos::cptl_.pptl[i][4] = v / 1_GeV;
38  }
39  void setMomentum(const unsigned int i, const MomentumVector& v) {
40  auto tmp = v.getComponents();
41  for (int idx = 0; idx < 3; ++idx) ::epos::cptl_.pptl[i][idx] = tmp[idx] / 1_GeV;
42  }
43  void setState(const unsigned int i, const int v) { ::epos::cptl_.istptl[i] = v; }
44 
45  int getId(const unsigned int i) const { return ::epos::cptl_.idptl[i]; }
46  int getState(const unsigned int i) const { return ::epos::cptl_.istptl[i]; }
47  HEPEnergyType getEnergy(const int i) const {
48  return ::epos::cptl_.pptl[i][3] * 1_GeV;
49  }
50  HEPEnergyType getMass(const unsigned int i) const {
51  return ::epos::cptl_.pptl[i][4] * 1_GeV;
52  }
53  MomentumVector getMomentum(const unsigned int i) const {
55  QuantityVector<hepmomentum_d> components = {::epos::cptl_.pptl[i][0] * 1_GeV,
56  ::epos::cptl_.pptl[i][1] * 1_GeV,
57  ::epos::cptl_.pptl[i][2] * 1_GeV};
58  return MomentumVector(rootCS, components);
59  }
60 
61  MomentumVector getMomentum(const unsigned int i,
62  const CoordinateSystemPtr& CS) const {
63  QuantityVector<hepmomentum_d> components = {::epos::cptl_.pptl[i][0] * 1_GeV,
64  ::epos::cptl_.pptl[i][1] * 1_GeV,
65  ::epos::cptl_.pptl[i][2] * 1_GeV};
66  return MomentumVector(CS, components);
67  }
68 
69  void copy(const unsigned int i1, const unsigned int i2) {
70  ::epos::cptl_.idptl[i2] = ::epos::cptl_.idptl[i1];
71  ::epos::cptl_.iorptl[i2] = ::epos::cptl_.iorptl[i1];
72  ::epos::cptl_.jorptl[i2] = ::epos::cptl_.jorptl[i1];
73  ::epos::cptl_.istptl[i2] = ::epos::cptl_.istptl[i1];
74  ::epos::cptl_.ityptl[i2] = ::epos::cptl_.ityptl[i1];
75  for (unsigned int i = 0; i < 5; ++i)
76  ::epos::cptl_.pptl[i2][i] = ::epos::cptl_.pptl[i1][i];
77  for (unsigned int i = 0; i < 2; ++i) {
78  ::epos::cptl_.tivptl[i2][i] = ::epos::cptl_.tivptl[i1][i];
79  ::epos::cptl_.ifrptl[i2][i] = ::epos::cptl_.ifrptl[i1][i];
80  }
81  for (unsigned int i = 0; i < 4; ++i) {
82  ::epos::cptl_.xorptl[i2][i] = ::epos::cptl_.xorptl[i1][i];
83  ::epos::cptl_.ibptl[i2][i] = ::epos::cptl_.ibptl[i1][i];
84  }
85  }
86 
87  void swap(const unsigned int i1, const unsigned int i2) {
88  std::swap(::epos::cptl_.idptl[i2], ::epos::cptl_.idptl[i1]);
89  std::swap(::epos::cptl_.iorptl[i2], ::epos::cptl_.iorptl[i1]);
90  std::swap(::epos::cptl_.jorptl[i2], ::epos::cptl_.jorptl[i1]);
91  std::swap(::epos::cptl_.istptl[i2], ::epos::cptl_.istptl[i1]);
92  std::swap(::epos::cptl_.ityptl[i2], ::epos::cptl_.ityptl[i1]);
93  for (unsigned int i = 0; i < 5; ++i)
94  std::swap(::epos::cptl_.pptl[i2][i], ::epos::cptl_.pptl[i1][i]);
95  for (unsigned int i = 0; i < 2; ++i) {
96  std::swap(::epos::cptl_.tivptl[i2][i], ::epos::cptl_.tivptl[i1][i]);
97  std::swap(::epos::cptl_.ifrptl[i2][i], ::epos::cptl_.ifrptl[i1][i]);
98  }
99  for (unsigned int i = 0; i < 4; ++i) {
100  std::swap(::epos::cptl_.xorptl[i2][i], ::epos::cptl_.xorptl[i1][i]);
101  std::swap(::epos::cptl_.ibptl[i2][i], ::epos::cptl_.ibptl[i1][i]);
102  }
103  }
104 
105  void incrementSize() { ::epos::cptl_.nptl++; }
106  void decrementSize() {
107  if (::epos::cptl_.nptl > 0) { ::epos::cptl_.nptl--; }
108  }
109  };
110 
111  template <typename StackIteratorInterface>
112  class ParticleInterface : public corsika::ParticleBase<StackIteratorInterface> {
113 
116 
117  public:
118  void setParticleData(const int vID, // corsika::epos::EposCode vID,
119  const HEPEnergyType vE, const MomentumVector& vP,
120  const HEPMassType vM) {
121  setPID(vID);
122  setEnergy(vE);
123  setMomentum(vP);
124  setMass(vM);
125  setState(0);
126  }
127 
128  void setParticleData(ParticleInterface<StackIteratorInterface>& /*parent*/,
129  const int vID, // corsika::epos::EposCode vID,
130  const HEPEnergyType vE, const MomentumVector& vP,
131  const HEPMassType vM) {
132  setPID(vID);
133  setEnergy(vE);
134  setMomentum(vP);
135  setMass(vM);
136  setState(0);
137  }
138 
139  void setEnergy(const HEPEnergyType v) { getStackData().setEnergy(getIndex(), v); }
140 
141  HEPEnergyType getEnergy() const { return getStackData().getEnergy(getIndex()); }
142 
143  bool isFinal() const { return getStackData().getState(getIndex()) == 0; }
144 
145  void setMass(const HEPMassType v) { getStackData().setMass(getIndex(), v); }
146 
147  HEPEnergyType getMass() const { return getStackData().getMass(getIndex()); }
148 
149  void setPID(const int v) { getStackData().setId(getIndex(), v); }
150 
151  corsika::epos::EposCode getPID() const {
152  return static_cast<corsika::epos::EposCode>(getStackData().getId(getIndex()));
153  }
154 
155  void setState(const int v) { getStackData().setState(getIndex(), v); }
156 
157  corsika::epos::EposCode getState() const {
158  return static_cast<corsika::epos::EposCode>(getStackData().getState(getIndex()));
159  }
160 
161  MomentumVector getMomentum() const { return getStackData().getMomentum(getIndex()); }
162 
163  MomentumVector getMomentum(const CoordinateSystemPtr& CS) const {
164  return getStackData().getMomentum(getIndex(), CS);
165  }
166 
167  void setMomentum(const MomentumVector& v) {
168  getStackData().setMomentum(getIndex(), v);
169  }
170  };
171 
173 
174 } // end namespace corsika::epos
Import and extend the phys::units package.
The Stack class provides (and connects) the main particle data storage machinery. ...
Definition: Stack.hpp:77
Vector< hepmomentum_d > MomentumVector
A 3D vector defined in a specific coordinate system with units HEPMomentumType.
CoordinateSystemPtr const & get_root_CoordinateSystem()
this is the only way to create ONE unique root CS
Description of particle stacks.
std::shared_ptr< CoordinateSystem const > CoordinateSystemPtr
To refer to CoordinateSystems, only the CoordinateSystemPtr must be used.
The base class to define the readout of particle properties from a particle stack.
QuantityVector< TDimension > const & getComponents() const