Project
Loading...
Searching...
No Matches
testCartesian.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test Cartesian3D
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <TGeoMatrix.h>
16#include <boost/test/unit_test.hpp>
17#include <iostream>
18#include <algorithm>
19#include <memory>
20#include <cstring>
21#include "MathUtils/Cartesian.h"
22
23using namespace o2;
24
25BOOST_AUTO_TEST_CASE(Cartesian_test)
26{
27 // we create Transform3D by conversion from TGeoHMatrix
28 TGeoRotation rotg("r", 10., 20., 30.);
29 TGeoTranslation trag("g", 100., 200., 300.);
30 TGeoHMatrix hmat = trag;
31 hmat *= rotg;
32
34 math_utils::Point3D<double> pd(10., 20., 30.);
35 math_utils::Point3D<float> pf(10.f, 20.f, 30.f);
36 //
37 // local to master
38 auto pdt = tr(pd); // operator form
40 tr.LocalToMaster(pf, pft); // TGeoHMatrix form
41
42 std::cout << "Create Transform3D " << std::endl
43 << tr << std::endl
44 << "from" << std::endl;
45 hmat.Print();
46
47 std::cout << " Transforming " << pd << " to master" << std::endl;
48 // compare difference between float and double vector transform
49 std::cout << "Float: " << pft << std::endl;
50 std::cout << "Double: " << pdt << std::endl;
51 std::cout << "Diff: " << pdt.X() - pft.X() << "," << pdt.Y() - pft.Y() << "," << pdt.Z() - pft.Z() << std::endl;
52
53 const double toler = 1e-4;
54 BOOST_CHECK(std::abs(pdt.X() - pft.X()) < toler);
55 BOOST_CHECK(std::abs(pdt.Y() - pft.Y()) < toler);
56 BOOST_CHECK(std::abs(pdt.Z() - pft.Z()) < toler);
57
58 // inverse transform
59 auto pfti = tr ^ (pft); // operator form
61 tr.MasterToLocal(pdt, pdti); // TGeoHMatrix form
62
63 std::cout << " Transforming back to local" << std::endl;
64 std::cout << "Float: " << pfti << std::endl;
65 std::cout << "Double: " << pdti << std::endl;
66 std::cout << "Diff: " << pd.X() - pfti.X() << ", " << pd.Y() - pfti.Y() << ", " << pd.Z() - pfti.Z() << std::endl;
67
68 BOOST_CHECK(std::abs(pd.X() - pfti.X()) < toler);
69 BOOST_CHECK(std::abs(pd.Y() - pfti.Y()) < toler);
70 BOOST_CHECK(std::abs(pd.Z() - pfti.Z()) < toler);
71
72 BOOST_CHECK(std::abs(pdti.X() - pfti.X()) < toler);
73 BOOST_CHECK(std::abs(pdti.Y() - pfti.Y()) < toler);
74 BOOST_CHECK(std::abs(pdti.Z() - pfti.Z()) < toler);
75}
76
77BOOST_AUTO_TEST_CASE(Point3D_messageable)
78{
79 using ElementType = math_utils::Point3D<int>;
80 static_assert(std::is_trivially_copyable<ElementType>::value == true);
81 std::vector<ElementType> pts(10);
82 auto makeElement = [](int idx) {
83 return ElementType{idx, idx + 10, idx + 20};
84 };
85 std::generate(pts.begin(), pts.end(), [makeElement, idx = std::make_shared<int>(0)]() { return makeElement(++(*idx)); });
86
87 size_t memsize = sizeof(ElementType) * pts.size();
88 auto buffer = std::make_unique<char[]>(memsize);
89 memcpy(buffer.get(), (char*)pts.data(), memsize);
90 auto* pp = reinterpret_cast<ElementType*>(buffer.get());
91
92 for (auto const& point : pts) {
93 BOOST_REQUIRE(point == *pp);
94 ++pp;
95 }
96}
void MasterToLocal(const Point3D< T > &mst, Point3D< T > &loc) const
Definition Cartesian.h:231
void LocalToMaster(const Point3D< T > &loc, Point3D< T > &mst) const
Definition Cartesian.h:225
GLuint buffer
Definition glcorearb.h:655
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(Cartesian_test)
BOOST_CHECK(tree)