Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:01:39

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   using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0065 
0066   /// @struct Config
0067   ///
0068   /// Nested Configuration struct for the material mapper
0069   struct Config {
0070     /// Size of the step for the step extrapolation
0071     float mappingStep = 1.;
0072   };
0073 
0074   /// @struct State
0075   ///
0076   /// Nested State struct which is used for the mapping prococess
0077   struct State {
0078     /// Constructor of the State with contexts
0079     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0080         : geoContext(gctx), magFieldContext(mctx) {}
0081 
0082     /// The recorded material per geometry ID
0083     std::map<const GeometryIdentifier, Acts::AccumulatedVolumeMaterial>
0084         homogeneousGrid;
0085 
0086     /// The recorded 2D transform associated the grid for each geometry ID
0087     std::map<const GeometryIdentifier,
0088              std::function<Acts::Vector2(Acts::Vector3)>>
0089         transform2D;
0090 
0091     /// The 2D material grid for each geometry ID
0092     std::map<const GeometryIdentifier, Grid2D> grid2D;
0093 
0094     /// The recorded 3D transform associated the material grid for each geometry
0095     /// ID
0096     std::map<const GeometryIdentifier,
0097              std::function<Acts::Vector3(Acts::Vector3)>>
0098         transform3D;
0099 
0100     /// The 3D material grid for each geometry ID
0101     std::map<const GeometryIdentifier, Grid3D> grid3D;
0102 
0103     /// The binning for each geometry ID
0104     std::map<const GeometryIdentifier, BinUtility> materialBin;
0105 
0106     /// The surface material of the input tracking geometry
0107     std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>
0108         surfaceMaterial;
0109 
0110     /// The created volume material from it
0111     std::map<GeometryIdentifier, std::unique_ptr<const IVolumeMaterial>>
0112         volumeMaterial;
0113 
0114     /// Reference to the geometry context for the mapping
0115     std::reference_wrapper<const GeometryContext> geoContext;
0116 
0117     /// Reference to the magnetic field context
0118     std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0119   };
0120 
0121   /// Delete the Default constructor
0122   VolumeMaterialMapper() = delete;
0123 
0124   /// Constructor with config object
0125   ///
0126   /// @param cfg Configuration struct
0127   /// @param propagator The straight line propagator
0128   /// @param slogger The logger
0129   VolumeMaterialMapper(const Config& cfg, StraightLinePropagator propagator,
0130                        std::unique_ptr<const Logger> slogger = getDefaultLogger(
0131                            "VolumeMaterialMapper", Logging::INFO));
0132 
0133   /// @brief helper method that creates the cache for the mapping
0134   ///
0135   /// @param[in] gctx The geometry context to use
0136   /// @param[in] mctx The magnetic field context to use
0137   /// @param[in] tGeometry The geometry which should be mapped
0138   ///
0139   /// This method takes a TrackingGeometry,
0140   /// finds all surfaces with material proxis
0141   /// and returns you a Cache object tO be used
0142   State createState(const GeometryContext& gctx,
0143                     const MagneticFieldContext& mctx,
0144                     const TrackingGeometry& tGeometry) const;
0145 
0146   /// @brief Method to finalize the maps
0147   ///
0148   /// It calls the final run averaging and then transforms
0149   /// the Homogeneous material into HomogeneousVolumeMaterial and
0150   /// the 2D and 3D grid into a InterpolatedMaterialMap
0151   ///
0152   /// @param mState
0153   void finalizeMaps(State& mState) const;
0154 
0155   /// Process/map a single track
0156   ///
0157   /// @param mState The current state map
0158   /// @param mTrack The material track to be mapped
0159   ///
0160   /// @note the RecordedMaterialSlab of the track are assumed
0161   /// to be ordered from the starting position along the starting direction
0162   void mapMaterialTrack(State& mState, RecordedMaterialTrack& mTrack) const;
0163 
0164  private:
0165   /// selector for finding surface
0166   struct BoundSurfaceSelector {
0167     bool operator()(const Surface& sf) const {
0168       return (sf.geometryId().boundary() != 0);
0169     }
0170   };
0171 
0172   /// selector for finding
0173   struct MaterialVolumeSelector {
0174     bool operator()(const TrackingVolume& vf) const {
0175       return (vf.volumeMaterial() != nullptr);
0176     }
0177   };
0178 
0179   /// @brief finds all surfaces with ProtoVolumeMaterial of a volume
0180   ///
0181   /// @param mState The state to be filled
0182   /// @param tVolume is current TrackingVolume
0183   void resolveMaterialVolume(State& mState,
0184                              const TrackingVolume& tVolume) const;
0185 
0186   /// @brief check and insert
0187   ///
0188   /// @param mState is the map to be filled
0189   /// @param volume is the surface to be checked for a Proxy
0190   void checkAndInsert(State& mState, const TrackingVolume& volume) const;
0191 
0192   /// @brief check and insert
0193   ///
0194   /// @param mState is the map to be filled
0195   /// @param tVolume is the surface to collect from
0196   void collectMaterialSurfaces(State& mState,
0197                                const TrackingVolume& tVolume) const;
0198 
0199   /// Create extra material point for the mapping and add them to the grid
0200   ///
0201   /// @param mState The state to be filled
0202   /// @param currentBinning a pair containing the current geometry ID and the current binning
0203   /// @param properties material properties of the original hit
0204   /// @param position position of the original hit
0205   /// @param direction direction of the track
0206   void createExtraHits(
0207       State& mState,
0208       std::pair<const GeometryIdentifier, BinUtility>& currentBinning,
0209       Acts::MaterialSlab properties, const Vector3& position,
0210       Vector3 direction) const;
0211 
0212   /// Standard logger method
0213   const Logger& logger() const { return *m_logger; }
0214 
0215   /// The configuration object
0216   Config m_cfg;
0217 
0218   /// The straight line propagator
0219   StraightLinePropagator m_propagator;
0220 
0221   /// The logging instance
0222   std::unique_ptr<const Logger> m_logger;
0223 };
0224 
0225 }  // namespace Acts