Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

ThreeVector.h

Go to the documentation of this file.
00001 
00002 // Class ThreeVector
00003 //
00004 // Author: Benno List
00005 // Last update: $Date: 2005/01/12 10:11:46 $
00006 //          by: $Author: blist $
00007 // 
00008 // Description: class for three-vectors
00009 //               
00011 
00012 #ifndef __THREEVECTOR_H
00013 #define __THREEVECTOR_H
00014 
00015 #include <iostream>
00016 #include <cmath>
00017 
00018 class ThreeVector {
00019   public:
00020     inline ThreeVector();
00021     inline ThreeVector(double px_, double py_, double pz_);
00022     // automatically generated copy constructor and assignment is fine
00023     
00024     inline double getPx()    const;
00025     inline double getPy()    const;
00026     inline double getPz()    const;
00027     inline double getX()     const;
00028     inline double getY()     const;
00029     inline double getZ()     const;
00030     
00031     inline double getP2()    const;
00032     inline double getP()     const;
00033     inline double getMag()   const;
00034     inline double getPt2()   const;
00035     inline double getPt()    const;
00036     inline double getR()     const;
00037     
00038     inline double getPhi()   const;
00039     inline double getTheta() const;
00040     inline double getEta()   const;
00041     
00042     inline double getComponent (int i) const;
00043     
00044     inline ThreeVector& setValues(double px_, double py_, double pz_);
00045 
00046     inline ThreeVector& ThreeVector::operator+= (const ThreeVector& rhs);
00047     inline ThreeVector& ThreeVector::operator-= (const ThreeVector& rhs);
00048     inline ThreeVector& ThreeVector::operator*= (double rhs);
00049     
00050   private:
00051     double px, py, pz;
00052 };
00053 
00054 ThreeVector::ThreeVector()
00055 : px(0), py(0), pz(0)
00056 {}
00057 
00058 ThreeVector::ThreeVector(double px_, double py_, double pz_)
00059 : px(px_), py(py_), pz(pz_)
00060 {}
00061     
00062 double ThreeVector::getPx() const { return px; }
00063 double ThreeVector::getPy() const { return py; }
00064 double ThreeVector::getPz() const { return pz; }
00065 double ThreeVector::getX()  const { return px; }
00066 double ThreeVector::getY()  const { return py; }
00067 double ThreeVector::getZ()  const { return pz; }
00068 
00069 double ThreeVector::getPt2() const { return px*px + py*py; }
00070 double ThreeVector::getPt()  const { return std::sqrt(getPt2()); }
00071 double ThreeVector::getR()   const { return std::sqrt(getPt2()); }
00072 
00073 double ThreeVector::getP2() const { return px*px + py*py + pz*pz; }
00074 double ThreeVector::getP()  const { return std::sqrt(getP2()); }
00075 double ThreeVector::getMag()const { return std::sqrt(getP2()); }
00076 
00077 double ThreeVector::getPhi()   const { return std::atan2(py, px); }
00078 double ThreeVector::getTheta() const { return std::atan2(getPt(), pz); }
00079 double ThreeVector::getEta() const { return -std::log(std::tan(0.5*getTheta())); }
00080 
00081 double ThreeVector::getComponent(int i) const { 
00082   switch (i) {
00083     case 0: return getPx();
00084     case 1: return getPy();
00085     case 2: return getPz();
00086   }
00087   return NAN; // not-a-number, defined in cmath
00088 }
00089 
00090 ThreeVector& ThreeVector::setValues(double px_, double py_, double pz_) {
00091   px = px_;
00092   py = py_;
00093   pz = pz_;
00094   return *this;
00095 }
00096 
00097 
00098 ThreeVector& ThreeVector::operator+= (const ThreeVector& rhs) {
00099   px += rhs.px;
00100   py += rhs.py;
00101   pz += rhs.pz;
00102   return *this;
00103 }
00104 
00105 ThreeVector& ThreeVector::operator-= (const ThreeVector& rhs) {
00106   px -= rhs.px;
00107   py -= rhs.py;
00108   pz -= rhs.pz;
00109   return *this;
00110 }
00111 
00112 ThreeVector& ThreeVector::operator*= (double rhs) {
00113   px *= rhs;
00114   py *= rhs;
00115   pz *= rhs;
00116   return *this;
00117 }
00118 
00119 inline ThreeVector operator+ (const ThreeVector& lhs, const ThreeVector& rhs) {
00120   return ThreeVector (lhs.getPx()+rhs.getPx(), lhs.getPy()+rhs.getPy(), lhs.getPz()+rhs.getPz());
00121 }
00122 
00123 inline ThreeVector operator- (const ThreeVector& lhs, const ThreeVector& rhs) {
00124   return ThreeVector (lhs.getPx()-rhs.getPx(), lhs.getPy()-rhs.getPy(), lhs.getPz()-rhs.getPz());
00125 }
00126 
00127 inline ThreeVector operator- (const ThreeVector& rhs) {
00128   return ThreeVector (-rhs.getPx(), -rhs.getPy(), -rhs.getPz());
00129 }
00130 
00131 inline double operator* (const ThreeVector& lhs, const ThreeVector& rhs) {
00132   return lhs.getPx()*rhs.getPx() + lhs.getPy()*rhs.getPy() + lhs.getPz()*rhs.getPz();
00133 }
00134 
00135 inline ThreeVector operator* (double lhs, const ThreeVector& rhs) {
00136   return ThreeVector (lhs*rhs.getPx(), lhs*rhs.getPy(), lhs*rhs.getPz());
00137 }
00138     
00139 inline std::ostream& operator<< (std::ostream& out, const ThreeVector& v) {
00140   out << "(" << v.getPx() << ", " << v.getPy() << ", " << v.getPz() << ")";
00141   return out;
00142 }
00143 
00144 
00145 
00146 #endif // __THREEVECTOR_H
00147 

Generated on Fri Sep 14 17:38:21 2007 for Kinfit by doxygen 1.3.2