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

FourVector.h

Go to the documentation of this file.
00001 
00016 #ifndef __FOURVECTOR_H
00017 #define __FOURVECTOR_H
00018 
00019 #include "jbltools/kinfit/ThreeVector.h"
00020 
00021 #include <iostream>
00022 #include <cmath>
00023 #include <cassert>
00024 
00025 //  Class FourVector:
00027 
00034 class FourVector {
00035   public:
00037     inline FourVector();
00039     inline FourVector(double E_, double px_, double py_, double pz_);
00041     inline FourVector(double E_, const ThreeVector& p_);
00043     inline FourVector(const ThreeVector& p_, double m_);
00044     // automatically generated copy constructor and assignment is fine
00045     
00047     inline double getE()     const;
00049     inline double getPx()    const;
00051     inline double getPy()    const;
00053     inline double getPz()    const;
00055     inline double getM2()    const;
00057     inline double getM()     const;
00059     inline double getMass()     const;
00060     
00062     inline double getP2()    const;
00064     inline double getP()     const;
00066     inline double getPt2()   const;
00068     inline double getPt()    const;
00069     
00071     inline double getPhi()   const;
00073     inline double getTheta() const;
00075     inline double getEta() const;
00076     
00078     inline double getComponent (int i) const;
00079     
00080     inline ThreeVector getBeta() const { assert (E>0); return (1./E)*p;};
00081     inline double getGamma() const { assert (getM()>0); return getE()/getM();};
00082     inline ThreeVector getBetaGamma() const { assert (getM()>0); return (1./getM()>0)*p;};
00083 
00085     inline const ThreeVector& getThreeVector() const { return p;}
00086     
00087     FourVector& boost (const FourVector& P);
00088     void decayto (FourVector& d1, FourVector& d2) const;
00089     
00090     inline void setValues (double E_, double px_, double py_, double pz_);
00091     
00092     inline FourVector& operator+= (const FourVector& rhs);
00093     inline FourVector& operator-= (const FourVector& rhs);
00094     
00095     inline FourVector& operator*= (double rhs);
00096   
00097   private:
00098     double E;         
00099     ThreeVector p;    
00100 };
00101 
00102 FourVector::FourVector()
00103 : E(0), p()
00104 {}
00105 
00106 FourVector::FourVector(double E_, double px_, double py_, double pz_)
00107 : E(E_), p(px_, py_, pz_)
00108 {}
00109 
00110 FourVector::FourVector(double E_, const ThreeVector& p_)
00111 : E(E_), p(p_)
00112 {}
00113     
00114 FourVector::FourVector(const ThreeVector& p_, double m)
00115 : E(std::sqrt(p_.getP2() + m*m)), p(p_)
00116 {}
00117     
00118 double FourVector::getE()  const { return E; }
00119 double FourVector::getPx() const { return p.getPx(); }
00120 double FourVector::getPy() const { return p.getPy(); }
00121 double FourVector::getPz() const { return p.getPz(); }
00122 
00123 double FourVector::getPt2() const { return p.getPt2(); }
00124 double FourVector::getPt()  const { return p.getPt(); }
00125 
00126 double FourVector::getP2() const { return p.getP2(); }
00127 double FourVector::getP()  const { return p.getP(); }
00128 
00129 double FourVector::getM2()   const { return std::abs(getE()*getE()-getP2()); }
00130 double FourVector::getM()    const { return std::sqrt(getM2()); }
00131 double FourVector::getMass() const { return std::sqrt(getM2()); }
00132 
00133 double FourVector::getPhi()   const { return p.getPhi(); }
00134 double FourVector::getTheta() const { return p.getTheta(); }
00135 
00136 double FourVector::getEta() const { return p.getEta(); }
00137 
00138 double FourVector::getComponent(int i) const { 
00139   switch (i) {
00140     case 1: return getPx();
00141     case 2: return getPy();
00142     case 3: return getPz();
00143   }
00144   return getE();
00145 }
00146 
00147 void FourVector::setValues(double E_, double px_, double py_, double pz_) {
00148   E = E_;
00149   p.setValues (px_, py_, pz_);
00150 }
00151 
00152 FourVector& FourVector::operator+= (const FourVector& rhs) {
00153   p += rhs.p;
00154   E += rhs.E;
00155   return *this;
00156 }
00157 
00158 FourVector& FourVector::operator-= (const FourVector& rhs) {
00159   p -= rhs.p;
00160   E -= rhs.E;
00161   return *this;
00162 }
00163 
00164 FourVector& FourVector::operator*= (double rhs) {
00165   p *= rhs;
00166   E *= rhs;
00167   return *this;
00168 }
00169 
00174 inline FourVector operator+ (const FourVector& lhs, const FourVector& rhs) {
00175   return FourVector (lhs.getE()+rhs.getE(), lhs.getPx()+rhs.getPx(), lhs.getPy()+rhs.getPy(), lhs.getPz()+rhs.getPz());
00176 }
00177 
00182 inline FourVector operator- (const FourVector& lhs, const FourVector& rhs) {
00183   return FourVector (lhs.getE()-rhs.getE(), lhs.getPx()-rhs.getPx(), lhs.getPy()-rhs.getPy(), lhs.getPz()-rhs.getPz());
00184 }
00185 
00190 inline FourVector operator- (const FourVector& rhs) {
00191   return FourVector (-rhs.getE(), -rhs.getPx(), -rhs.getPy(), -rhs.getPz());
00192 }
00193 
00198 inline FourVector operator* (double lhs, const FourVector& rhs) {
00199   return FourVector (lhs*rhs.getE(), lhs*rhs.getPx(), lhs*rhs.getPy(), lhs*rhs.getPz());
00200 }
00201 
00206 inline double operator* (const FourVector& lhs, const FourVector& rhs) {
00207   return lhs.getE()*rhs.getE() - lhs.getPx()*rhs.getPx() - lhs.getPy()*rhs.getPy() - lhs.getPz()*rhs.getPz();
00208 }
00209 
00210 
00215 inline std::ostream& operator<< (std::ostream& os, 
00216                                  const FourVector& rhs 
00217                                 ) {
00218   os << "(" << rhs.getE() << ", " << rhs.getPx() << ", " << rhs.getPy() << ", " << rhs.getPz() << ")";
00219   return os;
00220 }
00221 
00222 
00223 #endif // __FOURVECTOR_H
00224 

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