Back to home page

sPhenix code displayed by LXR

 
 

    


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

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