31 using namespace ROOT::Math;
32 using namespace ROOT::Math::VectorUtil;
51 int compare(
double v1,
double v2,
const std::string &
name =
"",
double scale = 1.0) {
57 double delta = v2 - v1;
59 if (delta < 0 ) delta = - delta;
60 if (v1 == 0 || v2 == 0) {
71 if ( delta/d > eps && delta > eps )
78 int pr = std::cout.precision (18);
79 std::cout <<
"\nDiscrepancy in " <<
name <<
"() : " << v1 <<
" != " << v2 <<
" discr = " << int(delta/d/eps)
80 <<
" (Allowed discrepancy is " << eps <<
")\n";
81 std::cout.precision (pr);
87 template<
class Transform>
88 bool IsEqual(
const Transform &
t1,
const Transform & t2,
unsigned int size) {
90 std::vector<double>
x1(size);
91 std::vector<double>
x2(size);
92 t1.GetComponents(x1.begin(), x1.end() );
93 t2.GetComponents(x2.begin(), x2.end() );
96 while (ret && i < size) {
99 ( std::abs(x1[i]) + std::abs(x2[i] ) );
110 std::cout <<
"testing Vector3D \t:\t";
123 double r = vg.
Dot(vpg);
127 iret |=
compare(vcross.R(), 0.0,
"cross",10 );
137 iret |=
compare(vg3.R(), 2*vg.
R() );
140 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
145 #ifdef TEST_COMPILE_ERROR
156 if (iret == 0) std::cout <<
"\t\t\t\t\tOK\n";
157 else std::cout <<
"\t\t\t\tFAILED\n";
169 std::cout <<
"testing Point3D \t:\t";
186 double r = pg.
Dot(vg);
191 iret |=
compare(pcross.
R(), 0.0,
"cross",10 );
194 iret |=
compare(pg3.R(), 2*pg.
R() );
197 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
200 #ifdef TEST_COMPILE_ERROR
218 if (iret == 0) std::cout <<
"\t\t\t\t\tOK\n";
219 else std::cout <<
"\t\t\t\tFAILED\n";
237 std::cout <<
"testing Vector2D \t:\t";
250 double r = vg.
Dot(vpg);
257 iret |=
compare(vg3.R(), 2*vg.
R() );
260 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
265 iret |=
compare(vg.
Phi(), vpg.Phi() + angle );
277 #ifdef TEST_COMPILE_ERROR
287 if (iret == 0) std::cout <<
"\t\t\t\tOK\n";
288 else std::cout <<
"\t\t\tFAILED\n";
306 std::cout <<
"testing Point2D \t:\t";
323 double r = pg.
Dot(vg);
332 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
335 #ifdef TEST_COMPILE_ERROR
356 iret |=
compare(pg.Phi(), ppg.Phi() + angle );
357 iret |=
compare(pg.R(), ppg.R() );
366 if (iret == 0) std::cout <<
"\t\t\t\tOK\n";
367 else std::cout <<
"\t\t\tFAILED\n";
378 std::cout <<
"testing 3D Rotations\t:\t";
388 iret |=
compare(vg2.
R(), vg.
R(),
"rot3D" );
391 iret |=
compare(pg2.X(), vg2.
X(),
"x diff");
392 iret |=
compare(pg2.Y(), vg2.
Y(),
"y diff");
393 iret |=
compare(pg2.Z(), vg2.
Z(),
"z diff");
399 iret |=
compare(pg2.X(), vg2.
X(),
"x diff",10);
400 iret |=
compare(pg2.Y(), vg2.
Y(),
"y diff",10);
401 iret |=
compare(pg2.Z(), vg2.
Z(),
"z diff",10);
405 iret |=
compare(vpg2.X(), vg2.
X(),
"x diff",10 );
406 iret |=
compare(vpg2.Y(), vg2.
Y(),
"y diff",10 );
407 iret |=
compare(vpg2.Z(), vg2.
Z(),
"z diff",10 );
411 iret |=
compare(pg2.X(), vg2.
X(),
"x diff",10 );
412 iret |=
compare(pg2.Y(), vg2.
Y(),
"y diff",10 );
413 iret |=
compare(pg2.Z(), vg2.
Z(),
"z diff",10 );
416 iret |=
compare(vpg2.X(), vg2.
X(),
"x diff",10 );
417 iret |=
compare(vpg2.Y(), vg2.
Y(),
"y diff",10 );
418 iret |=
compare(vpg2.Z(), vg2.
Z(),
"z diff",10 );
423 iret |=
compare(vpg2.X(), vg2.
X(),
"x diff",10 );
424 iret |=
compare(vpg2.Y(), vg2.
Y(),
"y diff",10 );
425 iret |=
compare(vpg2.Z(), vg2.
Z(),
"z diff",10 );
430 iret |=
compare(vpg2.X(), vg2.
X(),
"x diff",10 );
431 iret |=
compare(vpg2.Y(), vg2.
Y(),
"y diff",10 );
432 iret |=
compare(vpg2.Z(), vg2.
Z(),
"z diff",10 );
442 for (
int i = 0; i < 9; ++i) {
443 iret |=
compare(r1[i],r2[i],
"Get/SetComponents");
453 iret |=
compare( (rot2==rot),
true,
"Get/SetRotMatrix");
459 bool comp = (rotInv == rot );
460 iret |=
compare(comp,
true,
"inversion");
466 iret |=
compare(qr1.
X(), qr2.
X(),
"x diff",10 );
467 iret |=
compare(qr1.
Y(), qr2.
Y(),
"y diff",10 );
468 iret |=
compare(qr1.
Z(), qr2.
Z(),
"z diff",10 );
471 if (iret == 0) std::cout <<
"\tOK\n";
472 else std::cout <<
"\t FAILED\n";
481 std::cout <<
"testing 3D Transform\t:\t";
492 iret |=
compare(pg.
X(), v.
X(),
"x diff",10 );
493 iret |=
compare(pg.
Y(), v.
Y(),
"y diff",10 );
494 iret |=
compare(pg.
Z(), v.
Z(),
"z diff",10 );
522 #if !defined(__i386__)
523 iret |=
compare(tr1 ==tr2, 1,
"eq transl",1 );
527 iret |=
compare(0, 0,
"dummy test",1 );
532 iret |=
compare(vp2.
X(), v.X(),
"x diff",10 );
533 iret |=
compare(vp2.
Y(), v.Y(),
"y diff",10 );
534 iret |=
compare(vp2.
Z(), v.Z(),
"z diff",10 );
551 t2b.GetDecomposition(rrr,vvv);
552 iret |=
compare(Rotation3D(r) ==rrr, 1,
"eq transf rot",1 );
553 iret |=
compare( tr1.
Vect() == vvv, 1,
"eq transf vec",1 );
558 t2b.GetDecomposition(rrr,ttt);
559 iret |=
compare( tr1 == ttt, 1,
"eq transf trans",1 );
564 t2b.GetDecomposition(err2,vvv2);
569 iret |=
compare( v == vvv2, 1,
"eq transf g vec",1 );
574 iret |=
compare( t4.
Rotation() == Rotation3D(rzyx), 1,
"eq trans rzyx",1 );
577 iret |=
compare( trf2 == t2b, 1,
"trasl * e rot",1 );
588 Transform3D t6(rzyx, rzyx * Translation3D(v).Vect() );
590 iret |=
compare( trf6 == t6, 1,
"rzyx * transl",1 );
591 if (iret) std::cout << t6 <<
"\n---\n" << trf6 << std::endl;
597 iret |=
compare(
IsEqual(trf7,trf6,12),
true,
"tranf * transl",1 );
599 iret |=
compare( trf8 == trf5, 1,
"trans * transf",1 );
602 iret |=
compare( trf9 == trf5, 1,
"tranf * rzyx",1 );
604 iret |=
compare( trf10 == trf6, 1,
"rzyx * transf",1 );
605 Transform3D trf11 = Rotation3D(rzyx) * Transform3D(v);
606 iret |=
compare( trf11 == trf10, 1,
"r3d * transf",1 );
610 iret |=
compare( rzyx.
Phi() , rrr2.
Phi(),
"gen Rotation() Phi",1 );
612 iret |=
compare( rzyx.
Psi(), rrr2.
Psi(),
"gen Rotation() Psi",1 );
613 if (iret) std::cout << rzyx <<
"\n---\n" << rrr2 << std::endl;
623 iret |=
compare(p3.
X(), p2.
X(),
"x diff",10 );
624 iret |=
compare(p3.
Y(), p2.
Y(),
"y diff",10 );
625 iret |=
compare(p3.
Z(), p2.
Z(),
"z diff",10 );
631 iret |=
compare(v3.
X(), v2.
X(),
"x diff",10 );
632 iret |=
compare(v3.
Y(), v2.
Y(),
"y diff",10 );
633 iret |=
compare(v3.
Z(), v2.
Z(),
"z diff",10 );
644 iret |=
compare(qt3.
X(), qt4.
X(),
"x diff",10 );
645 iret |=
compare(qt3.
Y(), qt4.
Y(),
"y diff",10 );
646 iret |=
compare(qt3.
Z(), qt4.
Z(),
"z diff",10 );
660 iret |=
compare( (t3==t3b),
true,
"Get/SetTransformMatrix");
668 iret |=
compare( (lr==lr2),
true,
"Get/SetLRotMatrix");
672 if (iret == 0) std::cout <<
"OK\n";
673 else std::cout <<
"\t\t\tFAILED\n";
681 std::cout <<
"testing VectorUtil \t:\t";
693 iret |=
compare(vpx.X(), 0,
"x",1 );
694 iret |=
compare(vpx.Y(), v.
Y(),
"y",1 );
695 iret |=
compare(vpx.Z(), v.
Z(),
"z",1 );
713 iret |=
compare(vp.X(), vp2.
X(),
"x",10 );
714 iret |=
compare(vp.Y(), vp2.
Y(),
"y",10 );
715 iret |=
compare(vp.Z(), vp2.
Z(),
"z",10 );
717 double perp =
Perp(v,u);
718 iret |=
compare(perp, vp.R(),
"perp",1 );
719 double perp2 =
Perp2(v,u);
720 iret |=
compare(perp2, vp.Mag2(),
"perp2",1 );
724 XYZVector vr1 =
RotateX(v,angle);
726 iret |=
compare(vr1.
Y(), vr2.
Y(),
"y",1 );
727 iret |=
compare(vr1.
Z(), vr2.
Z(),
"z",1 );
731 iret |=
compare(vr1.X(), vr2.
X(),
"x",1 );
732 iret |=
compare(vr1.Z(), vr2.
Z(),
"z",1 );
736 iret |=
compare(vr1.X(), vr2.
X(),
"x",1 );
737 iret |=
compare(vr1.Y(), vr2.
Y(),
"y",1 );
740 if (iret == 0) std::cout <<
"\t\t\tOK\n";
741 else std::cout <<
"\t\t\t\t\t\tFAILED\n";
762 if (iret !=0) std::cout <<
"\nTest GenVector FAILED!!!!!!!!!\n";
769 if (ret) std::cerr <<
"test FAILED !!! " << std::endl;
770 else std::cout <<
"test OK " << std::endl;
DisplacementVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZVector
Scalar Psi() const
Return Psi angle (X'' rotation angle)
Scalar Phi() const
Return Phi Euler angle.
static double p3(double t, double a, double b, double c, double d)
PositionVector3D< Polar3D< double >, DefaultCoordinateSystemTag > Polar3DPoint
3D Point based on the polar coordinates rho, theta, phi in double precision.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Translation3D Inverse() const
Return the inverse of the transformation.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
PositionVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DPoint
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 3x3, which must support operator()(i...
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar Phi() const
Polar phi, converting if necessary from internal coordinate system.
int compare(double v1, double v2, const std::string &name="", double scale=1.0)
Class describing a generic position vector (point) in 3 dimensions.
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
DisplacementVector2D< Cartesian2D< double >, DefaultCoordinateSystemTag > XYVector
2D Vector based on the cartesian coordinates x,y in double precision
DisplacementVector2D< Cartesian2D< double >, LocalCoordinateSystemTag > LocalXYVector
Vector RotateX(const Vector &v, double alpha)
rotation along X axis for a generic vector by an Angle alpha returning a new vector.
DisplacementVector2D Unit() const
return unit vector parallel to this
PositionVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZPoint
Scalar Phi() const
Return Phi angle (Z rotation angle)
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Rotation3D rrr(TestRotation const &t)
static const double x2[5]
Rotation3D Inverse() const
Return inverse of a rotation.
SMatrix: a generic fixed size D1 x D2 Matrix class.
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
double Perp2(const Vector1 &v, const Vector2 &u)
Find the magnitude square of the vector component of v perpendicular to the given direction of u...
Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matr...
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
static double p2(double t, double a, double b, double c)
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Vector RotateZ(const Vector &v, double alpha)
rotation along Z axis for a generic vector by an Angle alpha returning a new vector.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
void Rotate(Scalar angle)
Rotate by an angle.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
PositionVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYPoint
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
PositionVector2D< Cartesian2D< double >, LocalCoordinateSystemTag > LocalXYPoint
Class describing a generic displacement vector in 3 dimensions.
EulerAngles Inverse() const
Return inverse of a rotation.
unsigned int r1[N_CITIES]
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 4x4, which must support operator()(i...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Vector RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
void GetComponents(ForeignVector &v1, ForeignVector &v2, ForeignVector &v3) const
Get components into three vectors which will be the (orthonormal) columns of the rotation matrix...
static double p1(double t, double a, double b)
DisplacementVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZVector
Class describing a generic position vector (point) in 2 dimensions.
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 3x3, which must support operator()(i...
Scalar Theta() const
Return Theta Euler angle.
PositionVector3D Cross(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return vector (Cross) product of this point with a displacement, as a point vector in this coordinate...
Class describing a 3 dimensional translation.
static const double x1[5]
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
bool areEqual(const RULE *r1, const RULE *r2, bool moduloNameOrPattern=false)
EulerAngles class describing rotation as three angles (Euler Angles).
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 4x4, which must support operator()(i...
PositionVector3D< Polar3D< double >, LocalCoordinateSystemTag > LocalPolar3DPoint
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
DisplacementVector3D Cross(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return vector (cross) product of two displacement vectors, as a vector in the coordinate system of th...
PositionVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZPoint
PositionVector2D< Polar2D< double >, LocalCoordinateSystemTag > LocalPolar2DPoint
DisplacementVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DVector
Vector1 PerpVector(const Vector1 &v, const Vector2 &u)
Find the vector component of v perpendicular to the given direction of u.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
void Invert()
Invert a rotation in place.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
DisplacementVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYVector
Tag for identifying vectors based on a local coordinate system.
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of the vector component of v perpendicular to the given direction of u...
Scalar Theta() const
Return Theta angle (Y' rotation angle)
Tag for identifying vectors based on a global coordinate system.
PositionVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DPoint
DisplacementVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DVector
int main(int argc, char **argv)
unsigned int r2[N_CITIES]
Class describing a generic displacement vector in 2 dimensions.
Scalar Psi() const
Return Psi Euler angle.