CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VectorUtil.h
Go to the documentation of this file.
1 #ifndef GeometryVector_Geom_Util_h
2 #define GeometryVector_Geom_Util_h
3 
4 
5 
7 #include "Math/VectorUtil.h"
8 #include <cmath>
9 
10 
11 namespace Geom {
12 
21  inline double deltaBarePhi(double phi1, double phi2) {
22  double dphi = phi2-phi1;
23  if ( dphi > M_PI ) {
24  dphi -= 2.0*M_PI;
25  } else if ( dphi <= -M_PI ) {
26  dphi += 2.0*M_PI;
27  }
28  return dphi;
29  }
30  inline double deltaPhi(float phi1, float phi2) {
32  return deltaBarePhi(Phi_mpi_pi(phi2),Phi_mpi_pi(phi1));
33  }
34  inline double deltaPhi(double phi1, double phi2) {
36  return deltaBarePhi(Phi_mpi_pi(phi2),Phi_mpi_pi(phi1));
37  }
38  template <class Vector1, class Vector2>
39  double deltaPhi( const Vector1 & v1, const Vector2 & v2) {
40  return deltaBarePhi(v1.phi(),v2.phi());
41  }
42 
43 
49  /*
50  inline bool phiLess( float phi1, float phi2) {
51  float diff = fmod(phi2 - phi1, 2.0*M_PI);
52  // float diff = phi2-phi1;
53  if ( diff < 0) diff += 2*M_PI;
54  return diff < M_PI;
55  }
56  */
57  inline bool phiLess(float phi1, float phi2) {
58  return deltaPhi(phi1,phi2)<0;
59  }
60  inline bool phiLess(double phi1, double phi2) {
61  return deltaPhi(phi1,phi2)<0;
62  }
63  template <class Vector1, class Vector2>
64  bool phiLess(const Vector1 & v1, const Vector2 & v2) {
65  return deltaPhi(v1,v2)<0.;
66  }
67 
68 
77  template <class Vector1, class Vector2>
78  double deltaR2( const Vector1 & v1, const Vector2 & v2) {
79  double dphi = deltaPhi(v1,v2);
80  double deta = v2.eta() - v1.eta();
81  return dphi*dphi + deta*deta;
82  }
83  template <class Vector1, class Vector2>
84  double deltaR( const Vector1 & v1, const Vector2 & v2) {
85  return std::sqrt( deltaR2(v1,v2));
86  }
87 
88 }
89 
90 #endif
double deltaPhi(float phi1, float phi2)
Definition: VectorUtil.h:30
double deltaBarePhi(double phi1, double phi2)
Definition: VectorUtil.h:21
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
T sqrt(T t)
Definition: SSEVec.h:28
double deltaR2(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:78
bool phiLess(float phi1, float phi2)
Definition: VectorUtil.h:57
#define M_PI
Definition: BFit3D.cc:3
double deltaR(const Vector1 &v1, const Vector2 &v2)
Definition: VectorUtil.h:84