Back to home page

EIC code displayed by LXR

 
 

    


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

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