Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:22

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2024 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 http://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/Material.hpp"
0017 #include "Acts/Material/MaterialSlab.hpp"
0018 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0019 #include "Acts/Surfaces/CylinderSurface.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0022 #include "Acts/Utilities/BinUtility.hpp"
0023 #include "Acts/Utilities/Logger.hpp"
0024 
0025 #include <tuple>
0026 #include <utility>
0027 #include <vector>
0028 
0029 namespace Acts::Test {
0030 
0031 auto tContext = GeometryContext();
0032 
0033 BOOST_AUTO_TEST_SUITE(BinnedSurfaceMaterialAccumulaterSuite)
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().setSensitive(is + 1));
0043   }
0044 
0045   // First is homogeneous
0046   MaterialSlab mp;
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().setSensitive(is + 1));
0075   }
0076 
0077   // Accepted materials are:
0078   // - homogeneous
0079   // - Prot0
0080   // - Binned (remapping)
0081 
0082   // First is homogeneous
0083   MaterialSlab mp;
0084   surfaces[0u]->assignSurfaceMaterial(
0085       std::make_shared<HomogeneousSurfaceMaterial>(mp, 1.));
0086 
0087   // Second surface is binned Phi / Z
0088   BinUtility sb1(4, -M_PI, M_PI, closed, binPhi);
0089   sb1 += BinUtility(2, -100., 100., open, binZ);
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, binZ);
0096   surfaces[2u]->assignSurfaceMaterial(
0097       std::make_shared<BinnedSurfaceMaterial>(sb2, mps));
0098 
0099   BinnedSurfaceMaterialAccumulater::Config bsmaConfig;
0100   bsmaConfig.materialSurfaces = {surfaces[0].get(), surfaces[1].get(),
0101                                  surfaces[2].get()};
0102   bsmaConfig.emptyBinCorrection = true;
0103   bsmaConfig.geoContext = tContext;
0104 
0105   BinnedSurfaceMaterialAccumulater bsma(
0106       bsmaConfig,
0107       getDefaultLogger("BinnedSurfaceMaterialAccumulater", Logging::VERBOSE));
0108 
0109   // Generate the state
0110   auto state = bsma.createState();
0111 
0112   auto cState =
0113       static_cast<const BinnedSurfaceMaterialAccumulater::State*>(state.get());
0114 
0115   BOOST_CHECK_EQUAL(cState->accumulatedMaterial.size(), 3u);
0116 
0117   // Intersections
0118   // Track 0:
0119   // - Surface 0 hit once
0120   // - Surface 1 hit twice
0121   // - Surface 2 empty hit
0122   Vector3 p(0, 0, 0);
0123   Vector3 d0 = Vector3(50, 1, 0).normalized();
0124 
0125   MaterialInteraction m00;
0126   m00.surface = surfaces[0u].get();
0127   m00.position = 20 * d0;
0128   m00.direction = d0;
0129 
0130   MaterialInteraction m01;
0131   m01.surface = surfaces[1u].get();
0132   m01.position = 30 * d0;
0133   m01.direction = d0;
0134 
0135   MaterialInteraction m02;
0136   m02.surface = surfaces[1u].get();
0137   m02.position = 30 * d0;
0138   m02.direction = d0;
0139 
0140   std::vector<MaterialInteraction> mInteractions = {m01, m01, m02};
0141   std::vector<IAssignmentFinder::SurfaceAssignment> emptyHits = {
0142       {surfaces[2u].get(), 50 * d0, d0}};
0143 
0144   bsma.accumulate(*state, mInteractions, emptyHits);
0145 
0146   // Track 1:
0147   // - Surface 0 empty hit
0148   // - Surface 1 hit once
0149   // - Surface 2 hit once
0150   Vector3 d1 = Vector3(10, 10, 0).normalized();
0151   MaterialInteraction m11;
0152   m11.surface = surfaces[1u].get();
0153   m11.position = 30 * d1;
0154   m11.direction = d1;
0155 
0156   MaterialInteraction m12;
0157   m12.surface = surfaces[2u].get();
0158   m12.position = 50 * d1;
0159   m12.direction = d1;
0160 
0161   mInteractions = {m11, m12};
0162   emptyHits = {{surfaces[0u].get(), 50 * d1, d1}};
0163   bsma.accumulate(*state, mInteractions, emptyHits);
0164 
0165   // Get the maps
0166   auto maps = bsma.finalizeMaterial(*state);
0167 
0168   BOOST_CHECK_EQUAL(maps.size(), 3u);
0169 
0170   auto m0Itr = maps.find(GeometryIdentifier().setSensitive(1));
0171   BOOST_CHECK(m0Itr != maps.end());
0172   BOOST_CHECK(m0Itr->second != nullptr);
0173 
0174   auto m1Itr = maps.find(GeometryIdentifier().setSensitive(2));
0175   BOOST_CHECK(m1Itr != maps.end());
0176   BOOST_CHECK(m1Itr->second != nullptr);
0177 
0178   auto m2Itr = maps.find(GeometryIdentifier().setSensitive(3));
0179   BOOST_CHECK(m2Itr != maps.end());
0180   BOOST_CHECK(m2Itr->second != nullptr);
0181 
0182   // Check the material
0183   // map0 should be homogeneous
0184   auto m0 = m0Itr->second;
0185   const HomogeneousSurfaceMaterial* hm0 =
0186       dynamic_cast<const HomogeneousSurfaceMaterial*>(m0.get());
0187   BOOST_CHECK(hm0 != nullptr);
0188 
0189   // map1 should be binned
0190   auto m1 = m1Itr->second;
0191   const BinnedSurfaceMaterial* bm1 =
0192       dynamic_cast<const BinnedSurfaceMaterial*>(m1.get());
0193   BOOST_CHECK(bm1 != nullptr);
0194 
0195   // map2 should be binned
0196   auto m2 = m2Itr->second;
0197   const BinnedSurfaceMaterial* bm2 =
0198       dynamic_cast<const BinnedSurfaceMaterial*>(m2.get());
0199   BOOST_CHECK(bm2 != nullptr);
0200 
0201   // Check failures
0202   auto invalidSurface =
0203       Surface::makeShared<CylinderSurface>(Transform3::Identity(), 40.0, 100.0);
0204   invalidSurface->assignGeometryId(GeometryIdentifier().setSensitive(4));
0205 
0206   // Invalid surface amongst material
0207   MaterialInteraction mXX;
0208   mXX.surface = invalidSurface.get();
0209   mXX.position = 50 * d1;
0210   mXX.direction = d1;
0211   BOOST_CHECK_THROW(bsma.accumulate(*state, {mXX}, {}), std::invalid_argument);
0212 
0213   // Invalid surface amongst empty hits
0214   BOOST_CHECK_THROW(
0215       bsma.accumulate(*state, {}, {{invalidSurface.get(), 50 * d1, d1}}),
0216       std::invalid_argument);
0217 }
0218 
0219 BOOST_AUTO_TEST_SUITE_END()
0220 
0221 }  // namespace Acts::Test