CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RotationX.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 //
00006 // This is the implementation of methods of the HepRotationX class which
00007 // were introduced when ZOOM PhysicsVectors was merged in.
00008 //
00009 
00010 #ifdef GNUPRAGMA
00011 #pragma implementation
00012 #endif
00013 
00014 #include "CLHEP/Vector/defs.h"
00015 #include "CLHEP/Vector/RotationX.h"
00016 #include "CLHEP/Vector/AxisAngle.h"
00017 #include "CLHEP/Vector/EulerAngles.h"
00018 #include "CLHEP/Vector/LorentzRotation.h"
00019 #include "CLHEP/Units/PhysicalConstants.h"
00020 
00021 #include <cmath>
00022 #include <stdlib.h>
00023 #include <iostream>
00024 
00025 using std::abs;
00026 
00027 namespace CLHEP  {
00028 
00029 static inline double safe_acos (double x) {
00030   if (abs(x) <= 1.0) return acos(x);
00031   return ( (x>0) ? 0 : CLHEP::pi );
00032 }
00033 
00034 HepRotationX::HepRotationX(double delta) : 
00035                 d(proper(delta)), s(sin(delta)), c(cos(delta))
00036 {}
00037 
00038 HepRotationX & HepRotationX::set ( double delta ) {
00039   d = proper(delta);
00040   s = sin(d);
00041   c = cos(d);
00042   return *this;
00043 }
00044 
00045 double  HepRotationX::phi() const {
00046   if ( (d > 0) && (d < CLHEP::pi) ) {
00047     return CLHEP::pi;
00048   } else {
00049     return 0.0;
00050   }
00051 }  // HepRotationX::phi()
00052 
00053 double  HepRotationX::theta() const {
00054   return  fabs( d );
00055 }  // HepRotationX::theta()
00056 
00057 double  HepRotationX::psi() const {
00058   if ( (d > 0) && (d < CLHEP::pi) ) {
00059     return CLHEP::pi;
00060   } else {
00061     return 0.0;
00062   }
00063 }  // HepRotationX::psi()
00064 
00065 HepEulerAngles HepRotationX::eulerAngles() const {
00066   return HepEulerAngles(  phi(), theta(),  psi() );
00067 }  // HepRotationX::eulerAngles()
00068 
00069 
00070 // From the defining code in the implementation of CLHEP (in Rotation.cc)
00071 // it is clear that thetaX, phiX form the polar angles in the original
00072 // coordinate system of the new X axis (and similarly for phiY and phiZ).
00073 //
00074 // This code is taken directly from the original CLHEP. However, there are as
00075 // shown opportunities for significant speed improvement.
00076 
00077 double HepRotationX::phiX() const {
00078   return (yx() == 0.0 && xx() == 0.0) ? 0.0 : atan2(yx(),xx());
00079                 // or ---- return 0;
00080 }
00081 
00082 double HepRotationX::phiY() const {
00083   return (yy() == 0.0 && xy() == 0.0) ? 0.0 : atan2(yy(),xy());
00084                 // or ----  return (yy() == 0.0) ? 0.0 : atan2(yy(),xy());
00085 }
00086 
00087 double HepRotationX::phiZ() const {
00088   return (yz() == 0.0 && xz() == 0.0) ? 0.0 : atan2(yz(),xz());
00089                 // or ----  return (yz() == 0.0) ? 0.0 : atan2(yz(),xz());
00090 }
00091 
00092 double HepRotationX::thetaX() const {
00093   return safe_acos(zx());
00094                 // or ----  return CLHEP::halfpi;
00095 }
00096 
00097 double HepRotationX::thetaY() const {
00098   return safe_acos(zy());
00099 }
00100 
00101 double HepRotationX::thetaZ() const {
00102   return safe_acos(zz());  
00103                 // or ---- return d;
00104 }
00105 
00106 void HepRotationX::setDelta ( double delta ) {
00107   set(delta);
00108 }
00109 
00110 void HepRotationX::decompose
00111         (HepAxisAngle & rotation, Hep3Vector & boost) const {
00112   boost.set(0,0,0);
00113   rotation = axisAngle();
00114 }
00115 
00116 void HepRotationX::decompose
00117         (Hep3Vector & boost, HepAxisAngle & rotation) const {
00118   boost.set(0,0,0);
00119   rotation = axisAngle();
00120 }
00121 
00122 void HepRotationX::decompose
00123         (HepRotation & rotation, HepBoost & boost) const {
00124   boost.set(0,0,0);
00125   rotation = HepRotation(*this);
00126 } 
00127 
00128 void HepRotationX::decompose
00129         (HepBoost & boost, HepRotation & rotation) const {
00130   boost.set(0,0,0);
00131   rotation = HepRotation(*this);
00132 }
00133 
00134 double HepRotationX::distance2( const HepRotationX & r  ) const {
00135   double answer = 2.0 * ( 1.0 - ( s * r.s + c * r.c ) ) ;
00136   return (answer >= 0) ? answer : 0;
00137 }
00138 
00139 double HepRotationX::distance2( const HepRotation & r  ) const {
00140   double sum =        r.xx() + 
00141                                   yy() * r.yy() + yz() * r.yz()
00142                                 + zy() * r.zy() + zz() * r.zz();
00143   double answer = 3.0 - sum;
00144   return (answer >= 0 ) ? answer : 0;
00145 }
00146 
00147 double HepRotationX::distance2( const HepLorentzRotation & lt  ) const {
00148   HepAxisAngle a; 
00149   Hep3Vector   b;
00150   lt.decompose(b, a);
00151   double bet = b.beta();
00152   double bet2 = bet*bet;
00153   HepRotation r(a);
00154   return bet2/(1-bet2) + distance2(r);
00155 }
00156 
00157 double HepRotationX::distance2( const HepBoost & lt ) const {
00158   return distance2( HepLorentzRotation(lt));
00159 }
00160 
00161 double HepRotationX::howNear( const HepRotationX & r ) const {
00162   return sqrt(distance2(r));
00163 }
00164 double HepRotationX::howNear( const HepRotation & r ) const {
00165   return sqrt(distance2(r));
00166 }
00167 double HepRotationX::howNear( const HepBoost & b ) const {
00168   return sqrt(distance2(b));
00169 }
00170 double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
00171   return sqrt(distance2(lt));
00172 }
00173 bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
00174   return (distance2(r) <= epsilon*epsilon);
00175 }
00176 bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
00177   return (distance2(r) <= epsilon*epsilon);
00178 }
00179 bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
00180   return (distance2(lt) <= epsilon*epsilon);
00181 }
00182 
00183 bool HepRotationX::isNear( const HepLorentzRotation & lt,
00184                                      double epsilon ) const {
00185   return (distance2(lt) <= epsilon*epsilon);
00186 }
00187 
00188 double HepRotationX::norm2() const {
00189   return 2.0 - 2.0 * c;
00190 }
00191 
00192 std::ostream & HepRotationX::print( std::ostream & os ) const {
00193   os << "\nRotation about X (" << d << 
00194                 ") [cos d = " << c << " sin d = " << s << "]\n";
00195   return os;
00196 }
00197 
00198 }  // namespace CLHEP
00199 

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7