source: trunk/CLHEP/Vector/LorentzVector.icc@ 4

Last change on this file since 4 was 4, checked in by Pavel Demin, 16 years ago

first commit

File size: 12.3 KB
Line 
1// -*- C++ -*-
2// $Id: LorentzVector.icc,v 1.1 2008-06-04 14:14:58 demin Exp $
3// ---------------------------------------------------------------------------
4//
5// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6//
7// This is the definitions of the inline member functions of the
8// HepLorentzVector class.
9//
10
11#include "CLHEP/Vector/ZMxpv.h"
12
13#include <cmath>
14
15namespace CLHEP {
16
17inline double HepLorentzVector::x() const { return pp.x(); }
18inline double HepLorentzVector::y() const { return pp.y(); }
19inline double HepLorentzVector::z() const { return pp.z(); }
20inline double HepLorentzVector::t() const { return ee; }
21
22inline HepLorentzVector::
23HepLorentzVector(double x, double y, double z, double t)
24 : pp(x, y, z), ee(t) {}
25
26inline HepLorentzVector:: HepLorentzVector(double x, double y, double z)
27 : pp(x, y, z), ee(0) {}
28
29inline HepLorentzVector:: HepLorentzVector(double t)
30 : pp(0, 0, 0), ee(t) {}
31
32inline HepLorentzVector:: HepLorentzVector()
33 : pp(0, 0, 0), ee(0) {}
34
35inline HepLorentzVector::HepLorentzVector(const Hep3Vector & p, double e)
36 : pp(p), ee(e) {}
37
38inline HepLorentzVector::HepLorentzVector(double e, const Hep3Vector & p)
39 : pp(p), ee(e) {}
40
41inline HepLorentzVector::HepLorentzVector(const HepLorentzVector & p)
42 : pp(p.x(), p.y(), p.z()), ee(p.t()) {}
43
44inline HepLorentzVector::~HepLorentzVector() {}
45
46inline HepLorentzVector::operator const Hep3Vector & () const {return pp;}
47inline HepLorentzVector::operator Hep3Vector & () { return pp; }
48
49inline void HepLorentzVector::setX(double a) { pp.setX(a); }
50inline void HepLorentzVector::setY(double a) { pp.setY(a); }
51inline void HepLorentzVector::setZ(double a) { pp.setZ(a); }
52inline void HepLorentzVector::setT(double a) { ee = a;}
53
54inline double HepLorentzVector::px() const { return pp.x(); }
55inline double HepLorentzVector::py() const { return pp.y(); }
56inline double HepLorentzVector::pz() const { return pp.z(); }
57inline double HepLorentzVector::e() const { return ee; }
58
59inline void HepLorentzVector::setPx(double a) { pp.setX(a); }
60inline void HepLorentzVector::setPy(double a) { pp.setY(a); }
61inline void HepLorentzVector::setPz(double a) { pp.setZ(a); }
62inline void HepLorentzVector::setE(double a) { ee = a;}
63
64inline Hep3Vector HepLorentzVector::vect() const { return pp; }
65inline void HepLorentzVector::setVect(const Hep3Vector &p) { pp = p; }
66
67inline double HepLorentzVector::theta() const { return pp.theta(); }
68inline double HepLorentzVector::cosTheta() const { return pp.cosTheta(); }
69inline double HepLorentzVector::phi() const { return pp.phi(); }
70inline double HepLorentzVector::rho() const { return pp.mag(); }
71
72inline void HepLorentzVector::setTheta(double a) { pp.setTheta(a); }
73inline void HepLorentzVector::setPhi(double a) { pp.setPhi(a); }
74inline void HepLorentzVector::setRho(double a) { pp.setMag(a); }
75
76double & HepLorentzVector::operator [] (int i) { return (*this)(i); }
77double HepLorentzVector::operator [] (int i) const { return (*this)(i); }
78
79inline HepLorentzVector &
80HepLorentzVector::operator = (const HepLorentzVector & q) {
81 pp = q.vect();
82 ee = q.t();
83 return *this;
84}
85
86inline HepLorentzVector
87HepLorentzVector::operator + (const HepLorentzVector & q) const {
88 return HepLorentzVector(x()+q.x(), y()+q.y(), z()+q.z(), t()+q.t());
89}
90
91inline HepLorentzVector &
92HepLorentzVector::operator += (const HepLorentzVector & q) {
93 pp += q.vect();
94 ee += q.t();
95 return *this;
96}
97
98inline HepLorentzVector
99HepLorentzVector::operator - (const HepLorentzVector & q) const {
100 return HepLorentzVector(x()-q.x(), y()-q.y(), z()-q.z(), t()-q.t());
101}
102
103inline HepLorentzVector &
104HepLorentzVector::operator -= (const HepLorentzVector & q) {
105 pp -= q.vect();
106 ee -= q.t();
107 return *this;
108}
109
110inline HepLorentzVector HepLorentzVector::operator - () const {
111 return HepLorentzVector(-x(), -y(), -z(), -t());
112}
113
114inline HepLorentzVector& HepLorentzVector::operator *= (double a) {
115 pp *= a;
116 ee *= a;
117 return *this;
118}
119
120inline bool
121HepLorentzVector::operator == (const HepLorentzVector & q) const {
122 return (vect()==q.vect() && t()==q.t());
123}
124
125inline bool
126HepLorentzVector::operator != (const HepLorentzVector & q) const {
127 return (vect()!=q.vect() || t()!=q.t());
128}
129
130inline double HepLorentzVector::perp2() const { return pp.perp2(); }
131inline double HepLorentzVector::perp() const { return pp.perp(); }
132inline void HepLorentzVector::setPerp(double a) { pp.setPerp(a); }
133
134inline double HepLorentzVector::perp2(const Hep3Vector &v) const {
135 return pp.perp2(v);
136}
137
138inline double HepLorentzVector::perp(const Hep3Vector &v) const {
139 return pp.perp(v);
140}
141
142inline double HepLorentzVector::angle(const Hep3Vector &v) const {
143 return pp.angle(v);
144}
145
146inline double HepLorentzVector::mag2() const {
147#if defined USING_VISUAL
148 // kludge for problem building Windows DLL
149 double r = metric*(t()*t() - pp.mag2());
150 return r;
151#else
152 return metric*(t()*t() - pp.mag2());
153#endif
154}
155
156inline double HepLorentzVector::mag() const {
157 double mm = m2();
158 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
159}
160
161inline double HepLorentzVector::m2() const {
162 return t()*t() - pp.mag2();
163}
164
165inline double HepLorentzVector::m() const { return mag(); }
166
167inline double HepLorentzVector::mt2() const {
168 return e()*e() - pz()*pz();
169}
170
171inline double HepLorentzVector::mt() const {
172 double mm = mt2();
173 return mm < 0.0 ? -std::sqrt(-mm) : std::sqrt(mm);
174}
175
176inline double HepLorentzVector::et2() const {
177 double pt2 = pp.perp2();
178 return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+z()*z());
179}
180
181inline double HepLorentzVector::et() const {
182 double etet = et2();
183 return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
184}
185
186inline double HepLorentzVector::et2(const Hep3Vector & v) const {
187 double pt2 = pp.perp2(v);
188 double pv = pp.dot(v.unit());
189 return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+pv*pv);
190}
191
192inline double HepLorentzVector::et(const Hep3Vector & v) const {
193 double etet = et2(v);
194 return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
195}
196
197inline void
198HepLorentzVector::setVectMag(const Hep3Vector & spatial, double magnitude) {
199 setVect(spatial);
200 setT(std::sqrt(magnitude * magnitude + spatial * spatial));
201}
202
203inline void
204HepLorentzVector::setVectM(const Hep3Vector & spatial, double mass) {
205 setVectMag(spatial, mass);
206}
207
208inline double HepLorentzVector::dot(const HepLorentzVector & q) const {
209#if defined USING_VISUAL
210 // kludge for problem building Windows DLL
211 double r = metric*(t()*q.t() - z()*q.z() - y()*q.y() - x()*q.x());
212 return r;
213#else
214 return metric*(t()*q.t() - z()*q.z() - y()*q.y() - x()*q.x());
215#endif
216}
217
218inline double
219HepLorentzVector::operator * (const HepLorentzVector & q) const {
220 return dot(q);
221}
222
223inline double HepLorentzVector::plus() const {
224 return t() + z();
225}
226
227inline double HepLorentzVector::minus() const {
228 return t() - z();
229}
230
231inline HepLorentzVector & HepLorentzVector::boost(const Hep3Vector & b) {
232 return boost(b.x(), b.y(), b.z());
233}
234
235inline double HepLorentzVector::pseudoRapidity() const {
236 return pp.pseudoRapidity();
237}
238
239inline double HepLorentzVector::eta() const {
240 return pp.pseudoRapidity();
241}
242
243inline double HepLorentzVector::eta( const Hep3Vector & ref ) const {
244 return pp.eta( ref );
245}
246
247inline HepLorentzVector &
248HepLorentzVector::operator *= (const HepRotation & m) {
249 pp.transform(m);
250 return *this;
251}
252
253inline HepLorentzVector &
254HepLorentzVector::transform(const HepRotation & m) {
255 pp.transform(m);
256 return *this;
257}
258
259inline HepLorentzVector operator * (const HepLorentzVector & p, double a) {
260 return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
261}
262
263inline HepLorentzVector operator * (double a, const HepLorentzVector & p) {
264 return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
265}
266
267// The following were added when ZOOM PhysicsVectors was merged in:
268
269inline HepLorentzVector::HepLorentzVector(
270 double x, double y, double z, Tcomponent t ) :
271 pp(x, y, z), ee(t) {}
272
273inline void HepLorentzVector::set(
274 double x, double y, double z, Tcomponent t ) {
275 pp.set(x,y,z);
276 ee = t;
277}
278
279inline void HepLorentzVector::set(
280 double x, double y, double z, double t ) {
281 set (x,y,z,Tcomponent(t));
282}
283
284inline HepLorentzVector::HepLorentzVector(
285 Tcomponent t, double x, double y, double z ) :
286 pp(x, y, z), ee(t) {}
287
288inline void HepLorentzVector::set(
289 Tcomponent t, double x, double y, double z ) {
290 pp.set(x,y,z);
291 ee = t;
292}
293
294inline void HepLorentzVector::set( Tcomponent t ) {
295 pp.set(0, 0, 0);
296 ee = t;
297}
298
299inline void HepLorentzVector::set( double t ) {
300 pp.set(0, 0, 0);
301 ee = t;
302}
303
304inline HepLorentzVector::HepLorentzVector( Tcomponent t ) :
305 pp(0, 0, 0), ee(t) {}
306
307inline void HepLorentzVector::set( const Hep3Vector & v ) {
308 pp = v;
309 ee = 0;
310}
311
312inline HepLorentzVector::HepLorentzVector( const Hep3Vector & v ) :
313 pp(v), ee(0) {}
314
315inline void HepLorentzVector::setV(const Hep3Vector & v) {
316 pp = v;
317}
318
319inline HepLorentzVector & HepLorentzVector::operator=(const Hep3Vector & v) {
320 pp = v;
321 ee = 0;
322 return *this;
323}
324
325inline double HepLorentzVector::getX() const { return pp.x(); }
326inline double HepLorentzVector::getY() const { return pp.y(); }
327inline double HepLorentzVector::getZ() const { return pp.z(); }
328inline double HepLorentzVector::getT() const { return ee; }
329
330inline Hep3Vector HepLorentzVector::getV() const { return pp; }
331inline Hep3Vector HepLorentzVector::v() const { return pp; }
332
333inline void HepLorentzVector::set(double t, const Hep3Vector & v) {
334 pp = v;
335 ee = t;
336}
337
338inline void HepLorentzVector::set(const Hep3Vector & v, double t) {
339 pp = v;
340 ee = t;
341}
342
343inline void HepLorentzVector::setV( double x,
344 double y,
345 double z ) { pp.set(x, y, z); }
346
347inline void HepLorentzVector::setRThetaPhi
348 ( double r, double theta, double phi )
349 { pp.setRThetaPhi( r, theta, phi ); }
350
351inline void HepLorentzVector::setREtaPhi
352 ( double r, double eta, double phi )
353 { pp.setREtaPhi( r, eta, phi ); }
354
355inline void HepLorentzVector::setRhoPhiZ
356 ( double rho, double phi, double z )
357 { pp.setRhoPhiZ ( rho, phi, z ); }
358
359inline bool HepLorentzVector::isTimelike() const {
360 return restMass2() > 0;
361}
362
363inline bool HepLorentzVector::isSpacelike() const {
364 return restMass2() < 0;
365}
366
367inline bool HepLorentzVector::isLightlike(double epsilon) const {
368 return std::fabs(restMass2()) < 2.0 * epsilon * ee * ee;
369}
370
371inline double HepLorentzVector::diff2( const HepLorentzVector & w ) const {
372#if defined USING_VISUAL
373 // kludge for problem building Windows DLL
374 double r= metric*( (ee-w.ee)*(ee-w.ee) - (pp-w.pp).mag2() );
375 return r;
376#else
377 return metric*( (ee-w.ee)*(ee-w.ee) - (pp-w.pp).mag2() );
378#endif
379}
380
381inline double HepLorentzVector::delta2Euclidean
382 ( const HepLorentzVector & w ) const {
383 return (ee-w.ee)*(ee-w.ee) + (pp-w.pp).mag2();
384}
385
386inline double HepLorentzVector::euclideanNorm2() const {
387 return ee*ee + pp.mag2();
388}
389
390inline double HepLorentzVector::euclideanNorm() const {
391 return std::sqrt(euclideanNorm2());
392}
393
394inline double HepLorentzVector::restMass2() const { return m2(); }
395inline double HepLorentzVector::invariantMass2() const { return m2(); }
396
397inline double HepLorentzVector::restMass() const {
398 if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
399 "E^2-p^2 < 0 for this particle. Magnitude returned."));
400 return t() < 0.0 ? -m() : m();
401}
402
403inline double HepLorentzVector::invariantMass() const {
404 if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
405 "E^2-p^2 < 0 for this particle. Magnitude returned."));
406 return t() < 0.0 ? -m() : m();
407}
408
409inline double HepLorentzVector::invariantMass2
410 (const HepLorentzVector & w) const {
411 return (*this + w).m2();
412} /* invariantMass2 */
413
414//-*********
415// boostOf()
416//-*********
417
418// Each of these is a shell over a boost method.
419
420inline HepLorentzVector boostXOf
421 (const HepLorentzVector & vec, double beta) {
422 HepLorentzVector vv (vec);
423 return vv.boostX (beta);
424}
425
426inline HepLorentzVector boostYOf
427 (const HepLorentzVector & vec, double beta) {
428 HepLorentzVector vv (vec);
429 return vv.boostY (beta);
430}
431
432inline HepLorentzVector boostZOf
433 (const HepLorentzVector & vec, double beta) {
434 HepLorentzVector vv (vec);
435 return vv.boostZ (beta);
436}
437
438inline HepLorentzVector boostOf
439 (const HepLorentzVector & vec, const Hep3Vector & betaVector ) {
440 HepLorentzVector vv (vec);
441 return vv.boost (betaVector);
442}
443
444inline HepLorentzVector boostOf
445 (const HepLorentzVector & vec, const Hep3Vector & axis, double beta) {
446 HepLorentzVector vv (vec);
447 return vv.boost (axis, beta);
448}
449
450} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.