CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
FourVector.hpp
Go to the documentation of this file.
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/core/PhysicalGeometry.hpp>
13 #include <type_traits>
14 
22 namespace corsika {
23 
50  template <typename TTimeType, typename TSpaceVecType>
51  class FourVector {
52 
53  public:
54  using space_vec_type = typename std::decay<TSpaceVecType>::type;
55  using space_type = typename space_vec_type::quantity_type;
56  using time_type = typename std::decay<TTimeType>::type;
57 
58  // check the types and the physical units here:
59  static_assert(std::is_same<time_type, space_type>::value ||
60  std::is_same<time_type, decltype(std::declval<space_type>() /
61  meter * second)>::value,
62  "Units of time-like and space-like coordinates must either be idential "
63  "(e.g. GeV) or [E/c]=[p]");
64 
65  using norm_type = space_type;
66  using norm_square_type =
67  decltype(std::declval<norm_type>() * std::declval<norm_type>());
68 
69  public:
70  // resource management
71  FourVector() = default;
72  FourVector(FourVector&&) = default;
73  FourVector(FourVector const&) = default;
74  FourVector& operator=(const FourVector&) = default;
75  ~FourVector() = default;
76 
77  FourVector(TTimeType const& eT, TSpaceVecType const& eS)
78  : timeLike_(eT)
79  , spaceLike_(eS) {}
80 
84  TTimeType getTimeLikeComponent() const;
85 
89  TSpaceVecType& getSpaceLikeComponents();
90 
95  TSpaceVecType const& getSpaceLikeComponents() const;
96 
101  norm_square_type getNormSqr() const;
102 
107  norm_type getNorm() const;
108 
115  bool isTimelike() const;
118  bool isSpacelike() const;
119 
124  FourVector& operator+=(FourVector const&);
125  FourVector& operator-=(FourVector const&);
126  FourVector& operator*=(double const);
127  FourVector& operator/=(double const);
128  FourVector& operator/(double const);
129 
138  norm_type operator*(FourVector const& b);
139 
142  protected:
143  // the data members
144  TTimeType timeLike_;
145  TSpaceVecType spaceLike_;
146 
160  friend FourVector<time_type, space_vec_type> operator+(FourVector const& a,
161  FourVector const& b) {
162  return FourVector<time_type, space_vec_type>(a.timeLike_ + b.timeLike_,
163  a.spaceLike_ + b.spaceLike_);
164  }
165 
166  friend FourVector<time_type, space_vec_type> operator-(FourVector const& a,
167  FourVector const& b) {
168  return FourVector<time_type, space_vec_type>(a.timeLike_ - b.timeLike_,
169  a.spaceLike_ - b.spaceLike_);
170  }
171 
173  double const b) {
174  return FourVector<time_type, space_vec_type>(a.timeLike_ * b, a.spaceLike_ * b);
175  }
176 
177  friend FourVector<time_type, space_vec_type> operator/(FourVector const& a,
178  double const b) {
179  return FourVector<time_type, space_vec_type>(a.timeLike_ / b, a.spaceLike_ / b);
180  }
181 
184  private:
189  norm_square_type getTimeSquared() const;
190  };
191 
196  template <typename TTimeType, typename TSpaceVecType>
197  std::ostream& operator<<(std::ostream& os,
199 
204 
205 } // namespace corsika
206 
207 #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)
Code output operator.
norm_type getNorm() const
Description of physical four-vectors.
Definition: FourVector.hpp:51
`, since they are used everywhere as integral part of the framework.
norm_square_type getNormSqr() const
TSpaceVecType & getSpaceLikeComponents()