Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:19

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/Detector/PortalGenerators.hpp"
0010 
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/Portal.hpp"
0013 #include "Acts/Geometry/VolumeBounds.hpp"
0014 #include "Acts/Navigation/NavigationDelegates.hpp"
0015 #include "Acts/Navigation/PortalNavigation.hpp"
0016 #include "Acts/Utilities/Enumerate.hpp"
0017 
0018 #include <iterator>
0019 #include <stdexcept>
0020 #include <utility>
0021 
0022 std::vector<std::shared_ptr<Acts::Experimental::Portal>>
0023 Acts::Experimental::generatePortals(
0024     const Transform3& dTransform, const VolumeBounds& dBounds,
0025     const std::shared_ptr<DetectorVolume>& dVolume) noexcept(false) {
0026   if (dVolume == nullptr) {
0027     throw std::runtime_error("PortalsGenerator: no detector volume provided.");
0028   }
0029   // Get the oriented boundary surfaces
0030   auto orientedSurfaces = dBounds.orientedSurfaces(dTransform);
0031 
0032   // Create and fill the portal return vector
0033   std::vector<std::shared_ptr<Portal>> portals;
0034   for (auto [i, oSurface] : enumerate(orientedSurfaces)) {
0035     // Create a portal from the surface
0036     auto portal = std::make_shared<Portal>(oSurface.surface);
0037     // Create a shared link instance & delegate
0038     auto singleLinkImpl =
0039         std::make_unique<const SingleDetectorVolumeNavigation>(dVolume.get());
0040     ExternalNavigationDelegate singleLink;
0041     singleLink.connect<&SingleDetectorVolumeNavigation::update>(
0042         std::move(singleLinkImpl));
0043     // Update the volume link and the store
0044     portal->assignPortalNavigation(oSurface.direction, std::move(singleLink),
0045                                    {dVolume});
0046     // Portal is prepared
0047     portals.push_back(std::move(portal));
0048   }
0049 
0050   // The portals are returned
0051   return portals;
0052 }
0053 
0054 Acts::Experimental::PortalGenerator
0055 Acts::Experimental::defaultPortalGenerator() {
0056   PortalGenerator pGenerator;
0057   pGenerator.connect<&generatePortals>();
0058   return pGenerator;
0059 }
0060 
0061 std::vector<std::shared_ptr<Acts::Experimental::Portal>>
0062 Acts::Experimental::generatePortalsUpdateInternals(
0063     const Transform3& dTransform, const VolumeBounds& dBounds,
0064     const std::shared_ptr<DetectorVolume>& dVolume) noexcept(false) {
0065   if (dVolume == nullptr) {
0066     throw std::runtime_error(
0067         "generatePortalsUpdateInternals: no detector volume provided.");
0068   }
0069 
0070   // Setting link to the mother volume to all sub volumes of this volume
0071   for (auto& vPtr : dVolume->volumePtrs()) {
0072     for (auto& pPtr : vPtr->portalPtrs()) {
0073       // Creating a link to the mother
0074       auto motherLinkImpl =
0075           std::make_unique<const SingleDetectorVolumeNavigation>(dVolume.get());
0076       ExternalNavigationDelegate motherLink;
0077       motherLink.connect<&SingleDetectorVolumeNavigation::update>(
0078           std::move(motherLinkImpl));
0079       pPtr->assignPortalNavigation(std::move(motherLink), {dVolume});
0080     }
0081   }
0082   // Return from the standard generator
0083   return generatePortals(dTransform, dBounds, dVolume);
0084 }
0085 
0086 Acts::Experimental::PortalGenerator
0087 Acts::Experimental::defaultPortalAndSubPortalGenerator() {
0088   PortalGenerator pGenerator;
0089   pGenerator.connect<&generatePortalsUpdateInternals>();
0090   return pGenerator;
0091 }