CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/Math/interface/deltaPhi.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Math_deltaPhi_h
00002 #define DataFormats_Math_deltaPhi_h
00003 /* function to compute deltaPhi
00004  *
00005  * Ported from original code in RecoJets 
00006  * by Fedor Ratnikov, FNAL
00007  */
00008 #include <cmath>
00009 
00010 namespace reco {
00011 
00012   inline double deltaPhi(double phi1, double phi2) { 
00013     double result = phi1 - phi2;
00014     while (result > M_PI) result -= 2*M_PI;
00015     while (result <= -M_PI) result += 2*M_PI;
00016     return result;
00017   }
00018 
00019   inline double deltaPhi(float phi1, double phi2) {
00020     return deltaPhi(static_cast<double>(phi1), phi2);
00021   }
00022   
00023   inline double deltaPhi(double phi1, float phi2) {
00024     return deltaPhi(phi1, static_cast<double>(phi2));
00025   }
00026   
00027 
00028   inline float deltaPhi(float phi1, float phi2) { 
00029     float result = phi1 - phi2;
00030     while (result > float(M_PI)) result -= float(2*M_PI);
00031     while (result <= -float(M_PI)) result += float(2*M_PI);
00032     return result;
00033   }
00034 
00035   /*
00036   inline double deltaPhi(float phi1, float phi2) {
00037     return deltaPhi(static_cast<double>(phi1),
00038                     static_cast<double>(phi2));
00039   } 
00040   */
00041 
00042   template<typename T1, typename T2>
00043     inline double deltaPhi(T1& t1, T2 & t2) {
00044     return deltaPhi(t1.phi(), t2.phi());
00045   }      
00046 
00047   template <typename T> 
00048     inline T deltaPhi (T phi1, T phi2) { 
00049     T result = phi1 - phi2;
00050     while (result > M_PI) result -= 2*M_PI;
00051     while (result <= -M_PI) result += 2*M_PI;
00052     return result;
00053   }
00054 
00055 }
00056 
00057 using reco::deltaPhi;
00058 
00059 template<typename T1, typename T2 = T1>
00060 struct DeltaPhi {
00061   double operator()(const T1 & t1, const T2 & t2) const {
00062     return reco::deltaPhi(t1, t2);
00063   }
00064 };
00065 
00066 #endif