CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 
21 #include "Math/GenVector/Cartesian3D.h"
22 #include "Math/GenVector/DisplacementVector3D.h"
23 #include "Math/GenVector/PositionVector3D.h"
24 #include "Math/GenVector/LorentzVector.h"
25 #include "Math/GenVector/Rotation3D.h"
26 #include "Math/GenVector/AxisAnglefwd.h"
27 #include "Math/GenVector/EulerAnglesfwd.h"
28 #include "Math/GenVector/Quaternionfwd.h"
29 #include "Math/GenVector/RotationXfwd.h"
30 #include "Math/GenVector/RotationYfwd.h"
31 #include "Math/GenVector/RotationZfwd.h"
32 
33 #include <iostream>
34 
35 //#include "Math/Vector3Dfwd.h"
36 
37 
38 
39 namespace ROOT {
40 
41  namespace Math {
42 
43  class Plane3D;
44 
45 
46 
60  class Transform3DPJ {
61 
62 
63  public:
64 
65  typedef DisplacementVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > Vector;
66  typedef PositionVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > Point;
67 
68 
70  kXX = 0, kXY = 1, kXZ = 2, kDX = 3,
71  kYX = 4, kYY = 5, kYZ = 6, kDY = 7,
72  kZX = 8, kZY = 9, kZZ =10, kDZ = 11
73  };
74 
75 
76 
81  {
82  SetIdentity();
83  }
84 
89  template<class IT>
91  {
92  SetComponents(begin,end);
93  }
94 
98  Transform3DPJ( const Rotation3D & r, const Vector & v)
99  {
100  AssignFrom( r, v );
101  }
105  Transform3DPJ( const Vector & v, const Rotation3D & r)
106  {
107  // is equivalent from having first the rotation and then the translation vector rotated
108  AssignFrom( r, r(v) );
109  }
110 
114  explicit Transform3DPJ( const Rotation3D & r) {
115  AssignFrom(r);
116  }
117  // convenience methods for the other rotations (cannot use templates for conflict with LA)
118  explicit Transform3DPJ( const AxisAngle & r) {
119  AssignFrom(Rotation3D(r));
120  }
121  explicit Transform3DPJ( const EulerAngles & r) {
122  AssignFrom(Rotation3D(r));
123  }
124  explicit Transform3DPJ( const Quaternion & r) {
125  AssignFrom(Rotation3D(r));
126  }
127  // TO DO: implement direct methods for axial rotations without going through Rotation3D
128  explicit Transform3DPJ( const RotationX & r) {
129  AssignFrom(Rotation3D(r));
130  }
131  explicit Transform3DPJ( const RotationY & r) {
132  AssignFrom(Rotation3D(r));
133  }
134  explicit Transform3DPJ( const RotationZ & r) {
135  AssignFrom(Rotation3D(r));
136  }
137 
142  template<class CoordSystem, class Tag>
143  explicit Transform3DPJ( const DisplacementVector3D<CoordSystem,Tag> & v) {
144  AssignFrom(Vector(v.X(),v.Y(),v.Z()));
145  }
150  explicit Transform3DPJ( const Vector & v) {
151  AssignFrom(v);
152  }
153 
154 
155 
156  //#if !defined(__MAKECINT__) && !defined(G__DICTIONARY) // this is ambigous with double * , double *
163  // to do : change to displacement vector3D
164  template <class ARotation, class CoordSystem, class Tag>
165  Transform3DPJ( const ARotation & r, const DisplacementVector3D<CoordSystem,Tag> & v)
166  {
167  AssignFrom( Rotation3D(r), Vector (v.X(),v.Y(),v.Z()) );
168  }
175  template <class ARotation, class CoordSystem, class Tag>
176  Transform3DPJ(const DisplacementVector3D<CoordSystem,Tag> & v , const ARotation & r)
177  {
178  // is equivalent from having first the rotation and then the translation vector rotated
179  Rotation3D r3d(r);
180  AssignFrom( r3d, r3d( Vector(v.X(),v.Y(),v.Z()) ) );
181  }
182 
183  //#endif
184 
198  (const Point & fr0, const Point & fr1, const Point & fr2,
199  const Point & to0, const Point & to1, const Point & to2 );
200 
201 
202  // use compiler generated copy ctor, copy assignmet and dtor
203 
210  template<class ForeignMatrix>
211  explicit Transform3DPJ(const ForeignMatrix & m) {
212  SetComponents(m);
213  }
214 
218  Transform3DPJ(double xx, double xy, double xz, double dx,
219  double yx, double yy, double yz, double dy,
220  double zx, double zy, double zz, double dz)
221  {
222  SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
223  }
224 
225 
232  template<class ForeignMatrix>
233  Transform3DPJ & operator= (const ForeignMatrix & m) {
234  SetComponents(m);
235  return *this;
236  }
237 
238 
239  // ======== Components ==============
240 
241 
246  template<class IT>
248  for (int i = 0; i <12; ++i) {
249  fM[i] = *begin;
250  ++begin;
251  }
252  assert (end==begin);
253  }
254 
259  template<class IT>
260  void GetComponents(IT begin, IT end) const {
261  for (int i = 0; i <12; ++i) {
262  *begin = fM[i];
263  ++begin;
264  }
265  assert (end==begin);
266  }
267 
271  template<class IT>
272  void GetComponents(IT begin) const {
273  std::copy ( fM, fM+12, begin );
274  }
275 
282  template<class ForeignMatrix>
283  void
284  SetTransformMatrix (const ForeignMatrix & m) {
285  fM[kXX]=m(0,0); fM[kXY]=m(0,1); fM[kXZ]=m(0,2); fM[kDX]=m(0,3);
286  fM[kYX]=m(1,0); fM[kYY]=m(1,1); fM[kYZ]=m(1,2); fM[kDY]=m(1,3);
287  fM[kZX]=m(2,0); fM[kZY]=m(2,1); fM[kZZ]=m(2,2); fM[kDZ]=m(2,3);
288  }
289 
295  template<class ForeignMatrix>
296  void
297  GetTransformMatrix (ForeignMatrix & m) const {
298  m(0,0)=fM[kXX]; m(0,1)=fM[kXY]; m(0,2)=fM[kXZ]; m(0,3)=fM[kDX];
299  m(1,0)=fM[kYX]; m(1,1)=fM[kYY]; m(1,2)=fM[kYZ]; m(1,3)=fM[kDY];
300  m(2,0)=fM[kZX]; m(2,1)=fM[kZY]; m(2,2)=fM[kZZ]; m(2,3)=fM[kDZ];
301  }
302 
303 
307  void
308  SetComponents (double xx, double xy, double xz, double dx,
309  double yx, double yy, double yz, double dy,
310  double zx, double zy, double zz, double dz) {
311  fM[kXX]=xx; fM[kXY]=xy; fM[kXZ]=xz; fM[kDX]=dx;
312  fM[kYX]=yx; fM[kYY]=yy; fM[kYZ]=yz; fM[kDY]=dy;
313  fM[kZX]=zx; fM[kZY]=zy; fM[kZZ]=zz; fM[kDZ]=dz;
314  }
315 
319  void
320  GetComponents (double &xx, double &xy, double &xz, double &dx,
321  double &yx, double &yy, double &yz, double &dy,
322  double &zx, double &zy, double &zz, double &dz) const {
323  xx=fM[kXX]; xy=fM[kXY]; xz=fM[kXZ]; dx=fM[kDX];
324  yx=fM[kYX]; yy=fM[kYY]; yz=fM[kYZ]; dy=fM[kDY];
325  zx=fM[kZX]; zy=fM[kZY]; zz=fM[kZZ]; dz=fM[kDZ];
326  }
327 
328 
329 
333  void GetDecomposition(Rotation3D &r, Vector &v) const;
334 
335 
336 
337  // operations on points and vectors
338 
342  Point operator() (const Point & p) const;
343 
344 
349  Vector operator() (const Vector & v) const;
350 
351 
355  template<class CoordSystem >
356  PositionVector3D<CoordSystem> operator() (const PositionVector3D <CoordSystem> & p) const {
357  Point xyzNew = operator() ( Point(p) );
358  return PositionVector3D<CoordSystem> (xyzNew);
359  }
360 
364  template<class CoordSystem >
365  DisplacementVector3D<CoordSystem> operator() (const DisplacementVector3D <CoordSystem> & v) const {
366  Vector xyzNew = operator() ( Vector(v) );
367  return DisplacementVector3D<CoordSystem> (xyzNew);
368  }
369 
373  template<class CoordSystem, class Tag1, class Tag2 >
374  void Transform (const PositionVector3D <CoordSystem,Tag1> & p1, PositionVector3D <CoordSystem,Tag2> & p2 ) const {
375  Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) );
376  p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
377  }
378 
379 
383  template<class CoordSystem, class Tag1, class Tag2 >
384  void Transform (const DisplacementVector3D <CoordSystem,Tag1> & v1, DisplacementVector3D <CoordSystem,Tag2> & v2 ) const {
385  Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) );
386  v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
387  }
388 
392  template <class CoordSystem >
394  Vector xyzNew = operator() ( Vector(q.Vect() ) );
395  return LorentzVector<CoordSystem> (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() );
396  }
397 
401  Plane3D operator() (const Plane3D & plane) const;
402 
403 
404  // skip transformation for arbitrary vectors - not really defined if point or displacement vectors
405 
406  // same but with operator *
412  template<class AVector >
413  AVector operator * (const AVector & v) const {
414  return operator() (v);
415  }
416 
417 
418 
423 
428  Transform3DPJ tmp(*this);
429  tmp*= t;
430  return tmp;
431  }
432 
436  void Invert();
437 
442  Transform3DPJ t(*this);
443  t.Invert();
444  return t;
445  }
446 
447 
451  bool operator == (const Transform3DPJ & rhs) const {
452  if( fM[0] != rhs.fM[0] ) return false;
453  if( fM[1] != rhs.fM[1] ) return false;
454  if( fM[2] != rhs.fM[2] ) return false;
455  if( fM[3] != rhs.fM[3] ) return false;
456  if( fM[4] != rhs.fM[4] ) return false;
457  if( fM[5] != rhs.fM[5] ) return false;
458  if( fM[6] != rhs.fM[6] ) return false;
459  if( fM[7] != rhs.fM[7] ) return false;
460  if( fM[8] != rhs.fM[8] ) return false;
461  if( fM[9] != rhs.fM[9] ) return false;
462  if( fM[10]!= rhs.fM[10] ) return false;
463  if( fM[11]!= rhs.fM[11] ) return false;
464  return true;
465  }
466 
467  bool operator != (const Transform3DPJ & rhs) const {
468  return ! operator==(rhs);
469  }
470 
471 
472  protected:
473 
477  void AssignFrom( const Rotation3D & r, const Vector & v);
478 
482  void AssignFrom( const Rotation3D & r);
483 
487  void AssignFrom( const Vector & v);
488 
492  void SetIdentity() ;
493 
494  private:
495 
496 
497  double fM[12];
498 
499  };
500 
501 
502  // global functions
503 
504  // TODO - I/O should be put in the manipulator form
505 
506  std::ostream & operator<< (std::ostream & os, const Transform3DPJ & t);
507 
508  // need a function Transform = Translation * Rotation ???
509 
510 
511 
512 
513 
514 
515  } // end namespace Math
516 
517 } // end namespace ROOT
518 
519 
520 #endif /* MATHCORE_BASIC3DTRANSFORMATION */
void AssignFrom(const Rotation3D &r, const Vector &v)
int i
Definition: DBlmapReader.cc:9
PositionVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Point
Definition: Transform3DPJ.h:66
Transform3DPJ(const Rotation3D &r)
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > Vector
Definition: Transform3DPJ.h:65
Transform3DPJ & operator=(const ForeignMatrix &m)
bool operator!=(const Transform3DPJ &rhs) const
bool operator==(const Transform3DPJ &rhs) const
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
Transform3DPJ(const DisplacementVector3D< CoordSystem, Tag > &v)
math::XYZTLorentzVector LorentzVector
void GetTransformMatrix(ForeignMatrix &m) const
Transform3DPJ & operator*=(const Transform3DPJ &t)
Transform3DPJ(const Rotation3D &r, const Vector &v)
Definition: Transform3DPJ.h:98
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 Transform(const DisplacementVector3D< CoordSystem, Tag1 > &v1, DisplacementVector3D< CoordSystem, Tag2 > &v2) const
std::ostream & operator<<(std::ostream &os, const Transform3DPJ &t)
Transform3DPJ(const ARotation &r, const DisplacementVector3D< CoordSystem, Tag > &v)
Transform3DPJ(const Quaternion &r)
math::XYZPoint Point
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
#define end
Definition: vmac.h:37
Transform3DPJ(const RotationZ &r)
std::vector< LinkConnSpec >::const_iterator IT
Transform3DPJ(const Vector &v)
double p2[4]
Definition: TauolaWrapper.h:90
Transform3DPJ(const DisplacementVector3D< CoordSystem, Tag > &v, const ARotation &r)
void GetComponents(IT begin) const
AlgebraicVector EulerAngles
Definition: Definitions.h:36
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)
void GetDecomposition(Rotation3D &r, Vector &v) const
Transform3DPJ(const RotationY &r)
Transform3DPJ(const ForeignMatrix &m)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Transform3DPJ(IT begin, IT end)
Definition: Transform3DPJ.h:90
#define begin
Definition: vmac.h:30
Transform3DPJ Inverse() const
double p1[4]
Definition: TauolaWrapper.h:89
void Transform(const PositionVector3D< CoordSystem, Tag1 > &p1, PositionVector3D< CoordSystem, Tag2 > &p2) const
void GetComponents(IT begin, IT end) const
Transform3DPJ(const EulerAngles &r)
Transform3DPJ(const AxisAngle &r)
AVector operator*(const AVector &v) const
ROOT::Math::Plane3D Plane3D
Point operator()(const Point &p) const
Transform3DPJ(const Vector &v, const Rotation3D &r)