Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:23

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/GeometryIdentifier.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 #include "Acts/Material/IMaterialDecorator.hpp"
0015 #include "Acts/Material/ISurfaceMaterial.hpp"
0016 #include "Acts/Material/IVolumeMaterial.hpp"
0017 #include "Acts/Material/TrackingGeometryMaterial.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "ActsPlugins/Root/RootMaterialMapIo.hpp"
0021 
0022 #include <map>
0023 #include <memory>
0024 #include <mutex>
0025 #include <string>
0026 #include <utility>
0027 
0028 class TFile;
0029 
0030 namespace ActsPlugins {
0031 
0032 /// @class RootMaterialDecorator
0033 ///
0034 /// @brief Read the collection of SurfaceMaterial & VolumeMaterial
0035 class RootMaterialDecorator : public Acts::IMaterialDecorator {
0036  public:
0037   /// @class Config
0038   /// Configuration of the Reader
0039   class Config {
0040    public:
0041     /// Accessor config
0042     RootMaterialMapIo::Config accessorConfig;
0043     /// Accessor options
0044     RootMaterialMapIo::Options accessorOptions;
0045     /// The name of the output file
0046     std::string fileName = "material-maps.root";
0047   };
0048 
0049   /// Constructor
0050   ///
0051   /// @param config configuration struct for the reader
0052   /// @param level the logging level
0053   RootMaterialDecorator(const Config& config, Acts::Logging::Level level);
0054 
0055   /// Destructor
0056   ~RootMaterialDecorator() override;
0057 
0058   /// Decorate a surface
0059   ///
0060   /// @param surface the non-cost surface that is decorated
0061   void decorate(Acts::Surface& surface) const final {
0062     // Null out the material for this surface
0063     if (m_clearSurfaceMaterial) {
0064       surface.assignSurfaceMaterial(nullptr);
0065     }
0066     // Try to find the surface in the map
0067     auto sMaterial = m_surfaceMaterialMap.find(surface.geometryId());
0068     if (sMaterial != m_surfaceMaterialMap.end()) {
0069       surface.assignSurfaceMaterial(sMaterial->second);
0070     }
0071   }
0072 
0073   /// Decorate a TrackingVolume
0074   ///
0075   /// @param volume the non-cost volume that is decorated
0076   void decorate(Acts::TrackingVolume& volume) const final {
0077     // Null out the material for this volume
0078     if (m_clearSurfaceMaterial) {
0079       volume.assignVolumeMaterial(nullptr);
0080     }
0081     // Try to find the surface in the map
0082     auto vMaterial = m_volumeMaterialMap.find(volume.geometryId());
0083     if (vMaterial != m_volumeMaterialMap.end()) {
0084       volume.assignVolumeMaterial(vMaterial->second);
0085     }
0086   }
0087 
0088   /// Return the maps
0089   Acts::TrackingGeometryMaterial materialMaps() const {
0090     return {m_surfaceMaterialMap, m_volumeMaterialMap};
0091   }
0092 
0093   /// Get readonly access to the config parameters
0094   const Config& config() const { return m_cfg; }
0095 
0096  private:
0097   /// The config class
0098   Config m_cfg;
0099 
0100   std::unique_ptr<const Acts::Logger> m_logger{nullptr};
0101 
0102   /// The input file
0103   TFile* m_inputFile{nullptr};
0104 
0105   /// Surface based material
0106   Acts::SurfaceMaterialMaps m_surfaceMaterialMap;
0107 
0108   /// Volume based material
0109   Acts::VolumeMaterialMaps m_volumeMaterialMap;
0110 
0111   bool m_clearSurfaceMaterial{true};
0112 
0113   /// Private access to the logging instance
0114   const Acts::Logger& logger() const { return *m_logger; }
0115 };
0116 
0117 }  // namespace ActsPlugins