Back to home page

EIC code displayed by LXR

 
 

    


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

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