[349] | 1 | //////////////////////////////////////////////////////////////////////////
|
---|
| 2 | // SimpleVector.icc
|
---|
| 3 | //////////////////////////////////////////////////////////////////////////
|
---|
| 4 |
|
---|
| 5 | //////////////////////////////////////////////////////////////////////////
|
---|
| 6 | // garren@fnal.gov, July 2006
|
---|
| 7 | //
|
---|
| 8 | //
|
---|
| 9 | //////////////////////////////////////////////////////////////////////////
|
---|
| 10 |
|
---|
| 11 | #include <cmath>
|
---|
| 12 | #include <algorithm> // for swap
|
---|
| 13 |
|
---|
| 14 | namespace HepMC {
|
---|
| 15 |
|
---|
| 16 | //////////////////////////////////////////////////////////////////////////
|
---|
| 17 | // FourVector inline methods
|
---|
| 18 | //////////////////////////////////////////////////////////////////////////
|
---|
| 19 |
|
---|
| 20 | inline void FourVector::swap( FourVector & other ) {
|
---|
| 21 | std::swap( m_x, other.m_x );
|
---|
| 22 | std::swap( m_y, other.m_y );
|
---|
| 23 | std::swap( m_z, other.m_z );
|
---|
| 24 | std::swap( m_t, other.m_t );
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | inline FourVector & FourVector::operator=(const FourVector & v) {
|
---|
| 28 | m_x = v.x();
|
---|
| 29 | m_y = v.y();
|
---|
| 30 | m_z = v.z();
|
---|
| 31 | m_t = v.t();
|
---|
| 32 | return *this;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | inline void FourVector::set(double x, double y, double z, double t) {
|
---|
| 36 | m_x = x;
|
---|
| 37 | m_y = y;
|
---|
| 38 | m_z = z;
|
---|
| 39 | m_t = t;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | inline double FourVector::m2() const {
|
---|
| 43 | return m_t*m_t - (m_x*m_x + m_y*m_y + m_z*m_z);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | inline double FourVector::m() const {
|
---|
| 47 | double mm = m2();
|
---|
| 48 | return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
|
---|
| 52 |
|
---|
| 53 | inline double FourVector::perp() const { return std::sqrt(perp2()); }
|
---|
| 54 |
|
---|
| 55 | inline double FourVector::theta() const {
|
---|
| 56 | return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | inline double FourVector::phi() const {
|
---|
| 60 | return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | inline double FourVector::rho() const {
|
---|
| 64 | return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | inline bool FourVector::operator == (const FourVector & v) const {
|
---|
| 68 | return (v.x()==x() && v.y()==y() && v.z()==z() && v.t()==t()) ? true : false;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | inline bool FourVector::operator != (const FourVector & v) const {
|
---|
| 72 | return (v.x()!=x() || v.y()!=y() || v.z()!=z() || v.t()!=t()) ? true : false;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | inline double FourVector::pseudoRapidity() const {
|
---|
[572] | 76 | double m = std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
[349] | 77 | if ( m== 0 ) return 0.0;
|
---|
| 78 | if ( m== z() ) return 1.0E72;
|
---|
| 79 | if ( m== -z() ) return -1.0E72;
|
---|
| 80 | return 0.5*log( (m+z())/(m-z()) );
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | inline double FourVector::eta() const { return pseudoRapidity();}
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | //////////////////////////////////////////////////////////////////////////
|
---|
| 87 | // ThreeVector inline methods
|
---|
| 88 | //////////////////////////////////////////////////////////////////////////
|
---|
| 89 |
|
---|
| 90 | inline void ThreeVector::swap( ThreeVector & other ) {
|
---|
| 91 | std::swap( m_x, other.m_x );
|
---|
| 92 | std::swap( m_y, other.m_y );
|
---|
| 93 | std::swap( m_z, other.m_z );
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | inline double ThreeVector::theta() const {
|
---|
| 97 | return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | inline double ThreeVector::phi() const {
|
---|
| 101 | return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[572] | 104 | inline double ThreeVector::r() const {
|
---|
[349] | 105 | return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | inline void ThreeVector::set(double x, double y, double z) {
|
---|
| 109 | m_x = x;
|
---|
| 110 | m_y = y;
|
---|
| 111 | m_z = z;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | inline void ThreeVector::setPhi(double ph) {
|
---|
| 115 | double xy = perp();
|
---|
| 116 | setX(xy*std::cos(ph));
|
---|
| 117 | setY(xy*std::sin(ph));
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | inline void ThreeVector::setTheta(double th) {
|
---|
[572] | 121 | double ma = r();
|
---|
[349] | 122 | double ph = phi();
|
---|
| 123 | setX(ma*std::sin(th)*std::cos(ph));
|
---|
| 124 | setY(ma*std::sin(th)*std::sin(ph));
|
---|
| 125 | setZ(ma*std::cos(th));
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
|
---|
| 129 |
|
---|
| 130 | inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
|
---|
| 131 |
|
---|
| 132 | inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
|
---|
| 133 | m_x = p.x();
|
---|
| 134 | m_y = p.y();
|
---|
| 135 | m_z = p.z();
|
---|
| 136 | return *this;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | inline bool ThreeVector::operator == (const ThreeVector& v) const {
|
---|
| 141 | return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | inline bool ThreeVector::operator != (const ThreeVector& v) const {
|
---|
| 145 | return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | } // HepMC
|
---|