Back to home page

EIC code displayed by LXR

 
 

    


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

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/IndexedRootVolumeFinderBuilder.hpp"
0010 
0011 #include "Acts/Detector/DetectorVolume.hpp"
0012 #include "Acts/Detector/detail/CylindricalDetectorHelper.hpp"
0013 #include "Acts/Navigation/DetectorVolumeFinders.hpp"
0014 #include "Acts/Utilities/Enumerate.hpp"
0015 #include "Acts/Utilities/GridAxisGenerators.hpp"
0016 
0017 namespace {
0018 
0019 template <typename Grid2D>
0020 void fillGridIndices2D(
0021     const Acts::GeometryContext& gctx, Grid2D& grid,
0022     const std::vector<std::shared_ptr<Acts::Experimental::DetectorVolume>>&
0023         rootVolumes,
0024     const std::array<std::vector<double>, 2u>& boundaries,
0025     const std::array<Acts::AxisDirection, 2u>& casts) {
0026   // Brute force loop over all bins & all volumes
0027   for (const auto [ic0, c0] : Acts::enumerate(boundaries[0u])) {
0028     if (ic0 > 0) {
0029       double v0 = 0.5 * (c0 + boundaries[0u][ic0 - 1]);
0030       for (const auto [ic1, c1] : Acts::enumerate(boundaries[1u])) {
0031         if (ic1 > 0) {
0032           double v1 = 0.5 * (c1 + boundaries[1u][ic1 - 1]);
0033           if (casts ==
0034               std::array<Acts::AxisDirection, 2u>{Acts::AxisDirection::AxisZ,
0035                                                   Acts::AxisDirection::AxisR}) {
0036             Acts::Vector3 zrPosition{v1, 0., v0};
0037             for (const auto [iv, v] : Acts::enumerate(rootVolumes)) {
0038               if (v->inside(gctx, zrPosition)) {
0039                 typename Grid2D::point_t p{v0, v1};
0040                 grid.atPosition(p) = iv;
0041               }
0042             }
0043           }
0044         }
0045       }
0046     }
0047   }
0048 }
0049 }  // namespace
0050 
0051 Acts::Experimental::IndexedRootVolumeFinderBuilder::
0052     IndexedRootVolumeFinderBuilder(std::vector<Acts::AxisDirection> binning)
0053     : m_casts(std::move(binning)) {
0054   if (m_casts != std::vector<Acts::AxisDirection>{Acts::AxisDirection::AxisZ,
0055                                                   Acts::AxisDirection::AxisR}) {
0056     throw std::invalid_argument("Online (z,r) binning is currently supported.");
0057   }
0058 }
0059 
0060 Acts::Experimental::ExternalNavigationDelegate
0061 Acts::Experimental::IndexedRootVolumeFinderBuilder::construct(
0062     const GeometryContext& gctx,
0063     const std::vector<std::shared_ptr<DetectorVolume>>& rootVolumes) const {
0064   auto rzphis =
0065       detail::CylindricalDetectorHelper::rzphiBoundaries(gctx, rootVolumes);
0066 
0067   using AxesGeneratorType = Acts::GridAxisGenerators::VarBoundVarBound;
0068 
0069   AxesGeneratorType zrAxes{rzphis[1], rzphis[0]};
0070 
0071   // Create the grid with the provided axis generator
0072   using GridType = typename AxesGeneratorType::template grid_type<std::size_t>;
0073   GridType grid(zrAxes());
0074 
0075   auto casts = std::array<AxisDirection, 2u>{m_casts[0u], m_casts[1u]};
0076 
0077   auto boundaries = std::array<std::vector<double>, 2u>{rzphis[1], rzphis[0]};
0078   fillGridIndices2D(gctx, grid, rootVolumes, boundaries, casts);
0079 
0080   using IndexedDetectorVolumesImpl =
0081       IndexedGridNavigation<IExternalNavigation, GridType,
0082                             IndexedDetectorVolumeExtractor,
0083                             DetectorVolumeFiller>;
0084 
0085   auto indexedDetectorVolumeImpl =
0086       std::make_unique<const IndexedDetectorVolumesImpl>(std::move(grid),
0087                                                          casts);
0088 
0089   // Return the root volume finder
0090   ExternalNavigationDelegate rootVolumeFinder;
0091   rootVolumeFinder.connect<&IndexedDetectorVolumesImpl::update>(
0092       std::move(indexedDetectorVolumeImpl));
0093   return rootVolumeFinder;
0094 }