int testVector3D() { std::cout << "\n************************************************************************\n " << " Vector 3D Test" << "\n************************************************************************\n"; //CINT cannot autoload classes known only via a typedef (here XYZVector) gSystem->Load("libGenVector"); XYZVector v1(0.01, 0.02, 16); //XYZVector v1(1.0, 2.0, 3.0); // XYZVector v1(1.0, 2.0, 30.0); // double R = sqrt (v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z()); // // this formula in not precise enough // // double Theta = R>0 ? acos ( v1.Z()/r ) : 0; // double Rho = sqrt (v1.X()*v1.X() + v1.Y()*v1.Y()); // double Theta = v1.Z() == 0 || Rho == 0 ? 0 : atan2( Rho, v1.Z() ); // double Phi = Rho>0 ? atan2 (v1.Y(), v1.X()) : 0; std::cout << "Test Cartesian-Polar : " ; Polar3DVector v2(v1.R(), v1.Theta(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v2.X(), "x"); ok+= compare(v1.Y(), v2.Y(), "y"); ok+= compare(v1.Z(), v2.Z(), "z"); ok+= compare(v1.Phi(), v2.Phi(), "phi"); ok+= compare(v1.Theta(), v2.Theta(), "theta"); ok+= compare(v1.R(), v2.R(), "r"); ok+= compare(v1.Eta(), v2.Eta(), "eta"); ok+= compare(v1.Rho(), v2.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Cartesian-CylindricalEta : "; RhoEtaPhiVector v3( v1.Rho(), v1.Eta(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v3.X(), "x"); ok+= compare(v1.Y(), v3.Y(), "y"); ok+= compare(v1.Z(), v3.Z(), "z"); ok+= compare(v1.Phi(), v3.Phi(), "phi"); ok+= compare(v1.Theta(), v3.Theta(), "theta"); ok+= compare(v1.R(), v3.R(), "r"); ok+= compare(v1.Eta(), v3.Eta(), "eta"); ok+= compare(v1.Rho(), v3.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Cartesian-Cylindrical : "; RhoZPhiVector v4( v1.Rho(), v1.Z(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v4.X(), "x"); ok+= compare(v1.Y(), v4.Y(), "y"); ok+= compare(v1.Z(), v4.Z(), "z"); ok+= compare(v1.Phi(), v4.Phi(), "phi"); ok+= compare(v1.Theta(), v4.Theta(), "theta"); ok+= compare(v1.R(), v4.R(), "r"); ok+= compare(v1.Eta(), v4.Eta(), "eta"); ok+= compare(v1.Rho(), v4.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Operations : " ; ok = 0; double Dot = v1.Dot(v2); ok+= compare( Dot, v1.Mag2(),"dot" ); XYZVector vcross = v1.Cross(v2); ok+= compare( vcross.R(), 0,"cross" ); //std::cout << "\nTest Unit & scaling : " ; XYZVector vscale1 = v1*10; XYZVector vscale2 = vscale1/10; ok+= compare( v1.R(), vscale2.R(), "scale"); XYZVector vu = v1.Unit(); ok+= compare(v2.Phi(),vu.Phi(),"unit Phi"); ok+= compare(v2.Theta(),vu.Theta(),"unit Theta"); ok+= compare(1.0,vu.R(),"unit "); XYZVector q1 = v1; // RhoEtaPhiVector q2 = v1; ! copy onstructor between different vector does not work yet) RhoEtaPhiVector q2(1.0,1.0,1.0); XYZVector q3 = q1 + q2; XYZVector q4 = q3 - q2; ok+= compare( q4.X(), q1.X(), "op X" ); ok+= compare( q4.Y(), q1.Y(), "op Y" ); ok+= compare( q4.Z(), q1.Z(), "op Z" ); // test operator == XYZVector w1 = v1; Polar3DVector w2 = v2; RhoEtaPhiVector w3 = v3; RhoZPhiVector w4 = v4; ok+= compare( w1 == v1, static_cast<double>(true), "== XYZ"); ok+= compare( w2 == v2, static_cast<double>(true), "== Polar"); ok+= compare( w3 == v3, static_cast<double>(true), "== RhoEtaPhi"); ok+= compare( w4 == v4, static_cast<double>(true), "== RhoZPhi"); if (ok == 0) std::cout << "\t OK " << std::endl; //test setters std::cout << "Test Setters : " ; q2.SetXYZ(q1.X(), q1.Y(), q1.Z() ); ok+= compare( q2.X(), q1.X(), "setXYZ X" ); ok+= compare( q2.Y(), q1.Y(), "setXYZ Y" ); ok+= compare( q2.Z(), q1.Z(), "setXYZ Z" ); q2.SetCoordinates( 2.0*q1.Rho(), q1.Eta(), q1.Phi() ); XYZVector q1s = 2.0*q1; ok+= compare( q2.X(), q1s.X(), "set X" ); ok+= compare( q2.Y(), q1s.Y(), "set Y" ); ok+= compare( q2.Z(), q1s.Z(), "set Z" ); if (ok == 0) std::cout << "\t\t OK " << std::endl; std::cout << "Test Linear Algebra conversion: " ; XYZVector vxyz1(1.,2.,3.); TVectorD vla1(3); vxyz1.Coordinates().GetCoordinates(vla1.GetMatrixArray() ); TVectorD vla2(3); vla2[0] = 1.; vla2[1] = -2.; vla2[2] = 1.; XYZVector vxyz2; vxyz2.SetCoordinates(&vla2[0]); ok = 0; double prod1 = vxyz1.Dot(vxyz2); double prod2 = vla1*vla2; ok+= compare( prod1, prod2, "la test" ); if (ok == 0) std::cout << "\t\t OK " << std::endl; return ok; }
int testLorentzVector() { std::cout << "\n************************************************************************\n " << " Loorentz Vector Tests" << "\n************************************************************************\n"; //XYZTVector v1(0.00001, 0.00001, 30000000000.0); XYZTVector v1(1.0, 2.0, 3.0, 4.0); std::cout << "Test XYZT - PtEtaPhiE Vectors: "; PtEtaPhiEVector v2( v1.Rho(), v1.Eta(), v1.Phi(), v1.E() ); ok = 0; ok+= compare(v1.Px(), v2.X(), "x"); ok+= compare(v1.Py(), v2.Y(), "y"); ok+= compare(v1.Pz(), v2.Z(), "z", 2); ok+= compare(v1.E(), v2.T(), "e"); ok+= compare(v1.Phi(), v2.Phi(), "phi"); ok+= compare(v1.Theta(), v2.Theta(), "theta"); ok+= compare(v1.Pt(), v2.Pt(), "pt"); ok+= compare(v1.M(), v2.M(), "mass", 5); ok+= compare(v1.Et(), v2.Et(), "et"); ok+= compare(v1.Mt(), v2.Mt(), "mt", 3); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test XYZT - PtEtaPhiM Vectors: "; PtEtaPhiMVector v3( v1.Rho(), v1.Eta(), v1.Phi(), v1.M() ); ok = 0; ok+= compare(v1.Px(), v3.X(), "x"); ok+= compare(v1.Py(), v3.Y(), "y"); ok+= compare(v1.Pz(), v3.Z(), "z", 2); ok+= compare(v1.E(), v3.T(), "e"); ok+= compare(v1.Phi(), v3.Phi(), "phi"); ok+= compare(v1.Theta(), v3.Theta(), "theta"); ok+= compare(v1.Pt(), v3.Pt(), "pt"); ok+= compare(v1.M(), v3.M(), "mass", 5); ok+= compare(v1.Et(), v3.Et(), "et"); ok+= compare(v1.Mt(), v3.Mt(), "mt", 3); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test PtEtaPhiE - PxPyPzM Vect.: "; PxPyPzMVector v4( v3.X(), v3.Y(), v3.Z(), v3.M() ); ok = 0; ok+= compare(v4.Px(), v3.X(), "x"); ok+= compare(v4.Py(), v3.Y(), "y"); ok+= compare(v4.Pz(), v3.Z(), "z",2); ok+= compare(v4.E(), v3.T(), "e"); ok+= compare(v4.Phi(), v3.Phi(), "phi"); ok+= compare(v4.Theta(), v3.Theta(), "theta"); ok+= compare(v4.Pt(), v3.Pt(), "pt"); ok+= compare(v4.M(), v3.M(), "mass",5); ok+= compare(v4.Et(), v3.Et(), "et"); ok+= compare(v4.Mt(), v3.Mt(), "mt",3); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test operations : "; //std::cout << "\nTest Dot product : " ; ok = 0; double Dot = v1.Dot(v2); ok+= compare( Dot, v1.M2(),"dot" , 10 ); //std::cout << "\nTest scaling : " ; XYZTVector vscale1 = v1*10; XYZTVector vscale2 = vscale1/10; ok+= compare( v1.M(), vscale2.M(), "scale"); XYZTVector q1 = v1; // RhoEtaPhiVector q2 = v1; ! copy onstructor between different vector does not work yet) PtEtaPhiEVector q2(1.0,1.0,1.0,5.0); XYZTVector q3 = q1 + q2; XYZTVector q4 = q3 - q2; ok+= compare( q4.x(), q1.X(), "op X" ); ok+= compare( q4.y(), q1.Y(), "op Y" ); ok+= compare( q4.z(), q1.Z(), "op Z" ); ok+= compare( q4.t(), q1.E(), "op E" ); // test operator == XYZTVector w1 = v1; PtEtaPhiEVector w2 = v2; PtEtaPhiMVector w3 = v3; PxPyPzMVector w4 = v4; ok+= compare( w1 == v1, static_cast<double>(true), "== PxPyPzE"); ok+= compare( w2 == v2, static_cast<double>(true), "== PtEtaPhiE"); ok+= compare( w3 == v3, static_cast<double>(true), "== PtEtaPhiM"); ok+= compare( w4 == v4, static_cast<double>(true), "== PxPyPzM"); // test gamma beta and boost XYZVector b = q1.BoostToCM(); double beta = q1.Beta(); double gamma = q1.Gamma(); ok += compare( b.R(), beta, "beta" ); ok += compare( gamma, 1./sqrt( 1 - beta*beta ), "gamma"); if (ok == 0) std::cout << "\t OK " << std::endl; //test setters std::cout << "Test Setters : " ; q2.SetXYZT(q1.Px(), q1.Py(), q1.Pz(), q1.E() ); ok+= compare( q2.X(), q1.X(), "setXYZT X" ); ok+= compare( q2.Y(), q1.Y(), "setXYZT Y" ); ok+= compare( q2.Z(), q1.Z(), "setXYZT Z" ,2); ok+= compare( q2.T(), q1.E(), "setXYZT E" ); q2.SetCoordinates( 2.0*q1.Rho(), q1.Eta(), q1.Phi(), 2.0*q1.E() ); XYZTVector q1s = q1*2.0; ok+= compare( q2.X(), q1s.X(), "set X" ); ok+= compare( q2.Y(), q1s.Y(), "set Y" ); ok+= compare( q2.Z(), q1s.Z(), "set Z" ,2); ok+= compare( q2.T(), q1s.T(), "set E" ); if (ok == 0) std::cout << "\t OK " << std::endl; return ok; }