Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:16:15

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/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0013 #include "Acts/Utilities/Axis.hpp"
0014 #include "Acts/Utilities/AxisDefinitions.hpp"
0015 #include "Acts/Utilities/ProtoAxis.hpp"
0016 
0017 BOOST_AUTO_TEST_SUITE(ProtoAxis)
0018 
0019 BOOST_AUTO_TEST_CASE(EquidistantProtoAxis) {
0020   using enum Acts::AxisBoundaryType;
0021   using enum Acts::AxisDirection;
0022   using enum Acts::AxisType;
0023 
0024   // Bound, equidistant axis
0025   Acts::ProtoAxis epab(AxisX, Bound, 0.0, 1.0, 10);
0026 
0027   // Direct access
0028   BOOST_CHECK_EQUAL(epab.getAxisDirection(), AxisX);
0029   BOOST_CHECK(!epab.isAutorange());
0030 
0031   // Access via IAxis
0032   BOOST_CHECK(epab.getAxis().isEquidistant());
0033 
0034   BOOST_CHECK(!epab.getAxis().isVariable());
0035 
0036   auto edges = epab.getAxis().getBinEdges();
0037   BOOST_CHECK_EQUAL(edges.size(), 11);
0038 
0039   BOOST_CHECK_EQUAL(epab.getAxis().getType(), Equidistant);
0040 
0041   BOOST_CHECK_EQUAL(epab.getAxis().getBoundaryType(), Bound);
0042 
0043   BOOST_CHECK_EQUAL(epab.getAxis().getNBins(), 10);
0044 
0045   CHECK_CLOSE_ABS(epab.getAxis().getMin(), 0.0, 1e-15);
0046 
0047   CHECK_CLOSE_ABS(epab.getAxis().getMax(), 1.0, 1e-15);
0048 
0049   std::string rString =
0050       "ProtoAxis: 10 bins in AxisX, equidistant within [0, 1]";
0051   std::string oString = epab.toString();
0052   BOOST_CHECK_EQUAL(rString, oString);
0053 
0054   // Create a grid from a single proto axis
0055   auto grid1D = Acts::makeGrid<double>(epab);
0056   BOOST_CHECK(grid1D != nullptr);
0057   BOOST_CHECK_EQUAL(grid1D->axes().size(), 1);
0058   auto axis1D =
0059       dynamic_cast<const Acts::Axis<Acts::AxisType::Equidistant, Bound>*>(
0060           grid1D->axes().front());
0061   BOOST_CHECK(axis1D != nullptr);
0062 
0063   // Open, equidistant axis
0064   Acts::ProtoAxis epao(AxisY, Open, 0., 2.0, 10.);
0065   BOOST_CHECK_EQUAL(epao.getAxis().getBoundaryType(), Open);
0066 
0067   // Create a 2D grid from a two proto axes
0068   auto grid2D = Acts::makeGrid<double>(epab, epao);
0069   BOOST_CHECK(grid2D != nullptr);
0070   auto grid2Daxes = grid2D->axes();
0071   BOOST_CHECK_EQUAL(grid2Daxes.size(), 2);
0072   auto axis2D1 =
0073       dynamic_cast<const Acts::Axis<Acts::AxisType::Equidistant, Bound>*>(
0074           grid2Daxes[0]);
0075   BOOST_CHECK(axis2D1 != nullptr);
0076   auto axis2D2 =
0077       dynamic_cast<const Acts::Axis<Acts::AxisType::Equidistant, Open>*>(
0078           grid2Daxes[1]);
0079   BOOST_CHECK(axis2D2 != nullptr);
0080 
0081   // Invalid grid construction with two proto axis in the same direction
0082   BOOST_CHECK_THROW(Acts::makeGrid<double>(epab, epab), std::invalid_argument);
0083 
0084   // Invalid constructor, min > max
0085   BOOST_CHECK_THROW(Acts::ProtoAxis(AxisZ, Bound, 1.0, 0.0, 10),
0086                     std::invalid_argument);
0087 
0088   // Invalid constructor, nbins < 1
0089   BOOST_CHECK_THROW(Acts::ProtoAxis(AxisZ, Bound, 0.0, 1.0, 0),
0090                     std::invalid_argument);
0091 
0092   // Invalid constructor, closed with something else than phi or rphi
0093   std::vector<Acts::AxisDirection> invalidDirections = {
0094       AxisX, AxisY, AxisZ, AxisR, AxisEta, AxisTheta, AxisMag};
0095   for (const auto& adir : invalidDirections) {
0096     BOOST_CHECK_THROW(Acts::ProtoAxis(adir, Closed, 0.0, 1.0, 10),
0097                       std::invalid_argument);
0098   }
0099 }
0100 
0101 BOOST_AUTO_TEST_CASE(AutorangeProtoAxis) {
0102   using enum Acts::AxisBoundaryType;
0103   using enum Acts::AxisDirection;
0104   using enum Acts::AxisType;
0105 
0106   // Bound, equidistant axis, autorange
0107   Acts::ProtoAxis epa(AxisX, Bound, 10);
0108 
0109   // Direct access
0110   BOOST_CHECK_EQUAL(epa.getAxisDirection(), AxisX);
0111 
0112   BOOST_CHECK(epa.isAutorange());
0113 
0114   // Access via IAxis
0115   BOOST_CHECK(epa.getAxis().isEquidistant());
0116 
0117   BOOST_CHECK(!epa.getAxis().isVariable());
0118 
0119   BOOST_CHECK_EQUAL(epa.getAxis().getType(), Equidistant);
0120 
0121   BOOST_CHECK_EQUAL(epa.getAxis().getBoundaryType(), Bound);
0122 
0123   BOOST_CHECK_EQUAL(epa.getAxis().getNBins(), 10);
0124 
0125   std::string rString =
0126       "ProtoAxis: 10 bins in AxisX, equidistant within automatic range";
0127   std::string oString = epa.toString();
0128   BOOST_CHECK_EQUAL(rString, oString);
0129 
0130   // Invalid 1D grid construction with autorange axis
0131   BOOST_CHECK_THROW(Acts::makeGrid<double>(epa), std::invalid_argument);
0132 
0133   // Invalid 2D grid construction with autorange axis
0134   Acts::ProtoAxis epao(AxisY, Open, 0., 2.0, 10.);
0135   BOOST_CHECK_THROW(Acts::makeGrid<double>(epao, epa), std::invalid_argument);
0136   BOOST_CHECK_THROW(Acts::makeGrid<double>(epa, epao), std::invalid_argument);
0137 
0138   // Set the range now
0139   epa.setRange(0.0, 20.0);
0140   BOOST_CHECK(!epa.isAutorange());
0141 
0142   // 1D Grid consstruction works now
0143   BOOST_CHECK_NO_THROW(Acts::makeGrid<double>(epa));
0144 
0145   // 2D Grid consstruction works now
0146   BOOST_CHECK_NO_THROW(Acts::makeGrid<double>(epa, epao));
0147 
0148   // Invalid constructor, closed with something else than phi or rphi
0149   BOOST_CHECK_THROW(Acts::ProtoAxis(AxisZ, Closed, 10), std::invalid_argument);
0150 }
0151 
0152 BOOST_AUTO_TEST_CASE(VariableProtoAxis) {
0153   using enum Acts::AxisBoundaryType;
0154   using enum Acts::AxisDirection;
0155   using enum Acts::AxisType;
0156 
0157   // Bound, equidistant axis
0158   Acts::ProtoAxis vpab(AxisX, Bound, {0.0, 1.0, 10});
0159 
0160   // Direct access
0161   BOOST_CHECK_EQUAL(vpab.getAxisDirection(), AxisX);
0162 
0163   BOOST_CHECK(!vpab.isAutorange());
0164 
0165   // Access via IAxis
0166   BOOST_CHECK(!vpab.getAxis().isEquidistant());
0167 
0168   BOOST_CHECK(vpab.getAxis().isVariable());
0169 
0170   auto edges = vpab.getAxis().getBinEdges();
0171   BOOST_CHECK_EQUAL(edges.size(), 3);
0172 
0173   BOOST_CHECK_EQUAL(vpab.getAxis().getType(), Variable);
0174 
0175   BOOST_CHECK_EQUAL(vpab.getAxis().getBoundaryType(), Bound);
0176 
0177   BOOST_CHECK_EQUAL(vpab.getAxis().getNBins(), 2);
0178 
0179   CHECK_CLOSE_ABS(vpab.getAxis().getMin(), 0.0, 1e-15);
0180 
0181   CHECK_CLOSE_ABS(vpab.getAxis().getMax(), 10.0, 1e-15);
0182 
0183   std::string rString = "ProtoAxis: 2 bins in AxisX, variable within [0, 10]";
0184   std::string oString = vpab.toString();
0185   BOOST_CHECK_EQUAL(rString, oString);
0186 
0187   // Invalid constructor, min > max
0188   BOOST_CHECK_THROW(Acts::ProtoAxis(AxisZ, Bound, std::vector<double>{2.}),
0189                     std::invalid_argument);
0190 
0191   // Invalid constructor, nbins < 1
0192   BOOST_CHECK_THROW(Acts::ProtoAxis(AxisZ, Bound, {3., 2., 1}),
0193                     std::invalid_argument);
0194 
0195   // Invalid constructor, closed with something else than phi or rphi
0196   std::vector<Acts::AxisDirection> invalidDirections = {
0197       AxisX, AxisY, AxisZ, AxisR, AxisEta, AxisTheta, AxisMag};
0198   for (const auto& adir : invalidDirections) {
0199     BOOST_CHECK_THROW(Acts::ProtoAxis(adir, Closed, {0., 1., 2., 3.}),
0200                       std::invalid_argument);
0201   }
0202 }
0203 
0204 BOOST_AUTO_TEST_SUITE_END()