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/definitions/math.hpp"
0015 #include "detray/material/material.hpp"
0016 #include "detray/material/predefined_materials.hpp"
0017
0018
0019 #include <limits>
0020 #include <ostream>
0021
0022 namespace detray {
0023
0024
0025 template <concepts::scalar scalar_t>
0026 struct material_rod {
0027 using scalar_type = scalar_t;
0028 using material_type = material<scalar_t>;
0029
0030 constexpr material_rod() = default;
0031
0032 constexpr material_rod(const material_type& material, scalar_type radius)
0033 : m_material(material),
0034 m_radius(radius),
0035 m_radius_in_X0(radius / material.X0()),
0036 m_radius_in_L0(radius / material.L0()) {}
0037
0038
0039
0040
0041 DETRAY_HOST_DEVICE
0042 constexpr bool operator==(const material_rod<scalar_type>& rhs) const {
0043 return (m_material == rhs.get_material() && m_radius == rhs.radius());
0044 }
0045
0046
0047 DETRAY_HOST_DEVICE
0048 constexpr explicit operator bool() const {
0049 if (m_radius <= std::numeric_limits<scalar_type>::epsilon() ||
0050 m_material == vacuum<scalar_type>() || m_material.Z() == 0 ||
0051 m_material.mass_density() == 0) {
0052 return false;
0053 }
0054 return true;
0055 }
0056
0057
0058 DETRAY_HOST_DEVICE
0059 constexpr const material_type& get_material() const { return m_material; }
0060
0061
0062 DETRAY_HOST_DEVICE
0063 constexpr scalar_type radius() const { return m_radius; }
0064
0065
0066 DETRAY_HOST_DEVICE
0067 constexpr scalar_type thickness() const { return m_radius; }
0068
0069
0070
0071
0072
0073 DETRAY_HOST_DEVICE constexpr scalar_type path_segment(
0074 const scalar_type cos_inc_angle, const scalar_type approach) const {
0075
0076 if (math::fabs(approach) > m_radius) {
0077 return 0.f;
0078 }
0079
0080 const scalar_type sin_inc_angle_2{1.f - cos_inc_angle * cos_inc_angle};
0081
0082 return 2.f * math::sqrt((m_radius * m_radius - approach * approach) /
0083 sin_inc_angle_2);
0084 }
0085
0086
0087
0088
0089
0090 DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_X0(
0091 const scalar_type cos_inc_angle, const scalar_type approach) const {
0092 return this->path_segment(cos_inc_angle, approach) / m_material.X0();
0093 }
0094
0095
0096
0097
0098
0099 DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_L0(
0100 const scalar_type cos_inc_angle, const scalar_type approach) const {
0101 return this->path_segment(cos_inc_angle, approach) / m_material.L0();
0102 }
0103
0104
0105 DETRAY_HOST
0106 friend std::ostream& operator<<(std::ostream& os, const material_rod& mat) {
0107 os << "rod: ";
0108 os << mat.get_material();
0109 os << " | radius = " << mat.radius() << "mm";
0110
0111 return os;
0112 }
0113
0114 private:
0115 material_type m_material = {};
0116 scalar_type m_radius = std::numeric_limits<scalar_type>::epsilon();
0117 scalar_type m_radius_in_X0 = std::numeric_limits<scalar_type>::epsilon();
0118 scalar_type m_radius_in_L0 = std::numeric_limits<scalar_type>::epsilon();
0119 };
0120
0121 }