Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-18 08:20:35

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 {
0043     return (sf.surfaceMaterial() != nullptr);
0044   }
0045 };
0046 
0047 /// @brief selector for finding volume
0048 struct MaterialVolume {
0049   /// Selection function for volumes with material
0050   /// @param vf The tracking volume to check
0051   /// @return True if volume has material, false otherwise
0052   bool operator()(const TrackingVolume& vf) const {
0053     return (vf.volumeMaterial() != nullptr);
0054   }
0055 };
0056 
0057 /// @brief SurfaceMaterialMapper
0058 ///
0059 /// This is the main feature tool to map material information
0060 /// from a 3D geometry onto the TrackingGeometry with its surface
0061 /// material description.
0062 ///
0063 /// The process runs as such:
0064 ///
0065 ///  1) TrackingGeometry is parsed and for each Surface with
0066 ///     ProtoSurfaceMaterial a local store is initialized
0067 ///     the identification is done hereby through the
0068 ///     Surface::GeometryIdentifier
0069 ///
0070 ///  2) A Cache is generated that is used to keep the filling thread local,
0071 ///     the filling is protected with std::mutex
0072 ///
0073 ///  3) A number of N material tracks is read in, each track has :
0074 ///       origin, direction, material steps < position, step length, x0, l0, a,
0075 ///       z, rho >
0076 ///
0077 ///       for each track:
0078 ///          surfaces along the origin/direction path are collected
0079 ///          the closest material steps are assigned
0080 ///
0081 ///  4) Each 'hit' bin per event is counted and averaged at the end of the run
0082 ///
0083 class SurfaceMaterialMapper {
0084  public:
0085   /// Type alias for straight line propagator used in material mapping
0086   using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0087 
0088   /// @struct Config
0089   ///
0090   /// Nested Configuration struct for the material mapper
0091   struct Config {
0092     /// Mapping range
0093     std::array<double, 2> etaRange = {{-6., 6.}};
0094     /// Correct for empty bins (recommended)
0095     bool emptyBinCorrection = true;
0096     /// Mapping output to debug stream
0097     bool mapperDebugOutput = false;
0098     /// Compute the variance of each material slab (only if using an input map)
0099     bool computeVariance = false;
0100   };
0101 
0102   /// @struct State
0103   ///
0104   /// Nested State struct which is used for the mapping prococess
0105   struct State {
0106     /// @param [in] gctx The geometry context to use
0107     /// @param [in] mctx The magnetic field context to use
0108     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0109         : geoContext(gctx), magFieldContext(mctx) {}
0110 
0111     /// The accumulated material per geometry ID
0112     std::map<GeometryIdentifier, AccumulatedSurfaceMaterial>
0113         accumulatedMaterial;
0114 
0115     /// The created surface material from it
0116     std::map<GeometryIdentifier, std::unique_ptr<const ISurfaceMaterial>>
0117         surfaceMaterial;
0118 
0119     /// The surface material of the input tracking geometry
0120     std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>
0121         inputSurfaceMaterial;
0122 
0123     /// The volume material of the input tracking geometry
0124     std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>
0125         volumeMaterial;
0126 
0127     /// Reference to the geometry context for the mapping
0128     std::reference_wrapper<const GeometryContext> geoContext;
0129 
0130     /// Reference to the magnetic field context
0131     std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0132   };
0133 
0134   /// Delete the Default constructor
0135   SurfaceMaterialMapper() = delete;
0136 
0137   /// Constructor with config object
0138   ///
0139   /// @param cfg Configuration struct
0140   /// @param propagator The straight line propagator
0141   /// @param slogger The logger
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   /// @param mState The current state map
0173   /// @param mTrack The material track to be mapped
0174   ///
0175   /// @note the RecordedMaterialSlab of the track are assumed
0176   /// to be ordered from the starting position along the starting direction
0177   void mapMaterialTrack(State& mState, RecordedMaterialTrack& mTrack) const;
0178 
0179   /// Loop through all the material interactions and add them to the
0180   /// associated surface
0181   ///
0182   /// @param mState The current state map
0183   /// @param mTrack The material track to be mapped
0184   ///
0185   void mapInteraction(State& mState, RecordedMaterialTrack& mTrack) const;
0186 
0187   /// Loop through all the material interactions and add them to the
0188   /// associated surface
0189   ///
0190   /// @param mState The current state map
0191   /// @param rMaterial Vector of all the material interactions that will be mapped
0192   ///
0193   /// @note The material interactions are assumed to have an associated surface ID
0194   void mapSurfaceInteraction(State& mState,
0195                              std::vector<MaterialInteraction>& rMaterial) const;
0196 
0197  private:
0198   /// @brief finds all surfaces with ProtoSurfaceMaterial of a volume
0199   ///
0200   /// @param mState The state to be filled
0201   /// @param tVolume is current TrackingVolume
0202   void resolveMaterialSurfaces(State& mState,
0203                                const TrackingVolume& tVolume) const;
0204 
0205   /// @brief check and insert
0206   ///
0207   /// @param mState is the map to be filled
0208   /// @param surface is the surface to be checked for a Proxy
0209   void checkAndInsert(State& mState, const Surface& surface) const;
0210 
0211   /// @brief check and insert
0212   ///
0213   /// @param mState is the map to be filled
0214   /// @param tVolume is the volume collect from
0215   void collectMaterialVolumes(State& mState,
0216                               const TrackingVolume& tVolume) const;
0217 
0218   /// Standard logger method
0219   const Logger& logger() const { return *m_logger; }
0220 
0221   /// The configuration object
0222   Config m_cfg;
0223 
0224   /// The straight line propagator
0225   StraightLinePropagator m_propagator;
0226 
0227   /// The logging instance
0228   std::unique_ptr<const Logger> m_logger;
0229 };
0230 
0231 }  // namespace Acts