Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:42

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