LorentzMatrix.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include "boca/math/Matrix3.hh"
5 
6 namespace boca
7 {
8 
13 template<typename Value_>
14 class LorentzMatrix : public boost::totally_ordered<LorentzMatrix<Value_>>
15  , boost::additive<LorentzMatrix<Value_>>
16 {
17 
18  template<typename Value_2_>
19  using ValueProduct = ValueProduct<Value_, Value_2_>;
20  using ValueSquare = boca::ValueSquare<Value_>;
21  using ValueCubed = boca::ValueCubed<Value_>;
22  using Value4 = boca::Value4<Value_>;
23  template<typename Value_2>
24  using ValueQuotient = ValueQuotient<Value_, Value_2>;
25  using ValueInverse = boost::units::divide_typeof_helper<double, Value_>;
26  template<typename Value_2>
27  using OnlyIfNotOrSameQuantity = typename std::enable_if < !IsQuantity<Value_2>::value || std::is_same<Value_, Value_2>::value >::type;
28  template<typename Value_2>
29  using OnlyIfNotQuantity = typename std::enable_if < !IsQuantity<Value_2>::value >::type;
30 
31 public:
32 
42 
46  LorentzMatrix(Matrix3<Value_> const &matrix, Vector3<Value_> const &vector, Value_ scalar, Matrix symmetry = Matrix::none)
47  {
48  if (symmetry == Matrix::none) symmetry == matrix.Symmetry();
49  if (symmetry != Matrix::symmetric || symmetry != Matrix::antisymmetric) std::cout << "matrix symmetry not well defiend" << '\n';
50  SetMatrix(matrix);
51  SetVector(vector, symmetry);
52  SetScalar(scalar);
53  }
54 
59  {
60  SetMatrix(matrix);
61  SetVector({0, 0, 0}, Matrix::symmetric);
62  SetScalar(Value_(1));
63  }
64 
69  {
70  SetBoost(vector);
71  }
72 
77  {
78  switch (matrix) {
79  case Matrix::row:
80  SetRows(x, y, z, t);
81  break;
82  case Matrix::column :
83  SetColumns(x, y, z, t);
84  break;
85  default :
86  std::cout << "Maformed matrix constructor: " << Name(matrix) << '\n';
87  }
88  }
89 
91 
100  void SetMatrix(Matrix3<Value_> const &matrix)
101  {
102  x_.SetVector(matrix.X());
103  y_.SetVector(matrix.Y());
104  z_.SetVector(matrix.Z());
105  }
106 
110  void SetVector(Vector3<Value_> const &vector, Matrix symmetry)
111  {
112  x_.SetScalar(vector.X());
113  y_.SetScalar(vector.Y());
114  z_.SetScalar(vector.Z());
115  switch (symmetry) {
116  case Matrix::symmetric :
117  t_.SetVector(vector);
118  break;
119  case Matrix::antisymmetric :
120  t_.SetVector(-vector);
121  break;
122  default :
123  std::cout << "matrix symmetry not well defiend" << '\n';
124  }
125  }
126 
130  void SetScalar(Value_ scalar)
131  {
132  t_.SetScalar(scalar);
133  }
134 
139  {
140  x_ = x;
141  y_ = y;
142  z_ = z;
143  t_ = t;
144  }
145 
150  {
151  x_ = {x.X(), y.X(), z.X(), t.X()};
152  y_ = {x.Y(), y.Y(), z.Y(), t.Y()};
153  z_ = {x.Z(), y.Z(), z.Z(), t.Z()};
154  t_ = {x.T(), y.T(), z.T(), t.T()};
155  }
156 
167  {
168  return x_;
169  }
170 
172  {
173  return x_;
174  }
176 
182  {
183  return y_;
184  }
185 
187  {
188  return y_;
189  }
191 
197  {
198  return z_;
199  }
200 
202  {
203  return z_;
204  }
206 
212  {
213  return t_;
214  }
215 
217  {
218  return t_;
219  }
221 
223 
232  Value4 Determinant()const
233  {
234  return boost::accumulate(LorentzDimensions(), Value4(0), [&](Value4 & sum, LorentzDim dim) {
235  return sum + Laplace(LorentzDim::x, dim);
236  });
237  }
238 
242  Value4 Laplace(LorentzDim dim_1, LorentzDim dim_2) const
243  {
244  return (*this)[dim_1][dim_2] * Cofactor(dim_1, dim_2);
245  }
246 
250  ValueCubed Cofactor(LorentzDim dim_1, LorentzDim dim_2) const
251  {
252  return static_cast<double>(Sign(dim_1, dim_2)) * Minor(dim_1, dim_2);
253  }
254 
258  ValueCubed Minor(LorentzDim delete_1, LorentzDim delete_2) const
259  {
260  return SubMatrix(delete_1, delete_2).Determinant();
261  }
262 
266  Value4 ReducedDeterminant(LorentzDim dim_1, LorentzDim dim_2) const
267  {
268  return Determinant() - (*this)[dim_1][dim_2] * Cofactor(dim_1, dim_2);
269  }
270 
274  Value4 ReducedLaplace(LorentzDim dim_1, LorentzDim dim_2, Dim3 dim_3, Dim3 dim_4)
275  {
276  return (*this)[dim_1][dim_2] * SubMatrix(dim_1, dim_2).ReducedDeterminant(dim_3, dim_4);
277  }
278 
282  int Sign(LorentzDim i, LorentzDim j) const
283  {
284  return (static_cast<int>(i) + static_cast<int>(j)) % 2 ? -1 : 1;
285  }
286 
288 
297  Matrix3<Value_> SubMatrix(LorentzDim delete_1, LorentzDim delete_2) const
298  {
299  auto dim3_1 = EnumIterator<Dim3> {Dim3::x};
300  auto dim3_2 = EnumIterator<Dim3> {Dim3::x};
301  auto matrix = Matrix3<Value_> {};
302  for (auto dim4_1 : LorentzDimensions()) {
303  if (dim4_1 == delete_1) continue;
304  for (auto dim4_2 : LorentzDimensions()) {
305  if (dim4_2 == delete_2) continue;
306  matrix(*dim3_1, *dim3_2) = (*this)(dim4_1, dim4_2);
307  ++dim3_2;
308  }
309  ++dim3_1;
310  dim3_2.Set(Dim3::x);
311  }
312  return matrix;
313  }
314 
316 
326  {
327  return {x_.X(), y_.X(), z_.X(), t_.X()};
328  }
329 
334  {
335  return {x_.Y(), y_.Y(), z_.Y(), t_.Y()};
336  }
337 
342  {
343  return {x_.Z(), y_.Z(), z_.Z(), t_.Z()};
344  }
345 
350  {
351  return {x_.T(), y_.T(), z_.T(), t_.T()};
352  }
353 
355 
364  template<typename Value_2_>
365  auto Multiply(const LorentzVectorBase<Value_2_> &vector) const
366  {
367  return {x_ * vector, y_ * vector, z_ * vector, t_ * vector};
368  }
369 
373  template<typename Value_2_>
375  {
376  return {{x_ * matrix.ColumnX(), x_ * matrix.ColumnY(), x_ * matrix.ColumnZ(), x_ * matrix.ColumnT()},
377  {y_ * matrix.ColumnX(), y_ * matrix.ColumnY(), y_ * matrix.ColumnZ(), y_ * matrix.ColumnT()},
378  {z_ * matrix.ColumnX(), z_ * matrix.ColumnY(), z_ * matrix.ColumnZ(), z_ * matrix.ColumnT()},
379  {t_ * matrix.ColumnX(), t_ * matrix.ColumnY(), t_ * matrix.ColumnZ(), t_ * matrix.ColumnT()}
380  };
381  }
382 
386  template<typename Value_2_>
388  {
389  return *this = matrix.Multiply(*this);
390  }
391 
397  template<typename Value_2_>
398  auto &Transform(const Matrix3<Value_2_> &matrix)
399  {
400  return Transform(LorentzMatrix(matrix));
401  }
402 
406  auto Transposed() const
407  {
408  return {ColumnX(), ColumnY(), ColumnZ(),ColumnT()};
409  }
410 
414  auto &Transpose()
415  {
416  return *this = Transposed();
417  }
418 
422  template<typename Value_2_>
424  {
425  return Transform(LorentzMatrix(boost));
426  }
427 
431  template<typename Value_2_>
432  auto &Rotate(Angle angle, Dim3 dim)
433  {
434  return Transform(Matrix3<double>().Rotate(angle, dim));
435  }
436 
440  template<typename Value_2_>
441  auto &Rotate(Angle angle, const Vector3<Value_> &axis)
442  {
443  return Transform(Matrix3<double>().Rotate(angle, axis));
444  }
445 
447 
456  bool operator<(LorentzMatrix const &matrix) const
457  {
458  return abs(Determinant()) < abs(matrix.Determinant());
459  }
460 
464  bool operator==(LorentzMatrix const &matrix) const
465  {
466  return x_ == matrix.x_ && y_ == matrix.y_ && z_ == matrix.z_ && t_ == matrix.t_ ;
467  }
468 
472  template<typename Value_2_>
473  auto operator*(const LorentzVectorBase<Value_2_> &vector) const
474  {
475  return Multiply(vector);
476  }
477 
481  template<typename Value_2_>
482  auto operator*(const LorentzMatrix<Value_2_> &matrix) const
483  {
484  return Multiply(matrix);
485  }
486 
491  {
492  return *this = Multiply(matrix);
493  }
494 
499  {
500  switch (lorentz_dim) {
501  case LorentzDim::x :
502  return x_;
503  case LorentzDim::y :
504  return y_;
505  case LorentzDim::z :
506  return z_;
507  case LorentzDim::t :
508  return t_;
509  default : Default("LorentzMatrix", Name(lorentz_dim));
510  return x_;
511  }
512  }
513 
518  {
519  return const_cast<LorentzVectorBase<Value_> &>(static_cast<LorentzMatrix<Value_> const &>(*this)[lorentz_dim]);
520  }
521 
525  friend auto &operator<<(std::ostream &stream, LorentzMatrix<Value_> const &matrix)
526  {
527  for(auto const& vector : matrix) stream << vector;
528  return stream;
529  }
530 
532 
533 private:
534 
536 
538 
540 
542 
543  // Set elements according to a boost vector.
544  //boost this Lorentz vector
545  void SetBoost(Vector3<double> const &boost)
546  {
547  auto bp2 = boost.Mag2();
548  auto gamma = 1 / std::sqrt(1 - bp2);
549  auto bgamma = sqr(gamma) / (1 + gamma);
550  auto matrix = Matrix3<double>(bgamma, Matrix::uniform) + Multiply(boost, boost) + Matrix3<double>(1);
551  auto vector = boost + Vector3<double>(gamma, gamma, gamma);
552  *this = LorentzMatrix<double>(matrix, vector, gamma);
553  }
554 
555 
556  // Assignment.
557 // LorentzMatrix<Value_> &operator=(const Matrix3<Value_> &matrix)
558 // {
559 // SetMatrix(matrix);
560 // SetVector({0, 0, 0}, Matrix::symmetric);
561 // SetScalar(Value_(1));
562 // return *this;
563 // }
564 
565 
566 };
567 
568 }
bool operator==(LorentzMatrix const &matrix) const
Equallity comparison.
Definition: LorentzMatrix.hh:464
LorentzMatrix(Matrix3< Value_ > const &matrix)
Constructor accepting one three dimensional matrix.
Definition: LorentzMatrix.hh:58
auto operator*(const LorentzVectorBase< Value_2_ > &vector) const
Multiply with a vector.
Definition: LorentzMatrix.hh:473
LorentzMatrix(LorentzVectorBase< Value_ > const &x, LorentzVectorBase< Value_ > const &y, LorentzVectorBase< Value_ > const &z, LorentzVectorBase< Value_ > const &t, Matrix matrix=Matrix::row)
Constructor accepting three Lorentz vectors.
Definition: LorentzMatrix.hh:76
auto & Rotate(Angle angle, const Vector3< Value_ > &axis)
Rotation around specified vector.
Definition: LorentzMatrix.hh:441
int Sign(LorentzDim i, LorentzDim j) const
Sign of a given element .
Definition: LorentzMatrix.hh:282
Enables the use of strongly typed enumerators as iterators.
Definition: EnumIterator.hh:17
typename boost::units::multiply_typeof_helper< ValueSquare< Value >, Value >::type ValueCubed
Definition: Units.hh:149
Dim3
Three dimensions.
Definition: Vector3.hh:13
Boost provides free peer-reviewed portable C++ source libraries.
Definition: LorentzVectorBase.hh:726
Lorentz matrix.
Definition: LorentzMatrix.hh:14
auto operator*(const LorentzMatrix< Value_2_ > &matrix) const
Multiply with a matrix.
Definition: LorentzMatrix.hh:482
boost::units::quantity< boost::units::si::plane_angle > Angle
Angle measured in radian.
Definition: Si.hh:35
Value4 ReducedLaplace(LorentzDim dim_1, LorentzDim dim_2, Dim3 dim_3, Dim3 dim_4)
Reduced Laplace .
Definition: LorentzMatrix.hh:274
LorentzMatrix()
Default constructor.
Definition: LorentzMatrix.hh:41
LorentzVectorBase< Value_ > & Z()
z-row
Definition: LorentzMatrix.hh:201
Value4 Laplace(LorentzDim dim_1, LorentzDim dim_2) const
Laplace .
Definition: LorentzMatrix.hh:242
LorentzVectorBase< Value_ > & operator[](LorentzDim lorentz_dim)
Row by index.
Definition: LorentzMatrix.hh:517
constexpr Value_ const & Z() const
Getter for Z.
Definition: Vector3.hh:216
void SetRows(LorentzVectorBase< Value_ > const &x, LorentzVectorBase< Value_ > const &y, LorentzVectorBase< Value_ > const &z, LorentzVectorBase< Value_ > const &t)
Set the rows.
Definition: LorentzMatrix.hh:138
auto & Boost(const Vector3< Value_ > &boost)
Boost.
Definition: LorentzMatrix.hh:423
LorentzDim
Lorentz Dimensions.
Definition: LorentzVectorBase.hh:14
constexpr ValueSquare Mag2() const
The magnitude squared .
Definition: Vector3.hh:385
typename boost::units::multiply_typeof_helper< ValueSquare< Value >, ValueSquare< Value >>::type Value4
Definition: Units.hh:152
slighly more complicated estimator for significance
constexpr Vector3< Value_ > const & X() const
x-row
Definition: Matrix3.hh:371
Three dimensional matrix.
Definition: Matrix3.hh:21
LorentzMatrix Multiply(const LorentzMatrix< Value_2_ > &matrix) const
Multiply with a matrix.
Definition: LorentzMatrix.hh:374
auto Transposed() const
Transposed.
Definition: LorentzMatrix.hh:406
auto & operator*=(const LorentzMatrix< Value_2_ > &matrix)
Multiply with a matrix.
Definition: LorentzMatrix.hh:490
Matrix
Matrix types.
Definition: Matrix2.hh:18
auto sqr(Value const &value)
square of value
Definition: Math.hh:24
auto Multiply(const LorentzVectorBase< Value_2_ > &vector) const
Multiply with a vector.
Definition: LorentzMatrix.hh:365
Value4 ReducedDeterminant(LorentzDim dim_1, LorentzDim dim_2) const
Reduced determinant .
Definition: LorentzMatrix.hh:266
ValueCubed Minor(LorentzDim delete_1, LorentzDim delete_2) const
Minor .
Definition: LorentzMatrix.hh:258
LorentzMatrix(Vector3< double > const &vector)
Constructor accepting one three dimensional vector as a Lorenz-boost.
Definition: LorentzMatrix.hh:68
LorentzVectorBase< Value_ > ColumnX() const
x column
Definition: LorentzMatrix.hh:325
auto & Rotate(Angle angle, Dim3 dim)
Rotate.
Definition: LorentzMatrix.hh:432
ValueSqrt< Value > sqrt(Value const &value)
Square Root.
Definition: Units.hh:160
void Default(std::string const &variable, const Value value)
Definition: Debug.hh:165
constexpr Matrix Symmetry()
Definition: Matrix3.hh:414
LorentzVectorBase< Value_ > const & operator[](LorentzDim lorentz_dim) const
Row by index.
Definition: LorentzMatrix.hh:498
LorentzMatrix(Matrix3< Value_ > const &matrix, Vector3< Value_ > const &vector, Value_ scalar, Matrix symmetry=Matrix::none)
Constructor accepting one three dimensional matrix, vector and scalar.
Definition: LorentzMatrix.hh:46
LorentzVectorBase< Value_ > & T()
t-row
Definition: LorentzMatrix.hh:216
Vector3< Value_ > & Z()
z-row
Definition: Matrix3.hh:401
Boosted Collider Analysis.
Definition: Analysis.hh:15
void SetMatrix(Matrix3< Value_ > const &matrix)
Set the three dimension matrix.
Definition: LorentzMatrix.hh:100
Value abs(Value const &value)
Absolute value.
Definition: Units.hh:235
LorentzVectorBase< Value_ > ColumnY() const
y column
Definition: LorentzMatrix.hh:333
typename boost::units::multiply_typeof_helper< Value, Value >::type ValueSquare
Definition: Units.hh:143
LorentzVectorBase< Value_ > & X()
x-row
Definition: LorentzMatrix.hh:171
Value_ & T()
Getter for the spatial components.
Definition: LorentzVectorBase.hh:196
Three dimensionial vector.
Definition: PseudoJet.hh:20
LorentzVectorBase< Value_ > const & Z() const
z-row
Definition: LorentzMatrix.hh:196
auto & Transpose()
Transpose.
Definition: LorentzMatrix.hh:414
LorentzVectorBase< Value_ > const & Y() const
y-row
Definition: LorentzMatrix.hh:181
LorentzVectorBase< Value_ > ColumnT() const
t column
Definition: LorentzMatrix.hh:349
constexpr Value_ const & X() const
Getter for X.
Definition: Vector3.hh:200
LorentzVectorBase< Value_ > T() const
t-row
Definition: LorentzMatrix.hh:211
ValueCubed Cofactor(LorentzDim dim_1, LorentzDim dim_2) const
Cofactor .
Definition: LorentzMatrix.hh:250
constexpr Value_ const & Y() const
Getter for Y.
Definition: Vector3.hh:208
LorentzVectorBase< Value_ > const & X() const
x-row
Definition: LorentzMatrix.hh:166
Matrix3< Value_ > SubMatrix(LorentzDim delete_1, LorentzDim delete_2) const
Sub matrix .
Definition: LorentzMatrix.hh:297
LorentzMatrix & Transform(const LorentzMatrix< Value_2_ > &matrix)
Transform this matrix.
Definition: LorentzMatrix.hh:387
Lorentz Vector.
Definition: LorentzVectorBase.hh:32
std::string Name(Output output)
Definition: Base.cpp:23
LorentzVectorBase< Value_ > ColumnZ() const
z column
Definition: LorentzMatrix.hh:341
void SetVector(Vector3< Value_ > const &vector, Matrix symmetry)
Set the three dimensional vectors.
Definition: LorentzMatrix.hh:110
void SetScalar(Value_ scalar)
Set the three dimensional scalar.
Definition: LorentzMatrix.hh:130
Value4 Determinant() const
Determinant .
Definition: LorentzMatrix.hh:232
bool operator<(LorentzMatrix const &matrix) const
Less than comparison.
Definition: LorentzMatrix.hh:456
auto & Transform(const Matrix3< Value_2_ > &matrix)
Transform this matrix with a three dimensional matrix.
Definition: LorentzMatrix.hh:398
constexpr Vector3< Value_ > const & Y() const
y-row
Definition: Matrix3.hh:386
LorentzVectorBase< Value_ > & Y()
y-row
Definition: LorentzMatrix.hh:186
void SetColumns(LorentzVectorBase< Value_ > const &x, LorentzVectorBase< Value_ > const &y, LorentzVectorBase< Value_ > const &z, LorentzVectorBase< Value_ > const &t)
Set the columns.
Definition: LorentzMatrix.hh:149
std::vector< LorentzDim > LorentzDimensions()
Definition: LorentzVectorBase.cpp:17