Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-20 07:59:58

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