Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:42

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2023 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 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Geometry/GeometryIdentifier.hpp"
0013 #include "Acts/Geometry/TrackingGeometry.hpp"
0014 #include "Acts/Material/ISurfaceMaterial.hpp"
0015 #include "Acts/Material/IVolumeMaterial.hpp"
0016 #include "Acts/Plugins/Json/ActsJson.hpp"
0017 #include "Acts/Plugins/Json/GeometryHierarchyMapJsonConverter.hpp"
0018 #include "Acts/Plugins/Json/ITrackingGeometryJsonDecorator.hpp"
0019 #include "Acts/Plugins/Json/IVolumeMaterialJsonDecorator.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021 #include <Acts/Geometry/TrackingVolume.hpp>
0022 #include <Acts/Surfaces/Surface.hpp>
0023 
0024 #include <map>
0025 #include <memory>
0026 #include <string>
0027 #include <tuple>
0028 #include <utility>
0029 #include <vector>
0030 
0031 #include <nlohmann/json.hpp>
0032 
0033 namespace Acts {
0034 class ISurfaceMaterial;
0035 class ITrackingGeometryJsonDecorator;
0036 class IVolumeMaterial;
0037 class IVolumeMaterialJsonDecorator;
0038 class Surface;
0039 class TrackingGeometry;
0040 class TrackingVolume;
0041 
0042 using SurfaceAndMaterialWithContext =
0043     std::tuple<std::shared_ptr<const Acts::Surface>,
0044                std::shared_ptr<const Acts::ISurfaceMaterial>,
0045                Acts::GeometryContext>;
0046 using TrackingVolumeAndMaterial =
0047     std::pair<const Acts::TrackingVolume*,
0048               std::shared_ptr<const Acts::IVolumeMaterial>>;
0049 
0050 /// @class MaterialMapJsonConverter
0051 ///
0052 /// @brief read the material from Json
0053 class MaterialMapJsonConverter {
0054  public:
0055   using SurfaceMaterialMap =
0056       std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
0057   using VolumeMaterialMap =
0058       std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
0059   using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>;
0060 
0061   /// @class Config
0062   /// Configuration of the Converter
0063   class Config {
0064    public:
0065     /// Default geometry context to extract surface transforms
0066     GeometryContext context = GeometryContext();
0067 
0068     /// Steering to handle sensitive data
0069     bool processSensitives = true;
0070     /// Steering to handle approach data
0071     bool processApproaches = true;
0072     /// Steering to handle representing data
0073     bool processRepresenting = true;
0074     /// Steering to handle boundary data
0075     bool processBoundaries = true;
0076     /// Steering to handle volume data
0077     bool processVolumes = true;
0078     /// Steering to handle volume data
0079     bool processDenseVolumes = false;
0080     /// Add proto material to all surfaces
0081     bool processNonMaterial = false;
0082   };
0083 
0084   /// Constructor
0085   ///
0086   /// @param config configuration struct for the reader
0087   /// @param level The log level
0088   MaterialMapJsonConverter(const Config& config, Acts::Logging::Level level);
0089 
0090   /// Destructor
0091   ~MaterialMapJsonConverter() = default;
0092 
0093   /// Convert a json material map to a DetectorMaterialMaps
0094   ///
0095   /// @param materialmaps The json material
0096   DetectorMaterialMaps jsonToMaterialMaps(const nlohmann::json& materialmaps);
0097 
0098   /// Convert a DetectorMaterialMaps to json
0099   ///
0100   /// @param maps The material map collection
0101   /// @param decorator nullptr or a decorator to add extra attributes
0102   nlohmann::json materialMapsToJson(
0103       const DetectorMaterialMaps& maps,
0104       const IVolumeMaterialJsonDecorator* decorator = nullptr);
0105 
0106   /// Convert a tracking geometry to json.
0107   /// Can be used to initialise the material mapping process.
0108   ///
0109   /// @param tGeometry is the tracking geometry
0110   /// @param decorator nullptr or a decorator to add extra attributes
0111   nlohmann::json trackingGeometryToJson(
0112       const TrackingGeometry& tGeometry,
0113       const ITrackingGeometryJsonDecorator* decorator = nullptr);
0114 
0115   /// Go through a volume to find subvolume, layers and surfaces.
0116   /// Store volumes and surfaces in two vector used to initialised the geometry
0117   /// hierarchy.
0118   ///
0119   /// @param volumeHierarchy is a vector of volume to be filled
0120   /// @param surfaceHierarchy is a vector of surfaces to be filled
0121   /// @param tVolume is a volume
0122   void convertToHierarchy(
0123       std::vector<std::pair<GeometryIdentifier,
0124                             Acts::TrackingVolumeAndMaterial>>& volumeHierarchy,
0125       std::vector<
0126           std::pair<GeometryIdentifier, Acts::SurfaceAndMaterialWithContext>>&
0127           surfaceHierarchy,
0128       const Acts::TrackingVolume* tVolume);
0129 
0130  private:
0131   /// The config class
0132   Config m_cfg;
0133 
0134   /// The logger instance
0135   std::unique_ptr<const Logger> m_logger{nullptr};
0136 
0137   /// Name of the volume hierarchy
0138   std::string m_volumeName = "Material Volume Map";
0139   /// Geometry hierarchy writer for volume material.
0140   Acts::GeometryHierarchyMapJsonConverter<const IVolumeMaterial*,
0141                                           Acts::IVolumeMaterialJsonDecorator>
0142       m_volumeMaterialConverter;
0143   /// Geometry hierarchy writer for tracking volume.
0144   Acts::GeometryHierarchyMapJsonConverter<Acts::TrackingVolumeAndMaterial,
0145                                           Acts::ITrackingGeometryJsonDecorator>
0146       m_volumeConverter;
0147 
0148   /// Name of the surface hierarchy
0149   std::string m_surfaceName = "Material Surface Map";
0150   /// Geometry hierarchy writer for surface material.
0151   Acts::GeometryHierarchyMapJsonConverter<const ISurfaceMaterial*,
0152                                           Acts::IVolumeMaterialJsonDecorator>
0153       m_surfaceMaterialConverter;
0154   /// Geometry hierarchy writer for surface.
0155   Acts::GeometryHierarchyMapJsonConverter<Acts::SurfaceAndMaterialWithContext,
0156                                           Acts::ITrackingGeometryJsonDecorator>
0157       m_surfaceConverter;
0158 
0159   /// Private access to the logging instance
0160   const Logger& logger() const { return *m_logger; }
0161 };
0162 
0163 }  // namespace Acts