Belle II Software  release-05-02-19
FourVector.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * See https://github.com/tferber/OrcaKinfit, forked from *
4  * https://github.com/iLCSoft/MarlinKinfit *
5  * *
6  * Further information about the fit engine and the user interface *
7  * provided in MarlinKinfit can be found at *
8  * https://www.desy.de/~blist/kinfit/doc/html/ *
9  * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
10  * from http://www-flc.desy.de/lcnotes/ *
11  * *
12  * Adopted by: Torben Ferber (torben.ferber@desy.de) (TF) *
13  * *
14  * This software is provided "as is" without any warranty. *
15  **************************************************************************/
16 
17 #ifndef __FOURVECTOR_H
18 #define __FOURVECTOR_H
19 
20 #include "analysis/OrcaKinFit/ThreeVector.h"
21 
22 namespace Belle2 {
28  namespace OrcaKinFit {
29 
30 #include <iostream>
31 #include <cmath>
32 #include <cassert>
33 
34 // Class FourVector:
36 
43  class FourVector {
44  public:
46  inline FourVector();
48  inline FourVector(double E_, double px_, double py_, double pz_);
50  inline FourVector(double E_, const ThreeVector& p_);
52  inline FourVector(const ThreeVector& p_, double m_);
53  // automatically generated copy constructor and assignment is fine
54 
56  inline double getE() const;
58  inline double getPx() const;
60  inline double getPy() const;
62  inline double getPz() const;
64  inline double getM2() const;
66  inline double getM() const;
68  inline double getMass() const;
69 
71  inline double getP2() const;
73  inline double getP() const;
75  inline double getPt2() const;
77  inline double getPt() const;
78 
80  inline double getPhi() const;
82  inline double getTheta() const;
84  inline double getEta() const;
85 
87  inline double getComponent(int i) const;
88 
89  inline ThreeVector getBeta() const { assert(E > 0); return (1. / E) * p;};
90  inline double getGamma() const { assert(getM() > 0); return getE() / getM();};
91  inline ThreeVector getBetaGamma() const { assert(getM() > 0); return (1. / getM() > 0) * p;};
92 
94  inline const ThreeVector& getThreeVector() const { return p;}
95 
96  FourVector& boost(const FourVector& P);
97  void decayto(FourVector& d1, FourVector& d2) const;
98 
99  inline void setValues(double E_, double px_, double py_, double pz_);
100 
101  inline FourVector& operator+= (const FourVector& rhs);
102  inline FourVector& operator-= (const FourVector& rhs);
103 
104  inline FourVector& operator*= (double rhs);
105 
106  private:
107  double E;
109  };
110 
112  : E(0), p()
113  {}
114 
115  FourVector::FourVector(double E_, double px_, double py_, double pz_)
116  : E(E_), p(px_, py_, pz_)
117  {}
118 
119  FourVector::FourVector(double E_, const ThreeVector& p_)
120  : E(E_), p(p_)
121  {}
122 
123  FourVector::FourVector(const ThreeVector& p_, double m)
124  : E(std::sqrt(p_.getP2() + m * m)), p(p_)
125  {}
126 
127  double FourVector::getE() const { return E; }
128  double FourVector::getPx() const { return p.getPx(); }
129  double FourVector::getPy() const { return p.getPy(); }
130  double FourVector::getPz() const { return p.getPz(); }
131 
132  double FourVector::getPt2() const { return p.getPt2(); }
133  double FourVector::getPt() const { return p.getPt(); }
134 
135  double FourVector::getP2() const { return p.getP2(); }
136  double FourVector::getP() const { return p.getP(); }
137 
138  double FourVector::getM2() const { return std::abs(getE() * getE() - getP2()); }
139  double FourVector::getM() const { return std::sqrt(getM2()); }
140  double FourVector::getMass() const { return std::sqrt(getM2()); }
141 
142  double FourVector::getPhi() const { return p.getPhi(); }
143  double FourVector::getTheta() const { return p.getTheta(); }
144 
145  double FourVector::getEta() const { return p.getEta(); }
146 
147  double FourVector::getComponent(int i) const
148  {
149  switch (i) {
150  case 1: return getPx();
151  case 2: return getPy();
152  case 3: return getPz();
153  }
154  return getE();
155  }
156 
157  void FourVector::setValues(double E_, double px_, double py_, double pz_)
158  {
159  E = E_;
160  p.setValues(px_, py_, pz_);
161  }
162 
163  FourVector& FourVector::operator+= (const FourVector& rhs)
164  {
165  p += rhs.p;
166  E += rhs.E;
167  return *this;
168  }
169 
170  FourVector& FourVector::operator-= (const FourVector& rhs)
171  {
172  p -= rhs.p;
173  E -= rhs.E;
174  return *this;
175  }
176 
177  FourVector& FourVector::operator*= (double rhs)
178  {
179  p *= rhs;
180  E *= rhs;
181  return *this;
182  }
183 
188  inline FourVector operator+ (const FourVector& lhs, const FourVector& rhs)
189  {
190  return FourVector(lhs.getE() + rhs.getE(), lhs.getPx() + rhs.getPx(), lhs.getPy() + rhs.getPy(), lhs.getPz() + rhs.getPz());
191  }
192 
197  inline FourVector operator- (const FourVector& lhs, const FourVector& rhs)
198  {
199  return FourVector(lhs.getE() - rhs.getE(), lhs.getPx() - rhs.getPx(), lhs.getPy() - rhs.getPy(), lhs.getPz() - rhs.getPz());
200  }
201 
206  inline FourVector operator- (const FourVector& rhs)
207  {
208  return FourVector(-rhs.getE(), -rhs.getPx(), -rhs.getPy(), -rhs.getPz());
209  }
210 
215  inline FourVector operator* (double lhs, const FourVector& rhs)
216  {
217  return FourVector(lhs * rhs.getE(), lhs * rhs.getPx(), lhs * rhs.getPy(), lhs * rhs.getPz());
218  }
219 
224  inline double operator* (const FourVector& lhs, const FourVector& rhs)
225  {
226  return lhs.getE() * rhs.getE() - lhs.getPx() * rhs.getPx() - lhs.getPy() * rhs.getPy() - lhs.getPz() * rhs.getPz();
227  }
228 
229 
234  inline std::ostream& operator<< (std::ostream& os,
235  const FourVector& rhs
236  )
237  {
238  os << "(" << rhs.getE() << ", " << rhs.getPx() << ", " << rhs.getPy() << ", " << rhs.getPz() << ")";
239  return os;
240  }
241 
242  }// end OrcaKinFit namespace
244 } // end Belle2 namespace
245 
246 #endif // __FOURVECTOR_H
Belle2::OrcaKinFit::FourVector::getMass
double getMass() const
Returns the mass / magnitude.
Definition: FourVector.h:154
Belle2::OrcaKinFit::FourVector::getPt2
double getPt2() const
Returns the transverse momentum squared / magnitude of the 1 and 2 component vector squared.
Definition: FourVector.h:146
Belle2::OrcaKinFit::FourVector::getP
double getP() const
Returns the momentum / magnitude of the three vector.
Definition: FourVector.h:150
Belle2::OrcaKinFit::FourVector::getComponent
double getComponent(int i) const
Returns the i'th component (starting from 0=energy)
Definition: FourVector.h:161
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::OrcaKinFit::FourVector::getThreeVector
const ThreeVector & getThreeVector() const
Returns the momentum three vector.
Definition: FourVector.h:108
Belle2::OrcaKinFit::FourVector::getPhi
double getPhi() const
Returns the azimuthal angle of the momentum / three vector squared.
Definition: FourVector.h:156
Belle2::OrcaKinFit::FourVector::getPt
double getPt() const
Returns the transverse momentum / magnitude of the 1 and 2 component vector.
Definition: FourVector.h:147
Belle2::OrcaKinFit::FourVector::getM2
double getM2() const
Returns the mass squared / magnitude squared.
Definition: FourVector.h:152
Belle2::OrcaKinFit::FourVector::getPx
double getPx() const
Returns the x momentum / 1 component.
Definition: FourVector.h:142
Belle2::OrcaKinFit::FourVector::getTheta
double getTheta() const
Returns the polar angle of the momentum / three vector squared.
Definition: FourVector.h:157
Belle2::operator*
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition: B2Vector3.h:528
Belle2::OrcaKinFit::FourVector
Yet another four vector class, with metric +—.
Definition: FourVector.h:57
Belle2::OrcaKinFit::FourVector::getPy
double getPy() const
Returns the y momentum / 2 component.
Definition: FourVector.h:143
Belle2::OrcaKinFit::FourVector::getP2
double getP2() const
Returns the momentum squared / magnitude of the three vector squared.
Definition: FourVector.h:149
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::OrcaKinFit::FourVector::E
double E
The energy / 0 component.
Definition: FourVector.h:121
Belle2::OrcaKinFit::FourVector::getM
double getM() const
Returns the mass / magnitude.
Definition: FourVector.h:153
Belle2::operator-
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for substracting a TVector3 from a B2Vector3
Definition: B2Vector3.h:542
Belle2::operator+
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Definition: B2Vector3.h:535
Belle2::OrcaKinFit::ThreeVector
Definition: ThreeVector.h:56
Belle2::OrcaKinFit::FourVector::getE
double getE() const
Returns the energy / 0 component.
Definition: FourVector.h:141
Belle2::OrcaKinFit::FourVector::FourVector
FourVector()
Default constructor.
Definition: FourVector.h:125
Belle2::OrcaKinFit::FourVector::getEta
double getEta() const
Returns the pseudo rapidity of the momentum / three vector squared.
Definition: FourVector.h:159
Belle2::OrcaKinFit::FourVector::getPz
double getPz() const
Returns the z momentum / 3 component.
Definition: FourVector.h:144
Belle2::OrcaKinFit::FourVector::p
ThreeVector p
The momentum three vector.
Definition: FourVector.h:122