Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-08 09:18:01

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/Definitions/Common.hpp"
0013 #include "Acts/Definitions/Direction.hpp"
0014 #include "Acts/Material/MaterialSlab.hpp"
0015 
0016 #include <sstream>
0017 
0018 namespace Acts {
0019 
0020 /// This enum describes the type of surface material mapping
0021 enum MappingType { PreMapping = -1, Default = 0, PostMapping = 1, Sensor = 2 };
0022 
0023 /// @class ISurfaceMaterial
0024 ///
0025 /// Virtual base class of surface based material description
0026 ///
0027 /// MaterialSlab that are associated to a surface,
0028 /// extended by certain special representations (binned, homogeneous)
0029 ///
0030 class ISurfaceMaterial {
0031  public:
0032   /// Constructor
0033   ISurfaceMaterial() = default;
0034 
0035   /// Constructor
0036   ///
0037   /// @param splitFactor is the splitting ratio between pre/post update
0038   explicit ISurfaceMaterial(double splitFactor) : m_splitFactor(splitFactor) {}
0039 
0040   /// Constructor
0041   ///
0042   /// @param splitFactor is the splitting ratio between pre/post update
0043   /// @param mappingType is the type of surface mapping associated to the surface
0044   explicit ISurfaceMaterial(double splitFactor, Acts::MappingType mappingType)
0045       : m_splitFactor(splitFactor), m_mappingType(mappingType) {}
0046 
0047   /// Destructor
0048   virtual ~ISurfaceMaterial() = default;
0049 
0050   /// Scale material
0051   ///
0052   /// @param factor is the scale factor applied
0053   /// @return Reference to this material object for chaining
0054   virtual ISurfaceMaterial& scale(double factor) = 0;
0055 
0056   /// Return method for full material description of the Surface
0057   /// - from local coordinate on the surface
0058   ///
0059   /// @param lp is the local position used for the (eventual) lookup
0060   ///
0061   /// @return const MaterialSlab
0062   virtual const MaterialSlab& materialSlab(const Vector2& lp) const = 0;
0063 
0064   /// Return method for full material description of the Surface
0065   /// - from the global coordinates
0066   ///
0067   /// @param gp is the global position used for the (eventual) lookup
0068   ///
0069   /// @return const MaterialSlab
0070   virtual const MaterialSlab& materialSlab(const Vector3& gp) const = 0;
0071 
0072   /// Update pre factor
0073   ///
0074   /// @param pDir is the positive direction through the surface
0075   /// @param mStage is the material update directive (onapproach, full, onleave)
0076   /// @return Factor for material scaling based on direction and update stage
0077   double factor(Direction pDir, MaterialUpdateStage mStage) const;
0078 
0079   /// Return the type of surface material mapping
0080   ///
0081   /// @return The mapping type indicating how material is associated with the surface
0082   MappingType mappingType() const { return m_mappingType; }
0083 
0084   /// Return method for fully scaled material description of the Surface
0085   /// - from local coordinate on the surface
0086   ///
0087   /// @param lp is the local position used for the (eventual) lookup
0088   /// @param pDir is the positive direction through the surface
0089   /// @param mStage is the material update directive (onapproach, full, onleave)
0090   ///
0091   /// @return MaterialSlab
0092   MaterialSlab materialSlab(const Vector2& lp, Direction pDir,
0093                             MaterialUpdateStage mStage) const;
0094 
0095   /// Return method for full material description of the Surface
0096   /// - from the global coordinates
0097   ///
0098   /// @param gp is the global position used for the (eventual) lookup
0099   /// @param pDir is the positive direction through the surface
0100   /// @param mStage is the material update directive (onapproach, full, onleave)
0101   ///
0102   /// @return MaterialSlab
0103   MaterialSlab materialSlab(const Vector3& gp, Direction pDir,
0104                             MaterialUpdateStage mStage) const;
0105 
0106   /// @brief output stream operator
0107   ///
0108   /// Prints information about this object to the output stream using the
0109   /// virtual ISurfaceMaterial::toStream method
0110   ///
0111   /// @return modified output stream object
0112   friend std::ostream& operator<<(std::ostream& out,
0113                                   const ISurfaceMaterial& sm) {
0114     sm.toStream(out);
0115     return out;
0116   }
0117 
0118   /// Output Method for std::ostream, to be overloaded by child classes
0119   /// @param sl Output stream to write to
0120   /// @return Reference to the output stream for chaining
0121   virtual std::ostream& toStream(std::ostream& sl) const = 0;
0122 
0123   /// @brief output into a string
0124   ///
0125   /// @return the string representation
0126   std::string toString() const {
0127     std::stringstream sstrm;
0128     toStream(sstrm);
0129     return sstrm.str();
0130   }
0131 
0132  protected:
0133   /// the split factor in favour of oppositePre
0134   double m_splitFactor{1.};
0135 
0136   /// Use the default mapping type by default
0137   MappingType m_mappingType{Acts::MappingType::Default};
0138 };
0139 
0140 inline double ISurfaceMaterial::factor(Direction pDir,
0141                                        MaterialUpdateStage mStage) const {
0142   if (mStage == Acts::MaterialUpdateStage::FullUpdate) {
0143     return 1.;
0144   } else if (mStage == Acts::MaterialUpdateStage::PreUpdate) {
0145     return pDir == Direction::Negative() ? m_splitFactor : 1 - m_splitFactor;
0146   } else /*if (mStage == Acts::MaterialUpdateStage::PostUpdate)*/ {
0147     return pDir == Direction::Positive() ? m_splitFactor : 1 - m_splitFactor;
0148   }
0149 }
0150 
0151 inline MaterialSlab ISurfaceMaterial::materialSlab(
0152     const Vector2& lp, Direction pDir, MaterialUpdateStage mStage) const {
0153   // The plain material properties associated to this bin
0154   MaterialSlab plainMatProp = materialSlab(lp);
0155   // Scale if you have material to scale
0156   if (!plainMatProp.isVacuum()) {
0157     double scaleFactor = factor(pDir, mStage);
0158     if (scaleFactor == 0.) {
0159       return MaterialSlab::Nothing();
0160     }
0161     plainMatProp.scaleThickness(scaleFactor);
0162   }
0163   return plainMatProp;
0164 }
0165 
0166 inline MaterialSlab ISurfaceMaterial::materialSlab(
0167     const Vector3& gp, Direction pDir, MaterialUpdateStage mStage) const {
0168   // The plain material properties associated to this bin
0169   MaterialSlab plainMatProp = materialSlab(gp);
0170   // Scale if you have material to scale
0171   if (!plainMatProp.isVacuum()) {
0172     double scaleFactor = factor(pDir, mStage);
0173     if (scaleFactor == 0.) {
0174       return MaterialSlab::Nothing();
0175     }
0176     plainMatProp.scaleThickness(scaleFactor);
0177   }
0178   return plainMatProp;
0179 }
0180 
0181 }  // namespace Acts