Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // ------------------------------------------- 2 // --------------------------------------------------------------------------- 3 // 3 // 4 // This file is a part of the CLHEP - a Class 4 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 5 // 5 // 6 // This is the implementation of methods of th 6 // This is the implementation of methods of the HepRotationZ class which 7 // were introduced when ZOOM PhysicsVectors wa 7 // were introduced when ZOOM PhysicsVectors was merged in. 8 // 8 // 9 9 10 #include "CLHEP/Vector/RotationZ.h" 10 #include "CLHEP/Vector/RotationZ.h" 11 #include "CLHEP/Vector/AxisAngle.h" 11 #include "CLHEP/Vector/AxisAngle.h" 12 #include "CLHEP/Vector/EulerAngles.h" 12 #include "CLHEP/Vector/EulerAngles.h" 13 #include "CLHEP/Vector/LorentzRotation.h" 13 #include "CLHEP/Vector/LorentzRotation.h" 14 #include "CLHEP/Units/PhysicalConstants.h" 14 #include "CLHEP/Units/PhysicalConstants.h" 15 15 16 #include <cmath> 16 #include <cmath> 17 #include <stdlib.h> 17 #include <stdlib.h> 18 #include <iostream> 18 #include <iostream> 19 19 20 namespace CLHEP { 20 namespace CLHEP { 21 21 22 static inline double safe_acos (double x) { 22 static inline double safe_acos (double x) { 23 if (std::abs(x) <= 1.0) return std::acos(x); 23 if (std::abs(x) <= 1.0) return std::acos(x); 24 return ( (x>0) ? 0 : CLHEP::pi ); 24 return ( (x>0) ? 0 : CLHEP::pi ); 25 } 25 } 26 26 27 HepRotationZ::HepRotationZ(double ddelta) : 27 HepRotationZ::HepRotationZ(double ddelta) : 28 its_d(proper(ddelta)), its_s(std::sin(ddel 28 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta)) 29 {} 29 {} 30 30 31 HepRotationZ & HepRotationZ::set ( double ddel 31 HepRotationZ & HepRotationZ::set ( double ddelta ) { 32 its_d = proper(ddelta); 32 its_d = proper(ddelta); 33 its_s = std::sin(its_d); 33 its_s = std::sin(its_d); 34 its_c = std::cos(its_d); 34 its_c = std::cos(its_d); 35 return *this; 35 return *this; 36 } 36 } 37 37 38 double HepRotationZ::phi() const { 38 double HepRotationZ::phi() const { 39 return - its_d/2.0; 39 return - its_d/2.0; 40 } // HepRotationZ::phi() 40 } // HepRotationZ::phi() 41 41 42 double HepRotationZ::theta() const { 42 double HepRotationZ::theta() const { 43 return 0.0 ; 43 return 0.0 ; 44 } // HepRotationZ::theta() 44 } // HepRotationZ::theta() 45 45 46 double HepRotationZ::psi() const { 46 double HepRotationZ::psi() const { 47 return - its_d/2.0; 47 return - its_d/2.0; 48 } // HepRotationZ::psi() 48 } // HepRotationZ::psi() 49 49 50 HepEulerAngles HepRotationZ::eulerAngles() con 50 HepEulerAngles HepRotationZ::eulerAngles() const { 51 return HepEulerAngles( phi(), theta(), ps 51 return HepEulerAngles( phi(), theta(), psi() ); 52 } // HepRotationZ::eulerAngles() 52 } // HepRotationZ::eulerAngles() 53 53 54 54 55 // From the defining code in the implementatio 55 // From the defining code in the implementation of CLHEP (in Rotation.cc) 56 // it is clear that thetaX, phiX form the pola 56 // it is clear that thetaX, phiX form the polar angles in the original 57 // coordinate system of the new X axis (and si 57 // coordinate system of the new X axis (and similarly for phiY and phiZ). 58 // 58 // 59 // This code is take directly from CLHEP origi 59 // This code is take directly from CLHEP original. However, there are as 60 // shown opportunities for significant speed i 60 // shown opportunities for significant speed improvement. 61 61 62 double HepRotationZ::phiX() const { 62 double HepRotationZ::phiX() const { 63 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : 63 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx()); 64 // or ---- return d; 64 // or ---- return d; 65 } 65 } 66 66 67 double HepRotationZ::phiY() const { 67 double HepRotationZ::phiY() const { 68 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : 68 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy()); 69 } 69 } 70 70 71 double HepRotationZ::phiZ() const { 71 double HepRotationZ::phiZ() const { 72 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : 72 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz()); 73 // or ---- return 0.0; 73 // or ---- return 0.0; 74 } 74 } 75 75 76 double HepRotationZ::thetaX() const { 76 double HepRotationZ::thetaX() const { 77 return safe_acos(zx()); 77 return safe_acos(zx()); 78 // or ---- return CLHEP::halfpi; 78 // or ---- return CLHEP::halfpi; 79 } 79 } 80 80 81 double HepRotationZ::thetaY() const { 81 double HepRotationZ::thetaY() const { 82 return safe_acos(zy()); 82 return safe_acos(zy()); 83 // or ---- return CLHEP::halfpi; 83 // or ---- return CLHEP::halfpi; 84 } 84 } 85 85 86 double HepRotationZ::thetaZ() const { 86 double HepRotationZ::thetaZ() const { 87 return safe_acos(zz()); 87 return safe_acos(zz()); 88 // or ---- return 0.0; 88 // or ---- return 0.0; 89 } 89 } 90 90 91 void HepRotationZ::setDelta ( double ddelta ) 91 void HepRotationZ::setDelta ( double ddelta ) { 92 set(ddelta); 92 set(ddelta); 93 } 93 } 94 94 95 void HepRotationZ::decompose 95 void HepRotationZ::decompose 96 (HepAxisAngle & rotation, Hep3Vector & boost 96 (HepAxisAngle & rotation, Hep3Vector & boost) const { 97 boost.set(0,0,0); 97 boost.set(0,0,0); 98 rotation = axisAngle(); 98 rotation = axisAngle(); 99 } 99 } 100 100 101 void HepRotationZ::decompose 101 void HepRotationZ::decompose 102 (Hep3Vector & boost, HepAxisAngle & rotation 102 (Hep3Vector & boost, HepAxisAngle & rotation) const { 103 boost.set(0,0,0); 103 boost.set(0,0,0); 104 rotation = axisAngle(); 104 rotation = axisAngle(); 105 } 105 } 106 106 107 void HepRotationZ::decompose 107 void HepRotationZ::decompose 108 (HepRotation & rotation, HepBoost & bo 108 (HepRotation & rotation, HepBoost & boost) const { 109 boost.set(0,0,0); 109 boost.set(0,0,0); 110 rotation = HepRotation(*this); 110 rotation = HepRotation(*this); 111 } 111 } 112 112 113 void HepRotationZ::decompose 113 void HepRotationZ::decompose 114 (HepBoost & boost, HepRotation & rotat 114 (HepBoost & boost, HepRotation & rotation) const { 115 boost.set(0,0,0); 115 boost.set(0,0,0); 116 rotation = HepRotation(*this); 116 rotation = HepRotation(*this); 117 } 117 } 118 118 119 double HepRotationZ::distance2( const HepRotat 119 double HepRotationZ::distance2( const HepRotationZ & r ) const { 120 double answer = 2.0 * ( 1.0 - ( its_s * r.it 120 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ; 121 return (answer >= 0) ? answer : 0; 121 return (answer >= 0) ? answer : 0; 122 } 122 } 123 123 124 double HepRotationZ::distance2( const HepRotat 124 double HepRotationZ::distance2( const HepRotation & r ) const { 125 double sum = xx() * r.xx() + xy() * r.xy( 125 double sum = xx() * r.xx() + xy() * r.xy() 126 + yx() * r.yx() + yy() * r. 126 + yx() * r.yx() + yy() * r.yy() 127 + r.zz(); 127 + r.zz(); 128 double answer = 3.0 - sum; 128 double answer = 3.0 - sum; 129 return (answer >= 0 ) ? answer : 0; 129 return (answer >= 0 ) ? answer : 0; 130 } 130 } 131 131 132 double HepRotationZ::distance2( const HepLoren 132 double HepRotationZ::distance2( const HepLorentzRotation & lt ) const { 133 HepAxisAngle a; 133 HepAxisAngle a; 134 Hep3Vector b; 134 Hep3Vector b; 135 lt.decompose(b, a); 135 lt.decompose(b, a); 136 double bet = b.beta(); 136 double bet = b.beta(); 137 double bet2 = bet*bet; 137 double bet2 = bet*bet; 138 HepRotation r(a); 138 HepRotation r(a); 139 return bet2/(1-bet2) + distance2(r); 139 return bet2/(1-bet2) + distance2(r); 140 } 140 } 141 141 142 double HepRotationZ::distance2( const HepBoost 142 double HepRotationZ::distance2( const HepBoost & lt ) const { 143 return distance2( HepLorentzRotation(lt)); 143 return distance2( HepLorentzRotation(lt)); 144 } 144 } 145 145 146 double HepRotationZ::howNear( const HepRotatio 146 double HepRotationZ::howNear( const HepRotationZ & r ) const { 147 return std::sqrt(distance2(r)); 147 return std::sqrt(distance2(r)); 148 } 148 } 149 double HepRotationZ::howNear( const HepRotatio 149 double HepRotationZ::howNear( const HepRotation & r ) const { 150 return std::sqrt(distance2(r)); 150 return std::sqrt(distance2(r)); 151 } 151 } 152 double HepRotationZ::howNear( const HepBoost & 152 double HepRotationZ::howNear( const HepBoost & lt ) const { 153 return std::sqrt(distance2(lt)); 153 return std::sqrt(distance2(lt)); 154 } 154 } 155 double HepRotationZ::howNear( const HepLorentz 155 double HepRotationZ::howNear( const HepLorentzRotation & lt ) const { 156 return std::sqrt(distance2(lt)); 156 return std::sqrt(distance2(lt)); 157 } 157 } 158 bool HepRotationZ::isNear(const HepRotationZ & 158 bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const { 159 return (distance2(r) <= epsilon*epsilon); 159 return (distance2(r) <= epsilon*epsilon); 160 } 160 } 161 bool HepRotationZ::isNear(const HepRotation & 161 bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const { 162 return (distance2(r) <= epsilon*epsilon); 162 return (distance2(r) <= epsilon*epsilon); 163 } 163 } 164 bool HepRotationZ::isNear( const HepBoost & lt 164 bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const { 165 return (distance2(lt) <= epsilon*epsilon); 165 return (distance2(lt) <= epsilon*epsilon); 166 } 166 } 167 bool HepRotationZ::isNear( const HepLorentzRot 167 bool HepRotationZ::isNear( const HepLorentzRotation & lt, 168 double ep 168 double epsilon) const { 169 return (distance2(lt) <= epsilon*epsilon); 169 return (distance2(lt) <= epsilon*epsilon); 170 } 170 } 171 171 172 double HepRotationZ::norm2() const { 172 double HepRotationZ::norm2() const { 173 return 2.0 - 2.0 * its_c; 173 return 2.0 - 2.0 * its_c; 174 } 174 } 175 175 176 std::ostream & HepRotationZ::print( std::ostre 176 std::ostream & HepRotationZ::print( std::ostream & os ) const { 177 os << "\nRotation about Z (" << its_d << 177 os << "\nRotation about Z (" << its_d << 178 ") [cos d = " << its_c << " si 178 ") [cos d = " << its_c << " sin d = " << its_s << "]\n"; 179 return os; 179 return os; 180 } 180 } 181 181 182 } // namespace CLHEP 182 } // namespace CLHEP 183 183 184 184