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> class TkRotation;
5 
6 // to be moved in an external common library???
7 
11 template <class T>
12 class SOARotation {
13 public:
14 
15  constexpr inline
17 
18  constexpr inline
19  explicit SOARotation(T) :
20  R11(1), R12(0), R13(0),
21  R21(0), R22(1), R23(0),
22  R31(0), R32(0), R33(1) {}
23 
24  constexpr inline
25  SOARotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) :
26  R11(xx), R12(xy), R13(xz),
27  R21(yx), R22(yy), R23(yz),
28  R31(zx), R32(zy), R33(zz) {}
29 
30  constexpr inline
31  SOARotation(const T* p) :
32  R11(p[0]), R12(p[1]), R13(p[2]),
33  R21(p[3]), R22(p[4]), R23(p[5]),
34  R31(p[6]), R32(p[7]), R33(p[8]) {}
35 
36 
37  template <typename U>
38  constexpr inline
40  R11(a.xx()), R12(a.xy()), R13(a.xz()),
41  R21(a.yx()), R22(a.yy()), R23(a.yz()),
42  R31(a.zx()), R32(a.zy()), R33(a.zz()) {}
43 
44  constexpr inline
46  return SOARotation(R11, R21, R31,
47  R12, R22, R32,
48  R13, R23, R33);
49  }
50 
51  // if frame this is to local
52  constexpr inline
53  void multiply(T const vx, T const vy, T const vz,
54  T & ux, T & uy, T & uz) const {
55  ux = R11*vx + R12*vy + R13*vz;
56  uy = R21*vx + R22*vy + R23*vz;
57  uz = R31*vx + R32*vy + R33*vz;
58  }
59 
60  // if frame this is to global
61  constexpr inline
62  void multiplyInverse (T const vx, T const vy, T const vz,
63  T & ux, T & uy, T & uz) const {
64  ux = R11*vx + R21*vy + R31*vz;
65  uy = R12*vx + R22*vy + R32*vz;
66  uz = R13*vx + R23*vy + R33*vz;
67  }
68 
69 
70  // if frame this is to global
71  constexpr inline
72  void multiplyInverse (T const vx, T const vy,
73  T & ux, T & uy, T & uz) const {
74  ux = R11*vx + R21*vy;
75  uy = R12*vx + R22*vy;
76  uz = R13*vx + R23*vy;
77  }
78 
79 
80  constexpr inline
81  T const &xx() const { return R11; }
82  constexpr inline
83  T const &xy() const { return R12; }
84  constexpr inline
85  T const &xz() const { return R13; }
86  constexpr inline
87  T const &yx() const { return R21; }
88  constexpr inline
89  T const &yy() const { return R22; }
90  constexpr inline
91  T const &yz() const { return R23; }
92  constexpr inline
93  T const &zx() const { return R31; }
94  constexpr inline
95  T const &zy() const { return R32; }
96  constexpr inline
97  T const &zz() const { return R33; }
98 
99 private:
100 
104 };
105 
106 
107 template <class T>
108 class SOAFrame {
109 public:
110 
111  constexpr inline
113 
114  constexpr inline
115  SOAFrame(T ix, T iy, T iz, SOARotation<T> const & irot) :
116  px(ix), py(iy), pz(iz), rot(irot){}
117 
118  constexpr inline
119  SOARotation<T> const & rotation() const { return rot; }
120 
121  constexpr inline
122  void toLocal(T const vx, T const vy, T const vz,
123  T & ux, T & uy, T & uz) const {
124  rot.multiply(vx-px, vy-py, vz-pz, ux, uy, uz);
125  }
126 
127 
128  constexpr inline
129  void toGlobal(T const vx, T const vy, T const vz,
130  T & ux, T & uy, T & uz) const {
131  rot.multiplyInverse(vx, vy, vz, ux, uy, uz);
132  ux+=px; uy+=py; uz+=pz;
133  }
134 
135  constexpr inline
136  void toGlobal(T const vx, T const vy,
137  T & ux, T & uy, T & uz) const {
138  rot.multiplyInverse(vx, vy, ux, uy, uz);
139  ux+=px; uy+=py; uz+=pz;
140  }
141 
142 
143  constexpr inline
144  T x() const { return px; }
145  constexpr inline
146  T y() const { return py; }
147  constexpr inline
148  T z() const { return pz; }
149 
150 private:
151 
152  T px, py, pz;
154 
155 };
156 
157 #endif // DataFormats_GeometrySurface_SOARotation_h
constexpr SOAFrame()
Definition: SOARotation.h:112
constexpr SOARotation(const T *p)
Definition: SOARotation.h:31
constexpr T const & yy() const
Definition: SOARotation.h:89
constexpr SOARotation(const TkRotation< U > &a)
Definition: SOARotation.h:39
constexpr void toGlobal(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:136
constexpr void toLocal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:122
constexpr SOARotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: SOARotation.h:25
constexpr T const & yz() const
Definition: SOARotation.h:91
constexpr T x() const
Definition: SOARotation.h:144
constexpr void multiplyInverse(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:72
constexpr T const & xz() const
Definition: SOARotation.h:85
constexpr SOARotation transposed() const
Definition: SOARotation.h:45
SOARotation< T > rot
Definition: SOARotation.h:153
constexpr T const & zz() const
Definition: SOARotation.h:97
constexpr T const & zy() const
Definition: SOARotation.h:95
constexpr T const & yx() const
Definition: SOARotation.h:87
constexpr SOARotation()
Definition: SOARotation.h:16
constexpr void toGlobal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:129
constexpr T const & zx() const
Definition: SOARotation.h:93
constexpr T const & xx() const
Definition: SOARotation.h:81
constexpr T const & xy() const
Definition: SOARotation.h:83
constexpr T y() const
Definition: SOARotation.h:146
constexpr SOAFrame(T ix, T iy, T iz, SOARotation< T > const &irot)
Definition: SOARotation.h:115
constexpr T z() const
Definition: SOARotation.h:148
constexpr SOARotation< T > const & rotation() const
Definition: SOARotation.h:119
constexpr SOARotation(T)
Definition: SOARotation.h:19
constexpr void multiplyInverse(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:62
double a
Definition: hdecay.h:121
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:53