Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:38

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2018 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 http://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 std::shared_ptr<const Acts::TrackingVolumeArray>
0022 Acts::TrackingVolumeArrayCreator::trackingVolumeArray(
0023     const GeometryContext& gctx, const TrackingVolumeVector& tVolumes,
0024     BinningValue bValue) const {
0025   // MSG_VERBOSE("Create VolumeArray of "<< tVolumes.size() << " TrackingVolumes
0026   // with binning in : " << binningValueNames()[bValue] );
0027   // let's copy and sort
0028   TrackingVolumeVector volumes(tVolumes);
0029   // sort it accordingly to the binning value
0030   GeometryObjectSorterT<std::shared_ptr<const TrackingVolume>> volumeSorter(
0031       gctx, bValue);
0032   std::sort(volumes.begin(), volumes.end(), volumeSorter);
0033 
0034   // prepare what we need :
0035   // (1) arbitrary binning for volumes is fast enough
0036   std::vector<float> boundaries;
0037   boundaries.reserve(tVolumes.size() + 1);
0038   // (2) the vector needed for the BinnedArray
0039   std::vector<TrackingVolumeOrderPosition> tVolumesOrdered;
0040 
0041   // let's loop over the (sorted) volumes
0042   for (auto& tVolume : volumes) {
0043     // get the binning position
0044     Vector3 binningPosition = tVolume->binningPosition(gctx, bValue);
0045     double binningBorder = tVolume->volumeBounds().binningBorder(bValue);
0046     // get the center value according to the bin
0047     double value = tVolume->binningPositionValue(gctx, bValue);
0048     // for the first one take low and high boundary
0049     if (boundaries.empty()) {
0050       boundaries.push_back(value - binningBorder);
0051     }
0052     // always take the high boundary
0053     boundaries.push_back(value + binningBorder);
0054     // record the volume to be ordered
0055     tVolumesOrdered.push_back(
0056         TrackingVolumeOrderPosition(tVolume, binningPosition));
0057   }
0058 
0059   // now create the bin utility
0060   auto binUtility =
0061       std::make_unique<const BinUtility>(boundaries, open, bValue);
0062 
0063   // and return the newly created binned array
0064   return std::make_shared<const BinnedArrayXD<TrackingVolumePtr>>(
0065       tVolumesOrdered, std::move(binUtility));
0066 }