CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RotationY.cc

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

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7