Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:28

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/Geometry/GeometryContext.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0015 #include "Acts/Material/AccumulatedSurfaceMaterial.hpp"
0016 #include "Acts/Material/ISurfaceMaterial.hpp"
0017 #include "Acts/Material/MaterialInteraction.hpp"
0018 #include "Acts/Propagator/Navigator.hpp"
0019 #include "Acts/Propagator/Propagator.hpp"
0020 #include "Acts/Propagator/StraightLineStepper.hpp"
0021 #include "Acts/Surfaces/Surface.hpp"
0022 #include "Acts/Utilities/Logger.hpp"
0023 
0024 #include <array>
0025 #include <functional>
0026 #include <map>
0027 #include <memory>
0028 #include <vector>
0029 
0030 namespace Acts {
0031 
0032 class IVolumeMaterial;
0033 class ISurfaceMaterial;
0034 class TrackingGeometry;
0035 struct MaterialInteraction;
0036 
0037 /// @brief selector for finding surface
0038 struct MaterialSurface {
0039   /// Selection function for surfaces with material
0040   /// @param sf The surface to check
0041   /// @return True if surface has material, false otherwise
0042   bool operator()(const Surface& sf) const { return sf.hasMaterial(); }
0043 };
0044 
0045 /// @brief selector for finding volume
0046 struct MaterialVolume {
0047   /// Selection function for volumes with material
0048   /// @param vf The tracking volume to check
0049   /// @return True if volume has material, false otherwise
0050   bool operator()(const TrackingVolume& vf) const { return vf.hasMaterial(); }
0051 };
0052 
0053 /// @brief SurfaceMaterialMapper
0054 ///
0055 /// This is the main feature tool to map material information
0056 /// from a 3D geometry onto the TrackingGeometry with its surface
0057 /// material description.
0058 ///
0059 /// The process runs as such:
0060 ///
0061 ///  1) TrackingGeometry is parsed and for each Surface with
0062 ///     ProtoSurfaceMaterial a local store is initialized
0063 ///     the identification is done hereby through the
0064 ///     Surface::GeometryIdentifier
0065 ///
0066 ///  2) A Cache is generated that is used to keep the filling thread local,
0067 ///     the filling is protected with std::mutex
0068 ///
0069 ///  3) A number of N material tracks is read in, each track has :
0070 ///       origin, direction, material steps < position, step length, x0, l0, a,
0071 ///       z, rho >
0072 ///
0073 ///       for each track:
0074 ///          surfaces along the origin/direction path are collected
0075 ///          the closest material steps are assigned
0076 ///
0077 ///  4) Each 'hit' bin per event is counted and averaged at the end of the run
0078 ///
0079 class SurfaceMaterialMapper {
0080  public:
0081   /// Type alias for straight line propagator used in material mapping
0082   using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0083 
0084   /// @struct Config
0085   ///
0086   /// Nested Configuration struct for the material mapper
0087   struct Config {
0088     /// Mapping range
0089     std::array<double, 2> etaRange = {{-6., 6.}};
0090     /// Correct for empty bins (recommended)
0091     bool emptyBinCorrection = true;
0092     /// Mapping output to debug stream
0093     bool mapperDebugOutput = false;
0094     /// Compute the variance of each material slab (only if using an input map)
0095     bool computeVariance = false;
0096   };
0097 
0098   /// @struct State
0099   ///
0100   /// Nested State struct which is used for the mapping prococess
0101   struct State {
0102     /// @param [in] gctx The geometry context to use
0103     /// @param [in] mctx The magnetic field context to use
0104     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0105         : geoContext(gctx), magFieldContext(mctx) {}
0106 
0107     /// The accumulated material per geometry ID
0108     std::map<GeometryIdentifier, AccumulatedSurfaceMaterial>
0109         accumulatedMaterial;
0110 
0111     /// The created surface material from it
0112     std::map<GeometryIdentifier, std::unique_ptr<const ISurfaceMaterial>>
0113         surfaceMaterial;
0114 
0115     /// The surface material of the input tracking geometry
0116     std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>
0117         inputSurfaceMaterial;
0118 
0119     /// The volume material of the input tracking geometry
0120     std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>
0121         volumeMaterial;
0122 
0123     /// Reference to the geometry context for the mapping
0124     std::reference_wrapper<const GeometryContext> geoContext;
0125 
0126     /// Reference to the magnetic field context
0127     std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0128   };
0129 
0130   /// Delete the Default constructor
0131   SurfaceMaterialMapper() = delete;
0132 
0133   // mark as deprecated
0134   /// Constructor with config object
0135   ///
0136   /// @param cfg Configuration struct
0137   /// @param propagator The straight line propagator
0138   /// @param slogger The logger
0139   [[deprecated(
0140       "Material mapping with propagation is deprecated. Use MaterialMapper "
0141       "instead.")]]
0142   SurfaceMaterialMapper(const Config& cfg, StraightLinePropagator propagator,
0143                         std::unique_ptr<const Logger> slogger =
0144                             getDefaultLogger("SurfaceMaterialMapper",
0145                                              Logging::INFO));
0146 
0147   /// @brief helper method that creates the cache for the mapping
0148   ///
0149   /// @param [in] gctx The geometry context to use
0150   /// @param [in] mctx The magnetic field context to use
0151   /// @param[in] tGeometry The geometry which should be mapped
0152   ///
0153   /// This method takes a TrackingGeometry,
0154   /// finds all surfaces with material proxis
0155   /// and returns you a Cache object tO be used
0156   /// @return State object configured for material mapping
0157   State createState(const GeometryContext& gctx,
0158                     const MagneticFieldContext& mctx,
0159                     const TrackingGeometry& tGeometry) const;
0160 
0161   /// @brief Method to finalize the maps
0162   ///
0163   /// It calls the final run averaging and then transforms
0164   /// the AccumulatedSurface material class to a surface material
0165   /// class type
0166   ///
0167   /// @param mState
0168   void finalizeMaps(State& mState) const;
0169 
0170   /// Process/map a single track
0171   ///
0172   /// @note the RecordedMaterialSlab of the track are assumed
0173   /// to be ordered from the starting position along the starting direction
0174   ///
0175   /// @param mState The current state map
0176   /// @param mTrack The material track to be mapped
0177   /// @return Result of the mapping process
0178   Result<void> mapMaterialTrack(State& mState,
0179                                 RecordedMaterialTrack& mTrack) const;
0180 
0181   /// Loop through all the material interactions and add them to the
0182   /// associated surface
0183   ///
0184   /// @param mState The current state map
0185   /// @param mTrack The material track to be mapped
0186   /// @return Result of the mapping process
0187   Result<void> mapInteraction(State& mState,
0188                               RecordedMaterialTrack& mTrack) const;
0189 
0190   /// Loop through all the material interactions and add them to the
0191   /// associated surface
0192   ///
0193   /// @note The material interactions are assumed to have an associated surface ID
0194   ///
0195   /// @param mState The current state map
0196   /// @param rMaterial Vector of all the material interactions that will be mapped
0197   void mapSurfaceInteraction(State& mState,
0198                              std::vector<MaterialInteraction>& rMaterial) const;
0199 
0200  private:
0201   /// @brief finds all surfaces with ProtoSurfaceMaterial of a volume
0202   ///
0203   /// @param mState The state to be filled
0204   /// @param tVolume is current TrackingVolume
0205   void resolveMaterialSurfaces(State& mState,
0206                                const TrackingVolume& tVolume) const;
0207 
0208   /// @brief check and insert
0209   ///
0210   /// @param mState is the map to be filled
0211   /// @param surface is the surface to be checked for a Proxy
0212   void checkAndInsert(State& mState, const Surface& surface) const;
0213 
0214   /// @brief check and insert
0215   ///
0216   /// @param mState is the map to be filled
0217   /// @param tVolume is the volume collect from
0218   void collectMaterialVolumes(State& mState,
0219                               const TrackingVolume& tVolume) const;
0220 
0221   /// Standard logger method
0222   const Logger& logger() const { return *m_logger; }
0223 
0224   /// The configuration object
0225   Config m_cfg;
0226 
0227   /// The straight line propagator
0228   StraightLinePropagator m_propagator;
0229 
0230   /// The logging instance
0231   std::unique_ptr<const Logger> m_logger;
0232 };
0233 
0234 }  // namespace Acts