CLHEP/Vector/LorentzRotation.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // $Id: LorentzRotation.h,v 1.15 2003/10/10 19:25:24 mf Exp $
00004 // ---------------------------------------------------------------------------
00005 // CLASSDOC ON
00006 //
00007 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00008 //
00009 // This is the definition of the HepLorentzRotation class for performing 
00010 // Lorentz transformations (rotations and boosts) on objects of the
00011 // HepLorentzVector class.
00012 //
00013 // HepLorentzRotation is a concrete implementation of Hep4RotationInterface.
00014 //
00015 // .SS See Also
00016 // RotationInterfaces.h
00017 // ThreeVector.h, LorentzVector.h
00018 // Rotation.h, Boost.h
00019 //
00020 // .SS Author
00021 // Leif Lonnblad, Mark Fischler
00022 
00023 #ifndef HEP_LORENTZROTATION_H
00024 #define HEP_LORENTZROTATION_H
00025 
00026 #ifdef GNUPRAGMA
00027 #pragma interface
00028 #endif
00029 
00030 #ifdef HEP_NO_INLINE_IN_DECLARATION
00031 #define inline
00032 #endif
00033 
00034 #include "CLHEP/Vector/RotationInterfaces.h"
00035 #include "CLHEP/Vector/Rotation.h" 
00036 #include "CLHEP/Vector/Boost.h" 
00037 #include "CLHEP/Vector/LorentzVector.h"
00038 
00039 // Global methods
00040 
00041 inline HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
00042 HepLorentzRotation operator * (const HepRotation & r,
00043                                         const HepLorentzRotation & lt);
00044 HepLorentzRotation operator * (const HepRotationX & r,
00045                                         const HepLorentzRotation & lt);
00046 HepLorentzRotation operator * (const HepRotationY & r,
00047                                         const HepLorentzRotation & lt);
00048 HepLorentzRotation operator * (const HepRotationZ & r,
00049                                         const HepLorentzRotation & lt);
00050 
00055 class HepLorentzRotation {
00056 
00057 public:
00058   // ----------  Identity HepLorentzRotation:
00059 
00060   static const HepLorentzRotation IDENTITY;
00061 
00062   // ----------  Constructors and Assignment:
00063 
00064   inline HepLorentzRotation();
00065   // Default constructor. Gives a unit matrix.
00066 
00067   inline  HepLorentzRotation       (const HepLorentzRotation & r);
00068   // Copy constructor.
00069 
00070   inline           HepLorentzRotation (const HepRotation  & r);
00071   inline  explicit HepLorentzRotation (const HepRotationX & r);
00072   inline  explicit HepLorentzRotation (const HepRotationY & r);
00073   inline  explicit HepLorentzRotation (const HepRotationZ & r);
00074   inline           HepLorentzRotation (const HepBoost  &    b);
00075   inline  explicit HepLorentzRotation (const HepBoostX &    b);
00076   inline  explicit HepLorentzRotation (const HepBoostY &    b);
00077   inline  explicit HepLorentzRotation (const HepBoostZ &    b);
00078   // Constructors from special cases.  
00079 
00080   inline HepLorentzRotation & operator = (const HepLorentzRotation & m);
00081   inline HepLorentzRotation & operator = (const HepRotation        & m);
00082   inline HepLorentzRotation & operator = (const HepBoost           & m);
00083   // Assignment.
00084 
00085          HepLorentzRotation & set (double bx, double by, double bz);
00086   inline HepLorentzRotation & set (const Hep3Vector & p);
00087   inline HepLorentzRotation & set (const HepRotation  & r);
00088   inline HepLorentzRotation & set (const HepRotationX & r);
00089   inline HepLorentzRotation & set (const HepRotationY & r);
00090   inline HepLorentzRotation & set (const HepRotationZ & r);
00091   inline HepLorentzRotation & set (const HepBoost & boost);
00092   inline HepLorentzRotation & set (const HepBoostX & boost);
00093   inline HepLorentzRotation & set (const HepBoostY & boost);
00094   inline HepLorentzRotation & set (const HepBoostZ & boost);
00095   inline HepLorentzRotation (double bx, double by, double bz);
00096   inline HepLorentzRotation (const Hep3Vector & p);
00097   // Other Constructors giving a Lorentz-boost.
00098 
00099          HepLorentzRotation & set( const HepBoost & B, const HepRotation & R );
00100   inline HepLorentzRotation (      const HepBoost & B, const HepRotation & R );
00101   //   supply B and R:  T = B R:
00102 
00103          HepLorentzRotation & set( const HepRotation & R, const HepBoost & B );
00104   inline HepLorentzRotation (      const HepRotation & R, const HepBoost & B );
00105   //   supply R and B:  T = R B:
00106 
00107   HepLorentzRotation ( const HepLorentzVector & col1,
00108                        const HepLorentzVector & col2,
00109                        const HepLorentzVector & col3,
00110                        const HepLorentzVector & col4 );
00111   // Construct from four *orthosymplectic* LorentzVectors for the columns:
00112         // NOTE:
00113         //      This constructor, and the two set methods below,
00114         //      will check that the columns (or rows) form an orthosymplectic
00115         //      matrix, and will adjust values so that this relation is
00116         //      as exact as possible.
00117         //      Orthosymplectic means the dot product USING THE METRIC
00118         //      of two different coumns will be 0, and of a column with
00119         //      itself will be one. 
00120 
00121   HepLorentzRotation & set( const HepLorentzVector & col1,
00122                             const HepLorentzVector & col2,
00123                             const HepLorentzVector & col3,
00124                             const HepLorentzVector & col4 );
00125   //   supply four *orthosymplectic* HepLorentzVectors for the columns
00126 
00127   HepLorentzRotation & setRows( const HepLorentzVector & row1,
00128                                 const HepLorentzVector & row2,
00129                                 const HepLorentzVector & row3,
00130                                 const HepLorentzVector & row4 );
00131   //   supply four *orthosymplectic* HepLorentzVectors for the columns
00132 
00133   inline HepLorentzRotation & set( const HepRep4x4 & rep );
00134   inline HepLorentzRotation      ( const HepRep4x4 & rep );
00135   //   supply a HepRep4x4 structure (16 numbers)
00136   // WARNING:
00137   //            This constructor and set method will assume the
00138   //            HepRep4x4 supplied is in fact an orthosymplectic matrix.
00139   //            No checking or correction is done.  If you are
00140   //            not certain the matrix is orthosymplectic, break it
00141   //            into four HepLorentzVector columns and use the form
00142   //            HepLorentzRotation (col1, col2, col3, col4)
00143 
00144   // ----------  Accessors:
00145 
00146   inline double xx() const;
00147   inline double xy() const;
00148   inline double xz() const;
00149   inline double xt() const;
00150   inline double yx() const;
00151   inline double yy() const;
00152   inline double yz() const;
00153   inline double yt() const;
00154   inline double zx() const;
00155   inline double zy() const;
00156   inline double zz() const;
00157   inline double zt() const;
00158   inline double tx() const;
00159   inline double ty() const;
00160   inline double tz() const;
00161   inline double tt() const;
00162   // Elements of the matrix.
00163 
00164   inline HepLorentzVector col1() const;
00165   inline HepLorentzVector col2() const;
00166   inline HepLorentzVector col3() const;
00167   inline HepLorentzVector col4() const;
00168   // orthosymplectic column vectors
00169 
00170   inline HepLorentzVector row1() const;
00171   inline HepLorentzVector row2() const;
00172   inline HepLorentzVector row3() const;
00173   inline HepLorentzVector row4() const;
00174   // orthosymplectic row vectors
00175 
00176   inline HepRep4x4 rep4x4() const;
00177   //   4x4 representation:
00178 
00179   // ------------  Subscripting:
00180 
00181   class HepLorentzRotation_row {
00182   public:
00183     inline HepLorentzRotation_row(const HepLorentzRotation &, int);
00184     inline double operator [] (int) const;
00185   private:
00186     const HepLorentzRotation & rr;
00187     int ii;
00188   };
00189   // Helper class for implemention of C-style subscripting r[i][j] 
00190 
00191   inline const HepLorentzRotation_row operator [] (int) const; 
00192   // Returns object of the helper class for C-style subscripting r[i][j]
00193 
00194   double operator () (int, int) const;
00195   // Fortran-style subscripting: returns (i,j) element of the matrix.
00196 
00197   // ----------  Decomposition:
00198 
00199   void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
00200   void decompose (HepBoost   & boost, HepRotation  & rotation) const;
00201   // Find B and R such that L = B*R
00202 
00203   void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
00204   void decompose (HepRotation  & rotation, HepBoost   & boost) const;
00205   // Find R and B such that L = R*B 
00206 
00207   // ----------  Comparisons:
00208 
00209   int compare( const HepLorentzRotation & m  ) const;
00210   // Dictionary-order comparison, in order tt,tz,...zt,zz,zy,zx,yt,yz,...,xx
00211   // Used in operator<, >, <=, >=
00212 
00213   inline bool operator == (const HepLorentzRotation &) const;
00214   inline bool operator != (const HepLorentzRotation &) const;
00215   inline bool operator <= (const HepLorentzRotation &) const;
00216   inline bool operator >= (const HepLorentzRotation &) const;
00217   inline bool operator <  (const HepLorentzRotation &) const;
00218   inline bool operator >  (const HepLorentzRotation &) const;
00219 
00220   inline bool isIdentity() const;
00221   // Returns true if the Identity matrix.
00222 
00223   double distance2( const HepBoost & b  ) const;
00224   double distance2( const HepRotation & r  ) const;
00225   double distance2( const HepLorentzRotation & lt  ) const;
00226   // Decomposes L = B*R, returns the sum of distance2 for B and R.
00227 
00228   double howNear(   const HepBoost & b ) const;
00229   double howNear(   const HepRotation & r) const;
00230   double howNear(   const HepLorentzRotation & lt ) const;
00231 
00232   bool isNear(const HepBoost & b,
00233              double epsilon=Hep4RotationInterface::tolerance) const;
00234   bool isNear(const HepRotation & r,
00235              double epsilon=Hep4RotationInterface::tolerance) const;
00236   bool isNear(const HepLorentzRotation & lt,
00237              double epsilon=Hep4RotationInterface::tolerance) const;
00238 
00239   // ----------  Properties:
00240 
00241   double norm2() const;
00242   // distance2 (IDENTITY), which involves decomposing into B and R and summing 
00243   // norm2 for the individual B and R parts. 
00244 
00245   void rectify();
00246   // non-const but logically moot correction for accumulated roundoff errors
00247         // rectify averages the matrix with the orthotranspose of its actual
00248         // inverse (absent accumulated roundoff errors, the orthotranspose IS
00249         // the inverse)); this removes to first order those errors.
00250         // Then it formally decomposes that, extracts axis and delta for its
00251         // Rotation part, forms a LorentzRotation from a true HepRotation 
00252         // with those values of axis and delta, times the true Boost
00253         // with that boost vector.
00254 
00255   // ---------- Application:
00256 
00257   inline HepLorentzVector vectorMultiplication(const HepLorentzVector&) const;
00258   inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
00259   inline HepLorentzVector operator* ( const HepLorentzVector & p ) const;
00260   // Multiplication with a Lorentz Vector.
00261 
00262   // ---------- Operations in the group of 4-Rotations
00263 
00264   HepLorentzRotation matrixMultiplication(const HepRep4x4 & m) const;
00265 
00266   inline HepLorentzRotation operator * (const HepBoost & b) const;
00267   inline HepLorentzRotation operator * (const HepRotation & r) const;
00268   inline HepLorentzRotation operator * (const HepLorentzRotation & lt) const;
00269   // Product of two Lorentz Rotations (this) * lt - matrix multiplication  
00270 
00271   inline  HepLorentzRotation & operator *= (const HepBoost & b);
00272   inline  HepLorentzRotation & operator *= (const HepRotation & r);
00273   inline  HepLorentzRotation & operator *= (const HepLorentzRotation & lt);
00274   inline  HepLorentzRotation & transform   (const HepBoost & b);
00275   inline  HepLorentzRotation & transform   (const HepRotation & r);
00276   inline  HepLorentzRotation & transform   (const HepLorentzRotation & lt);
00277   // Matrix multiplication.
00278   // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
00279 
00280   // Here there is an opportunity for speedup by providing specialized forms
00281   // of lt * r and lt * b where r is a RotationX Y or Z or b is a BoostX Y or Z
00282   // These are, in fact, provided below for the transform() methods.
00283 
00284   HepLorentzRotation & rotateX(double delta);
00285   // Rotation around the x-axis; equivalent to LT = RotationX(delta) * LT
00286 
00287   HepLorentzRotation & rotateY(double delta);
00288   // Rotation around the y-axis; equivalent to LT = RotationY(delta) * LT
00289 
00290   HepLorentzRotation & rotateZ(double delta);
00291   // Rotation around the z-axis; equivalent to LT = RotationZ(delta) * LT
00292 
00293   inline HepLorentzRotation & rotate(double delta, const Hep3Vector& axis);
00294   inline HepLorentzRotation & rotate(double delta, const Hep3Vector *axis);
00295   // Rotation around specified vector - LT = Rotation(delta,axis)*LT
00296 
00297   HepLorentzRotation & boostX(double beta);
00298   // Pure boost along the x-axis; equivalent to LT = BoostX(beta) * LT
00299 
00300   HepLorentzRotation & boostY(double beta);
00301   // Pure boost along the y-axis; equivalent to LT = BoostX(beta) * LT
00302 
00303   HepLorentzRotation & boostZ(double beta);
00304   // Pure boost along the z-axis; equivalent to LT = BoostX(beta) * LT
00305 
00306   inline HepLorentzRotation & boost(double, double, double);
00307   inline HepLorentzRotation & boost(const Hep3Vector &);
00308   // Lorenz boost.
00309 
00310   inline HepLorentzRotation inverse() const;
00311   // Return the inverse.
00312 
00313   inline HepLorentzRotation & invert();
00314   // Inverts the LorentzRotation matrix.
00315 
00316   // ---------- I/O:
00317 
00318   HepStd::ostream & print( HepStd::ostream & os ) const;
00319   // Aligned six-digit-accurate output of the transformation matrix. 
00320 
00321   // ---------- Tolerance
00322 
00323   static inline double getTolerance();
00324   static inline double setTolerance(double tol); 
00325 
00326   friend HepLorentzRotation inverseOf ( const HepLorentzRotation & lt );
00327 
00328 protected:
00329 
00330   inline HepLorentzRotation
00331        (double mxx, double mxy, double mxz, double mxt,
00332         double myx, double myy, double myz, double myt,
00333         double mzx, double mzy, double mzz, double mzt,
00334         double mtx, double mty, double mtz, double mtt);
00335   // Protected constructor.
00336   // DOES NOT CHECK FOR VALIDITY AS A LORENTZ TRANSFORMATION.
00337 
00338   inline void setBoost(double, double, double);
00339   // Set elements according to a boost vector.
00340 
00341   double mxx, mxy, mxz, mxt,
00342             myx, myy, myz, myt,
00343             mzx, mzy, mzz, mzt,
00344             mtx, mty, mtz, mtt;
00345   // The matrix elements.
00346 
00347 };
00348 
00349 inline HepStd::ostream & operator<<
00350                 ( HepStd::ostream & os, const  HepLorentzRotation& lt ) 
00351   {return lt.print(os);}
00352 
00353 inline bool operator==(const HepRotation &r, const HepLorentzRotation & lt)
00354   { return lt==r; }
00355 inline bool operator!=(const HepRotation &r, const HepLorentzRotation & lt)
00356   { return lt!=r; }
00357 inline bool operator<=(const HepRotation &r, const HepLorentzRotation & lt)
00358   { return lt<=r; }
00359 inline bool operator>=(const HepRotation &r, const HepLorentzRotation & lt)
00360   { return lt>=r; }
00361 inline bool operator<(const HepRotation &r, const HepLorentzRotation & lt)
00362   { return lt<r; }
00363 inline bool operator>(const HepRotation &r, const HepLorentzRotation & lt)
00364   { return lt>r; }
00365 
00366 inline bool operator==(const HepBoost &b, const HepLorentzRotation & lt)
00367   { return lt==b; }
00368 inline bool operator!=(const HepBoost &b, const HepLorentzRotation & lt)
00369   { return lt!=b; }
00370 inline bool operator<=(const HepBoost &b, const HepLorentzRotation & lt)
00371   { return lt<=b; }
00372 inline bool operator>=(const HepBoost &b, const HepLorentzRotation & lt)
00373   { return lt>=b; }
00374 inline bool operator<(const HepBoost &b, const HepLorentzRotation & lt)
00375   { return lt<b; }
00376 inline bool operator>(const HepBoost &b, const HepLorentzRotation & lt)
00377   { return lt>b; }
00378     
00379 #ifdef HEP_NO_INLINE_IN_DECLARATION
00380 #undef inline
00381 #endif
00382 
00383 #ifdef HEP_SHORT_NAMES
00384 typedef HepLorentzRotation LRotation;
00385 #endif
00386 
00387 #ifndef HEP_DEBUG_INLINE
00388 #include "CLHEP/Vector/LorentzRotation.icc"
00389 #endif
00390 
00391 #endif /* HEP_LORENTZROTATION_H */
00392 

Class Library for High Energy Physics (version 1.8)