File indexing completed on 2025-08-06 08:10:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Detector/detail/PortalHelper.hpp"
0010
0011 #include "Acts/Detector/Portal.hpp"
0012 #include "Acts/Navigation/DetectorVolumeUpdaters.hpp"
0013 #include "Acts/Navigation/NavigationDelegates.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Utilities/Helpers.hpp"
0016
0017 #include <array>
0018 #include <stdexcept>
0019 #include <utility>
0020
0021 void Acts::Experimental::detail::PortalHelper::attachDetectorVolumeUpdater(
0022 Portal& portal, const std::shared_ptr<DetectorVolume>& volume,
0023 const Direction& direction) {
0024
0025 auto volumeLinkImpl =
0026 std::make_unique<const Acts::Experimental::SingleDetectorVolumeImpl>(
0027 volume.get());
0028 Acts::Experimental::DetectorVolumeUpdater volumeLink;
0029 volumeLink.connect<&Acts::Experimental::SingleDetectorVolumeImpl::update>(
0030 std::move(volumeLinkImpl));
0031
0032 portal.assignDetectorVolumeUpdater(direction, std::move(volumeLink),
0033 {volume});
0034 }
0035
0036 void Acts::Experimental::detail::PortalHelper::attachDetectorVolumesUpdater(
0037 const GeometryContext& gctx, Portal& portal,
0038 const std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0039 const Direction& direction, const std::vector<ActsScalar>& boundaries,
0040 const BinningValue& binning) {
0041
0042 const auto pTransform = portal.surface().transform(gctx);
0043
0044 auto volumes1D = std::make_unique<const BoundVolumesGrid1Impl>(
0045 boundaries, binning, unpack_shared_const_vector(volumes),
0046 pTransform.inverse());
0047 DetectorVolumeUpdater dVolumeUpdater;
0048 dVolumeUpdater.connect<&BoundVolumesGrid1Impl::update>(std::move(volumes1D));
0049 portal.assignDetectorVolumeUpdater(direction, std::move(dVolumeUpdater),
0050 volumes);
0051 }
0052
0053 void Acts::Experimental::detail::PortalHelper::attachDetectorVolumeUpdaters(
0054 const GeometryContext& gctx,
0055 const std::vector<std::shared_ptr<DetectorVolume>>& volumes,
0056 std::vector<PortalReplacement>& pReplacements) {
0057
0058 auto cVolumes = unpack_shared_const_vector(volumes);
0059
0060
0061 for (auto& [p, i, dir, boundaries, binning] : pReplacements) {
0062
0063 const auto pTransform = p->surface().transform(gctx);
0064
0065 auto volumes1D = std::make_unique<const BoundVolumesGrid1Impl>(
0066 boundaries, binning, cVolumes, pTransform.inverse());
0067 DetectorVolumeUpdater dVolumeUpdater;
0068 dVolumeUpdater.connect<&BoundVolumesGrid1Impl::update>(
0069 std::move(volumes1D));
0070 p->assignDetectorVolumeUpdater(dir, std::move(dVolumeUpdater), volumes);
0071 }
0072 }
0073
0074 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>
0075 Acts::Experimental::detail::PortalHelper::attachedDetectorVolumes(
0076 Portal& portal) noexcept(false) {
0077 auto& attachedVolumes = portal.attachedDetectorVolumes();
0078 if (!attachedVolumes[0u].empty() && !attachedVolumes[1u].empty()) {
0079 throw std::invalid_argument(
0080 "PortalHelper: trying to get attachedVolumes from already populated "
0081 "portal.");
0082 }
0083 unsigned int iu = attachedVolumes[0u].empty() ? 1u : 0u;
0084 return attachedVolumes[iu];
0085 }
0086
0087 std::map<unsigned int,
0088 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>>
0089 Acts::Experimental::detail::PortalHelper::stripSideVolumes(
0090 const std::vector<std::map<unsigned int, std::shared_ptr<Portal>>>&
0091 pContainers,
0092 const std::vector<unsigned int>& sides,
0093 const std::vector<unsigned int>& selectedOnly,
0094 Acts::Logging::Level logLevel) {
0095 ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("::stripSideVolumes", logLevel));
0096
0097
0098 std::map<unsigned int,
0099 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>>
0100 sideVolumes;
0101
0102
0103 std::vector<unsigned int> selectedSides;
0104 if (!selectedOnly.empty()) {
0105 std::set_intersection(sides.begin(), sides.end(), selectedOnly.begin(),
0106 selectedOnly.end(),
0107 std::back_inserter(selectedSides));
0108 } else {
0109 selectedSides = sides;
0110 }
0111
0112
0113 for (const auto& pc : pContainers) {
0114
0115 for (const auto& s : selectedSides) {
0116 auto cSide = pc.find(s);
0117 if (cSide != pc.end()) {
0118 auto p = cSide->second;
0119 auto& sVolumes = sideVolumes[s];
0120 auto aVolumes =
0121 Acts::Experimental::detail::PortalHelper::attachedDetectorVolumes(
0122 *p);
0123 sVolumes.insert(sVolumes.end(), aVolumes.begin(), aVolumes.end());
0124 }
0125 }
0126 }
0127
0128 return sideVolumes;
0129 }