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::mag() const {
|
---|
52 | return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
53 | }
|
---|
54 |
|
---|
55 | inline double FourVector::perp2() const { return m_x*m_x + m_y*m_y; }
|
---|
56 |
|
---|
57 | inline double FourVector::perp() const { return std::sqrt(perp2()); }
|
---|
58 |
|
---|
59 | inline double FourVector::theta() const {
|
---|
60 | return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
|
---|
61 | }
|
---|
62 |
|
---|
63 | inline double FourVector::phi() const {
|
---|
64 | return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
|
---|
65 | }
|
---|
66 |
|
---|
67 | inline double FourVector::rho() const {
|
---|
68 | return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
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 bool FourVector::operator != (const FourVector & v) const {
|
---|
76 | return (v.x()!=x() || v.y()!=y() || v.z()!=z() || v.t()!=t()) ? true : false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline double FourVector::pseudoRapidity() const {
|
---|
80 | double m = mag();
|
---|
81 | if ( m== 0 ) return 0.0;
|
---|
82 | if ( m== z() ) return 1.0E72;
|
---|
83 | if ( m== -z() ) return -1.0E72;
|
---|
84 | return 0.5*log( (m+z())/(m-z()) );
|
---|
85 | }
|
---|
86 |
|
---|
87 | inline double FourVector::eta() const { return pseudoRapidity();}
|
---|
88 |
|
---|
89 |
|
---|
90 | //////////////////////////////////////////////////////////////////////////
|
---|
91 | // ThreeVector inline methods
|
---|
92 | //////////////////////////////////////////////////////////////////////////
|
---|
93 |
|
---|
94 | inline void ThreeVector::swap( ThreeVector & other ) {
|
---|
95 | std::swap( m_x, other.m_x );
|
---|
96 | std::swap( m_y, other.m_y );
|
---|
97 | std::swap( m_z, other.m_z );
|
---|
98 | }
|
---|
99 |
|
---|
100 | inline double ThreeVector::theta() const {
|
---|
101 | return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
|
---|
102 | }
|
---|
103 |
|
---|
104 | inline double ThreeVector::phi() const {
|
---|
105 | return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
|
---|
106 | }
|
---|
107 |
|
---|
108 | inline double ThreeVector::mag() const {
|
---|
109 | return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
|
---|
110 | }
|
---|
111 |
|
---|
112 | inline double ThreeVector::r() const { return mag(); }
|
---|
113 |
|
---|
114 | inline void ThreeVector::set(double x, double y, double z) {
|
---|
115 | m_x = x;
|
---|
116 | m_y = y;
|
---|
117 | m_z = z;
|
---|
118 | }
|
---|
119 |
|
---|
120 | inline void ThreeVector::setPhi(double ph) {
|
---|
121 | double xy = perp();
|
---|
122 | setX(xy*std::cos(ph));
|
---|
123 | setY(xy*std::sin(ph));
|
---|
124 | }
|
---|
125 |
|
---|
126 | inline void ThreeVector::setTheta(double th) {
|
---|
127 | double ma = mag();
|
---|
128 | double ph = phi();
|
---|
129 | setX(ma*std::sin(th)*std::cos(ph));
|
---|
130 | setY(ma*std::sin(th)*std::sin(ph));
|
---|
131 | setZ(ma*std::cos(th));
|
---|
132 | }
|
---|
133 |
|
---|
134 | inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
|
---|
135 |
|
---|
136 | inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
|
---|
137 |
|
---|
138 | inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
|
---|
139 | m_x = p.x();
|
---|
140 | m_y = p.y();
|
---|
141 | m_z = p.z();
|
---|
142 | return *this;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | inline bool ThreeVector::operator == (const ThreeVector& v) const {
|
---|
147 | return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
|
---|
148 | }
|
---|
149 |
|
---|
150 | inline bool ThreeVector::operator != (const ThreeVector& v) const {
|
---|
151 | return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
|
---|
152 | }
|
---|
153 |
|
---|
154 | } // HepMC
|
---|