CLHEP 2.4.7.1
C++ Class Library for High Energy Physics
LorentzVector.icc
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: LorentzVector.icc,v 1.3 2010/06/16 17:15:57 garren 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
23HepLorentzVector(double x1, double y1, double z1, double t1)
24 : pp(x1, y1, z1), ee(t1) {}
25
26inline HepLorentzVector:: HepLorentzVector(double x1, double y1, double z1)
27 : pp(x1, y1, z1), ee(0) {}
28
30 : pp(0, 0, 0), ee(t1) {}
31
33 : pp(0, 0, 0), ee(0) {}
34
36 : pp(p), ee(e1) {}
37
39 : pp(p), ee(e1) {}
40
42 : pp(p.x(), p.y(), p.z()), ee(p.t()) {}
43
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 &
81 pp = q.vect();
82 ee = q.t();
83 return *this;
84}
85
88 return HepLorentzVector(x()+q.x(), y()+q.y(), z()+q.z(), t()+q.t());
89}
90
91inline HepLorentzVector &
93 pp += q.vect();
94 ee += q.t();
95 return *this;
96}
97
100 return HepLorentzVector(x()-q.x(), y()-q.y(), z()-q.z(), t()-q.t());
101}
102
103inline HepLorentzVector &
105 pp -= q.vect();
106 ee -= q.t();
107 return *this;
108}
109
111 return HepLorentzVector(-x(), -y(), -z(), -t());
112}
113
115 pp *= a;
116 ee *= a;
117 return *this;
118}
119
120inline bool
122 return (vect()==q.vect() && t()==q.t());
123}
124
125inline bool
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 &v1) const {
135 return pp.perp2(v1);
136}
137
138inline double HepLorentzVector::perp(const Hep3Vector &v1) const {
139 return pp.perp(v1);
140}
141
142inline double HepLorentzVector::angle(const Hep3Vector &v1) const {
143 return pp.angle(v1);
144}
145
146inline double HepLorentzVector::mag2() const {
147 return metric*(t()*t() - pp.mag2());
148}
149
150inline double HepLorentzVector::mag() const {
151 double mmm = m2();
152 return mmm < 0.0 ? -std::sqrt(-mmm) : std::sqrt(mmm);
153}
154
155inline double HepLorentzVector::m2() const {
156 return t()*t() - pp.mag2();
157}
158
159inline double HepLorentzVector::m() const { return mag(); }
160
161inline double HepLorentzVector::mt2() const {
162 return e()*e() - pz()*pz();
163}
164
165inline double HepLorentzVector::mt() const {
166 double mmm = mt2();
167 return mmm < 0.0 ? -std::sqrt(-mmm) : std::sqrt(mmm);
168}
169
170inline double HepLorentzVector::et2() const {
171 double pt2 = pp.perp2();
172 return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+z()*z());
173}
174
175inline double HepLorentzVector::et() const {
176 double etet = et2();
177 return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
178}
179
180inline double HepLorentzVector::et2(const Hep3Vector & v1) const {
181 double pt2 = pp.perp2(v1);
182 double pv = pp.dot(v1.unit());
183 return pt2 == 0 ? 0 : e()*e() * pt2/(pt2+pv*pv);
184}
185
186inline double HepLorentzVector::et(const Hep3Vector & v1) const {
187 double etet = et2(v1);
188 return e() < 0.0 ? -std::sqrt(etet) : std::sqrt(etet);
189}
190
191inline void
192HepLorentzVector::setVectMag(const Hep3Vector & spatial, double magnitude) {
193 setVect(spatial);
194 setT(std::sqrt(magnitude * magnitude + spatial * spatial));
195}
196
197inline void
198HepLorentzVector::setVectM(const Hep3Vector & spatial, double mass) {
199 setVectMag(spatial, mass);
200}
201
202inline double HepLorentzVector::dot(const HepLorentzVector & q) const {
203 return metric*(t()*q.t() - z()*q.z() - y()*q.y() - x()*q.x());
204}
205
206inline double
208 return dot(q);
209}
210
211inline double HepLorentzVector::plus() const {
212 return t() + z();
213}
214
215inline double HepLorentzVector::minus() const {
216 return t() - z();
217}
218
220 return boost(b.x(), b.y(), b.z());
221}
222
223inline double HepLorentzVector::pseudoRapidity() const {
224 return pp.pseudoRapidity();
225}
226
227inline double HepLorentzVector::eta() const {
228 return pp.pseudoRapidity();
229}
230
231inline double HepLorentzVector::eta( const Hep3Vector & ref ) const {
232 return pp.eta( ref );
233}
234
235inline HepLorentzVector &
237 pp.transform(m1);
238 return *this;
239}
240
241inline HepLorentzVector &
243 pp.transform(m1);
244 return *this;
245}
246
247inline HepLorentzVector operator * (const HepLorentzVector & p, double a) {
248 return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
249}
250
251inline HepLorentzVector operator * (double a, const HepLorentzVector & p) {
252 return HepLorentzVector(a*p.x(), a*p.y(), a*p.z(), a*p.t());
253}
254
255// The following were added when ZOOM PhysicsVectors was merged in:
256
258 double x1, double y1, double z1, Tcomponent t1 ) :
259 pp(x1, y1, z1), ee(t1) {}
260
262 double x1, double y1, double z1, Tcomponent t1 ) {
263 pp.set(x1,y1,z1);
264 ee = t1;
265}
266
268 double x1, double y1, double z1, double t1 ) {
269 set (x1,y1,z1,Tcomponent(t1));
270}
271
273 Tcomponent t1, double x1, double y1, double z1 ) :
274 pp(x1, y1, z1), ee(t1) {}
275
277 Tcomponent t1, double x1, double y1, double z1 ) {
278 pp.set(x1,y1,z1);
279 ee = t1;
280}
281
283 pp.set(0, 0, 0);
284 ee = t1;
285}
286
287inline void HepLorentzVector::set( double t1 ) {
288 pp.set(0, 0, 0);
289 ee = t1;
290}
291
293 pp(0, 0, 0), ee(t1) {}
294
295inline void HepLorentzVector::set( const Hep3Vector & v1 ) {
296 pp = v1;
297 ee = 0;
298}
299
301 pp(v1), ee(0) {}
302
303inline void HepLorentzVector::setV(const Hep3Vector & v1) {
304 pp = v1;
305}
306
308 pp = v1;
309 ee = 0;
310 return *this;
311}
312
313inline double HepLorentzVector::getX() const { return pp.x(); }
314inline double HepLorentzVector::getY() const { return pp.y(); }
315inline double HepLorentzVector::getZ() const { return pp.z(); }
316inline double HepLorentzVector::getT() const { return ee; }
317
318inline Hep3Vector HepLorentzVector::getV() const { return pp; }
319inline Hep3Vector HepLorentzVector::v() const { return pp; }
320
321inline void HepLorentzVector::set(double t1, const Hep3Vector & v1) {
322 pp = v1;
323 ee = t1;
324}
325
326inline void HepLorentzVector::set(const Hep3Vector & v1, double t1) {
327 pp = v1;
328 ee = t1;
329}
330
331inline void HepLorentzVector::setV( double x1,
332 double y1,
333 double z1 ) { pp.set(x1, y1, z1); }
334
336 ( double r, double ttheta, double phi1 )
337 { pp.setRThetaPhi( r, ttheta, phi1 ); }
338
340 ( double r, double eta1, double phi1 )
341 { pp.setREtaPhi( r, eta1, phi1 ); }
342
344 ( double rho1, double phi1, double z1 )
345 { pp.setRhoPhiZ ( rho1, phi1, z1 ); }
346
347inline bool HepLorentzVector::isTimelike() const {
348 return restMass2() > 0;
349}
350
351inline bool HepLorentzVector::isSpacelike() const {
352 return restMass2() < 0;
353}
354
355inline bool HepLorentzVector::isLightlike(double epsilon) const {
356 return std::fabs(restMass2()) < 2.0 * epsilon * ee * ee;
357}
358
359inline double HepLorentzVector::diff2( const HepLorentzVector & w ) const {
360 return metric*( (ee-w.ee)*(ee-w.ee) - (pp-w.pp).mag2() );
361}
362
364 ( const HepLorentzVector & w ) const {
365 return (ee-w.ee)*(ee-w.ee) + (pp-w.pp).mag2();
366}
367
368inline double HepLorentzVector::euclideanNorm2() const {
369 return ee*ee + pp.mag2();
370}
371
372inline double HepLorentzVector::euclideanNorm() const {
373 return std::sqrt(euclideanNorm2());
374}
375
376inline double HepLorentzVector::restMass2() const { return m2(); }
377inline double HepLorentzVector::invariantMass2() const { return m2(); }
378
379inline double HepLorentzVector::restMass() const {
380 if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
381 "E^2-p^2 < 0 for this particle. Magnitude returned."));
382 return t() < 0.0 ? -m() : m();
383}
384
385inline double HepLorentzVector::invariantMass() const {
386 if( t() < 0.0 ) ZMthrowC(ZMxpvNegativeMass(
387 "E^2-p^2 < 0 for this particle. Magnitude returned."));
388 return t() < 0.0 ? -m() : m();
389}
390
392 (const HepLorentzVector & w) const {
393 return (*this + w).m2();
394} /* invariantMass2 */
395
396//-*********
397// boostOf()
398//-*********
399
400// Each of these is a shell over a boost method.
401
403 (const HepLorentzVector & vec, double bbeta) {
404 HepLorentzVector vv (vec);
405 return vv.boostX (bbeta);
406}
407
409 (const HepLorentzVector & vec, double bbeta) {
410 HepLorentzVector vv (vec);
411 return vv.boostY (bbeta);
412}
413
415 (const HepLorentzVector & vec, double bbeta) {
416 HepLorentzVector vv (vec);
417 return vv.boostZ (bbeta);
418}
419
421 (const HepLorentzVector & vec, const Hep3Vector & betaVector ) {
422 HepLorentzVector vv (vec);
423 return vv.boost (betaVector);
424}
425
427 (const HepLorentzVector & vec, const Hep3Vector & aaxis, double bbeta) {
428 HepLorentzVector vv (vec);
429 return vv.boost (aaxis, bbeta);
430}
431
432} // namespace CLHEP
#define ZMthrowC(A)
Definition ZMxpv.h:133
double z() const
Hep3Vector unit() const
double eta() const
double phi() const
void setPerp(double)
double theta() const
double x() const
void setY(double)
double mag2() const
double y() const
void setRhoPhiZ(double rho, double phi, double z)
void setRThetaPhi(double r, double theta, double phi)
double angle(const Hep3Vector &) const
double dot(const Hep3Vector &) const
double perp2() const
void setTheta(double)
void setZ(double)
double mag() const
double pseudoRapidity() const
Hep3Vector & transform(const HepRotation &)
void set(double x, double y, double z)
void setMag(double)
void setX(double)
void setREtaPhi(double r, double eta, double phi)
double cosTheta() const
void setPhi(double)
double perp() const
HepLorentzVector operator-() const
double pseudoRapidity() const
HepLorentzVector & boost(double, double, double)
bool operator!=(const HepLorentzVector &) const
HepLorentzVector & boostZ(double beta)
Hep3Vector getV() const
bool operator==(const HepLorentzVector &) const
void setVectM(const Hep3Vector &spatial, double mass)
double diff2(const HepLorentzVector &w) const
double dot(const HepLorentzVector &) const
Hep3Vector vect() const
HepLorentzVector & operator*=(double)
HepLorentzVector & boostX(double beta)
void set(double x, double y, double z, double t)
void setRThetaPhi(double r, double theta, double phi)
void setVectMag(const Hep3Vector &spatial, double magnitude)
HepLorentzVector & operator-=(const HepLorentzVector &)
HepLorentzVector operator+(const HepLorentzVector &) const
HepLorentzVector & boostY(double beta)
bool isLightlike(double epsilon=tolerance) const
void setV(const Hep3Vector &)
double operator[](int) const
double invariantMass2() const
HepLorentzVector & operator+=(const HepLorentzVector &)
double euclideanNorm2() const
void setVect(const Hep3Vector &)
void setREtaPhi(double r, double eta, double phi)
double delta2Euclidean(const HepLorentzVector &w) const
void setRhoPhiZ(double rho, double phi, double z)
double angle(const Hep3Vector &) const
HepLorentzVector & operator=(const HepLorentzVector &)
HepLorentzVector & transform(const HepRotation &)
double operator*(const HepLorentzVector &) const
HepLorentzVector boostOf(const HepLorentzVector &vec, const Hep3Vector &betaVector)
HepMatrix operator*(const HepMatrix &hm1, const HepDiagMatrix &hm2)
HepLorentzVector boostXOf(const HepLorentzVector &vec, double beta)
HepLorentzVector boostZOf(const HepLorentzVector &vec, double beta)
HepLorentzVector boostYOf(const HepLorentzVector &vec, double beta)