Back to home page

EIC code displayed by LXR

 
 

    


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

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/Material.hpp"
0012 #include "Acts/Material/MaterialSlab.hpp"
0013 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <limits>
0016 #include <vector>
0017 
0018 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
0019 
0020 BOOST_AUTO_TEST_SUITE(material_properties)
0021 
0022 BOOST_AUTO_TEST_CASE(construct_simple) {
0023   /// construct from material and thickness
0024   Acts::MaterialSlab fromMaterial(
0025       Acts::Material::fromMolarDensity(1., 2., 3., 4., 5.), 6.);
0026 
0027   CHECK_CLOSE_REL(fromMaterial.thickness(), 6., eps);
0028   CHECK_CLOSE_REL(fromMaterial.thicknessInX0(), 6., eps);
0029   CHECK_CLOSE_REL(fromMaterial.thicknessInL0(), 3., eps);
0030 }
0031 
0032 BOOST_AUTO_TEST_CASE(construct_compound) {
0033   using Acts::Material;
0034   using Acts::MaterialSlab;
0035 
0036   MaterialSlab a(Material::fromMolarDensity(1., 2., 3., 4., 5.), 1.);
0037   MaterialSlab b(Material::fromMolarDensity(2., 4., 6., 8., 10.), 2.);
0038   MaterialSlab c(Material::fromMolarDensity(4., 8., 12., 16., 20.), 3.);
0039   std::vector<MaterialSlab> components = {a, b, c};
0040   MaterialSlab abc = MaterialSlab::averageLayers(components);
0041 
0042   // consistency checks
0043   CHECK_CLOSE_REL(abc.thickness() / abc.material().X0(), abc.thicknessInX0(),
0044                   eps);
0045   CHECK_CLOSE_REL(abc.thickness() / abc.material().L0(), abc.thicknessInL0(),
0046                   eps);
0047 
0048   // absolute and relative thicknesses are additive
0049   CHECK_CLOSE_REL(abc.thickness(),
0050                   a.thickness() + b.thickness() + c.thickness(), eps);
0051   CHECK_CLOSE_REL(abc.thicknessInX0(),
0052                   a.thicknessInX0() + b.thicknessInX0() + c.thicknessInX0(),
0053                   eps);
0054   CHECK_CLOSE_REL(abc.thicknessInL0(),
0055                   a.thicknessInL0() + b.thicknessInL0() + c.thicknessInL0(),
0056                   eps);
0057   // The density scales with the thickness
0058   CHECK_CLOSE_REL(abc.material().massDensity(),
0059                   (a.thickness() * a.material().massDensity() +
0060                    b.thickness() * b.material().massDensity() +
0061                    c.thickness() * c.material().massDensity()) /
0062                       (a.thickness() + b.thickness() + c.thickness()),
0063                   eps);
0064 }
0065 
0066 BOOST_AUTO_TEST_CASE(scale_thickness) {
0067   const auto material = Acts::Material::fromMassDensity(1., 2., 3., 4., 5.);
0068   const Acts::MaterialSlab mat(material, 0.1);
0069   const Acts::MaterialSlab halfMat(material, 0.05);
0070   Acts::MaterialSlab halfScaled = mat;
0071   halfScaled.scaleThickness(0.5);
0072 
0073   BOOST_CHECK_NE(mat, halfMat);
0074   BOOST_CHECK_EQUAL(halfMat, halfScaled);
0075   CHECK_CLOSE_REL(mat.thicknessInX0(), 2 * halfMat.thicknessInX0(), eps);
0076   CHECK_CLOSE_REL(mat.thicknessInL0(), 2 * halfMat.thicknessInL0(), eps);
0077   CHECK_CLOSE_REL(mat.thickness() * mat.material().massDensity(),
0078                   2. * halfMat.thickness() * halfMat.material().massDensity(),
0079                   eps);
0080 }
0081 
0082 BOOST_AUTO_TEST_SUITE_END()