Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:18:37

0001 //////////////////////////////////////////////////////////////////////////
0002 // SimpleVector.icc
0003 //////////////////////////////////////////////////////////////////////////
0004 
0005 //////////////////////////////////////////////////////////////////////////
0006 // garren@fnal.gov, July 2006
0007 //
0008 //
0009 //////////////////////////////////////////////////////////////////////////
0010 
0011 #include <cmath>
0012 #include <algorithm>    // for swap
0013 
0014 namespace HepMC {
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //  FourVector inline methods
0018 //////////////////////////////////////////////////////////////////////////
0019 
0020 inline void FourVector::swap( FourVector & other ) {
0021     std::swap( m_x, other.m_x );
0022     std::swap( m_y, other.m_y );
0023     std::swap( m_z, other.m_z );
0024     std::swap( m_t, other.m_t );
0025 }
0026 
0027 inline FourVector & FourVector::operator=(const FourVector & v) {
0028   m_x = v.x();
0029   m_y = v.y();
0030   m_z = v.z();
0031   m_t = v.t();
0032   return *this;
0033 }
0034 
0035 inline void FourVector::set(double xin, double yin, double zin, double  tin) {
0036   m_x = xin;
0037   m_y = yin;
0038   m_z = zin;
0039   m_t = tin;
0040 }
0041 
0042 inline double FourVector::m2() const {
0043   return m_t*m_t - (m_x*m_x + m_y*m_y + m_z*m_z);
0044 }
0045 
0046 inline double FourVector::m() const {
0047   double mm = m2();
0048   return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
0049 }
0050 
0051 inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
0052 
0053 inline double FourVector::perp() const { return std::sqrt(perp2()); }
0054 
0055 inline double FourVector::theta() const  {
0056   return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
0057 }
0058 
0059 inline double FourVector::phi() const {
0060   return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
0061 }
0062 
0063 inline double  FourVector::rho() const { 
0064 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
0065 }
0066 
0067 inline bool FourVector::operator == (const FourVector & v) const {
0068   return (v.x()==x() && v.y()==y() && v.z()==z() && v.t()==t()) ? true : false;
0069 }
0070 
0071 inline bool FourVector::operator != (const FourVector & v) const {
0072   return (v.x()!=x() || v.y()!=y() || v.z()!=z() || v.t()!=t()) ? true : false;
0073 }
0074 
0075 inline double FourVector::pseudoRapidity() const {
0076   double m1 = std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
0077   if ( m1==  0   ) return  0.0;   
0078   if ( m1==  z() ) return  1.0E72;
0079   if ( m1== -z() ) return -1.0E72;
0080   return 0.5*log( (m1+z())/(m1-z()) );
0081 }
0082 
0083 inline double FourVector::eta()    const { return pseudoRapidity();}
0084 
0085 
0086 //////////////////////////////////////////////////////////////////////////
0087 //  ThreeVector inline methods
0088 //////////////////////////////////////////////////////////////////////////
0089 
0090 inline void ThreeVector::swap( ThreeVector & other ) {
0091     std::swap( m_x, other.m_x );
0092     std::swap( m_y, other.m_y );
0093     std::swap( m_z, other.m_z );
0094 }
0095 
0096 inline double ThreeVector::theta() const     {
0097   return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
0098 }
0099 
0100 inline double ThreeVector::phi() const {
0101   return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
0102 }
0103 
0104 inline double ThreeVector::r()    const { 
0105 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
0106 }
0107 
0108 inline void ThreeVector::set(double xin, double yin, double zin) {
0109   m_x = xin;
0110   m_y = yin;
0111   m_z = zin;
0112 }
0113 
0114 inline void ThreeVector::setPhi(double ph) { 
0115   double xy   = perp();
0116   setX(xy*std::cos(ph));
0117   setY(xy*std::sin(ph));
0118 }
0119 
0120 inline void ThreeVector::setTheta(double th) { 
0121   double ma   = r();
0122   double ph   = phi();
0123   setX(ma*std::sin(th)*std::cos(ph));
0124   setY(ma*std::sin(th)*std::sin(ph));
0125   setZ(ma*std::cos(th));
0126 }
0127 
0128 inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
0129 
0130 inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
0131 
0132 inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
0133   m_x = p.x();
0134   m_y = p.y();
0135   m_z = p.z();
0136   return *this;
0137 }
0138 
0139 
0140 inline bool ThreeVector::operator == (const ThreeVector& v) const {
0141   return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
0142 }
0143 
0144 inline bool ThreeVector::operator != (const ThreeVector& v) const {
0145   return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
0146 }
0147 
0148 } // HepMC