Back to home page

EIC code displayed by LXR

 
 

    


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

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