CMS 3D CMS Logo

Transform3DPJ.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Name: V02-02-29 $:$Id: Transform3DPJ.h,v 1.1 2007/05/27 20:12:30 pjanot Exp $
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 , LCG ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class Transform3DPJ
12 //
13 // Created by: Lorenzo Moneta October 21 2005
14 //
15 //
16 #ifndef ROOT_Math_GenVector_Transform3DPJ
17 #define ROOT_Math_GenVector_Transform3DPJ 1
18 
19 #include "Math/GenVector/Cartesian3D.h"
20 #include "Math/GenVector/DisplacementVector3D.h"
21 #include "Math/GenVector/PositionVector3D.h"
22 #include "Math/GenVector/LorentzVector.h"
23 #include "Math/GenVector/Rotation3D.h"
24 #include "Math/GenVector/AxisAnglefwd.h"
25 #include "Math/GenVector/EulerAnglesfwd.h"
26 #include "Math/GenVector/Quaternionfwd.h"
27 #include "Math/GenVector/RotationXfwd.h"
28 #include "Math/GenVector/RotationYfwd.h"
29 #include "Math/GenVector/RotationZfwd.h"
30 #include "Math/GenVector/Plane3D.h"
31 
32 #include <iostream>
33 
34 //#include "Math/Vector3Dfwd.h"
35 
36 namespace ROOT {
37 
38  namespace Math {
39 
40  using ROOT::Math::Plane3D;
41 
55  class Transform3DPJ {
56  public:
57  typedef DisplacementVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag> Vector;
58  typedef PositionVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag> Point;
59 
61  kXX = 0,
62  kXY = 1,
63  kXZ = 2,
64  kDX = 3,
65  kYX = 4,
66  kYY = 5,
67  kYZ = 6,
68  kDY = 7,
69  kZX = 8,
70  kZY = 9,
71  kZZ = 10,
72  kDZ = 11
73  };
74 
79 
84  template <class IT>
85  Transform3DPJ(IT begin, IT end) {
86  SetComponents(begin, end);
87  }
88 
92  Transform3DPJ(const Rotation3D &r, const Vector &v) { AssignFrom(r, v); }
96  Transform3DPJ(const Vector &v, const Rotation3D &r) {
97  // is equivalent from having first the rotation and then the translation vector rotated
98  AssignFrom(r, r(v));
99  }
100 
104  explicit Transform3DPJ(const Rotation3D &r) { AssignFrom(r); }
105  // convenience methods for the other rotations (cannot use templates for conflict with LA)
106  explicit Transform3DPJ(const AxisAngle &r) { AssignFrom(Rotation3D(r)); }
107  explicit Transform3DPJ(const EulerAngles &r) { AssignFrom(Rotation3D(r)); }
108  explicit Transform3DPJ(const Quaternion &r) { AssignFrom(Rotation3D(r)); }
109  // TO DO: implement direct methods for axial rotations without going through Rotation3D
110  explicit Transform3DPJ(const RotationX &r) { AssignFrom(Rotation3D(r)); }
111  explicit Transform3DPJ(const RotationY &r) { AssignFrom(Rotation3D(r)); }
112  explicit Transform3DPJ(const RotationZ &r) { AssignFrom(Rotation3D(r)); }
113 
118  template <class CoordSystem, class Tag>
119  explicit Transform3DPJ(const DisplacementVector3D<CoordSystem, Tag> &v) {
120  AssignFrom(Vector(v.X(), v.Y(), v.Z()));
121  }
126  explicit Transform3DPJ(const Vector &v) { AssignFrom(v); }
127 
128  //#if !defined(__MAKECINT__) && !defined(G__DICTIONARY) // this is ambigous with double * , double *
135  // to do : change to displacement vector3D
136  template <class ARotation, class CoordSystem, class Tag>
137  Transform3DPJ(const ARotation &r, const DisplacementVector3D<CoordSystem, Tag> &v) {
138  AssignFrom(Rotation3D(r), Vector(v.X(), v.Y(), v.Z()));
139  }
146  template <class ARotation, class CoordSystem, class Tag>
147  Transform3DPJ(const DisplacementVector3D<CoordSystem, Tag> &v, const ARotation &r) {
148  // is equivalent from having first the rotation and then the translation vector rotated
149  Rotation3D r3d(r);
150  AssignFrom(r3d, r3d(Vector(v.X(), v.Y(), v.Z())));
151  }
152 
153  //#endif
154 
168  const Point &fr0, const Point &fr1, const Point &fr2, const Point &to0, const Point &to1, const Point &to2);
169 
170  // use compiler generated copy ctor, copy assignmet and dtor
171 
178  template <class ForeignMatrix>
179  explicit Transform3DPJ(const ForeignMatrix &m) {
180  SetComponents(m);
181  }
182 
187  double xy,
188  double xz,
189  double dx,
190  double yx,
191  double yy,
192  double yz,
193  double dy,
194  double zx,
195  double zy,
196  double zz,
197  double dz) {
198  SetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
199  }
200 
207  template <class ForeignMatrix>
208  Transform3DPJ &operator=(const ForeignMatrix &m) {
209  SetComponents(m);
210  return *this;
211  }
212 
213  // ======== Components ==============
214 
219  template <class IT>
220  void SetComponents(IT begin, IT end) {
221  for (int i = 0; i < 12; ++i) {
222  fM[i] = *begin;
223  ++begin;
224  }
225  assert(end == begin);
226  }
227 
232  template <class IT>
233  void GetComponents(IT begin, IT end) const {
234  for (int i = 0; i < 12; ++i) {
235  *begin = fM[i];
236  ++begin;
237  }
238  assert(end == begin);
239  }
240 
244  template <class IT>
245  void GetComponents(IT begin) const {
246  std::copy(fM, fM + 12, begin);
247  }
248 
255  template <class ForeignMatrix>
256  void SetTransformMatrix(const ForeignMatrix &m) {
257  fM[kXX] = m(0, 0);
258  fM[kXY] = m(0, 1);
259  fM[kXZ] = m(0, 2);
260  fM[kDX] = m(0, 3);
261  fM[kYX] = m(1, 0);
262  fM[kYY] = m(1, 1);
263  fM[kYZ] = m(1, 2);
264  fM[kDY] = m(1, 3);
265  fM[kZX] = m(2, 0);
266  fM[kZY] = m(2, 1);
267  fM[kZZ] = m(2, 2);
268  fM[kDZ] = m(2, 3);
269  }
270 
276  template <class ForeignMatrix>
277  void GetTransformMatrix(ForeignMatrix &m) const {
278  m(0, 0) = fM[kXX];
279  m(0, 1) = fM[kXY];
280  m(0, 2) = fM[kXZ];
281  m(0, 3) = fM[kDX];
282  m(1, 0) = fM[kYX];
283  m(1, 1) = fM[kYY];
284  m(1, 2) = fM[kYZ];
285  m(1, 3) = fM[kDY];
286  m(2, 0) = fM[kZX];
287  m(2, 1) = fM[kZY];
288  m(2, 2) = fM[kZZ];
289  m(2, 3) = fM[kDZ];
290  }
291 
295  void SetComponents(double xx,
296  double xy,
297  double xz,
298  double dx,
299  double yx,
300  double yy,
301  double yz,
302  double dy,
303  double zx,
304  double zy,
305  double zz,
306  double dz) {
307  fM[kXX] = xx;
308  fM[kXY] = xy;
309  fM[kXZ] = xz;
310  fM[kDX] = dx;
311  fM[kYX] = yx;
312  fM[kYY] = yy;
313  fM[kYZ] = yz;
314  fM[kDY] = dy;
315  fM[kZX] = zx;
316  fM[kZY] = zy;
317  fM[kZZ] = zz;
318  fM[kDZ] = dz;
319  }
320 
324  void GetComponents(double &xx,
325  double &xy,
326  double &xz,
327  double &dx,
328  double &yx,
329  double &yy,
330  double &yz,
331  double &dy,
332  double &zx,
333  double &zy,
334  double &zz,
335  double &dz) const {
336  xx = fM[kXX];
337  xy = fM[kXY];
338  xz = fM[kXZ];
339  dx = fM[kDX];
340  yx = fM[kYX];
341  yy = fM[kYY];
342  yz = fM[kYZ];
343  dy = fM[kDY];
344  zx = fM[kZX];
345  zy = fM[kZY];
346  zz = fM[kZZ];
347  dz = fM[kDZ];
348  }
349 
353  void GetDecomposition(Rotation3D &r, Vector &v) const;
354 
355  // operations on points and vectors
356 
360  Point operator()(const Point &p) const;
361 
366  Vector operator()(const Vector &v) const;
367 
371  template <class CoordSystem>
372  PositionVector3D<CoordSystem> operator()(const PositionVector3D<CoordSystem> &p) const {
373  Point xyzNew = operator()(Point(p));
374  return PositionVector3D<CoordSystem>(xyzNew);
375  }
376 
380  template <class CoordSystem>
381  DisplacementVector3D<CoordSystem> operator()(const DisplacementVector3D<CoordSystem> &v) const {
382  Vector xyzNew = operator()(Vector(v));
383  return DisplacementVector3D<CoordSystem>(xyzNew);
384  }
385 
389  template <class CoordSystem, class Tag1, class Tag2>
390  void Transform(const PositionVector3D<CoordSystem, Tag1> &p1, PositionVector3D<CoordSystem, Tag2> &p2) const {
391  Point xyzNew = operator()(Point(p1.X(), p1.Y(), p1.Z()));
392  p2.SetXYZ(xyzNew.X(), xyzNew.Y(), xyzNew.Z());
393  }
394 
398  template <class CoordSystem, class Tag1, class Tag2>
399  void Transform(const DisplacementVector3D<CoordSystem, Tag1> &v1,
400  DisplacementVector3D<CoordSystem, Tag2> &v2) const {
401  Vector xyzNew = operator()(Vector(v1.X(), v1.Y(), v1.Z()));
402  v2.SetXYZ(xyzNew.X(), xyzNew.Y(), xyzNew.Z());
403  }
404 
408  template <class CoordSystem>
410  Vector xyzNew = operator()(Vector(q.Vect()));
411  return LorentzVector<CoordSystem>(xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E());
412  }
413 
417  Plane3D operator()(const Plane3D &plane) const;
418 
419  // skip transformation for arbitrary vectors - not really defined if point or displacement vectors
420 
421  // same but with operator *
427  template <class AVector>
428  AVector operator*(const AVector &v) const {
429  return operator()(v);
430  }
431 
436 
441  Transform3DPJ tmp(*this);
442  tmp *= t;
443  return tmp;
444  }
445 
449  void Invert();
450 
455  Transform3DPJ t(*this);
456  t.Invert();
457  return t;
458  }
459 
463  bool operator==(const Transform3DPJ &rhs) const {
464  if (fM[0] != rhs.fM[0])
465  return false;
466  if (fM[1] != rhs.fM[1])
467  return false;
468  if (fM[2] != rhs.fM[2])
469  return false;
470  if (fM[3] != rhs.fM[3])
471  return false;
472  if (fM[4] != rhs.fM[4])
473  return false;
474  if (fM[5] != rhs.fM[5])
475  return false;
476  if (fM[6] != rhs.fM[6])
477  return false;
478  if (fM[7] != rhs.fM[7])
479  return false;
480  if (fM[8] != rhs.fM[8])
481  return false;
482  if (fM[9] != rhs.fM[9])
483  return false;
484  if (fM[10] != rhs.fM[10])
485  return false;
486  if (fM[11] != rhs.fM[11])
487  return false;
488  return true;
489  }
490 
491  bool operator!=(const Transform3DPJ &rhs) const { return !operator==(rhs); }
492 
493  protected:
497  void AssignFrom(const Rotation3D &r, const Vector &v);
498 
502  void AssignFrom(const Rotation3D &r);
503 
507  void AssignFrom(const Vector &v);
508 
512  void SetIdentity();
513 
514  private:
515  double fM[12];
516  };
517 
518  // global functions
519 
520  // TODO - I/O should be put in the manipulator form
521 
522  std::ostream &operator<<(std::ostream &os, const Transform3DPJ &t);
523 
524  // need a function Transform = Translation * Rotation ???
525 
526  } // end namespace Math
527 
528 } // end namespace ROOT
529 
530 #endif /* MATHCORE_BASIC3DTRANSFORMATION */
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Vector
Definition: Transform3DPJ.h:57
void AssignFrom(const Rotation3D &r, const Vector &v)
Transform3DPJ(const Rotation3D &r)
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &q) const
void GetComponents(IT begin, IT end) const
Transform3DPJ & operator=(const ForeignMatrix &m)
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
Transform3DPJ(const DisplacementVector3D< CoordSystem, Tag > &v)
Transform3DPJ operator*(const Transform3DPJ &t) const
Transform3DPJ & operator*=(const Transform3DPJ &t)
void GetDecomposition(Rotation3D &r, Vector &v) const
Transform3DPJ(const Rotation3D &r, const Vector &v)
Definition: Transform3DPJ.h:92
assert(be >=bs)
void SetTransformMatrix(const ForeignMatrix &m)
Transform3DPJ(double xx, double xy, double xz, double dx, double yx, double yy, double yz, double dy, double zx, double zy, double zz, double dz)
void GetTransformMatrix(ForeignMatrix &m) const
std::ostream & operator<<(std::ostream &os, const Transform3DPJ &t)
Transform3DPJ(const ARotation &r, const DisplacementVector3D< CoordSystem, Tag > &v)
Transform3DPJ(const Quaternion &r)
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3DPJ.h:58
AVector operator*(const AVector &v) const
math::XYZTLorentzVector LorentzVector
void Transform(const DisplacementVector3D< CoordSystem, Tag1 > &v1, DisplacementVector3D< CoordSystem, Tag2 > &v2) const
Transform3DPJ(const RotationZ &r)
std::vector< LinkConnSpec >::const_iterator IT
Transform3DPJ(const Vector &v)
bool operator==(const Transform3DPJ &rhs) const
Transform3DPJ(const DisplacementVector3D< CoordSystem, Tag > &v, const ARotation &r)
DisplacementVector3D< CoordSystem > operator()(const DisplacementVector3D< CoordSystem > &v) const
void GetComponents(IT begin) const
AlgebraicVector EulerAngles
Definition: Definitions.h:34
void GetComponents(double &xx, double &xy, double &xz, double &dx, double &yx, double &yy, double &yz, double &dy, double &zx, double &zy, double &zz, double &dz) const
Transform3DPJ(const RotationX &r)
void SetComponents(double xx, double xy, double xz, double dx, double yx, double yy, double yz, double dy, double zx, double zy, double zz, double dz)
void SetComponents(IT begin, IT end)
Point operator()(const Point &p) const
Transform3DPJ(const RotationY &r)
Transform3DPJ(const ForeignMatrix &m)
Transform3DPJ Inverse() const
Transform3DPJ(IT begin, IT end)
Definition: Transform3DPJ.h:85
Structure Point Contains parameters of Gaussian fits to DMRs.
PositionVector3D< CoordSystem > operator()(const PositionVector3D< CoordSystem > &p) const
tmp
align.sh
Definition: createJobs.py:716
Transform3DPJ(const EulerAngles &r)
Transform3DPJ(const AxisAngle &r)
ROOT::Math::Plane3D Plane3D
Transform3DPJ(const Vector &v, const Rotation3D &r)
Definition: Transform3DPJ.h:96
bool operator!=(const Transform3DPJ &rhs) const