Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:59

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 #pragma once
0010 
0011 // Project include(s)
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 // System include(s)
0018 #include <limits>
0019 #include <ostream>
0020 
0021 namespace detray {
0022 
0023 // Slab structure to be mapped on the mask (plane, cylinder)
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   /// Constructor
0032   /// @param material is the elemental or mixture material
0033   /// @param thickness is the thickness of the slab
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   /// Equality operator
0041   ///
0042   /// @param rhs is the right hand side to be compared to
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   /// Boolean operator
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   /// Access the (average) material parameters.
0061   DETRAY_HOST_DEVICE
0062   constexpr const material_type& get_material() const { return m_material; }
0063   /// Return the thickness.
0064   DETRAY_HOST_DEVICE
0065   constexpr scalar_type thickness() const { return m_thickness; }
0066   /// Return the radiation length fraction.
0067   DETRAY_HOST_DEVICE
0068   constexpr scalar_type thickness_in_X0() const { return m_thickness_in_X0; }
0069   /// Return the nuclear interaction length fraction.
0070   DETRAY_HOST_DEVICE
0071   constexpr scalar_type thickness_in_L0() const { return m_thickness_in_L0; }
0072 
0073   /// @returns the path segment through the material
0074   ///
0075   /// @param cos_inc_angle cosine of the track incidence angle
0076   DETRAY_HOST_DEVICE constexpr scalar_type path_segment(
0077       const scalar_type cos_inc_angle,
0078       const scalar_type /*unused*/ = 0.f) const {
0079     return m_thickness / cos_inc_angle;
0080   }
0081 
0082   /// @returns the path segment through the material in X0
0083   ///
0084   /// @param cos_inc_angle cosine of the track incidence angle
0085   DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_X0(
0086       const scalar_type cos_inc_angle,
0087       const scalar_type /*unused*/ = 0.f) const {
0088     return m_thickness_in_X0 / cos_inc_angle;
0089   }
0090 
0091   /// @returns the path segment through the material in L0
0092   ///
0093   /// @param cos_inc_angle cosine of the track incidence angle
0094   DETRAY_HOST_DEVICE constexpr scalar_type path_segment_in_L0(
0095       const scalar_type cos_inc_angle,
0096       const scalar_type /*unused*/ = 0.f) const {
0097     return m_thickness_in_L0 / cos_inc_angle;
0098   }
0099 
0100   /// @returns a string stream that prints the material details
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 }  // namespace detray