CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
NuclearStackExtension.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 
14 #include <corsika/framework/geometry/Point.hpp>
15 #include <corsika/framework/geometry/Vector.hpp>
16 #include <corsika/framework/geometry/PhysicalGeometry.hpp>
17 #include <corsika/stack/VectorStack.hpp>
18 
19 #include <algorithm>
20 #include <tuple>
21 #include <vector>
22 
23 namespace corsika::nuclear_stack {
24 
42  template <template <typename> class InnerParticleInterface,
43  typename StackIteratorInterface>
45  : public InnerParticleInterface<StackIteratorInterface> {
46 
47  typedef InnerParticleInterface<StackIteratorInterface> super_type;
48 
49  public:
50  typedef std::tuple<Code, HEPEnergyType, DirectionVector, Point, TimeType,
51  unsigned short, unsigned short>
52  nuclear_particle_data_type;
53 
54  typedef std::tuple<Code, MomentumVector, Point, TimeType, unsigned short,
55  unsigned short>
56  nuclear_particle_data_momentum_type;
57 
63  void setParticleData(typename super_type::particle_data_type const& v);
64 
70  void setParticleData(nuclear_particle_data_type const& v);
71 
78  void setParticleData(super_type& p, typename super_type::particle_data_type const& v);
79 
86  void setParticleData(super_type& p, nuclear_particle_data_type const& v);
87 
93  void setParticleData(typename super_type::particle_data_momentum_type const& v);
94 
100  void setParticleData(nuclear_particle_data_momentum_type const& v);
101 
108  void setParticleData(super_type& p,
109  typename super_type::particle_data_momentum_type const& v);
110 
117  void setParticleData(super_type& p, nuclear_particle_data_momentum_type const& v);
118 
119  std::string asString() const;
120 
125  void setNuclearA(const unsigned short vA) {
126  super_type::getStackData().setNuclearA(super_type::getIndex(), vA);
127  }
128  void setNuclearZ(const unsigned short vZ) {
129  super_type::getStackData().setNuclearZ(super_type::getIndex(), vZ);
130  }
132 
137  int getNuclearA() const {
138  return super_type::getStackData().getNuclearA(super_type::getIndex());
139  }
140  int getNuclearZ() const {
141  return super_type::getStackData().getNuclearZ(super_type::getIndex());
142  }
144 
148  PDGCode getPDG() const;
149 
153  void setMomentum(MomentumVector const& v);
154 
158  MomentumVector getMomentum() const;
159 
163  void setEnergy(HEPEnergyType const& e);
164 
168  VelocityVector getVelocity() const;
169 
173  HEPMassType getMass() const;
174 
179 
183  HEPEnergyType getEnergy() const;
184 
188  int16_t getChargeNumber() const;
189 
190  int getNucleusRef() const {
191  return super_type::getStackData().getNucleusRef(super_type::getIndex());
192  } // LCOV_EXCL_LINE
193 
194  protected:
195  void setNucleusRef(const int vR) {
196  super_type::getStackData().setNucleusRef(super_type::getIndex(), vR);
197  }
198 
199  bool isNucleus() const {
200  return super_type::getStackData().isNucleus(super_type::getIndex());
201  }
202  };
203 
216  template <typename InnerStackImpl>
217  class NuclearStackExtensionImpl : public InnerStackImpl {
218 
219  typedef InnerStackImpl super_type;
220 
221  public:
222  typedef std::vector<int> nucleus_ref_type;
223  typedef std::vector<unsigned short> nuclear_a_type;
224  typedef std::vector<unsigned short> nuclear_z_type;
225 
226  NuclearStackExtensionImpl() = default;
227 
229 
231 
234 
237 
238  void init() { super_type::init(); }
239 
240  void dump() { super_type::dump(); }
241 
242  void clear();
243 
244  unsigned int getSize() const { return nucleusRef_.size(); }
245 
246  unsigned int getCapacity() const { return nucleusRef_.capacity(); }
247 
248  void setNuclearA(const unsigned int i, const unsigned short vA) {
249  nuclearA_[getNucleusRef(i)] = vA;
250  }
251 
252  void setNuclearZ(const unsigned int i, const unsigned short vZ) {
253  nuclearZ_[getNucleusRef(i)] = vZ;
254  }
255 
256  void setNucleusRef(const unsigned int i, const int v) { nucleusRef_[i] = v; }
257 
258  int getNuclearA(const unsigned int i) const { return nuclearA_[getNucleusRef(i)]; }
259 
260  int getNuclearZ(const unsigned int i) const { return nuclearZ_[getNucleusRef(i)]; }
261 
262  // this function will create new storage for Nuclear Properties, and return the
263  // reference to it
264  int getNucleusNextRef();
265 
266  int getNucleusRef(const unsigned int i) const;
267 
268  bool isNucleus(const unsigned int i) const { return nucleusRef_[i] >= 0; }
269 
273  void copy(const unsigned int i1, const unsigned int i2);
277  void swap(const unsigned int i1, const unsigned int i2);
278 
279  void incrementSize();
280 
281  void decrementSize();
282 
283  private:
285 
286  nucleus_ref_type nucleusRef_;
287  nuclear_a_type nuclearA_;
288  nuclear_z_type nuclearZ_;
289 
290  }; // end class NuclearStackExtensionImpl
291 
292  template <typename TInnerStack, template <typename> typename PI_>
293  using NuclearStackExtension =
295 
296  //
297  template <typename TStackIter>
300 
301  // the particle data stack with extra nuclear information:
302  using ParticleDataStack =
304 
305 } // namespace corsika::nuclear_stack
306 
307 #include <corsika/detail/stack/NuclearStackExtension.inl>
Import and extend the phys::units package.
The Stack class provides (and connects) the main particle data storage machinery. ...
Definition: Stack.hpp:77
HEPEnergyType getEnergy() const
Overwrite normal getEnergy function with nuclear version.
Vector< hepmomentum_d > MomentumVector
A 3D vector defined in a specific coordinate system with units HEPMomentumType.
PDGCode getPDG() const
Overwrite normal getPDG function with nuclear version.
MomentumVector getMomentum() const
Overwrite normal getMomentum function with nuclear version.
Description of particle stacks.
VelocityVector getVelocity() const
Overwrite normal getVelocity function with nuclear version.
Define ParticleInterface for NuclearStackExtension Stack derived from ParticleInterface of Inner stac...
void setEnergy(HEPEnergyType const &e)
Overwrite normal getEnergy function with nuclear version.
HEPMassType getMass() const
Overwrite normal getMass function with nuclear version.
Vector< dimensionless_d > DirectionVector
A 3D vector defined in a specific coordinate system with no units.
void setParticleData(typename super_type::particle_data_type const &v)
Interface to particle properties.
ElectricChargeType getCharge() const
Overwrite normal getParticleCharge function with nuclear version.
int16_t getChargeNumber() const
Overwirte normal getChargeNumber function with nuclear version.
void setMomentum(MomentumVector const &v)
Overwrite normal setMomentum function with nuclear version.