// // Test.C // // Implements a suite of simple tests to verify that the basic classes // of the Dirac++ package have been built successfully. // // author: richard.t.jones at uconn.edu // version: january 1, 2000 #include #include "Complex.h" #include "TFourVectorReal.h" #include "TFourVectorComplex.h" #include "TThreeRotation.h" #include "TLorentzBoost.h" #include "TDiracSpinor.h" #include "TDiracMatrix.h" int tests() { TThreeVectorReal v3v; v3v.Zero(); std::cout << "tests.C is now loaded." << std::endl; std::cout << "To run a test of a class, type Test()" << std::endl; std::cout << "Example: TestFourVectorReal()" << std::endl; return 0; } void TestThreeVectorReal() { TThreeVectorReal v3v; v3v.Zero(); std::cout << "Zero(): "; v3v.Print(); v3v[1] = 1; v3v[2] = 2; v3v[3] = 3; std::cout << "Set to 1,2,3: "; v3v.Print(); TThreeVectorReal v3w(4,5,6); std::cout << "Initialized to 4,5,6: "; v3w.Print(); Float_t aarray[]={7,8,9,10}; TThreeVectorReal v3x(aarray); std::cout << "Initialized to (Float_t *) 7,8,9: "; v3x.Print(); LDouble_t darray[]={10,11,12,13}; TThreeVectorReal v3y(darray); std::cout << "Initialized to (LDouble_t *) 10,11,12: "; v3y.Print(); TThreeVectorReal v3z(v3v); std::cout << "Initialized to (TThreeVectorReal) 1,2,3: "; v3z.Print(); v3z.SpaceInv(); std::cout << "SpaceInv(): "; v3z.Print(); v3z.Normalize(1); std::cout << "Normalize(1): "; v3z.Print(); v3z.SetPolar(10,2.5,-1.2); std::cout << "SetPolar(10,2.5,-1.2) : GetPolar("; std::cout << v3z.Length() << "," << v3z.Theta() << "," << v3z.Phi() << ")" << std::endl; std::cout << "z == z ? " << ((v3z == v3z) ? "yes!" : "no!") << std::endl; std::cout << "z != w ? " << ((v3z != v3w) ? "yes!" : "no!") << std::endl; v3z.Rotate(-1.2,2.5,0); LDouble_t v3zhat[]={0,0,10}; std::cout << "Rotate(phi,theta,0) gets back z axis? "; std::cout << ((v3z == TThreeVectorReal(v3zhat)) ? "yes!" : "no!" ) << std::endl; std::cout << "(w cross x) != 0 ? "; std::cout << ((v3z.Cross(v3w,v3x).Length() >= v3w.Resolution()) ? "yes!" : "no!" ) << std::endl; std::cout << "w dot (w cross x) == 0 ? "; std::cout << ((v3w.Dot(v3z.Cross(v3w,v3x)) < v3w.Resolution()) ? "yes!" : "no!" ) << std::endl; v3y.Cross(v3w,v3w-v3x); v3z.Cross(v3x,v3w); std::cout << "w cross (w - x) == x cross w ? "; std::cout << ((v3y.Cross(v3w,v3w-v3x) == v3z.Cross(v3x,v3w)) ? "yes!" : "no!" ) << std::endl; } void TestThreeVectorComplex() { TThreeVectorComplex v3v; v3v.Zero(); std::cout << "Zero(): "; v3v.Print(); v3v[1] = 1; v3v[2] = 2; v3v[3] = 3; std::cout << "Set to 1,2,3: "; v3v.Print(); TThreeVectorComplex v3w(4,5,6); std::cout << "Initialized to 4,5,6: "; v3w.Print(); Float_t farray[]={7,8,9,10}; TThreeVectorComplex v3x(farray); std::cout << "Initialized to (Float_t *) 7,8,9: "; v3x.Print(); LDouble_t darray[]={10,11,12,13}; TThreeVectorComplex v3y(darray); std::cout << "Initialized to (LDouble_t *) 10,11,12: "; v3y.Print(); TThreeVectorComplex v3z(v3v); std::cout << "Initialized to (TThreeVectorComplex) 1,2,3: "; v3z.Print(); v3z.SpaceInv(); std::cout << "SpaceInv(): "; v3z.Print(); v3z.Normalize(1); std::cout << "Normalize(1): "; v3z.Print(); std::cout << "z == z ? " << ((v3z == v3z) ? "yes!" : "no!") << std::endl; std::cout << "z != w ? " << ((v3z != v3w) ? "yes!" : "no!") << std::endl; TThreeVectorReal v3r(242.99,-485,0.6666); v3z = v3r.Normalize(10); v3z.Rotate(v3r.Phi(),v3r.Theta(),0); LDouble_t v3zhat[]={0,0,10}; std::cout << "Rotate(phi,theta,0) gets back z axis? "; std::cout << ((v3z == TThreeVectorReal(v3zhat)) ? "yes!" : "no!" ) << std::endl; std::cout << "(w cross x) != 0 ? "; std::cout << ((v3z.Cross(v3w,v3x).Length() >= v3w.Resolution()) ? "yes!" : "no!" ) << std::endl; std::cout << "w dot (w cross x) == 0 ? "; std::cout << ((abs(v3w.Dot(v3z.Cross(v3w,v3x))) < v3w.Resolution()) ? "yes!" : "no!" ) << std::endl; v3y.Cross(v3w,v3w-v3x); v3z.Cross(v3x,v3w); std::cout << "w cross (w - x) == x cross w ? "; std::cout << ((v3y.Cross(v3w,v3w-v3x) == v3z.Cross(v3x,v3w)) ? "yes!" : "no!" ) << std::endl; } void TestFourVectorReal() { TFourVectorReal v4v; v4v.Zero(); std::cout << "Zero(): "; v4v.Print(); v4v[0] = 10; v4v[1] = 1; v4v[2] = 2; v4v[3] = 3; std::cout << "Set to 10,1,2,3: "; v4v.Print(); TFourVectorReal v4w(-4,4,5,6); std::cout << "Initialized to -4,4,5,6: "; v4w.Print(); Float_t aarray[]={7,8,9,10}; TFourVectorReal v4x(aarray); std::cout << "Initialized to (Float_t *) 7,8,9,10: "; v4x.Print(); LDouble_t darray[]={10,11,12,13}; TFourVectorReal v4y(darray); std::cout << "Initialized to (LDouble_t *) 10,11,12,13: "; v4y.Print(); TFourVectorReal v4z(v4v); std::cout << "Initialized to (TFourVectorReal) 10,1,2,3: "; v4z.Print(); v4z.SpaceInv(); std::cout << "SpaceInv(): "; v4z.Print(); v4z /= v4z.Invariant(); std::cout << "v4z /= v4z.Invariant(): "; v4z.Print(); TFourVectorReal v4u(v4z); v4z.Boost(0,0,.99); std::cout << "v4z.Boost(0,0,.99): "; v4z.Print(); std::cout << "Lorentz invariant? "; std::cout << ((abs(v4z.Invariant()-v4u.Invariant()) < v4z.Resolution()) ? "yes!" : "no!") << std::endl; v4z.Boost(0,0,-.99); std::cout << "Boost back, recover original vector? "; std::cout << ((v4z == v4u) ? "yes!" : "no!") << std::endl; } void TestFourVectorComplex() { TFourVectorComplex v4v; v4v.Zero(); std::cout << "Zero(): "; v4v.Print(); v4v[0] = 10; v4v[1] = 1; v4v[2] = 2; v4v[3] = 3; std::cout << "Set to 10,1,2,3: "; v4v.Print(); TFourVectorComplex v4w(-4,4,5,6); std::cout << "Initialized to -4,4,5,6: "; v4w.Print(); Float_t aarray[]={7,8,9,10}; TFourVectorComplex v4x(aarray); std::cout << "Initialized to (Float_t *) 7,8,9,10: "; v4x.Print(); LDouble_t darray[]={10,11,12,13}; TFourVectorComplex v4y(darray); std::cout << "Initialized to (LDouble_t *) 10,11,12,13: "; v4y.Print(); TFourVectorComplex v4z(v4v); std::cout << "Initialized to (TFourVectorComplex) 10,1,2,3: "; v4z.Print(); v4z.SpaceInv(); std::cout << "SpaceInv(): "; v4z.Print(); v4z /= v4z.Invariant(); std::cout << "v4z /= v4z.Invariant(): "; v4z.Print(); TFourVectorComplex v4u(v4z); v4z.Boost(0,0,.99); std::cout << "v4z.Boost(0,0,.99): "; v4z.Print(); std::cout << "Lorentz invariant? "; std::cout << ((abs(v4z.Invariant()-v4u.Invariant()) < v4z.Resolution()) ? "yes!" : "no!") << std::endl; v4z.Boost(0,0,-.99); std::cout << "Boost back, recover original vector? "; std::cout << ((v4z == v4u) ? "yes!" : "no!") << std::endl; } void TestRotation() { TThreeVectorReal w1(0,0,1.2); TThreeVectorReal w2(0,0.887,0); TThreeVectorReal w3(0,0,-1.557); TThreeRotation r1(w1), r2(w2), r3(w3); TThreeRotation r123=r3*r2*r1; LDouble_t phi=0,theta=0,psi=0; r123.GetEuler(phi,theta,psi); std::cout << "First rotate 1.2 radians about z axis" <