CMS 3D CMS Logo

SOARotation.h
Go to the documentation of this file.
1 #ifndef DataFormats_GeometrySurface_SOARotation_h
2 #define DataFormats_GeometrySurface_SOARotation_h
3 
4 template <class T>
5 class TkRotation;
6 
7 // to be moved in an external common library???
8 
12 template <class T>
13 class SOARotation {
14 public:
15  constexpr inline SOARotation() {}
16 
17  constexpr inline explicit SOARotation(T) : R11(1), R12(0), R13(0), R21(0), R22(1), R23(0), R31(0), R32(0), R33(1) {}
18 
19  constexpr inline SOARotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
20  : R11(xx), R12(xy), R13(xz), R21(yx), R22(yy), R23(yz), R31(zx), R32(zy), R33(zz) {}
21 
22  constexpr inline SOARotation(const T *p)
23  : R11(p[0]), R12(p[1]), R13(p[2]), R21(p[3]), R22(p[4]), R23(p[5]), R31(p[6]), R32(p[7]), R33(p[8]) {}
24 
25  template <typename U>
27  : R11(a.xx()),
28  R12(a.xy()),
29  R13(a.xz()),
30  R21(a.yx()),
31  R22(a.yy()),
32  R23(a.yz()),
33  R31(a.zx()),
34  R32(a.zy()),
35  R33(a.zz()) {}
36 
37  constexpr inline SOARotation transposed() const { return SOARotation(R11, R21, R31, R12, R22, R32, R13, R23, R33); }
38 
39  // if frame this is to local
40  constexpr inline void multiply(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const {
41  ux = R11 * vx + R12 * vy + R13 * vz;
42  uy = R21 * vx + R22 * vy + R23 * vz;
43  uz = R31 * vx + R32 * vy + R33 * vz;
44  }
45 
46  // if frame this is to global
47  constexpr inline void multiplyInverse(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const {
48  ux = R11 * vx + R21 * vy + R31 * vz;
49  uy = R12 * vx + R22 * vy + R32 * vz;
50  uz = R13 * vx + R23 * vy + R33 * vz;
51  }
52 
53  // if frame this is to global
54  constexpr inline void multiplyInverse(T const vx, T const vy, T &ux, T &uy, T &uz) const {
55  ux = R11 * vx + R21 * vy;
56  uy = R12 * vx + R22 * vy;
57  uz = R13 * vx + R23 * vy;
58  }
59 
60  constexpr inline T const &xx() const { return R11; }
61  constexpr inline T const &xy() const { return R12; }
62  constexpr inline T const &xz() const { return R13; }
63  constexpr inline T const &yx() const { return R21; }
64  constexpr inline T const &yy() const { return R22; }
65  constexpr inline T const &yz() const { return R23; }
66  constexpr inline T const &zx() const { return R31; }
67  constexpr inline T const &zy() const { return R32; }
68  constexpr inline T const &zz() const { return R33; }
69 
70 private:
71  T R11, R12, R13;
72  T R21, R22, R23;
73  T R31, R32, R33;
74 };
75 
76 template <class T>
77 class SOAFrame {
78 public:
79  constexpr inline SOAFrame() {}
80 
81  constexpr inline SOAFrame(T ix, T iy, T iz, SOARotation<T> const &irot) : px(ix), py(iy), pz(iz), rot(irot) {}
82 
83  constexpr inline SOARotation<T> const &rotation() const { return rot; }
84 
85  constexpr inline void toLocal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const {
86  rot.multiply(vx - px, vy - py, vz - pz, ux, uy, uz);
87  }
88 
89  constexpr inline void toGlobal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const {
90  rot.multiplyInverse(vx, vy, vz, ux, uy, uz);
91  ux += px;
92  uy += py;
93  uz += pz;
94  }
95 
96  constexpr inline void toGlobal(T const vx, T const vy, T &ux, T &uy, T &uz) const {
97  rot.multiplyInverse(vx, vy, ux, uy, uz);
98  ux += px;
99  uy += py;
100  uz += pz;
101  }
102 
103  constexpr inline T x() const { return px; }
104  constexpr inline T y() const { return py; }
105  constexpr inline T z() const { return pz; }
106 
107 private:
108  T px, py, pz;
110 };
111 
112 #endif // DataFormats_GeometrySurface_SOARotation_h
constexpr SOAFrame()
Definition: SOARotation.h:79
constexpr SOARotation(const T *p)
Definition: SOARotation.h:22
constexpr T const & yy() const
Definition: SOARotation.h:64
constexpr SOARotation(const TkRotation< U > &a)
Definition: SOARotation.h:26
constexpr void toGlobal(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:96
constexpr void toLocal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:85
constexpr SOARotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: SOARotation.h:19
constexpr T const & yz() const
Definition: SOARotation.h:65
constexpr T x() const
Definition: SOARotation.h:103
constexpr void multiplyInverse(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:54
constexpr T const & xz() const
Definition: SOARotation.h:62
constexpr SOARotation transposed() const
Definition: SOARotation.h:37
SOARotation< T > rot
Definition: SOARotation.h:109
constexpr T const & zz() const
Definition: SOARotation.h:68
constexpr T const & zy() const
Definition: SOARotation.h:67
constexpr T const & yx() const
Definition: SOARotation.h:63
constexpr SOARotation()
Definition: SOARotation.h:15
constexpr void toGlobal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:89
constexpr T const & zx() const
Definition: SOARotation.h:66
constexpr T const & xx() const
Definition: SOARotation.h:60
constexpr T const & xy() const
Definition: SOARotation.h:61
constexpr T y() const
Definition: SOARotation.h:104
constexpr SOAFrame(T ix, T iy, T iz, SOARotation< T > const &irot)
Definition: SOARotation.h:81
constexpr T z() const
Definition: SOARotation.h:105
constexpr SOARotation< T > const & rotation() const
Definition: SOARotation.h:83
constexpr SOARotation(T)
Definition: SOARotation.h:17
constexpr void multiplyInverse(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:47
double a
Definition: hdecay.h:119
long double T
#define constexpr
constexpr void multiply(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:40