Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:54

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   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   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   virtual ISurfaceMaterial& scale(double factor) = 0;
0054 
0055   /// Return method for full material description of the Surface
0056   /// - from local coordinate on the surface
0057   ///
0058   /// @param lp is the local position used for the (eventual) lookup
0059   ///
0060   /// @return const MaterialSlab
0061   virtual const MaterialSlab& materialSlab(const Vector2& lp) const = 0;
0062 
0063   /// Return method for full material description of the Surface
0064   /// - from the global coordinates
0065   ///
0066   /// @param gp is the global position used for the (eventual) lookup
0067   ///
0068   /// @return const MaterialSlab
0069   virtual const MaterialSlab& materialSlab(const Vector3& gp) const = 0;
0070 
0071   /// Update pre factor
0072   ///
0073   /// @param pDir is the positive direction through the surface
0074   /// @param mStage is the material update directive (onapproach, full, onleave)
0075   double factor(Direction pDir, MaterialUpdateStage mStage) const;
0076 
0077   /// Return the type of surface material mapping
0078   ///
0079   MappingType mappingType() const { return m_mappingType; }
0080 
0081   /// Return method for fully scaled material description of the Surface
0082   /// - from local coordinate on the surface
0083   ///
0084   /// @param lp is the local position used for the (eventual) lookup
0085   /// @param pDir is the positive direction through the surface
0086   /// @param mStage is the material update directive (onapproach, full, onleave)
0087   ///
0088   /// @return MaterialSlab
0089   MaterialSlab materialSlab(const Vector2& lp, Direction pDir,
0090                             MaterialUpdateStage mStage) const;
0091 
0092   /// Return method for full material description of the Surface
0093   /// - from the global coordinates
0094   ///
0095   /// @param gp is the global position used for the (eventual) lookup
0096   /// @param pDir is the positive direction through the surface
0097   /// @param mStage is the material update directive (onapproach, full, onleave)
0098   ///
0099   /// @return MaterialSlab
0100   MaterialSlab materialSlab(const Vector3& gp, Direction pDir,
0101                             MaterialUpdateStage mStage) const;
0102 
0103   /// @brief output stream operator
0104   ///
0105   /// Prints information about this object to the output stream using the
0106   /// virtual ISurfaceMaterial::toStream method
0107   ///
0108   /// @return modified output stream object
0109   friend std::ostream& operator<<(std::ostream& out,
0110                                   const ISurfaceMaterial& sm) {
0111     sm.toStream(out);
0112     return out;
0113   }
0114 
0115   /// Output Method for std::ostream, to be overloaded by child classes
0116   virtual std::ostream& toStream(std::ostream& sl) const = 0;
0117 
0118   /// @brief output into a string
0119   ///
0120   /// @return the string representation
0121   std::string toString() const {
0122     std::stringstream sstrm;
0123     toStream(sstrm);
0124     return sstrm.str();
0125   }
0126 
0127  protected:
0128   /// the split factor in favour of oppositePre
0129   double m_splitFactor{1.};
0130 
0131   /// Use the default mapping type by default
0132   MappingType m_mappingType{Acts::MappingType::Default};
0133 };
0134 
0135 inline double ISurfaceMaterial::factor(Direction pDir,
0136                                        MaterialUpdateStage mStage) const {
0137   if (mStage == Acts::MaterialUpdateStage::FullUpdate) {
0138     return 1.;
0139   } else if (mStage == Acts::MaterialUpdateStage::PreUpdate) {
0140     return pDir == Direction::Negative() ? m_splitFactor : 1 - m_splitFactor;
0141   } else /*if (mStage == Acts::MaterialUpdateStage::PostUpdate)*/ {
0142     return pDir == Direction::Positive() ? m_splitFactor : 1 - m_splitFactor;
0143   }
0144 }
0145 
0146 inline MaterialSlab ISurfaceMaterial::materialSlab(
0147     const Vector2& lp, Direction pDir, MaterialUpdateStage mStage) const {
0148   // The plain material properties associated to this bin
0149   MaterialSlab plainMatProp = materialSlab(lp);
0150   // Scale if you have material to scale
0151   if (plainMatProp.isValid()) {
0152     double scaleFactor = factor(pDir, mStage);
0153     if (scaleFactor == 0.) {
0154       return MaterialSlab();
0155     }
0156     plainMatProp.scaleThickness(scaleFactor);
0157   }
0158   return plainMatProp;
0159 }
0160 
0161 inline MaterialSlab ISurfaceMaterial::materialSlab(
0162     const Vector3& gp, Direction pDir, MaterialUpdateStage mStage) const {
0163   // The plain material properties associated to this bin
0164   MaterialSlab plainMatProp = materialSlab(gp);
0165   // Scale if you have material to scale
0166   if (plainMatProp.isValid()) {
0167     double scaleFactor = factor(pDir, mStage);
0168     if (scaleFactor == 0.) {
0169       return MaterialSlab();
0170     }
0171     plainMatProp.scaleThickness(scaleFactor);
0172   }
0173   return plainMatProp;
0174 }
0175 
0176 }  // namespace Acts