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