Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:24

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