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>
26  constexpr inline SOARotation(const TkRotation<U> &a)
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 void toGlobal(T cxx, T cxy, T cyy, T *gl) const {
104  auto const &r = rot;
105  gl[0] = r.xx() * (r.xx() * cxx + r.yx() * cxy) + r.yx() * (r.xx() * cxy + r.yx() * cyy);
106  gl[1] = r.xx() * (r.xy() * cxx + r.yy() * cxy) + r.yx() * (r.xy() * cxy + r.yy() * cyy);
107  gl[2] = r.xy() * (r.xy() * cxx + r.yy() * cxy) + r.yy() * (r.xy() * cxy + r.yy() * cyy);
108  gl[3] = r.xx() * (r.xz() * cxx + r.yz() * cxy) + r.yx() * (r.xz() * cxy + r.yz() * cyy);
109  gl[4] = r.xy() * (r.xz() * cxx + r.yz() * cxy) + r.yy() * (r.xz() * cxy + r.yz() * cyy);
110  gl[5] = r.xz() * (r.xz() * cxx + r.yz() * cxy) + r.yz() * (r.xz() * cxy + r.yz() * cyy);
111  }
112 
113  constexpr inline void toLocal(T const *ge, T &lxx, T &lxy, T &lyy) const {
114  auto const &r = rot;
115 
116  T cxx = ge[0];
117  T cyx = ge[1];
118  T cyy = ge[2];
119  T czx = ge[3];
120  T czy = ge[4];
121  T czz = ge[5];
122 
123  lxx = r.xx() * (r.xx() * cxx + r.xy() * cyx + r.xz() * czx) +
124  r.xy() * (r.xx() * cyx + r.xy() * cyy + r.xz() * czy) + r.xz() * (r.xx() * czx + r.xy() * czy + r.xz() * czz);
125  lxy = r.yx() * (r.xx() * cxx + r.xy() * cyx + r.xz() * czx) +
126  r.yy() * (r.xx() * cyx + r.xy() * cyy + r.xz() * czy) + r.yz() * (r.xx() * czx + r.xy() * czy + r.xz() * czz);
127  lyy = r.yx() * (r.yx() * cxx + r.yy() * cyx + r.yz() * czx) +
128  r.yy() * (r.yx() * cyx + r.yy() * cyy + r.yz() * czy) + r.yz() * (r.yx() * czx + r.yy() * czy + r.yz() * czz);
129  }
130 
131  constexpr inline T x() const { return px; }
132  constexpr inline T y() const { return py; }
133  constexpr inline T z() const { return pz; }
134 
135 private:
136  T px, py, pz;
138 };
139 
140 #endif // DataFormats_GeometrySurface_SOARotation_h
TkRotation
Definition: extTkRotation.h:13
SOARotation::SOARotation
constexpr SOARotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: SOARotation.h:19
SOARotation::multiplyInverse
constexpr void multiplyInverse(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:47
SOAFrame::toLocal
constexpr void toLocal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:85
SOAFrame::rotation
constexpr const SOARotation< T > & rotation() const
Definition: SOARotation.h:83
SOARotation::R21
T R21
Definition: SOARotation.h:72
SOAFrame::toGlobal
constexpr void toGlobal(T cxx, T cxy, T cyy, T *gl) const
Definition: SOARotation.h:103
SOAFrame::pz
T pz
Definition: SOARotation.h:136
SOARotation::SOARotation
constexpr SOARotation(const TkRotation< U > &a)
Definition: SOARotation.h:26
SOAFrame::toGlobal
constexpr void toGlobal(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:96
SOARotation::xz
constexpr const T & xz() const
Definition: SOARotation.h:62
SOARotation::R13
T R13
Definition: SOARotation.h:71
SOARotation::R33
T R33
Definition: SOARotation.h:73
SOAFrame::py
T py
Definition: SOARotation.h:136
SOARotation::R22
T R22
Definition: SOARotation.h:72
SOARotation::zz
constexpr const T & zz() const
Definition: SOARotation.h:68
SOARotation::yz
constexpr const T & yz() const
Definition: SOARotation.h:65
SOARotation::R23
T R23
Definition: SOARotation.h:72
SOAFrame::x
constexpr T x() const
Definition: SOARotation.h:131
SOAFrame::SOAFrame
constexpr SOAFrame()
Definition: SOARotation.h:79
SOARotation::SOARotation
constexpr SOARotation()
Definition: SOARotation.h:15
a
double a
Definition: hdecay.h:119
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SOARotation::zy
constexpr const T & zy() const
Definition: SOARotation.h:67
SOARotation
Definition: SOARotation.h:13
SOAFrame::toGlobal
constexpr void toGlobal(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:89
SOARotation::yx
constexpr const T & yx() const
Definition: SOARotation.h:63
SOAFrame::y
constexpr T y() const
Definition: SOARotation.h:132
SOARotation::R11
T R11
Definition: SOARotation.h:71
SOAFrame
Definition: SOARotation.h:77
alignCSCRings.r
r
Definition: alignCSCRings.py:93
SOARotation::zx
constexpr const T & zx() const
Definition: SOARotation.h:66
SOARotation::xy
constexpr const T & xy() const
Definition: SOARotation.h:61
SOARotation::SOARotation
constexpr SOARotation(T)
Definition: SOARotation.h:17
T
long double T
Definition: Basic3DVectorLD.h:48
SOAFrame::SOAFrame
constexpr SOAFrame(T ix, T iy, T iz, SOARotation< T > const &irot)
Definition: SOARotation.h:81
SOARotation::multiplyInverse
constexpr void multiplyInverse(T const vx, T const vy, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:54
SOARotation::SOARotation
constexpr SOARotation(const T *p)
Definition: SOARotation.h:22
SOARotation::R32
T R32
Definition: SOARotation.h:73
SOARotation::xx
constexpr const T & xx() const
Definition: SOARotation.h:60
SOARotation::yy
constexpr const T & yy() const
Definition: SOARotation.h:64
SOARotation::transposed
constexpr SOARotation transposed() const
Definition: SOARotation.h:37
SOAFrame::rot
SOARotation< T > rot
Definition: SOARotation.h:137
SOAFrame::z
constexpr T z() const
Definition: SOARotation.h:133
SOARotation::multiply
constexpr void multiply(T const vx, T const vy, T const vz, T &ux, T &uy, T &uz) const
Definition: SOARotation.h:40
SOARotation::R31
T R31
Definition: SOARotation.h:73
SOARotation::R12
T R12
Definition: SOARotation.h:71
SOAFrame::px
T px
Definition: SOARotation.h:136
SOAFrame::toLocal
constexpr void toLocal(T const *ge, T &lxx, T &lxy, T &lyy) const
Definition: SOARotation.h:113