Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-22 07:48:40

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/Geometry/GeometryIdentifier.hpp"
0012 
0013 #include <format>
0014 #include <sstream>
0015 
0016 using namespace Acts;
0017 
0018 namespace ActsTests {
0019 
0020 BOOST_AUTO_TEST_CASE(GeometryIdentifier_construct_default) {
0021   GeometryIdentifier id;
0022   BOOST_CHECK_EQUAL(id.volume(), 0u);
0023   BOOST_CHECK_EQUAL(id.boundary(), 0u);
0024   BOOST_CHECK_EQUAL(id.layer(), 0u);
0025   BOOST_CHECK_EQUAL(id.approach(), 0u);
0026   BOOST_CHECK_EQUAL(id.sensitive(), 0u);
0027 }
0028 
0029 BOOST_AUTO_TEST_CASE(GeometryIdentifier_construct_encoded) {
0030   // not sure if it is a good idea to test for the encoding since it should be
0031   // an implementation detail. only the resulting functionality is relevant.
0032   GeometryIdentifier id{0xa0b00c00d00affe0u};
0033   BOOST_CHECK_EQUAL(id.volume(), 0xa0u);
0034   BOOST_CHECK_EQUAL(id.boundary(), 0xb0u);
0035   BOOST_CHECK_EQUAL(id.layer(), 0x0c0u);
0036   BOOST_CHECK_EQUAL(id.approach(), 0x0du);
0037   BOOST_CHECK_EQUAL(id.sensitive(), 0x00affu);
0038   BOOST_CHECK_EQUAL(id.extra(), 0xe0u);
0039 }
0040 
0041 BOOST_AUTO_TEST_CASE(GeometryIdentifier_max_values) {
0042   // compute maximum value for each component
0043   constexpr GeometryIdentifier::Value volumeMax = (1u << 8) - 1;
0044   constexpr GeometryIdentifier::Value boundaryMax = (1u << 8) - 1;
0045   constexpr GeometryIdentifier::Value layerMax = (1u << 12) - 1;
0046   constexpr GeometryIdentifier::Value approachMax = (1u << 8) - 1;
0047   constexpr GeometryIdentifier::Value sensitiveMax = (1u << 20) - 1;
0048   constexpr GeometryIdentifier::Value extraMax = (1u << 8) - 1;
0049   // reference values non-zero values everywhere
0050   constexpr GeometryIdentifier ref{0xdeadaffe01234567};
0051   // values above the maximum are truncated
0052   // max+1 has all available bits zeroed
0053   BOOST_CHECK_THROW(
0054       static_cast<void>(GeometryIdentifier(ref).withVolume(volumeMax + 1)),
0055       std::invalid_argument);
0056   BOOST_CHECK_THROW(
0057       static_cast<void>(GeometryIdentifier(ref).withBoundary(boundaryMax + 1)),
0058       std::invalid_argument);
0059   BOOST_CHECK_THROW(
0060       static_cast<void>(GeometryIdentifier(ref).withLayer(layerMax + 1)),
0061       std::invalid_argument);
0062   BOOST_CHECK_THROW(
0063       static_cast<void>(GeometryIdentifier(ref).withApproach(approachMax + 1)),
0064       std::invalid_argument);
0065   BOOST_CHECK_THROW(static_cast<void>(GeometryIdentifier(ref).withSensitive(
0066                         sensitiveMax + 1)),
0067                     std::invalid_argument);
0068   BOOST_CHECK_THROW(
0069       static_cast<void>(GeometryIdentifier(ref).withExtra(extraMax + 1)),
0070       std::invalid_argument);
0071 
0072   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxVolume(), 255);
0073   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxBoundary(), 255);
0074   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxLayer(), 4095);
0075   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxApproach(), 255);
0076   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxSensitive(), 1048575);
0077   BOOST_CHECK_EQUAL(GeometryIdentifier::getMaxExtra(), 255);
0078 }
0079 
0080 BOOST_AUTO_TEST_CASE(GeometryIdentifier_order) {
0081   auto vol1 = GeometryIdentifier()
0082                   .withVolume(1u)
0083                   .withLayer(14u)
0084                   .withSensitive(5u)
0085                   .withExtra(42u);
0086   auto vol2 = GeometryIdentifier()
0087                   .withVolume(2u)
0088                   .withLayer(13u)
0089                   .withSensitive(3u)
0090                   .withExtra(43u);
0091 
0092   // order uses volume first even if other components are larger
0093   BOOST_CHECK_LT(vol1, vol2);
0094   BOOST_CHECK_LT(vol1.withBoundary(64u), vol2);
0095   BOOST_CHECK_LT(vol1.withLayer(64u), vol2);
0096   BOOST_CHECK_LT(vol1.withApproach(64u), vol2);
0097   BOOST_CHECK_LT(vol1.withSensitive(64u), vol2);
0098   BOOST_CHECK_LT(vol1.withSensitive(64u), vol2);
0099   BOOST_CHECK_LT(vol2, GeometryIdentifier(vol1).withVolume(3u));
0100   // other components are hierarchical
0101   BOOST_CHECK_LT(vol1.withVolume(1u).withBoundary(2u),
0102                  vol1.withVolume(2u).withBoundary(1u));
0103   BOOST_CHECK_LT(vol1.withBoundary(1u).withLayer(2u),
0104                  vol1.withBoundary(2u).withLayer(1u));
0105   BOOST_CHECK_LT(vol1.withLayer(1u).withApproach(2u),
0106                  vol1.withLayer(2u).withApproach(1u));
0107   BOOST_CHECK_LT(vol1.withApproach(1u).withSensitive(2u),
0108                  vol1.withApproach(2u).withSensitive(1u));
0109   BOOST_CHECK_LT(vol1.withSensitive(1u).withExtra(2u),
0110                  vol1.withSensitive(2u).withExtra(1u));
0111 }
0112 
0113 BOOST_AUTO_TEST_CASE(GeometryIdentifier_format) {
0114   // Test formatting of undefined identifier
0115   {
0116     GeometryIdentifier id;
0117     std::string formatted = std::format("{}", id);
0118     BOOST_CHECK_EQUAL(formatted, "undefined");
0119   }
0120 
0121   // Test formatting with only volume
0122   {
0123     GeometryIdentifier id = GeometryIdentifier().withVolume(42);
0124     std::string formatted = std::format("{}", id);
0125     BOOST_CHECK_EQUAL(formatted, "vol=42");
0126   }
0127 
0128   // Test formatting with multiple components
0129   {
0130     GeometryIdentifier id = GeometryIdentifier()
0131                                 .withVolume(1)
0132                                 .withLayer(14)
0133                                 .withSensitive(5)
0134                                 .withExtra(42);
0135     std::string formatted = std::format("{}", id);
0136     BOOST_CHECK_EQUAL(formatted, "vol=1|lay=14|sen=5|ext=42");
0137   }
0138 
0139   // Test formatting with all components
0140   {
0141     GeometryIdentifier id = GeometryIdentifier()
0142                                 .withVolume(1)
0143                                 .withBoundary(2)
0144                                 .withLayer(3)
0145                                 .withApproach(4)
0146                                 .withSensitive(5)
0147                                 .withExtra(6);
0148     std::string formatted = std::format("{}", id);
0149     BOOST_CHECK_EQUAL(formatted, "vol=1|bnd=2|lay=3|apr=4|sen=5|ext=6");
0150   }
0151 
0152   // Test that formatted output matches stream output
0153   {
0154     GeometryIdentifier id =
0155         GeometryIdentifier().withVolume(10).withLayer(20).withSensitive(30);
0156     std::string formatted = std::format("{}", id);
0157     std::ostringstream os;
0158     os << id;
0159     BOOST_CHECK_EQUAL(formatted, os.str());
0160   }
0161 }
0162 
0163 }  // namespace ActsTests