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) 2018-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/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/GeometryIdentifier.hpp"
0016 #include "Acts/Geometry/TrackingVolume.hpp"
0017 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0018 #include "Acts/Material/AccumulatedSurfaceMaterial.hpp"
0019 #include "Acts/Material/ISurfaceMaterial.hpp"
0020 #include "Acts/Material/MaterialInteraction.hpp"
0021 #include "Acts/Propagator/MaterialInteractor.hpp"
0022 #include "Acts/Propagator/Navigator.hpp"
0023 #include "Acts/Propagator/Propagator.hpp"
0024 #include "Acts/Propagator/StraightLineStepper.hpp"
0025 #include "Acts/Propagator/SurfaceCollector.hpp"
0026 #include "Acts/Propagator/VolumeCollector.hpp"
0027 #include "Acts/Surfaces/Surface.hpp"
0028 #include "Acts/Utilities/Logger.hpp"
0029 
0030 #include <array>
0031 #include <functional>
0032 #include <map>
0033 #include <memory>
0034 #include <vector>
0035 
0036 namespace Acts {
0037 
0038 class IVolumeMaterial;
0039 class ISurfaceMaterial;
0040 class TrackingGeometry;
0041 struct MaterialInteraction;
0042 
0043 /// @brief selector for finding surface
0044 struct MaterialSurface {
0045   bool operator()(const Surface& sf) const {
0046     return (sf.surfaceMaterial() != nullptr);
0047   }
0048 };
0049 
0050 /// @brief selector for finding volume
0051 struct MaterialVolume {
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   using StraightLinePropagator = Propagator<StraightLineStepper, Navigator>;
0086 
0087   /// @struct Config
0088   ///
0089   /// Nested Configuration struct for the material mapper
0090   struct Config {
0091     /// Mapping range
0092     std::array<double, 2> etaRange = {{-6., 6.}};
0093     /// Correct for empty bins (recommended)
0094     bool emptyBinCorrection = true;
0095     /// Mapping output to debug stream
0096     bool mapperDebugOutput = false;
0097     /// Compute the variance of each material slab (only if using an input map)
0098     bool computeVariance = false;
0099   };
0100 
0101   /// @struct State
0102   ///
0103   /// Nested State struct which is used for the mapping prococess
0104   struct State {
0105     /// @param [in] gctx The geometry context to use
0106     /// @param [in] mctx The magnetic field context to use
0107     State(const GeometryContext& gctx, const MagneticFieldContext& mctx)
0108         : geoContext(gctx), magFieldContext(mctx) {}
0109 
0110     /// The accumulated material per geometry ID
0111     std::map<GeometryIdentifier, AccumulatedSurfaceMaterial>
0112         accumulatedMaterial;
0113 
0114     /// The created surface material from it
0115     std::map<GeometryIdentifier, std::unique_ptr<const ISurfaceMaterial>>
0116         surfaceMaterial;
0117 
0118     /// The surface material of the input tracking geometry
0119     std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>
0120         inputSurfaceMaterial;
0121 
0122     /// The volume material of the input tracking geometry
0123     std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>
0124         volumeMaterial;
0125 
0126     /// Reference to the geometry context for the mapping
0127     std::reference_wrapper<const GeometryContext> geoContext;
0128 
0129     /// Reference to the magnetic field context
0130     std::reference_wrapper<const MagneticFieldContext> magFieldContext;
0131   };
0132 
0133   /// Delete the Default constructor
0134   SurfaceMaterialMapper() = delete;
0135 
0136   /// Constructor with config object
0137   ///
0138   /// @param cfg Configuration struct
0139   /// @param propagator The straight line propagator
0140   /// @param slogger The logger
0141   SurfaceMaterialMapper(const Config& cfg, StraightLinePropagator propagator,
0142                         std::unique_ptr<const Logger> slogger =
0143                             getDefaultLogger("SurfaceMaterialMapper",
0144                                              Logging::INFO));
0145 
0146   /// @brief helper method that creates the cache for the mapping
0147   ///
0148   /// @param [in] gctx The geometry context to use
0149   /// @param [in] mctx The magnetic field context to use
0150   /// @param[in] tGeometry The geometry which should be mapped
0151   ///
0152   /// This method takes a TrackingGeometry,
0153   /// finds all surfaces with material proxis
0154   /// and returns you a Cache object tO be used
0155   State createState(const GeometryContext& gctx,
0156                     const MagneticFieldContext& mctx,
0157                     const TrackingGeometry& tGeometry) const;
0158 
0159   /// @brief Method to finalize the maps
0160   ///
0161   /// It calls the final run averaging and then transforms
0162   /// the AccumulatedSurface material class to a surface material
0163   /// class type
0164   ///
0165   /// @param mState
0166   void finalizeMaps(State& mState) const;
0167 
0168   /// Process/map a single track
0169   ///
0170   /// @param mState The current state map
0171   /// @param mTrack The material track to be mapped
0172   ///
0173   /// @note the RecordedMaterialSlab of the track are assumed
0174   /// to be ordered from the starting position along the starting direction
0175   void mapMaterialTrack(State& mState, RecordedMaterialTrack& mTrack) const;
0176 
0177   /// Loop through all the material interactions and add them to the
0178   /// associated surface
0179   ///
0180   /// @param mState The current state map
0181   /// @param mTrack The material track to be mapped
0182   ///
0183   void mapInteraction(State& mState, RecordedMaterialTrack& mTrack) const;
0184 
0185   /// Loop through all the material interactions and add them to the
0186   /// associated surface
0187   ///
0188   /// @param mState The current state map
0189   /// @param rMaterial Vector of all the material interactions that will be mapped
0190   ///
0191   /// @note The material interactions are assumed to have an associated surface ID
0192   void mapSurfaceInteraction(State& mState,
0193                              std::vector<MaterialInteraction>& rMaterial) const;
0194 
0195  private:
0196   /// @brief finds all surfaces with ProtoSurfaceMaterial of a volume
0197   ///
0198   /// @param mState The state to be filled
0199   /// @param tVolume is current TrackingVolume
0200   void resolveMaterialSurfaces(State& mState,
0201                                const TrackingVolume& tVolume) const;
0202 
0203   /// @brief check and insert
0204   ///
0205   /// @param mState is the map to be filled
0206   /// @param surface is the surface to be checked for a Proxy
0207   void checkAndInsert(State& mState, const Surface& surface) const;
0208 
0209   /// @brief check and insert
0210   ///
0211   /// @param mState is the map to be filled
0212   /// @param tVolume is the volume collect from
0213   void collectMaterialVolumes(State& mState,
0214                               const TrackingVolume& tVolume) const;
0215 
0216   /// Standard logger method
0217   const Logger& logger() const { return *m_logger; }
0218 
0219   /// The configuration object
0220   Config m_cfg;
0221 
0222   /// The straight line propagator
0223   StraightLinePropagator m_propagator;
0224 
0225   /// The logging instance
0226   std::unique_ptr<const Logger> m_logger;
0227 };
0228 }  // namespace Acts