Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:26

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 "Acts/Material/MaterialSlab.hpp"
0010 
0011 #include "Acts/Material/detail/AverageMaterials.hpp"
0012 
0013 #include <limits>
0014 #include <ostream>
0015 #include <stdexcept>
0016 
0017 namespace Acts {
0018 
0019 namespace {
0020 static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
0021 }
0022 
0023 MaterialSlab::MaterialSlab(float thickness) : m_thickness(thickness) {}
0024 
0025 MaterialSlab::MaterialSlab(const Material& material, float thickness)
0026     : m_material(material),
0027       m_thickness(thickness),
0028       m_thicknessInX0((eps < material.X0()) ? (thickness / material.X0()) : 0),
0029       m_thicknessInL0((eps < material.L0()) ? (thickness / material.L0()) : 0) {
0030   if (thickness < 0) {
0031     throw std::runtime_error("thickness < 0");
0032   }
0033 }
0034 
0035 MaterialSlab MaterialSlab::averageLayers(const MaterialSlab& layerA,
0036                                          const MaterialSlab& layerB) {
0037   return detail::combineSlabs(layerA, layerB);
0038 }
0039 
0040 MaterialSlab MaterialSlab::averageLayers(
0041     const std::vector<MaterialSlab>& layers) {
0042   // NOTE 2020-08-26 msmk
0043   //   the reduce work best (in the numerical stability sense) if the input
0044   //   layers are sorted by thickness/mass density. then, the later terms
0045   //   of the averaging are only small corrections to the large average of
0046   //   the initial layers. this could be enforced by sorting the layers first,
0047   //   but I am not sure if this is actually a problem.
0048   // NOTE yes, this loop is exactly like std::reduce which apparently does not
0049   //   exist on gcc 8 although it is required by C++17.
0050   MaterialSlab result;
0051   for (const auto& layer : layers) {
0052     result = detail::combineSlabs(result, layer);
0053   }
0054   return result;
0055 }
0056 
0057 void MaterialSlab::scaleThickness(float scale) {
0058   if (scale < 0) {
0059     throw std::runtime_error("scale < 0");
0060   }
0061 
0062   m_thickness *= scale;
0063   m_thicknessInX0 *= scale;
0064   m_thicknessInL0 *= scale;
0065 }
0066 
0067 std::ostream& operator<<(std::ostream& os, const MaterialSlab& materialSlab) {
0068   os << materialSlab.material() << "|t=" << materialSlab.thickness();
0069   return os;
0070 }
0071 
0072 }  // namespace Acts