File indexing completed on 2025-01-18 09:12:33
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Detector/ProtoBinning.hpp"
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013 #include "Acts/Utilities/BinUtility.hpp"
0014
0015 #include <numbers>
0016
0017 using namespace Acts::Experimental;
0018
0019 BOOST_AUTO_TEST_SUITE(Detector)
0020
0021 BOOST_AUTO_TEST_CASE(ProtoBinningPlaceHolderEquidistant) {
0022
0023 auto peq = ProtoBinning(Acts::AxisDirection::AxisX,
0024 Acts::AxisBoundaryType::Bound, 5u);
0025 BOOST_CHECK_EQUAL(peq.bins(), 5u);
0026 }
0027
0028 BOOST_AUTO_TEST_CASE(ProtoBinningEquidistant) {
0029
0030 BOOST_CHECK_THROW(ProtoBinning(Acts::AxisDirection::AxisX,
0031 Acts::AxisBoundaryType::Bound, 15., 20., 0),
0032 std::invalid_argument);
0033
0034
0035 BOOST_CHECK_THROW(ProtoBinning(Acts::AxisDirection::AxisX,
0036 Acts::AxisBoundaryType::Bound, 150., 20., 10),
0037 std::invalid_argument);
0038
0039
0040 auto eq = ProtoBinning(Acts::AxisDirection::AxisX,
0041 Acts::AxisBoundaryType::Bound, 0., 10., 5u);
0042
0043 std::vector<double> reference = {0., 2., 4., 6., 8., 10.};
0044 BOOST_CHECK_EQUAL(eq.bins(), 5u);
0045 BOOST_CHECK_EQUAL(eq.axisDir, Acts::AxisDirection::AxisX);
0046 BOOST_CHECK(eq.axisType == Acts::AxisType::Equidistant);
0047 BOOST_CHECK(eq.boundaryType == Acts::AxisBoundaryType::Bound);
0048 BOOST_CHECK_EQUAL_COLLECTIONS(eq.edges.begin(), eq.edges.end(),
0049 reference.begin(), reference.end());
0050 }
0051
0052 BOOST_AUTO_TEST_CASE(ProtoBinningVariable) {
0053
0054 std::vector<double> iedges = {12.};
0055 BOOST_CHECK_THROW(ProtoBinning(Acts::AxisDirection::AxisX,
0056 Acts::AxisBoundaryType::Bound, iedges),
0057 std::invalid_argument);
0058
0059
0060 std::vector<double> varEdges = {0., 12., 13., 15., 20.};
0061 auto var = ProtoBinning(Acts::AxisDirection::AxisX,
0062 Acts::AxisBoundaryType::Bound, varEdges);
0063
0064 BOOST_CHECK_EQUAL(var.bins(), 4u);
0065 BOOST_CHECK_EQUAL(var.axisDir, Acts::AxisDirection::AxisX);
0066 BOOST_CHECK(var.axisType == Acts::AxisType::Variable);
0067 BOOST_CHECK(var.boundaryType == Acts::AxisBoundaryType::Bound);
0068 BOOST_CHECK_EQUAL_COLLECTIONS(var.edges.begin(), var.edges.end(),
0069 varEdges.begin(), varEdges.end());
0070 }
0071
0072 BOOST_AUTO_TEST_CASE(BinningDescriptionFromAndToBinUtility) {
0073
0074 Acts::BinUtility bUtility(5u, 0., 10., Acts::open,
0075 Acts::AxisDirection::AxisR);
0076 std::vector<float> edges = {-std::numbers::pi, 0.1, std::numbers::pi};
0077 bUtility +=
0078 Acts::BinUtility(edges, Acts::closed, Acts::AxisDirection::AxisPhi);
0079
0080 auto bDescription = BinningDescription::fromBinUtility(bUtility);
0081
0082 BOOST_CHECK_EQUAL(bDescription.binning.size(), 2u);
0083
0084
0085 BOOST_CHECK_EQUAL(bDescription.binning[0].bins(), 5u);
0086 BOOST_CHECK_EQUAL(bDescription.binning[0].axisDir,
0087 Acts::AxisDirection::AxisR);
0088 BOOST_CHECK(bDescription.binning[0].axisType == Acts::AxisType::Equidistant);
0089 BOOST_CHECK(bDescription.binning[0].boundaryType ==
0090 Acts::AxisBoundaryType::Bound);
0091 BOOST_CHECK_EQUAL(bDescription.binning[0].edges.size(), 6u);
0092
0093
0094 BOOST_CHECK_EQUAL(bDescription.binning[1].bins(), 2u);
0095 BOOST_CHECK_EQUAL(bDescription.binning[1].axisDir,
0096 Acts::AxisDirection::AxisPhi);
0097 BOOST_CHECK(bDescription.binning[1].axisType == Acts::AxisType::Variable);
0098 BOOST_CHECK(bDescription.binning[1].boundaryType ==
0099 Acts::AxisBoundaryType::Closed);
0100 BOOST_CHECK_EQUAL(bDescription.binning[1].edges.size(), 3u);
0101
0102
0103 auto binUtility = bDescription.toBinUtility();
0104 BOOST_CHECK_EQUAL(binUtility.binningData().size(), 2u);
0105 BOOST_CHECK_EQUAL(binUtility.binningData()[0].bins(), 5u);
0106 BOOST_CHECK_EQUAL(binUtility.binningData()[1].bins(), 2u);
0107 BOOST_CHECK_EQUAL(binUtility.binningData()[1].boundaries().size(), 3u);
0108 CHECK_CLOSE_ABS(binUtility.binningData()[1].boundaries()[0],
0109 -std::numbers::pi, 1e-5);
0110 CHECK_CLOSE_ABS(binUtility.binningData()[1].boundaries()[1], 0.1, 1e-4);
0111 }
0112
0113 BOOST_AUTO_TEST_SUITE_END()