Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PortalGenerators.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PortalGenerators.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 
12 #include "Acts/Detector/Portal.hpp"
17 
18 #include <iterator>
19 #include <stdexcept>
20 #include <utility>
21 
22 std::vector<std::shared_ptr<Acts::Experimental::Portal>>
24  const Transform3& dTransform, const VolumeBounds& dBounds,
25  const std::shared_ptr<DetectorVolume>& dVolume) noexcept(false) {
26  if (dVolume == nullptr) {
27  throw std::runtime_error("PortalsGenerator: no detector volume provided.");
28  }
29  // Get the oriented boundary surfaces
30  auto orientedSurfaces = dBounds.orientedSurfaces(dTransform);
31 
32  // Create and fill the portal return vector
33  std::vector<std::shared_ptr<Portal>> portals;
34  for (auto [i, oSurface] : enumerate(orientedSurfaces)) {
35  // Create a portal from the surface
36  auto portal = Portal::makeShared(oSurface.first);
37  // Create a shared link instance & delegate
38  auto singleLinkImpl =
39  std::make_unique<const SingleDetectorVolumeImpl>(dVolume.get());
40  DetectorVolumeUpdator singleLink;
41  singleLink.connect<&SingleDetectorVolumeImpl::update>(
42  std::move(singleLinkImpl));
43  // Update the volume link and the store
44  portal->assignDetectorVolumeUpdator(oSurface.second, std::move(singleLink),
45  {dVolume});
46  // Portal is prepared
47  portals.push_back(std::move(portal));
48  }
49 
50  // The portals are returned
51  return portals;
52 }
53 
56  PortalGenerator pGenerator;
57  pGenerator.connect<&generatePortals>();
58  return pGenerator;
59 }
60 
61 std::vector<std::shared_ptr<Acts::Experimental::Portal>>
63  const Transform3& dTransform, const VolumeBounds& dBounds,
64  const std::shared_ptr<DetectorVolume>& dVolume) noexcept(false) {
65  if (dVolume == nullptr) {
66  throw std::runtime_error(
67  "generatePortalsUpdateInternals: no detector volume provided.");
68  }
69 
70  // Setting link to the mother volume to all sub volumes of this volume
71  for (auto& vPtr : dVolume->volumePtrs()) {
72  for (auto& pPtr : vPtr->portalPtrs()) {
73  // Creating a link to the mother
74  auto motherLinkImpl =
75  std::make_unique<const SingleDetectorVolumeImpl>(dVolume.get());
76  DetectorVolumeUpdator motherLink;
77  motherLink.connect<&SingleDetectorVolumeImpl::update>(
78  std::move(motherLinkImpl));
79  pPtr->assignDetectorVolumeUpdator(std::move(motherLink), {dVolume});
80  }
81  }
82  // Return from the standard generator
83  return generatePortals(dTransform, dBounds, dVolume);
84 }
85 
88  PortalGenerator pGenerator;
89  pGenerator.connect<&generatePortalsUpdateInternals>();
90  return pGenerator;
91 }