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
33 math_utils::Transform3D tr(hmat);
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
39 math_utils::Point3D<float> pft;
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
60 math_utils::Point3D<double> pdti;
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>;
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}
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char pp
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)