YAP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FourVector.h
1 /* YAP - Yet another PWA toolkit
2  Copyright 2015, Technische Universitaet Muenchen,
3  Authors: Daniel Greenwald, Johannes Rauch
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
20 
21 #ifndef yap_FourVector_h
22 #define yap_FourVector_h
23 
24 #include "CoordinateSystem.h"
25 #include "Matrix.h"
26 #include "ThreeVector.h"
27 #include "Vector.h"
28 
29 #include <algorithm>
30 #include <array>
31 #include <type_traits>
32 #include <vector>
33 
34 namespace yap {
35 
40 template <typename T>
41 class FourVector : public Vector<T, 4>
42 {
43 public:
45  constexpr FourVector(const std::array<T, 4>& l) noexcept : Vector<T, 4>(l) {}
46 
48  constexpr FourVector(const Vector<T, 4>& V) : Vector<T, 4>(V) {}
49 
53  constexpr FourVector(const T& E, const ThreeVector<T>& P) noexcept : Vector<T, 4>( {E, P[0], P[1], P[2]}) {}
54 
56  FourVector() = default;
57 
59  using Vector<T, 4>::operator=;
60 
62  constexpr T operator*(const Vector<T, 4>& B) const override
63  { return this->front() * B.front() - std::inner_product(this->begin() + 1, this->end(), B.begin() + 1, (T)0); }
64 };
65 
67 template <typename T>
68 constexpr ThreeVector<T> vect(const FourVector<T>& V) noexcept
69 { return ThreeVector<T>({V[1], V[2], V[3]}); }
70 
72 template <typename T>
73 constexpr ThreeVector<T> boost(const FourVector<T>& V)
74 { return (V[0] != 0) ? (T(1) / V[0]) * vect(V) : ThreeVector<T>({0, 0, 0}); }
75 
78 template <typename T>
80 { return FourVector<T>(V[0], -vect(V)); }
81 
84 template <typename T>
85 const std::vector<FourVector<T> > operator-(const std::vector<FourVector<T> >& V)
86 {
87  std::vector<FourVector<T> > result;
88  result.reserve(V.size());
89  for (auto& v : V)
90  result.push_back(-v);
91  return result;
92 }
93 
95 template <typename T>
96 constexpr FourVector<T> operator*(const FourMatrix<T>& R, const FourVector<T>& V)
97 { return FourVector<T>(R * static_cast<const Vector<T, 4> >(V)); }
98 
100 template <typename T>
101 const std::vector<FourVector<T> > operator*(const FourMatrix<T>& R, const std::vector<FourVector<T> >& V)
102 {
103  std::vector<FourVector<T> > result;
104  result.reserve(V.size());
105  for (auto& v : V)
106  result.push_back(FourVector<T>(R * static_cast<Vector<T, 4> >(v)));
107  return result;
108 }
109 
111 template <typename T>
112 constexpr FourVector<T> operator*(const ThreeMatrix<T>& R, const FourVector<T>& V)
113 { return FourVector<T>(V[0], R * vect(V)); }
114 
116 template <typename T>
117 const std::vector<FourVector<T> > operator*(const ThreeMatrix<T>& R, const std::vector<FourVector<T> >& V)
118 {
119  std::vector<FourVector<T> > result;
120  result.reserve(V.size());
121  for (auto& v : V)
122  result.push_back(R * v);
123  return result;
124 }
125 
130 template <typename T>
131 const CoordinateSystem<T, 3> helicityFrame(const FourVector<T>& V, const CoordinateSystem<T, 3>& C)
132 { return helicityFrame(vect<T>(V), C); }
133 
134 }
135 #endif
const CoordinateSystem< T, 3 > helicityFrame(const FourVector< T > &V, const CoordinateSystem< T, 3 > &C)
Definition: FourVector.h:131
Four-Vector handling.
Definition: FourVector.h:41
constexpr ThreeVector< T > vect(const FourVector< T > &V) noexcept
Definition: FourVector.h:68
constexpr FourVector(const Vector< T, 4 > &V)
Vector<T, 4> constructor.
Definition: FourVector.h:48
const DataIterator operator-(const DataIterator &lhs, DataIterator::difference_type n)
subraction operator
Definition: DataPartition.h:139
VectorIterator< T, N > end()
access to end
Definition: Vector.h:208
constexpr T operator*(const Vector< T, 4 > &B) const override
Definition: FourVector.h:62
const CoordinateSystem< T, N > operator*(const SquareMatrix< T, N > &M, const CoordinateSystem< T, N > &C)
Definition: CoordinateSystem.h:62
constexpr FourVector(const T &E, const ThreeVector< T > &P) noexcept
Definition: FourVector.h:53
T & front()
access to front
Definition: Vector.h:192
constexpr FourVector(const std::array< T, 4 > &l) noexcept
intializer_list constructor
Definition: FourVector.h:45
VectorIterator< T, N > begin()
access to begin
Definition: Vector.h:200
constexpr ThreeVector< T > boost(const FourVector< T > &V)
Definition: FourVector.h:73
N-dimensional column vector.
Definition: Vector.h:168