CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DataFormats/GeometryVector/interface/VectorUtil.h

Go to the documentation of this file.
00001 #ifndef GeometryVector_Geom_Util_h
00002 #define GeometryVector_Geom_Util_h
00003 
00004 
00005 
00006 #include "DataFormats/GeometryVector/interface/Pi.h"
00007 #include "Math/VectorUtil.h" 
00008 #include <cmath>
00009 
00010 
00011 namespace Geom {
00012 
00021   inline double deltaBarePhi(double phi1, double phi2) { 
00022     double dphi = phi2-phi1; 
00023     if ( dphi > M_PI ) {
00024       dphi -= 2.0*M_PI;
00025     } else if ( dphi <= -M_PI ) {
00026       dphi += 2.0*M_PI;
00027     }
00028     return dphi;
00029   }
00030   inline double deltaPhi(float phi1, float phi2) { 
00031     using ROOT::Math::VectorUtil::Phi_mpi_pi;
00032     return deltaBarePhi(Phi_mpi_pi(phi2),Phi_mpi_pi(phi1));
00033   }
00034   inline double deltaPhi(double phi1, double phi2) { 
00035     using ROOT::Math::VectorUtil::Phi_mpi_pi;
00036     return deltaBarePhi(Phi_mpi_pi(phi2),Phi_mpi_pi(phi1));
00037   }
00038   template <class Vector1, class Vector2> 
00039   double deltaPhi( const Vector1 & v1, const Vector2 & v2) { 
00040     return deltaBarePhi(v1.phi(),v2.phi()); 
00041   }
00042   
00043 
00049   /*
00050   inline bool phiLess( float phi1, float phi2) {
00051     float diff = fmod(phi2 - phi1, 2.0*M_PI);
00052     // float diff = phi2-phi1; 
00053     if ( diff < 0) diff += 2*M_PI;
00054     return diff < M_PI;
00055   }
00056   */
00057   inline bool phiLess(float phi1, float phi2) {
00058     return deltaPhi(phi1,phi2)<0;
00059   }
00060   inline bool phiLess(double phi1, double phi2) {
00061     return deltaPhi(phi1,phi2)<0;
00062   }
00063   template <class Vector1, class Vector2> 
00064   bool phiLess(const Vector1 & v1, const Vector2 & v2) {
00065     return deltaPhi(v1,v2)<0.; 
00066   }
00067 
00068     
00077   template <class Vector1, class Vector2> 
00078   double deltaR2( const Vector1 & v1, const Vector2 & v2) { 
00079     double dphi = deltaPhi(v1,v2); 
00080     double deta = v2.eta() - v1.eta(); 
00081     return dphi*dphi + deta*deta; 
00082   }
00083   template <class Vector1, class Vector2> 
00084   double deltaR( const Vector1 & v1, const Vector2 & v2) { 
00085     return std::sqrt( deltaR2(v1,v2));
00086   }
00087   
00088 }
00089 
00090 #endif