Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-03 07:48: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/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/GeometryIdentifier.hpp"
0014 #include "Acts/Geometry/TrackingVolume.hpp"
0015 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0016 #include "Acts/Material/AccumulatedVolumeMaterial.hpp"
0017 #include "Acts/Material/MaterialGridHelper.hpp"
0018 #include "Acts/Material/MaterialInteraction.hpp"
0019 #include "Acts/Material/MaterialSlab.hpp"
0020 #include "Acts/Propagator/Navigator.hpp"
0021 #include "Acts/Propagator/Propagator.hpp"
0022 #include "Acts/Propagator/StraightLineStepper.hpp"
0023 #include "Acts/Surfaces/Surface.hpp"
0024 #include "Acts/Utilities/BinUtility.hpp"
0025 #include "Acts/Utilities/Logger.hpp"
0026 
0027 #include <functional>
0028 #include <map>
0029 #include <memory>
0030 #include <utility>
0031 
0032 namespace Acts {
0033 
0034 class ISurfaceMaterial;
0035 class IVolumeMaterial;
0036 class TrackingGeometry;
0037 
0038 //
0039 /// @brief VolumeMaterialMapper
0040 ///
0041 /// This is the main feature tool to map material information
0042 /// from a 3D geometry onto the TrackingGeometry with its surface
0043 /// material description.
0044 ///
0045 /// The process runs as such:
0046 ///
0047 ///  1) TrackingGeometry is parsed and for each Volume with
0048 ///     ProtoVolumeMaterial a local store is initialized
0049 ///     the identification is done hereby through the Volume::GeometryIdentifier
0050 ///
0051 ///  2) A number of N material tracks is read in, each track has :
0052 ///       origin, direction, material steps (< position, step length, x0, l0, a,
0053 ///       z, rho >, thichness)
0054 ///
0055 ///       for each track:
0056 ///          volume along the origin/direction path are collected.
0057 ///          the step are then associated to volume inside which they are.
0058 ///          Additional step are created along the track direction.
0059 ///
0060 ///  3) Each 'hit' bin per event is counted and averaged at the end of the run
0061 
0062 class VolumeMaterialMapper {
0063  public:
0064   /// Type alias for straight line propagator used in material mapping
0065   using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0066 
0067   /// @struct Config
0068   ///
0069   /// Nested Configuration struct for the material mapper
0070   struct Config {
0071     /// Size of the step for the step extrapolation
0072     float mappingStep = 1.;
0073   };
0074 
0075   /// @struct State
0076   ///
0077   /// Nested State struct which is used for the mapping prococess
0078   struct State {
0079     /// Constructor of the State with contexts
0080     /// @param gctx Geometry context for volume material mapping
0081     /// @param mctx Magnetic field context for volume material mapping
0082     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0083         : geoContext(gctx), magFieldContext(mctx) {}
0084 
0085     /// The recorded material per geometry ID
0086     std::map<const GeometryIdentifier, Acts::AccumulatedVolumeMaterial>
0087         homogeneousGrid;
0088 
0089     /// The recorded 2D transform associated the grid for each geometry ID
0090     std::map<const GeometryIdentifier,
0091              std::function<Acts::Vector2(Acts::Vector3)>>
0092         transform2D;
0093 
0094     /// The 2D material grid for each geometry ID
0095     std::map<const GeometryIdentifier, Grid2D> grid2D;
0096 
0097     /// The recorded 3D transform associated the material grid for each geometry
0098     /// ID
0099     std::map<const GeometryIdentifier,
0100              std::function<Acts::Vector3(Acts::Vector3)>>
0101         transform3D;
0102 
0103     /// The 3D material grid for each geometry ID
0104     std::map<const GeometryIdentifier, Grid3D> grid3D;
0105 
0106     /// The binning for each geometry ID
0107     std::map<const GeometryIdentifier, BinUtility> materialBin;
0108 
0109     /// The surface material of the input tracking geometry
0110     std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>
0111         surfaceMaterial;
0112 
0113     /// The created volume material from it
0114     std::map<GeometryIdentifier, std::unique_ptr<const IVolumeMaterial>>
0115         volumeMaterial;
0116 
0117     /// Reference to the geometry context for the mapping
0118     std::reference_wrapper<const GeometryContext> geoContext;
0119 
0120     /// Reference to the magnetic field context
0121     std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0122   };
0123 
0124   /// Delete the Default constructor
0125   VolumeMaterialMapper() = delete;
0126 
0127   /// Constructor with config object
0128   ///
0129   /// @param cfg Configuration struct
0130   /// @param propagator The straight line propagator
0131   /// @param slogger The logger
0132   [[deprecated(
0133       "Material mapping with propagation is deprecated. Use MaterialMapper "
0134       "instead.")]]
0135   VolumeMaterialMapper(const Config& cfg, StraightLinePropagator propagator,
0136                        std::unique_ptr<const Logger> slogger = getDefaultLogger(
0137                            "VolumeMaterialMapper", Logging::INFO));
0138 
0139   /// @brief helper method that creates the cache for the mapping
0140   ///
0141   /// @param[in] gctx The geometry context to use
0142   /// @param[in] mctx The magnetic field context to use
0143   /// @param[in] tGeometry The geometry which should be mapped
0144   ///
0145   /// This method takes a TrackingGeometry,
0146   /// finds all surfaces with material proxis
0147   /// and returns you a Cache object tO be used
0148   /// @return State object configured for volume material mapping
0149   State createState(const GeometryContext& gctx,
0150                     const MagneticFieldContext& mctx,
0151                     const TrackingGeometry& tGeometry) const;
0152 
0153   /// @brief Method to finalize the maps
0154   ///
0155   /// It calls the final run averaging and then transforms
0156   /// the Homogeneous material into HomogeneousVolumeMaterial and
0157   /// the 2D and 3D grid into a InterpolatedMaterialMap
0158   ///
0159   /// @param mState
0160   void finalizeMaps(State& mState) const;
0161 
0162   /// Process/map a single track
0163   ///
0164   /// @note the RecordedMaterialSlab of the track are assumed
0165   /// to be ordered from the starting position along the starting direction
0166   ///
0167   /// @param mState The current state map
0168   /// @param mTrack The material track to be mapped
0169   /// @return Result of the mapping process
0170   Result<void> mapMaterialTrack(State& mState,
0171                                 RecordedMaterialTrack& mTrack) const;
0172 
0173  private:
0174   /// selector for finding surface
0175   struct BoundSurfaceSelector {
0176     bool operator()(const Surface& sf) const {
0177       return (sf.geometryId().boundary() != 0);
0178     }
0179   };
0180 
0181   /// selector for finding
0182   struct MaterialVolumeSelector {
0183     bool operator()(const TrackingVolume& vf) const { return vf.hasMaterial(); }
0184   };
0185 
0186   /// @brief finds all surfaces with ProtoVolumeMaterial of a volume
0187   ///
0188   /// @param mState The state to be filled
0189   /// @param tVolume is current TrackingVolume
0190   void resolveMaterialVolume(State& mState,
0191                              const TrackingVolume& tVolume) const;
0192 
0193   /// @brief check and insert
0194   ///
0195   /// @param mState is the map to be filled
0196   /// @param volume is the surface to be checked for a Proxy
0197   void checkAndInsert(State& mState, const TrackingVolume& volume) const;
0198 
0199   /// @brief check and insert
0200   ///
0201   /// @param mState is the map to be filled
0202   /// @param tVolume is the surface to collect from
0203   void collectMaterialSurfaces(State& mState,
0204                                const TrackingVolume& tVolume) const;
0205 
0206   /// Create extra material point for the mapping and add them to the grid
0207   ///
0208   /// @param mState The state to be filled
0209   /// @param currentBinning a pair containing the current geometry ID and the current binning
0210   /// @param properties material properties of the original hit
0211   /// @param position position of the original hit
0212   /// @param direction direction of the track
0213   void createExtraHits(
0214       State& mState,
0215       std::pair<const GeometryIdentifier, BinUtility>& currentBinning,
0216       Acts::MaterialSlab properties, const Vector3& position,
0217       Vector3 direction) const;
0218 
0219   /// Standard logger method
0220   const Logger& logger() const { return *m_logger; }
0221 
0222   /// The configuration object
0223   Config m_cfg;
0224 
0225   /// The straight line propagator
0226   StraightLinePropagator m_propagator;
0227 
0228   /// The logging instance
0229   std::unique_ptr<const Logger> m_logger;
0230 };
0231 
0232 }  // namespace Acts