CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
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 namespace CLHEP { 00026 00027 static inline double safe_acos (double x) { 00028 if (std::abs(x) <= 1.0) return std::acos(x); 00029 return ( (x>0) ? 0 : CLHEP::pi ); 00030 } 00031 00032 HepRotationX::HepRotationX(double ddelta) : 00033 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta)) 00034 {} 00035 00036 HepRotationX & HepRotationX::set ( double ddelta ) { 00037 its_d = proper(ddelta); 00038 its_s = std::sin(its_d); 00039 its_c = std::cos(its_d); 00040 return *this; 00041 } 00042 00043 double HepRotationX::phi() const { 00044 if ( (its_d > 0) && (its_d < CLHEP::pi) ) { 00045 return CLHEP::pi; 00046 } else { 00047 return 0.0; 00048 } 00049 } // HepRotationX::phi() 00050 00051 double HepRotationX::theta() const { 00052 return std::fabs( its_d ); 00053 } // HepRotationX::theta() 00054 00055 double HepRotationX::psi() const { 00056 if ( (its_d > 0) && (its_d < CLHEP::pi) ) { 00057 return CLHEP::pi; 00058 } else { 00059 return 0.0; 00060 } 00061 } // HepRotationX::psi() 00062 00063 HepEulerAngles HepRotationX::eulerAngles() const { 00064 return HepEulerAngles( phi(), theta(), psi() ); 00065 } // HepRotationX::eulerAngles() 00066 00067 00068 // From the defining code in the implementation of CLHEP (in Rotation.cc) 00069 // it is clear that thetaX, phiX form the polar angles in the original 00070 // coordinate system of the new X axis (and similarly for phiY and phiZ). 00071 // 00072 // This code is taken directly from the original CLHEP. However, there are as 00073 // shown opportunities for significant speed improvement. 00074 00075 double HepRotationX::phiX() const { 00076 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx()); 00077 // or ---- return 0; 00078 } 00079 00080 double HepRotationX::phiY() const { 00081 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy()); 00082 // or ---- return (yy() == 0.0) ? 0.0 : std::atan2(yy(),xy()); 00083 } 00084 00085 double HepRotationX::phiZ() const { 00086 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz()); 00087 // or ---- return (yz() == 0.0) ? 0.0 : std::atan2(yz(),xz()); 00088 } 00089 00090 double HepRotationX::thetaX() const { 00091 return safe_acos(zx()); 00092 // or ---- return CLHEP::halfpi; 00093 } 00094 00095 double HepRotationX::thetaY() const { 00096 return safe_acos(zy()); 00097 } 00098 00099 double HepRotationX::thetaZ() const { 00100 return safe_acos(zz()); 00101 // or ---- return d; 00102 } 00103 00104 void HepRotationX::setDelta ( double ddelta ) { 00105 set(ddelta); 00106 } 00107 00108 void HepRotationX::decompose 00109 (HepAxisAngle & rotation, Hep3Vector & boost) const { 00110 boost.set(0,0,0); 00111 rotation = axisAngle(); 00112 } 00113 00114 void HepRotationX::decompose 00115 (Hep3Vector & boost, HepAxisAngle & rotation) const { 00116 boost.set(0,0,0); 00117 rotation = axisAngle(); 00118 } 00119 00120 void HepRotationX::decompose 00121 (HepRotation & rotation, HepBoost & boost) const { 00122 boost.set(0,0,0); 00123 rotation = HepRotation(*this); 00124 } 00125 00126 void HepRotationX::decompose 00127 (HepBoost & boost, HepRotation & rotation) const { 00128 boost.set(0,0,0); 00129 rotation = HepRotation(*this); 00130 } 00131 00132 double HepRotationX::distance2( const HepRotationX & r ) const { 00133 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ; 00134 return (answer >= 0) ? answer : 0; 00135 } 00136 00137 double HepRotationX::distance2( const HepRotation & r ) const { 00138 double sum = r.xx() + 00139 yy() * r.yy() + yz() * r.yz() 00140 + zy() * r.zy() + zz() * r.zz(); 00141 double answer = 3.0 - sum; 00142 return (answer >= 0 ) ? answer : 0; 00143 } 00144 00145 double HepRotationX::distance2( const HepLorentzRotation & lt ) const { 00146 HepAxisAngle a; 00147 Hep3Vector b; 00148 lt.decompose(b, a); 00149 double bet = b.beta(); 00150 double bet2 = bet*bet; 00151 HepRotation r(a); 00152 return bet2/(1-bet2) + distance2(r); 00153 } 00154 00155 double HepRotationX::distance2( const HepBoost & lt ) const { 00156 return distance2( HepLorentzRotation(lt)); 00157 } 00158 00159 double HepRotationX::howNear( const HepRotationX & r ) const { 00160 return std::sqrt(distance2(r)); 00161 } 00162 double HepRotationX::howNear( const HepRotation & r ) const { 00163 return std::sqrt(distance2(r)); 00164 } 00165 double HepRotationX::howNear( const HepBoost & b ) const { 00166 return std::sqrt(distance2(b)); 00167 } 00168 double HepRotationX::howNear( const HepLorentzRotation & lt ) const { 00169 return std::sqrt(distance2(lt)); 00170 } 00171 bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{ 00172 return (distance2(r) <= epsilon*epsilon); 00173 } 00174 bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{ 00175 return (distance2(r) <= epsilon*epsilon); 00176 } 00177 bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const { 00178 return (distance2(lt) <= epsilon*epsilon); 00179 } 00180 00181 bool HepRotationX::isNear( const HepLorentzRotation & lt, 00182 double epsilon ) const { 00183 return (distance2(lt) <= epsilon*epsilon); 00184 } 00185 00186 double HepRotationX::norm2() const { 00187 return 2.0 - 2.0 * its_c; 00188 } 00189 00190 std::ostream & HepRotationX::print( std::ostream & os ) const { 00191 os << "\nRotation about X (" << its_d << 00192 ") [cos d = " << its_c << " sin d = " << its_s << "]\n"; 00193 return os; 00194 } 00195 00196 } // namespace CLHEP 00197