MarlinKinfit  0.4.0
ThreeVector.h
1 // Class ThreeVector
3 //
4 // Author: Benno List
5 // Last update: $Date: 2008/02/12 10:19:07 $
6 // by: $Author: blist $
7 //
8 // Description: class for three-vectors
9 //
11 
12 #ifndef __THREEVECTOR_H
13 #define __THREEVECTOR_H
14 
15 #include <iostream>
16 #include <cmath>
17 
18 class ThreeVector {
19  public:
20  inline ThreeVector();
21  inline ThreeVector(double px_, double py_, double pz_);
22  // automatically generated copy constructor and assignment is fine
23 
24  inline double getPx() const;
25  inline double getPy() const;
26  inline double getPz() const;
27  inline double getX() const;
28  inline double getY() const;
29  inline double getZ() const;
30 
31  inline double getP2() const;
32  inline double getP() const;
33  inline double getMag() const;
34  inline double getPt2() const;
35  inline double getPt() const;
36  inline double getR() const;
37 
38  inline double getPhi() const;
39  inline double getTheta() const;
40  inline double getEta() const;
41 
42  inline double getComponent (int i) const;
43 
44  inline ThreeVector& setValues(double px_, double py_, double pz_);
45 
46  inline ThreeVector& operator+= (const ThreeVector& rhs);
47  inline ThreeVector& operator-= (const ThreeVector& rhs);
48  inline ThreeVector& operator*= (double rhs);
49 
50  private:
51  double px, py, pz;
52 };
53 
54 ThreeVector::ThreeVector()
55 : px(0), py(0), pz(0)
56 {}
57 
58 ThreeVector::ThreeVector(double px_, double py_, double pz_)
59 : px(px_), py(py_), pz(pz_)
60 {}
61 
62 double ThreeVector::getPx() const { return px; }
63 double ThreeVector::getPy() const { return py; }
64 double ThreeVector::getPz() const { return pz; }
65 double ThreeVector::getX() const { return px; }
66 double ThreeVector::getY() const { return py; }
67 double ThreeVector::getZ() const { return pz; }
68 
69 double ThreeVector::getPt2() const { return px*px + py*py; }
70 double ThreeVector::getPt() const { return std::sqrt(getPt2()); }
71 double ThreeVector::getR() const { return std::sqrt(getPt2()); }
72 
73 double ThreeVector::getP2() const { return px*px + py*py + pz*pz; }
74 double ThreeVector::getP() const { return std::sqrt(getP2()); }
75 double ThreeVector::getMag()const { return std::sqrt(getP2()); }
76 
77 double ThreeVector::getPhi() const { return std::atan2(py, px); }
78 double ThreeVector::getTheta() const { return std::atan2(getPt(), pz); }
79 double ThreeVector::getEta() const { return -std::log(std::tan(0.5*getTheta())); }
80 
81 double ThreeVector::getComponent(int i) const {
82  switch (i) {
83  case 0: return getPx();
84  case 1: return getPy();
85  case 2: return getPz();
86  }
87  return NAN; // not-a-number, defined in cmath
88 }
89 
90 ThreeVector& ThreeVector::setValues(double px_, double py_, double pz_) {
91  px = px_;
92  py = py_;
93  pz = pz_;
94  return *this;
95 }
96 
97 
98 ThreeVector& ThreeVector::operator+= (const ThreeVector& rhs) {
99  px += rhs.px;
100  py += rhs.py;
101  pz += rhs.pz;
102  return *this;
103 }
104 
105 ThreeVector& ThreeVector::operator-= (const ThreeVector& rhs) {
106  px -= rhs.px;
107  py -= rhs.py;
108  pz -= rhs.pz;
109  return *this;
110 }
111 
112 ThreeVector& ThreeVector::operator*= (double rhs) {
113  px *= rhs;
114  py *= rhs;
115  pz *= rhs;
116  return *this;
117 }
118 
119 inline ThreeVector operator+ (const ThreeVector& lhs, const ThreeVector& rhs) {
120  return ThreeVector (lhs.getPx()+rhs.getPx(), lhs.getPy()+rhs.getPy(), lhs.getPz()+rhs.getPz());
121 }
122 
123 inline ThreeVector operator- (const ThreeVector& lhs, const ThreeVector& rhs) {
124  return ThreeVector (lhs.getPx()-rhs.getPx(), lhs.getPy()-rhs.getPy(), lhs.getPz()-rhs.getPz());
125 }
126 
127 inline ThreeVector operator- (const ThreeVector& rhs) {
128  return ThreeVector (-rhs.getPx(), -rhs.getPy(), -rhs.getPz());
129 }
130 
131 inline double operator* (const ThreeVector& lhs, const ThreeVector& rhs) {
132  return lhs.getPx()*rhs.getPx() + lhs.getPy()*rhs.getPy() + lhs.getPz()*rhs.getPz();
133 }
134 
135 inline ThreeVector operator* (double lhs, const ThreeVector& rhs) {
136  return ThreeVector (lhs*rhs.getPx(), lhs*rhs.getPy(), lhs*rhs.getPz());
137 }
138 
139 inline std::ostream& operator<< (std::ostream& out, const ThreeVector& v) {
140  out << "(" << v.getPx() << ", " << v.getPy() << ", " << v.getPz() << ")";
141  return out;
142 }
143 
144 
145 
146 #endif // __THREEVECTOR_H
147 
std::ostream & operator<<(std::ostream &os, const BaseConstraint &bc)
Prints out a BaseConstraint, using its print method.
Definition: BaseConstraint.h:128
Definition: ThreeVector.h:18