Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-07 09:20:30

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 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Material/Material.hpp"
0013 
0014 #include <iosfwd>
0015 #include <limits>
0016 #include <utility>
0017 #include <vector>
0018 
0019 // Tell the compiler to optimize the containing block assuming that
0020 // FP may trap.  This is sometimes needed with clang to avoid spurious FPEs
0021 // resulting from auto-vectorization.
0022 
0023 #if defined(__clang__) && defined(__x86_64__)
0024 #pragma float_control(push)
0025 #pragma float_control(except, on)
0026 #endif
0027 
0028 namespace Acts {
0029 
0030 /// Material description for an object with defined thickness.
0031 ///
0032 /// This is intended to describe concrete surface materials.
0033 ///
0034 /// @see Material for a description of the available parameters.
0035 class MaterialSlab {
0036  public:
0037   /// Create a material slab with no material content
0038   /// @return Empty material slab with zero thickness and no material
0039   static constexpr MaterialSlab Nothing() {
0040     return MaterialSlab(Material::Vacuum(), 0, false);
0041   }
0042 
0043   /// Create a vacuum material slab with specified thickness
0044   /// @param thickness The thickness of the vacuum region
0045   /// @return Vacuum material slab with the given thickness
0046   static constexpr MaterialSlab Vacuum(float thickness) {
0047     return MaterialSlab(Material::Vacuum(), thickness, false);
0048   }
0049 
0050   /// Combine material properties of two layers by averaging them.
0051   ///
0052   /// @param layerA Input layer A to average over.
0053   /// @param layerB Input layer B to average over.
0054   ///
0055   /// @return The resulting object has the combined thickness of all layers but just
0056   ///         one set of appropriately averaged material constants.
0057   static MaterialSlab combineLayers(const MaterialSlab& layerA,
0058                                     const MaterialSlab& layerB);
0059 
0060   /// Compute the average properties for a combined slab of two materials.
0061   ///
0062   /// The averaged material slab has the combined thickness of the two input
0063   /// slabs and assumes the two input materials are homogeneously and
0064   /// continuously mixed throughout the slab.
0065   ///
0066   /// @param slab1 Properties of the first material slab
0067   /// @param material2 Properties of the second material
0068   /// @param thickness2 Thickness of the second material slab. Can be negative to
0069   ///                   subtract the second material from the first slab.
0070   ///
0071   /// @returns Material slab with the combined thickness and average parameters
0072   static MaterialSlab combine(const MaterialSlab& slab1,
0073                               const Material& material2, float thickness2);
0074 
0075   /// Combine material properties of multiple layers by averaging them.
0076   ///
0077   /// @param layers Input layers to average over.
0078   ///
0079   /// @return The resulting object has the combined thickness of all layers but just
0080   ///         one set of appropriately averaged material constants.
0081   static MaterialSlab combineLayers(const std::vector<MaterialSlab>& layers);
0082 
0083   /// Default constructor.
0084   ///
0085   /// TODO consider removing. currently needed for default construction in grids
0086   constexpr MaterialSlab() : m_material(Material::Vacuum()) {}
0087 
0088   /// Construct from material description.
0089   ///
0090   /// @param material  is the material description
0091   /// @param thickness is the thickness of the material
0092   MaterialSlab(const Material& material, float thickness);
0093 
0094   /// Scale the material thickness by the given factor.
0095   /// @param scale Factor by which to scale the thickness
0096   void scaleThickness(float scale);
0097 
0098   /// Check if the material is vacuum.
0099   /// @return True if the material is vacuum or thickness is zero/negative
0100   bool isVacuum() const { return m_material.isVacuum() || m_thickness <= 0; }
0101 
0102   /// Access the (average) material parameters.
0103   /// @return Reference to the material properties
0104   constexpr const Material& material() const { return m_material; }
0105   /// Return the thickness.
0106   /// @return Material thickness in millimeters
0107   constexpr float thickness() const { return m_thickness; }
0108   /// Return the radiation length fraction.
0109   /// @return Thickness as a fraction of radiation length
0110   constexpr float thicknessInX0() const { return m_thicknessInX0; }
0111   /// Return the nuclear interaction length fraction.
0112   /// @return Thickness as a fraction of nuclear interaction length
0113   constexpr float thicknessInL0() const { return m_thicknessInL0; }
0114 
0115  private:
0116   Material m_material;
0117   float m_thickness = 0.0f;
0118   float m_thicknessInX0 = 0.0f;
0119   float m_thicknessInL0 = 0.0f;
0120 
0121   static constexpr auto eps = 2 * std::numeric_limits<float>::epsilon();
0122 
0123   constexpr MaterialSlab(const Material& material, float thickness,
0124                          [[maybe_unused]] bool dummy)
0125       : m_material(material), m_thickness(thickness) {
0126     m_thicknessInX0 = (eps < material.X0()) ? (thickness / material.X0()) : 0;
0127     m_thicknessInL0 = (eps < material.L0()) ? (thickness / material.L0()) : 0;
0128   }
0129 
0130   /// @brief Check if two materials are exactly equal.
0131   ///
0132   /// This is a strict equality check, i.e. the materials must have identical
0133   /// properties.
0134   ///
0135   /// @param lhs is the left hand side material
0136   /// @param rhs is the right hand side material
0137   ///
0138   /// @return true if the materials are equal
0139   friend constexpr bool operator==(const MaterialSlab& lhs,
0140                                    const MaterialSlab& rhs) {
0141     // t/X0 and t/L0 are dependent variables and need not be checked
0142     return (lhs.m_material == rhs.m_material) &&
0143            (lhs.m_thickness == rhs.m_thickness);
0144   }
0145 };
0146 
0147 /// Stream operator for MaterialSlab
0148 /// @param os Output stream
0149 /// @param materialSlab MaterialSlab to output
0150 /// @return Reference to output stream
0151 std::ostream& operator<<(std::ostream& os, const MaterialSlab& materialSlab);
0152 
0153 /// @brief Type alias for a vector of material slabs
0154 /// @details Used to store a collection of material slabs in sequence
0155 using MaterialSlabVector = std::vector<MaterialSlab>;
0156 
0157 /// @brief Type alias for a matrix of material slabs
0158 /// @details Used to store a 2D collection of material slabs
0159 using MaterialSlabMatrix = std::vector<MaterialSlabVector>;
0160 
0161 /// list of point used in the mapping of a volume
0162 using RecordedMaterialVolumePoint =
0163     std::vector<std::pair<Acts::MaterialSlab, std::vector<Acts::Vector3>>>;
0164 
0165 }  // namespace Acts
0166 
0167 #if defined(__clang__) && defined(__x86_64__)
0168 #pragma float_control(pop)
0169 #endif