CORSIKA  @c8_version@
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 
15 
16 #include <corsika/framework/geometry/Point.hpp>
17 #include <corsika/framework/geometry/Vector.hpp>
18 #include <corsika/framework/geometry/PhysicalGeometry.hpp>
19 
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 namespace corsika {
25 
30  template <typename TStackIterator>
31  class ParticleInterface : public ParticleBase<TStackIterator> {
32 
33  private:
35 
36  public:
42  typedef std::tuple<Code, HEPEnergyType, DirectionVector, Point, TimeType>
44 
50  typedef std::tuple<Code, HEPEnergyType, DirectionVector> secondary_data_type;
51 
57  typedef std::tuple<Code, HEPEnergyType, DirectionVector, Vector<length_d>, TimeType>
59 
60  std::string asString() const;
61 
68  void setParticleData(particle_data_type const& v);
69 
77  secondary_data_type const& v);
78 
87 
89  void setPID(Code const id) {
90  super_type::getStackData().setPID(super_type::getIndex(), id);
91  }
92 
94  void setEnergy(HEPEnergyType const& e) {
95  super_type::getStackData().setKineticEnergy(super_type::getIndex(),
96  e - this->getMass());
97  }
98 
100  void setKineticEnergy(HEPEnergyType const& ekin) {
101  super_type::getStackData().setKineticEnergy(super_type::getIndex(), ekin);
102  }
103 
105  void setDirection(DirectionVector const& v) {
106  super_type::getStackData().setDirection(super_type::getIndex(), v);
107  }
109  void setPosition(Point const& v) {
110  super_type::getStackData().setPosition(super_type::getIndex(), v);
111  }
113  void setTime(TimeType const& v) {
114  super_type::getStackData().setTime(super_type::getIndex(), v);
115  }
116 
118  Code getPID() const {
119  return super_type::getStackData().getPID(super_type::getIndex());
120  }
122  PDGCode getPDG() const { return get_PDG(getPID()); }
125  return super_type::getStackData().getKineticEnergy(super_type::getIndex());
126  }
128  DirectionVector const& getDirection() const {
129  return super_type::getStackData().getDirection(super_type::getIndex());
130  }
132  Point const& getPosition() const {
133  return super_type::getStackData().getPosition(super_type::getIndex());
134  }
136  TimeType getTime() const {
137  return super_type::getStackData().getTime(super_type::getIndex());
138  }
144  VelocityVector getVelocity() const {
146  return this->getMomentum() / this->getEnergy() * constants::c;
147  }
150  auto const P = calculate_momentum(this->getEnergy(), this->getMass());
151  return super_type::getStackData().getDirection(super_type::getIndex()) * P;
152  }
154  HEPMassType getMass() const { return get_mass(this->getPID()); }
155 
157  ElectricChargeType getCharge() const { return get_charge(this->getPID()); }
158 
160  HEPEnergyType getEnergy() const { return this->getKineticEnergy() + this->getMass(); }
161 
163  int16_t getChargeNumber() const { return get_charge_number(this->getPID()); }
165  };
166 
175 
176  public:
177  typedef std::vector<Code> code_vector_type;
178  typedef std::vector<HEPEnergyType> kinetic_energy_vector_type;
179  typedef std::vector<Point> point_vector_type;
180  typedef std::vector<TimeType> time_vector_type;
181  typedef std::vector<DirectionVector> direction_vector_type;
182 
183  VectorStackImpl() = default;
184 
185  VectorStackImpl(VectorStackImpl const& other) = default;
186 
187  VectorStackImpl(VectorStackImpl&& other) = default;
188 
189  VectorStackImpl& operator=(VectorStackImpl const& other) = default;
190 
191  VectorStackImpl& operator=(VectorStackImpl&& other) = default;
192 
193  void dump() const {}
194 
195  void clear();
196 
197  unsigned int getSize() const { return dataPID_.size(); }
198  unsigned int getCapacity() const { return dataPID_.size(); }
199 
200  void setPID(size_t i, Code const id) { dataPID_[i] = id; }
201  void setKineticEnergy(size_t i, HEPEnergyType const& e) { dataEkin_[i] = e; }
202  void setDirection(size_t i, DirectionVector const& v) { direction_[i] = v; }
203  void setPosition(size_t i, Point const& v) { position_[i] = v; }
204  void setTime(size_t i, TimeType const& v) { time_[i] = v; }
205 
206  Code getPID(size_t i) const { return dataPID_[i]; }
207  HEPEnergyType getKineticEnergy(size_t i) const { return dataEkin_[i]; }
208  DirectionVector const& getDirection(size_t i) const { return direction_[i]; }
209  Point const& getPosition(size_t i) const { return position_[i]; }
210  TimeType getTime(size_t i) const { return time_[i]; }
211 
215  void copy(size_t const i1, size_t const i2);
216 
220  void swap(size_t const i1, size_t const i2);
221 
222  void incrementSize();
223  void decrementSize();
224 
225  private:
227  code_vector_type dataPID_;
228  kinetic_energy_vector_type dataEkin_;
229  direction_vector_type direction_;
230  point_vector_type position_;
231  time_vector_type time_;
232 
233  }; // end class VectorStackImpl
234 
236 
237 } // namespace corsika
238 
239 #include <corsika/detail/stack/VectorStack.inl>
Memory implementation of the most simple particle stack object.
int16_t getChargeNumber() const
Get charge number.
std::tuple< Code, HEPEnergyType, DirectionVector, Vector< length_d >, TimeType > secondary_extended_data_type
secondary particle data information content with position and time update.
Definition: VectorStack.hpp:58
std::tuple< Code, HEPEnergyType, DirectionVector > secondary_data_type
secondary particle data information content.
Definition: VectorStack.hpp:50
Import and extend the phys::units package.
DirectionVector const & getDirection() const
Get direction.
void setKineticEnergy(HEPEnergyType const &ekin)
! Set kinetic energy
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.
HEPMassType getMass() const
Get mass of particle.
Description of particle stacks.
HEPEnergyType constexpr calculate_momentum(HEPEnergyType const E, HEPMassType const m)
Code getPID() const
Get corsika::Code.
Example of a particle object on the stack.
Definition: VectorStack.hpp:31
`, since they are used everywhere as integral part of the framework.
std::size_t getIndex() const
return the index number of the underlying iterator object
Point const & getPosition() const
Get position.
void setPID(Code const id)
! Set particle corsika::Code
Definition: VectorStack.hpp:89
ElectricChargeType constexpr get_charge(Code const)
electric charge
HEPEnergyType getEnergy() const
Get total energy.
ElectricChargeType getCharge() const
Get electric charge.
Relativistic energy momentum calculations.
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
void setEnergy(HEPEnergyType const &e)
! Set energy
Definition: VectorStack.hpp:94
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.
std::tuple< Code, HEPEnergyType, DirectionVector, Point, TimeType > particle_data_type
particle data information content.
Definition: VectorStack.hpp:43
MomentumVector getMomentum() const
Get momentum.