00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ROOT_Math_GenVector_Transform3DPJ
00017 #define ROOT_Math_GenVector_Transform3DPJ 1
00018
00019
00020
00021 #include "Math/GenVector/Cartesian3D.h"
00022 #include "Math/GenVector/DisplacementVector3D.h"
00023 #include "Math/GenVector/PositionVector3D.h"
00024 #include "Math/GenVector/LorentzVector.h"
00025 #include "Math/GenVector/Rotation3D.h"
00026 #include "Math/GenVector/AxisAnglefwd.h"
00027 #include "Math/GenVector/EulerAnglesfwd.h"
00028 #include "Math/GenVector/Quaternionfwd.h"
00029 #include "Math/GenVector/RotationXfwd.h"
00030 #include "Math/GenVector/RotationYfwd.h"
00031 #include "Math/GenVector/RotationZfwd.h"
00032
00033 #include <iostream>
00034
00035
00036
00037
00038
00039 namespace ROOT {
00040
00041 namespace Math {
00042
00043 class Plane3D;
00044
00045
00046
00060 class Transform3DPJ {
00061
00062
00063 public:
00064
00065 typedef DisplacementVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > Vector;
00066 typedef PositionVector3D<Cartesian3D<double>, DefaultCoordinateSystemTag > Point;
00067
00068
00069 enum ETransform3DMatrixIndex {
00070 kXX = 0, kXY = 1, kXZ = 2, kDX = 3,
00071 kYX = 4, kYY = 5, kYZ = 6, kDY = 7,
00072 kZX = 8, kZY = 9, kZZ =10, kDZ = 11
00073 };
00074
00075
00076
00080 Transform3DPJ()
00081 {
00082 SetIdentity();
00083 }
00084
00089 template<class IT>
00090 Transform3DPJ(IT begin, IT end)
00091 {
00092 SetComponents(begin,end);
00093 }
00094
00098 Transform3DPJ( const Rotation3D & r, const Vector & v)
00099 {
00100 AssignFrom( r, v );
00101 }
00105 Transform3DPJ( const Vector & v, const Rotation3D & r)
00106 {
00107
00108 AssignFrom( r, r(v) );
00109 }
00110
00114 explicit Transform3DPJ( const Rotation3D & r) {
00115 AssignFrom(r);
00116 }
00117
00118 explicit Transform3DPJ( const AxisAngle & r) {
00119 AssignFrom(Rotation3D(r));
00120 }
00121 explicit Transform3DPJ( const EulerAngles & r) {
00122 AssignFrom(Rotation3D(r));
00123 }
00124 explicit Transform3DPJ( const Quaternion & r) {
00125 AssignFrom(Rotation3D(r));
00126 }
00127
00128 explicit Transform3DPJ( const RotationX & r) {
00129 AssignFrom(Rotation3D(r));
00130 }
00131 explicit Transform3DPJ( const RotationY & r) {
00132 AssignFrom(Rotation3D(r));
00133 }
00134 explicit Transform3DPJ( const RotationZ & r) {
00135 AssignFrom(Rotation3D(r));
00136 }
00137
00142 template<class CoordSystem, class Tag>
00143 explicit Transform3DPJ( const DisplacementVector3D<CoordSystem,Tag> & v) {
00144 AssignFrom(Vector(v.X(),v.Y(),v.Z()));
00145 }
00150 explicit Transform3DPJ( const Vector & v) {
00151 AssignFrom(v);
00152 }
00153
00154
00155
00156
00163
00164 template <class ARotation, class CoordSystem, class Tag>
00165 Transform3DPJ( const ARotation & r, const DisplacementVector3D<CoordSystem,Tag> & v)
00166 {
00167 AssignFrom( Rotation3D(r), Vector (v.X(),v.Y(),v.Z()) );
00168 }
00175 template <class ARotation, class CoordSystem, class Tag>
00176 Transform3DPJ(const DisplacementVector3D<CoordSystem,Tag> & v , const ARotation & r)
00177 {
00178
00179 Rotation3D r3d(r);
00180 AssignFrom( r3d, r3d( Vector(v.X(),v.Y(),v.Z()) ) );
00181 }
00182
00183
00184
00197 Transform3DPJ
00198 (const Point & fr0, const Point & fr1, const Point & fr2,
00199 const Point & to0, const Point & to1, const Point & to2 );
00200
00201
00202
00203
00210 template<class ForeignMatrix>
00211 explicit Transform3DPJ(const ForeignMatrix & m) {
00212 SetComponents(m);
00213 }
00214
00218 Transform3DPJ(double xx, double xy, double xz, double dx,
00219 double yx, double yy, double yz, double dy,
00220 double zx, double zy, double zz, double dz)
00221 {
00222 SetComponents (xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
00223 }
00224
00225
00232 template<class ForeignMatrix>
00233 Transform3DPJ & operator= (const ForeignMatrix & m) {
00234 SetComponents(m);
00235 return *this;
00236 }
00237
00238
00239
00240
00241
00246 template<class IT>
00247 void SetComponents(IT begin, IT end) {
00248 for (int i = 0; i <12; ++i) {
00249 fM[i] = *begin;
00250 ++begin;
00251 }
00252 assert (end==begin);
00253 }
00254
00259 template<class IT>
00260 void GetComponents(IT begin, IT end) const {
00261 for (int i = 0; i <12; ++i) {
00262 *begin = fM[i];
00263 ++begin;
00264 }
00265 assert (end==begin);
00266 }
00267
00271 template<class IT>
00272 void GetComponents(IT begin) const {
00273 std::copy ( fM, fM+12, begin );
00274 }
00275
00282 template<class ForeignMatrix>
00283 void
00284 SetTransformMatrix (const ForeignMatrix & m) {
00285 fM[kXX]=m(0,0); fM[kXY]=m(0,1); fM[kXZ]=m(0,2); fM[kDX]=m(0,3);
00286 fM[kYX]=m(1,0); fM[kYY]=m(1,1); fM[kYZ]=m(1,2); fM[kDY]=m(1,3);
00287 fM[kZX]=m(2,0); fM[kZY]=m(2,1); fM[kZZ]=m(2,2); fM[kDZ]=m(2,3);
00288 }
00289
00295 template<class ForeignMatrix>
00296 void
00297 GetTransformMatrix (ForeignMatrix & m) const {
00298 m(0,0)=fM[kXX]; m(0,1)=fM[kXY]; m(0,2)=fM[kXZ]; m(0,3)=fM[kDX];
00299 m(1,0)=fM[kYX]; m(1,1)=fM[kYY]; m(1,2)=fM[kYZ]; m(1,3)=fM[kDY];
00300 m(2,0)=fM[kZX]; m(2,1)=fM[kZY]; m(2,2)=fM[kZZ]; m(2,3)=fM[kDZ];
00301 }
00302
00303
00307 void
00308 SetComponents (double xx, double xy, double xz, double dx,
00309 double yx, double yy, double yz, double dy,
00310 double zx, double zy, double zz, double dz) {
00311 fM[kXX]=xx; fM[kXY]=xy; fM[kXZ]=xz; fM[kDX]=dx;
00312 fM[kYX]=yx; fM[kYY]=yy; fM[kYZ]=yz; fM[kDY]=dy;
00313 fM[kZX]=zx; fM[kZY]=zy; fM[kZZ]=zz; fM[kDZ]=dz;
00314 }
00315
00319 void
00320 GetComponents (double &xx, double &xy, double &xz, double &dx,
00321 double &yx, double &yy, double &yz, double &dy,
00322 double &zx, double &zy, double &zz, double &dz) const {
00323 xx=fM[kXX]; xy=fM[kXY]; xz=fM[kXZ]; dx=fM[kDX];
00324 yx=fM[kYX]; yy=fM[kYY]; yz=fM[kYZ]; dy=fM[kDY];
00325 zx=fM[kZX]; zy=fM[kZY]; zz=fM[kZZ]; dz=fM[kDZ];
00326 }
00327
00328
00329
00333 void GetDecomposition(Rotation3D &r, Vector &v) const;
00334
00335
00336
00337
00338
00342 Point operator() (const Point & p) const;
00343
00344
00349 Vector operator() (const Vector & v) const;
00350
00351
00355 template<class CoordSystem >
00356 PositionVector3D<CoordSystem> operator() (const PositionVector3D <CoordSystem> & p) const {
00357 Point xyzNew = operator() ( Point(p) );
00358 return PositionVector3D<CoordSystem> (xyzNew);
00359 }
00360
00364 template<class CoordSystem >
00365 DisplacementVector3D<CoordSystem> operator() (const DisplacementVector3D <CoordSystem> & v) const {
00366 Vector xyzNew = operator() ( Vector(v) );
00367 return DisplacementVector3D<CoordSystem> (xyzNew);
00368 }
00369
00373 template<class CoordSystem, class Tag1, class Tag2 >
00374 void Transform (const PositionVector3D <CoordSystem,Tag1> & p1, PositionVector3D <CoordSystem,Tag2> & p2 ) const {
00375 Point xyzNew = operator() ( Point(p1.X(), p1.Y(), p1.Z()) );
00376 p2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
00377 }
00378
00379
00383 template<class CoordSystem, class Tag1, class Tag2 >
00384 void Transform (const DisplacementVector3D <CoordSystem,Tag1> & v1, DisplacementVector3D <CoordSystem,Tag2> & v2 ) const {
00385 Vector xyzNew = operator() ( Vector(v1.X(), v1.Y(), v1.Z() ) );
00386 v2.SetXYZ( xyzNew.X(), xyzNew.Y(), xyzNew.Z() );
00387 }
00388
00392 template <class CoordSystem >
00393 LorentzVector<CoordSystem> operator() (const LorentzVector<CoordSystem> & q) const {
00394 Vector xyzNew = operator() ( Vector(q.Vect() ) );
00395 return LorentzVector<CoordSystem> (xyzNew.X(), xyzNew.Y(), xyzNew.Z(), q.E() );
00396 }
00397
00401 Plane3D operator() (const Plane3D & plane) const;
00402
00403
00404
00405
00406
00412 template<class AVector >
00413 AVector operator * (const AVector & v) const {
00414 return operator() (v);
00415 }
00416
00417
00418
00422 Transform3DPJ & operator *= (const Transform3DPJ & t);
00423
00427 Transform3DPJ operator * (const Transform3DPJ & t) const {
00428 Transform3DPJ tmp(*this);
00429 tmp*= t;
00430 return tmp;
00431 }
00432
00436 void Invert();
00437
00441 Transform3DPJ Inverse() const {
00442 Transform3DPJ t(*this);
00443 t.Invert();
00444 return t;
00445 }
00446
00447
00451 bool operator == (const Transform3DPJ & rhs) const {
00452 if( fM[0] != rhs.fM[0] ) return false;
00453 if( fM[1] != rhs.fM[1] ) return false;
00454 if( fM[2] != rhs.fM[2] ) return false;
00455 if( fM[3] != rhs.fM[3] ) return false;
00456 if( fM[4] != rhs.fM[4] ) return false;
00457 if( fM[5] != rhs.fM[5] ) return false;
00458 if( fM[6] != rhs.fM[6] ) return false;
00459 if( fM[7] != rhs.fM[7] ) return false;
00460 if( fM[8] != rhs.fM[8] ) return false;
00461 if( fM[9] != rhs.fM[9] ) return false;
00462 if( fM[10]!= rhs.fM[10] ) return false;
00463 if( fM[11]!= rhs.fM[11] ) return false;
00464 return true;
00465 }
00466
00467 bool operator != (const Transform3DPJ & rhs) const {
00468 return ! operator==(rhs);
00469 }
00470
00471
00472 protected:
00473
00477 void AssignFrom( const Rotation3D & r, const Vector & v);
00478
00482 void AssignFrom( const Rotation3D & r);
00483
00487 void AssignFrom( const Vector & v);
00488
00492 void SetIdentity() ;
00493
00494 private:
00495
00496
00497 double fM[12];
00498
00499 };
00500
00501
00502
00503
00504
00505
00506 std::ostream & operator<< (std::ostream & os, const Transform3DPJ & t);
00507
00508
00509
00510
00511
00512
00513
00514
00515 }
00516
00517 }
00518
00519
00520 #endif