Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 07:54:11

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 namespace Acts::Test {
0025 
0026 // OPEN - equidistant binning tests
0027 BOOST_AUTO_TEST_CASE(BinUtility_equidistant_binning) {
0028   Vector3 xyzPosition(1.5, 2.5, 3.5);
0029   Vector3 edgePosition(0.5, 0.5, 0.5);
0030 
0031   // | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
0032   BinUtility xUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0033   BinUtility yUtil_eq(10, 0., 10., open, AxisDirection::AxisY);
0034   BinUtility zUtil_eq(10, 0., 10., open, AxisDirection::AxisZ);
0035   BOOST_CHECK_EQUAL(xUtil_eq.bins(), std::size_t{10});
0036   // make it 2-dim
0037   BinUtility xyUtil_eq(10, 0., 10., open, AxisDirection::AxisX);
0038   xyUtil_eq += yUtil_eq;
0039   BOOST_CHECK_EQUAL(xyUtil_eq.bins(), 100u);
0040   // make it 3-dim
0041   BinUtility xyzUtil_eq(xyUtil_eq);
0042   xyzUtil_eq += zUtil_eq;
0043   BOOST_CHECK_EQUAL(xyzUtil_eq.bins(), 1000u);
0044   // check the dimensions
0045   BOOST_CHECK_EQUAL(xUtil_eq.dimensions(), 1u);
0046   BOOST_CHECK_EQUAL(xyUtil_eq.dimensions(), 2u);
0047   BOOST_CHECK_EQUAL(xyzUtil_eq.dimensions(), 3u);
0048 
0049   // check equality operator
0050   BinUtility xUtil_eq_copy(10, 0., 10., open, AxisDirection::AxisX);
0051   BOOST_CHECK_EQUAL(xUtil_eq_copy, xUtil_eq);
0052   BOOST_CHECK_NE(yUtil_eq, xUtil_eq);
0053 
0054   // bin triples and clusters
0055   auto xTriple = xUtil_eq.binTriple(xyzPosition);
0056   auto xyTriple = xyUtil_eq.binTriple(xyzPosition);
0057   auto xyzTriple = xyzUtil_eq.binTriple(xyzPosition);
0058 
0059   BOOST_CHECK_EQUAL(xTriple[0], 1u);
0060   BOOST_CHECK_EQUAL(xTriple[1], 0u);
0061   BOOST_CHECK_EQUAL(xTriple[2], 0u);
0062 
0063   BOOST_CHECK_EQUAL(xyTriple[0], 1u);
0064   BOOST_CHECK_EQUAL(xyTriple[1], 2u);
0065   BOOST_CHECK_EQUAL(xyTriple[2], 0u);
0066 
0067   BOOST_CHECK_EQUAL(xyzTriple[0], 1u);
0068   BOOST_CHECK_EQUAL(xyzTriple[1], 2u);
0069   BOOST_CHECK_EQUAL(xyzTriple[2], 3u);
0070 }
0071 
0072 // OPEN - equidistant binning tests
0073 BOOST_AUTO_TEST_CASE(BinUtility_arbitrary_binning) {
0074   std::vector<float> bvalues = {-5., 0., 1., 1.1, 8.};
0075   BinUtility xUtil(bvalues, Acts::open, Acts::AxisDirection::AxisX);
0076 
0077   // Underflow
0078   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-6., 0., 0.)), 0u);
0079   // Bin 0
0080   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(-4., 0., 0.)), 0u);
0081   // Bin 1
0082   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(0.5, 0., 0.)), 1u);
0083   // Bin 2
0084   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(1.05, 0., 0.)), 2u);
0085   // Bin 3
0086   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(4., 0., 0.)), 3u);
0087   // Overflow
0088   BOOST_CHECK_EQUAL(xUtil.bin(Vector3(9., 0., 0.)), 3u);
0089 }
0090 
0091 // OPEN - local to global transform test
0092 BOOST_AUTO_TEST_CASE(BinUtility_transform) {
0093   Transform3 transform_LtoG = Transform3::Identity();
0094   transform_LtoG = transform_LtoG * Translation3(0., 0., -50);
0095   transform_LtoG =
0096       transform_LtoG * AngleAxis3(std::numbers::pi / 4., Vector3(0, 0, 1));
0097 
0098   Transform3 transform_GtoL = transform_LtoG.inverse();
0099 
0100   BinUtility rUtil(10, 0., 100., open, AxisDirection::AxisR);
0101   BinUtility phiUtil(10, -std::numbers::pi, std::numbers::pi, closed,
0102                      AxisDirection::AxisPhi);
0103   BinUtility zUtil(10, -100., 100., open, AxisDirection::AxisZ);
0104 
0105   BinUtility noTranform;
0106   noTranform += rUtil;
0107   noTranform += phiUtil;
0108   noTranform += zUtil;
0109 
0110   BinUtility withTranform(transform_LtoG);
0111   withTranform += rUtil;
0112   withTranform += phiUtil;
0113   withTranform += zUtil;
0114 
0115   Vector3 pos1(0, 0, 0);
0116   Vector3 pos2(60, 0, 0);
0117   Vector3 pos3(34, std::numbers::pi / 2., 0);
0118   Vector3 pos4(0, 0, -80);
0119   Vector3 pos5(80, -std::numbers::pi / 4., 50);
0120 
0121   for (int i = 0; i < 3; i++) {
0122     BOOST_CHECK_EQUAL(withTranform.bin(pos1, i),
0123                       noTranform.bin(transform_GtoL * pos1, i));
0124     BOOST_CHECK_EQUAL(withTranform.bin(pos2, i),
0125                       noTranform.bin(transform_GtoL * pos2, i));
0126     BOOST_CHECK_EQUAL(withTranform.bin(pos3, i),
0127                       noTranform.bin(transform_GtoL * pos3, i));
0128     BOOST_CHECK_EQUAL(withTranform.bin(pos4, i),
0129                       noTranform.bin(transform_GtoL * pos4, i));
0130     BOOST_CHECK_EQUAL(withTranform.bin(pos5, i),
0131                       noTranform.bin(transform_GtoL * pos5, i));
0132   }
0133 }
0134 
0135 BOOST_AUTO_TEST_CASE(BinUtility_from_ProtoAxis) {
0136   using enum AxisDirection;
0137   using enum AxisBoundaryType;
0138 
0139   DirectedProtoAxis epabX(AxisX, Bound, 0.0, 1.0, 10);
0140   BinUtility buX(epabX);
0141   BOOST_CHECK_EQUAL(buX.bins(), std::size_t{10});
0142   BOOST_CHECK_EQUAL(buX.dimensions(), std::size_t{1});
0143 
0144   DirectedProtoAxis epabY(AxisY, Bound, 0.0, 1.0, 10);
0145   BinUtility buXY({epabX, epabY});
0146   BOOST_CHECK_EQUAL(buXY.bins(), std::size_t{100});
0147   BOOST_CHECK_EQUAL(buXY.dimensions(), std::size_t{2});
0148 }
0149 
0150 }  // namespace Acts::Test