CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oldTkRotation.h
Go to the documentation of this file.
1 #ifndef Geom_oldTkRotation_H
2 #define Geom_oldTkRotation_H
3 
7 /*
8 #include "DataFormats/GeometrySurface/interface/GlobalError.h"
9 #include "DataFormats/GeometrySurface/interface/LocalError.h"
10 */
11 #include <iosfwd>
12 
13 template <class T> class TkRotation;
14 
15 template <class T>
16 std::ostream & operator<<( std::ostream& s, const TkRotation<T>& r);
17 
18 namespace geometryDetails {
19  void TkRotationErr1();
20  void TkRotationErr2();
21 
22 }
23 
24 
28 template <class T>
29 class TkRotation {
30 public:
32 
34  R11( 1), R12( 0), R13( 0),
35  R21( 0), R22( 1), R23( 0),
36  R31( 0), R32( 0), R33( 1) {}
37 
38  TkRotation( T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz) :
39  R11(xx), R12(xy), R13(xz),
40  R21(yx), R22(yy), R23(yz),
41  R31(zx), R32(zy), R33(zz) {}
42 
43  TkRotation( const T* p) :
44  R11(p[0]), R12(p[1]), R13(p[2]),
45  R21(p[3]), R22(p[4]), R23(p[5]),
46  R31(p[6]), R32(p[7]), R33(p[8]) {}
47 
48  TkRotation( const GlobalVector & aX, const GlobalVector & aY) {
49 
50  GlobalVector uX = aX.unit();
51  GlobalVector uY = aY.unit();
52  GlobalVector uZ(uX.cross(uY));
53 
54  R11 = uX.x(); R12 = uX.y(); R13 = uX.z();
55  R21 = uY.x(); R22 = uY.y(); R23 = uY.z();
56  R31 = uZ.x(); R32 = uZ.y(); R33 = uZ.z();
57 
58  }
59 
64  TkRotation( const GlobalVector & aX, const GlobalVector & aY,
65  const GlobalVector & aZ) :
66  R11( aX.x()), R12( aX.y()), R13( aX.z()),
67  R21( aY.x()), R22( aY.y()), R23( aY.z()),
68  R31( aZ.x()), R32( aZ.y()), R33( aZ.z()) {}
69 
70 
79  TkRotation( const Basic3DVector<T>& axis, T phi) :
80  R11( cos(phi) ), R12( sin(phi)), R13( 0),
81  R21( -sin(phi)), R22( cos(phi)), R23( 0),
82  R31( 0), R32( 0), R33( 1) {
83 
84  //rotation around the z-axis by phi
85  TkRotation tmpRotz ( cos(axis.phi()), sin(axis.phi()), 0.,
86  -sin(axis.phi()), cos(axis.phi()), 0.,
87  0., 0., 1. );
88  //rotation around y-axis by theta
89  TkRotation tmpRoty ( cos(axis.theta()), 0.,-sin(axis.theta()),
90  0., 1., 0.,
91  sin(axis.theta()), 0., cos(axis.theta()) );
92  (*this)*=tmpRoty;
93  (*this)*=tmpRotz; // = this * tmpRoty * tmpRotz
94 
95  // (tmpRoty * tmpRotz)^-1 * this * tmpRoty * tmpRotz
96 
97  *this = (tmpRoty*tmpRotz).multiplyInverse(*this);
98 
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>
135  R11(a.xx()), R12(a.xy()), R13(a.xz()),
136  R21(a.yx()), R22(a.yy()), R23(a.yz()),
137  R31(a.zx()), R32(a.zy()), R33(a.zz()) {}
138 
140  return TkRotation( R11, R21, R31,
141  R12, R22, R32,
142  R13, R23, R33);
143  }
144 
146  return Basic3DVector<T>( R11*v.x() + R12*v.y() + R13*v.z(),
147  R21*v.x() + R22*v.y() + R23*v.z(),
148  R31*v.x() + R32*v.y() + R33*v.z());
149  }
150 
152  return Basic3DVector<T>( R11*v.x() + R21*v.y() + R31*v.z(),
153  R12*v.x() + R22*v.y() + R32*v.z(),
154  R13*v.x() + R23*v.y() + R33*v.z());
155  }
156 
157 #ifndef CMS_NO_TEMPLATE_MEMBERS
158  template <class Scalar>
160  return Basic3DVector<Scalar>( R11*v.x() + R21*v.y() + R31*v.z(),
161  R12*v.x() + R22*v.y() + R32*v.z(),
162  R13*v.x() + R23*v.y() + R33*v.z());
163  }
164 #endif
165 
167  return Basic3DVector<T>( R11*v.x() + R12*v.y(),
168  R21*v.x() + R22*v.y(),
169  R31*v.x() + R32*v.y());
170  }
172  return Basic3DVector<T>( R11*v.x() + R21*v.y(),
173  R12*v.x() + R22*v.y(),
174  R13*v.x() + R23*v.y());
175  }
176 
177 
178 
179  TkRotation operator*( const TkRotation& b) const {
180  return TkRotation(R11*b.R11 + R12*b.R21 + R13*b.R31,
181  R11*b.R12 + R12*b.R22 + R13*b.R32,
182  R11*b.R13 + R12*b.R23 + R13*b.R33,
183  R21*b.R11 + R22*b.R21 + R23*b.R31,
184  R21*b.R12 + R22*b.R22 + R23*b.R32,
185  R21*b.R13 + R22*b.R23 + R23*b.R33,
186  R31*b.R11 + R32*b.R21 + R33*b.R31,
187  R31*b.R12 + R32*b.R22 + R33*b.R32,
188  R31*b.R13 + R32*b.R23 + R33*b.R33);
189  }
190 
192  return TkRotation(R11*b.R11 + R21*b.R21 + R31*b.R31,
193  R11*b.R12 + R21*b.R22 + R31*b.R32,
194  R11*b.R13 + R21*b.R23 + R31*b.R33,
195  R12*b.R11 + R22*b.R21 + R32*b.R31,
196  R12*b.R12 + R22*b.R22 + R32*b.R32,
197  R12*b.R13 + R22*b.R23 + R32*b.R33,
198  R13*b.R11 + R23*b.R21 + R33*b.R31,
199  R13*b.R12 + R23*b.R22 + R33*b.R32,
200  R13*b.R13 + R23*b.R23 + R33*b.R33);
201  }
202 
204  return *this = operator * (b);
205  }
206 
207  // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
209  return *this = b.operator * (*this);
210  }
211 
213  const Basic3DVector<T>& newY,
214  const Basic3DVector<T>& newZ) {
215  T del = 0.001;
216 
217  if (
218 
219  // the check for right-handedness is not needed since
220  // we want to change the handedness when it's left in cmsim
221  //
222  // fabs(newZ.x()-w.x()) > del ||
223  // fabs(newZ.y()-w.y()) > del ||
224  // fabs(newZ.z()-w.z()) > del ||
225  fabs(newX.mag2()-1.) > del ||
226  fabs(newY.mag2()-1.) > del ||
227  fabs(newZ.mag2()-1.) > del ||
228  fabs(newX.dot(newY)) > del ||
229  fabs(newY.dot(newZ)) > del ||
230  fabs(newZ.dot(newX)) > del) {
232  return *this;
233  } else {
234  return transform(TkRotation(newX.x(), newY.x(), newZ.x(),
235  newX.y(), newY.y(), newZ.y(),
236  newX.z(), newY.z(), newZ.z()));
237  }
238  }
239 
240  Basic3DVector<T> x() const { return Basic3DVector<T>(xx(),xy(),xz());}
241  Basic3DVector<T> y() const { return Basic3DVector<T>(yx(),yy(),yz());}
242  Basic3DVector<T> z() const { return Basic3DVector<T>(zx(),zy(),zz());}
243 
244 
245  T const &xx() const { return R11;}
246  T const &xy() const { return R12;}
247  T const &xz() const { return R13;}
248  T const &yx() const { return R21;}
249  T const &yy() const { return R22;}
250  T const &yz() const { return R23;}
251  T const &zx() const { return R31;}
252  T const &zy() const { return R32;}
253  T const &zz() const { return R33;}
254 
255 private:
256 
260 };
261 
262 
263 template<>
264 std::ostream & operator<< <float>( std::ostream& s, const TkRotation<float>& r);
265 
266 template<>
267 std::ostream & operator<< <double>( std::ostream& s, const TkRotation<double>& r);
268 
269 
270 template <class T, class U>
272  return Basic3DVector<U>( r.xx()*v.x() + r.xy()*v.y() + r.xz()*v.z(),
273  r.yx()*v.x() + r.yy()*v.y() + r.yz()*v.z(),
274  r.zx()*v.x() + r.zy()*v.y() + r.zz()*v.z());
275 }
276 
277 template <class T, class U>
281  return RT( a.xx()*b.xx() + a.xy()*b.yx() + a.xz()*b.zx(),
282  a.xx()*b.xy() + a.xy()*b.yy() + a.xz()*b.zy(),
283  a.xx()*b.xz() + a.xy()*b.yz() + a.xz()*b.zz(),
284  a.yx()*b.xx() + a.yy()*b.yx() + a.yz()*b.zx(),
285  a.yx()*b.xy() + a.yy()*b.yy() + a.yz()*b.zy(),
286  a.yx()*b.xz() + a.yy()*b.yz() + a.yz()*b.zz(),
287  a.zx()*b.xx() + a.zy()*b.yx() + a.zz()*b.zx(),
288  a.zx()*b.xy() + a.zy()*b.yy() + a.zz()*b.zy(),
289  a.zx()*b.xz() + a.zy()*b.yz() + a.zz()*b.zz());
290 }
291 
292 #endif
293 
294 
295 
296 
T xx() const
Basic3DVector< T > z() const
Basic3DVector< T > operator*(const Basic3DVector< T > &v) const
TkRotation(const GlobalVector &aX, const GlobalVector &aY)
Definition: oldTkRotation.h:48
std::ostream & operator<< < float >(std::ostream &s, const TkRotation< float > &r)
Definition: TkRotation.cc:5
T y() const
Cartesian y coordinate.
T const & xy() const
T x() const
Cartesian x coordinate.
Basic3DVector< T > y() const
TkRotation(const GlobalVector &aX, const GlobalVector &aY, const GlobalVector &aZ)
Definition: oldTkRotation.h:64
TkRotation(const Basic3DVector< T > &axis, T phi)
Definition: oldTkRotation.h:79
TkRotation & transform(const TkRotation &b)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
TkRotation operator*(const TkRotation &b) const
T y() const
Definition: PV3DBase.h:62
T yx() const
Basic3DVector< Scalar > multiplyInverse(const Basic3DVector< Scalar > &v) const
Vector3DBase< T, GlobalTag > GlobalVector
Definition: oldTkRotation.h:31
T const & yz() const
TkRotation multiplyInverse(const TkRotation &b) const
Geom::Phi< T > phi() const
TkRotation(const TkRotation< U > &a)
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
Basic3DVector< T > x() const
T zx() const
T xy() const
T zz() const
T const & xx() const
T const & yx() const
T z() const
Cartesian z coordinate.
TkRotation(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Definition: oldTkRotation.h:38
Basic3DVector< T > operator*(const Basic2DVector< T > &v) const
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Basic3DVector< T > multiplyInverse(const Basic2DVector< T > &v) const
void TkRotationErr2()
Definition: TkRotation.cc:32
T zy() const
T const & yy() const
T const & zy() const
T yy() const
T y() const
Cartesian y coordinate.
void TkRotationErr1()
Definition: TkRotation.cc:29
Vector3DBase unit() const
Definition: Vector3DBase.h:57
TkRotation & operator*=(const TkRotation &b)
std::ostream & operator<< < double >(std::ostream &s, const TkRotation< double > &r)
Definition: TkRotation.cc:12
double b
Definition: hdecay.h:120
T const & zx() const
double a
Definition: hdecay.h:121
T xz() const
TkRotation transposed() const
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
T const & xz() const
TkRotation(const T *p)
Definition: oldTkRotation.h:43
long double T
T x() const
Definition: PV3DBase.h:61
T yz() const
mathSSE::Vec4< T > v
T x() const
Cartesian x coordinate.
T const & zz() const
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T dot(const Basic3DVector &rh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
Definition: DDAxes.h:10