Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-01 07:55:16

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/Material/InterpolatedMaterialMap.hpp"
0013 #include "Acts/Material/Material.hpp"
0014 #include "Acts/Material/MaterialMapUtils.hpp"
0015 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0016 
0017 #include <array>
0018 #include <cstddef>
0019 #include <vector>
0020 
0021 using namespace Acts;
0022 
0023 namespace ActsTests {
0024 
0025 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0026 
0027 BOOST_AUTO_TEST_CASE(materialmap_creation) {
0028   // Create grid values
0029   std::vector<double> rPos = {0., 1., 2.};
0030   std::vector<double> xPos = {0., 1., 2.};
0031   std::vector<double> yPos = {0., 1., 2.};
0032   std::vector<double> zPos = {0., 1., 2.};
0033 
0034   // Create material association in rz
0035   std::vector<Material> material_rz;
0036   for (int i = 0; i < 9; i++) {
0037     material_rz.push_back(Material::fromMolarDensity(i, i, i, i, i));
0038   }
0039 
0040   auto localToGlobalBin_rz = [](std::array<std::size_t, 2> binsRZ,
0041                                 std::array<std::size_t, 2> nBinsRZ) {
0042     return (binsRZ.at(1) * nBinsRZ.at(0) + binsRZ.at(0));
0043   };
0044   // Create material mapper in rz
0045   auto mapper_rz =
0046       materialMapperRZ(localToGlobalBin_rz, rPos, zPos, material_rz);
0047   // check number of bins, minima & maxima
0048   std::vector<std::size_t> nBins_rz = {rPos.size(), zPos.size()};
0049   std::vector<double> minima_rz = {0., 0.};
0050   std::vector<double> maxima_rz = {3., 3.};
0051   BOOST_CHECK(mapper_rz.getNBins() == nBins_rz);
0052   // Check minimum (should be first value because bin values are always
0053   // assigned to the left boundary)
0054   BOOST_CHECK(mapper_rz.getMin() == minima_rz);
0055   // Check maximum (should be last value + 1 step because bin values are
0056   // always assigned to the left boundary)
0057   BOOST_CHECK(mapper_rz.getMax() == maxima_rz);
0058 
0059   // Create map in xyz
0060   std::vector<Material> material_xyz;
0061   for (int i = 0; i < 27; i++) {
0062     material_xyz.push_back(Material::fromMolarDensity(i, i, i, i, i));
0063   }
0064 
0065   auto localToGlobalBin_xyz = [](std::array<std::size_t, 3> binsXYZ,
0066                                  std::array<std::size_t, 3> nBinsXYZ) {
0067     return (binsXYZ.at(0) * (nBinsXYZ.at(1) * nBinsXYZ.at(2)) +
0068             binsXYZ.at(1) * nBinsXYZ.at(2) + binsXYZ.at(2));
0069   };
0070 
0071   // Create material mapper in xyz
0072   auto mapper_xyz =
0073       materialMapperXYZ(localToGlobalBin_xyz, xPos, yPos, zPos, material_xyz);
0074   // Check number of bins, minima & maxima
0075   std::vector<std::size_t> nBins_xyz = {xPos.size(), yPos.size(), zPos.size()};
0076   std::vector<double> minima_xyz = {0., 0., 0.};
0077   std::vector<double> maxima_xyz = {3., 3., 3.};
0078   BOOST_CHECK(mapper_xyz.getNBins() == nBins_xyz);
0079   // Check minimum (should be first value because bin values are always
0080   // assigned to the left boundary)
0081   BOOST_CHECK(mapper_xyz.getMin() == minima_xyz);
0082   // Check maximum (should be last value + 1 step because bin values are
0083   // always assigned to the left boundary)
0084   BOOST_CHECK(mapper_xyz.getMax() == maxima_xyz);
0085 
0086   // Check if filled value is expected value in rz
0087   Vector3 pos0_rz(0., 0., 0.);
0088   Vector3 pos1_rz(1., 0., 1.);
0089   Vector3 pos2_rz(0., 2., 2.);
0090   auto value0_rz = mapper_rz.getMaterial(pos0_rz);
0091   auto value1_rz = mapper_rz.getMaterial(pos1_rz);
0092   auto value2_rz = mapper_rz.getMaterial(pos2_rz);
0093   // Calculate what the value should be at this point
0094   Material mat0_rz = material_rz.at(
0095       localToGlobalBin_rz({{0, 0}}, {{rPos.size(), zPos.size()}}));
0096   Material mat1_rz = material_rz.at(
0097       localToGlobalBin_rz({{1, 1}}, {{rPos.size(), zPos.size()}}));
0098   Material mat2_rz = material_rz.at(
0099       localToGlobalBin_rz({{2, 2}}, {{rPos.size(), zPos.size()}}));
0100 
0101   // Check the value
0102   // in rz case material is phi symmetric (check radius)
0103   CHECK_CLOSE_ABS(value0_rz.parameters(), mat0_rz.parameters(), 1e-9);
0104   CHECK_CLOSE_ABS(value1_rz.parameters(), mat1_rz.parameters(), 1e-9);
0105   CHECK_CLOSE_ABS(value2_rz.parameters(), mat2_rz.parameters(), 1e-9);
0106 
0107   // Check if filled value is expected value in xyz
0108   Vector3 pos0_xyz(0., 0., 0.);
0109   Vector3 pos1_xyz(1., 1., 1.);
0110   Vector3 pos2_xyz(2., 2., 2.);
0111   auto value0_xyz = mapper_xyz.getMaterial(pos0_xyz);
0112   auto value1_xyz = mapper_xyz.getMaterial(pos1_xyz);
0113   auto value2_xyz = mapper_xyz.getMaterial(pos2_xyz);
0114   // Calculate what the value should be at this point
0115   Material mat0_xyz = material_xyz.at(localToGlobalBin_xyz(
0116       {{0, 0, 0}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0117   Material mat1_xyz = material_xyz.at(localToGlobalBin_xyz(
0118       {{1, 1, 1}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0119   Material mat2_xyz = material_xyz.at(localToGlobalBin_xyz(
0120       {{2, 2, 2}}, {{xPos.size(), yPos.size(), zPos.size()}}));
0121 
0122   // Check the value
0123   // in xyz case material is phi symmetric (check radius)
0124   CHECK_CLOSE_ABS(value0_xyz.parameters(), mat0_xyz.parameters(), 1e-9);
0125   CHECK_CLOSE_ABS(value1_xyz.parameters(), mat1_xyz.parameters(), 1e-9);
0126   CHECK_CLOSE_ABS(value2_xyz.parameters(), mat2_xyz.parameters(), 1e-9);
0127 }
0128 
0129 BOOST_AUTO_TEST_SUITE_END()
0130 
0131 }  // namespace ActsTests