Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:51:18

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/BinnedSurfaceMaterialAccumulater.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 namespace Acts::Test {
0028 
0029 auto tContext = GeometryContext();
0030 
0031 BOOST_AUTO_TEST_SUITE(BinnedSurfaceMaterialAccumulaterSuite)
0032 
0033 BOOST_AUTO_TEST_CASE(InvalidSetupTest) {
0034   std::vector<std::shared_ptr<Surface>> surfaces = {
0035       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0036       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0037   };
0038 
0039   for (auto [is, surface] : enumerate(surfaces)) {
0040     surface->assignGeometryId(GeometryIdentifier().withSensitive(is + 1));
0041   }
0042 
0043   // First is homogeneous
0044   MaterialSlab mp = MaterialSlab::Nothing();
0045   surfaces[0u]->assignSurfaceMaterial(
0046       std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0047 
0048   // Second is empty - invalid
0049 
0050   BinnedSurfaceMaterialAccumulater::Config bsmaConfig;
0051   bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get()};
0052   bsmaConfig.emptyBinCorrection = true;
0053   bsmaConfig.geoContext = tContext;
0054 
0055   BinnedSurfaceMaterialAccumulater bsma(
0056       bsmaConfig,
0057       getDefaultLogger("BinnedSurfaceMaterialAccumulater", Logging::VERBOSE));
0058 
0059   // Generate the state - will throw and exception as the second surface is
0060   // invalid (w/o material)
0061   BOOST_CHECK_THROW(bsma.createState(), std::invalid_argument);
0062 }
0063 
0064 BOOST_AUTO_TEST_CASE(AccumulationTest) {
0065   std::vector<std::shared_ptr<Surface>> surfaces = {
0066       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 20.0, 100.0),
0067       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 30.0, 100.0),
0068       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 50.0,
0069                                            100.0)};
0070 
0071   for (auto [is, surface] : enumerate(surfaces)) {
0072     surface->assignGeometryId(GeometryIdentifier().withSensitive(is + 1));
0073   }
0074 
0075   // Accepted materials are:
0076   // - homogeneous
0077   // - Prot0
0078   // - Binned (remapping)
0079 
0080   // First is homogeneous
0081   MaterialSlab mp = MaterialSlab::Nothing();
0082   surfaces[0u]->assignSurfaceMaterial(
0083       std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0084 
0085   // Second surface is binned Phi / Z
0086   BinUtility sb1(4, -std::numbers::pi, std::numbers::pi, closed,
0087                  AxisDirection::AxisPhi);
0088   sb1 += BinUtility(2, -100., 100., open, AxisDirection::AxisZ);
0089   surfaces[1u]->assignSurfaceMaterial(
0090       std::make_shared<ProtoSurfaceMaterial>(sb1));
0091 
0092   // Third is binned
0093   std::vector<MaterialSlab> mps = {mp, mp, mp};
0094   BinUtility sb2(3, -100., 100., open, AxisDirection::AxisZ);
0095   surfaces[2u]->assignSurfaceMaterial(
0096       std::make_shared<BinnedSurfaceMaterial>(sb2, mps));
0097 
0098   BinnedSurfaceMaterialAccumulater::Config bsmaConfig;
0099   bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get(),
0100                                  surfaces[2].get()};
0101   bsmaConfig.emptyBinCorrection = true;
0102   bsmaConfig.geoContext = tContext;
0103 
0104   BinnedSurfaceMaterialAccumulater bsma(
0105       bsmaConfig,
0106       getDefaultLogger("BinnedSurfaceMaterialAccumulater", Logging::VERBOSE));
0107 
0108   // Generate the state
0109   auto state = bsma.createState();
0110 
0111   auto cState =
0112       static_cast<const BinnedSurfaceMaterialAccumulater::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, 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, mInteractions, emptyHits);
0163 
0164   // Get the maps
0165   auto maps = bsma.finalizeMaterial(*state);
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, {mXX}, {}), std::invalid_argument);
0211 
0212   // Invalid surface amongst empty hits
0213   BOOST_CHECK_THROW(
0214       bsma.accumulate(*state, {}, {{invalidSurface.get(), 50 * d1, d1}}),
0215       std::invalid_argument);
0216 }
0217 
0218 BOOST_AUTO_TEST_SUITE_END()
0219 
0220 }  // namespace Acts::Test