CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
FourVector.hpp
1 /*
2  * (c) Copyright 2020 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/Vector.hpp>
13 #include <type_traits>
14 
15 namespace corsika {
16 
44  template <typename TTimeType, typename TSpaceVecType>
45  class FourVector {
46 
47  public:
48  using space_vec_type = typename std::decay<TSpaceVecType>::type;
49  using space_type = typename space_vec_type::quantity_type;
50  using time_type = typename std::decay<TTimeType>::type;
51 
52  // check the types and the physical units here:
53  static_assert(std::is_same<time_type, space_type>::value ||
54  std::is_same<time_type, decltype(std::declval<space_type>() /
55  meter * second)>::value,
56  "Units of time-like and space-like coordinates must either be idential "
57  "(e.g. GeV) or [E/c]=[p]");
58 
59  using norm_type = space_type;
60  using norm_square_type =
61  decltype(std::declval<norm_type>() * std::declval<norm_type>());
62 
63  public:
64  // resource management
65  FourVector() = default;
66  FourVector(FourVector&&) = default;
67  FourVector(FourVector const&) = default;
68  FourVector& operator=(const FourVector&) = default;
69  ~FourVector() = default;
70 
71  FourVector(TTimeType const& eT, TSpaceVecType const& eS)
72  : timeLike_(eT)
73  , spaceLike_(eS) {}
74 
79  TTimeType getTimeLikeComponent() const;
80 
85  TSpaceVecType& getSpaceLikeComponents();
86 
91  TSpaceVecType const& getSpaceLikeComponents() const;
92 
97  norm_square_type getNormSqr() const;
98 
103  norm_type getNorm() const;
104 
111  bool isTimelike() const;
114  bool isSpacelike() const;
115 
120  FourVector& operator+=(FourVector const&);
121  FourVector& operator-=(FourVector const&);
122  FourVector& operator*=(double const);
123  FourVector& operator/=(double const);
124  FourVector& operator/(double const);
125 
134  norm_type operator*(FourVector const& b);
135 
138  protected:
139  // the data members
140  TTimeType timeLike_;
141  TSpaceVecType spaceLike_;
142 
156  friend FourVector<time_type, space_vec_type> operator+(FourVector const& a,
157  FourVector const& b) {
158  return FourVector<time_type, space_vec_type>(a.timeLike_ + b.timeLike_,
159  a.spaceLike_ + b.spaceLike_);
160  }
161 
162  friend FourVector<time_type, space_vec_type> operator-(FourVector const& a,
163  FourVector const& b) {
164  return FourVector<time_type, space_vec_type>(a.timeLike_ - b.timeLike_,
165  a.spaceLike_ - b.spaceLike_);
166  }
167 
169  double const b) {
170  return FourVector<time_type, space_vec_type>(a.timeLike_ * b, a.spaceLike_ * b);
171  }
172 
173  friend FourVector<time_type, space_vec_type> operator/(FourVector const& a,
174  double const b) {
175  return FourVector<time_type, space_vec_type>(a.timeLike_ / b, a.spaceLike_ / b);
176  }
177 
180  private:
185  norm_square_type getTimeSquared() const;
186  };
187 
192  template <typename TTimeType, typename TSpaceVecType>
193  std::ostream& operator<<(std::ostream& os,
195 
196 } // namespace corsika
197 
198 #include <corsika/detail/framework/geometry/FourVector.inl>
bool isSpacelike() const
bool isTimelike() const
Import and extend the phys::units package.
TTimeType getTimeLikeComponent() const
norm_type operator*(FourVector const &b)
Scalar product of two FourVectors.
std::ostream & operator<<(std::ostream &, corsika::Code)
the output stream operator for human-readable particle codes
norm_type getNorm() const
Description of physical four-vectors.
Definition: FourVector.hpp:45
The cascade namespace assembles all objects needed to simulate full particles cascades.
norm_square_type getNormSqr() const
TSpaceVecType & getSpaceLikeComponents()