File indexing completed on 2025-01-18 09:11:26
0001
0002
0003
0004
0005
0006
0007
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
0043
0044
0045
0046
0047
0048
0049
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 }