CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
SibStack.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/sibyll/ParticleConversion.hpp>
16 
17 #include <sibyll2.3d.hpp>
18 
19 namespace corsika::sibyll {
20 
22 
23  class SibStackData {
24 
25  public:
26  void dump() const {}
27 
28  void clear() { s_plist_.np = 0; }
29  unsigned int getSize() const { return s_plist_.np; }
30  unsigned int getCapacity() const { return 8000; }
31 
32  void setId(const unsigned int i, const int v) { s_plist_.llist[i] = v; }
33  void setEnergy(const unsigned int i, const HEPEnergyType v) {
34  s_plist_.p[3][i] = v / 1_GeV;
35  }
36  void setMass(const unsigned int i, const HEPMassType v) {
37  s_plist_.p[4][i] = 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) s_plist_.p[idx][i] = tmp[idx] / 1_GeV;
42  }
43 
44  int getId(const unsigned int i) const { return s_plist_.llist[i]; }
45  HEPEnergyType getEnergy(const int i) const { return s_plist_.p[3][i] * 1_GeV; }
46  HEPEnergyType getMass(const unsigned int i) const { return s_plist_.p[4][i] * 1_GeV; }
47  MomentumVector getMomentum(const unsigned int i) const {
49  QuantityVector<hepmomentum_d> components = {
50  s_plist_.p[0][i] * 1_GeV, s_plist_.p[1][i] * 1_GeV, s_plist_.p[2][i] * 1_GeV};
51  return MomentumVector(rootCS, components);
52  }
53 
54  void copy(const unsigned int i1, const unsigned int i2) {
55  s_plist_.llist[i2] = s_plist_.llist[i1];
56  for (unsigned int i = 0; i < 5; ++i) s_plist_.p[i][i2] = s_plist_.p[i][i1];
57  }
58 
59  void swap(const unsigned int i1, const unsigned int i2) {
60  std::swap(s_plist_.llist[i1], s_plist_.llist[i2]);
61  for (unsigned int i = 0; i < 5; ++i)
62  std::swap(s_plist_.p[i][i1], s_plist_.p[i][i2]);
63  }
64 
65  void incrementSize() { s_plist_.np++; }
66  void decrementSize() {
67  if (s_plist_.np > 0) { s_plist_.np--; }
68  }
69  };
70 
71  template <typename TStackIterator>
72  class ParticleInterface : public corsika::ParticleBase<TStackIterator> {
73 
76 
77  public:
78  void setParticleData(const int vID, const HEPEnergyType vE, const MomentumVector& vP,
79  const HEPMassType vM) {
80  setPID(vID);
81  setEnergy(vE);
82  setMomentum(vP);
83  setMass(vM);
84  }
85 
86  void setParticleData(ParticleInterface<TStackIterator>& /*parent*/, const int vID,
87  const HEPEnergyType vE, const MomentumVector& vP,
88  const HEPMassType vM) {
89  setPID(vID);
90  setEnergy(vE);
91  setMomentum(vP);
92  setMass(vM);
93  }
94 
95  void setEnergy(const HEPEnergyType v) { getStackData().setEnergy(getIndex(), v); }
96 
97  HEPEnergyType getEnergy() const { return getStackData().getEnergy(getIndex()); }
98 
99  bool hasDecayed() const { return abs(getStackData().getId(getIndex())) > 100; }
100 
101  void setMass(const HEPMassType v) { getStackData().setMass(getIndex(), v); }
102 
103  HEPEnergyType getMass() const { return getStackData().getMass(getIndex()); }
104 
105  void setPID(const int v) { getStackData().setId(getIndex(), v); }
106 
107  corsika::sibyll::SibyllCode getPID() const {
108  return static_cast<corsika::sibyll::SibyllCode>(getStackData().getId(getIndex()));
109  }
110 
111  MomentumVector getMomentum() const { return getStackData().getMomentum(getIndex()); }
112 
113  void setMomentum(const MomentumVector& v) {
114  getStackData().setMomentum(getIndex(), v);
115  }
116  };
117 
119 
120 } // end namespace corsika::sibyll
quantity< D, X > constexpr abs(quantity< D, X > const &x)
absolute value.
Definition: quantity.hpp:632
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