Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortalHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PortalHelper.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include "Acts/Detector/Portal.hpp"
16 
17 #include <array>
18 #include <stdexcept>
19 #include <utility>
20 
22  Portal& portal, const std::shared_ptr<DetectorVolume>& volume,
23  const Direction& direction) {
24  // Create a shared link instance & delegate
25  auto volumeLinkImpl =
26  std::make_unique<const Acts::Experimental::SingleDetectorVolumeImpl>(
27  volume.get());
30  std::move(volumeLinkImpl));
31  // Update the volume link and the store
32  portal.assignDetectorVolumeUpdator(direction, std::move(volumeLink),
33  {volume});
34 }
35 
37  const GeometryContext& gctx, Portal& portal,
38  const std::vector<std::shared_ptr<DetectorVolume>>& volumes,
39  const Direction& direction, const std::vector<ActsScalar>& boundaries,
40  const BinningValue& binning) {
41  // Check if the boundaries need a transform
42  const auto pTransform = portal.surface().transform(gctx);
43  // Creating a link to the mother
44  auto volumes1D = std::make_unique<const BoundVolumesGrid1Impl>(
45  boundaries, binning, unpack_shared_const_vector(volumes),
46  pTransform.inverse());
47  DetectorVolumeUpdator dVolumeUpdator;
48  dVolumeUpdator.connect<&BoundVolumesGrid1Impl::update>(std::move(volumes1D));
49  portal.assignDetectorVolumeUpdator(direction, std::move(dVolumeUpdator),
50  volumes);
51 }
52 
54  const GeometryContext& gctx,
55  const std::vector<std::shared_ptr<DetectorVolume>>& volumes,
56  std::vector<PortalReplacement>& pReplacements) {
57  // Unpack to navigation bare points
58  auto cVolumes = unpack_shared_const_vector(volumes);
59  // Set to the constructed portals (p), at index (i), in direction (d)
60  // using boundaries and binning
61  for (auto& [p, i, dir, boundaries, binning] : pReplacements) {
62  // Check if the boundaries need a transform
63  const auto pTransform = p->surface().transform(gctx);
64  // Creating a link to the mother
65  auto volumes1D = std::make_unique<const BoundVolumesGrid1Impl>(
66  boundaries, binning, cVolumes, pTransform.inverse());
67  DetectorVolumeUpdator dVolumeUpdator;
68  dVolumeUpdator.connect<&BoundVolumesGrid1Impl::update>(
69  std::move(volumes1D));
70  p->assignDetectorVolumeUpdator(dir, std::move(dVolumeUpdator), volumes);
71  }
72 }
73 
74 std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>
76  Portal& portal) noexcept(false) {
77  auto& attachedVolumes = portal.attachedDetectorVolumes();
78  if (not attachedVolumes[0u].empty() and not attachedVolumes[1u].empty()) {
79  throw std::invalid_argument(
80  "PortalHelper: trying to get attachedVolumes from already populated "
81  "portal.");
82  }
83  unsigned int iu = attachedVolumes[0u].empty() ? 1u : 0u;
84  return attachedVolumes[iu];
85 }