Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:40

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