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";
114 GlobalXYZVector vg(1.,2.,3.);
115 GlobalXYZVector vg2(vg);
117 GlobalPolar3DVector vpg(vg);
123 double r = vg.
Dot(vpg);
126 GlobalXYZVector vcross = vg.
Cross(vpg);
127 iret |=
compare(vcross.R(), 0.0,
"cross",10 );
136 GlobalXYZVector vg3 = vg + vpg;
137 iret |=
compare(vg3.R(), 2*vg.
R() );
139 GlobalXYZVector vg4 = vg - vpg;
140 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
145 #ifdef TEST_COMPILE_ERROR 146 LocalXYZVector vl; vl = vg;
147 LocalXYZVector vl2(vg2);
148 LocalXYZVector vl3(vpg);
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";
173 GlobalXYZPoint pg(1.,2.,3.);
174 GlobalXYZPoint pg2(pg);
176 GlobalPolar3DPoint ppg(pg);
184 GlobalXYZVector vg(pg);
186 double r = pg.
Dot(vg);
189 GlobalPolar3DVector vpg(pg);
190 GlobalXYZPoint pcross = pg.
Cross(vpg);
191 iret |=
compare(pcross.
R(), 0.0,
"cross",10 );
193 GlobalPolar3DPoint pg3 = ppg + vg;
194 iret |=
compare(pg3.R(), 2*pg.
R() );
196 GlobalXYZVector vg4 = pg - ppg;
197 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
200 #ifdef TEST_COMPILE_ERROR 201 LocalXYZPoint pl; pl = pg;
202 LocalXYZVector pl2(pg2);
203 LocalXYZVector pl3(ppg);
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";
241 GlobalXYVector vg(1.,2.);
242 GlobalXYVector vg2(vg);
244 GlobalPolar2DVector vpg(vg);
250 double r = vg.
Dot(vpg);
256 GlobalXYVector vg3 = vg + vpg;
257 iret |=
compare(vg3.R(), 2*vg.
R() );
259 GlobalXYVector vg4 = vg - vpg;
260 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
265 iret |=
compare(vg.
Phi(), vpg.Phi() + angle );
268 GlobalXYZVector v3d(1,2,0);
269 GlobalXYZVector vr3d =
RotationZ(angle) * v3d;
273 GlobalXYVector vu = vg3.
Unit();
277 #ifdef TEST_COMPILE_ERROR 278 LocalXYVector vl; vl = vg;
279 LocalXYVector vl2(vg2);
280 LocalXYVector vl3(vpg);
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";
310 GlobalXYPoint pg(1.,2.);
311 GlobalXYPoint pg2(pg);
313 GlobalPolar2DPoint ppg(pg);
321 GlobalXYVector vg(pg);
323 double r = pg.
Dot(vg);
326 GlobalPolar2DVector vpg(pg);
328 GlobalPolar2DPoint pg3 = ppg + vg;
331 GlobalXYVector vg4 = pg - ppg;
332 iret |=
compare(vg4.R(), 0.0,
"diff",10 );
335 #ifdef TEST_COMPILE_ERROR 336 LocalXYPoint pl; pl = pg;
337 LocalXYVector pl2(pg2);
338 LocalXYVector pl3(ppg);
356 iret |=
compare(pg.Phi(), ppg.Phi() + angle );
357 iret |=
compare(pg.R(), ppg.R() );
359 GlobalXYZVector v3d(1,2,0);
360 GlobalXYZVector vr3d =
RotationZ(angle) * v3d;
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";
382 GlobalXYZVector vg(1.,2.,3);
383 GlobalXYZPoint pg(1.,2.,3);
384 GlobalPolar3DVector vpg(vg);
387 GlobalXYZVector vg2 = rot(vg);
388 iret |=
compare(vg2.
R(), vg.
R(),
"rot3D" );
390 GlobalXYZPoint pg2 = rot(pg);
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);
403 GlobalPolar3DVector vpg2 = qrot * vpg;
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 );
428 GlobalXYZVector vry =
RotationY(2) * vrx;
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";
486 GlobalPolar3DVector
v(1.,2.,3.);
487 GlobalXYZVector w(v);
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 );
499 GlobalPolar3DVector vr = r.
Inverse()*
v;
522 #if !defined(__i386__) 523 iret |=
compare(tr1 ==tr2, 1,
"eq transl",1 );
527 iret |=
compare(0, 0,
"dummy test",1 );
531 GlobalPolar3DVector vp2 = tr3 *
v;
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 );
563 GlobalPolar3DVector vvv2;
564 t2b.GetDecomposition(err2,vvv2);
570 iret |=
compare( v.X(), vvv2.
X(),
"eq transf g vec",4 );
571 iret |=
compare( v.Y(), vvv2.
Y(),
"eq transf g vec",1 );
572 iret |=
compare( v.Z(), vvv2.
Z(),
"eq transf g vec",1 );
577 iret |=
compare( t4.
Rotation() == Rotation3D(rzyx), 1,
"eq trans rzyx",1 );
580 iret |=
compare( trf2 == t2b, 1,
"trasl * e rot",1 );
593 iret |=
compare( trf6 == t6, 1,
"rzyx * transl",1 );
594 if (iret) std::cout << t6 <<
"\n---\n" << trf6 << std::endl;
600 iret |=
compare(
IsEqual(trf7,trf6,12),
true,
"tranf * transl",1 );
602 iret |=
compare( trf8 == trf5, 1,
"trans * transf",1 );
605 iret |=
compare( trf9 == trf5, 1,
"tranf * rzyx",1 );
607 iret |=
compare( trf10 == trf6, 1,
"rzyx * transf",1 );
608 Transform3D trf11 = Rotation3D(rzyx) *
Transform3D(v);
609 iret |=
compare( trf11 == trf10, 1,
"r3d * transf",1 );
613 iret |=
compare( rzyx.Phi() , rrr2.
Phi(),
"gen Rotation() Phi",1 );
614 iret |=
compare( rzyx.Theta(), rrr2.
Theta(),
"gen Rotation() Theta",10 );
615 iret |=
compare( rzyx.Psi(), rrr2.
Psi(),
"gen Rotation() Psi",1 );
616 if (iret) std::cout << rzyx <<
"\n---\n" << rrr2 << std::endl;
626 iret |=
compare(p3.
X(), p2.
X(),
"x diff",10 );
627 iret |=
compare(p3.
Y(), p2.
Y(),
"y diff",10 );
628 iret |=
compare(p3.
Z(), p2.
Z(),
"z diff",10 );
630 GlobalXYZVector v1(1.,2.,3.);
631 LocalXYZVector v2; t2.Transform (v1, v2);
634 iret |=
compare(v3.
X(), v2.
X(),
"x diff",10 );
635 iret |=
compare(v3.
Y(), v2.
Y(),
"y diff",10 );
636 iret |=
compare(v3.
Z(), v2.
Z(),
"z diff",10 );
647 iret |=
compare(qt3.
X(), qt4.
X(),
"x diff",10 );
648 iret |=
compare(qt3.
Y(), qt4.
Y(),
"y diff",10 );
649 iret |=
compare(qt3.
Z(), qt4.
Z(),
"z diff",10 );
663 iret |=
compare( (t3==t3b),
true,
"Get/SetTransformMatrix");
671 iret |=
compare( (lr==lr2),
true,
"Get/SetLRotMatrix");
681 auto r0_2 = tr.
Inverse()(tr(point));
683 iret |=
compare(r0.X(), point.
X(),
"ApplyInverse/PointX", 100);
684 iret |=
compare(r0_2.X(), point.
X(),
"ApplyInverse/PointX", 100);
685 iret |=
compare(r0.Y(), point.
Y(),
"ApplyInverse/PointY", 10);
686 iret |=
compare(r0_2.Y(), point.
Y(),
"ApplyInverse/PointY", 10);
687 iret |=
compare(r0.Z(), point.
Z(),
"ApplyInverse/PointZ", 10);
688 iret |=
compare(r0_2.Z(), point.
Z(),
"ApplyInverse/PointZ", 10);
693 iret |=
compare(r1.X(),
r2.X(),
"ApplyInverse/Point", 10);
694 iret |=
compare(r1.Y(),
r2.Y(),
"ApplyInverse/Point", 10);
695 iret |=
compare(r1.Z(),
r2.Z(),
"ApplyInverse/Point", 10);
700 XYZVector vector(1, -2., 3);
704 iret |=
compare(
r1.X(),
r2.X(),
"ApplyInverse/Vector", 10);
705 iret |=
compare(
r1.Y(),
r2.Y(),
"ApplyInverse/Vector", 10);
706 iret |=
compare(
r1.Z(),
r2.Z(),
"ApplyInverse/Vector", 10);
709 if (iret == 0) std::cout <<
"OK\n";
710 else std::cout <<
"\t\t\tFAILED\n";
718 std::cout <<
"testing VectorUtil \t:\t";
730 iret |=
compare(vpx.X(), 0,
"x",1 );
731 iret |=
compare(vpx.Y(), v.
Y(),
"y",1 );
732 iret |=
compare(vpx.Z(), v.
Z(),
"z",1 );
750 iret |=
compare(vp.X(), vp2.
X(),
"x",10 );
751 iret |=
compare(vp.Y(), vp2.
Y(),
"y",10 );
752 iret |=
compare(vp.Z(), vp2.
Z(),
"z",10 );
754 double perp =
Perp(v,u);
755 iret |=
compare(perp, vp.R(),
"perp",1 );
756 double perp2 =
Perp2(v,u);
757 iret |=
compare(perp2, vp.Mag2(),
"perp2",1 );
761 XYZVector vr1 =
RotateX(v,angle);
763 iret |=
compare(vr1.
Y(), vr2.
Y(),
"y",1 );
764 iret |=
compare(vr1.
Z(), vr2.
Z(),
"z",1 );
768 iret |=
compare(vr1.X(), vr2.
X(),
"x",1 );
769 iret |=
compare(vr1.Z(), vr2.
Z(),
"z",1 );
773 iret |=
compare(vr1.X(), vr2.
X(),
"x",1 );
774 iret |=
compare(vr1.Y(), vr2.
Y(),
"y",1 );
777 if (iret == 0) std::cout <<
"\t\t\tOK\n";
778 else std::cout <<
"\t\t\t\t\t\tFAILED\n";
799 if (iret !=0) std::cout <<
"\nTest GenVector FAILED!!!!!!!!!\n";
806 if (ret) std::cerr <<
"test FAILED !!! " << std::endl;
807 else std::cout <<
"test OK " << std::endl;
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
DisplacementVector3D< Cartesian3D< double >, LocalCoordinateSystemTag > LocalXYZVector
Translation3D< T > Inverse() const
Return the inverse of the transformation.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar Psi() const
Return Psi angle (X'' rotation 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.
void GetComponents(ForeignVector &v1, ForeignVector &v2, ForeignVector &v3) const
Get components into three vectors which will be the (orthonormal) columns of the rotation matrix...
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
PositionVector3D< Polar3D< double >, GlobalCoordinateSystemTag > GlobalPolar3DPoint
void SetRotationMatrix(const ForeignMatrix &m)
Set components from a linear algebra matrix of size at least 3x3, which must support operator()(i...
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Vector1 ProjVector(const Vector1 &v, const Vector2 &u)
Find the projection of v along the given direction u.
EulerAngles Inverse() const
Return inverse of a rotation.
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Scalar Phi() const
Polar phi, converting if necessary from internal coordinate system.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
int compare(double v1, double v2, const std::string &name="", double scale=1.0)
Class describing a generic position vector (point) in 3 dimensions.
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.
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
Rotation3D Inverse() const
Return inverse of a rotation.
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 3x3, which must support operator()(i...
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.
PositionVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZPoint
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Scalar Phi() const
Return Phi Euler angle.
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Psi() const
Return Psi Euler angle.
Rotation3D rrr(TestRotation const &t)
static const double x2[5]
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...
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 Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar R() const
Polar R, 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 Theta() const
Return Theta Euler angle.
static double p2(double t, double a, double b, double c)
Scalar X() const
Cartesian X, 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.
void GetRotationMatrix(ForeignMatrix &m) const
Get components into a linear algebra matrix of size at least 4x4, which must support operator()(i...
void Rotate(Scalar angle)
Rotate by an angle.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
PositionVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYPoint
Class describing a 3 dimensional translation.
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
PositionVector2D< Cartesian2D< double >, LocalCoordinateSystemTag > LocalXYPoint
Class describing a generic displacement vector in 3 dimensions.
Global Helper functions for generic Vector classes.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
unsigned int r1[N_CITIES]
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
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...
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
const Vector & Vect() const
return a const reference to the underline vector representing the translation
Vector RotateY(const Vector &v, double alpha)
rotation along Y axis for a generic vector by an Angle alpha returning a new vector.
static double p1(double t, double a, double b)
DisplacementVector3D< Cartesian3D< double >, GlobalCoordinateSystemTag > GlobalXYZVector
Class describing a generic position vector (point) in 2 dimensions.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
Impl::Transform3D< double > Transform3D
static const double x1[5]
EulerAngles class describing rotation as three angles (Euler Angles).
DisplacementVector2D Unit() const
return unit vector parallel to this
bool IsEqual(const Transform &t1, const Transform &t2, unsigned int size)
Scalar Theta() const
Return Theta angle (Y' rotation angle)
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
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 Y() const
Cartesian Y, converting if necessary from internal coordinate system.
void Invert()
Invert a rotation in place.
Scalar Phi() const
Return Phi angle (Z rotation angle)
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
Scalar Dot(const DisplacementVector2D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
DisplacementVector2D< Cartesian2D< double >, GlobalCoordinateSystemTag > GlobalXYVector
Tag for identifying vectors based on a local coordinate system.
Scalar Mag2() const
Magnitute squared ( r^2 in spherical coordinate)
double Perp(const Vector1 &v, const Vector2 &u)
Find the magnitude of the vector component of v perpendicular to the given direction of u...
Tag for identifying vectors based on a global coordinate system.
Impl::Translation3D< double > Translation3D
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (Dot) product of this with a displacement vector in any coordinate system...
PositionVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DPoint
DisplacementVector2D< Polar2D< double >, GlobalCoordinateSystemTag > GlobalPolar2DVector
unsigned int r2[N_CITIES]
Class describing a generic displacement vector in 2 dimensions.
Scalar Dot(const DisplacementVector3D< OtherCoords, Tag > &v) const
Return the scalar (dot) product of two displacement vectors.