Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-27 07:57:02

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