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

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

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7