File indexing completed on 2025-01-18 09:12:18
0001
0002
0003
0004
0005
0006
0007
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
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
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
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
0060 LayerStructureBuilder::Config lsbConfig;
0061 lsbConfig.auxiliary = "*** DD4hep auto-generated builder for: ";
0062 lsbConfig.extent = fCache.sExtent;
0063 lsbConfig.auxiliary += options.name;
0064
0065
0066 if (fCache.sExtent.has_value() && options.patchBinningWithExtent) {
0067 const auto& extent = fCache.sExtent.value();
0068
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
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
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
0103 for (const auto& [ps, toAll] : fCache.passiveSurfaces) {
0104
0105 if (!toAll) {
0106 lSurfaces.push_back(ps);
0107 } else {
0108
0109 Experimental::ProtoSupport pSupport;
0110 pSupport.surface = ps;
0111 pSupport.assignToAll = true;
0112 lsbConfig.supports.push_back(pSupport);
0113 }
0114 }
0115
0116
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
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
0135 return {std::make_shared<LayerStructureBuilder>(
0136 lsbConfig, getDefaultLogger(options.name, options.logLevel)),
0137 fCache.sExtent};
0138 }