Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-18 07:36:47

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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Material/BinnedSurfaceMaterial.hpp"
0014 #include "Acts/Material/BinnedSurfaceMaterialAccumulator.hpp"
0015 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0016 #include "Acts/Material/MaterialSlab.hpp"
0017 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0018 #include "Acts/Surfaces/CylinderSurface.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Utilities/BinUtility.hpp"
0021 #include "Acts/Utilities/Logger.hpp"
0022 
0023 #include <numbers>
0024 #include <utility>
0025 #include <vector>
0026 
0027 using namespace Acts;
0028 
0029 namespace ActsTests {
0030 
0031 auto tContext = GeometryContext::dangerouslyDefaultConstruct();
0032 
0033 BOOST_AUTO_TEST_SUITE(MaterialSuite)
0034 
0035 BOOST_AUTO_TEST_CASE(InvalidSetupTest) {
0036   std::vector<std::shared_ptr<Surface>> surfaces = {
0037       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0038       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0039   };
0040 
0041   for (auto [is, surface] : enumerate(surfaces)) {
0042     surface->assignGeometryId(GeometryIdentifier().withSensitive(is + 1));
0043   }
0044 
0045   // First is homogeneous
0046   MaterialSlab mp = MaterialSlab::Nothing();
0047   surfaces[0u]->assignSurfaceMaterial(
0048       std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0049 
0050   // Second is empty - invalid
0051 
0052   BinnedSurfaceMaterialAccumulator::Config bsmaConfig;
0053   bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get()};
0054   bsmaConfig.emptyBinCorrection = true;
0055 
0056   BinnedSurfaceMaterialAccumulator bsma(
0057       bsmaConfig,
0058       getDefaultLogger("BinnedSurfaceMaterialAccumulator", Logging::VERBOSE));
0059 
0060   // Generate the state - this throws because the second surface has no
0061   // material assigned.
0062   BOOST_CHECK_THROW(bsma.createState(tContext), std::invalid_argument);
0063 }
0064 
0065 BOOST_AUTO_TEST_CASE(AccumulationTest) {
0066   std::vector<std::shared_ptr<Surface>> surfaces = {
0067       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0068       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0069       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 50.0,
0070                                            100.0)};
0071 
0072   for (auto [is, surface] : enumerate(surfaces)) {
0073     surface->assignGeometryId(GeometryIdentifier().withSensitive(is + 1));
0074   }
0075 
0076   // Accepted materials are:
0077   // - homogeneous
0078   // - Prot0
0079   // - Binned (remapping)
0080 
0081   // First is homogeneous
0082   MaterialSlab mp = MaterialSlab::Nothing();
0083   surfaces[0u]->assignSurfaceMaterial(
0084       std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0085 
0086   // Second surface is binned Phi / Z
0087   BinUtility sb1(4, -std::numbers::pi, std::numbers::pi, closed,
0088                  AxisDirection::AxisPhi);
0089   sb1 += BinUtility(2, -100., 100., open, AxisDirection::AxisZ);
0090   surfaces[1u]->assignSurfaceMaterial(
0091       std::make_shared<ProtoSurfaceMaterial>(sb1));
0092 
0093   // Third is binned
0094   std::vector<MaterialSlab> mps = {mp, mp, mp};
0095   BinUtility sb2(3, -100., 100., open, AxisDirection::AxisZ);
0096   surfaces[2u]->assignSurfaceMaterial(
0097       std::make_shared<BinnedSurfaceMaterial>(sb2, mps));
0098 
0099   BinnedSurfaceMaterialAccumulator::Config bsmaConfig;
0100   bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get(),
0101                                  surfaces[2].get()};
0102   bsmaConfig.emptyBinCorrection = true;
0103 
0104   BinnedSurfaceMaterialAccumulator bsma(
0105       bsmaConfig,
0106       getDefaultLogger("BinnedSurfaceMaterialAccumulator", Logging::VERBOSE));
0107 
0108   // Generate the state
0109   auto state = bsma.createState(tContext);
0110 
0111   auto cState =
0112       static_cast<const BinnedSurfaceMaterialAccumulator::State*>(state.get());
0113 
0114   BOOST_CHECK_EQUAL(cState->accumulatedMaterial.size(), 3u);
0115 
0116   // Intersections
0117   // Track 0:
0118   // - Surface 0 hit once
0119   // - Surface 1 hit twice
0120   // - Surface 2 empty hit
0121   Vector3 p(0, 0, 0);
0122   Vector3 d0 = Vector3(50, 1, 0).normalized();
0123 
0124   MaterialInteraction m00;
0125   m00.surface = surfaces[0u].get();
0126   m00.position = 20 * d0;
0127   m00.direction = d0;
0128 
0129   MaterialInteraction m01;
0130   m01.surface = surfaces[1u].get();
0131   m01.position = 30 * d0;
0132   m01.direction = d0;
0133 
0134   MaterialInteraction m02;
0135   m02.surface = surfaces[1u].get();
0136   m02.position = 30 * d0;
0137   m02.direction = d0;
0138 
0139   std::vector<MaterialInteraction> mInteractions = {m01, m01, m02};
0140   std::vector<IAssignmentFinder::SurfaceAssignment> emptyHits = {
0141       {surfaces[2u].get(), 50 * d0, d0}};
0142 
0143   bsma.accumulate(*state, tContext, mInteractions, emptyHits);
0144 
0145   // Track 1:
0146   // - Surface 0 empty hit
0147   // - Surface 1 hit once
0148   // - Surface 2 hit once
0149   Vector3 d1 = Vector3(10, 10, 0).normalized();
0150   MaterialInteraction m11;
0151   m11.surface = surfaces[1u].get();
0152   m11.position = 30 * d1;
0153   m11.direction = d1;
0154 
0155   MaterialInteraction m12;
0156   m12.surface = surfaces[2u].get();
0157   m12.position = 50 * d1;
0158   m12.direction = d1;
0159 
0160   mInteractions = {m11, m12};
0161   emptyHits = {{surfaces[0u].get(), 50 * d1, d1}};
0162   bsma.accumulate(*state, tContext, mInteractions, emptyHits);
0163 
0164   // Get the maps
0165   auto maps = bsma.finalizeMaterial(*state, tContext);
0166 
0167   BOOST_CHECK_EQUAL(maps.size(), 3u);
0168 
0169   auto m0Itr = maps.find(GeometryIdentifier().withSensitive(1));
0170   BOOST_CHECK(m0Itr != maps.end());
0171   BOOST_CHECK(m0Itr->second != nullptr);
0172 
0173   auto m1Itr = maps.find(GeometryIdentifier().withSensitive(2));
0174   BOOST_CHECK(m1Itr != maps.end());
0175   BOOST_CHECK(m1Itr->second != nullptr);
0176 
0177   auto m2Itr = maps.find(GeometryIdentifier().withSensitive(3));
0178   BOOST_CHECK(m2Itr != maps.end());
0179   BOOST_CHECK(m2Itr->second != nullptr);
0180 
0181   // Check the material
0182   // map0 should be homogeneous
0183   auto m0 = m0Itr->second;
0184   const HomogeneousSurfaceMaterial* hm0 =
0185       dynamic_cast<const HomogeneousSurfaceMaterial*>(m0.get());
0186   BOOST_CHECK(hm0 != nullptr);
0187 
0188   // map1 should be binned
0189   auto m1 = m1Itr->second;
0190   const BinnedSurfaceMaterial* bm1 =
0191       dynamic_cast<const BinnedSurfaceMaterial*>(m1.get());
0192   BOOST_CHECK(bm1 != nullptr);
0193 
0194   // map2 should be binned
0195   auto m2 = m2Itr->second;
0196   const BinnedSurfaceMaterial* bm2 =
0197       dynamic_cast<const BinnedSurfaceMaterial*>(m2.get());
0198   BOOST_CHECK(bm2 != nullptr);
0199 
0200   // Check failures
0201   auto invalidSurface =
0202       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 40.0, 100.0);
0203   invalidSurface->assignGeometryId(GeometryIdentifier().withSensitive(4));
0204 
0205   // Invalid surface amongst material
0206   MaterialInteraction mXX;
0207   mXX.surface = invalidSurface.get();
0208   mXX.position = 50 * d1;
0209   mXX.direction = d1;
0210   BOOST_CHECK_THROW(bsma.accumulate(*state, tContext, {mXX}, {}),
0211                     std::invalid_argument);
0212 
0213   // Invalid surface amongst empty hits
0214   BOOST_CHECK_THROW(bsma.accumulate(*state, tContext, {},
0215                                     {{invalidSurface.get(), 50 * d1, d1}}),
0216                     std::invalid_argument);
0217 }
0218 
0219 BOOST_AUTO_TEST_SUITE_END()
0220 
0221 }  // namespace ActsTests