00001
00002
00004
00006
00007
00008
00010
00011 #include <cmath>
00012 #include <algorithm>
00013
00014 namespace HepMC {
00015
00017
00019
00020 inline void FourVector::swap( FourVector & other ) {
00021 std::swap( m_x, other.m_x );
00022 std::swap( m_y, other.m_y );
00023 std::swap( m_z, other.m_z );
00024 std::swap( m_t, other.m_t );
00025 }
00026
00027 inline FourVector & FourVector::operator=(const FourVector & v) {
00028 m_x = v.x();
00029 m_y = v.y();
00030 m_z = v.z();
00031 m_t = v.t();
00032 return *this;
00033 }
00034
00035 inline void FourVector::set(double x, double y, double z, double t) {
00036 m_x = x;
00037 m_y = y;
00038 m_z = z;
00039 m_t = t;
00040 }
00041
00042 inline double FourVector::m2() const {
00043 return m_t*m_t - (m_x*m_x + m_y*m_y + m_z*m_z);
00044 }
00045
00046 inline double FourVector::m() const {
00047 double mm = m2();
00048 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
00049 }
00050
00051 inline double FourVector::mag() const {
00052 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
00053 }
00054
00055 inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
00056
00057 inline double FourVector::perp() const { return std::sqrt(perp2()); }
00058
00059 inline double FourVector::theta() const {
00060 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
00061 }
00062
00063 inline double FourVector::phi() const {
00064 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
00065 }
00066
00067 inline double FourVector::rho() const {
00068 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
00069 }
00070
00071 inline bool FourVector::operator == (const FourVector & v) const {
00072 return (v.x()==x() && v.y()==y() && v.z()==z() && v.t()==t()) ? true : false;
00073 }
00074
00075 inline bool FourVector::operator != (const FourVector & v) const {
00076 return (v.x()!=x() || v.y()!=y() || v.z()!=z() || v.t()!=t()) ? true : false;
00077 }
00078
00079 inline double FourVector::pseudoRapidity() const {
00080 double m = mag();
00081 if ( m== 0 ) return 0.0;
00082 if ( m== z() ) return 1.0E72;
00083 if ( m== -z() ) return -1.0E72;
00084 return 0.5*log( (m+z())/(m-z()) );
00085 }
00086
00087 inline double FourVector::eta() const { return pseudoRapidity();}
00088
00089
00091
00093
00094 inline void ThreeVector::swap( ThreeVector & other ) {
00095 std::swap( m_x, other.m_x );
00096 std::swap( m_y, other.m_y );
00097 std::swap( m_z, other.m_z );
00098 }
00099
00100 inline double ThreeVector::theta() const {
00101 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
00102 }
00103
00104 inline double ThreeVector::phi() const {
00105 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
00106 }
00107
00108 inline double ThreeVector::mag() const {
00109 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
00110 }
00111
00112 inline double ThreeVector::r() const { return mag(); }
00113
00114 inline void ThreeVector::set(double x, double y, double z) {
00115 m_x = x;
00116 m_y = y;
00117 m_z = z;
00118 }
00119
00120 inline void ThreeVector::setPhi(double ph) {
00121 double xy = perp();
00122 setX(xy*std::cos(ph));
00123 setY(xy*std::sin(ph));
00124 }
00125
00126 inline void ThreeVector::setTheta(double th) {
00127 double ma = mag();
00128 double ph = phi();
00129 setX(ma*std::sin(th)*std::cos(ph));
00130 setY(ma*std::sin(th)*std::sin(ph));
00131 setZ(ma*std::cos(th));
00132 }
00133
00134 inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
00135
00136 inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
00137
00138 inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
00139 m_x = p.x();
00140 m_y = p.y();
00141 m_z = p.z();
00142 return *this;
00143 }
00144
00145
00146 inline bool ThreeVector::operator == (const ThreeVector& v) const {
00147 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
00148 }
00149
00150 inline bool ThreeVector::operator != (const ThreeVector& v) const {
00151 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
00152 }
00153
00154 }