hepmc - Blame information for rev 209

Subversion Repositories:
Rev:
Rev Author Line No. Line
43 garren 1 //////////////////////////////////////////////////////////////////////////
2 // SimpleVector.icc
3 //////////////////////////////////////////////////////////////////////////
4  
5 //////////////////////////////////////////////////////////////////////////
6 // garren@fnal.gov, July 2006
7 //
8 //
9 //////////////////////////////////////////////////////////////////////////
10  
11 #include <cmath>
147 garren 12 #include <algorithm> // for swap
43 garren 13  
14 namespace HepMC {
15  
16 //////////////////////////////////////////////////////////////////////////
17 // FourVector inline methods
18 //////////////////////////////////////////////////////////////////////////
19  
147 garren 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  
43 garren 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  
209 garren 89 inline FourVector FourVector::operator + (const FourVector & q) const {
90 return FourVector(x()+q.x(), y()+q.y(), z()+q.z(), t()+q.t());
91 }
43 garren 92  
209 garren 93 inline FourVector & FourVector::operator += (const FourVector & q) {
94 m_x += q.x();
95 m_y += q.y();
96 m_z += q.z();
97 m_t += q.t();
98 return *this;
99 }
100  
101 inline FourVector FourVector::operator - (const FourVector & q) const {
102 return FourVector(x()-q.x(), y()-q.y(), z()-q.z(), t()-q.t());
103 }
104  
105 inline FourVector & FourVector::operator -= (const FourVector & q) {
106 m_x -= q.x();
107 m_y -= q.y();
108 m_z -= q.z();
109 m_t -= q.t();
110 return *this;
111 }
112  
113 inline FourVector FourVector::operator - () const {
114 return FourVector(-x(), -y(), -z(), -t());
115 }
116  
117 inline FourVector& FourVector::operator *= (double a) {
118 m_x *= a;
119 m_y *= a;
120 m_z *= a;
121 m_t *= a;
122 return *this;
123 }
124  
125  
43 garren 126 //////////////////////////////////////////////////////////////////////////
127 // ThreeVector inline methods
128 //////////////////////////////////////////////////////////////////////////
129  
147 garren 130 inline void ThreeVector::swap( ThreeVector & other ) {
131 std::swap( m_x, other.m_x );
132 std::swap( m_y, other.m_y );
133 std::swap( m_z, other.m_z );
134 }
135  
43 garren 136 inline double ThreeVector::theta() const {
137 return m_x == 0.0 && m_y == 0.0 && m_z == 0.0 ? 0.0 : std::atan2(perp(),m_z);
138 }
139  
140 inline double ThreeVector::phi() const {
141 return m_x == 0.0 && m_y == 0.0 ? 0.0 : std::atan2(m_y,m_x);
142 }
143  
144 inline double ThreeVector::mag() const {
145 return std::sqrt( m_x*m_x + m_y*m_y + m_z*m_z );
146 }
147  
148 inline double ThreeVector::r() const { return mag(); }
149  
54 garren 150 inline void ThreeVector::set(double x, double y, double z) {
151 m_x = x;
152 m_y = y;
153 m_z = z;
154 }
155  
43 garren 156 inline void ThreeVector::setPhi(double ph) {
157 double xy = perp();
158 setX(xy*std::cos(ph));
159 setY(xy*std::sin(ph));
160 }
161  
162 inline void ThreeVector::setTheta(double th) {
163 double ma = mag();
164 double ph = phi();
165 setX(ma*std::sin(th)*std::cos(ph));
166 setY(ma*std::sin(th)*std::sin(ph));
167 setZ(ma*std::cos(th));
168 }
169  
170 inline double ThreeVector::perp2() const { return m_x*m_x + m_y*m_y; }
171  
172 inline double ThreeVector::perp() const { return std::sqrt(perp2()); }
173  
174 inline ThreeVector & ThreeVector::operator = (const ThreeVector & p) {
175 m_x = p.x();
176 m_y = p.y();
177 m_z = p.z();
178 return *this;
179 }
180  
181  
182 inline bool ThreeVector::operator == (const ThreeVector& v) const {
183 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
184 }
185  
186 inline bool ThreeVector::operator != (const ThreeVector& v) const {
187 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
188 }
189  
209 garren 190 inline ThreeVector ThreeVector::operator + (const ThreeVector & q) const {
191 return ThreeVector(x()+q.x(), y()+q.y(), z()+q.z());
192 }
193  
194 inline ThreeVector & ThreeVector::operator += (const ThreeVector & q) {
195 m_x += q.x();
196 m_y += q.y();
197 m_z += q.z();
198 return *this;
199 }
200  
201 inline ThreeVector ThreeVector::operator - (const ThreeVector & q) const {
202 return ThreeVector(x()-q.x(), y()-q.y(), z()-q.z());
203 }
204  
205 inline ThreeVector & ThreeVector::operator -= (const ThreeVector & q) {
206 m_x -= q.x();
207 m_y -= q.y();
208 m_z -= q.z();
209 return *this;
210 }
211  
212 inline ThreeVector ThreeVector::operator - () const {
213 return ThreeVector(-x(), -y(), -z());
214 }
215  
216 inline ThreeVector& ThreeVector::operator *= (double a) {
217 m_x *= a;
218 m_y *= a;
219 m_z *= a;
220 return *this;
221 }
222  
43 garren 223 } // HepMC