1 //////////////////////////////////////////////////////////////////////////
3 //////////////////////////////////////////////////////////////////////////
5 //////////////////////////////////////////////////////////////////////////
6 // garren@fnal.gov, July 2006
9 //////////////////////////////////////////////////////////////////////////
12 #include <algorithm> // for swap
16 //////////////////////////////////////////////////////////////////////////
17 // FourVector inline methods
18 //////////////////////////////////////////////////////////////////////////
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 );
27 inline FourVector & FourVector::operator=(const FourVector & v) {
35 inline void FourVector::set(double xin, double yin, double zin, double tin) {
42 inline double FourVector::m2() const {
43 return m_t*m_t - (m_x*m_x + m_y*m_y + m_z*m_z);
46 inline double FourVector::m() const {
48 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
51 inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
53 inline double FourVector::perp() const { return std::sqrt(perp2()); }
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);
59 inline double FourVector::phi() const {
60 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
63 inline double FourVector::rho() const {
64 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
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;
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;
75 inline double FourVector::pseudoRapidity() const {
76 double m1 = std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
77 if ( m1== 0 ) return 0.0;
78 if ( m1== z() ) return 1.0E72;
79 if ( m1== -z() ) return -1.0E72;
80 return 0.5*log( (m1+z())/(m1-z()) );
83 inline double FourVector::eta() const { return pseudoRapidity();}
86 //////////////////////////////////////////////////////////////////////////
87 // ThreeVector inline methods
88 //////////////////////////////////////////////////////////////////////////
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 );
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);
100 inline double ThreeVector::phi() const {
101 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
104 inline double ThreeVector::r() const {
105 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
108 inline void ThreeVector::set(double xin, double yin, double zin) {
114 inline void ThreeVector::setPhi(double ph) {
116 setX(xy*std::cos(ph));
117 setY(xy*std::sin(ph));
120 inline void ThreeVector::setTheta(double th) {
123 setX(ma*std::sin(th)*std::cos(ph));
124 setY(ma*std::sin(th)*std::sin(ph));
125 setZ(ma*std::cos(th));
128 inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
130 inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
132 inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
140 inline bool ThreeVector::operator == (const ThreeVector& v) const {
141 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
144 inline bool ThreeVector::operator != (const ThreeVector& v) const {
145 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;