Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:18

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 #include "Acts/Plugins/DD4hep/DD4hepLayerStructure.hpp"
0010 
0011 #include "Acts/Utilities/BinningType.hpp"
0012 
0013 Acts::Experimental::DD4hepLayerStructure::DD4hepLayerStructure(
0014     std::shared_ptr<DD4hepDetectorSurfaceFactory> surfaceFactory,
0015     std::unique_ptr<const Logger> logger)
0016     : m_surfaceFactory(std::move(surfaceFactory)), m_logger(std::move(logger)) {
0017   if (m_surfaceFactory == nullptr) {
0018     throw std::invalid_argument(
0019         "DD4hepLayerStructure: no surface factory provided");
0020   }
0021 }
0022 
0023 std::tuple<std::shared_ptr<Acts::Experimental::LayerStructureBuilder>,
0024            std::optional<Acts::Extent>>
0025 Acts::Experimental::DD4hepLayerStructure::builder(
0026     DD4hepDetectorElement::Store& dd4hepStore, const GeometryContext& gctx,
0027     const dd4hep::DetElement& dd4hepElement, const Options& options) const {
0028   // Check for misconfiguration with double naming
0029   if (dd4hepStore.contains(options.name)) {
0030     std::string reMessage = "DD4hepLayerStructure: structure with name '";
0031     reMessage += options.name;
0032     reMessage += "' already registered in DetectorElementStore";
0033     throw std::runtime_error(reMessage.c_str());
0034   }
0035 
0036   // This object is going to be filled with the created surfaces
0037   DD4hepDetectorSurfaceFactory::Cache fCache;
0038   fCache.sExtent = options.extent;
0039   fCache.pExtent = options.extent;
0040   fCache.extentConstraints = options.extentConstraints;
0041   fCache.nExtentQSegments = options.quarterSegments;
0042   m_surfaceFactory->construct(fCache, gctx, dd4hepElement,
0043                               options.conversionOptions);
0044 
0045   ACTS_DEBUG("Conversion from DD4Hep : " << fCache.sensitiveSurfaces.size()
0046                                          << " sensitive surfaces");
0047 
0048   ACTS_DEBUG("Conversion from DD4Hep : " << fCache.passiveSurfaces.size()
0049                                          << " passive surfaces");
0050 
0051   // Check if binning was provided or detected
0052   if (fCache.binnings.empty() &&
0053       (fCache.sensitiveSurfaces.size() + fCache.passiveSurfaces.size()) > 0u) {
0054     ACTS_VERBOSE(
0055         "Surface binning neither provided nor found, navigation will be "
0056         "'tryAll' (could result in slow navigation).");
0057   }
0058 
0059   // Surfaces are prepared for creating the builder
0060   LayerStructureBuilder::Config lsbConfig;
0061   lsbConfig.auxiliary = "*** DD4hep auto-generated builder for: ";
0062   lsbConfig.extent = fCache.sExtent;
0063   lsbConfig.auxiliary += options.name;
0064 
0065   // Patch the binning to the extent parameters
0066   if (fCache.sExtent.has_value() && options.patchBinningWithExtent) {
0067     const auto& extent = fCache.sExtent.value();
0068     // Check if the binning
0069     ACTS_VERBOSE("Checking if surface binning ranges can be patched.");
0070     for (auto& b : fCache.binnings) {
0071       if (extent.constrains(b.axisDir)) {
0072         ACTS_VERBOSE("Binning '" << axisDirectionName(b.axisDir)
0073                                  << "' is patched.");
0074         ACTS_VERBOSE(" <- from : [" << b.edges.front() << ", " << b.edges.back()
0075                                     << "]");
0076         b.edges.front() = extent.min(b.axisDir);
0077         b.edges.back() = extent.max(b.axisDir);
0078         ACTS_VERBOSE(" -> to   : [" << b.edges.front() << ", " << b.edges.back()
0079                                     << "]");
0080       }
0081     }
0082   }
0083 
0084   // Translate binings and supports
0085   lsbConfig.binnings = fCache.binnings;
0086   lsbConfig.supports = fCache.supports;
0087 
0088   std::vector<std::shared_ptr<Surface>> lSurfaces;
0089   lSurfaces.reserve(fCache.sensitiveSurfaces.size() +
0090                     fCache.passiveSurfaces.size());
0091 
0092   std::vector<std::shared_ptr<DD4hepDetectorElement>> cElements;
0093   cElements.reserve(fCache.sensitiveSurfaces.size());
0094 
0095   // Fill them in to the surface provider struct and detector store
0096   for (const auto& [de, ds] : fCache.sensitiveSurfaces) {
0097     lSurfaces.push_back(ds);
0098     cElements.push_back(de);
0099   }
0100   dd4hepStore[options.name] = cElements;
0101 
0102   // Passive surfaces to be added
0103   for (const auto& [ps, toAll] : fCache.passiveSurfaces) {
0104     // Passive surface is not declared to be added to all navigation bins
0105     if (!toAll) {
0106       lSurfaces.push_back(ps);
0107     } else {
0108       // Passive surface is indeed declared to be added to all navigaiton bins
0109       Experimental::ProtoSupport pSupport;
0110       pSupport.surface = ps;
0111       pSupport.assignToAll = true;
0112       lsbConfig.supports.push_back(pSupport);
0113     }
0114   }
0115 
0116   // Create the surface provider from the layer structure
0117   lsbConfig.surfacesProvider =
0118       std::make_shared<Experimental::LayerStructureBuilder::SurfacesHolder>(
0119           lSurfaces);
0120 
0121   ACTS_DEBUG("Configured with " << lsbConfig.binnings.size() << " binnings.");
0122   ACTS_DEBUG("Configured to build " << lsbConfig.supports.size()
0123                                     << " supports.");
0124 
0125   // Make one common extent
0126   if (fCache.sExtent.has_value() && fCache.pExtent.has_value()) {
0127     ACTS_DEBUG(
0128         "Sensitive extent determined: " << fCache.sExtent.value().toString());
0129     ACTS_DEBUG(
0130         "Passive   extent determined: " << fCache.pExtent.value().toString());
0131     fCache.sExtent.value().extend(fCache.pExtent.value());
0132   }
0133 
0134   // Return the structure builder
0135   return {std::make_shared<LayerStructureBuilder>(
0136               lsbConfig, getDefaultLogger(options.name, options.logLevel)),
0137           fCache.sExtent};
0138 }