Back to home page

EIC code displayed by LXR

 
 

    


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

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