Back to home page

EIC code displayed by LXR

 
 

    


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

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/Units.hpp"
0012 #include "Acts/Detector/Blueprint.hpp"
0013 #include "Acts/Detector/interface/IGeometryIdGenerator.hpp"
0014 #include "Acts/Detector/interface/IInternalStructureBuilder.hpp"
0015 #include "Acts/Detector/interface/IRootVolumeFinderBuilder.hpp"
0016 #include "Acts/Geometry/Extent.hpp"
0017 #include "Acts/Geometry/GeometryContext.hpp"
0018 #include "Acts/Geometry/VolumeBounds.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "ActsPlugins/DD4hep/DD4hepDetectorElement.hpp"
0021 #include "ActsPlugins/DD4hep/DD4hepLayerStructure.hpp"
0022 
0023 #include <memory>
0024 #include <optional>
0025 #include <tuple>
0026 #include <vector>
0027 
0028 #include <DD4hep/DD4hepUnits.h>
0029 #include <DD4hep/DetElement.h>
0030 
0031 namespace ActsPlugins {
0032 
0033 class DD4hepBlueprintFactory {
0034  public:
0035   /// @brief Nested config object
0036   struct Config {
0037     std::shared_ptr<ActsPlugins::DD4hepLayerStructure> layerStructure = nullptr;
0038     /// Configuration for DD4hep layer structure extraction
0039 
0040     /// The maximum number of portals to be checked for protal material
0041     unsigned int maxPortals = 8u;
0042   };
0043 
0044   /// @brief Nested cache object for the detector store
0045   struct Cache {
0046     /// Storage for DD4hep detector elements
0047     DD4hepDetectorElement::Store dd4hepStore;
0048   };
0049 
0050   /// @brief Constructor with arguments
0051   ///
0052   /// @param cfg the config object
0053   /// @param mlogger the logging instance
0054   explicit DD4hepBlueprintFactory(
0055       const Config& cfg,
0056       std::unique_ptr<const Acts::Logger> mlogger = Acts::getDefaultLogger(
0057           "DD4hepBlueprintFactory", Acts::Logging::INFO));
0058 
0059   /// @brief Create a blueprint from a DD4hep detector element
0060   ///
0061   /// @param cache the cache object for the detector store
0062   /// @param gctx the geometry context
0063   /// @param dd4hepElement the dd4hep detector element tree
0064   ///
0065   /// @return a new blueprint top node
0066   std::unique_ptr<Acts::Experimental::Gen2Blueprint::Node> create(
0067       Cache& cache, const Acts::GeometryContext& gctx,
0068       const dd4hep::DetElement& dd4hepElement) const;
0069 
0070  private:
0071   /// @brief auto-calculate the unit length conversion
0072   static constexpr double unitLength =
0073       Acts::UnitConstants::mm / dd4hep::millimeter;
0074 
0075   /// Configuration struct
0076   Config m_cfg;
0077 
0078   /// Logging instance
0079   std::unique_ptr<const Acts::Logger> m_logger;
0080 
0081   /// Private access to the logger
0082   const Acts::Logger& logger() const { return *m_logger; }
0083 
0084   /// @brief Recursive parsing of the detector element tree
0085   ///
0086   /// @param cache the cache object
0087   /// @param mother the mother node
0088   /// @param gctx the geometry context
0089   /// @param dd4hepElement the detector element at current level
0090   /// @param hiearchyLevel the current hierarchy level
0091   void recursiveParse(Cache& cache,
0092                       Acts::Experimental::Gen2Blueprint::Node& mother,
0093                       const Acts::GeometryContext& gctx,
0094                       const dd4hep::DetElement& dd4hepElement,
0095                       unsigned int hiearchyLevel = 0) const;
0096 
0097   /// @brief Extract the bounds type, values and binning from a DD4hep element
0098   ///
0099   /// @param gctx the geometry context
0100   /// @param dd4hepElement the DD4hep element
0101   /// @param baseName the base name of the acts type, e.g. "acts_volume", "acts_container", ...
0102   /// @param extOpt the optional extent as output from the internal parsing
0103   ///
0104   /// @return a tuple of the bounds type, values and binning, auxiliary data
0105   std::tuple<Acts::Transform3, Acts::VolumeBounds::BoundsType,
0106              std::vector<double>, std::vector<Acts::AxisDirection>, std::string>
0107   extractExternals(
0108       [[maybe_unused]] const Acts::GeometryContext& gctx,
0109       const dd4hep::DetElement& dd4hepElement, const std::string& baseName,
0110       const std::optional<Acts::Extent>& extOpt = std::nullopt) const;
0111 
0112   /// @brief Extract the internals from a DD4hep element
0113   ///
0114   /// This method parses the dd4hep element to return the internal structure
0115   /// builder, the root volume finder, and the geometry id generator.
0116   ///
0117   /// If any of the elements is not found, a nullptr is returned.
0118   ///
0119   /// @param dd4hepStore the store for the created dd4hep detector elements
0120   /// @param gctx the geometry context
0121   /// @param dd4hepElement the DD4hep element
0122   /// @param baseName the base name of the acts type, e.g. "acts_volume", "acts_container", ...
0123   ///
0124   /// @note The auxiliary information is returned as well for each of them
0125   ///
0126   /// @return a tuple of tools and auxiliary information
0127   std::tuple<
0128       std::shared_ptr<const Acts::Experimental::IInternalStructureBuilder>,
0129       std::shared_ptr<const Acts::Experimental::IRootVolumeFinderBuilder>,
0130       std::shared_ptr<const Acts::Experimental::IGeometryIdGenerator>,
0131       std::array<std::string, 3u>, std::optional<Acts::Extent>>
0132   extractInternals(DD4hepDetectorElement::Store& dd4hepStore,
0133                    const Acts::GeometryContext& gctx,
0134                    const dd4hep::DetElement& dd4hepElement,
0135                    const std::string& baseName) const;
0136 };
0137 
0138 }  // namespace ActsPlugins