File indexing completed on 2026-05-27 07:23:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/definitions/detail/qualifiers.hpp"
0014 #include "detray/material/material.hpp"
0015 #include "detray/material/predefined_materials.hpp"
0016
0017
0018 #include <limits>
0019 #include <ostream>
0020
0021 namespace detray {
0022
0023
0024 template <concepts::scalar scalar_t>
0025 struct material_slab {
0026 using scalar_type = scalar_t;
0027 using material_type = material<scalar_t>;
0028
0029 constexpr material_slab() = default;
0030
0031
0032
0033
0034 constexpr material_slab(const material_type& material, scalar_type thickness)
0035 : m_material(material),
0036 m_thickness(thickness),
0037 m_thickness_in_X0(thickness / material.X0()),
0038 m_thickness_in_L0(thickness / material.L0()) {}
0039
0040
0041
0042
0043 DETRAY_HOST_DEVICE
0044 constexpr bool operator==(const material_slab& rhs) const {
0045 return (m_material == rhs.get_material() && m_thickness == rhs.thickness());
0046 }
0047
0048
0049 DETRAY_HOST_DEVICE
0050 constexpr explicit operator bool() const {
0051 if (m_thickness <= std::numeric_limits<scalar_type>::epsilon() ||
0052 m_thickness == std::numeric_limits<scalar_type>::max() ||
0053 m_material == vacuum<scalar_type>() ||
0054 m_material.mass_density() == 0.f || m_material.molar_density() == 0.f) {
0055 return false;
0056 }
0057 return true;
0058 }
0059
0060
0061 DETRAY_HOST_DEVICE
0062 constexpr const material_type& get_material() const { return m_material; }
0063
0064 DETRAY_HOST_DEVICE
0065 constexpr scalar_type thickness() const { return m_thickness; }
0066
0067 DETRAY_HOST_DEVICE
0068 constexpr scalar_type thickness_in_X0() const { return m_thickness_in_X0; }
0069
0070 DETRAY_HOST_DEVICE
0071 constexpr scalar_type thickness_in_L0() const { return m_thickness_in_L0; }
0072
0073
0074
0075
0076 DETRAY_HOST_DEVICE constexpr scalar_type path_segment(
0077 const scalar_type cos_inc_angle,
0078 const scalar_type = 0.f) const {
0079 return m_thickness / cos_inc_angle;
0080 }
0081
0082
0083
0084
0085 DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_X0(
0086 const scalar_type cos_inc_angle,
0087 const scalar_type = 0.f) const {
0088 return m_thickness_in_X0 / cos_inc_angle;
0089 }
0090
0091
0092
0093
0094 DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_L0(
0095 const scalar_type cos_inc_angle,
0096 const scalar_type = 0.f) const {
0097 return m_thickness_in_L0 / cos_inc_angle;
0098 }
0099
0100
0101 DETRAY_HOST
0102 friend std::ostream& operator<<(std::ostream& os, const material_slab& mat) {
0103 os << "slab: ";
0104 os << mat.get_material();
0105 os << " | thickness = " << mat.thickness() << " mm";
0106
0107 return os;
0108 }
0109
0110 private:
0111 material_type m_material = {};
0112 scalar_type m_thickness = std::numeric_limits<scalar_type>::epsilon();
0113 scalar_type m_thickness_in_X0 = std::numeric_limits<scalar_type>::epsilon();
0114 scalar_type m_thickness_in_L0 = std::numeric_limits<scalar_type>::epsilon();
0115 };
0116
0117 }