49 using namespace ROOT::Math;
55 int compare(
double v1,
double v2,
const char* name,
double Scale = 1.0) {
59 double eps = Scale* 2.22044604925031308e-16;
61 double delta = v2 -
v1;
63 if (delta < 0 ) delta = - delta;
64 if (v1 == 0 || v2 == 0) {
75 if ( delta/d > eps && delta > eps )
82 int pr = std::cout.precision (18);
85 discr = int(delta/d/eps);
87 discr = int(delta/eps);
89 std::cout <<
"\nDiscrepancy in " << name <<
"() : " << v1 <<
" != " << v2 <<
" discr = " << discr
90 <<
" (Allowed discrepancy is " << eps <<
")\n";
91 std::cout.precision (pr);
98 std::cout <<
"\n************************************************************************\n "
100 <<
"\n************************************************************************\n";
106 std::cout <<
"Test Cartesian-Polar : " ;
111 ok+=
compare(v1.X(), v2.X(),
"x");
112 ok+=
compare(v1.Y(), v2.Y(),
"y");
113 ok+=
compare(v1.Z(), v2.Z(),
"z");
114 ok+=
compare(v1.Phi(), v2.Phi(),
"phi");
115 ok+=
compare(v1.Theta(), v2.Theta(),
"theta");
116 ok+=
compare(v1.R(), v2.R(),
"r");
117 ok+=
compare(v1.Eta(), v2.Eta(),
"eta");
118 ok+=
compare(v1.Rho(), v2.Rho(),
"rho");
120 if (ok == 0) std::cout <<
"\t OK " << std::endl;
122 std::cout <<
"Test Cartesian-CylindricalEta : ";
136 if (ok == 0) std::cout <<
"\t OK " << std::endl;
138 std::cout <<
"Test Cartesian-Cylindrical : ";
152 if (ok == 0) std::cout <<
"\t OK " << std::endl;
154 std::cout <<
"Test Operations : " ;
157 double Dot = v1.Dot(v2);
158 ok+=
compare( Dot, v1.Mag2(),
"dot" );
160 ok+=
compare( vcross.R(), 0,
"cross" );
164 ok+=
compare( v1.R(), vscale2.
R(),
"scale");
167 ok+=
compare(v2.Phi(),vu.Phi(),
"unit Phi");
168 ok+=
compare(v2.Theta(),vu.Theta(),
"unit Theta");
169 ok+=
compare(1.0,vu.R(),
"unit ");
177 ok+=
compare( q4.
X(), q1.X(),
"op X" );
178 ok+=
compare( q4.
Y(), q1.Y(),
"op Y" );
179 ok+=
compare( q4.
Z(), q1.Z(),
"op Z" );
186 ok+=
compare( w1 == v1, static_cast<double>(
true),
"== XYZ");
187 ok+=
compare( w2 == v2, static_cast<double>(
true),
"== Polar");
188 ok+=
compare( w3 == v3, static_cast<double>(
true),
"== RhoEtaPhi");
189 ok+=
compare( w4 == v4, static_cast<double>(
true),
"== RhoZPhi");
191 if (ok == 0) std::cout <<
"\t OK " << std::endl;
194 std::cout <<
"Test Setters : " ;
196 q2.SetXYZ(q1.X(), q1.Y(), q1.Z() );
198 ok+=
compare( q2.X(), q1.X(),
"setXYZ X" );
199 ok+=
compare( q2.Y(), q1.Y(),
"setXYZ Y" );
200 ok+=
compare( q2.Z(), q1.Z(),
"setXYZ Z" );
202 q2.SetCoordinates( 2.0*q1.Rho(), q1.Eta(), q1.Phi() );
204 ok+=
compare( q2.X(), q1s.
X(),
"set X" );
205 ok+=
compare( q2.Y(), q1s.
Y(),
"set Y" );
206 ok+=
compare( q2.Z(), q1s.
Z(),
"set Z" );
208 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
210 std::cout <<
"Test Linear Algebra conversion: " ;
215 vxyz1.Coordinates().GetCoordinates(vla1.GetMatrixArray() );
218 vla2[0] = 1.; vla2[1] = -2.; vla2[2] = 1.;
224 double prod1 = vxyz1.
Dot(vxyz2);
225 double prod2 = vla1*vla2;
226 ok+=
compare( prod1, prod2,
"la test" );
228 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
234 std::cout <<
"\n************************************************************************\n "
236 <<
"\n************************************************************************\n";
240 std::cout <<
"Test Cartesian-Polar : ";
254 if (ok == 0) std::cout <<
"\t OK " << std::endl;
256 std::cout <<
"Test Polar-CylindricalEta : ";
270 if (ok == 0) std::cout <<
"\t OK " << std::endl;
272 std::cout <<
"Test operations : ";
276 double Dot =
p1.Dot(vperp);
277 ok+=
compare( Dot, 0.0,
"dot", 10 );
280 ok+=
compare( vcross.
R(),
p1.R(),
"cross mag" );
281 ok+=
compare( vcross.
Dot(vperp), 0.0,
"cross dir" );
288 ok+=
compare(
p1 == pscale2, static_cast<double>(
true),
"== Point");
296 if (ok == 0) std::cout <<
"\t OK " << std::endl;
301 int testLorentzVector() {
302 std::cout <<
"\n************************************************************************\n "
303 <<
" Lorentz Vector Tests"
304 <<
"\n************************************************************************\n";
308 std::cout <<
"Test XYZT - PtEtaPhiE Vectors: ";
313 ok+=
compare(v1.Px(), v2.X(),
"x");
314 ok+=
compare(v1.Py(), v2.Y(),
"y");
315 ok+=
compare(v1.Pz(), v2.Z(),
"z", 2);
316 ok+=
compare(v1.E(), v2.T(),
"e");
317 ok+=
compare(v1.Phi(), v2.Phi(),
"phi");
318 ok+=
compare(v1.Theta(), v2.Theta(),
"theta");
319 ok+=
compare(v1.Pt(), v2.Pt(),
"pt");
320 ok+=
compare(v1.M(), v2.M(),
"mass", 5);
321 ok+=
compare(v1.Et(), v2.Et(),
"et");
322 ok+=
compare(v1.Mt(), v2.Mt(),
"mt", 3);
324 if (ok == 0) std::cout <<
"\t OK " << std::endl;
326 std::cout <<
"Test XYZT - PtEtaPhiM Vectors: ";
333 ok+=
compare(v1.Pz(), v3.
Z(),
"z", 2);
334 ok+=
compare(v1.E(), v3.T(),
"e");
337 ok+=
compare(v1.Pt(), v3.Pt(),
"pt");
338 ok+=
compare(v1.M(), v3.M(),
"mass", 5);
339 ok+=
compare(v1.Et(), v3.Et(),
"et");
340 ok+=
compare(v1.Mt(), v3.Mt(),
"mt", 3);
342 if (ok == 0) std::cout <<
"\t OK " << std::endl;
344 std::cout <<
"Test PtEtaPhiE - PxPyPzM Vect.: ";
351 ok+=
compare(v4.Pz(), v3.
Z(),
"z",2);
352 ok+=
compare(v4.E(), v3.T(),
"e");
355 ok+=
compare(v4.Pt(), v3.Pt(),
"pt");
356 ok+=
compare(v4.M(), v3.M(),
"mass",5);
357 ok+=
compare(v4.Et(), v3.Et(),
"et");
358 ok+=
compare(v4.Mt(), v3.Mt(),
"mt",3);
360 if (ok == 0) std::cout <<
"\t OK " << std::endl;
362 std::cout <<
"Test operations : ";
365 double Dot = v1.Dot(v2);
366 ok+=
compare( Dot, v1.M2(),
"dot" , 10 );
370 ok+=
compare( v1.M(), vscale2.
M(),
"scale");
378 ok+=
compare( q4.
x(), q1.X(),
"op X" );
379 ok+=
compare( q4.
y(), q1.Y(),
"op Y" );
380 ok+=
compare( q4.
z(), q1.Z(),
"op Z" );
381 ok+=
compare( q4.
t(), q1.E(),
"op E" );
388 ok+=
compare( w1 == v1, static_cast<double>(
true),
"== PxPyPzE");
389 ok+=
compare( w2 == v2, static_cast<double>(
true),
"== PtEtaPhiE");
390 ok+=
compare( w3 == v3, static_cast<double>(
true),
"== PtEtaPhiM");
391 ok+=
compare( w4 == v4, static_cast<double>(
true),
"== PxPyPzM");
395 double beta = q1.Beta();
396 double gamma = q1.Gamma();
399 ok +=
compare( gamma, 1./
sqrt( 1 - beta*beta ),
"gamma");
401 if (ok == 0) std::cout <<
"\t OK " << std::endl;
404 std::cout <<
"Test Setters : " ;
406 q2.SetXYZT(q1.Px(), q1.Py(), q1.Pz(), q1.E() );
408 ok+=
compare( q2.X(), q1.X(),
"setXYZT X" );
409 ok+=
compare( q2.Y(), q1.Y(),
"setXYZT Y" );
410 ok+=
compare( q2.Z(), q1.Z(),
"setXYZT Z" ,2);
411 ok+=
compare( q2.T(), q1.E(),
"setXYZT E" );
413 q2.SetCoordinates( 2.0*q1.Rho(), q1.Eta(), q1.Phi(), 2.0*q1.E() );
415 ok+=
compare( q2.X(), q1s.
X(),
"set X" );
416 ok+=
compare( q2.Y(), q1s.
Y(),
"set Y" );
417 ok+=
compare( q2.Z(), q1s.
Z(),
"set Z" ,2);
418 ok+=
compare( q2.T(), q1s.
T(),
"set E" );
420 if (ok == 0) std::cout <<
"\t OK " << std::endl;
426 std::cout <<
"\n************************************************************************\n "
427 <<
" Utility Function Tests"
428 <<
"\n************************************************************************\n";
430 std::cout <<
"Test Vector utility functions : ";
449 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
452 std::cout <<
"Test Point utility functions : ";
470 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
472 std::cout <<
"LorentzVector utility funct.: ";
485 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
491 std::cout <<
"\n************************************************************************\n "
492 <<
" Rotation and Transformation Tests"
493 <<
"\n************************************************************************\n";
495 std::cout <<
"Test Vector Rotations : ";
533 r2.GetComponents(rdata, rdata+9);
536 v.GetCoordinates(vdata);
547 if (ok == 0) std::cout <<
"\t OK " << std::endl;
548 else std::cout << std::endl;
550 std::cout <<
"Test Axial Rotations : ";
565 RotationZYX rzyx( rz.Angle(), ry.Angle(), rx.Angle() );
570 ok+=
compare(vrot1.X(), vrot2.
X(),
"x");
571 ok+=
compare(vrot1.Y(), vrot2.
Y(),
"y");
572 ok+=
compare(vrot1.Z(), vrot2.
Z(),
"z");
574 vrot2 = qx * qy * qz *
v;
576 ok+=
compare(vrot1.X(), vrot2.X(),
"x",2);
577 ok+=
compare(vrot1.Y(), vrot2.Y(),
"y",2);
578 ok+=
compare(vrot1.Z(), vrot2.Z(),
"z",2);
582 ok+=
compare(vrot1.X(), vrot2.X(),
"x");
583 ok+=
compare(vrot1.Y(), vrot2.Y(),
"y");
584 ok+=
compare(vrot1.Z(), vrot2.Z(),
"z");
587 vrot1 = rz * ry * rx *
v;
588 vrot2 = r3z * r3y * r3x *
v;
590 ok+=
compare(vrot1.X(), vrot2.X(),
"x");
591 ok+=
compare(vrot1.Y(), vrot2.Y(),
"y");
592 ok+=
compare(vrot1.Z(), vrot2.Z(),
"z");
594 XYZPoint vinv1 = rx.Inverse()*ry.Inverse()*rz.Inverse()*vrot1;
596 ok+=
compare(vinv1.X(), v.X(),
"x",2);
597 ok+=
compare(vinv1.Y(), v.Y(),
"y");
598 ok+=
compare(vinv1.Z(), v.Z(),
"z");
600 if (ok == 0) std::cout <<
"\t OK " << std::endl;
601 else std::cout << std::endl;
604 std::cout <<
"Test Rotations by a PI angle : ";
607 double b[4] = { 6,8,10,3.14159265358979323 };
622 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
623 else std::cout << std::endl;
625 std::cout <<
"Test Inversions : ";
644 ok+=
compare(p.X(), v.X(),
"x",10);
645 ok+=
compare(p.Y(), v.Y(),
"y",10);
646 ok+=
compare(p.Z(), v.Z(),
"z",10);
650 ok+=
compare(p.X(), v.X(),
"x",1E9);
651 ok+=
compare(p.Y(), v.Y(),
"y",1E9);
652 ok+=
compare(p.Z(), v.Z(),
"z",1E9);
656 ok+=
compare(p.X(), v.X(),
"x",10);
657 ok+=
compare(p.Y(), v.Y(),
"y",10);
658 ok+=
compare(p.Z(), v.Z(),
"z",10);
666 ok+=
compare(p.X(), v.X(),
"x",10);
667 ok+=
compare(p.Y(), v.Y(),
"y",10);
668 ok+=
compare(p.Z(), v.Z(),
"z",10);
670 if (ok == 0) std::cout <<
"\t OK " << std::endl;
671 else std::cout << std::endl;
674 std::cout <<
"Test rectify : ";
677 XYZVector u1(0.999498,-0.00118212,-0.0316611);
679 XYZVector u3(0.0316832,0.0372921,0.998802);
683 ok+=
compare(v.R(), vrr.
R(),
"R",1.E9);
685 if (ok == 0) std::cout <<
"\t\t OK " << std::endl;
686 else std::cout << std::endl;
688 std::cout <<
"Test Transform3D : ";
704 t.GetComponents(tdata);
707 v.GetCoordinates(vData);
723 ok+=
compare(p.X(), v.X(),
"x",10);
724 ok+=
compare(p.Y(), v.Y(),
"y",10);
725 ok+=
compare(p.Z(), v.Z(),
"z",10);
732 ok+=
compare(p.X(), v.X(),
"x",10);
733 ok+=
compare(p.Y(), v.Y(),
"y",10);
734 ok+=
compare(p.Z(), v.Z(),
"z",10);
742 ok+=
compare( tc == tb*ta, static_cast<double>(
true),
"== Rot*Tra");
743 ok+=
compare( td == ta*tb, static_cast<double>(
true),
"== Rot*Tra");
746 if (ok == 0) std::cout <<
"\t OK " << std::endl;
747 else std::cout << std::endl;
749 std::cout <<
"Test Plane3D : ";
779 ok+=
compare(plane1.HesseDistance(), plane2.HesseDistance(),
"d",10);
782 ok +=
compare(plane1.Distance(pt1), 0.0,
"distance",10);
784 if (ok == 0) std::cout <<
"\t OK " << std::endl;
785 else std::cout << std::endl;
787 std::cout <<
"Test LorentzRotation : ";
809 ok+=
compare(lv1== lv2,
true,
"V0==V2");
810 ok+=
compare(lv1== lv2,
true,
"V1==V2");
816 lv.GetCoordinates(lvData);
829 ok+=
compare(lv0.X(), lv.X(),
"x");
830 ok+=
compare(lv0.Y(), lv.Y(),
"y");
831 ok+=
compare(lv0.Z(), lv.Z(),
"z");
832 ok+=
compare(lv0.E(), lv.E(),
"t");
834 if (ok == 0) std::cout <<
"\t OK " << std::endl;
835 else std::cout << std::endl;
838 std::cout <<
"Test Boost : ";
841 Boost bst( 0.3,0.4,0.5);
854 ok+=
compare(lvb.
M(), lv.M(),
"m",50);
857 lv0 = bst.Inverse() * lvb;
859 ok+=
compare(lv0.X(), lv.X(),
"x",5);
860 ok+=
compare(lv0.Y(), lv.Y(),
"y",5);
861 ok+=
compare(lv0.Z(), lv.Z(),
"z",3);
862 ok+=
compare(lv0.E(), lv.E(),
"t",3);
865 bst.SetComponents( brest.X(), brest.Y(), brest.Z() );
872 ok+=
compare(lvr.
M(), lv.M(),
"m",10);
874 if (ok == 0) std::cout <<
"\t OK " << std::endl;
875 else std::cout << std::endl;
879 void mathcoreGenVector() {
883 using namespace ROOT::Math;
892 std::cout <<
"\n\nNumber of tests " << ntest <<
" failed = " << nfail << std::endl;
Quaternion Inverse() const
Return inverse of a rotation.
Class describing a geometrical plane in 3 dimensions.
Scalar E() const
return 4-th component (time, or energy for a 4-momentum vector)
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
DisplacementVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Scalar Phi() const
Return Phi Euler angle.
static double p3(double t, double a, double b, double c, double d)
RotationZYX Inverse() const
Return inverse of a rotation.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar R() const
Polar R, 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.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Scalar Rho() const
Cylindrical transverse component rho.
Scalar M() const
return magnitude (mass) using the (-,-,-,+) metric.
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
AxisVector Axis() const
accesss to rotation axis
Scalar Eta() const
Polar eta, converting if necessary from internal coordinate system.
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.
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
double beta(double x, double y)
Calculates the beta function.
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...
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
unsigned int r3[N_CITIES]
Vector1::Scalar DeltaR(const Vector1 &v1, const Vector2 &v2)
Find difference in pseudorapidity (Eta) and Phi betwen two generic vectors The only requirements on t...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matr...
static double p2(double t, double a, double b, double c)
Vector1::Scalar InvariantMass(const Vector1 &v1, const Vector2 &v2)
return the invariant mass of two LorentzVector The only requirement on the LorentzVector is that they...
PositionVector3D< CoordSystem, Tag > & SetCoordinates(const Scalar src[])
Set internal data based on a C-style array of 3 Scalar numbers.
Scalar R() const
Polar R, converting if necessary from internal coordinate system.
Scalar Angle() const
access to rotation angle
AxisAngle Inverse() const
Return inverse of an AxisAngle rotation.
Element * GetMatrixArray()
Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix...
Vector1::Scalar DeltaPhi(const Vector1 &v1, const Vector2 &v2)
Find aximutal Angle difference between two generic vectors ( v2.Phi() - v1.Phi() ) The only requireme...
R__EXTERN TSystem * gSystem
double Angle(const Vector1 &v1, const Vector2 &v2)
Find Angle between two vectors.
LorentzRotation 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.
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
void GetComponents(Foreign4Vector &v1, Foreign4Vector &v2, Foreign4Vector &v3, Foreign4Vector &v4) const
Get components into four 4-vectors which will be the (orthosymplectic) columns of the rotation matrix...
static double p1(double t, double a, double b)
Scalar Phi() const
Polar phi, converting if necessary from internal coordinate system.
Scalar Theta() const
Polar theta, converting if necessary from internal coordinate system.
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...
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
EulerAngles class describing rotation as three angles (Euler Angles).
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...
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
DisplacementVector3D Unit() const
return unit vector parallel to this
double CosTheta(const Vector1 &v1, const Vector2 &v2)
Find CosTheta Angle between two generic 3D vectors pre-requisite: vectors implement the X()...
unsigned int r2[N_CITIES]
Scalar Psi() const
Return Psi Euler angle.