59 template <
typename T1,
typename T2 >
61 enum {
result = std::numeric_limits<T1>::digits <= std::numeric_limits<T2>::digits };
64 template <
typename T1,
typename T2,
bool>
65 struct LessPreciseType {
68 template <
typename T1,
typename T2>
69 struct LessPreciseType<
T1,
T2, false> {
76 template <
typename Scalar1,
typename Scalar2>
78 closeEnough (Scalar1 s1, Scalar2 s2, std::string
const & coord,
double ticks) {
80 int pr = std::cout.precision(18);
84 Scalar
epsilon = (eps1 >= eps2) ? eps1 : eps2;
87 Scalar diff = ss1 - ss2;
88 if (diff < 0) diff = -diff;
89 if ( diff > ticks*epsilon ) {
91 std::cout <<
"\n\n????????\n\nAbsolute discrepancy in " << coord <<
"(): " 92 << ss1 <<
" != " << ss2 <<
"\n" 93 <<
" (Allowed discrepancy is " << ticks
94 <<
" ticks = " << ticks*epsilon
95 <<
")\nDifference is " << diff/epsilon <<
" ticks\n";
97 std::cout.precision (pr);
101 template <
class V1,
class V2>
102 int compare3D (
const V1 & v1,
const V2 & v2,
double ticks) {
104 typedef typename V1::CoordinateType CoordType1;
105 typedef typename V2::CoordinateType CoordType2;
112 std::cout <<
"Discrepancy detected (see above) is between:\n " 115 <<
"with v = (" << v1.x() <<
", " << v1.y() <<
", " << v1.z()
117 <<
"\nv2 is " << v2 <<
"\n\n";
123 template <
class V>
struct correctedTicks {
131 double e = ticks*
std::fabs( z*z / (r*r-z*z) );
132 if (e < ticks)
return ticks;
137 correctedTicks< DisplacementVector3D < CylindricalEta3D<double> > > {
143 return t1 > t2 ?
t1 : t2;
148 correctedTicks< PositionVector3D < CylindricalEta3D<double> > > {
154 return t1 > t2 ?
t1 : t2;
158 template <
class R,
class V>
161 typedef typename V::CoordinateType CoordType;
164 correctedTicks<V> ct;
165 double ticks = ct(t, v, answer);
167 std::cout <<
">>>>> Testing application of " 170 v <<
" ticks = " << ticks;
173 std::cout <<
" about to do V rv = r(v) - \n";
182 std::cout <<
"Inconsistency between R(v) and R*v for R = " 188 std::cout <<
"+ also did rv != r*v ";
190 if (
closeEnough(v.r(), rv.r(),
"r", ticks) != 0 ) {
191 std::cout <<
"Radius change between R(v) and R*v for R = " 199 std::cout <<
"\n---- about to do compare3D ----";
203 std::cout <<
" done \n";
206 if (ret == 0) std::cout <<
" OK\n";
232 struct TestRotation {
233 std::vector<XYZ> xyz;
234 std::vector<double> phi;
235 TestRotation (std::vector<XYZ>
const & xyz_, std::vector<double>
const & phi_)
236 : xyz(xyz_), phi(phi_) {}
242 std::cout <<
"---- rrr ----";
245 for (
unsigned int i=0; i<t.xyz.size(); ++i) {
246 switch ( t.xyz[i] ) {
259 std::cout <<
" done\n";
266 for (
int i=t.xyz.size()-1; i >= 0; --i) {
267 switch ( t.xyz[i] ) {
269 v =
rxv ( t.phi[i],v );
272 v =
ryv ( t.phi[i],v );
275 v =
rzv ( t.phi[i],v );
282 const double pi = 3.1415926535897932385;
284 std::vector<TestRotation>
287 std::cout <<
"---- makeTestRotations ----";
289 std::vector<TestRotation> t;
290 std::vector<XYZ> xyz;
291 std::vector<double> phi;
295 xyz.clear(); phi.clear();
296 xyz.push_back(
X); phi.push_back(
pi/2 );
297 t.push_back(TestRotation(xyz,phi));
299 xyz.clear(); phi.clear();
300 xyz.push_back(
Y); phi.push_back(
pi/2 );
301 t.push_back(TestRotation(xyz,phi));
303 xyz.clear(); phi.clear();
304 xyz.push_back(
Z); phi.push_back(
pi/2 );
305 t.push_back(TestRotation(xyz,phi));
307 xyz.clear(); phi.clear();
308 xyz.push_back(
X); phi.push_back( -
pi/6 );
309 t.push_back(TestRotation(xyz,phi));
311 xyz.clear(); phi.clear();
312 xyz.push_back(
Y); phi.push_back(
pi/6 );
313 t.push_back(TestRotation(xyz,phi));
315 xyz.clear(); phi.clear();
316 xyz.push_back(
Z); phi.push_back(
pi/3 );
317 t.push_back(TestRotation(xyz,phi));
319 xyz.clear(); phi.clear();
320 xyz.push_back(
X); phi.push_back( -
pi/6 );
321 xyz.push_back(
Y); phi.push_back(
pi/3 );
322 t.push_back(TestRotation(xyz,phi));
324 xyz.clear(); phi.clear();
325 xyz.push_back(
X); phi.push_back( -
pi/6 );
326 xyz.push_back(
Y); phi.push_back(
pi/4 );
327 xyz.push_back(
Z); phi.push_back( -
pi/5 );
328 t.push_back(TestRotation(xyz,phi));
330 xyz.clear(); phi.clear();
331 xyz.push_back(
Y); phi.push_back(
pi );
332 xyz.push_back(
X); phi.push_back( -
pi/2 );
333 xyz.push_back(
Z); phi.push_back( -
pi/1.5 );
334 xyz.push_back(
Y); phi.push_back( -
pi/3 );
335 t.push_back(TestRotation(xyz,phi));
337 xyz.clear(); phi.clear();
338 xyz.push_back(
Z); phi.push_back( 1.3 );
339 xyz.push_back(
Y); phi.push_back( -1.1 );
340 xyz.push_back(
X); phi.push_back( 0.4 );
341 xyz.push_back(
Y); phi.push_back( 0.7 );
342 t.push_back(TestRotation(xyz,phi));
344 xyz.clear(); phi.clear();
345 xyz.push_back(
X); phi.push_back( 1.3 );
346 xyz.push_back(
Z); phi.push_back( -1.1 );
347 xyz.push_back(
Y); phi.push_back( 0.4 );
348 xyz.push_back(
Z); phi.push_back( 0.7 );
349 t.push_back(TestRotation(xyz,phi));
351 xyz.clear(); phi.clear();
352 xyz.push_back(
Y); phi.push_back( 1.3 );
353 xyz.push_back(
X); phi.push_back( -1.1 );
354 xyz.push_back(
Z); phi.push_back( 0.4 );
355 xyz.push_back(
X); phi.push_back( 0.7 );
356 t.push_back(TestRotation(xyz,phi));
358 xyz.clear(); phi.clear();
359 xyz.push_back(
Z); phi.push_back( .03 );
360 xyz.push_back(
Y); phi.push_back( -.05 );
361 xyz.push_back(
X); phi.push_back( 0.04 );
362 xyz.push_back(
Y); phi.push_back( 0.07 );
363 xyz.push_back(
Z); phi.push_back( -0.02 );
364 t.push_back(TestRotation(xyz,phi));
367 std::cout <<
" done\n";
374 std::cout <<
"---- makeTestVectors ----";
376 std::vector<XYZVector> vs;
386 vs.push_back(
XYZVector ( 0, .00001, -2 ));
389 std::cout <<
" done\n";
394 template <
class R,
class V>
398 std::cout <<
"---- doTest ----";
401 R r (
rrr(testRotation) );
406 std::cout <<
" done\n";
409 if (ret == 0) std::cout <<
".";
414 template <
class R,
class C>
418 std::cout <<
"---- doTestL ----";
421 R r (
rrr(testRotation) );
423 double x = testVector.
X();
424 double y = testVector.
Y();
425 double z = testVector.
Z();
426 double t =
std::sqrt (x*x + y*y + z*z + 1);
433 std::cout <<
" done\n";
438 struct ForeignVector {
442 explicit ForeignVector (V
const & v_) :
v(v_) {}
443 ForeignVector (
double xx,
double yy,
double zz) :
v(xx,yy,zz) {}
444 double x()
const {
return v.
x(); }
445 double y()
const {
return v.
y(); }
446 double z()
const {
return v.
z(); }
447 double r()
const {
return v.
r(); }
448 bool operator==(ForeignVector
const & rhs) {
return v == rhs.v;}
449 bool operator!=(ForeignVector
const & rhs) {
return v != rhs.v;}
451 std::ostream &
operator<< (std::ostream& os,
const ForeignVector&
v) {
459 std::cout <<
"---- doTestofR ----\n";
462 const double ticks = 100;
464 std::cout <<
">>>>> DisplacementVector3D< Cartesian3D<double> \n";
466 ret |= doTest <R, DisplacementVector3D< Cartesian3D<double> > >
467 (testRotation,testVector,ticks);
469 std::cout <<
">>>>> DisplacementVector3D< Polar3D<double> \n";
471 ret |= doTest <R, DisplacementVector3D< Polar3D<double> > >
472 (testRotation,testVector,ticks);
474 std::cout <<
">>>>> DisplacementVector3D< CylindricalEta3D<double> \n";
476 ret |= doTest <R, DisplacementVector3D< CylindricalEta3D<double> > >
477 (testRotation,testVector,ticks);
479 std::cout <<
">>>>> PositionVector3D< Cartesian3D<double> \n";
481 ret |= doTest <R, PositionVector3D< Cartesian3D<double> > >
482 (testRotation,testVector,ticks);
484 std::cout <<
">>>>> PositionVector3D< Polar3D<double> \n";
486 ret |= doTest <R, PositionVector3D< Polar3D<double> > >
487 (testRotation,testVector,ticks);
489 std::cout <<
">>>>> PositionVector3D< CylindricalEta3D<double> \n";
491 ret |= doTest <R, PositionVector3D< CylindricalEta3D<double> > >
492 (testRotation,testVector,ticks);
494 std::cout <<
">>>>> ForeignVector\n";
496 ret |= doTest <R, ForeignVector >
497 (testRotation,testVector,ticks);
499 std::cout <<
">>>>> LorentzVector<PxPyPzE4D<double> >\n";
501 ret |= doTestL <R, PxPyPzE4D<double> >
502 (testRotation,testVector,ticks);
504 std::cout <<
" ---- doTestofR ---- done\n";
507 if (ret == 0) std::cout <<
".";
519 std::cout <<
">>>>> Rotation Tests of " << testVector <<
"\t\t: " ;
522 std::cout <<
"---- exerciseTestCase ----";
525 ret |= doTestOfR <Rotation3D> (testRotation,testVector);
526 ret |= doTestOfR <AxisAngle> (testRotation,testVector);
527 ret |= doTestOfR <EulerAngles> (testRotation,testVector);
528 ret |= doTestOfR <Quaternion> (testRotation,testVector);
529 ret |= doTestOfR <RotationZYX> (testRotation,testVector);
531 std::cout <<
" done\n";
535 std::cout <<
"\t OK\n";
537 std::cout <<
"\t Failed!\n ";
538 std::cerr <<
"\n>>>>> Rotation Tests of " << testVector <<
"\t\t:\t FAILED \n";
546 template <
class R,
class V>
549 std::cout <<
"---- doTestA ----";
554 for (
double angle = -4.0; angle < 4.0; angle += .15) {
556 rv =
rxv (angle, testVector);
559 rv =
ryv (angle, testVector);
562 rv =
rzv (angle, testVector);
566 std::cout <<
" done\n";
568 if (ret == 0) std::cout <<
".";
572 template <
class R,
class C>
575 std::cout <<
"---- doTestLA ----";
579 double x = testVector.
X();
580 double y = testVector.
Y();
581 double z = testVector.
Z();
582 double t =
std::sqrt (x*x + y*y + z*z + 1);
585 for (
double angle = -4.0; angle < 4.0; angle += .15) {
588 rv =
rxv (angle, testVector);
591 rv =
ryv (angle, testVector);
594 rv =
rzv (angle, testVector);
598 std::cout <<
" done\n";
601 if (ret == 0) std::cout <<
".";
608 std::cout <<
"---- doTestOfAxial ----\n";
611 const double ticks = 32;
613 std::cout <<
">>>>> DisplacementVector3D< Cartesian3D<double> \n";
615 ret |= doTestA <R, DisplacementVector3D< Cartesian3D<double> > >
618 std::cout <<
">>>>> DisplacementVector3D< Polar3D<double> \n";
620 ret |= doTestA <R, DisplacementVector3D< Polar3D<double> > >
623 std::cout <<
">>>>> DisplacementVector3D< CylindricalEta3D<double> \n";
625 ret |= doTestA <R, DisplacementVector3D< CylindricalEta3D<double> > >
628 std::cout <<
">>>>> PositionVector3D< Cartesian3D<double> \n";
630 ret |= doTestA <R, PositionVector3D< Cartesian3D<double> > >
633 std::cout <<
">>>>> PositionVector3D< Polar3D<double> \n";
635 ret |= doTestA <R, PositionVector3D< Polar3D<double> > > (testVector,ticks);
637 std::cout <<
">>>>> PositionVector3D< CylindricalEta3D<double> \n";
639 ret |= doTestA <R, PositionVector3D< CylindricalEta3D<double> > >
642 std::cout <<
">>>>> ForeignVector\n";
644 ret |= doTestA <R, ForeignVector > (testVector,ticks);
646 std::cout <<
">>>>> LorentzVector<PxPyPzE4D<double> >\n";
648 ret |= doTestLA <R, PxPyPzE4D<double> > (testVector,ticks);
650 std::cout <<
" ---- doTestofR ---- done\n";
654 if (ret == 0) std::cout <<
".";
663 std::cout <<
"---- exerciseAxialTest ----";
666 std::cout <<
">>>>> Axial Rotation Tests of " << testVector <<
"\t\t: ";
669 ret |= doTestOfAxial <RotationX> (testVector);
670 ret |= doTestOfAxial <RotationY> (testVector);
671 ret |= doTestOfAxial <RotationZ> (testVector);
673 std::cout <<
" done\n";
677 std::cout <<
"\t OK\n";
679 std::cout <<
"\t Failed!\n ";
680 std::cerr <<
"\n>>>>> Axial Rotation Tests of " << testVector <<
"\t\t:\t FAILED \n";
687 #endif // endif on __CINT__ 695 bool skipTests =
false;
696 #if defined(__i386__) 702 if (skipTests && !forceRun) {
703 std::cout <<
"Skip the tests - it is probably a 32 bit arch - return 0" << std::endl;
709 for ( std::vector<TestRotation>::const_iterator
n = testRotations.begin();
710 n != testRotations.end(); ++
n ) {
711 for ( std::vector<XYZVector>::const_iterator
m = testVectors.begin();
712 m != testVectors.end(); ++
m ) {
716 for ( std::vector<XYZVector>::const_iterator vp = testVectors.begin();
717 vp != testVectors.end(); ++vp ) {
726 if (ret) std::cerr <<
"test FAILED !!! " << std::endl;
727 else std::cout <<
"test OK " << std::endl;
int testApplication(const R &r, const V &v, const XYZVector &answer, double t)
XYZVector ans(TestRotation const &t, XYZVector const &v_in)
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
int doTest(TestRotation const &testRotation, XYZVector const &testVector, double ticks)
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z...
DisplacementVector3D< Cartesian3D< double >, DefaultCoordinateSystemTag > XYZVector
3D Vector based on the cartesian coordinates x,y,z in double precision
Class describing a generic position vector (point) in 3 dimensions.
int doTestA(XYZVector const &testVector, double ticks)
int doTestLA(XYZVector const &testVector, double ticks)
Class describing a 3D cartesian coordinate system (x, y, z coordinates)
LorentzVector< CoordSystem > & SetXYZT(Scalar xx, Scalar yy, Scalar zz, Scalar tt)
set the values of the vector from the cartesian components (x,y,z,t) (if the vector is held in anothe...
TRObject operator()(const T1 &t1) const
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Rotation3D rrr(TestRotation const &t)
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.
double pow(double, double)
int doTestOfR(TestRotation const &testRotation, XYZVector const &testVector)
double correctTicks(double ticks, double z, double r)
Scalar E() const
return 4-th component (time, or energy for a 4-momentum vector)
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
static const std::string name()
int doTestOfAxial(XYZVector const &testVector)
Class describing a generic displacement vector in 3 dimensions.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
int rotationApplication(bool forceRun=false)
int exerciseTestCase(TestRotation const &testRotation, XYZVector const &testVector)
static const std::string name()
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
std::vector< TestRotation > makeTestRotations()
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
int exerciseAxialTest(XYZVector const &testVector)
int compare3D(const V1 &v1, const V2 &v2, double ticks)
XYZVector rzv(double phi, XYZVector v)
RooCmdArg Precision(Double_t prec)
int doTestL(TestRotation const &testRotation, XYZVector const &testVector, double ticks)
XYZVector ryv(double phi, XYZVector v)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
XYZVector rxv(double phi, XYZVector v)
you should not use this method at all Int_t Int_t z
Bool_t operator==(const TDatime &d1, const TDatime &d2)
int closeEnough(Scalar1 s1, Scalar2 s2, std::string const &coord, double ticks)
std::vector< XYZVector > makeTestVectors()
Rotation3D::Scalar Scalar