CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OnePiRange.h
Go to the documentation of this file.
1 #ifndef GeometryVector_Geom_OnePiRange_h
2 #define GeometryVector_Geom_OnePiRange_h
3 
5 #include <cmath>
6 
7 namespace Geom {
8 
19  template <class T>
20  class OnePiRange {
21  public:
22 
25 
27  explicit OnePiRange( const T& val) : theValue(val) { normalize(); }
28 
30  operator T() const { return theValue;}
31 
33  template <class T1> operator OnePiRange<T1>() { return OnePiRange<T1>(theValue);}
34 
36  T value() const { return theValue;}
37 
38  // Standard arithmetics
39  OnePiRange& operator+=(const T& a) {theValue+=a; normalize(); return *this;}
41 
42  OnePiRange& operator-=(const T& a) {theValue-=a; normalize(); return *this;}
44 
45  OnePiRange& operator*=(const T& a) {theValue*=a; normalize(); return *this;}
46 
47  OnePiRange& operator/=(const T& a) {theValue/=a; normalize(); return *this;}
48 
49  T degrees() const { return theValue*180./pi();}
50 
52  // No need to handle 0 or pi; in this case "inf" is returned.
53  T eta() const { return -log(tan(theValue/2.)); }
54 
55 
56  private:
57 
59 
60  void normalize() {
61  if( theValue > (T) pi() || theValue < 0) {
62  theValue = fmod( theValue, (T) pi());
63  }
64  if (theValue < 0.) theValue += pi();
65  }
66 
67  };
68 
70  template <class T>
71  inline OnePiRange<T> operator-(const OnePiRange<T>& a) {return OnePiRange<T>(-a.value());}
72 
73 
75  template <class T>
77  return OnePiRange<T>(a) += b;
78  }
80  template <class T, class Scalar>
81  inline OnePiRange<T> operator+(const OnePiRange<T>& a, const Scalar& b) {
82  return OnePiRange<T>(a) += b;
83  }
85  template <class T, class Scalar>
86  inline OnePiRange<T> operator+(const Scalar& a, const OnePiRange<T>& b) {
87  return OnePiRange<T>(b) += a;
88  }
89 
91  template <class T>
93  return OnePiRange<T>(a) -= b;
94  }
95 
97  template <class T, class Scalar>
98  inline OnePiRange<T> operator-(const OnePiRange<T>& a, const Scalar& b) {
99  return OnePiRange<T>(a) -= b;
100  }
101 
103  template <class T, class Scalar>
104  inline OnePiRange<T> operator-(const Scalar& a, const OnePiRange<T>& b) {
105  return OnePiRange<T>(a - b.value()); // use of unary operators would normalize twice
106  }
107 
109  template <class T, class Scalar>
110  inline OnePiRange<T> operator*(const OnePiRange<T>& a, const Scalar& b) {
111  return OnePiRange<T>(a) *= b;
112  }
113 
115  template <class T>
116  inline OnePiRange<T> operator*(double a, const OnePiRange<T>& b) {
117  return OnePiRange<T>(b) *= a;
118  }
119 
121  template <class T>
122  inline T operator/(const OnePiRange<T>& a, const OnePiRange<T>& b) {
123  return a.value() / b.value();
124  }
125 
127  template <class T>
128  inline OnePiRange<T> operator/(const OnePiRange<T>& a, double b) {
129  return OnePiRange<T>(a) /= b;
130  }
131 
132 }
133 #endif
T operator/(const OnePiRange< T > &a, const OnePiRange< T > &b)
Division.
Definition: OnePiRange.h:122
OnePiRange< T > operator-(const OnePiRange< T > &a)
Definition: OnePiRange.h:71
T eta() const
Return the pseudorapidity.
Definition: OnePiRange.h:53
double Scalar
Definition: Definitions.h:27
OnePiRange & operator+=(const T &a)
Definition: OnePiRange.h:39
OnePiRange & operator/=(const T &a)
Definition: OnePiRange.h:47
OnePiRange & operator+=(const OnePiRange &a)
Definition: OnePiRange.h:40
OnePiRange< T > operator+(const OnePiRange< T > &a, const OnePiRange< T > &b)
Addition.
Definition: OnePiRange.h:76
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
T value() const
Explicit access to value in case implicit conversion not OK.
Definition: OnePiRange.h:36
OnePiRange< T > operator*(const OnePiRange< T > &a, const Scalar &b)
Multiplication with scalar, does not change the precision.
Definition: OnePiRange.h:110
OnePiRange()
Default constructor does not initialise - just as double.
Definition: OnePiRange.h:24
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
OnePiRange(const T &val)
Constructor from T, does not provide automatic conversion.
Definition: OnePiRange.h:27
constexpr double pi()
Definition: Pi.h:31
OnePiRange & operator-=(const T &a)
Definition: OnePiRange.h:42
OnePiRange & operator-=(const OnePiRange &a)
Definition: OnePiRange.h:43
T degrees() const
Definition: OnePiRange.h:49
long double T
void normalize()
Definition: OnePiRange.h:60
OnePiRange & operator*=(const T &a)
Definition: OnePiRange.h:45