SpaceVectorD.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 the subset of those methods of the Hep3Vector 
00007 // class which originated from the ZOOM SpaceVector class *and* which involve
00008 // the esoteric concepts of polar/azimuthal angular decomposition.
00009 //
00010 
00011 #ifdef GNUPRAGMA
00012 #pragma implementation
00013 #endif
00014 
00015 #include "CLHEP/Vector/ThreeVector.h"
00016 
00017 #include <cmath>
00018 
00019 namespace CLHEP  {
00020 
00021 //-*********************************************
00022 //                      - 6 -
00023 // Decomposition of an angle between two vectors
00024 //
00025 //-*********************************************
00026 
00027 
00028 double Hep3Vector::polarAngle (const Hep3Vector & v2) const {
00029   return std::fabs(v2.getTheta() - getTheta());
00030 } /* polarAngle */
00031 
00032 double Hep3Vector::polarAngle (const Hep3Vector & v2,
00033                                 const Hep3Vector & ref) const {
00034   return std::fabs( v2.angle(ref) - angle(ref) );
00035 } /* polarAngle (v2, ref) */
00036 
00037 // double Hep3Vector::azimAngle (const Hep3Vector & v2) const 
00038 // is now in the .icc file as deltaPhi(v2)
00039 
00040 double Hep3Vector::azimAngle  (const Hep3Vector & v2,
00041                                 const Hep3Vector & ref) const {
00042 
00043   Hep3Vector vperp ( perpPart(ref) );
00044   if ( vperp.mag2() == 0 ) {
00045     std::cerr << "Hep3Vector::azimAngle() - "
00046       << "Cannot find azimuthal angle with reference direction parallel to "
00047       << "vector 1 -- will return zero" << std::endl;
00048    return 0;
00049   }
00050 
00051   Hep3Vector v2perp ( v2.perpPart(ref) );
00052   if ( v2perp.mag2() == 0 ) {
00053     std::cerr << "Hep3Vector::azimAngle() - "
00054       << "Cannot find azimuthal angle with reference direction parallel to "
00055       << "vector 2 -- will return zero" << std::endl;
00056    return 0;
00057   }
00058 
00059   double ang = vperp.angle(v2perp);
00060 
00061   // Now compute the sign of the answer:  that of U*(VxV2) or 
00062   // the equivalent expression V*(V2xU).
00063 
00064   if  ( dot(v2.cross(ref)) >= 0 ) {
00065     return ang;
00066   } else {
00067     return -ang;
00068   }
00069 
00070         //-| Note that if V*(V2xU) is zero, we want to return 0 or PI
00071         //-| depending on whether vperp is aligned or antialigned with v2perp.
00072         //-| The computed angle() expression does this properly.
00073 
00074 } /* azimAngle (v2, ref) */
00075 
00076 }  // namespace CLHEP

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7