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