diff --git a/mathcore/test/testGenVector.cxx b/mathcore/test/testGenVector.cxx index 288fec85708782c00d15ac3e0f57bdf271df5533..658d7cebb36f9dcc53fbb581a8b132c15bd60c64 100644 --- a/mathcore/test/testGenVector.cxx +++ b/mathcore/test/testGenVector.cxx @@ -13,7 +13,11 @@ #include "Math/AxisAngle.h" #include "Math/EulerAngles.h" +#include "Math/LorentzRotation.h" + #include "Math/VectorUtil.h" +#include "Math/SMatrix.h" + using namespace ROOT::Math; using namespace ROOT::Math::VectorUtil; @@ -109,6 +113,7 @@ int testVector3D() { + #ifdef TEST_COMPILE_ERROR LocalXYZVector vl; vl = vg; LocalXYZVector vl2(vg2); @@ -253,8 +258,8 @@ int testRotations3D() { // test Get/SetComponents XYZVector v1,v2,v3; rot.GetComponents(v1,v2,v3); - Rotation3D rot2; - rot2.SetComponents(v1,v2,v3); + const Rotation3D rot2(v1,v2,v3); + //rot2.SetComponents(v1,v2,v3); double r1[9],r2[9]; rot.GetComponents(r1,r1+9); rot2.GetComponents(r2,r2+9); @@ -264,6 +269,13 @@ int testRotations3D() { // operator == fails for numerical precision //iret |= compare( (rot2==rot),true,"Get/SetComponens"); + // test get/set with a matrix + SMatrix<double,3> mat; + rot2.GetRotationMatrix(mat); + rot.SetRotationMatrix(mat); + iret |= compare( (rot2==rot),true,"Get/SetRotMatrix"); + + //test inversion Rotation3D rotInv = rot.Inverse(); rot.Invert(); // invert in place @@ -370,6 +382,19 @@ int testTransform3D() { // std::cout << t3( a * q1) << std::endl; // std::cout << a * t3(q1) << std::endl; + // test get/set with a matrix + SMatrix<double,3,4> mat; + t3.GetTransformMatrix(mat); + Transform3D t3b; t3b.SetTransformMatrix(mat); + iret |= compare( (t3==t3b),true,"Get/SetTransformMatrix"); + + // test LR + Boost b(0.2,0.4,0.8); + LorentzRotation lr(b); + SMatrix<double,4> mat4; + lr.GetRotationMatrix(mat4); + LorentzRotation lr2; lr2.SetRotationMatrix(mat4); + iret |= compare( (lr==lr2),true,"Get/SetLRotMatrix"); if (iret == 0) std::cout << "\t\t\t\tOK\n"; else std::cout << "\t\t\t\tFAILED\n"; diff --git a/mathcore/test/testIterator.cxx b/mathcore/test/testIterator.cxx index 21fdf52fc16d785b1320cdf781186b00707a77e5..034159e8f68ca21b8d523e17c6b269333a9270b7 100644 --- a/mathcore/test/testIterator.cxx +++ b/mathcore/test/testIterator.cxx @@ -21,6 +21,9 @@ #include <iostream> #include <iterator> #include <vector> +#include <list> +#include <set> +#include <algorithm> using namespace ROOT::Math; using namespace ROOT::Math::VectorUtil; @@ -39,15 +42,22 @@ void printVec(const V & v ) { v.GetCoordinates(oi); std::cout << ") " << std::endl; } -int main() { +template<class L> +void printList(const L & l ) { + std::cout << "list : ( " ; + std::ostream_iterator<double> oi(std::cout," "); + std::copy(l.begin(),l.end(),oi); + std::cout << ") " << std::endl; +} + +void testOstreamIter() { - std::vector<double> data(16); XYZVector v(1.,2.,3); printVec(v); XYZPoint p(v); printVec(p); XYZTVector q(1.,2,3,4); printVec(q); - AxisAngle ar(v,3.); printRot(ar); + AxisAngle ar(v,4.); printRot(ar); EulerAngles er(ar); printRot(er); Quaternion qr(er); printRot(qr); Rotation3D rr(qr) ; printRot(rr); @@ -55,8 +65,96 @@ int main() { Transform3D t(rr,v); printRot(t); - Boost b(0.9*v/(v.R())); printRot(b); + Boost b(0.3,0.4,0.8); printRot(b); LorentzRotation lr(rr); printRot(lr); LorentzRotation lr2(b); printRot(lr2); } + +void testListIter() { + + // test with lists + double d[10] = {1,2,3,4,5,6,7,8,9,10}; + std::list<double> inputData(d,d+3); + + XYZVector v; v.SetCoordinates(inputData.begin(), inputData.end() ); + std::list<double> data(3); + v.GetCoordinates(data.begin(),data.end()); + printList(data); + + inputData = std::list<double>(d+3,d+6); + XYZPoint p; p.SetCoordinates(inputData.begin(),inputData.end() ); + data.clear(); + data = std::list<double>(3); + p.GetCoordinates(data.begin(), data.end() ); + printList(data); + + inputData = std::list<double>(d+6,d+10); + XYZTVector q; q.SetCoordinates(inputData.begin(),inputData.end() ); + data.clear(); + data = std::list<double>(4); + q.GetCoordinates(data.begin(), data.end() ); + printList(data); + + // test on rotations + inputData = std::list<double>(d,d+3); + EulerAngles re(inputData.begin(), inputData.end() ); + data = std::list<double>(3); + re.GetComponents(data.begin(), data.end() ); + printList(data); + + inputData = std::list<double>(d,d+4); + AxisAngle ra(inputData.begin(), inputData.end() ); + data = std::list<double>(4); + ra.GetComponents(data.begin(), data.end() ); + printList(data); + + inputData = std::list<double>(d,d+4); + Quaternion rq(inputData.begin(), inputData.end() ); + data = std::list<double>(4); + rq.GetComponents(data.begin(), data.end() ); + printList(data); + + double b[3] = {0.3,0.4,0.8}; + inputData = std::list<double>(b,b+3); + Boost bst(inputData.begin(), inputData.end() ); + data = std::list<double>(3); + bst.GetComponents(data.begin(), data.end() ); + printList(data); + + Rotation3D tmp(ra); + inputData = std::list<double>(9); + tmp.GetComponents(inputData.begin()); printList(inputData); + Rotation3D r(inputData.begin(),inputData.end()); + data = std::list<double>(9); + r.GetComponents(data.begin(), data.end() ); + printList(data); + + + Transform3D ttmp(r,XYZVector(1,2,3)); + inputData = std::list<double>(12); + ttmp.GetComponents(inputData.begin()); printList(inputData); + Transform3D t(inputData.begin(),inputData.end()); + data = std::list<double>(12); + t.GetComponents(data.begin(), data.end() ); + printList(data); + + + LorentzRotation ltmp(bst); + inputData = std::list<double>(16); + ltmp.GetComponents(inputData.begin()); printList(inputData); + LorentzRotation lr(inputData.begin(),inputData.end()); + data = std::list<double>(16); + lr.GetComponents(data.begin(), data.end() ); + printList(data); + + +} + +int main() { + + testOstreamIter(); + testListIter(); + + +} diff --git a/mathcore/test/testVectorIO.cxx b/mathcore/test/testVectorIO.cxx index d0bf707922ff40d4b17f518b01756d9f09750f02..124e79e4eda2e3b31a5e8ad87b6f09532ca42b41 100644 --- a/mathcore/test/testVectorIO.cxx +++ b/mathcore/test/testVectorIO.cxx @@ -27,6 +27,8 @@ #define DEBUG +//#define READONLY + //#define USE_REFLEX #ifdef USE_REFLEX #include "Cintex/Cintex.h" @@ -46,6 +48,7 @@ typedef TYPE Point3D; \ const std::string point3d_type = #TYPE ; + //const double tol = 1.0E-16; const double tol = 1.0E-6; // or doublr 32 or float @@ -298,15 +301,25 @@ int testVectorIO() { testDummy<Vector4D>(nEvents); +#ifdef READONLY + w1 = 98.995527276968474; +#else w1 = write<Vector4D>(nEvents,"lorentzvector",vector4d_type); +#endif r1 = read<Vector4D>("lorentzvector"); iret |= testResult(w1,r1,vector4d_type); +#ifdef READONLY + w1 = 17.3281570633214095; +#else w1 = write<Vector3D>(nEvents,"displacementvector",vector3d_type); +#endif r1 = read<Vector3D>("displacementvector"); iret |= testResult(w1,r1,vector3d_type); +#ifndef READONLY w1 = write<Point3D>(nEvents,"positionvector",point3d_type); +#endif r1 = read<Point3D>("positionvector"); iret |= testResult(w1,r1,point3d_type);