ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LorentzVector.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file LorentzVector.h
1 // -*- C++ -*-
2 // CLASSDOC OFF
3 // ---------------------------------------------------------------------------
4 // CLASSDOC ON
5 //
6 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
7 //
8 // HepLorentzVector is a Lorentz vector consisting of Hep3Vector and
9 // double components. Lorentz transformations (rotations and boosts)
10 // of these vectors are perfomed by multiplying with objects of
11 // the HepLorenzRotation class.
12 //
13 // .SS See Also
14 // ThreeVector.h, Rotation.h, LorentzRotation.h
15 //
16 // .SS Authors
17 // Leif Lonnblad and Anders Nilsson. Modified by Evgueni Tcherniaev, Mark Fischler
18 //
19 
20 #ifndef HEP_LORENTZVECTOR_H
21 #define HEP_LORENTZVECTOR_H
22 
23 #ifdef GNUPRAGMA
24 #pragma interface
25 #endif
26 
27 #include <iostream>
29 
30 namespace CLHEP {
31 
32 // Declarations of classes and global methods
33 class HepLorentzVector;
34 class HepLorentzRotation;
35 class HepRotation;
36 class HepAxisAngle;
37 class HepEulerAngles;
38 class Tcomponent;
39 HepLorentzVector rotationXOf( const HepLorentzVector & vec, double delta );
40 HepLorentzVector rotationYOf( const HepLorentzVector & vec, double delta );
41 HepLorentzVector rotationZOf( const HepLorentzVector & vec, double delta );
42 HepLorentzVector rotationOf
43  ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
44 HepLorentzVector rotationOf
45  ( const HepLorentzVector & vec, const HepAxisAngle & ax );
46 HepLorentzVector rotationOf
47  ( const HepLorentzVector & vec, const HepEulerAngles & e );
48 HepLorentzVector rotationOf
49  ( const HepLorentzVector & vec, double phi,
50  double theta,
51  double psi );
52 inline
53 HepLorentzVector boostXOf( const HepLorentzVector & vec, double beta );
54 inline
55 HepLorentzVector boostYOf( const HepLorentzVector & vec, double beta );
56 inline
57 HepLorentzVector boostZOf( const HepLorentzVector & vec, double beta );
58 inline HepLorentzVector boostOf
59  ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
60 inline HepLorentzVector boostOf
61  ( const HepLorentzVector & vec, const Hep3Vector & axis, double beta );
62 
64 
65 
72 
73 public:
74 
75  enum { X=0, Y=1, Z=2, T=3, NUM_COORDINATES=4, SIZE=NUM_COORDINATES };
76  // Safe indexing of the coordinates when using with matrices, arrays, etc.
77  // (BaBar)
78 
79  inline HepLorentzVector(double x, double y,
80  double z, double t);
81  // Constructor giving the components x, y, z, t.
82 
83  inline HepLorentzVector(double x, double y, double z);
84  // Constructor giving the components x, y, z with t-component set to 0.0.
85 
86  explicit HepLorentzVector(double t);
87  // Constructor giving the t-component with x, y and z set to 0.0.
88 
89  inline HepLorentzVector();
90  // Default constructor with x, y, z and t set to 0.0.
91 
92  inline HepLorentzVector(const Hep3Vector & p, double e);
93  inline HepLorentzVector(double e, const Hep3Vector & p);
94  // Constructor giving a 3-Vector and a time component.
95 
96  inline HepLorentzVector(const HepLorentzVector &);
97  inline HepLorentzVector(HepLorentzVector &&) = default;
98  // Copy and move constructors.
99 
100  inline ~HepLorentzVector();
101  // The destructor.
102 
103  inline operator const Hep3Vector & () const;
104  inline operator Hep3Vector & ();
105  // Conversion (cast) to Hep3Vector.
106 
107  inline double x() const;
108  inline double y() const;
109  inline double z() const;
110  inline double t() const;
111  // Get position and time.
112 
113  inline void setX(double);
114  inline void setY(double);
115  inline void setZ(double);
116  inline void setT(double);
117  // Set position and time.
118 
119  inline double px() const;
120  inline double py() const;
121  inline double pz() const;
122  inline double e() const;
123  // Get momentum and energy.
124 
125  inline void setPx(double);
126  inline void setPy(double);
127  inline void setPz(double);
128  inline void setE(double);
129  // Set momentum and energy.
130 
131  inline Hep3Vector vect() const;
132  // Get spatial component.
133 
134  inline void setVect(const Hep3Vector &);
135  // Set spatial component.
136 
137  inline double theta() const;
138  inline double cosTheta() const;
139  inline double phi() const;
140  inline double rho() const;
141  // Get spatial vector components in spherical coordinate system.
142 
143  inline void setTheta(double);
144  inline void setPhi(double);
145  inline void setRho(double);
146  // Set spatial vector components in spherical coordinate system.
147 
148  double operator () (int) const;
149  inline double operator [] (int) const;
150  // Get components by index.
151 
152  double & operator () (int);
153  inline double & operator [] (int);
154  // Set components by index.
155 
157  inline HepLorentzVector & operator = (HepLorentzVector &&) = default;
158  // Copy and move assignment operators.
159 
160  inline HepLorentzVector operator + (const HepLorentzVector &) const;
162  // Additions.
163 
164  inline HepLorentzVector operator - (const HepLorentzVector &) const;
166  // Subtractions.
167 
168  inline HepLorentzVector operator - () const;
169  // Unary minus.
170 
171  inline HepLorentzVector & operator *= (double);
172  HepLorentzVector & operator /= (double);
173  // Scaling with real numbers.
174 
175  inline bool operator == (const HepLorentzVector &) const;
176  inline bool operator != (const HepLorentzVector &) const;
177  // Comparisons.
178 
179  inline double perp2() const;
180  // Transverse component of the spatial vector squared.
181 
182  inline double perp() const;
183  // Transverse component of the spatial vector (R in cylindrical system).
184 
185  inline void setPerp(double);
186  // Set the transverse component of the spatial vector.
187 
188  inline double perp2(const Hep3Vector &) const;
189  // Transverse component of the spatial vector w.r.t. given axis squared.
190 
191  inline double perp(const Hep3Vector &) const;
192  // Transverse component of the spatial vector w.r.t. given axis.
193 
194  inline double angle(const Hep3Vector &) const;
195  // Angle wrt. another vector.
196 
197  inline double mag2() const;
198  // Dot product of 4-vector with itself.
199  // By default the metric is TimePositive, and mag2() is the same as m2().
200 
201  inline double m2() const;
202  // Invariant mass squared.
203 
204  inline double mag() const;
205  inline double m() const;
206  // Invariant mass. If m2() is negative then -sqrt(-m2()) is returned.
207 
208  inline double mt2() const;
209  // Transverse mass squared.
210 
211  inline double mt() const;
212  // Transverse mass.
213 
214  inline double et2() const;
215  // Transverse energy squared.
216 
217  inline double et() const;
218  // Transverse energy.
219 
220  inline double dot(const HepLorentzVector &) const;
221  inline double operator * (const HepLorentzVector &) const;
222  // Scalar product.
223 
224  inline double invariantMass2( const HepLorentzVector & w ) const;
225  // Invariant mass squared of pair of 4-vectors
226 
227  double invariantMass ( const HepLorentzVector & w ) const;
228  // Invariant mass of pair of 4-vectors
229 
230  inline void setVectMag(const Hep3Vector & spatial, double magnitude);
231  inline void setVectM(const Hep3Vector & spatial, double mass);
232  // Copy spatial coordinates, and set energy = sqrt(mass^2 + spatial^2)
233 
234  inline double plus() const;
235  inline double minus() const;
236  // Returns the positive/negative light-cone component t +/- z.
237 
238  Hep3Vector boostVector() const;
239  // Boost needed from rest4Vector in rest frame to form this 4-vector
240  // Returns the spatial components divided by the time component.
241 
242  HepLorentzVector & boost(double, double, double);
243  inline HepLorentzVector & boost(const Hep3Vector &);
244  // Lorentz boost.
245 
246  HepLorentzVector & boostX( double beta );
247  HepLorentzVector & boostY( double beta );
248  HepLorentzVector & boostZ( double beta );
249  // Boost along an axis, by magnitue beta (fraction of speed of light)
250 
251  double rapidity() const;
252  // Returns the rapidity, i.e. 0.5*ln((E+pz)/(E-pz))
253 
254  inline double pseudoRapidity() const;
255  // Returns the pseudo-rapidity, i.e. -ln(tan(theta/2))
256 
257  inline bool isTimelike() const;
258  // Test if the 4-vector is timelike
259 
260  inline bool isSpacelike() const;
261  // Test if the 4-vector is spacelike
262 
263  inline bool isLightlike(double epsilon=tolerance) const;
264  // Test for lightlike is within tolerance epsilon
265 
266  HepLorentzVector & rotateX(double);
267  // Rotate the spatial component around the x-axis.
268 
269  HepLorentzVector & rotateY(double);
270  // Rotate the spatial component around the y-axis.
271 
272  HepLorentzVector & rotateZ(double);
273  // Rotate the spatial component around the z-axis.
274 
276  // Rotates the reference frame from Uz to newUz (unit vector).
277 
278  HepLorentzVector & rotate(double, const Hep3Vector &);
279  // Rotate the spatial component around specified axis.
280 
281  inline HepLorentzVector & operator *= (const HepRotation &);
282  inline HepLorentzVector & transform(const HepRotation &);
283  // Transformation with HepRotation.
284 
287  // Transformation with HepLorenzRotation.
288 
289 // = = = = = = = = = = = = = = = = = = = = = = = =
290 //
291 // Esoteric properties and operations on 4-vectors:
292 //
293 // 0 - Flexible metric convention and axial unit 4-vectors
294 // 1 - Construct and set 4-vectors in various ways
295 // 2 - Synonyms for accessing coordinates and properties
296 // 2a - Setting space coordinates in different ways
297 // 3 - Comparisions (dictionary, near-ness, and geometric)
298 // 4 - Intrinsic properties
299 // 4a - Releativistic kinematic properties
300 // 4b - Methods combining two 4-vectors
301 // 5 - Properties releative to z axis and to arbitrary directions
302 // 7 - Rotations and Boosts
303 //
304 // = = = = = = = = = = = = = = = = = = = = = = = =
305 
306 // 0 - Flexible metric convention
307 
308  static ZMpvMetric_t setMetric( ZMpvMetric_t met );
309  static ZMpvMetric_t getMetric();
310 
311 // 1 - Construct and set 4-vectors in various ways
312 
313  inline void set (double x, double y, double z, double t);
314  inline void set (double x, double y, double z, Tcomponent t);
315  inline HepLorentzVector(double x, double y, double z, Tcomponent t);
316  // Form 4-vector by supplying cartesian coordinate components
317 
318  inline void set (Tcomponent t, double x, double y, double z);
319  inline HepLorentzVector(Tcomponent t, double x, double y, double z);
320  // Deprecated because the 4-doubles form uses x,y,z,t, not t,x,y,z.
321 
322  inline void set ( double t );
323 
324  inline void set ( Tcomponent t );
325  inline explicit HepLorentzVector( Tcomponent t );
326  // Form 4-vector with zero space components, by supplying t component
327 
328  inline void set ( const Hep3Vector & v );
329  inline explicit HepLorentzVector( const Hep3Vector & v );
330  // Form 4-vector with zero time component, by supplying space 3-vector
331 
332  inline HepLorentzVector & operator=( const Hep3Vector & v );
333  // Form 4-vector with zero time component, equal to space 3-vector
334 
335  inline void set ( const Hep3Vector & v, double t );
336  inline void set ( double t, const Hep3Vector & v );
337  // Set using specified space vector and time component
338 
339 // 2 - Synonyms for accessing coordinates and properties
340 
341  inline double getX() const;
342  inline double getY() const;
343  inline double getZ() const;
344  inline double getT() const;
345  // Get position and time.
346 
347  inline Hep3Vector v() const;
348  inline Hep3Vector getV() const;
349  // Get spatial component. Same as vect.
350 
351  inline void setV(const Hep3Vector &);
352  // Set spatial component. Same as setVect.
353 
354 // 2a - Setting space coordinates in different ways
355 
356  inline void setV( double x, double y, double z );
357 
358  inline void setRThetaPhi( double r, double theta, double phi);
359  inline void setREtaPhi( double r, double eta, double phi);
360  inline void setRhoPhiZ( double rho, double phi, double z );
361 
362 // 3 - Comparisions (dictionary, near-ness, and geometric)
363 
364  int compare( const HepLorentzVector & w ) const;
365 
366  bool operator >( const HepLorentzVector & w ) const;
367  bool operator <( const HepLorentzVector & w ) const;
368  bool operator>=( const HepLorentzVector & w ) const;
369  bool operator<=( const HepLorentzVector & w ) const;
370 
371  bool isNear ( const HepLorentzVector & w,
372  double epsilon=tolerance ) const;
373  double howNear( const HepLorentzVector & w ) const;
374  // Is near using Euclidean measure t**2 + v**2
375 
376  bool isNearCM ( const HepLorentzVector & w,
377  double epsilon=tolerance ) const;
378  double howNearCM( const HepLorentzVector & w ) const;
379  // Is near in CM frame: Applicable only for two timelike HepLorentzVectors
380 
381  // If w1 and w2 are already in their CM frame, then w1.isNearCM(w2)
382  // is exactly equivalent to w1.isNear(w2).
383  // If w1 and w2 have T components of zero, w1.isNear(w2) is exactly
384  // equivalent to w1.getV().isNear(w2.v()).
385 
386  bool isParallel( const HepLorentzVector & w,
387  double epsilon=tolerance ) const;
388  // Test for isParallel is within tolerance epsilon
389  double howParallel (const HepLorentzVector & w) const;
390 
391  static double getTolerance();
392  static double setTolerance( double tol );
393  // Set the tolerance for HepLorentzVectors to be considered near
394  // The same tolerance is used for determining isLightlike, and isParallel
395 
396  double deltaR(const HepLorentzVector & v) const;
397  // sqrt ( (delta eta)^2 + (delta phi)^2 ) of space part
398 
399 // 4 - Intrinsic properties
400 
401  double howLightlike() const;
402  // Close to zero for almost lightlike 4-vectors; up to 1.
403 
404  inline double euclideanNorm2() const;
405  // Sum of the squares of time and space components; not Lorentz invariant.
406 
407  inline double euclideanNorm() const;
408  // Length considering the metric as (+ + + +); not Lorentz invariant.
409 
410 
411 // 4a - Relativistic kinematic properties
412 
413 // All Relativistic kinematic properties are independent of the sense of metric
414 
415  inline double restMass2() const;
416  inline double invariantMass2() const;
417  // Rest mass squared -- same as m2()
418 
419  inline double restMass() const;
420  inline double invariantMass() const;
421  // Same as m(). If m2() is negative then -sqrt(-m2()) is returned.
422 
423 // The following properties are rest-frame related,
424 // and are applicable only to non-spacelike 4-vectors
425 
427  // This 4-vector, boosted into its own rest frame: (0, 0, 0, m())
428  // The following relation holds by definition:
429  // w.rest4Vector().boost(w.boostVector()) == w
430 
431  // Beta and gamma of the boost vector
432  double beta() const;
433  // Relativistic beta of the boost vector
434 
435  double gamma() const;
436  // Relativistic gamma of the boost vector
437 
438  inline double eta() const;
439  // Pseudorapidity (of the space part)
440 
441  inline double eta(const Hep3Vector & ref) const;
442  // Pseudorapidity (of the space part) w.r.t. specified direction
443 
444  double rapidity(const Hep3Vector & ref) const;
445  // Rapidity in specified direction
446 
447  double coLinearRapidity() const;
448  // Rapidity, in the relativity textbook sense: atanh (|P|/E)
449 
450  Hep3Vector findBoostToCM() const;
451  // Boost needed to get to center-of-mass frame:
452  // w.findBoostToCM() == - w.boostVector()
453  // w.boost(w.findBoostToCM()) == w.rest4Vector()
454 
455  Hep3Vector findBoostToCM( const HepLorentzVector & w ) const;
456  // Boost needed to get to combined center-of-mass frame:
457  // w1.findBoostToCM(w2) == w2.findBoostToCM(w1)
458  // w.findBoostToCM(w) == w.findBoostToCM()
459 
460  inline double et2(const Hep3Vector &) const;
461  // Transverse energy w.r.t. given axis squared.
462 
463  inline double et(const Hep3Vector &) const;
464  // Transverse energy w.r.t. given axis.
465 
466 // 4b - Methods combining two 4-vectors
467 
468  inline double diff2( const HepLorentzVector & w ) const;
469  // (this - w).dot(this-w); sign depends on metric choice
470 
471  inline double delta2Euclidean ( const HepLorentzVector & w ) const;
472  // Euclidean norm of differnce: (delta_T)^2 + (delta_V)^2
473 
474 // 5 - Properties releative to z axis and to arbitrary directions
475 
476  double plus( const Hep3Vector & ref ) const;
477  // t + projection in reference direction
478 
479  double minus( const Hep3Vector & ref ) const;
480  // t - projection in reference direction
481 
482 // 7 - Rotations and boosts
483 
484  HepLorentzVector & rotate ( const Hep3Vector & axis, double delta );
485  // Same as rotate (delta, axis)
486 
487  HepLorentzVector & rotate ( const HepAxisAngle & ax );
488  HepLorentzVector & rotate ( const HepEulerAngles & e );
489  HepLorentzVector & rotate ( double phi,
490  double theta,
491  double psi );
492  // Rotate using these HepEuler angles - see Goldstein page 107 for conventions
493 
494  HepLorentzVector & boost ( const Hep3Vector & axis, double beta );
495  // Normalizes the Hep3Vector to define a direction, and uses beta to
496  // define the magnitude of the boost.
497 
499  ( const HepLorentzVector & vec, double delta );
501  ( const HepLorentzVector & vec, double delta );
503  ( const HepLorentzVector & vec, double delta );
505  ( const HepLorentzVector & vec, const Hep3Vector & axis, double delta );
507  ( const HepLorentzVector & vec, const HepAxisAngle & ax );
509  ( const HepLorentzVector & vec, const HepEulerAngles & e );
511  ( const HepLorentzVector & vec, double phi,
512  double theta,
513  double psi );
514 
515  inline friend HepLorentzVector boostXOf
516  ( const HepLorentzVector & vec, double beta );
517  inline friend HepLorentzVector boostYOf
518  ( const HepLorentzVector & vec, double beta );
519  inline friend HepLorentzVector boostZOf
520  ( const HepLorentzVector & vec, double beta );
521  inline friend HepLorentzVector boostOf
522  ( const HepLorentzVector & vec, const Hep3Vector & betaVector );
523  inline friend HepLorentzVector boostOf
524  ( const HepLorentzVector & vec, const Hep3Vector & axis, double beta );
525 
526 private:
527 
529  double ee;
530 
531  DLL_API static double tolerance;
532  DLL_API static double metric;
533 
534 }; // HepLorentzVector
535 
536 // 8 - Axial Unit 4-vectors
537 
538 static const HepLorentzVector X_HAT4 = HepLorentzVector( 1, 0, 0, 0 );
539 static const HepLorentzVector Y_HAT4 = HepLorentzVector( 0, 1, 0, 0 );
540 static const HepLorentzVector Z_HAT4 = HepLorentzVector( 0, 0, 1, 0 );
541 static const HepLorentzVector T_HAT4 = HepLorentzVector( 0, 0, 0, 1 );
542 
543 // Global methods
544 
545 std::ostream & operator << (std::ostream &, const HepLorentzVector &);
546 // Output to a stream.
547 
548 std::istream & operator >> (std::istream &, HepLorentzVector &);
549 // Input from a stream.
550 
553 
554 inline HepLorentzVector operator * (const HepLorentzVector &, double a);
555 inline HepLorentzVector operator * (double a, const HepLorentzVector &);
556 // Scaling LorentzVector with a real number
557 
559 // Dividing LorentzVector by a real number
560 
561 // Tcomponent definition:
562 
563 // Signature protection for 4-vector constructors taking 4 components
564 class Tcomponent {
565 private:
566  double t_;
567 public:
568  explicit Tcomponent(double t) : t_(t) {}
569  operator double() const { return t_; }
570 }; // Tcomponent
571 
572 } // namespace CLHEP
573 
574 #include "CLHEP/Vector/LorentzVector.icc"
575 
576 #endif /* HEP_LORENTZVECTOR_H */