// SpacePointVector_t.cpp // Test the SpacePointVector class. #include "SpacePointVector.h" #include "ptr/Ptr.h" #include #include #include #include #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; #ifndef DEFECT_CMATH_NOT_STD using std::fabs; using std::sqrt; #endif #endif //********************************************************************** bool myequal(double x1, double x2) { return fabs(x2-x1) < 1.e-10; } //********************************************************************** int main() { string name = "SpacePointVector"; string ok_prefix = name + " test (I): "; string error_prefix = name + " test (E): "; cout << ok_prefix << "------- Testing component " + name + ". -------" << endl; double x = 1.23; double y = 2.46; double z = 3.69; double vx = 0.23; double vy = 0.45; double vz = 0.67; //********************************************************************** cout << ok_prefix << "Testing constructors." << endl; // Create a spacevector CartesianPointVector cart(x,y,z,vx,vy,vz); cout << cart << endl; // Create in cylindrical coordinates. CylindricalPointVector cyl( cart.rxy(), cart.phi(), cart.z(), cart.v_rxy(), cart.v_phi(), cart.v_z() ); cout << cyl << endl; // Create in spherical coordinates. SphericalPointVector sph( cyl.rxyz(), cyl.phi(), cyl.theta(), cyl.v_rxyz(), cyl.v_theta(), cyl.v_phi() ); cout << sph << endl; assert( myequal(sph.x(),x) ); assert( myequal(sph.y(),y) ); assert( myequal(sph.z(),z) ); assert( myequal(sph.v_x(),vx) ); assert( myequal(sph.v_y(),vy) ); assert( myequal(sph.v_z(),vz) ); // Create a cartesian coordinates from spacepoint CartesianPointVector cart2( sph, sph.v_x(), sph.v_y(), sph.v_z() ); cout << cart2 << endl; // Create in cylindrical coordinates. CylindricalPointVector cyl2( cart2, cart2.v_rxy(), cart2.v_phi(), cart2.v_z() ); cout << cyl2 << endl; // Create in spherical coordinates. SphericalPointVector sph2( cyl2, cyl2.v_rxyz(), cyl2.v_theta(), cyl2.v_phi() ); cout << sph2 << endl; assert( myequal(sph2.x(),x) ); assert( myequal(sph2.y(),y) ); assert( myequal(sph2.z(),z) ); assert( myequal(sph2.v_x(),vx) ); assert( myequal(sph2.v_y(),vy) ); assert( myequal(sph2.v_z(),vz) ); //********************************************************************** cout << ok_prefix << "Testing equality." << endl; assert( sph == sph ); if ( sph != sph2 ) { cout.precision(17); cout << "Tolerance is " << SpacePoint::equal_tolerance() << endl; cout << sph << endl; cout << sph2 << endl; } assert( sph == sph2 ); assert( ! ( sph != sph2 ) ); //********************************************************************** cout << ok_prefix << "Testing assignment." << endl; SpacePointVector svec; cout << svec << endl; assert( svec.magnitude() == 0.0 ); svec = sph; cout << svec << endl; assert( myequal(svec.x(),x) ); assert( myequal(svec.y(),y) ); assert( myequal(svec.z(),z) ); assert( myequal(svec.v_x(),vx) ); assert( myequal(svec.v_y(),vy) ); assert( myequal(svec.v_z(),vz) ); //********************************************************************** cout << ok_prefix << "Testing normalizations." << endl; double n0 = vx*vx + vy*vy + vz*vz; cout << n0 << endl; double ncart = svec.v_x()*svec.v_x() + svec.v_y()*svec.v_y() + svec.v_z()*svec.v_z(); cout << ncart << endl; double ncyl = svec.v_rxy()*svec.v_rxy() + svec.v_phi()*svec.v_phi() + svec.v_z()*svec.v_z(); cout << ncyl << endl; double nsph = svec.v_rxyz()*svec.v_rxyz() + svec.v_theta()*svec.v_theta() + svec.v_phi()*svec.v_phi(); cout << nsph << endl; assert( myequal(ncart,n0) ); assert( myequal(ncyl,n0) ); assert( myequal(nsph,n0) ); assert( myequal( sqrt(n0), svec.magnitude() ) ); //********************************************************************** cout << ok_prefix << "------------- All tests passed. ------------" << endl; return 0; }