CMS 3D CMS Logo

CoordinateSets.h
Go to the documentation of this file.
1 #ifndef GeometryVector_Geom_CoordinateSets_h
2 #define GeometryVector_Geom_CoordinateSets_h
3 
4 #include <cmath>
5 
6 namespace Geom {
7 
13  template <typename T>
15  public:
17  Polar2Cartesian(const T& r, const T& phi) : r_(r), phi_(phi) {}
18 
19  const T& r() const { return r_; }
20  const T& phi() const { return phi_; }
21 
22  T x() const { return r_ * cos(phi_); }
23  T y() const { return r_ * sin(phi_); }
24 
25  private:
26  T r_;
28  };
29 
33  template <typename T>
35  public:
39  Cylindrical2Cartesian(const T& r, const T& phi, const T& z) : r_(r), phi_(phi), z_(z) {}
40 
41  const T& r() const { return r_; }
42  const T& phi() const { return phi_; }
43  const T& z() const { return z_; }
44 
45  T x() const { return r_ * cos(phi_); }
46  T y() const { return r_ * sin(phi_); }
47 
48  private:
49  T r_;
51  T z_;
52  };
53 
57  template <typename T>
59  public:
63  Spherical2Cartesian(const T& theta, const T& phi, const T& mag)
64  : theta_(theta), phi_(phi), r_(mag), transv_(sin(theta) * mag) {}
65 
66  const T& theta() const { return theta_; }
67  const T& phi() const { return phi_; }
68  const T& r() const { return r_; }
69 
70  T x() const { return transv_ * cos(phi()); }
71  T y() const { return transv_ * sin(phi()); }
72  T z() const { return cos(theta()) * r(); }
73 
74  private:
77  T r_;
79  };
80 
84  template <typename T>
86  public:
87  Cartesian2Cartesian3D(const T& x, const T& y, const T& z) : x_(x), y_(y), z_(z) {}
88 
89  const T& x() const { return x_; }
90  const T& y() const { return y_; }
91  const T& z() const { return z_; }
92 
93  private:
94  T x_;
95  T y_;
96  T z_;
97  };
98 } // namespace Geom
99 
100 #endif
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Spherical2Cartesian(const T &theta, const T &phi, const T &mag)
Cartesian2Cartesian3D(const T &x, const T &y, const T &z)
Polar2Cartesian(const T &r, const T &phi)
Construct from radius and polar angle.
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const T & phi() const
const T & theta() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const T & r() const
long double T
Cylindrical2Cartesian(const T &r, const T &phi, const T &z)
const T & phi() const