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