CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
VectorStack.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 
15 #include <corsika/framework/geometry/Point.hpp>
16 #include <corsika/framework/geometry/Vector.hpp>
17 #include <corsika/framework/geometry/PhysicalGeometry.hpp>
18 
19 #include <string>
20 #include <tuple>
21 #include <vector>
22 
23 namespace corsika {
24 
29  template <typename TStackIterator>
30  class ParticleInterface : public ParticleBase<TStackIterator> {
31 
32  private:
34 
35  public:
36  typedef std::tuple<Code, HEPEnergyType, DirectionVector, Point, TimeType>
37  particle_data_type;
38 
39  typedef std::tuple<Code, MomentumVector, Point, TimeType> particle_data_momentum_type;
40 
41  std::string asString() const;
42 
51  void setParticleData(particle_data_type const& v);
52 
63  particle_data_type const& v);
64 
71  void setParticleData(particle_data_momentum_type const& v);
72 
81  particle_data_momentum_type const& v);
82 
84  void setPID(Code const id) {
85  super_type::getStackData().setPID(super_type::getIndex(), id);
86  }
87 
89  void setEnergy(HEPEnergyType const& e) {
90  super_type::getStackData().setKineticEnergy(super_type::getIndex(),
91  e - this->getMass());
92  }
93 
95  void setKineticEnergy(HEPEnergyType const& ekin) {
96  super_type::getStackData().setKineticEnergy(super_type::getIndex(), ekin);
97  }
98 
103  void setMomentum(MomentumVector const& v) {
104  HEPMomentumType const P = v.getNorm();
105  if (P == 0_eV) {
106  super_type::getStackData().setKineticEnergy(super_type::getIndex(), 0_eV);
107  super_type::getStackData().setDirection(
108  super_type::getIndex(), DirectionVector(v.getCoordinateSystem(), {0, 0, 0}));
109  } else {
110  super_type::getStackData().setKineticEnergy(
112  sqrt(square(getMass()) + square(P)) - this->getMass());
113  super_type::getStackData().setDirection(super_type::getIndex(), v / P);
114  }
115  }
117  void setDirection(DirectionVector const& v) {
118  super_type::getStackData().setDirection(super_type::getIndex(), v);
119  }
121  void setPosition(Point const& v) {
122  super_type::getStackData().setPosition(super_type::getIndex(), v);
123  }
125  void setTime(TimeType const& v) {
126  super_type::getStackData().setTime(super_type::getIndex(), v);
127  }
128 
130  Code getPID() const {
131  return super_type::getStackData().getPID(super_type::getIndex());
132  }
134  PDGCode getPDG() const { return get_PDG(getPID()); }
137  return super_type::getStackData().getKineticEnergy(super_type::getIndex());
138  }
141  return super_type::getStackData().getDirection(super_type::getIndex());
142  }
144  Point getPosition() const {
145  return super_type::getStackData().getPosition(super_type::getIndex());
146  }
148  TimeType getTime() const {
149  return super_type::getStackData().getTime(super_type::getIndex());
150  }
156  VelocityVector getVelocity() const {
158  return this->getMomentum() / this->getEnergy() * constants::c;
159  }
162  auto const P = sqrt(square(getEnergy()) - square(this->getMass()));
163  return super_type::getStackData().getDirection(super_type::getIndex()) * P;
164  }
166  HEPMassType getMass() const { return get_mass(this->getPID()); }
167 
169  ElectricChargeType getCharge() const { return get_charge(this->getPID()); }
170 
172  HEPEnergyType getEnergy() const { return this->getKineticEnergy() + this->getMass(); }
173 
175  int16_t getChargeNumber() const { return get_charge_number(this->getPID()); }
177  };
178 
187 
188  public:
189  typedef std::vector<Code> code_vector_type;
190  typedef std::vector<HEPEnergyType> kinetic_energy_vector_type;
191  typedef std::vector<Point> point_vector_type;
192  typedef std::vector<TimeType> time_vector_type;
193  typedef std::vector<DirectionVector> direction_vector_type;
194 
195  VectorStackImpl() = default;
196 
197  VectorStackImpl(VectorStackImpl const& other) = default;
198 
199  VectorStackImpl(VectorStackImpl&& other) = default;
200 
201  VectorStackImpl& operator=(VectorStackImpl const& other) = default;
202 
203  VectorStackImpl& operator=(VectorStackImpl&& other) = default;
204 
205  void dump() const {}
206 
207  void clear();
208 
209  unsigned int getSize() const { return dataPID_.size(); }
210  unsigned int getCapacity() const { return dataPID_.size(); }
211 
212  void setPID(size_t i, Code const id) { dataPID_[i] = id; }
213  void setKineticEnergy(size_t i, HEPEnergyType const& e) { dataEkin_[i] = e; }
214  void setDirection(size_t i, DirectionVector const& v) { direction_[i] = v; }
215  void setPosition(size_t i, Point const& v) { position_[i] = v; }
216  void setTime(size_t i, TimeType const& v) { time_[i] = v; }
217 
218  Code getPID(size_t i) const { return dataPID_[i]; }
219  HEPEnergyType getKineticEnergy(size_t i) const { return dataEkin_[i]; }
220  DirectionVector getDirection(size_t i) const { return direction_[i]; }
221  Point getPosition(size_t i) const { return position_[i]; }
222  TimeType getTime(size_t i) const { return time_[i]; }
223 
227  void copy(size_t i1, size_t i2);
228 
232  void swap(size_t i1, size_t i2);
233 
234  void incrementSize();
235  void decrementSize();
236 
237  private:
239  code_vector_type dataPID_;
240  kinetic_energy_vector_type dataEkin_;
241  direction_vector_type direction_;
242  point_vector_type position_;
243  time_vector_type time_;
244 
245  }; // end class VectorStackImpl
246 
248 
249 } // namespace corsika
250 
251 #include <corsika/detail/stack/VectorStack.inl>
Memory implementation of the most simple (stupid) particle stack object.
int16_t getChargeNumber() const
Get charge number.
Import and extend the phys::units package.
void setKineticEnergy(HEPEnergyType const &ekin)
! Set kinetic energy
Definition: VectorStack.hpp:95
The Stack class provides (and connects) the main particle data storage machinery. ...
Definition: Stack.hpp:77
void setDirection(DirectionVector const &v)
Set direction.
void setTime(TimeType const &v)
Set time.
Point getPosition() const
Get position.
HEPMassType getMass() const
Get mass of particle.
DirectionVector getDirection() const
Get direction.
Description of particle stacks.
Code getPID() const
Get corsika::Code.
Example of a particle object on the stack.
Definition: VectorStack.hpp:30
constexpr detail::Power< D, 2, X > square(quantity< D, X > const &x)
square.
Definition: quantity.hpp:650
The cascade namespace assembles all objects needed to simulate full particles cascades.
Vector< dimensionless_d > DirectionVector
A 3D vector defined in a specific coordinate system with no units.
std::size_t getIndex() const
return the index number of the underlying iterator object
void setPID(Code const id)
! Set particle corsika::Code
Definition: VectorStack.hpp:84
ElectricChargeType constexpr get_charge(Code const)
electric charge
HEPEnergyType getEnergy() const
Get kinetic energy.
ElectricChargeType getCharge() const
Get electric charge.
TimeType getTime() const
Get time.
PDGCode getPDG() const
Get PDG code.
void setParticleData(particle_data_type const &v)
Set data of new particle.
int16_t constexpr get_charge_number(Code const)
electric charge in units of e
quantity_type getNorm() const
void setEnergy(HEPEnergyType const &e)
! Set energy
Definition: VectorStack.hpp:89
HEPMassType constexpr get_mass(Code const)
mass
Interface to particle properties.
void setPosition(Point const &v)
Set position.
PDGCode constexpr get_PDG(Code const)
Particle code according to PDG, "Monte Carlo Particle Numbering Scheme".
HEPEnergyType getKineticEnergy() const
Get kinetic energy.
The base class to define the readout of particle properties from a particle stack.
VelocityVector getVelocity() const
Get velocity.
MomentumVector getMomentum() const
Get momentum.
void setMomentum(MomentumVector const &v)
The MomentumVector v is used to determine the DirectionVector, and to update the particle energy...
detail::Root< D, 2, X > sqrt(quantity< D, X > const &x)
square root.
Definition: quantity.hpp:678