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) 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/unit_test.hpp>
0010 
0011 #include "Acts/Material/AccumulatedVolumeMaterial.hpp"
0012 #include "Acts/Material/Material.hpp"
0013 #include "Acts/Material/MaterialSlab.hpp"
0014 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0015 
0016 #include <cmath>
0017 
0018 namespace Acts {
0019 namespace Test {
0020 
0021 BOOST_AUTO_TEST_SUITE(accumulated_material)
0022 
0023 BOOST_AUTO_TEST_CASE(vacuum) {
0024   AccumulatedVolumeMaterial avm;
0025 
0026   // averaging over nothing is vacuum
0027   BOOST_CHECK(!avm.average());
0028 
0029   // averaging over vacuum is still vacuum
0030   avm.accumulate(MaterialSlab(1));
0031   BOOST_CHECK(!avm.average());
0032 }
0033 
0034 BOOST_AUTO_TEST_CASE(single_material) {
0035   Material mat = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0036   MaterialSlab matprop(mat, 1);
0037   AccumulatedVolumeMaterial avm;
0038   // mean of a single material should be the same material again for a thickness
0039   // of 1
0040   avm.accumulate(matprop);
0041   {
0042     auto result = avm.average();
0043     CHECK_CLOSE_REL(result.parameters(), mat.parameters(), 1e-4);
0044     CHECK_CLOSE_REL(result.L0(), mat.L0(), 1e-4);
0045     CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
0046     CHECK_CLOSE_REL(result.Z(), mat.Z(), 1e-4);
0047     CHECK_CLOSE_REL(result.molarDensity(), mat.molarDensity(), 1e-4);
0048     CHECK_CLOSE_REL(result.massDensity(), mat.massDensity(), 1e-4);
0049   }
0050   // adding a vacuum step changes the average
0051   avm.accumulate(MaterialSlab(1));
0052   {
0053     auto result = avm.average();
0054     // less scattering in vacuum, larger radiation length
0055     CHECK_CLOSE_REL(result.X0(), 2 * mat.X0(), 1e-4);
0056     CHECK_CLOSE_REL(result.L0(), 2 * mat.L0(), 1e-4);
0057     // less material, lower density
0058     CHECK_CLOSE_REL(result.molarDensity(), 0.5 * mat.molarDensity(), 1e-4);
0059     CHECK_CLOSE_REL(result.massDensity(), 0.5 * mat.massDensity(), 1e-4);
0060     // but atom species stays the same
0061     CHECK_CLOSE_REL(result.Ar(), mat.Ar(), 1e-4);
0062     CHECK_CLOSE_REL(result.Z(), 0.5 * mat.Z(), 1e-4);
0063   }
0064 }
0065 
0066 BOOST_AUTO_TEST_CASE(two_materials) {
0067   Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0068   Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
0069 
0070   MaterialSlab matprop1(mat1, 1);
0071   MaterialSlab matprop2(mat2, 1);
0072 
0073   AccumulatedVolumeMaterial avm;
0074   avm.accumulate(matprop1);
0075   avm.accumulate(matprop2);
0076   auto result = avm.average();
0077   CHECK_CLOSE_REL(result.X0(), 2. / (1. / 1. + 1. / 6.), 1e-4);
0078   CHECK_CLOSE_REL(result.L0(), 2. / (1. / 2. + 1. / 7.), 1e-4);
0079   CHECK_CLOSE_REL(result.Ar(), (5 * 3. + 10 * 8.) / (5 + 10), 1e-4);
0080   CHECK_CLOSE_REL(result.Z(), exp((1. / 2.) * log(4.) + (1. / 2.) * log(9.)),
0081                   1e-4);
0082   CHECK_CLOSE_REL(result.molarDensity(), 0.5 * (5. + 10.), 1e-4);
0083 }
0084 
0085 BOOST_AUTO_TEST_CASE(two_materials_different_lengh) {
0086   Material mat1 = Material::fromMolarDensity(1., 2., 3., 4., 5.);
0087   Material mat2 = Material::fromMolarDensity(6., 7., 8., 9., 10.);
0088 
0089   MaterialSlab matprop1(mat1, 0.5);
0090   MaterialSlab matprop2(mat2, 2);
0091 
0092   AccumulatedVolumeMaterial avm;
0093   avm.accumulate(matprop1);
0094   avm.accumulate(matprop2);
0095   auto result = avm.average();
0096   CHECK_CLOSE_REL(result.X0(), 2.5 / (0.5 / 1. + 2. / 6.), 1e-4);
0097   CHECK_CLOSE_REL(result.L0(), 2.5 / (0.5 / 2. + 2. / 7.), 1e-4);
0098   CHECK_CLOSE_REL(result.Ar(),
0099                   (0.5 * 5 * 3. + 2 * 10 * 8.) / (0.5 * 5 + 2 * 10), 1e-4);
0100   CHECK_CLOSE_REL(
0101       result.Z(),
0102       exp((0.5 / (0.5 + 2.)) * log(4.) + (2. / (0.5 + 2.)) * log(9.)), 1e-4);
0103   CHECK_CLOSE_REL(result.molarDensity(), (0.5 * 5. + 2 * 10.) / (0.5 + 2),
0104                   1e-4);
0105 }
0106 
0107 BOOST_AUTO_TEST_SUITE_END()
0108 
0109 }  // namespace Test
0110 }  // namespace Acts