Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 07:49:56

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