Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:12:21

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/Geometry/TrackingVolumeArrayCreator.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryObjectSorter.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 #include "Acts/Geometry/VolumeBounds.hpp"
0015 #include "Acts/Utilities/BinUtility.hpp"
0016 #include "Acts/Utilities/BinnedArrayXD.hpp"
0017 
0018 #include <algorithm>
0019 #include <vector>
0020 
0021 namespace Acts {
0022 
0023 std::shared_ptr<const TrackingVolumeArray>
0024 TrackingVolumeArrayCreator::trackingVolumeArray(
0025     const GeometryContext& gctx, const TrackingVolumeVector& tVolumes,
0026     AxisDirection aDir) const {
0027   // MSG_VERBOSE("Create VolumeArray of "<< tVolumes.size() << " TrackingVolumes
0028   // with binning in : " << axisDirectionName(aDir) );
0029   // let's copy and sort
0030   TrackingVolumeVector volumes(tVolumes);
0031   // sort it accordingly to the binning value
0032   GeometryObjectSorterT<std::shared_ptr<const TrackingVolume>> volumeSorter(
0033       gctx, aDir);
0034   std::ranges::sort(volumes, volumeSorter);
0035 
0036   // prepare what we need :
0037   // (1) arbitrary binning for volumes is fast enough
0038   std::vector<float> boundaries;
0039   boundaries.reserve(tVolumes.size() + 1);
0040   // (2) the vector needed for the BinnedArray
0041   std::vector<TrackingVolumeOrderPosition> tVolumesOrdered;
0042 
0043   // let's loop over the (sorted) volumes
0044   for (auto& tVolume : volumes) {
0045     // get the binning position
0046     Vector3 referencePosition = tVolume->referencePosition(gctx, aDir);
0047     double referenceBorder = tVolume->volumeBounds().referenceBorder(aDir);
0048     // get the center value according to the bin
0049     double value = tVolume->referencePositionValue(gctx, aDir);
0050     // for the first one take low and high boundary
0051     if (boundaries.empty()) {
0052       boundaries.push_back(value - referenceBorder);
0053     }
0054     // always take the high boundary
0055     boundaries.push_back(value + referenceBorder);
0056     // record the volume to be ordered
0057     tVolumesOrdered.push_back(
0058         TrackingVolumeOrderPosition(tVolume, referencePosition));
0059   }
0060 
0061   // now create the bin utility
0062   auto binUtility = std::make_unique<const BinUtility>(boundaries, open, aDir);
0063 
0064   // and return the newly created binned array
0065   return std::make_shared<const BinnedArrayXD<TrackingVolumePtr>>(
0066       tVolumesOrdered, std::move(binUtility));
0067 }
0068 
0069 }  // namespace Acts