MarlinKinfit  0.4.0
FourVector.h
Go to the documentation of this file.
1 
19 #ifdef MARLIN_USE_ROOT
20 
21 #ifndef __FOURVECTOR_H
22 #define __FOURVECTOR_H
23 
24 #include "ThreeVector.h"
25 
26 #include <iostream>
27 #include <cmath>
28 #include <cassert>
29 
30 // Class FourVector:
32 
39 class FourVector {
40  public:
42  inline FourVector();
44  inline FourVector(double E_, double px_, double py_, double pz_);
46  inline FourVector(double E_, const ThreeVector& p_);
48  inline FourVector(const ThreeVector& p_, double m_);
49  // automatically generated copy constructor and assignment is fine
50 
52  inline double getE() const;
54  inline double getPx() const;
56  inline double getPy() const;
58  inline double getPz() const;
60  inline double getM2() const;
62  inline double getM() const;
64  inline double getMass() const;
65 
67  inline double getP2() const;
69  inline double getP() const;
71  inline double getPt2() const;
73  inline double getPt() const;
74 
76  inline double getPhi() const;
78  inline double getTheta() const;
80  inline double getEta() const;
81 
83  inline double getComponent (int i) const;
84 
85  inline ThreeVector getBeta() const { assert (E>0); return (1./E)*p;};
86  inline double getGamma() const { assert (getM()>0); return getE()/getM();};
87  inline ThreeVector getBetaGamma() const { assert (getM()>0); return (1./getM()>0)*p;};
88 
90  inline const ThreeVector& getThreeVector() const { return p;}
91 
92  FourVector& boost (const FourVector& P);
93  void decayto (FourVector& d1, FourVector& d2) const;
94 
95  inline void setValues (double E_, double px_, double py_, double pz_);
96 
97  inline FourVector& operator+= (const FourVector& rhs);
98  inline FourVector& operator-= (const FourVector& rhs);
99 
100  inline FourVector& operator*= (double rhs);
101 
102  private:
103  double E;
104  ThreeVector p;
105 };
106 
107 FourVector::FourVector()
108 : E(0), p()
109 {}
110 
111 FourVector::FourVector(double E_, double px_, double py_, double pz_)
112 : E(E_), p(px_, py_, pz_)
113 {}
114 
115 FourVector::FourVector(double E_, const ThreeVector& p_)
116 : E(E_), p(p_)
117 {}
118 
119 FourVector::FourVector(const ThreeVector& p_, double m)
120 : E(std::sqrt(p_.getP2() + m*m)), p(p_)
121 {}
122 
123 double FourVector::getE() const { return E; }
124 double FourVector::getPx() const { return p.getPx(); }
125 double FourVector::getPy() const { return p.getPy(); }
126 double FourVector::getPz() const { return p.getPz(); }
127 
128 double FourVector::getPt2() const { return p.getPt2(); }
129 double FourVector::getPt() const { return p.getPt(); }
130 
131 double FourVector::getP2() const { return p.getP2(); }
132 double FourVector::getP() const { return p.getP(); }
133 
134 double FourVector::getM2() const { return std::abs(getE()*getE()-getP2()); }
135 double FourVector::getM() const { return std::sqrt(getM2()); }
136 double FourVector::getMass() const { return std::sqrt(getM2()); }
137 
138 double FourVector::getPhi() const { return p.getPhi(); }
139 double FourVector::getTheta() const { return p.getTheta(); }
140 
141 double FourVector::getEta() const { return p.getEta(); }
142 
143 double FourVector::getComponent(int i) const {
144  switch (i) {
145  case 1: return getPx();
146  case 2: return getPy();
147  case 3: return getPz();
148  }
149  return getE();
150 }
151 
152 void FourVector::setValues(double E_, double px_, double py_, double pz_) {
153  E = E_;
154  p.setValues (px_, py_, pz_);
155 }
156 
157 FourVector& FourVector::operator+= (const FourVector& rhs) {
158  p += rhs.p;
159  E += rhs.E;
160  return *this;
161 }
162 
163 FourVector& FourVector::operator-= (const FourVector& rhs) {
164  p -= rhs.p;
165  E -= rhs.E;
166  return *this;
167 }
168 
169 FourVector& FourVector::operator*= (double rhs) {
170  p *= rhs;
171  E *= rhs;
172  return *this;
173 }
174 
179 inline FourVector operator+ (const FourVector& lhs, const FourVector& rhs) {
180  return FourVector (lhs.getE()+rhs.getE(), lhs.getPx()+rhs.getPx(), lhs.getPy()+rhs.getPy(), lhs.getPz()+rhs.getPz());
181 }
182 
187 inline FourVector operator- (const FourVector& lhs, const FourVector& rhs) {
188  return FourVector (lhs.getE()-rhs.getE(), lhs.getPx()-rhs.getPx(), lhs.getPy()-rhs.getPy(), lhs.getPz()-rhs.getPz());
189 }
190 
195 inline FourVector operator- (const FourVector& rhs) {
196  return FourVector (-rhs.getE(), -rhs.getPx(), -rhs.getPy(), -rhs.getPz());
197 }
198 
203 inline FourVector operator* (double lhs, const FourVector& rhs) {
204  return FourVector (lhs*rhs.getE(), lhs*rhs.getPx(), lhs*rhs.getPy(), lhs*rhs.getPz());
205 }
206 
211 inline double operator* (const FourVector& lhs, const FourVector& rhs) {
212  return lhs.getE()*rhs.getE() - lhs.getPx()*rhs.getPx() - lhs.getPy()*rhs.getPy() - lhs.getPz()*rhs.getPz();
213 }
214 
215 
220 inline std::ostream& operator<< (std::ostream& os,
221  const FourVector& rhs
222  ) {
223  os << "(" << rhs.getE() << ", " << rhs.getPx() << ", " << rhs.getPy() << ", " << rhs.getPz() << ")";
224  return os;
225 }
226 
227 
228 #endif // __FOURVECTOR_H
229 
230 #endif // MARLIN_USE_ROOT
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