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