Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Tests/UnitTests/Core/Utilities/BinUtilityTests.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013 #include "Acts/Utilities/BinUtility.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "Acts/Utilities/ProtoAxis.hpp"
0016 
0017 #include <array>
0018 #include <cmath>
0019 #include <cstddef>
0020 #include <numbers>
0021 #include <utility>
0022 #include <vector>
0023 
0024 using namespace Acts;
0025 
0026 namespace ActsTests {
0027 
0028 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0029 
0030 // OPEN - equidistant binning tests
0031 BOOST_AUTO_TEST_CASE(BinUtility_equidistant_binning) {
0032   Vector3 xyzPosition(1.5, 2.5, 3.5);
0033   Vector3 edgePosition(0.5, 0.5, 0.5);
0034 
0035   // | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
0036   BinUtility xUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0037   BinUtility yUtil_eq(10, 0., 10., open, AxisDirection::AxisY);
0038   BinUtility zUtil_eq(10, 0., 10., open, AxisDirection::AxisZ);
0039   BOOST_CHECK_EQUAL(xUtil_eq.bins(), std::size_t{10});
0040   // make it 2-dim
0041   BinUtility xyUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0042   xyUtil_eq += yUtil_eq;
0043   BOOST_CHECK_EQUAL(xyUtil_eq.bins(), 100u);
0044   // make it 3-dim
0045   BinUtility xyzUtil_eq(xyUtil_eq);
0046   xyzUtil_eq += zUtil_eq;
0047   BOOST_CHECK_EQUAL(xyzUtil_eq.bins(), 1000u);
0048   // check the dimensions
0049   BOOST_CHECK_EQUAL(xUtil_eq.dimensions(), 1u);
0050   BOOST_CHECK_EQUAL(xyUtil_eq.dimensions(), 2u);
0051   BOOST_CHECK_EQUAL(xyzUtil_eq.dimensions(), 3u);
0052 
0053   // check equality operator
0054   BinUtility xUtil_eq_copy(10, 0., 10., open, AxisDirection::AxisX);
0055   BOOST_CHECK_EQUAL(xUtil_eq_copy, xUtil_eq);
0056   BOOST_CHECK_NE(yUtil_eq, xUtil_eq);
0057 
0058   // bin triples and clusters
0059   auto xTriple = xUtil_eq.binTriple(xyzPosition);
0060   auto xyTriple = xyUtil_eq.binTriple(xyzPosition);
0061   auto xyzTriple = xyzUtil_eq.binTriple(xyzPosition);
0062 
0063   BOOST_CHECK_EQUAL(xTriple[0], 1u);
0064   BOOST_CHECK_EQUAL(xTriple[1], 0u);
0065   BOOST_CHECK_EQUAL(xTriple[2], 0u);
0066 
0067   BOOST_CHECK_EQUAL(xyTriple[0], 1u);
0068   BOOST_CHECK_EQUAL(xyTriple[1], 2u);
0069   BOOST_CHECK_EQUAL(xyTriple[2], 0u);
0070 
0071   BOOST_CHECK_EQUAL(xyzTriple[0], 1u);
0072   BOOST_CHECK_EQUAL(xyzTriple[1], 2u);
0073   BOOST_CHECK_EQUAL(xyzTriple[2], 3u);
0074 }
0075 
0076 // OPEN - equidistant binning tests
0077 BOOST_AUTO_TEST_CASE(BinUtility_arbitrary_binning) {
0078   std::vector<float> bvalues = {-5., 0., 1., 1.1, 8.};
0079   BinUtility xUtil(bvalues, open, AxisDirection::AxisX);
0080 
0081   // Underflow
0082   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-6., 0., 0.)), 0u);
0083   // Bin 0
0084   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-4., 0., 0.)), 0u);
0085   // Bin 1
0086   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(0.5, 0., 0.)), 1u);
0087   // Bin 2
0088   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(1.05, 0., 0.)), 2u);
0089   // Bin 3
0090   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(4., 0., 0.)), 3u);
0091   // Overflow
0092   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(9., 0., 0.)), 3u);
0093 }
0094 
0095 // OPEN - local to global transform test
0096 BOOST_AUTO_TEST_CASE(BinUtility_transform) {
0097   Transform3 transform_LtoG = Transform3::Identity();
0098   transform_LtoG = transform_LtoG * Translation3(0., 0., -50);
0099   transform_LtoG =
0100       transform_LtoG * AngleAxis3(std::numbers::pi / 4., Vector3(0, 0, 1));
0101 
0102   Transform3 transform_GtoL = transform_LtoG.inverse();
0103 
0104   BinUtility rUtil(10, 0., 100., open, AxisDirection::AxisR);
0105   BinUtility phiUtil(10, -std::numbers::pi, std::numbers::pi, closed,
0106                      AxisDirection::AxisPhi);
0107   BinUtility zUtil(10, -100., 100., open, AxisDirection::AxisZ);
0108 
0109   BinUtility noTranform;
0110   noTranform += rUtil;
0111   noTranform += phiUtil;
0112   noTranform += zUtil;
0113 
0114   BinUtility withTranform(transform_LtoG);
0115   withTranform += rUtil;
0116   withTranform += phiUtil;
0117   withTranform += zUtil;
0118 
0119   Vector3 pos1(0, 0, 0);
0120   Vector3 pos2(60, 0, 0);
0121   Vector3 pos3(34, std::numbers::pi / 2., 0);
0122   Vector3 pos4(0, 0, -80);
0123   Vector3 pos5(80, -std::numbers::pi / 4., 50);
0124 
0125   for (int i = 0; i < 3; i++) {
0126     BOOST_CHECK_EQUAL(withTranform.bin(pos1, i),
0127                       noTranform.bin(transform_GtoL * pos1, i));
0128     BOOST_CHECK_EQUAL(withTranform.bin(pos2, i),
0129                       noTranform.bin(transform_GtoL * pos2, i));
0130     BOOST_CHECK_EQUAL(withTranform.bin(pos3, i),
0131                       noTranform.bin(transform_GtoL * pos3, i));
0132     BOOST_CHECK_EQUAL(withTranform.bin(pos4, i),
0133                       noTranform.bin(transform_GtoL * pos4, i));
0134     BOOST_CHECK_EQUAL(withTranform.bin(pos5, i),
0135                       noTranform.bin(transform_GtoL * pos5, i));
0136   }
0137 }
0138 
0139 BOOST_AUTO_TEST_CASE(BinUtility_from_ProtoAxis) {
0140   using enum AxisDirection;
0141   using enum AxisBoundaryType;
0142 
0143   DirectedProtoAxis epabX(AxisX, Bound, 0.0, 1.0, 10);
0144   BinUtility buX(epabX);
0145   BOOST_CHECK_EQUAL(buX.bins(), std::size_t{10});
0146   BOOST_CHECK_EQUAL(buX.dimensions(), std::size_t{1});
0147 
0148   DirectedProtoAxis epabY(AxisY, Bound, 0.0, 1.0, 10);
0149   BinUtility buXY({epabX, epabY});
0150   BOOST_CHECK_EQUAL(buXY.bins(), std::size_t{100});
0151   BOOST_CHECK_EQUAL(buXY.dimensions(), std::size_t{2});
0152 }
0153 
0154 BOOST_AUTO_TEST_SUITE_END()
0155 
0156 }  // namespace ActsTests