CMS 3D CMS Logo

sseTkRotation.h
Go to the documentation of this file.
1 #ifndef Geom_newTkRotation_H
2 #define Geom_newTkRotation_H
3 
7 
9 
10 #include <iosfwd>
11 
12 template <class T>
13 class TkRotation;
14 template <class T>
15 class TkRotation2D;
16 
17 template <class T>
18 std::ostream& operator<<(std::ostream& s, const TkRotation<T>& r);
19 template <class T>
20 std::ostream& operator<<(std::ostream& s, const TkRotation2D<T>& r);
21 
22 namespace geometryDetails {
23  void TkRotationErr1();
24  void TkRotationErr2();
25 
26 } // namespace geometryDetails
27 
31 template <class T>
32 class TkRotation {
33 public:
36 
38  TkRotation(mathSSE::Rot3<T> const& irot) : rot(irot) {}
39 
40  TkRotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) : rot(xx, xy, xz, yx, yy, yz, zx, zy, zz) {}
41 
42  TkRotation(const T* p) : rot(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]) {}
43 
44  TkRotation(const GlobalVector& aX, const GlobalVector& aY) {
45  GlobalVector uX = aX.unit();
46  GlobalVector uY = aY.unit();
47  GlobalVector uZ(uX.cross(uY));
48 
49  rot.axis[0] = uX.basicVector().v;
50  rot.axis[1] = uY.basicVector().v;
51  rot.axis[2] = uZ.basicVector().v;
52  }
53 
54  TkRotation(const BasicVector& aX, const BasicVector& aY) {
55  BasicVector uX = aX.unit();
56  BasicVector uY = aY.unit();
57  BasicVector uZ(uX.cross(uY));
58 
59  rot.axis[0] = uX.v;
60  rot.axis[1] = uY.v;
61  rot.axis[2] = uZ.v;
62  }
63 
68  TkRotation(const GlobalVector& uX, const GlobalVector& uY, const GlobalVector& uZ) {
69  rot.axis[0] = uX.basicVector().v;
70  rot.axis[1] = uY.basicVector().v;
71  rot.axis[2] = uZ.basicVector().v;
72  }
73 
74  TkRotation(const BasicVector& uX, const BasicVector& uY, const BasicVector& uZ) {
75  rot.axis[0] = uX.v;
76  rot.axis[1] = uY.v;
77  rot.axis[2] = uZ.v;
78  }
79 
88  TkRotation(const Basic3DVector<T>& axis, T phi) : rot(cos(phi), sin(phi), 0, -sin(phi), cos(phi), 0, 0, 0, 1) {
89  //rotation around the z-axis by phi
90  TkRotation tmpRotz(cos(axis.phi()), sin(axis.phi()), 0., -sin(axis.phi()), cos(axis.phi()), 0., 0., 0., 1.);
91  //rotation around y-axis by theta
92  TkRotation tmpRoty(cos(axis.theta()), 0., -sin(axis.theta()), 0., 1., 0., sin(axis.theta()), 0., cos(axis.theta()));
93  (*this) *= tmpRoty;
94  (*this) *= tmpRotz; // = this * tmpRoty * tmpRotz
95 
96  // (tmpRoty * tmpRotz)^-1 * this * tmpRoty * tmpRotz
97 
98  *this = (tmpRoty * tmpRotz).multiplyInverse(*this);
99  }
100  /* this is the same thing...derived from the CLHEP ... it gives the
101  same results MODULO the sign of the rotation.... but I don't want
102  that... had
103  TkRotation (const Basic3DVector<T>& axis, float phi) {
104  T cx = axis.x();
105  T cy = axis.y();
106  T cz = axis.z();
107 
108  T ll = axis.mag();
109  if (ll == 0) {
110  geometryDetails::TkRotationErr1();
111  }else{
112 
113  float cosa = cos(phi), sina = sin(phi);
114  cx /= ll; cy /= ll; cz /= ll;
115 
116  R11 = cosa + (1-cosa)*cx*cx;
117  R12 = (1-cosa)*cx*cy - sina*cz;
118  R13 = (1-cosa)*cx*cz + sina*cy;
119 
120  R21 = (1-cosa)*cy*cx + sina*cz;
121  R22 = cosa + (1-cosa)*cy*cy;
122  R23 = (1-cosa)*cy*cz - sina*cx;
123 
124  R31 = (1-cosa)*cz*cx - sina*cy;
125  R32 = (1-cosa)*cz*cy + sina*cx;
126  R33 = cosa + (1-cosa)*cz*cz;
127 
128  }
129 
130  }
131  */
132 
133  template <typename U>
134  TkRotation(const TkRotation<U>& a) : rot(a.xx(), a.xy(), a.xz(), a.yx(), a.yy(), a.yz(), a.zx(), a.zy(), a.zz()) {}
135 
136  TkRotation transposed() const { return rot.transpose(); }
137 
138  Basic3DVector<T> rotate(const Basic3DVector<T>& v) const { return rot.rotate(v.v); }
139 
140  Basic3DVector<T> rotateBack(const Basic3DVector<T>& v) const { return rot.rotateBack(v.v); }
141 
142  Basic3DVector<T> operator*(const Basic3DVector<T>& v) const { return rot.rotate(v.v); }
143 
144  Basic3DVector<T> multiplyInverse(const Basic3DVector<T>& v) const { return rot.rotateBack(v.v); }
145 
146  template <class Scalar>
148  return Basic3DVector<Scalar>(xx() * v.x() + yx() * v.y() + zx() * v.z(),
149  xy() * v.x() + yy() * v.y() + zy() * v.z(),
150  xz() * v.x() + yz() * v.y() + zz() * v.z());
151  }
152 
154  return Basic3DVector<T>(xx() * v.x() + xy() * v.y(), yx() * v.x() + yy() * v.y(), zx() * v.x() + zy() * v.y());
155  }
157  return Basic3DVector<T>(xx() * v.x() + yx() * v.y(), xy() * v.x() + yy() * v.y(), xz() * v.x() + yz() * v.y());
158  }
159 
160  TkRotation operator*(const TkRotation& b) const { return rot * b.rot; }
161  TkRotation multiplyInverse(const TkRotation& b) const { return rot.transpose() * b.rot; }
162 
163  TkRotation& operator*=(const TkRotation& b) { return *this = operator*(b); }
164 
165  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
166  TkRotation& transform(const TkRotation& b) { return *this = b.operator*(*this); }
167 
168  TkRotation& rotateAxes(const Basic3DVector<T>& newX, const Basic3DVector<T>& newY, const Basic3DVector<T>& newZ) {
169  T del = 0.001;
170 
171  if (
172 
173  // the check for right-handedness is not needed since
174  // we want to change the handedness when it's left in cmsim
175  //
176  // fabs(newZ.x()-w.x()) > del ||
177  // fabs(newZ.y()-w.y()) > del ||
178  // fabs(newZ.z()-w.z()) > del ||
179  fabs(newX.mag2() - 1.) > del || fabs(newY.mag2() - 1.) > del || fabs(newZ.mag2() - 1.) > del ||
180  fabs(newX.dot(newY)) > del || fabs(newY.dot(newZ)) > del || fabs(newZ.dot(newX)) > del) {
182  return *this;
183  } else {
184  return transform(
185  TkRotation(newX.x(), newY.x(), newZ.x(), newX.y(), newY.y(), newZ.y(), newX.z(), newY.z(), newZ.z()));
186  }
187  }
188 
189  Basic3DVector<T> x() const { return rot.axis[0]; }
190  Basic3DVector<T> y() const { return rot.axis[1]; }
191  Basic3DVector<T> z() const { return rot.axis[2]; }
192 
193  T xx() const { return rot.axis[0].arr[0]; }
194  T xy() const { return rot.axis[0].arr[1]; }
195  T xz() const { return rot.axis[0].arr[2]; }
196  T yx() const { return rot.axis[1].arr[0]; }
197  T yy() const { return rot.axis[1].arr[1]; }
198  T yz() const { return rot.axis[1].arr[2]; }
199  T zx() const { return rot.axis[2].arr[0]; }
200  T zy() const { return rot.axis[2].arr[1]; }
201  T zz() const { return rot.axis[2].arr[2]; }
202 
203 private:
205 };
206 
207 template <>
208 std::ostream& operator<<<float>(std::ostream& s, const TkRotation<float>& r);
209 
210 template <>
211 std::ostream& operator<<<double>(std::ostream& s, const TkRotation<double>& r);
212 
213 template <class T, class U>
215  return Basic3DVector<U>(r.xx() * v.x() + r.xy() * v.y() + r.xz() * v.z(),
216  r.yx() * v.x() + r.yy() * v.y() + r.yz() * v.z(),
217  r.zx() * v.x() + r.zy() * v.y() + r.zz() * v.z());
218 }
219 
220 template <class T, class U>
223  return RT(a.xx() * b.xx() + a.xy() * b.yx() + a.xz() * b.zx(),
224  a.xx() * b.xy() + a.xy() * b.yy() + a.xz() * b.zy(),
225  a.xx() * b.xz() + a.xy() * b.yz() + a.xz() * b.zz(),
226  a.yx() * b.xx() + a.yy() * b.yx() + a.yz() * b.zx(),
227  a.yx() * b.xy() + a.yy() * b.yy() + a.yz() * b.zy(),
228  a.yx() * b.xz() + a.yy() * b.yz() + a.yz() * b.zz(),
229  a.zx() * b.xx() + a.zy() * b.yx() + a.zz() * b.zx(),
230  a.zx() * b.xy() + a.zy() * b.yy() + a.zz() * b.zy(),
231  a.zx() * b.xz() + a.zy() * b.yz() + a.zz() * b.zz());
232 }
233 
234 template <class T>
235 class TkRotation2D {
236 public:
238 
240  TkRotation2D(mathSSE::Rot2<T> const& irot) : rot(irot) {}
241 
242  TkRotation2D(T xx, T xy, T yx, T yy) : rot(xx, xy, yx, yy) {}
243 
244  TkRotation2D(const T* p) : rot(p[0], p[1], p[2], p[3]) {}
245 
247  BasicVector uX = aX.unit();
248  BasicVector uY(-uX.y(), uX.x());
249 
250  rot.axis[0] = uX.v;
251  rot.axis[1] = uY.v;
252  }
253 
254  TkRotation2D(const BasicVector& uX, const BasicVector& uY) {
255  rot.axis[0] = uX.v;
256  rot.axis[1] = uY.v;
257  }
258 
259  BasicVector x() const { return rot.axis[0]; }
260  BasicVector y() const { return rot.axis[1]; }
261 
262  TkRotation2D transposed() const { return rot.transpose(); }
263 
264  BasicVector rotate(const BasicVector& v) const { return rot.rotate(v.v); }
265 
266  BasicVector rotateBack(const BasicVector& v) const { return rot.rotateBack(v.v); }
267 
268 private:
270 };
271 
272 template <>
273 std::ostream& operator<<<float>(std::ostream& s, const TkRotation2D<float>& r);
274 
275 template <>
276 std::ostream& operator<<<double>(std::ostream& s, const TkRotation2D<double>& r);
277 
278 #endif
Vector3DBase
Definition: Vector3DBase.h:8
TkRotation::TkRotation
TkRotation(mathSSE::Rot3< T > const &irot)
Definition: sseTkRotation.h:38
TkRotation
Definition: extTkRotation.h:13
Basic3DVector::theta
Geom::Theta< T > theta() const
Definition: extBasic3DVector.h:139
TkRotation::zy
T zy() const
Definition: extTkRotation.h:258
TkRotation::rotateBack
Basic3DVector< T > rotateBack(const Basic3DVector< T > &v) const
Definition: sseTkRotation.h:140
TkRotation2D::TkRotation2D
TkRotation2D(T xx, T xy, T yx, T yy)
Definition: sseTkRotation.h:242
TkRotation::TkRotation
TkRotation(const BasicVector &aX, const BasicVector &aY)
Definition: sseTkRotation.h:54
TkRotation::operator*=
TkRotation & operator*=(const TkRotation &b)
Definition: sseTkRotation.h:163
mathSSE::Rot3
Definition: SSERot.h:16
TkRotation2D::TkRotation2D
TkRotation2D(mathSSE::Rot2< T > const &irot)
Definition: sseTkRotation.h:240
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
operator<<<double >
std::ostream & operator<<<double >(std::ostream &s, const TkRotation< double > &r)
Definition: TkRotation.cc:12
TkRotation2D::x
BasicVector x() const
Definition: sseTkRotation.h:259
Basic2DVector::v
Vec2< T > v
Definition: extBasic2DVector.h:156
Basic3DVector.h
TkRotation::TkRotation
TkRotation(const GlobalVector &uX, const GlobalVector &uY, const GlobalVector &uZ)
Definition: sseTkRotation.h:68
TkRotation2D::rotateBack
BasicVector rotateBack(const BasicVector &v) const
Definition: sseTkRotation.h:266
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
Definition: extTkRotation.h:178
TkRotation2D
Definition: extTkRotation.h:14
TkRotation::operator*
TkRotation operator*(const TkRotation &b) const
Definition: sseTkRotation.h:160
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Basic3DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: extBasic3DVector.h:113
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
TkRotation2D::TkRotation2D
TkRotation2D()
Definition: sseTkRotation.h:239
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Basic3DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic3DVector.h:97
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic2DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic2DVector.h:67
TkRotation::operator*
Basic3DVector< T > operator*(const Basic2DVector< T > &v) const
Definition: sseTkRotation.h:153
geometryDetails::TkRotationErr2
void TkRotationErr2()
Definition: TkRotation.cc:30
TkRotation::xz
T xz() const
Definition: extTkRotation.h:253
Basic3DVector::cross
Basic3DVector cross(const Basic3DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: extBasic3DVector.h:203
Basic3DVector::dot
T dot(const Basic3DVector &rh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic3DVector.h:189
Basic2DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic2DVector.h:64
TkRotation::TkRotation
TkRotation(const BasicVector &uX, const BasicVector &uY, const BasicVector &uZ)
Definition: sseTkRotation.h:74
TkRotation::TkRotation
TkRotation(const T *p)
Definition: sseTkRotation.h:42
b
double b
Definition: hdecay.h:118
TkRotation::TkRotation
TkRotation(const GlobalVector &aX, const GlobalVector &aY)
Definition: sseTkRotation.h:44
TkRotation2D::rotate
BasicVector rotate(const BasicVector &v) const
Definition: sseTkRotation.h:264
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
TkRotation::yx
T yx() const
Definition: extTkRotation.h:254
Basic2DVector
Definition: extBasic2DVector.h:15
operator*
Basic3DVector< U > operator*(const TkRotation< T > &r, const Basic3DVector< U > &v)
Definition: sseTkRotation.h:214
TkRotation2D::BasicVector
Basic2DVector< T > BasicVector
Definition: sseTkRotation.h:237
TkRotation::multiplyInverse
TkRotation multiplyInverse(const TkRotation &b) const
Definition: sseTkRotation.h:161
operator<<
std::ostream & operator<<(std::ostream &s, const TkRotation< T > &r)
TkRotation::BasicVector
Basic3DVector< T > BasicVector
Definition: sseTkRotation.h:35
a
double a
Definition: hdecay.h:119
operator<<<float >
std::ostream & operator<<<float >(std::ostream &s, const TkRotation< float > &r)
Definition: TkRotation.cc:5
TkRotation::xx
T xx() const
Definition: extTkRotation.h:251
TkRotation2D::rot
Rot2< T > rot
Definition: extTkRotation.h:350
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
TkRotation::TkRotation
TkRotation(const Basic3DVector< T > &axis, T phi)
Definition: sseTkRotation.h:88
TkRotation::xy
T xy() const
Definition: extTkRotation.h:252
Vector3DBase::cross
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
TkRotation::transform
TkRotation & transform(const TkRotation &b)
Definition: sseTkRotation.h:166
TkRotation::zz
T zz() const
Definition: extTkRotation.h:259
TkRotation2D::TkRotation2D
TkRotation2D(const BasicVector &aX)
Definition: sseTkRotation.h:246
geometryDetails
Definition: extTkRotation.h:21
Basic2DVector::unit
Basic2DVector unit() const
Definition: extBasic2DVector.h:88
Basic3DVector::v
Vec4< T > v
Definition: extBasic3DVector.h:217
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
TkRotation::y
Basic3DVector< T > y() const
Definition: sseTkRotation.h:190
geometryDetails::TkRotationErr1
void TkRotationErr1()
Definition: TkRotation.cc:29
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TkRotation::yz
T yz() const
Definition: extTkRotation.h:256
TkRotation::rotate
Basic3DVector< T > rotate(const Basic3DVector< T > &v) const
Definition: sseTkRotation.h:138
DDAxes::phi
TkRotation::TkRotation
TkRotation(const TkRotation< U > &a)
Definition: sseTkRotation.h:134
TkRotation::rotateAxes
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
Definition: sseTkRotation.h:168
Basic2DVector.h
T
long double T
Definition: Basic3DVectorLD.h:48
TkRotation::yy
T yy() const
Definition: extTkRotation.h:255
TkRotation::TkRotation
TkRotation()
Definition: sseTkRotation.h:37
SSERot.h
GlobalVector.h
Basic3DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic3DVector.h:94
TkRotation::transposed
TkRotation transposed() const
Definition: sseTkRotation.h:136
TkRotation::x
Basic3DVector< T > x() const
Definition: sseTkRotation.h:189
TkRotation::GlobalVector
Vector3DBase< T, GlobalTag > GlobalVector
Definition: sseTkRotation.h:34
TkRotation2D::y
BasicVector y() const
Definition: sseTkRotation.h:260
TkRotation::TkRotation
TkRotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: sseTkRotation.h:40
TkRotation::rot
Rot3< T > rot
Definition: extTkRotation.h:263
TkRotation::zx
T zx() const
Definition: extTkRotation.h:257
mathSSE::Rot2
Definition: SSERot.h:99
Basic3DVector::z
T z() const
Cartesian z coordinate.
Definition: extBasic3DVector.h:100
Basic3DVector::unit
Basic3DVector unit() const
Definition: extBasic3DVector.h:151
Basic3DVector::phi
Geom::Phi< T > phi() const
Definition: extBasic3DVector.h:132
TkRotation2D::transposed
TkRotation2D transposed() const
Definition: sseTkRotation.h:262
TkRotation2D::TkRotation2D
TkRotation2D(const BasicVector &uX, const BasicVector &uY)
Definition: sseTkRotation.h:254
Basic3DVector
Definition: extBasic3DVector.h:30
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
TkRotation::z
Basic3DVector< T > z() const
Definition: sseTkRotation.h:191
TkRotation2D::TkRotation2D
TkRotation2D(const T *p)
Definition: sseTkRotation.h:244
TkRotation::multiplyInverse
Basic3DVector< Scalar > multiplyInverse(const Basic3DVector< Scalar > &v) const
Definition: sseTkRotation.h:147
TkRotation::operator*
Basic3DVector< T > operator*(const Basic3DVector< T > &v) const
Definition: sseTkRotation.h:142
TkRotation::multiplyInverse
Basic3DVector< T > multiplyInverse(const Basic2DVector< T > &v) const
Definition: sseTkRotation.h:156