CLHEP/Vector/RotationX.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // ---------------------------------------------------------------------------
00004 // CLASSDOC ON
00005 //
00006 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00007 //
00008 // This is the definition of the HepRotationX class for performing rotations
00009 // around the X axis on objects of the Hep3Vector (and HepLorentzVector) class.
00010 //
00011 // HepRotationX is a concrete implementation of Hep3RotationInterface.
00012 //
00013 // .SS See Also
00014 // RotationInterfaces.h
00015 // ThreeVector.h, LorentzVector.h, LorentzRotation.h
00016 //
00017 // .SS Author
00018 // Mark Fischler
00019 
00020 #ifndef HEP_ROTATIONX_H
00021 #define HEP_ROTATIONX_H
00022 
00023 #ifdef GNUPRAGMA
00024 #pragma interface
00025 #endif
00026 
00027 #include "CLHEP/Vector/RotationInterfaces.h"
00028 
00029 #ifdef HEP_NO_INLINE_IN_DECLARATION
00030 #define inline
00031 #endif
00032 
00033 class HepRotationX;
00034 
00035 class HepRotation;
00036 class HepBoost;
00037 
00038 inline HepRotationX inverseOf(const HepRotationX & r);
00039 // Returns the inverse of a RotationX.
00040 
00045 class HepRotationX {
00046 
00047 public:
00048 
00049   // ----------  Constructors and Assignment:
00050 
00051   inline HepRotationX();
00052   // Default constructor. Gives an identity rotation. 
00053 
00054   HepRotationX(double delta);
00055   // supply angle of rotation 
00056 
00057   inline HepRotationX(const HepRotationX & orig);
00058   // Copy constructor.
00059 
00060   inline HepRotationX & operator = (const HepRotationX & r);
00061   // Assignment from a Rotation, which must be RotationX
00062 
00063   HepRotationX & set ( double delta );
00064   // set angle of rotation 
00065 
00066   inline ~HepRotationX();
00067   // Trivial destructor.
00068 
00069   // ----------  Accessors:
00070 
00071   inline Hep3Vector colX() const;
00072   inline Hep3Vector colY() const;
00073   inline Hep3Vector colZ() const;
00074   // orthogonal unit-length column vectors
00075 
00076   inline Hep3Vector rowX() const;
00077   inline Hep3Vector rowY() const;
00078   inline Hep3Vector rowZ() const;
00079   // orthogonal unit-length row vectors
00080                                 
00081   inline double xx() const;
00082   inline double xy() const;
00083   inline double xz() const;
00084   inline double yx() const;
00085   inline double yy() const;
00086   inline double yz() const;
00087   inline double zx() const;
00088   inline double zy() const;
00089   inline double zz() const;
00090   // Elements of the rotation matrix (Geant4).
00091 
00092   inline HepRep3x3 rep3x3() const;
00093   //   3x3 representation:
00094 
00095   // ------------  Euler angles:
00096   inline  double getPhi  () const;
00097   inline  double getTheta() const;
00098   inline  double getPsi  () const;
00099   double    phi  () const;
00100   double    theta() const;
00101   double    psi  () const;
00102   HepEulerAngles eulerAngles() const;
00103 
00104   // ------------  axis & angle of rotation:
00105   inline  double  getDelta() const;
00106   inline  Hep3Vector getAxis () const;
00107   inline  double     delta() const;
00108   inline  Hep3Vector    axis () const;
00109   inline  HepAxisAngle  axisAngle() const;
00110   inline  void getAngleAxis(double & delta, Hep3Vector & axis) const;
00111   // Returns the rotation angle and rotation axis (Geant4).     
00112 
00113   // ------------- Angles of rotated axes
00114   double phiX() const;
00115   double phiY() const;
00116   double phiZ() const;
00117   double thetaX() const;
00118   double thetaY() const;
00119   double thetaZ() const;
00120   // Return angles (RADS) made by rotated axes against original axes (Geant4).
00121 
00122   // ----------  Other accessors treating pure rotation as a 4-rotation
00123 
00124   inline HepLorentzVector col1() const;
00125   inline HepLorentzVector col2() const;
00126   inline HepLorentzVector col3() const;
00127   //  orthosymplectic 4-vector columns - T component will be zero
00128 
00129   inline HepLorentzVector col4() const;
00130   // Will be (0,0,0,1) for this pure Rotation.
00131 
00132   inline HepLorentzVector row1() const;
00133   inline HepLorentzVector row2() const;
00134   inline HepLorentzVector row3() const;
00135   //  orthosymplectic 4-vector rows - T component will be zero
00136 
00137   inline HepLorentzVector row4() const;
00138   // Will be (0,0,0,1) for this pure Rotation.
00139 
00140   inline double xt() const;
00141   inline double yt() const;
00142   inline double zt() const;
00143   inline double tx() const;
00144   inline double ty() const;
00145   inline double tz() const;
00146   // Will be zero for this pure Rotation
00147 
00148   inline double tt() const;
00149   // Will be one for this pure Rotation
00150 
00151   inline HepRep4x4 rep4x4() const;
00152   //   4x4 representation.
00153 
00154   // ---------   Mutators 
00155 
00156   void setDelta (double delta);
00157   // change angle of rotation, leaving rotation axis unchanged.
00158 
00159   // ----------  Decomposition:
00160 
00161   void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
00162   void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
00163   void decompose (HepRotation & rotation, HepBoost & boost) const;
00164   void decompose (HepBoost & boost, HepRotation & rotation) const;
00165   // These are trivial, as the boost vector is 0.               
00166 
00167   // ----------  Comparisons: 
00168   
00169   inline bool isIdentity() const;                               
00170   // Returns true if the identity matrix (Geant4).      
00171 
00172   inline int compare( const HepRotationX & r  ) const;
00173   // Dictionary-order comparison, in order of delta
00174   // Used in operator<, >, <=, >= 
00175 
00176   inline bool operator== ( const HepRotationX & r ) const;
00177   inline bool operator!= ( const HepRotationX & r ) const;
00178   inline bool operator<  ( const HepRotationX & r ) const;
00179   inline bool operator>  ( const HepRotationX & r ) const;
00180   inline bool operator<= ( const HepRotationX & r ) const;
00181   inline bool operator>= ( const HepRotationX & r ) const;
00182   
00183   double distance2( const HepRotationX & r  ) const; 
00184   // 3 - Tr ( this/r )
00185 
00186   double distance2( const HepRotation &  r  ) const; 
00187   // 3 - Tr ( this/r ) -- This works with RotationY or Z also
00188 
00189   double howNear( const HepRotationX & r ) const;
00190   double howNear( const HepRotation  & r ) const;
00191   bool isNear( const HepRotationX & r,
00192                double epsilon=Hep4RotationInterface::tolerance) const;
00193   bool isNear( const HepRotation  & r,
00194                double epsilon=Hep4RotationInterface::tolerance) const;
00195 
00196   double distance2( const HepBoost           & lt  ) const; 
00197   // 3 - Tr ( this ) + |b|^2 / (1-|b|^2) 
00198   double distance2( const HepLorentzRotation & lt  ) const; 
00199   // 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
00200 
00201   double howNear( const HepBoost           & lt ) const;
00202   double howNear( const HepLorentzRotation & lt ) const;
00203   bool isNear( const HepBoost           & lt, 
00204                double epsilon=Hep4RotationInterface::tolerance) const;
00205   bool isNear( const HepLorentzRotation & lt,
00206                double epsilon=Hep4RotationInterface::tolerance) const;
00207 
00208   // ----------  Properties:
00209 
00210   double norm2() const; 
00211   // distance2 (IDENTITY), which is 3 - Tr ( *this )
00212 
00213   inline void rectify();
00214   // non-const but logically moot correction for accumulated roundoff errors
00215 
00216   // ---------- Application:
00217 
00218   inline Hep3Vector operator() (const Hep3Vector & p) const;
00219   // Rotate a Hep3Vector.                                       
00220 
00221   inline  Hep3Vector operator * (const Hep3Vector & p) const;
00222   // Multiplication with a Hep3Vector.
00223 
00224   inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
00225   // Rotate (the space part of) a HepLorentzVector.             
00226 
00227   inline  HepLorentzVector operator* ( const HepLorentzVector & w ) const;
00228   // Multiplication with a HepLorentzVector.
00229 
00230   // ---------- Operations in the group of Rotations 
00231 
00232   inline HepRotationX operator * (const HepRotationX & rx) const;
00233   // Product of two X rotations: (this) * rx is known to be RotationX.
00234 
00235   inline  HepRotationX & operator *= (const HepRotationX & r);
00236   inline  HepRotationX & transform   (const HepRotationX & r);
00237   // Matrix multiplication.
00238   // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
00239   // However, in this special case, they commute:  Both just add deltas.
00240 
00241   inline HepRotationX inverse() const;
00242   // Returns the inverse.
00243 
00244   friend HepRotationX inverseOf(const HepRotationX & r);
00245   // Returns the inverse of a RotationX.
00246 
00247   inline HepRotationX & invert();
00248   // Inverts the Rotation matrix (be negating delta).
00249 
00250   // ---------- I/O: 
00251 
00252   HepStd::ostream & print( HepStd::ostream & os ) const;
00253   // Output, identifying type of rotation and delta.
00254 
00255   // ---------- Tolerance
00256 
00257   static inline double getTolerance();
00258   static inline double setTolerance(double tol);
00259 
00260 protected:
00261 
00262   double d;
00263   // The angle of rotation.
00264 
00265   double s;
00266   double c;
00267   // Cache the trig functions, for rapid operations.
00268 
00269   inline HepRotationX ( double dd, double ss, double cc );
00270   // Unchecked load-the-data-members
00271 
00272   static inline double proper (double delta);
00273   // Put an angle into the range of (-PI, PI].  Useful helper method.
00274 
00275 };
00276 // ---------- Free-function operations in the group of Rotations
00277 
00278 inline   
00279 HepStd::ostream & operator << 
00280         ( HepStd::ostream & os, const HepRotationX & r ) {return r.print(os);}
00281 
00282 #ifdef HEP_NO_INLINE_IN_DECLARATION
00283 #undef inline
00284 #endif
00285 
00286 #ifndef HEP_DEBUG_INLINE
00287 #include "CLHEP/Vector/RotationX.icc"
00288 #endif
00289 
00290 #endif /* HEP_ROTATIONX_H */
00291 

Class Library for High Energy Physics (version 1.8)