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