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