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