ComPWA
Common Partial-Wave-Analysis Framework
FourMomentum.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #ifndef _FOURMOMENTUM_HPP_
6 #define _FOURMOMENTUM_HPP_
7 
8 #include <algorithm>
9 #include <array>
10 #include <cmath>
11 #include <iostream>
12 #include <numeric>
13 #include <stdexcept>
14 #include <vector>
15 
16 #include <boost/property_tree/ptree.hpp>
17 
18 namespace ComPWA {
19 
21 class FourMomentum {
22 
23 public:
24  FourMomentum() : FourMomentum(0.0, 0.0, 0.0, 0.0){};
25  FourMomentum(double E) : FourMomentum(0.0, 0.0, 0.0, E){};
26 
27  FourMomentum(double Px, double Py, double Pz, double E)
28  : FourMomentum(std::array<double, 4>{{Px, Py, Pz, E}}) {}
29 
30  // main constructor
31  FourMomentum(std::array<double, 4> P4_) : P4(P4_) {}
32 
33  FourMomentum(std::vector<double> P4_)
34  : FourMomentum([&P4_]() {
35  if (P4_.size() != 4)
36  throw std::runtime_error(
37  "FourMomentum::Fourmomentum() | Size of vector not equal 4!");
38  return std::array<double, 4>{{P4_[0], P4_[1], P4_[2], P4_[3]}};
39  }()) {}
40 
41  double px() const { return P4[0]; }
42  double py() const { return P4[1]; }
43  double pz() const { return P4[2]; }
44  double e() const { return P4[3]; }
45 
46  FourMomentum operator+(const FourMomentum &pB) const {
47  FourMomentum newP(*this);
48  newP += pB;
49  return newP;
50  }
51 
52  void operator+=(const FourMomentum &pB) {
53  std::transform(P4.begin(), P4.end(), pB.P4.begin(), P4.begin(),
54  std::plus<double>());
55  }
56 
57  bool operator==(const FourMomentum &pB) const { return P4 == pB.P4; }
58 
59  friend std::ostream &operator<<(std::ostream &stream,
60  const FourMomentum &p4) {
61  stream << "(" << p4.px() << "," << p4.py() << "," << p4.e() << ")";
62  return stream;
63  }
64 
65  double invariantMassSquared() const {
66  return ((-1) *
67  (P4[0] * P4[0] + P4[1] * P4[1] + P4[2] * P4[2] - P4[3] * P4[3]));
68  }
69 
70  double invariantMass() const { return std::sqrt(invariantMassSquared()); }
71 
72  double threeMomentumSquared() const {
73  return (P4[0] * P4[0] + P4[1] * P4[1] + P4[2] * P4[2]);
74  }
75 
76 private:
77  std::array<double, 4> P4;
78 };
79 
80 } // namespace ComPWA
81 #endif
ComPWA four momentum class.
double threeMomentumSquared() const
double invariantMass() const
friend std::ostream & operator<<(std::ostream &stream, const FourMomentum &p4)
double px() const
double py() const
double e() const
std::array< double, 4 > P4
bool operator==(const FourMomentum &pB) const
FourMomentum(std::vector< double > P4_)
FourMomentum(double Px, double Py, double Pz, double E)
FourMomentum(std::array< double, 4 > P4_)
double invariantMassSquared() const
void operator+=(const FourMomentum &pB)
FourMomentum operator+(const FourMomentum &pB) const
double pz() const