Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 08:04:24

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/CylinderVolumeBounds.hpp"
0012 #include "Acts/Geometry/Portal.hpp"
0013 #include "Acts/Geometry/PortalLinkBase.hpp"
0014 #include "Acts/Geometry/TrackingGeometry.hpp"
0015 #include "Acts/Geometry/TrackingVolume.hpp"
0016 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0017 #include "Acts/Material/HomogeneousVolumeMaterial.hpp"
0018 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0019 #include "Acts/Material/TrackingGeometryMaterial.hpp"
0020 #include "Acts/Surfaces/CylinderSurface.hpp"
0021 
0022 using namespace Acts;
0023 
0024 namespace {
0025 std::shared_ptr<CylinderSurface> keyedSurface(std::uint64_t id,
0026                                               std::string key) {
0027   auto surface =
0028       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20., 100.);
0029   surface->assignGeometryId(GeometryIdentifier().withSensitive(id));
0030   surface->assignSurfaceMaterial(std::make_shared<ProtoSurfaceMaterial>(
0031       BinUtility{}, MappingType::Default, std::move(key)));
0032   return surface;
0033 }
0034 
0035 std::shared_ptr<const ISurfaceMaterial> material(double thickness) {
0036   return std::make_shared<HomogeneousSurfaceMaterial>(
0037       MaterialSlab(Material::fromMolarDensity(1., 2., 3., 4., 5.), thickness));
0038 }
0039 }  // namespace
0040 
0041 BOOST_AUTO_TEST_SUITE(TrackingGeometryMaterialTests)
0042 
0043 BOOST_AUTO_TEST_CASE(ApplyGeometryResolvesKeysAndVolumesBeforeMutation) {
0044   auto world = std::make_shared<TrackingVolume>(
0045       Transform3::Identity(),
0046       std::make_shared<CylinderVolumeBounds>(0., 100., 200.), "world");
0047   world->assignGeometryId(GeometryIdentifier().withVolume(1));
0048   auto a = keyedSurface(2, "a");
0049   auto b = keyedSurface(1, "b");
0050   auto legacy =
0051       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30., 100.);
0052   legacy->assignGeometryId(GeometryIdentifier().withSensitive(3));
0053   world->addPortal(
0054       std::make_shared<Portal>(GeometryContext::dangerouslyDefaultConstruct(),
0055                                Portal::Arguments{.alongNormal = {a, *world}}));
0056   world->addSurface(b);
0057   world->addSurface(legacy);
0058   TrackingGeometry geometry(world, nullptr, {}, getDummyLogger(), false);
0059   auto originalA = a->surfaceMaterialSharedPtr();
0060   auto originalB = b->surfaceMaterialSharedPtr();
0061   auto matA = material(1.);
0062   auto matB = material(2.);
0063   auto volumeMaterial =
0064       std::make_shared<HomogeneousVolumeMaterial>(Material::Vacuum());
0065   TrackingGeometryMaterial maps;
0066   maps.keyedSurfaces.emplace("a", KeyedSurfaceMaterial{b->geometryId(), matA});
0067   maps.keyedSurfaces.emplace("unused",
0068                              KeyedSurfaceMaterial{a->geometryId(), matB});
0069   // A matching ID must not mask a missing key.
0070   maps.surfaceMaterials.emplace(b->geometryId(), matA);
0071   maps.surfaceMaterials.emplace(legacy->geometryId(), matB);
0072   maps.volumeMaterials.emplace(world->geometryId(), volumeMaterial);
0073   BOOST_CHECK_THROW(maps.apply(geometry), std::invalid_argument);
0074   BOOST_CHECK(a->surfaceMaterialSharedPtr() == originalA);
0075   BOOST_CHECK(b->surfaceMaterialSharedPtr() == originalB);
0076   BOOST_CHECK(legacy->surfaceMaterial() == nullptr);
0077   BOOST_CHECK(world->volumeMaterial() == nullptr);
0078 
0079   maps.keyedSurfaces.emplace("b", KeyedSurfaceMaterial{a->geometryId(), matB});
0080   maps.apply(geometry);
0081   BOOST_CHECK(a->surfaceMaterialSharedPtr() == matA);
0082   BOOST_CHECK(b->surfaceMaterialSharedPtr() == matB);
0083   BOOST_CHECK(legacy->surfaceMaterialSharedPtr() == matB);
0084   BOOST_CHECK(world->volumeMaterial() == volumeMaterial.get());
0085 }
0086 
0087 BOOST_AUTO_TEST_CASE(KeyedMapsRejectGen1BeforeMutation) {
0088   auto world = std::make_shared<TrackingVolume>(
0089       Transform3::Identity(),
0090       std::make_shared<CylinderVolumeBounds>(0., 100., 200.), "world");
0091   TrackingGeometry geometry(world);
0092   BOOST_REQUIRE(geometry.geometryVersion() ==
0093                 TrackingGeometry::GeometryVersion::Gen1);
0094   TrackingGeometryMaterial maps;
0095   maps.volumeMaterials.emplace(
0096       world->geometryId(),
0097       std::make_shared<HomogeneousVolumeMaterial>(Material::Vacuum()));
0098   maps.keyedSurfaces.emplace("unused", KeyedSurfaceMaterial{{}, material(1.)});
0099   BOOST_CHECK_EXCEPTION(
0100       maps.apply(geometry), std::invalid_argument, [](const auto& error) {
0101         return std::string(error.what()).find("keyed material map to Gen1") !=
0102                std::string::npos;
0103       });
0104   BOOST_CHECK(world->volumeMaterial() == nullptr);
0105   maps.keyedSurfaces.clear();
0106   BOOST_CHECK_NO_THROW(maps.apply(geometry));
0107   BOOST_CHECK(world->volumeMaterial() != nullptr);
0108 }
0109 
0110 BOOST_AUTO_TEST_CASE(SelectedSurfacesRejectAmbiguityAndDeduplicateVisits) {
0111   auto a = keyedSurface(1, "a");
0112   auto b = keyedSurface(2, "a");
0113   auto mat = material(1.);
0114   TrackingGeometryMaterial maps;
0115   maps.keyedSurfaces.emplace("a", KeyedSurfaceMaterial{a->geometryId(), mat});
0116   auto before = a->surfaceMaterialSharedPtr();
0117   std::vector<Surface*> surfaces{a.get(), b.get()};
0118   BOOST_CHECK_THROW(maps.apply(surfaces), std::invalid_argument);
0119   BOOST_CHECK(a->surfaceMaterialSharedPtr() == before);
0120   surfaces = {a.get(), a.get()};
0121   BOOST_CHECK_NO_THROW(maps.apply(surfaces));
0122   BOOST_CHECK(a->surfaceMaterialSharedPtr() == mat);
0123 }
0124 
0125 BOOST_AUTO_TEST_SUITE_END()