Belle II Software  release-05-02-19
ThreeVector.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 
18 // Class ThreeVector
19 //
20 // Author: Benno List
21 // Last update: $Date: 2008/02/12 10:19:07 $
22 // by: $Author: blist $
23 //
24 // Description: class for three-vectors
25 //
27 
28 #ifndef __THREEVECTOR_H
29 #define __THREEVECTOR_H
30 
31 #include <iostream>
32 #include <cmath>
33 
34 namespace Belle2 {
39  namespace OrcaKinFit {
40 
41 
42  class ThreeVector {
43  public:
44  inline ThreeVector();
45  inline ThreeVector(double px_, double py_, double pz_);
46  // automatically generated copy constructor and assignment is fine
47 
48  inline double getPx() const;
49  inline double getPy() const;
50  inline double getPz() const;
51  inline double getX() const;
52  inline double getY() const;
53  inline double getZ() const;
54 
55  inline double getP2() const;
56  inline double getP() const;
57  inline double getMag() const;
58  inline double getPt2() const;
59  inline double getPt() const;
60  inline double getR() const;
61 
62  inline double getPhi() const;
63  inline double getTheta() const;
64  inline double getEta() const;
65 
66  inline double getComponent(int i) const;
67 
68  inline ThreeVector& setValues(double px_, double py_, double pz_);
69 
70  inline ThreeVector& operator+= (const ThreeVector& rhs);
71  inline ThreeVector& operator-= (const ThreeVector& rhs);
72  inline ThreeVector& operator*= (double rhs);
73 
74  private:
75  double px, py, pz;
76  };
77 
78  ThreeVector::ThreeVector()
79  : px(0), py(0), pz(0)
80  {}
81 
82  ThreeVector::ThreeVector(double px_, double py_, double pz_)
83  : px(px_), py(py_), pz(pz_)
84  {}
85 
86  double ThreeVector::getPx() const { return px; }
87  double ThreeVector::getPy() const { return py; }
88  double ThreeVector::getPz() const { return pz; }
89  double ThreeVector::getX() const { return px; }
90  double ThreeVector::getY() const { return py; }
91  double ThreeVector::getZ() const { return pz; }
92 
93  double ThreeVector::getPt2() const { return px * px + py * py; }
94  double ThreeVector::getPt() const { return std::sqrt(getPt2()); }
95  double ThreeVector::getR() const { return std::sqrt(getPt2()); }
96 
97  double ThreeVector::getP2() const { return px * px + py * py + pz * pz; }
98  double ThreeVector::getP() const { return std::sqrt(getP2()); }
99  double ThreeVector::getMag()const { return std::sqrt(getP2()); }
100 
101  double ThreeVector::getPhi() const { return std::atan2(py, px); }
102  double ThreeVector::getTheta() const { return std::atan2(getPt(), pz); }
103  double ThreeVector::getEta() const { return -std::log(std::tan(0.5 * getTheta())); }
104 
105  double ThreeVector::getComponent(int i) const
106  {
107  switch (i) {
108  case 0: return getPx();
109  case 1: return getPy();
110  case 2: return getPz();
111  }
112  return NAN; // not-a-number, defined in cmath
113  }
114 
115  ThreeVector& ThreeVector::setValues(double px_, double py_, double pz_)
116  {
117  px = px_;
118  py = py_;
119  pz = pz_;
120  return *this;
121  }
122 
123 
124  ThreeVector& ThreeVector::operator+= (const ThreeVector& rhs)
125  {
126  px += rhs.px;
127  py += rhs.py;
128  pz += rhs.pz;
129  return *this;
130  }
131 
132  ThreeVector& ThreeVector::operator-= (const ThreeVector& rhs)
133  {
134  px -= rhs.px;
135  py -= rhs.py;
136  pz -= rhs.pz;
137  return *this;
138  }
139 
140  ThreeVector& ThreeVector::operator*= (double rhs)
141  {
142  px *= rhs;
143  py *= rhs;
144  pz *= rhs;
145  return *this;
146  }
147 
148  inline ThreeVector operator+ (const ThreeVector& lhs, const ThreeVector& rhs)
149  {
150  return ThreeVector(lhs.getPx() + rhs.getPx(), lhs.getPy() + rhs.getPy(), lhs.getPz() + rhs.getPz());
151  }
152 
153  inline ThreeVector operator- (const ThreeVector& lhs, const ThreeVector& rhs)
154  {
155  return ThreeVector(lhs.getPx() - rhs.getPx(), lhs.getPy() - rhs.getPy(), lhs.getPz() - rhs.getPz());
156  }
157 
158  inline ThreeVector operator- (const ThreeVector& rhs)
159  {
160  return ThreeVector(-rhs.getPx(), -rhs.getPy(), -rhs.getPz());
161  }
162 
163  inline double operator* (const ThreeVector& lhs, const ThreeVector& rhs)
164  {
165  return lhs.getPx() * rhs.getPx() + lhs.getPy() * rhs.getPy() + lhs.getPz() * rhs.getPz();
166  }
167 
168  inline ThreeVector operator* (double lhs, const ThreeVector& rhs)
169  {
170  return ThreeVector(lhs * rhs.getPx(), lhs * rhs.getPy(), lhs * rhs.getPz());
171  }
172 
173  inline std::ostream& operator<< (std::ostream& out, const ThreeVector& v)
174  {
175  out << "(" << v.getPx() << ", " << v.getPy() << ", " << v.getPz() << ")";
176  return out;
177  }
178 
179 
180  }// end OrcaKinFit namespace
182 } // end Belle2 namespace
183 
184 
185 #endif // __THREEVECTOR_H
186 
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
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