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