Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-23 08:22:21

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