diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index f426da42b36..56aacc86bd4 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -147,17 +147,22 @@ class BinnedSPGroupIterator { BinnedSPGroupIterator& operator++() { if (zIndex < phiZbins[1]) { zIndex++; - } else { zIndex = 1; phiIndex++; } + + size_t this_zIndex = zIndex; + if (not customZorder.empty()) + this_zIndex = customZorder.at(this_zIndex - 1); + // set current & neighbor bins only if bin indices valid if (phiIndex <= phiZbins[0] && zIndex <= phiZbins[1]) { - currentBin = - NeighborhoodVector{grid->globalBinFromLocalBins({phiIndex, zIndex})}; - bottomBinIndices = m_bottomBinFinder->findBins(phiIndex, zIndex, grid); - topBinIndices = m_topBinFinder->findBins(phiIndex, zIndex, grid); + currentBin = NeighborhoodVector{ + grid->globalBinFromLocalBins({phiIndex, this_zIndex})}; + bottomBinIndices = + m_bottomBinFinder->findBins(phiIndex, this_zIndex, grid); + topBinIndices = m_topBinFinder->findBins(phiIndex, this_zIndex, grid); outputIndex++; return *this; } @@ -188,34 +193,50 @@ class BinnedSPGroupIterator { BinnedSPGroupIterator(const SpacePointGrid* spgrid, BinFinder* botBinFinder, - BinFinder* tBinFinder) - : currentBin({spgrid->globalBinFromLocalBins({1, 1})}) { + BinFinder* tBinFinder, + boost::container::small_vector bins = {}) { grid = spgrid; m_bottomBinFinder = botBinFinder; m_topBinFinder = tBinFinder; phiZbins = grid->numLocalBins(); phiIndex = 1; zIndex = 1; - outputIndex = 0; - bottomBinIndices = m_bottomBinFinder->findBins(phiIndex, zIndex, grid); - topBinIndices = m_topBinFinder->findBins(phiIndex, zIndex, grid); + customZorder = bins; + // if m_bins vector was not defined, use z bin 1 (zIndex) to start the + // iterator, otherwise use the first value in m_bins vector + size_t this_zIndex = bins.empty() ? zIndex : bins.front(); + outputIndex = grid->globalBinFromLocalBins({phiIndex, this_zIndex}); + currentBin = NeighborhoodVector{ + grid->globalBinFromLocalBins({phiIndex, this_zIndex})}; + bottomBinIndices = m_bottomBinFinder->findBins(phiIndex, this_zIndex, grid); + topBinIndices = m_topBinFinder->findBins(phiIndex, this_zIndex, grid); } BinnedSPGroupIterator(const SpacePointGrid* spgrid, BinFinder* botBinFinder, BinFinder* tBinFinder, - size_t phiInd, size_t zInd) - : currentBin({spgrid->globalBinFromLocalBins({phiInd, zInd})}) { + size_t phiInd, size_t zInd, + boost::container::small_vector bins = {}) { m_bottomBinFinder = botBinFinder; m_topBinFinder = tBinFinder; grid = spgrid; phiIndex = phiInd; zIndex = zInd; phiZbins = grid->numLocalBins(); - outputIndex = (phiInd - 1) * phiZbins[1] + zInd - 1; + customZorder = bins; + // if m_bins vector was not defined, use the next z bin (zInd), otherwise + // use the z bin value stored in m_bins vector for a custom order + size_t this_zIndex = + bins.empty() + ? zIndex + : (zIndex <= phiZbins[1] ? bins.at(zIndex - 1) : bins.back()); + outputIndex = grid->globalBinFromLocalBins({phiIndex, this_zIndex}); + currentBin = + NeighborhoodVector(grid->globalBinFromLocalBins({phiInd, this_zIndex})); if (phiIndex <= phiZbins[0] && zIndex <= phiZbins[1]) { - bottomBinIndices = m_bottomBinFinder->findBins(phiIndex, zIndex, grid); - topBinIndices = m_topBinFinder->findBins(phiIndex, zIndex, grid); + bottomBinIndices = + m_bottomBinFinder->findBins(phiIndex, this_zIndex, grid); + topBinIndices = m_topBinFinder->findBins(phiIndex, this_zIndex, grid); } } @@ -231,6 +252,8 @@ class BinnedSPGroupIterator { std::array phiZbins; BinFinder* m_bottomBinFinder; BinFinder* m_topBinFinder; + boost::container::small_vector customZorder; + // bool start = true; }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator @@ -255,14 +278,15 @@ class BinnedSPGroup { BinnedSPGroupIterator begin() { return BinnedSPGroupIterator( - m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get()); + m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get(), + m_bins); } BinnedSPGroupIterator end() { auto phiZbins = m_binnedSP->numLocalBins(); return BinnedSPGroupIterator( m_binnedSP.get(), m_bottomBinFinder.get(), m_topBinFinder.get(), - phiZbins[0], phiZbins[1] + 1); + phiZbins[0], phiZbins[1] + 1, m_bins); } private: @@ -273,6 +297,8 @@ class BinnedSPGroup { // each bin sorted in r (ascending) std::shared_ptr> m_topBinFinder; std::shared_ptr> m_bottomBinFinder; + + boost::container::small_vector m_bins; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index c7724c9af02..b3ca604138a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -82,4 +82,6 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_binnedSP = std::move(grid); m_bottomBinFinder = botBinFinder; m_topBinFinder = tBinFinder; + + m_bins = _config.zBinsCustomLooping; } diff --git a/Core/include/Acts/Seeding/SeedfinderConfig.hpp b/Core/include/Acts/Seeding/SeedfinderConfig.hpp index 2cf85cb0322..06d606dc3d0 100644 --- a/Core/include/Acts/Seeding/SeedfinderConfig.hpp +++ b/Core/include/Acts/Seeding/SeedfinderConfig.hpp @@ -119,6 +119,8 @@ struct SeedfinderConfig { Acts::Vector2 beamPos{0 * Acts::UnitConstants::mm, 0 * Acts::UnitConstants::mm}; + boost::container::small_vector zBinsCustomLooping = {}; + // average radiation lengths of material on the length of a seed. used for // scattering. // default is 5% diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index c7ddc0e88c4..344ba07fdbd 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -87,6 +87,20 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( throw std::invalid_argument("Inconsistent config zBinNeighborsBottom"); } + if (m_cfg.seedFinderConfig.zBinsCustomLooping.size() != 0) { + // check if zBinsCustomLooping contains numbers from 1 to the total number + // of bin in zBinEdges + for (size_t i = 1; i != m_cfg.gridConfig.zBinEdges.size(); i++) { + if (std::find(m_cfg.seedFinderConfig.zBinsCustomLooping.begin(), + m_cfg.seedFinderConfig.zBinsCustomLooping.end(), + i) == m_cfg.seedFinderConfig.zBinsCustomLooping.end()) { + throw std::invalid_argument( + "Inconsistent config zBinsCustomLooping does not contain the same " + "bins as zBinEdges"); + } + } + } + m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); } diff --git a/Examples/Python/src/TrackFinding.cpp b/Examples/Python/src/TrackFinding.cpp index 7cd0a443b97..b6edc7e4978 100644 --- a/Examples/Python/src/TrackFinding.cpp +++ b/Examples/Python/src/TrackFinding.cpp @@ -109,6 +109,7 @@ void addTrackFinding(Context& ctx) { ACTS_PYTHON_MEMBER(enableCutsForSortedSP); ACTS_PYTHON_MEMBER(interactionPointCut); ACTS_PYTHON_MEMBER(zBinEdges); + ACTS_PYTHON_MEMBER(zBinsCustomLooping); ACTS_PYTHON_MEMBER(rRangeMiddleSP); ACTS_PYTHON_MEMBER(useVariableMiddleSPRange); ACTS_PYTHON_MEMBER(deltaRMiddleSPRange);