From 9aff3d6ee0725f705c70235c325aed4e69aa7b00 Mon Sep 17 00:00:00 2001 From: cvarni Date: Thu, 17 Feb 2022 16:51:35 -0800 Subject: [PATCH 001/120] Config for ITk --- .../include/Acts/Geometry/CylinderVolumeBuilder.hpp | 13 ++++++++++--- .../Run/Reconstruction/Common/SeedingExample.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp b/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp index ae00326ae2d..a7a424870ce 100644 --- a/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp +++ b/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp @@ -260,6 +260,11 @@ struct WrappingConfig { } } + static const Logger& logger() { + static std::unique_ptr logger = getDefaultLogger("WrappingConfig", Logging::INFO); + return *logger; + } + /// wrap, insert, attach void wrapInsertAttach() { // action is only needed if an existing volume @@ -362,9 +367,11 @@ struct WrappingConfig { existingVolumeConfig.rMin < containerVolumeConfig.rMax)) { // The volumes are overlapping this shouldn't be happening return an // error - throw std::invalid_argument( - "Volumes are overlapping, this shouldn't be happening. Please " - "check your geometry building."); + ACTS_WARNING( + "Volumes are overlapping, this shouldn't be happening. Please " + "check your geometry building." + << "\nexistingVolumeConfig, r = " << existingVolumeConfig.rMin << " - " << existingVolumeConfig.rMax + << "\ncontainerVolumeConfig, r = " << containerVolumeConfig.rMin << " - " << containerVolumeConfig.rMax); } // check if gaps are needed diff --git a/Examples/Run/Reconstruction/Common/SeedingExample.cpp b/Examples/Run/Reconstruction/Common/SeedingExample.cpp index 0ac3914a7fb..30b9bb2db32 100644 --- a/Examples/Run/Reconstruction/Common/SeedingExample.cpp +++ b/Examples/Run/Reconstruction/Common/SeedingExample.cpp @@ -121,7 +121,7 @@ int runSeedingExample( }; seedingCfg.outputSeeds = "seeds"; seedingCfg.outputProtoTracks = "prototracks"; - seedingCfg.gridConfig.rMax = 200._mm; + seedingCfg.gridConfig.rMax = 320._mm; seedingCfg.seedFinderConfig.rMax = seedingCfg.gridConfig.rMax; seedingCfg.seedFilterConfig.deltaRMin = 1_mm; @@ -131,7 +131,7 @@ int runSeedingExample( seedingCfg.seedFinderConfig.deltaRMinBottomSP = seedingCfg.seedFilterConfig.deltaRMin; - seedingCfg.gridConfig.deltaRMax = 60._mm; + seedingCfg.gridConfig.deltaRMax = 100._mm; seedingCfg.seedFinderConfig.deltaRMax = seedingCfg.gridConfig.deltaRMax; seedingCfg.seedFinderConfig.deltaRMaxTopSP = seedingCfg.gridConfig.deltaRMax; seedingCfg.seedFinderConfig.deltaRMaxBottomSP = @@ -140,8 +140,8 @@ int runSeedingExample( seedingCfg.seedFinderConfig.collisionRegionMin = -250_mm; seedingCfg.seedFinderConfig.collisionRegionMax = 250._mm; - seedingCfg.gridConfig.zMin = -2000._mm; - seedingCfg.gridConfig.zMax = 2000._mm; + seedingCfg.gridConfig.zMin = -3000._mm; + seedingCfg.gridConfig.zMax = 3000._mm; seedingCfg.seedFinderConfig.zMin = seedingCfg.gridConfig.zMin; seedingCfg.seedFinderConfig.zMax = seedingCfg.gridConfig.zMax; @@ -149,7 +149,7 @@ int runSeedingExample( seedingCfg.seedFinderConfig.maxSeedsPerSpM = seedingCfg.seedFilterConfig.maxSeedsPerSpM; - seedingCfg.gridConfig.cotThetaMax = 7.40627; // 2.7 eta + seedingCfg.gridConfig.cotThetaMax = 27.3; //7.40627; // 2.7 eta seedingCfg.seedFinderConfig.cotThetaMax = seedingCfg.gridConfig.cotThetaMax; seedingCfg.seedFinderConfig.sigmaScattering = 5; From 9552ebc696282eebcc61c8c668a3984caa7aadd5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 21 Nov 2023 21:57:41 +0100 Subject: [PATCH 002/120] First implementation --- Core/include/Acts/Utilities/GridIterator.hpp | 128 +++++++++ Core/include/Acts/Utilities/GridIterator.ipp | 259 +++++++++++++++++++ 2 files changed, 387 insertions(+) create mode 100644 Core/include/Acts/Utilities/GridIterator.hpp create mode 100644 Core/include/Acts/Utilities/GridIterator.ipp diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp new file mode 100644 index 00000000000..14249846ac8 --- /dev/null +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -0,0 +1,128 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/Holders.hpp" + +#include + +namespace Acts { + + // Using Global iterator, including over/under flow bins + template + class GridGlobalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridGlobalIterator(Acts::Grid&& grid, + std::size_t idx) = delete; + GridGlobalIterator(const Acts::Grid& grid, + std::size_t idx = 0ul); + + GridGlobalIterator(const GridGlobalIterator& other) = default; + GridGlobalIterator& operator=(const GridGlobalIterator& other) = default; + + GridGlobalIterator(GridGlobalIterator&& other) noexcept; + GridGlobalIterator& operator=(GridGlobalIterator&& other) noexcept; + + ~GridGlobalIterator() = default; + + bool operator==(const GridGlobalIterator& other) const; + bool operator!=(const GridGlobalIterator& other) const; + + bool operator<(const GridGlobalIterator& other) const; + bool operator>(const GridGlobalIterator& other) const; + bool operator<=(const GridGlobalIterator& other) const; + bool operator>=(const GridGlobalIterator& other) const; + + GridGlobalIterator& operator+=(const std::size_t offset); + GridGlobalIterator& operator-=(const std::size_t offset); + GridGlobalIterator operator+(const std::size_t offset) const; + GridGlobalIterator operator-(const std::size_t offset) const; + + difference_type operator-(const GridIterator& other) const; + const value_type& operator*() const; + + GridGlobalIterator& operator++(); + GridGlobalIterator operator++(int); + + private: + Acts::detail::RefHolder> m_grid {nullptr}; + std::size_t m_idx {0ul}; + }; + + + // Using Local iterator, excluding over/under flow bins + // Can also allow for custom navigation pattern along axes + template + class GridLocalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridLocalIterator(Acts::Grid&& grid, + std::array indexes) = delete; + GridLocalIterator(Acts::Grid&& grid, + std::array indexes, + std::array, DIM> navigation) = delete; + GridLocalIterator(const Acts::Grid& grid, + std::array indexes); + GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation); + + GridLocalIterator(const GridLocalIterator& other) = default; + GridLocalIterator& operator=(const GridLocalIterator& other) = default; + + GridLocalIterator(GridLocalIterator&& other) noexcept; + GridLocalIterator& operator=(GridLocalIterator&& other) noexcept; + + ~GridLocalIterator() = default; + + bool operator==(const Acts::GridLocalIterator& other) const; + bool operator!=(const Acts::GridLocalIterator& other) const; + + bool operator<(const Acts::GridLocalIterator& other) const; + bool operator>(const Acts::GridLocalIterator& other) const; + bool operator<=(const Acts::GridLocalIterator& other) const; + bool operator>=(const Acts::GridLocalIterator& other) const; + + difference_type operator-(const GridLocalIterator& other) const; + + const value_type& operator*() const; + + GridLocalIterator& operator++(); + GridLocalIterator operator++(int); + + private: + template + void increment(); + + private: + Acts::detail::RefHolder> m_grid {nullptr}; + std::array m_numLocalBins {}; + std::array m_currentIndex {}; + std::array, DIM> m_navigationIndex {}; + }; + +} // namespace Acts + +#include "Acts/Utilities/GridIterator.ipp" diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp new file mode 100644 index 00000000000..ca03adc28b4 --- /dev/null +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -0,0 +1,259 @@ +// -*- C++ -*- +// This file is part of the Acts project. +// +// Copyright (C) 2016-2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +namespace Acts { + // Global Iterator + template + GridGlobalIterator::GridGlobalIterator(const Acts::Grid& grid, + std::size_t idx) + : m_grid( &grid ), + m_idx( idx ) + {} + + template + GridGlobalIterator::GridGlobalIterator(GridGlobalIterator&& other) noexcept + : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), + m_idx( other.m_idx ) + {} + + template + GridGlobalIterator& + GridGlobalIterator::operator=(GridGlobalIterator&& other) noexcept + { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_idx = other.m_idx; + return *this; + } + + template + bool GridGlobalIterator::operator==(const GridGlobalIterator& other) const + { + return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; + } + + template + bool GridGlobalIterator::operator!=(const GridGlobalIterator& other) const + { + return !(*this == other); + } + + template + bool GridGlobalIterator::operator<(const GridGlobalIterator& other) const + { return m_idx < other.m_idx; } + + template + bool GridGlobalIterator::operator>(const GridGlobalIterator& other) const + { return m_idx > other.m_idx; } + + template + bool GridGlobalIterator::operator<=(const GridGlobalIterator& other) const + { return !(*this > other); } + + template + bool GridGlobalIterator::operator>=(const GridGlobalIterator& other) const + { return !(*this < other); } + + template + GridGlobalIterator& + GridGlobalIterator::operator+=(const std::size_t offset) + { + m_idx += offset; + return *this; + } + + template + GridGlobalIterator& + GridGlobalIterator::operator-=(const std::size_t offset) + { + m_idx -= offset; + return *this; + } + + template + GridGlobalIterator + GridGlobalIterator::operator+(const std::size_t offset) const + { + return {m_grid.ptr, m_idx + offset}; + } + + template + GridGlobalIterator + GridGlobalIterator::operator-(const std::size_t offset) const + { + return {m_grid.ptr, m_idx - offset}; + } + + template + typename GridGlobalIterator::difference_type + GridGlobalIterator::operator-(const GridIterator& other) const { + assert(other > *this); + return other.m_idx - m_idx; + } + + template + const typename GridGlobalIterator::value_type& + GridGlobalIterator::operator*() const + { + return m_grid->at(m_idx); + } + + template + GridGlobalIterator& + GridGlobalIterator::operator++() { + ++m_idx; + return *this; + } + + template + GridGlobalIterator + GridGlobalIterator::operator++(int) { + GridGlobalIterator output(m_grid, m_idx++); + return output; + } + + + + + + + // Local Iterator + template + Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, + std::array indexes) + : m_grid( &grid ), + m_numLocalBins( std::move(grid.numLocalBins()) ), + m_currentIndex( std::move(indexes) ) + { + for (std::size_t i(0); i + Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation) + : m_grid( &grid ), + m_numLocalBins( std::move(grid.numLocalBins()) ), + m_currentIndex( std::move(indexes) ), + m_navigationIndex( std::move(navigation) ) + { + // check navigation consistency + for (std::size_t i(0); i + Acts::GridLocalIterator::GridLocalIterator(Acts::GridLocalIterator&& other) noexcept + : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), + m_numLocalBins( std::move(other.m_numLocalBins) ), + m_currentIndex( std::move(other.m_currentIndex) ), + m_navigationIndex( std::move(other.m_navigationIndex) ) + {} + + template + Acts::GridLocalIterator& + Acts::GridLocalIterator::operator=(Acts::GridLocalIterator&& other) noexcept + { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_numLocalBins = std::move(other.m_numLocalBins); + m_currentIndex = std::move(other.m_currentIndex); + m_navigationIndex = std::move(other.m_navigationIndex); + return *this; + } + + template + bool Acts::GridLocalIterator::operator==(const Acts::GridLocalIterator& other) const + { + if (m_grid.ptr != other.m_grid.ptr) { + return false; + } + + for (std::size_t i(0); i + bool Acts::GridLocalIterator::operator!=(const Acts::GridLocalIterator& other) const + { return ! (*this == other); } + + template + bool Acts::GridLocalIterator::operator<(const GridLocalIterator& other) const + { return m_grid.globalBinFromLocalBins(m_currentIndex) < other.m_grid.globalBinFromLocalBins(m_currentIndex); } + + template + bool Acts::GridLocalIterator::operator>(const GridLocalIterator& other) const + { return m_grid.globalBinFromLocalBins(m_currentIndex) > other.m_grid.globalBinFromLocalBins(m_currentIndex); } + + template + bool Acts::GridLocalIterator::operator<=(const GridLocalIterator& other) const + { return ! (*this > other); } + + template + bool Acts::GridLocalIterator::operator>=(const GridLocalIterator& other) const + { return ! (*this < other); } + + template + typename Acts::GridLocalIterator::difference_type + Acts::GridLocalIterator::operator-(const Acts::GridLocalIterator& other) const + { return other.m_grid->globalBinFromLocalBins(m_currentIndex) - m_grid->globalBinFromLocalBins(m_currentIndex); } + + template + const typename Acts::GridLocalIterator::value_type& + Acts::GridLocalIterator::operator*() const + { + std::array localPositionBin; + for (std::size_t i(0); iatLocalBins(localPositionBin); + } + + template + GridLocalIterator& + GridLocalIterator::operator++() + { + increment(); + return *this; + } + + template + GridLocalIterator + GridLocalIterator::operator++(int) + { + GridLocalIterator output(m_grid.ptr, m_currentIndex); + this->operator++(); + return output; + } + + template + template + void GridLocalIterator::increment() { + if (++m_currentIndex[N] < m_numLocalBins[N]) return; + m_currentIndex[N] = 0; + if constexpr (N != 0) { + increment(); + } else { + m_currentIndex = m_numLocalBins; + } + } + +} // namespace Acts + From ae0724cb40e3e7ac6dfadaa51a9cedfaaf6dab19 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 22 Nov 2023 09:31:51 +0100 Subject: [PATCH 003/120] changes --- CMakeLists.txt | 4 +- .../Acts/Seeding/FutureBinnedSPGroup.hpp | 140 +++++++++++ .../Acts/Seeding/FutureBinnedSPGroup.ipp | 223 ++++++++++++++++++ Core/include/Acts/Utilities/Grid.hpp | 35 ++- Core/include/Acts/Utilities/GridIterator.hpp | 5 +- Core/include/Acts/Utilities/GridIterator.ipp | 21 +- .../TrackFinding/src/SeedingAlgorithm.cpp | 60 ++++- 7 files changed, 478 insertions(+), 10 deletions(-) create mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp create mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp diff --git a/CMakeLists.txt b/CMakeLists.txt index 946452b2bd3..9c420b5e705 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,14 @@ option(ACTS_BUILD_FATRAS_GEANT4 "Build Geant4 Fatras package" OFF) # alignment related options option(ACTS_BUILD_ALIGNMENT "Build Alignment package" OFF) # examples related options -option(ACTS_BUILD_EXAMPLES "Build standalone examples" OFF) +option(ACTS_BUILD_EXAMPLES "Build standalone examples" ON) option(ACTS_BUILD_EXAMPLES_DD4HEP "Build DD4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EDM4HEP "Build EDM4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EXATRKX "Build the Exa.TrkX example code" OFF) option(ACTS_BUILD_EXAMPLES_GEANT4 "Build Geant4-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_HEPMC3 "Build HepMC3-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_PYTHIA8 "Build Pythia8-based code in the examples" OFF) -option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" OFF) +option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" ON) option(ACTS_BUILD_EXAMPLES_BINARIES "Build the examples binaries (deprecated)" OFF) option(ACTS_USE_SYSTEM_PYBIND11 "Use a system installation of pybind11" ${ACTS_USE_SYSTEM_LIBS} ) option(ACTS_USE_EXAMPLES_TBB "Use Threading Building Blocks library in the examples" ON) diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp new file mode 100644 index 00000000000..7c6d7f63147 --- /dev/null +++ b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp @@ -0,0 +1,140 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/Extent.hpp" +#include "Acts/Seeding/BinFinder.hpp" +#include "Acts/Seeding/InternalSeed.hpp" +#include "Acts/Seeding/Seed.hpp" +#include "Acts/Seeding/SeedFinderConfig.hpp" +#include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/Holders.hpp" + +#include +#include + +#include + +namespace Acts::future { +template +class BinnedSPGroup; + +/// @c BinnedSPGroupIterator Allows to iterate over all groups of bins +/// a provided BinFinder can generate for each bin of a provided SPGrid + +/// SpacePointGrid is a very specific structure. +/// We know it is 2D and what it contains +/// No need to be too general with this class +template +class BinnedSPGroupIterator { + private: + enum INDEX : int { PHI = 0, Z = 1 }; + +public: + // Never take ownerships + BinnedSPGroupIterator(BinnedSPGroup&& group, + std::array index, + std::array, 2> navigation) = delete; + BinnedSPGroupIterator(BinnedSPGroup& group, + std::array index, + std::array, 2> navigation); + + BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; + BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; + + BinnedSPGroupIterator(BinnedSPGroupIterator&&) noexcept = default; + BinnedSPGroupIterator& operator=(BinnedSPGroupIterator&&) noexcept = default; + + ~BinnedSPGroupIterator() = default; + + BinnedSPGroupIterator& operator++(); + + bool operator==(const BinnedSPGroupIterator& other) const; + bool operator!=(const BinnedSPGroupIterator& other) const; + + std::tuple, std::size_t, + boost::container::small_vector> + operator*() const; + + private: + void findNotEmptyBin(); + + private: + // The group, it contains the grid and the bin finders + Acts::detail::RefHolder> m_group; + // Current grid iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + // End iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; +}; + +/// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator +/// for given BinFinders and SpacePointGrid. +/// Fulfills the range_expression interface. +template +class BinnedSPGroup { +#ifndef DOXYGEN + friend BinnedSPGroupIterator; +#endif + + enum INDEX : int { PHI = 0, Z = 1 }; + + public: + BinnedSPGroup() = delete; + + template + BinnedSPGroup( + spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + std::shared_ptr> + botBinFinder, + std::shared_ptr> tBinFinder, + std::unique_ptr> grid, + Acts::Extent& rRangeSPExtent, + const SeedFinderConfig& _config, + const SeedFinderOptions& _options); + + BinnedSPGroup(const BinnedSPGroup&) = delete; + BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; + + BinnedSPGroup(BinnedSPGroup&&) noexcept = default; + BinnedSPGroup& operator=(BinnedSPGroup&&) noexcept = default; + + ~BinnedSPGroup() = default; + + std::size_t size() const; + + BinnedSPGroupIterator begin(); + BinnedSPGroupIterator end(); + + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } + + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } + + private: + // grid with ownership of all InternalSpacePoint + std::unique_ptr> m_grid {nullptr}; + + // BinFinder must return std::vector with content of + // each bin sorted in r (ascending) + std::shared_ptr> m_topBinFinder {nullptr}; + std::shared_ptr> m_bottomBinFinder {nullptr}; + + // Order of z bins to loop over when searching for SPs + std::array, 2> m_bins {}; + // Number of Z bins to skip the search for middle SP + std::size_t m_skipZMiddleBin {0ul}; +}; + +} // namespace Acts +#include "Acts/Seeding/FutureBinnedSPGroup.ipp" diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp new file mode 100644 index 00000000000..7968ec14963 --- /dev/null +++ b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp @@ -0,0 +1,223 @@ +// -*- C++ -*- +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Binned SP Group Iterator + +#include + +template +Acts::future::BinnedSPGroupIterator::BinnedSPGroupIterator( + Acts::future::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) + : m_group(group), + m_gridItr(*group.m_grid.get(), std::move(index), navigation), + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) +{ + findNotEmptyBin(); +} + +template +inline Acts::future::BinnedSPGroupIterator& +Acts::future::BinnedSPGroupIterator::operator++() { + ++m_gridItr; + findNotEmptyBin(); + return *this; +} + +template +inline bool Acts::future::BinnedSPGroupIterator::operator==( + const Acts::future::BinnedSPGroupIterator& other) const { + return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; +} + +template +inline bool Acts::future::BinnedSPGroupIterator::operator!=( + const Acts::future::BinnedSPGroupIterator& other) const { + return !(*this == other); +} + +template +std::tuple, std::size_t, + boost::container::small_vector> +Acts::future::BinnedSPGroupIterator::operator*() const { + // Global Index + std::array localPosition = m_gridItr.localPosition(); + std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); + + boost::container::small_vector bottoms = + m_group->m_bottomBinFinder->findBins( + localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); + boost::container::small_vector tops = + m_group->m_topBinFinder->findBins( + localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); + + // GCC12+ in Release throws an overread warning here due to the move. + // This is from inside boost code, so best we can do is to suppress it. +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overread" +#endif + return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic pop +#endif +} + +template +inline void +Acts::future::BinnedSPGroupIterator::findNotEmptyBin() { + if (m_gridItr == m_gridItrEnd) return; + // Iterate on the grid till we find a not-empty bin + // We start from the current bin configuration and move forward + std::size_t dimCollection = (*m_gridItr).size(); + while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + dimCollection = (*m_gridItr).size(); + } +} + +// Binned SP Group +template +template +Acts::future::BinnedSPGroup::BinnedSPGroup( + spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + std::shared_ptr> botBinFinder, + std::shared_ptr> tBinFinder, + std::unique_ptr> grid, + Acts::Extent& rRangeSPExtent, + const SeedFinderConfig& config, + const SeedFinderOptions& options) { + if (!config.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); + } + if (!options.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); + } + static_assert( + std::is_same< + typename std::iterator_traits::value_type, + const external_spacepoint_t*>::value, + "Iterator does not contain type this class was templated with"); + + // get region of interest (or full detector if configured accordingly) + float phiMin = config.phiMin; + float phiMax = config.phiMax; + float zMin = config.zMin; + float zMax = config.zMax; + + // sort by radius + // add magnitude of beamPos to rMax to avoid excluding measurements + // create number of bins equal to number of millimeters rMax + // (worst case minR: configured minR + 1mm) + // binSizeR allows to increase or reduce numRBins if needed + std::size_t numRBins = static_cast( + (config.rMax + options.beamPos.norm()) / config.binSizeR); + + // keep track of changed bins while sorting + boost::container::flat_set rBinsIndex; + + std::size_t counter = 0; + for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { + if (*it == nullptr) { + continue; + } + const external_spacepoint_t& sp = **it; + const auto& [spPosition, variance] = + toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); + + float spX = spPosition[0]; + float spY = spPosition[1]; + float spZ = spPosition[2]; + + // store x,y,z values in extent + rRangeSPExtent.extend({spX, spY, spZ}); + + // remove SPs outside z and phi region + if (spZ > zMax || spZ < zMin) { + continue; + } + float spPhi = std::atan2(spY, spX); + if (spPhi > phiMax || spPhi < phiMin) { + continue; + } + + auto isp = std::make_unique>( + counter, sp, spPosition, options.beamPos, variance); + // calculate r-Bin index and protect against overflow (underflow not + // possible) + std::size_t rIndex = + static_cast(isp->radius() / config.binSizeR); + // if index out of bounds, the SP is outside the region of interest + if (rIndex >= numRBins) { + continue; + } + + // fill rbins into grid + Acts::Vector2 spLocation(isp->phi(), isp->z()); + std::vector>>& + rbin = grid->atPosition(spLocation); + rbin.push_back(std::move(isp)); + + // keep track of the bins we modify so that we can later sort the SPs in + // those bins only + if (rbin.size() > 1) { + rBinsIndex.insert(grid->globalBinFromPosition(spLocation)); + } + } + + // sort SPs in R for each filled (z, phi) bin + for (auto& binIndex : rBinsIndex) { + std::vector>>& + rbin = grid->atPosition(binIndex); + std::sort( + rbin.begin(), rbin.end(), + [](std::unique_ptr>& a, + std::unique_ptr>& b) { + return a->radius() < b->radius(); + }); + } + + m_grid = std::move(grid); + m_bottomBinFinder = botBinFinder; + m_topBinFinder = tBinFinder; + + m_skipZMiddleBin = config.skipZMiddleBinSearch; + m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); + m_bins[INDEX::Z] = config.zBinsCustomLooping; + if (m_bins[INDEX::Z].empty()) { + std::size_t nZbins = m_grid->numLocalBins()[1]; + m_bins[INDEX::Z].resize(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); + } +} + +template +inline std::size_t Acts::future::BinnedSPGroup::size() const { + return m_grid->size(); +} + +template +inline Acts::future::BinnedSPGroupIterator +Acts::future::BinnedSPGroup::begin() { + return {*this, {0ul, 0ul}, m_bins}; +} + +template +inline Acts::future::BinnedSPGroupIterator +Acts::future::BinnedSPGroup::end() { + return {*this, m_grid->numLocalBins(), m_bins}; +} diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index f4b1671a077..193c5b74c94 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -20,6 +20,14 @@ #include #include +namespace Acts { + template + class GridGlobalIterator; + + template + class GridLocalIterator; +} + namespace Acts { /// @brief class for describing a regular multi-dimensional grid @@ -48,7 +56,11 @@ class Grid final { using point_t = std::array; /// index type using local bin indices along each axis using index_t = std::array; - + /// global iterator type + using global_iterator_t = Acts::GridGlobalIterator; + /// local iterator type + using local_iterator_t = Acts::GridLocalIterator; + /// @brief default constructor /// /// @param [in] axes actual axis objects spanning the grid @@ -457,6 +469,27 @@ class Grid final { return detail::grid_helper::getAxes(m_axes); } + + global_iterator_t begin() const { + return global_iterator_t(*this, 0); + } + + global_iterator_t end() const { + return global_iterator_t(*this, size()); + } + + local_iterator_t begin(const std::array, DIM>& navigator) const { + std::array localBin; + for (std::size_t i(0); i, DIM>& navigator) const { + return local_iterator_t(*this, numLocalBins(), navigator); + } + private: /// set of axis defining the multi-dimensional grid std::tuple m_axes; diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 14249846ac8..a4cf195730e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -53,7 +53,7 @@ namespace Acts { GridGlobalIterator operator+(const std::size_t offset) const; GridGlobalIterator operator-(const std::size_t offset) const; - difference_type operator-(const GridIterator& other) const; + difference_type operator-(const GridGlobalIterator& other) const; const value_type& operator*() const; GridGlobalIterator& operator++(); @@ -111,6 +111,8 @@ namespace Acts { GridLocalIterator& operator++(); GridLocalIterator operator++(int); + + std::array localPosition() const; private: template @@ -120,6 +122,7 @@ namespace Acts { Acts::detail::RefHolder> m_grid {nullptr}; std::array m_numLocalBins {}; std::array m_currentIndex {}; + std::array m_localPosition {}; std::array, DIM> m_navigationIndex {}; }; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index ca03adc28b4..9ade6910cfe 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -93,7 +93,7 @@ namespace Acts { template typename GridGlobalIterator::difference_type - GridGlobalIterator::operator-(const GridIterator& other) const { + GridGlobalIterator::operator-(const GridGlobalIterator& other) const { assert(other > *this); return other.m_idx - m_idx; } @@ -134,7 +134,8 @@ namespace Acts { { for (std::size_t i(0); i @@ -171,6 +174,7 @@ namespace Acts { m_numLocalBins = std::move(other.m_numLocalBins); m_currentIndex = std::move(other.m_currentIndex); m_navigationIndex = std::move(other.m_navigationIndex); + m_localPosition = std::move(other.m_localPosition); return *this; } @@ -255,5 +259,16 @@ namespace Acts { } } + template + std::array::DIM> + GridLocalIterator::localPosition() const + { + std::array output; + for (std::size_t i(0); i #include @@ -29,6 +32,7 @@ #include #include #include +#include namespace ActsExamples { struct AlgorithmContext; @@ -252,11 +256,19 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( auto grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); + auto futureGrid = Acts::SpacePointGridCreator::createGrid( + m_cfg.gridConfig, m_cfg.gridOptions); + auto spacePointsGrouping = Acts::BinnedSPGroup( spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, m_bottomBinFinder, m_topBinFinder, std::move(grid), rRangeSPExtent, m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); + auto futureSpacePointsGrouping = Acts::future::BinnedSPGroup( + spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, + m_bottomBinFinder, m_topBinFinder, std::move(futureGrid), rRangeSPExtent, + m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); + // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); @@ -303,15 +315,57 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( } } + std::size_t counter = 0ul; + + auto start_nominal = std::chrono::high_resolution_clock::now(); for (const auto [bottom, middle, top] : spacePointsGrouping) { - m_seedFinder.createSeedsForGroup( - m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), - std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); + // m_seedFinder.createSeedsForGroup( + // m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), + // std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); + // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; } + auto stop_nominal = std::chrono::high_resolution_clock::now(); + + counter = 0ul; + auto start_modified = std::chrono::high_resolution_clock::now(); + for (const auto [bottom, middle, top] : futureSpacePointsGrouping) { + // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; + } + auto stop_modified = std::chrono::high_resolution_clock::now(); + + auto duration_nominal = std::chrono::duration_cast(stop_nominal - start_nominal).count(); + auto duration_modified = std::chrono::duration_cast(stop_modified - start_modified).count(); + std::cout << "Nominal: " << duration_nominal << std::endl; + std::cout << "Modified: " << duration_modified << std::endl; + ACTS_DEBUG("Created " << seeds.size() << " track seeds from " << spacePointPtrs.size() << " space points"); + + + + // * ----------------------- + /* + std::cout << "Making iterator for grid" << std::endl; + std::array, 2> navigation; + navigation[0].resize(spacePointsGrouping.grid().numLocalBins()[0]); + for (std::size_t i(0); i Date: Thu, 23 Nov 2023 14:10:29 +0100 Subject: [PATCH 004/120] no future --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 28 ++- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 100 +++----- .../Acts/Seeding/FutureBinnedSPGroup.hpp | 140 ----------- .../Acts/Seeding/FutureBinnedSPGroup.ipp | 223 ------------------ 4 files changed, 48 insertions(+), 443 deletions(-) delete mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp delete mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index b04135c202f..816af19a09a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -36,12 +36,14 @@ class BinnedSPGroupIterator { private: enum INDEX : int { PHI = 0, Z = 1 }; - public: +public: // Never take ownerships BinnedSPGroupIterator(BinnedSPGroup&& group, - std::size_t) = delete; + std::array index, + std::array, 2> navigation) = delete; BinnedSPGroupIterator(BinnedSPGroup& group, - std::size_t index); + std::array index, + std::array, 2> navigation); BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; @@ -66,10 +68,10 @@ class BinnedSPGroupIterator { private: // The group, it contains the grid and the bin finders Acts::detail::RefHolder> m_group; - // Max Local Bins - limits of the grid - std::array m_max_localBins; - // Current Local Bins - std::array m_current_localBins{0, 0}; + // Current grid iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + // End iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator @@ -81,6 +83,8 @@ class BinnedSPGroup { friend BinnedSPGroupIterator; #endif + enum INDEX : int { PHI = 0, Z = 1 }; + public: BinnedSPGroup() = delete; @@ -119,17 +123,17 @@ class BinnedSPGroup { private: // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid; + std::unique_ptr> m_grid {nullptr}; // BinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder; - std::shared_ptr> m_bottomBinFinder; + std::shared_ptr> m_topBinFinder {nullptr}; + std::shared_ptr> m_bottomBinFinder {nullptr}; // Order of z bins to loop over when searching for SPs - std::vector m_bins; + std::array, 2> m_bins {}; // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin; + std::size_t m_skipZMiddleBin {0ul}; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 0f10a0b3483..36362744b5c 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -12,45 +13,33 @@ template Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::BinnedSPGroup& group, std::size_t index) - : m_group(group), m_max_localBins(m_group->m_grid->numLocalBins()) { - m_max_localBins[INDEX::PHI] += 1; - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); - if (index == m_group->m_grid->size()) { - m_current_localBins = m_max_localBins; - } else { - // Go to the next not-empty bin - findNotEmptyBin(); - } + Acts::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) + : m_group(group), + m_gridItr(*group.m_grid.get(), std::move(index), navigation), + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) +{ + findNotEmptyBin(); } template inline Acts::BinnedSPGroupIterator& Acts::BinnedSPGroupIterator::operator++() { - // Increase the position by one - // if we were on the edge, go up one phi bin and reset z bin - if (++m_current_localBins[INDEX::Z] == m_max_localBins[INDEX::Z]) { - ++m_current_localBins[INDEX::PHI]; - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); - } - - // Get the next not-empty bin in the grid + ++m_gridItr; findNotEmptyBin(); return *this; } template inline bool Acts::BinnedSPGroupIterator::operator==( - const Acts::BinnedSPGroupIterator& other) const { - return m_group.ptr == other.m_group.ptr && - m_current_localBins[INDEX::PHI] == - other.m_current_localBins[INDEX::PHI] && - m_current_localBins[INDEX::Z] == other.m_current_localBins[INDEX::Z]; + const Acts::BinnedSPGroupIterator& other) const { + return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } template inline bool Acts::BinnedSPGroupIterator::operator!=( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return !(*this == other); } @@ -59,19 +48,18 @@ std::tuple, std::size_t, boost::container::small_vector> Acts::BinnedSPGroupIterator::operator*() const { // Global Index - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins( - {m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]]}); - + std::array localPosition = m_gridItr.localPosition(); + std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); + boost::container::small_vector bottoms = m_group->m_bottomBinFinder->findBins( - m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]], + localPosition[INDEX::PHI], + localPosition[INDEX::Z], m_group->m_grid.get()); boost::container::small_vector tops = m_group->m_topBinFinder->findBins( - m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]], + localPosition[INDEX::PHI], + localPosition[INDEX::Z], m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. @@ -89,37 +77,13 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { + if (m_gridItr == m_gridItrEnd) return; // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward - - for (std::size_t phiBin(m_current_localBins[INDEX::PHI]); - phiBin < m_max_localBins[INDEX::PHI]; ++phiBin) { - // 0 is the underflow - skip - if (phiBin == 0) { - continue; - } - - for (std::size_t zBin(m_current_localBins[INDEX::Z]); - zBin < m_max_localBins[INDEX::Z]; ++zBin) { - std::size_t zBinIndex = m_group->m_bins[zBin]; - std::size_t index = - m_group->m_grid->globalBinFromLocalBins({phiBin, zBinIndex}); - // Check if there are entries in this bin - if (m_group->m_grid->at(index).empty()) { - continue; - } - - // Set the new current bins - m_current_localBins[INDEX::PHI] = phiBin; - m_current_localBins[INDEX::Z] = zBin; - return; - } - // Reset z-index - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); + std::size_t dimCollection = (*m_gridItr).size(); + while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + dimCollection = (*m_gridItr).size(); } - - // Could find nothing ... setting this to end() - m_current_localBins = m_max_localBins; } // Binned SP Group @@ -231,13 +195,13 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_topBinFinder = tBinFinder; m_skipZMiddleBin = config.skipZMiddleBinSearch; - m_bins = config.zBinsCustomLooping; - if (m_bins.empty()) { + m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); + m_bins[INDEX::Z] = config.zBinsCustomLooping; + if (m_bins[INDEX::Z].empty()) { std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins.reserve(nZbins); - for (std::size_t i(0); i < nZbins; ++i) { - m_bins.push_back(i + 1); - } + m_bins[INDEX::Z].resize(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); } } @@ -249,11 +213,11 @@ inline std::size_t Acts::BinnedSPGroup::size() const { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::begin() { - return {*this, 0}; + return {*this, {0ul, 0ul}, m_bins}; } template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - return {*this, m_grid->size()}; + return {*this, m_grid->numLocalBins(), m_bins}; } diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp deleted file mode 100644 index 7c6d7f63147..00000000000 --- a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp +++ /dev/null @@ -1,140 +0,0 @@ -// This file is part of the Acts project. -// -// Copyright (C) 2023 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinFinder.hpp" -#include "Acts/Seeding/InternalSeed.hpp" -#include "Acts/Seeding/Seed.hpp" -#include "Acts/Seeding/SeedFinderConfig.hpp" -#include "Acts/Seeding/SpacePointGrid.hpp" -#include "Acts/Utilities/Holders.hpp" - -#include -#include - -#include - -namespace Acts::future { -template -class BinnedSPGroup; - -/// @c BinnedSPGroupIterator Allows to iterate over all groups of bins -/// a provided BinFinder can generate for each bin of a provided SPGrid - -/// SpacePointGrid is a very specific structure. -/// We know it is 2D and what it contains -/// No need to be too general with this class -template -class BinnedSPGroupIterator { - private: - enum INDEX : int { PHI = 0, Z = 1 }; - -public: - // Never take ownerships - BinnedSPGroupIterator(BinnedSPGroup&& group, - std::array index, - std::array, 2> navigation) = delete; - BinnedSPGroupIterator(BinnedSPGroup& group, - std::array index, - std::array, 2> navigation); - - BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; - BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; - - BinnedSPGroupIterator(BinnedSPGroupIterator&&) noexcept = default; - BinnedSPGroupIterator& operator=(BinnedSPGroupIterator&&) noexcept = default; - - ~BinnedSPGroupIterator() = default; - - BinnedSPGroupIterator& operator++(); - - bool operator==(const BinnedSPGroupIterator& other) const; - bool operator!=(const BinnedSPGroupIterator& other) const; - - std::tuple, std::size_t, - boost::container::small_vector> - operator*() const; - - private: - void findNotEmptyBin(); - - private: - // The group, it contains the grid and the bin finders - Acts::detail::RefHolder> m_group; - // Current grid iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItr; - // End iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; -}; - -/// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator -/// for given BinFinders and SpacePointGrid. -/// Fulfills the range_expression interface. -template -class BinnedSPGroup { -#ifndef DOXYGEN - friend BinnedSPGroupIterator; -#endif - - enum INDEX : int { PHI = 0, Z = 1 }; - - public: - BinnedSPGroup() = delete; - - template - BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> - botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& _config, - const SeedFinderOptions& _options); - - BinnedSPGroup(const BinnedSPGroup&) = delete; - BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; - - BinnedSPGroup(BinnedSPGroup&&) noexcept = default; - BinnedSPGroup& operator=(BinnedSPGroup&&) noexcept = default; - - ~BinnedSPGroup() = default; - - std::size_t size() const; - - BinnedSPGroupIterator begin(); - BinnedSPGroupIterator end(); - - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } - - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } - - private: - // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid {nullptr}; - - // BinFinder must return std::vector with content of - // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder {nullptr}; - std::shared_ptr> m_bottomBinFinder {nullptr}; - - // Order of z bins to loop over when searching for SPs - std::array, 2> m_bins {}; - // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin {0ul}; -}; - -} // namespace Acts -#include "Acts/Seeding/FutureBinnedSPGroup.ipp" diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp deleted file mode 100644 index 7968ec14963..00000000000 --- a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp +++ /dev/null @@ -1,223 +0,0 @@ -// -*- C++ -*- -// This file is part of the Acts project. -// -// Copyright (C) 2023 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// Binned SP Group Iterator - -#include - -template -Acts::future::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::future::BinnedSPGroup& group, - std::array index, - std::array, 2> navigation) - : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) -{ - findNotEmptyBin(); -} - -template -inline Acts::future::BinnedSPGroupIterator& -Acts::future::BinnedSPGroupIterator::operator++() { - ++m_gridItr; - findNotEmptyBin(); - return *this; -} - -template -inline bool Acts::future::BinnedSPGroupIterator::operator==( - const Acts::future::BinnedSPGroupIterator& other) const { - return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; -} - -template -inline bool Acts::future::BinnedSPGroupIterator::operator!=( - const Acts::future::BinnedSPGroupIterator& other) const { - return !(*this == other); -} - -template -std::tuple, std::size_t, - boost::container::small_vector> -Acts::future::BinnedSPGroupIterator::operator*() const { - // Global Index - std::array localPosition = m_gridItr.localPosition(); - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); - - boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); - boost::container::small_vector tops = - m_group->m_topBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); - - // GCC12+ in Release throws an overread warning here due to the move. - // This is from inside boost code, so best we can do is to suppress it. -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overread" -#endif - return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic pop -#endif -} - -template -inline void -Acts::future::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) return; - // Iterate on the grid till we find a not-empty bin - // We start from the current bin configuration and move forward - std::size_t dimCollection = (*m_gridItr).size(); - while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { - dimCollection = (*m_gridItr).size(); - } -} - -// Binned SP Group -template -template -Acts::future::BinnedSPGroup::BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& config, - const SeedFinderOptions& options) { - if (!config.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); - } - if (!options.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); - } - static_assert( - std::is_same< - typename std::iterator_traits::value_type, - const external_spacepoint_t*>::value, - "Iterator does not contain type this class was templated with"); - - // get region of interest (or full detector if configured accordingly) - float phiMin = config.phiMin; - float phiMax = config.phiMax; - float zMin = config.zMin; - float zMax = config.zMax; - - // sort by radius - // add magnitude of beamPos to rMax to avoid excluding measurements - // create number of bins equal to number of millimeters rMax - // (worst case minR: configured minR + 1mm) - // binSizeR allows to increase or reduce numRBins if needed - std::size_t numRBins = static_cast( - (config.rMax + options.beamPos.norm()) / config.binSizeR); - - // keep track of changed bins while sorting - boost::container::flat_set rBinsIndex; - - std::size_t counter = 0; - for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { - if (*it == nullptr) { - continue; - } - const external_spacepoint_t& sp = **it; - const auto& [spPosition, variance] = - toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); - - float spX = spPosition[0]; - float spY = spPosition[1]; - float spZ = spPosition[2]; - - // store x,y,z values in extent - rRangeSPExtent.extend({spX, spY, spZ}); - - // remove SPs outside z and phi region - if (spZ > zMax || spZ < zMin) { - continue; - } - float spPhi = std::atan2(spY, spX); - if (spPhi > phiMax || spPhi < phiMin) { - continue; - } - - auto isp = std::make_unique>( - counter, sp, spPosition, options.beamPos, variance); - // calculate r-Bin index and protect against overflow (underflow not - // possible) - std::size_t rIndex = - static_cast(isp->radius() / config.binSizeR); - // if index out of bounds, the SP is outside the region of interest - if (rIndex >= numRBins) { - continue; - } - - // fill rbins into grid - Acts::Vector2 spLocation(isp->phi(), isp->z()); - std::vector>>& - rbin = grid->atPosition(spLocation); - rbin.push_back(std::move(isp)); - - // keep track of the bins we modify so that we can later sort the SPs in - // those bins only - if (rbin.size() > 1) { - rBinsIndex.insert(grid->globalBinFromPosition(spLocation)); - } - } - - // sort SPs in R for each filled (z, phi) bin - for (auto& binIndex : rBinsIndex) { - std::vector>>& - rbin = grid->atPosition(binIndex); - std::sort( - rbin.begin(), rbin.end(), - [](std::unique_ptr>& a, - std::unique_ptr>& b) { - return a->radius() < b->radius(); - }); - } - - m_grid = std::move(grid); - m_bottomBinFinder = botBinFinder; - m_topBinFinder = tBinFinder; - - m_skipZMiddleBin = config.skipZMiddleBinSearch; - m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); - std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); - m_bins[INDEX::Z] = config.zBinsCustomLooping; - if (m_bins[INDEX::Z].empty()) { - std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins[INDEX::Z].resize(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); - } -} - -template -inline std::size_t Acts::future::BinnedSPGroup::size() const { - return m_grid->size(); -} - -template -inline Acts::future::BinnedSPGroupIterator -Acts::future::BinnedSPGroup::begin() { - return {*this, {0ul, 0ul}, m_bins}; -} - -template -inline Acts::future::BinnedSPGroupIterator -Acts::future::BinnedSPGroup::end() { - return {*this, m_grid->numLocalBins(), m_bins}; -} From 501f16cc83ca0071abc7344e089eb63776e3a2c1 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 23 Nov 2023 14:29:35 +0100 Subject: [PATCH 005/120] minor --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 1 + .../TrackFinding/src/SeedingAlgorithm.cpp | 60 +------------------ 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 816af19a09a..3f12619a03e 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -14,6 +14,7 @@ #include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" #include diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index f64dcaa9690..348f2ecd427 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -13,7 +13,6 @@ #include "Acts/Geometry/Extent.hpp" #include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" -#include "Acts/Seeding/FutureBinnedSPGroup.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Utilities/BinningType.hpp" @@ -22,8 +21,6 @@ #include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Range1D.hpp" #include "ActsExamples/EventData/SimSeed.hpp" -#include "Acts/Utilities/GridIterator.hpp" -#include "Acts/Seeding/InternalSpacePoint.hpp" #include #include @@ -32,7 +29,6 @@ #include #include #include -#include namespace ActsExamples { struct AlgorithmContext; @@ -256,19 +252,11 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( auto grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); - auto futureGrid = Acts::SpacePointGridCreator::createGrid( - m_cfg.gridConfig, m_cfg.gridOptions); - auto spacePointsGrouping = Acts::BinnedSPGroup( spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, m_bottomBinFinder, m_topBinFinder, std::move(grid), rRangeSPExtent, m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); - auto futureSpacePointsGrouping = Acts::future::BinnedSPGroup( - spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, - m_bottomBinFinder, m_topBinFinder, std::move(futureGrid), rRangeSPExtent, - m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); - // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); @@ -315,57 +303,15 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( } } - std::size_t counter = 0ul; - - auto start_nominal = std::chrono::high_resolution_clock::now(); for (const auto [bottom, middle, top] : spacePointsGrouping) { - // m_seedFinder.createSeedsForGroup( - // m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), - // std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); - // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; + m_seedFinder.createSeedsForGroup( + m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), + std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); } - auto stop_nominal = std::chrono::high_resolution_clock::now(); - - counter = 0ul; - auto start_modified = std::chrono::high_resolution_clock::now(); - for (const auto [bottom, middle, top] : futureSpacePointsGrouping) { - // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; - } - auto stop_modified = std::chrono::high_resolution_clock::now(); - - auto duration_nominal = std::chrono::duration_cast(stop_nominal - start_nominal).count(); - auto duration_modified = std::chrono::duration_cast(stop_modified - start_modified).count(); - std::cout << "Nominal: " << duration_nominal << std::endl; - std::cout << "Modified: " << duration_modified << std::endl; - ACTS_DEBUG("Created " << seeds.size() << " track seeds from " << spacePointPtrs.size() << " space points"); - - - - // * ----------------------- - /* - std::cout << "Making iterator for grid" << std::endl; - std::array, 2> navigation; - navigation[0].resize(spacePointsGrouping.grid().numLocalBins()[0]); - for (std::size_t i(0); i Date: Thu, 23 Nov 2023 14:31:29 +0100 Subject: [PATCH 006/120] format --- CMakeLists.txt | 4 +- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 35 +- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 38 +- Core/include/Acts/Utilities/Grid.hpp | 35 +- Core/include/Acts/Utilities/GridIterator.hpp | 225 ++++----- Core/include/Acts/Utilities/GridIterator.ipp | 489 ++++++++++--------- 6 files changed, 413 insertions(+), 413 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c420b5e705..946452b2bd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,14 @@ option(ACTS_BUILD_FATRAS_GEANT4 "Build Geant4 Fatras package" OFF) # alignment related options option(ACTS_BUILD_ALIGNMENT "Build Alignment package" OFF) # examples related options -option(ACTS_BUILD_EXAMPLES "Build standalone examples" ON) +option(ACTS_BUILD_EXAMPLES "Build standalone examples" OFF) option(ACTS_BUILD_EXAMPLES_DD4HEP "Build DD4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EDM4HEP "Build EDM4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EXATRKX "Build the Exa.TrkX example code" OFF) option(ACTS_BUILD_EXAMPLES_GEANT4 "Build Geant4-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_HEPMC3 "Build HepMC3-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_PYTHIA8 "Build Pythia8-based code in the examples" OFF) -option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" ON) +option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" OFF) option(ACTS_BUILD_EXAMPLES_BINARIES "Build the examples binaries (deprecated)" OFF) option(ACTS_USE_SYSTEM_PYBIND11 "Use a system installation of pybind11" ${ACTS_USE_SYSTEM_LIBS} ) option(ACTS_USE_EXAMPLES_TBB "Use Threading Building Blocks library in the examples" ON) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3f12619a03e..3c183c0835d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -37,14 +37,15 @@ class BinnedSPGroupIterator { private: enum INDEX : int { PHI = 0, Z = 1 }; -public: + public: // Never take ownerships BinnedSPGroupIterator(BinnedSPGroup&& group, std::array index, - std::array, 2> navigation) = delete; + std::array, 2> navigation) = + delete; BinnedSPGroupIterator(BinnedSPGroup& group, std::array index, - std::array, 2> navigation); + std::array, 2> navigation); BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; @@ -70,9 +71,11 @@ class BinnedSPGroupIterator { // The group, it contains the grid and the bin finders Acts::detail::RefHolder> m_group; // Current grid iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + typename Acts::SpacePointGrid::local_iterator_t + m_gridItr; // End iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; + typename Acts::SpacePointGrid::local_iterator_t + m_gridItrEnd; }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator @@ -85,7 +88,7 @@ class BinnedSPGroup { #endif enum INDEX : int { PHI = 0, Z = 1 }; - + public: BinnedSPGroup() = delete; @@ -114,27 +117,25 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } + Acts::SpacePointGrid& grid() { return *m_grid.get(); } - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } + std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } private: // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid {nullptr}; + std::unique_ptr> m_grid{nullptr}; // BinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder {nullptr}; - std::shared_ptr> m_bottomBinFinder {nullptr}; + std::shared_ptr> m_topBinFinder{ + nullptr}; + std::shared_ptr> m_bottomBinFinder{ + nullptr}; // Order of z bins to loop over when searching for SPs - std::array, 2> m_bins {}; + std::array, 2> m_bins{}; // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin {0ul}; + std::size_t m_skipZMiddleBin{0ul}; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 36362744b5c..85c60ca74a9 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -13,14 +13,14 @@ template Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::BinnedSPGroup& group, - std::array index, - std::array, 2> navigation) + Acts::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) : m_group(group), m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) -{ - findNotEmptyBin(); + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), + std::move(navigation)) { + findNotEmptyBin(); } template @@ -33,13 +33,13 @@ Acts::BinnedSPGroupIterator::operator++() { template inline bool Acts::BinnedSPGroupIterator::operator==( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } template inline bool Acts::BinnedSPGroupIterator::operator!=( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return !(*this == other); } @@ -49,18 +49,17 @@ std::tuple, std::size_t, Acts::BinnedSPGroupIterator::operator*() const { // Global Index std::array localPosition = m_gridItr.localPosition(); - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); - + std::size_t global_index = + m_group->m_grid->globalBinFromLocalBins(localPosition); + boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); + m_group->m_bottomBinFinder->findBins(localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); boost::container::small_vector tops = - m_group->m_topBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); + m_group->m_topBinFinder->findBins(localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. @@ -77,7 +76,8 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) return; + if (m_gridItr == m_gridItrEnd) + return; // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward std::size_t dimCollection = (*m_gridItr).size(); diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 193c5b74c94..cf6e1d39952 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -21,12 +21,12 @@ #include namespace Acts { - template - class GridGlobalIterator; +template +class GridGlobalIterator; - template - class GridLocalIterator; -} +template +class GridLocalIterator; +} // namespace Acts namespace Acts { @@ -57,10 +57,10 @@ class Grid final { /// index type using local bin indices along each axis using index_t = std::array; /// global iterator type - using global_iterator_t = Acts::GridGlobalIterator; + using global_iterator_t = Acts::GridGlobalIterator; /// local iterator type - using local_iterator_t = Acts::GridLocalIterator; - + using local_iterator_t = Acts::GridLocalIterator; + /// @brief default constructor /// /// @param [in] axes actual axis objects spanning the grid @@ -469,27 +469,24 @@ class Grid final { return detail::grid_helper::getAxes(m_axes); } - - global_iterator_t begin() const { - return global_iterator_t(*this, 0); - } + global_iterator_t begin() const { return global_iterator_t(*this, 0); } - global_iterator_t end() const { - return global_iterator_t(*this, size()); - } + global_iterator_t end() const { return global_iterator_t(*this, size()); } - local_iterator_t begin(const std::array, DIM>& navigator) const { + local_iterator_t begin( + const std::array, DIM>& navigator) const { std::array localBin; - for (std::size_t i(0); i, DIM>& navigator) const { + local_iterator_t end( + const std::array, DIM>& navigator) const { return local_iterator_t(*this, numLocalBins(), navigator); } - + private: /// set of axis defining the multi-dimensional grid std::tuple m_axes; diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index a4cf195730e..4bc33755e3e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -15,117 +15,118 @@ namespace Acts { - // Using Global iterator, including over/under flow bins - template - class GridGlobalIterator { - public: - static constexpr std::size_t DIM = sizeof...(Axes); - - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - GridGlobalIterator(Acts::Grid&& grid, - std::size_t idx) = delete; - GridGlobalIterator(const Acts::Grid& grid, - std::size_t idx = 0ul); - - GridGlobalIterator(const GridGlobalIterator& other) = default; - GridGlobalIterator& operator=(const GridGlobalIterator& other) = default; - - GridGlobalIterator(GridGlobalIterator&& other) noexcept; - GridGlobalIterator& operator=(GridGlobalIterator&& other) noexcept; - - ~GridGlobalIterator() = default; - - bool operator==(const GridGlobalIterator& other) const; - bool operator!=(const GridGlobalIterator& other) const; - - bool operator<(const GridGlobalIterator& other) const; - bool operator>(const GridGlobalIterator& other) const; - bool operator<=(const GridGlobalIterator& other) const; - bool operator>=(const GridGlobalIterator& other) const; - - GridGlobalIterator& operator+=(const std::size_t offset); - GridGlobalIterator& operator-=(const std::size_t offset); - GridGlobalIterator operator+(const std::size_t offset) const; - GridGlobalIterator operator-(const std::size_t offset) const; - - difference_type operator-(const GridGlobalIterator& other) const; - const value_type& operator*() const; - - GridGlobalIterator& operator++(); - GridGlobalIterator operator++(int); - - private: - Acts::detail::RefHolder> m_grid {nullptr}; - std::size_t m_idx {0ul}; - }; - - - // Using Local iterator, excluding over/under flow bins - // Can also allow for custom navigation pattern along axes - template - class GridLocalIterator { - public: - static constexpr std::size_t DIM = sizeof...(Axes); - - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - GridLocalIterator(Acts::Grid&& grid, - std::array indexes) = delete; - GridLocalIterator(Acts::Grid&& grid, - std::array indexes, - std::array, DIM> navigation) = delete; - GridLocalIterator(const Acts::Grid& grid, - std::array indexes); - GridLocalIterator(const Acts::Grid& grid, - std::array indexes, - std::array, DIM> navigation); - - GridLocalIterator(const GridLocalIterator& other) = default; - GridLocalIterator& operator=(const GridLocalIterator& other) = default; - - GridLocalIterator(GridLocalIterator&& other) noexcept; - GridLocalIterator& operator=(GridLocalIterator&& other) noexcept; - - ~GridLocalIterator() = default; - - bool operator==(const Acts::GridLocalIterator& other) const; - bool operator!=(const Acts::GridLocalIterator& other) const; - - bool operator<(const Acts::GridLocalIterator& other) const; - bool operator>(const Acts::GridLocalIterator& other) const; - bool operator<=(const Acts::GridLocalIterator& other) const; - bool operator>=(const Acts::GridLocalIterator& other) const; - - difference_type operator-(const GridLocalIterator& other) const; - - const value_type& operator*() const; - - GridLocalIterator& operator++(); - GridLocalIterator operator++(int); - - std::array localPosition() const; - - private: - template - void increment(); - - private: - Acts::detail::RefHolder> m_grid {nullptr}; - std::array m_numLocalBins {}; - std::array m_currentIndex {}; - std::array m_localPosition {}; - std::array, DIM> m_navigationIndex {}; - }; - -} // namespace Acts +// Using Global iterator, including over/under flow bins +template +class GridGlobalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridGlobalIterator(Acts::Grid&& grid, std::size_t idx) = delete; + GridGlobalIterator(const Acts::Grid& grid, std::size_t idx = 0ul); + + GridGlobalIterator(const GridGlobalIterator& other) = default; + GridGlobalIterator& operator=( + const GridGlobalIterator& other) = default; + + GridGlobalIterator(GridGlobalIterator&& other) noexcept; + GridGlobalIterator& operator=( + GridGlobalIterator&& other) noexcept; + + ~GridGlobalIterator() = default; + + bool operator==(const GridGlobalIterator& other) const; + bool operator!=(const GridGlobalIterator& other) const; + + bool operator<(const GridGlobalIterator& other) const; + bool operator>(const GridGlobalIterator& other) const; + bool operator<=(const GridGlobalIterator& other) const; + bool operator>=(const GridGlobalIterator& other) const; + + GridGlobalIterator& operator+=(const std::size_t offset); + GridGlobalIterator& operator-=(const std::size_t offset); + GridGlobalIterator operator+(const std::size_t offset) const; + GridGlobalIterator operator-(const std::size_t offset) const; + + difference_type operator-(const GridGlobalIterator& other) const; + const value_type& operator*() const; + + GridGlobalIterator& operator++(); + GridGlobalIterator operator++(int); + + private: + Acts::detail::RefHolder> m_grid{nullptr}; + std::size_t m_idx{0ul}; +}; + +// Using Local iterator, excluding over/under flow bins +// Can also allow for custom navigation pattern along axes +template +class GridLocalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridLocalIterator(Acts::Grid&& grid, + std::array indexes) = delete; + GridLocalIterator( + Acts::Grid&& grid, std::array indexes, + std::array, DIM> navigation) = delete; + GridLocalIterator(const Acts::Grid& grid, + std::array indexes); + GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation); + + GridLocalIterator(const GridLocalIterator& other) = default; + GridLocalIterator& operator=( + const GridLocalIterator& other) = default; + + GridLocalIterator(GridLocalIterator&& other) noexcept; + GridLocalIterator& operator=( + GridLocalIterator&& other) noexcept; + + ~GridLocalIterator() = default; + + bool operator==(const Acts::GridLocalIterator& other) const; + bool operator!=(const Acts::GridLocalIterator& other) const; + + bool operator<(const Acts::GridLocalIterator& other) const; + bool operator>(const Acts::GridLocalIterator& other) const; + bool operator<=(const Acts::GridLocalIterator& other) const; + bool operator>=(const Acts::GridLocalIterator& other) const; + + difference_type operator-(const GridLocalIterator& other) const; + + const value_type& operator*() const; + + GridLocalIterator& operator++(); + GridLocalIterator operator++(int); + + std::array localPosition() const; + + private: + template + void increment(); + + private: + Acts::detail::RefHolder> m_grid{nullptr}; + std::array m_numLocalBins{}; + std::array m_currentIndex{}; + std::array m_localPosition{}; + std::array, DIM> m_navigationIndex{}; +}; + +} // namespace Acts #include "Acts/Utilities/GridIterator.ipp" diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 9ade6910cfe..bc2af987498 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -10,265 +10,266 @@ #include namespace Acts { - // Global Iterator - template - GridGlobalIterator::GridGlobalIterator(const Acts::Grid& grid, - std::size_t idx) - : m_grid( &grid ), - m_idx( idx ) - {} - - template - GridGlobalIterator::GridGlobalIterator(GridGlobalIterator&& other) noexcept - : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), - m_idx( other.m_idx ) - {} - - template - GridGlobalIterator& - GridGlobalIterator::operator=(GridGlobalIterator&& other) noexcept - { - m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_idx = other.m_idx; - return *this; - } +// Global Iterator +template +GridGlobalIterator::GridGlobalIterator( + const Acts::Grid& grid, std::size_t idx) + : m_grid(&grid), m_idx(idx) {} - template - bool GridGlobalIterator::operator==(const GridGlobalIterator& other) const - { - return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; - } - - template - bool GridGlobalIterator::operator!=(const GridGlobalIterator& other) const - { - return !(*this == other); - } - - template - bool GridGlobalIterator::operator<(const GridGlobalIterator& other) const - { return m_idx < other.m_idx; } - - template - bool GridGlobalIterator::operator>(const GridGlobalIterator& other) const - { return m_idx > other.m_idx; } - - template - bool GridGlobalIterator::operator<=(const GridGlobalIterator& other) const - { return !(*this > other); } - - template - bool GridGlobalIterator::operator>=(const GridGlobalIterator& other) const - { return !(*this < other); } - - template - GridGlobalIterator& - GridGlobalIterator::operator+=(const std::size_t offset) - { - m_idx += offset; - return *this; - } - - template - GridGlobalIterator& - GridGlobalIterator::operator-=(const std::size_t offset) - { - m_idx -= offset; - return *this; - } - - template - GridGlobalIterator - GridGlobalIterator::operator+(const std::size_t offset) const - { - return {m_grid.ptr, m_idx + offset}; - } - - template - GridGlobalIterator - GridGlobalIterator::operator-(const std::size_t offset) const - { - return {m_grid.ptr, m_idx - offset}; - } - - template - typename GridGlobalIterator::difference_type - GridGlobalIterator::operator-(const GridGlobalIterator& other) const { - assert(other > *this); - return other.m_idx - m_idx; - } - - template - const typename GridGlobalIterator::value_type& - GridGlobalIterator::operator*() const - { - return m_grid->at(m_idx); - } - - template - GridGlobalIterator& - GridGlobalIterator::operator++() { - ++m_idx; - return *this; - } +template +GridGlobalIterator::GridGlobalIterator( + GridGlobalIterator&& other) noexcept + : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_idx(other.m_idx) {} - template - GridGlobalIterator - GridGlobalIterator::operator++(int) { - GridGlobalIterator output(m_grid, m_idx++); - return output; - } - - - - - - - // Local Iterator - template - Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, - std::array indexes) - : m_grid( &grid ), - m_numLocalBins( std::move(grid.numLocalBins()) ), - m_currentIndex( std::move(indexes) ) - { - for (std::size_t i(0); i +GridGlobalIterator& GridGlobalIterator::operator=( + GridGlobalIterator&& other) noexcept { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_idx = other.m_idx; + return *this; +} + +template +bool GridGlobalIterator::operator==( + const GridGlobalIterator& other) const { + return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; +} + +template +bool GridGlobalIterator::operator!=( + const GridGlobalIterator& other) const { + return !(*this == other); +} + +template +bool GridGlobalIterator::operator<( + const GridGlobalIterator& other) const { + return m_idx < other.m_idx; +} + +template +bool GridGlobalIterator::operator>( + const GridGlobalIterator& other) const { + return m_idx > other.m_idx; +} + +template +bool GridGlobalIterator::operator<=( + const GridGlobalIterator& other) const { + return !(*this > other); +} + +template +bool GridGlobalIterator::operator>=( + const GridGlobalIterator& other) const { + return !(*this < other); +} + +template +GridGlobalIterator& GridGlobalIterator::operator+=( + const std::size_t offset) { + m_idx += offset; + return *this; +} + +template +GridGlobalIterator& GridGlobalIterator::operator-=( + const std::size_t offset) { + m_idx -= offset; + return *this; +} + +template +GridGlobalIterator GridGlobalIterator::operator+( + const std::size_t offset) const { + return {m_grid.ptr, m_idx + offset}; +} + +template +GridGlobalIterator GridGlobalIterator::operator-( + const std::size_t offset) const { + return {m_grid.ptr, m_idx - offset}; +} + +template +typename GridGlobalIterator::difference_type +GridGlobalIterator::operator-( + const GridGlobalIterator& other) const { + assert(other > *this); + return other.m_idx - m_idx; +} + +template +const typename GridGlobalIterator::value_type& +GridGlobalIterator::operator*() const { + return m_grid->at(m_idx); +} + +template +GridGlobalIterator& GridGlobalIterator::operator++() { + ++m_idx; + return *this; +} + +template +GridGlobalIterator GridGlobalIterator::operator++(int) { + GridGlobalIterator output(m_grid, m_idx++); + return output; +} + +// Local Iterator +template +Acts::GridLocalIterator::GridLocalIterator( + const Acts::Grid& grid, std::array indexes) + : m_grid(&grid), + m_numLocalBins(std::move(grid.numLocalBins())), + m_currentIndex(std::move(indexes)) { + for (std::size_t i(0); i < DIM; ++i) { + m_navigationIndex[i].resize(m_numLocalBins[i]); + std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); + m_localPosition[i] = 1ul; } +} - template - Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, - std::array indexes, - std::array, DIM> navigation) - : m_grid( &grid ), - m_numLocalBins( std::move(grid.numLocalBins()) ), - m_currentIndex( std::move(indexes) ), - m_navigationIndex( std::move(navigation) ) - { - // check navigation consistency - for (std::size_t i(0); i +Acts::GridLocalIterator::GridLocalIterator( + const Acts::Grid& grid, std::array indexes, + std::array, DIM> navigation) + : m_grid(&grid), + m_numLocalBins(std::move(grid.numLocalBins())), + m_currentIndex(std::move(indexes)), + m_navigationIndex(std::move(navigation)) { + // check navigation consistency + for (std::size_t i(0); i < DIM; ++i) { + if (m_navigationIndex[i].size() != m_numLocalBins[i]) { + throw std::invalid_argument( + "Invalid navigation sequence in local grid iterator."); } + m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } - - template - Acts::GridLocalIterator::GridLocalIterator(Acts::GridLocalIterator&& other) noexcept - : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), - m_numLocalBins( std::move(other.m_numLocalBins) ), - m_currentIndex( std::move(other.m_currentIndex) ), - m_navigationIndex( std::move(other.m_navigationIndex) ), - m_localPosition( std::move(other.m_localPosition) ) - {} - - template - Acts::GridLocalIterator& - Acts::GridLocalIterator::operator=(Acts::GridLocalIterator&& other) noexcept - { - m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_numLocalBins = std::move(other.m_numLocalBins); - m_currentIndex = std::move(other.m_currentIndex); - m_navigationIndex = std::move(other.m_navigationIndex); - m_localPosition = std::move(other.m_localPosition); - return *this; +} + +template +Acts::GridLocalIterator::GridLocalIterator( + Acts::GridLocalIterator&& other) noexcept + : m_grid(std::exchange(other.m_grid.ptr, nullptr)), + m_numLocalBins(std::move(other.m_numLocalBins)), + m_currentIndex(std::move(other.m_currentIndex)), + m_navigationIndex(std::move(other.m_navigationIndex)), + m_localPosition(std::move(other.m_localPosition)) {} + +template +Acts::GridLocalIterator& +Acts::GridLocalIterator::operator=( + Acts::GridLocalIterator&& other) noexcept { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_numLocalBins = std::move(other.m_numLocalBins); + m_currentIndex = std::move(other.m_currentIndex); + m_navigationIndex = std::move(other.m_navigationIndex); + m_localPosition = std::move(other.m_localPosition); + return *this; +} + +template +bool Acts::GridLocalIterator::operator==( + const Acts::GridLocalIterator& other) const { + if (m_grid.ptr != other.m_grid.ptr) { + return false; } - - template - bool Acts::GridLocalIterator::operator==(const Acts::GridLocalIterator& other) const - { - if (m_grid.ptr != other.m_grid.ptr) { + + for (std::size_t i(0); i < DIM; ++i) { + if (m_currentIndex[i] != other.m_currentIndex[i]) { return false; } - - for (std::size_t i(0); i - bool Acts::GridLocalIterator::operator!=(const Acts::GridLocalIterator& other) const - { return ! (*this == other); } - - template - bool Acts::GridLocalIterator::operator<(const GridLocalIterator& other) const - { return m_grid.globalBinFromLocalBins(m_currentIndex) < other.m_grid.globalBinFromLocalBins(m_currentIndex); } - - template - bool Acts::GridLocalIterator::operator>(const GridLocalIterator& other) const - { return m_grid.globalBinFromLocalBins(m_currentIndex) > other.m_grid.globalBinFromLocalBins(m_currentIndex); } - - template - bool Acts::GridLocalIterator::operator<=(const GridLocalIterator& other) const - { return ! (*this > other); } - - template - bool Acts::GridLocalIterator::operator>=(const GridLocalIterator& other) const - { return ! (*this < other); } - - template - typename Acts::GridLocalIterator::difference_type - Acts::GridLocalIterator::operator-(const Acts::GridLocalIterator& other) const - { return other.m_grid->globalBinFromLocalBins(m_currentIndex) - m_grid->globalBinFromLocalBins(m_currentIndex); } - - template - const typename Acts::GridLocalIterator::value_type& - Acts::GridLocalIterator::operator*() const - { - std::array localPositionBin; - for (std::size_t i(0); iatLocalBins(localPositionBin); } - template - GridLocalIterator& - GridLocalIterator::operator++() - { - increment(); - return *this; - } + return true; +} + +template +bool Acts::GridLocalIterator::operator!=( + const Acts::GridLocalIterator& other) const { + return !(*this == other); +} + +template +bool Acts::GridLocalIterator::operator<( + const GridLocalIterator& other) const { + return m_grid.globalBinFromLocalBins(m_currentIndex) < + other.m_grid.globalBinFromLocalBins(m_currentIndex); +} + +template +bool Acts::GridLocalIterator::operator>( + const GridLocalIterator& other) const { + return m_grid.globalBinFromLocalBins(m_currentIndex) > + other.m_grid.globalBinFromLocalBins(m_currentIndex); +} + +template +bool Acts::GridLocalIterator::operator<=( + const GridLocalIterator& other) const { + return !(*this > other); +} + +template +bool Acts::GridLocalIterator::operator>=( + const GridLocalIterator& other) const { + return !(*this < other); +} - template - GridLocalIterator - GridLocalIterator::operator++(int) - { - GridLocalIterator output(m_grid.ptr, m_currentIndex); - this->operator++(); - return output; +template +typename Acts::GridLocalIterator::difference_type +Acts::GridLocalIterator::operator-( + const Acts::GridLocalIterator& other) const { + return other.m_grid->globalBinFromLocalBins(m_currentIndex) - + m_grid->globalBinFromLocalBins(m_currentIndex); +} + +template +const typename Acts::GridLocalIterator::value_type& +Acts::GridLocalIterator::operator*() const { + std::array localPositionBin; + for (std::size_t i(0); i < DIM; ++i) { + localPositionBin[i] = m_navigationIndex[i][m_currentIndex[i]]; } + return m_grid->atLocalBins(localPositionBin); +} - template - template - void GridLocalIterator::increment() { - if (++m_currentIndex[N] < m_numLocalBins[N]) return; - m_currentIndex[N] = 0; - if constexpr (N != 0) { - increment(); - } else { - m_currentIndex = m_numLocalBins; - } +template +GridLocalIterator& GridLocalIterator::operator++() { + increment(); + return *this; +} + +template +GridLocalIterator GridLocalIterator::operator++(int) { + GridLocalIterator output(m_grid.ptr, m_currentIndex); + this->operator++(); + return output; +} + +template +template +void GridLocalIterator::increment() { + if (++m_currentIndex[N] < m_numLocalBins[N]) + return; + m_currentIndex[N] = 0; + if constexpr (N != 0) { + increment(); + } else { + m_currentIndex = m_numLocalBins; } +} - template - std::array::DIM> - GridLocalIterator::localPosition() const - { - std::array output; - for (std::size_t i(0); i +std::array::DIM> +GridLocalIterator::localPosition() const { + std::array output; + for (std::size_t i(0); i < DIM; ++i) { + output[i] = m_navigationIndex[i][m_currentIndex[i]]; } - -} // namespace Acts + return output; +} +} // namespace Acts From 4326ed67f70fec23d32f9c7be1e6b6c2df65e95d Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 24 Nov 2023 15:29:42 +0100 Subject: [PATCH 007/120] first round of tests --- Core/include/Acts/Utilities/GridIterator.ipp | 2 +- Tests/UnitTests/Core/Utilities/CMakeLists.txt | 1 + .../Core/Utilities/GridIterationTests.cpp | 235 ++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 Tests/UnitTests/Core/Utilities/GridIterationTests.cpp diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index bc2af987498..6272da9a16b 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -254,8 +254,8 @@ template void GridLocalIterator::increment() { if (++m_currentIndex[N] < m_numLocalBins[N]) return; - m_currentIndex[N] = 0; if constexpr (N != 0) { + m_currentIndex[N] = 0; increment(); } else { m_currentIndex = m_numLocalBins; diff --git a/Tests/UnitTests/Core/Utilities/CMakeLists.txt b/Tests/UnitTests/Core/Utilities/CMakeLists.txt index 7e75e042034..78e9e6dcf8a 100644 --- a/Tests/UnitTests/Core/Utilities/CMakeLists.txt +++ b/Tests/UnitTests/Core/Utilities/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(ActsUnitTestBoundingBox PRIVATE std::filesystem) add_unittest(Extendable ExtendableTests.cpp) add_unittest(FiniteStateMachine FiniteStateMachineTests.cpp) add_unittest(Frustum FrustumTest.cpp) +add_unittest(GridIteration GridIterationTests.cpp) add_unittest(Grid GridTests.cpp) add_unittest(Helpers HelpersTests.cpp) add_unittest(Interpolation InterpolationTests.cpp) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp new file mode 100644 index 00000000000..761b4d28a9c --- /dev/null +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -0,0 +1,235 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridIterator.hpp" + +#include + +namespace Acts::Test { + + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + for (std::size_t i(0ul); i<2ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); + } + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + navigation[2ul].resize(nBinsZ); + for (std::size_t i(0ul); i<3ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); + } + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; + navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + +} From 558efd53a1ac2fb41702e7c7152c1984f23cdea0 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 10:45:35 +0100 Subject: [PATCH 008/120] sub iteration --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 26 +++++--- Core/include/Acts/Utilities/Grid.hpp | 6 +- Core/include/Acts/Utilities/GridIterator.hpp | 2 + Core/include/Acts/Utilities/GridIterator.ipp | 19 ++++-- .../Core/Utilities/GridIterationTests.cpp | 61 +++++++++++++++++++ 5 files changed, 97 insertions(+), 17 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 85c60ca74a9..692d61877f4 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -17,9 +16,11 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array index, std::array, 2> navigation) : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), - std::move(navigation)) { + m_gridItr(*group.m_grid.get(), std::move(index), navigation) { + std::array endline; + endline[0ul] = navigation[0ul].size(); + endline[1ul] = navigation[1ul].size(); + m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t(*group.m_grid.get(), std::move(endline), std::move(navigation)); findNotEmptyBin(); } @@ -195,13 +196,18 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_topBinFinder = tBinFinder; m_skipZMiddleBin = config.skipZMiddleBinSearch; + + // phi axis m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); - std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); - m_bins[INDEX::Z] = config.zBinsCustomLooping; - if (m_bins[INDEX::Z].empty()) { - std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins[INDEX::Z].resize(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1ul); + + // z axis + if (config.zBinsCustomLooping.empty()) { + std::size_t nZbins = m_grid->numLocalBins()[1] - m_skipZMiddleBin; + m_bins[INDEX::Z] = std::vector(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul + m_skipZMiddleBin); + } else { + m_bins[INDEX::Z] = std::vector(config.zBinsCustomLooping.begin() + m_skipZMiddleBin, config.zBinsCustomLooping.end()); } } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index cf6e1d39952..519de1774e3 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -484,7 +484,11 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { - return local_iterator_t(*this, numLocalBins(), navigator); + std::array endline; + for (std::size_t i(0ul); i&& grid, std::size_t idx) = delete; GridGlobalIterator(const Acts::Grid& grid, std::size_t idx = 0ul); @@ -77,6 +78,7 @@ class GridLocalIterator { using pointer = value_type*; using reference = value_type&; + GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, std::array indexes) = delete; GridLocalIterator( diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 6272da9a16b..61106301dae 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project @@ -139,12 +138,20 @@ Acts::GridLocalIterator::GridLocalIterator( m_numLocalBins(std::move(grid.numLocalBins())), m_currentIndex(std::move(indexes)), m_navigationIndex(std::move(navigation)) { - // check navigation consistency - for (std::size_t i(0); i < DIM; ++i) { - if (m_navigationIndex[i].size() != m_numLocalBins[i]) { - throw std::invalid_argument( - "Invalid navigation sequence in local grid iterator."); + // We can allow navigation on only a subset of bins. + // If the number of specified bins in the navigation for one axis is not + // zero then override the maximum number of navigation bins instead of using the + // total number of available bins in the axis + for (std::size_t i(0ul); i m_numLocalBins[i]) { + throw std::invalid_argument("Invalid navigation sequence in local grid iterator. Too many bins specified."); } + m_numLocalBins[i] = m_navigationIndex[i].size(); m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 761b4d28a9c..73b1c4beb19 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -232,4 +232,65 @@ namespace Acts::Test { BOOST_CHECK_EQUAL(numIterations, grid.size(false)); } + BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + const std::size_t nBinsJK = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); + Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), std::move(jAxis), std::move(kAxis)) ); + + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ * nBinsJK * nBinsJK); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul) * (nBinsJK + 2ul) * (nBinsJK + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); + BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); + + // Iterate only on a few bins + std::array, 5ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; + navigation[2ul] = {1ul, 5ul}; + navigation[3ul] = {5ul, 3ul, 2ul}; + navigation[4ul] = {2ul}; + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + + std::size_t expectedIterations = 1ul; + for (std::size_t i(0ul); i<5ul; ++i) { + expectedIterations *= navigation[i].size(); + } + + BOOST_CHECK_EQUAL(numIterations, expectedIterations); + } + } From cb8de3fab37eed63b7f071e3c118aa47d1960d75 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 10:47:51 +0100 Subject: [PATCH 009/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 11 +- Core/include/Acts/Utilities/Grid.hpp | 2 +- Core/include/Acts/Utilities/GridIterator.ipp | 16 +- .../Core/Utilities/GridIterationTests.cpp | 550 +++++++++--------- 4 files changed, 305 insertions(+), 274 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 692d61877f4..b567343a52a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -20,7 +20,9 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array endline; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); - m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t(*group.m_grid.get(), std::move(endline), std::move(navigation)); + m_gridItrEnd = + typename Acts::SpacePointGrid::local_iterator_t( + *group.m_grid.get(), std::move(endline), std::move(navigation)); findNotEmptyBin(); } @@ -205,9 +207,12 @@ Acts::BinnedSPGroup::BinnedSPGroup( if (config.zBinsCustomLooping.empty()) { std::size_t nZbins = m_grid->numLocalBins()[1] - m_skipZMiddleBin; m_bins[INDEX::Z] = std::vector(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul + m_skipZMiddleBin); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), + 1ul + m_skipZMiddleBin); } else { - m_bins[INDEX::Z] = std::vector(config.zBinsCustomLooping.begin() + m_skipZMiddleBin, config.zBinsCustomLooping.end()); + m_bins[INDEX::Z] = std::vector( + config.zBinsCustomLooping.begin() + m_skipZMiddleBin, + config.zBinsCustomLooping.end()); } } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 519de1774e3..22d9df902a6 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -485,7 +485,7 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { std::array endline; - for (std::size_t i(0ul); i::GridLocalIterator( m_navigationIndex(std::move(navigation)) { // We can allow navigation on only a subset of bins. // If the number of specified bins in the navigation for one axis is not - // zero then override the maximum number of navigation bins instead of using the - // total number of available bins in the axis - for (std::size_t i(0ul); i m_numLocalBins[i]) { - throw std::invalid_argument("Invalid navigation sequence in local grid iterator. Too many bins specified."); + throw std::invalid_argument( + "Invalid navigation sequence in local grid iterator. Too many bins " + "specified."); } - m_numLocalBins[i] = m_navigationIndex[i].size(); + m_numLocalBins[i] = m_navigationIndex[i].size(); m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 73b1c4beb19..83bd5137258 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -15,282 +15,304 @@ namespace Acts::Test { - BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins); - BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + + Acts::GridLocalIterator gridStart = + grid.begin(navigation); + Acts::GridLocalIterator gridStop = + grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + for (std::size_t i(0ul); i < 2ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); } - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins); - BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - - std::array, 1ul> navigation; - navigation[0ul].resize(nBins); - std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + navigation[2ul].resize(nBinsZ); + for (std::size_t i(0ul); i < 3ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); } - BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - - std::array, 2ul> navigation; - navigation[0ul].resize(nBins); - navigation[1ul].resize(nBins); - for (std::size_t i(0ul); i<2ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); - } - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - std::array, 3ul> navigation; - navigation[0ul].resize(nBins); - navigation[1ul].resize(nBins); - navigation[2ul].resize(nBinsZ); - for (std::size_t i(0ul); i<3ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); - } - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; + navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, + 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, + 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; + + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } - - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - std::array, 3ul> navigation; - navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; - navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; - navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + const std::size_t nBinsJK = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); + Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), + std::move(jAxis), std::move(kAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), + nBins * nBins * nBinsZ * nBinsJK * nBinsJK); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * + (nBinsZ + 2ul) * (nBinsJK + 2ul) * + (nBinsJK + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); + BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); + + // Iterate only on a few bins + std::array, 5ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; + navigation[2ul] = {1ul, 5ul}; + navigation[3ul] = {5ul, 3ul, 2ul}; + navigation[4ul] = {2ul}; + + Acts::GridLocalIterator< + double, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis> + gridStart = grid.begin(navigation); + Acts::GridLocalIterator< + double, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis> + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } - BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - const std::size_t nBinsJK = 5ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); - Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), std::move(jAxis), std::move(kAxis)) ); - - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ * nBinsJK * nBinsJK); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul) * (nBinsJK + 2ul) * (nBinsJK + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); - BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); - - // Iterate only on a few bins - std::array, 5ul> navigation; - navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; - navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; - navigation[2ul] = {1ul, 5ul}; - navigation[3ul] = {5ul, 3ul, 2ul}; - navigation[4ul] = {2ul}; - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - - std::size_t expectedIterations = 1ul; - for (std::size_t i(0ul); i<5ul; ++i) { - expectedIterations *= navigation[i].size(); - } - - BOOST_CHECK_EQUAL(numIterations, expectedIterations); + std::size_t expectedIterations = 1ul; + for (std::size_t i(0ul); i < 5ul; ++i) { + expectedIterations *= navigation[i].size(); } - + + BOOST_CHECK_EQUAL(numIterations, expectedIterations); } + +} // namespace Acts::Test From b9cf4cc02fad4fe58bd5170f61683a232a456414 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:26:22 +0100 Subject: [PATCH 010/120] changes --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 5 ++++- Core/include/Acts/Utilities/Grid.hpp | 2 +- Core/include/Acts/Utilities/GridIterator.hpp | 1 - Core/include/Acts/Utilities/GridIterator.ipp | 7 ++----- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index b567343a52a..be165a0b79d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -230,5 +230,8 @@ Acts::BinnedSPGroup::begin() { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - return {*this, m_grid->numLocalBins(), m_bins}; + std::array endline; + endline[0ul] = m_bins[0ul].size(); + endline[1ul] = m_bins[1ul].size(); + return {*this, std::move(endline), m_bins}; } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 22d9df902a6..f822441d916 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -488,7 +488,7 @@ class Grid final { for (std::size_t i(0ul); i < DIM; ++i) { endline[i] = navigator[i].size(); } - return local_iterator_t(*this, endline, navigator); + return local_iterator_t(*this, std::move(endline), navigator); } private: diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 5602bdb0d49..98e978dd47e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -125,7 +125,6 @@ class GridLocalIterator { Acts::detail::RefHolder> m_grid{nullptr}; std::array m_numLocalBins{}; std::array m_currentIndex{}; - std::array m_localPosition{}; std::array, DIM> m_navigationIndex{}; }; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 15d1ffab0ec..1542491dd8d 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -126,7 +126,6 @@ Acts::GridLocalIterator::GridLocalIterator( for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); - m_localPosition[i] = 1ul; } } @@ -156,7 +155,6 @@ Acts::GridLocalIterator::GridLocalIterator( "specified."); } m_numLocalBins[i] = m_navigationIndex[i].size(); - m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } @@ -166,8 +164,8 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_numLocalBins(std::move(other.m_numLocalBins)), m_currentIndex(std::move(other.m_currentIndex)), - m_navigationIndex(std::move(other.m_navigationIndex)), - m_localPosition(std::move(other.m_localPosition)) {} + m_navigationIndex(std::move(other.m_navigationIndex)) + {} template Acts::GridLocalIterator& @@ -177,7 +175,6 @@ Acts::GridLocalIterator::operator=( m_numLocalBins = std::move(other.m_numLocalBins); m_currentIndex = std::move(other.m_currentIndex); m_navigationIndex = std::move(other.m_navigationIndex); - m_localPosition = std::move(other.m_localPosition); return *this; } From 70c7febfbd460e7f66c72710f99394bf1912cd9b Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:28:28 +0100 Subject: [PATCH 011/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index be165a0b79d..c0fcc2f03f2 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -232,6 +232,6 @@ inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { std::array endline; endline[0ul] = m_bins[0ul].size(); - endline[1ul] = m_bins[1ul].size(); + endline[1ul] = m_bins[1ul].size(); return {*this, std::move(endline), m_bins}; } From a77b90bcb0532f62e2c507a1f63be1d2c6981265 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:28:47 +0100 Subject: [PATCH 012/120] format --- Core/include/Acts/Utilities/GridIterator.ipp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 1542491dd8d..9bf57dc321b 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -164,8 +164,7 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_numLocalBins(std::move(other.m_numLocalBins)), m_currentIndex(std::move(other.m_currentIndex)), - m_navigationIndex(std::move(other.m_navigationIndex)) - {} + m_navigationIndex(std::move(other.m_navigationIndex)) {} template Acts::GridLocalIterator& From 02bf47bd5bc5d68dcd8c18806b3cdbb2a95d7678 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:48:47 +0100 Subject: [PATCH 013/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3c183c0835d..cc10a493db7 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,9 +117,13 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { return *m_grid.get(); } + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } - std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } private: // grid with ownership of all InternalSpacePoint From b53dedd9d5a88256a03a10a682a3edda4e6d4d90 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:43:30 +0100 Subject: [PATCH 014/120] test 1 for cuda --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index f45aca17957..08185cd83a4 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -174,11 +174,18 @@ int main(int argc, char* argv[]) { // Create the result object. std::vector>> seeds_host; + std::array, 2ul> navigation; + navigation[0ul].resize(spGroup.grid().numLocalBins()[0ul]); + navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + // Perform the seed finding. if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, i); + std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; } @@ -214,7 +221,8 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, i); + std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; } From b8793b14e3b6e449a7be55022adbbfa4a05ff3aa Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:48:00 +0100 Subject: [PATCH 015/120] local, not global --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 08185cd83a4..e09384b6d5e 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) { if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; @@ -221,7 +221,7 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; From bc77b3e8779a1cd6881c065b04ed99bc30d7f0d9 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:52:30 +0100 Subject: [PATCH 016/120] agains cuda --- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index d7fd2f8d820..a76dd8792a1 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -261,8 +261,16 @@ int main(int argc, char** argv) { auto start_cpu = std::chrono::system_clock::now(); + std::array, 2ul> navigation; + navigation[0ul].resize(spGroup.grid().numLocalBins()[0ul]); + navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(skip); + int group_count; - auto groupIt = Acts::BinnedSPGroupIterator(spGroup, skip); + auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); //----------- CPU ----------// group_count = 0; @@ -298,7 +306,7 @@ int main(int argc, char** argv) { group_count = 0; std::vector>> seedVector_cuda; - groupIt = Acts::BinnedSPGroupIterator(spGroup, skip); + groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); Acts::SpacePointData spacePointData; spacePointData.resize(spVec.size()); From 0f0b59d91d7ed9da85d66eeae9d2a3388e20172c Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:54:00 +0100 Subject: [PATCH 017/120] and again format --- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 11 +++++++---- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 14 +++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index a76dd8792a1..edf77868991 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -267,10 +267,12 @@ int main(int argc, char** argv) { std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(skip); - + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(skip); + int group_count; - auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, + navigation); //----------- CPU ----------// group_count = 0; @@ -306,7 +308,8 @@ int main(int argc, char** argv) { group_count = 0; std::vector>> seedVector_cuda; - groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, + navigation); Acts::SpacePointData spacePointData; spacePointData.resize(spVec.size()); diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index e09384b6d5e..ee85f2bbdfe 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -179,13 +179,15 @@ int main(int argc, char* argv[]) { navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); - + // Perform the seed finding. if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(i); + auto spGroup_itr = + Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; } @@ -221,8 +223,10 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(i); + auto spGroup_itr = + Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; } From bf60dfd8e3fedd8d5e5037773fa2acaab09ccfb7 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 14:30:51 +0100 Subject: [PATCH 018/120] more tests for global iterator --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 15 ++--- Core/include/Acts/Utilities/Grid.hpp | 4 +- Core/include/Acts/Utilities/GridIterator.hpp | 8 +-- Core/include/Acts/Utilities/GridIterator.ipp | 34 ++++++------ .../Core/Utilities/GridIterationTests.cpp | 55 +++++++++++++++++++ 5 files changed, 86 insertions(+), 30 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index c0fcc2f03f2..e9dcf22d311 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -16,13 +16,13 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array index, std::array, 2> navigation) : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation) { - std::array endline; + m_gridItr(*group.m_grid.get(), index, navigation) { + std::array endline{}; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t( - *group.m_grid.get(), std::move(endline), std::move(navigation)); + *group.m_grid.get(), endline, std::move(navigation)); findNotEmptyBin(); } @@ -79,12 +79,13 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) + if (m_gridItr == m_gridItrEnd) { return; + } // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward std::size_t dimCollection = (*m_gridItr).size(); - while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + while (dimCollection == 0ul && ++m_gridItr != m_gridItrEnd) { dimCollection = (*m_gridItr).size(); } } @@ -230,8 +231,8 @@ Acts::BinnedSPGroup::begin() { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - std::array endline; + std::array endline{}; endline[0ul] = m_bins[0ul].size(); endline[1ul] = m_bins[1ul].size(); - return {*this, std::move(endline), m_bins}; + return {*this, endline, m_bins}; } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index f822441d916..04c6007447f 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -475,7 +475,7 @@ class Grid final { local_iterator_t begin( const std::array, DIM>& navigator) const { - std::array localBin; + std::array localBin{}; for (std::size_t i(0); i < DIM; ++i) { localBin[i] = 0ul; } @@ -484,7 +484,7 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { - std::array endline; + std::array endline{}; for (std::size_t i(0ul); i < DIM; ++i) { endline[i] = navigator[i].size(); } diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 98e978dd47e..4c2ef74c34f 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -80,14 +80,14 @@ class GridLocalIterator { GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, - std::array indexes) = delete; + const std::array& indexes) = delete; GridLocalIterator( - Acts::Grid&& grid, std::array indexes, + Acts::Grid&& grid, const std::array& indexes, std::array, DIM> navigation) = delete; GridLocalIterator(const Acts::Grid& grid, - std::array indexes); + const std::array& indexes); GridLocalIterator(const Acts::Grid& grid, - std::array indexes, + const std::array& indexes, std::array, DIM> navigation); GridLocalIterator(const GridLocalIterator& other) = default; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 9bf57dc321b..c37d18298d0 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -81,13 +81,13 @@ GridGlobalIterator& GridGlobalIterator::operator-=( template GridGlobalIterator GridGlobalIterator::operator+( const std::size_t offset) const { - return {m_grid.ptr, m_idx + offset}; + return {*m_grid, m_idx + offset}; } template GridGlobalIterator GridGlobalIterator::operator-( const std::size_t offset) const { - return {m_grid.ptr, m_idx - offset}; + return {*m_grid, m_idx - offset}; } template @@ -95,7 +95,7 @@ typename GridGlobalIterator::difference_type GridGlobalIterator::operator-( const GridGlobalIterator& other) const { assert(other > *this); - return other.m_idx - m_idx; + return m_idx - other.m_idx; } template @@ -112,17 +112,17 @@ GridGlobalIterator& GridGlobalIterator::operator++() { template GridGlobalIterator GridGlobalIterator::operator++(int) { - GridGlobalIterator output(m_grid, m_idx++); + GridGlobalIterator output(*m_grid, m_idx++); return output; } // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, std::array indexes) + const Acts::Grid& grid, const std::array& indexes) : m_grid(&grid), - m_numLocalBins(std::move(grid.numLocalBins())), - m_currentIndex(std::move(indexes)) { + m_numLocalBins(grid.numLocalBins()), + m_currentIndex(indexes) { for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); @@ -131,11 +131,11 @@ Acts::GridLocalIterator::GridLocalIterator( template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, std::array indexes, + const Acts::Grid& grid, const std::array& indexes, std::array, DIM> navigation) : m_grid(&grid), - m_numLocalBins(std::move(grid.numLocalBins())), - m_currentIndex(std::move(indexes)), + m_numLocalBins(grid.numLocalBins()), + m_currentIndex(indexes), m_navigationIndex(std::move(navigation)) { // We can allow navigation on only a subset of bins. // If the number of specified bins in the navigation for one axis is not @@ -162,8 +162,8 @@ template Acts::GridLocalIterator::GridLocalIterator( Acts::GridLocalIterator&& other) noexcept : m_grid(std::exchange(other.m_grid.ptr, nullptr)), - m_numLocalBins(std::move(other.m_numLocalBins)), - m_currentIndex(std::move(other.m_currentIndex)), + m_numLocalBins(other.m_numLocalBins), + m_currentIndex(other.m_currentIndex), m_navigationIndex(std::move(other.m_navigationIndex)) {} template @@ -171,8 +171,8 @@ Acts::GridLocalIterator& Acts::GridLocalIterator::operator=( Acts::GridLocalIterator&& other) noexcept { m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_numLocalBins = std::move(other.m_numLocalBins); - m_currentIndex = std::move(other.m_currentIndex); + m_numLocalBins = other.m_numLocalBins; + m_currentIndex = other.m_currentIndex; m_navigationIndex = std::move(other.m_navigationIndex); return *this; } @@ -229,8 +229,8 @@ template typename Acts::GridLocalIterator::difference_type Acts::GridLocalIterator::operator-( const Acts::GridLocalIterator& other) const { - return other.m_grid->globalBinFromLocalBins(m_currentIndex) - - m_grid->globalBinFromLocalBins(m_currentIndex); + return m_grid->globalBinFromLocalBins(m_currentIndex) - + other.m_grid->globalBinFromLocalBins(m_currentIndex); } template @@ -272,7 +272,7 @@ void GridLocalIterator::increment() { template std::array::DIM> GridLocalIterator::localPosition() const { - std::array output; + std::array output{}; for (std::size_t i(0); i < DIM; ++i) { output[i] = m_navigationIndex[i][m_currentIndex[i]]; } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 83bd5137258..9d3896e8a06 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -15,6 +15,61 @@ namespace Acts::Test { +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + BOOST_CHECK_EQUAL(gridStart < gridStop, true); + BOOST_CHECK_EQUAL(gridStart <= gridStop, true); + BOOST_CHECK_EQUAL(gridStart > gridStop, false); + BOOST_CHECK_EQUAL(gridStart >= gridStop, false); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 2ul); + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 2ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + + itr = gridStart + std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); + BOOST_CHECK_EQUAL(itr == gridStop, true); + + itr = gridStart - 1ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 1ul); + + gridStart += std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); + BOOST_CHECK_EQUAL(gridStart == gridStop, true); + + gridStart -= 3ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridGlobalIterator gridDefault; + Acts::GridGlobalIterator gridDummy(grid, 0ul); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); From e074e16077e244c58c8727a6662ad5b7e3de419d Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 16:20:46 +0100 Subject: [PATCH 019/120] more tests and some bug fixing --- Core/include/Acts/Utilities/GridIterator.hpp | 9 +- Core/include/Acts/Utilities/GridIterator.ipp | 37 +----- .../Core/Utilities/GridIterationTests.cpp | 106 +++++++++++++++++- 3 files changed, 106 insertions(+), 46 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 4c2ef74c34f..001d460049e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -72,7 +72,7 @@ class GridLocalIterator { public: static constexpr std::size_t DIM = sizeof...(Axes); - using iterator_category = std::random_access_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using value_type = T; using difference_type = std::ptrdiff_t; using pointer = value_type*; @@ -103,13 +103,6 @@ class GridLocalIterator { bool operator==(const Acts::GridLocalIterator& other) const; bool operator!=(const Acts::GridLocalIterator& other) const; - bool operator<(const Acts::GridLocalIterator& other) const; - bool operator>(const Acts::GridLocalIterator& other) const; - bool operator<=(const Acts::GridLocalIterator& other) const; - bool operator>=(const Acts::GridLocalIterator& other) const; - - difference_type operator-(const GridLocalIterator& other) const; - const value_type& operator*() const; GridLocalIterator& operator++(); diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index c37d18298d0..7bf7b98956a 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project @@ -199,40 +200,6 @@ bool Acts::GridLocalIterator::operator!=( return !(*this == other); } -template -bool Acts::GridLocalIterator::operator<( - const GridLocalIterator& other) const { - return m_grid.globalBinFromLocalBins(m_currentIndex) < - other.m_grid.globalBinFromLocalBins(m_currentIndex); -} - -template -bool Acts::GridLocalIterator::operator>( - const GridLocalIterator& other) const { - return m_grid.globalBinFromLocalBins(m_currentIndex) > - other.m_grid.globalBinFromLocalBins(m_currentIndex); -} - -template -bool Acts::GridLocalIterator::operator<=( - const GridLocalIterator& other) const { - return !(*this > other); -} - -template -bool Acts::GridLocalIterator::operator>=( - const GridLocalIterator& other) const { - return !(*this < other); -} - -template -typename Acts::GridLocalIterator::difference_type -Acts::GridLocalIterator::operator-( - const Acts::GridLocalIterator& other) const { - return m_grid->globalBinFromLocalBins(m_currentIndex) - - other.m_grid->globalBinFromLocalBins(m_currentIndex); -} - template const typename Acts::GridLocalIterator::value_type& Acts::GridLocalIterator::operator*() const { @@ -251,7 +218,7 @@ GridLocalIterator& GridLocalIterator::operator++() { template GridLocalIterator GridLocalIterator::operator++(int) { - GridLocalIterator output(m_grid.ptr, m_currentIndex); + GridLocalIterator output(*this); this->operator++(); return output; } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 9d3896e8a06..ff2c3824c81 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -70,6 +70,63 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid grid( + std::make_tuple(std::move(xAxis), std::move(yAxis))); + + BOOST_CHECK_EQUAL(grid.size(true), (nBinsX + 2ul) * (nBinsY + 2ul)); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + BOOST_CHECK_EQUAL(gridStart < gridStop, true); + BOOST_CHECK_EQUAL(gridStart <= gridStop, true); + BOOST_CHECK_EQUAL(gridStart > gridStop, false); + BOOST_CHECK_EQUAL(gridStart >= gridStop, false); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true)); + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true)); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + + itr = gridStart + std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); + BOOST_CHECK_EQUAL(itr == gridStop, true); + + itr = gridStart - 1ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true) - 1ul); + + gridStart += std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); + BOOST_CHECK_EQUAL(gridStart == gridStop, true); + + gridStart -= 3ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridGlobalIterator gridDefault; + Acts::GridGlobalIterator gridDummy(grid, 0ul); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -159,6 +216,49 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { BOOST_CHECK_EQUAL(numIterations, grid.size(true)); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + + // Constructor without navigation + Acts::GridLocalIterator gridIterNoNav(grid, {0ul}); + // Constructor(s) with navigation + Acts::GridLocalIterator gridStart(grid, {0ul}, navigation); + + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); + BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); + + Acts::GridLocalIterator gridStop(grid, {nBins}, std::move(navigation)); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false)); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 2ul); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridLocalIterator gridDefault; + Acts::GridLocalIterator gridDummy(grid, {0ul}); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -174,7 +274,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { std::array, 1ul> navigation; navigation[0ul].resize(nBins); - std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); Acts::GridLocalIterator gridStart = grid.begin(navigation); @@ -207,7 +307,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { navigation[0ul].resize(nBins); navigation[1ul].resize(nBins); for (std::size_t i(0ul); i < 2ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); + std::iota(navigation[i].begin(), navigation[i].end(), 1ul); } Acts::GridLocalIterator Date: Tue, 12 Dec 2023 17:21:00 +0100 Subject: [PATCH 020/120] oopsie --- Core/include/Acts/Utilities/GridIterator.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 7bf7b98956a..b640a5faf73 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -95,7 +95,7 @@ template typename GridGlobalIterator::difference_type GridGlobalIterator::operator-( const GridGlobalIterator& other) const { - assert(other > *this); + assert(other <= *this); return m_idx - other.m_idx; } From 9179279c5ec807bae4bce9fa0084716657b8363f Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:56:41 +0100 Subject: [PATCH 021/120] even more tests --- .../Core/Utilities/GridIterationTests.cpp | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index ff2c3824c81..eabe528b7f8 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -252,11 +252,92 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 2ul); [[maybe_unused]] double value = *gridStart; + std::array locPos = gridStart.localPosition(); + BOOST_CHECK_EQUAL(locPos[0ul], 3ul); Acts::GridLocalIterator gridDefault; Acts::GridLocalIterator gridDummy(grid, {0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); + + // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + itr = std::move(gridStart); + BOOST_CHECK_EQUAL(itr == gridStart, false); + BOOST_CHECK_EQUAL(itr != gridStart, true); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins - 2ul); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid grid( + std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBinsX); + navigation[1ul].resize(nBinsY); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + // Constructor without navigation + Acts::GridLocalIterator gridIterNoNav(grid, {0ul, 0ul}); + // Constructor(s) with navigation + Acts::GridLocalIterator gridStart(grid, {0ul, 0ul}, navigation); + + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); + BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); + + Acts::GridLocalIterator gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false)); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 2ul); + + [[maybe_unused]] double value = *gridStart; + std::array locPos = gridStart.localPosition(); + BOOST_CHECK_EQUAL(locPos[0ul], 1ul); + BOOST_CHECK_EQUAL(locPos[1ul], 3ul); + + Acts::GridLocalIterator gridDefault; + Acts::GridLocalIterator gridDummy(grid, {0ul, 0ul}); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); + + // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + itr = std::move(gridStart); + BOOST_CHECK_EQUAL(itr == gridStart, false); + BOOST_CHECK_EQUAL(itr != gridStart, true); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY - 2ul); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_notvalid) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // no navigation bins + std::array, 1ul> noNavigation; + BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(noNavigation))), std::invalid_argument); + + // too many steps in the navigation, there are not enough bins in the axis + std::array, 1ul> tooMuchNavigation; + tooMuchNavigation[0ul].resize(2 * nBins); + std::iota(tooMuchNavigation[0ul].begin(), tooMuchNavigation[0ul].end(), 1ul); + BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(tooMuchNavigation))), std::invalid_argument); } BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { From a35da6dfbca111fd29fee2bffcb5c9a1fe34425d Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:57:23 +0100 Subject: [PATCH 022/120] remove line --- Core/include/Acts/Utilities/GridIterator.ipp | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index b640a5faf73..1ee5da1f563 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project From 773d11c1346a05117a9956cd49c6a14a6629934f Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:59:17 +0100 Subject: [PATCH 023/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 +- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 3 +- Core/include/Acts/Utilities/GridIterator.hpp | 7 +- Core/include/Acts/Utilities/GridIterator.ipp | 6 +- .../Core/Utilities/GridIterationTests.cpp | 99 ++++++++++++------- 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index cc10a493db7..3c183c0835d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,13 +117,9 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } + Acts::SpacePointGrid& grid() { return *m_grid.get(); } - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } + std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } private: // grid with ownership of all InternalSpacePoint diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index e9dcf22d311..4402a8375cc 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -15,8 +15,7 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( Acts::BinnedSPGroup& group, std::array index, std::array, 2> navigation) - : m_group(group), - m_gridItr(*group.m_grid.get(), index, navigation) { + : m_group(group), m_gridItr(*group.m_grid.get(), index, navigation) { std::array endline{}; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 001d460049e..5fd2c687e62 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -81,9 +81,10 @@ class GridLocalIterator { GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, const std::array& indexes) = delete; - GridLocalIterator( - Acts::Grid&& grid, const std::array& indexes, - std::array, DIM> navigation) = delete; + GridLocalIterator(Acts::Grid&& grid, + const std::array& indexes, + std::array, DIM> navigation) = + delete; GridLocalIterator(const Acts::Grid& grid, const std::array& indexes); GridLocalIterator(const Acts::Grid& grid, diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 1ee5da1f563..723d0d4183c 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -119,7 +119,8 @@ GridGlobalIterator GridGlobalIterator::operator++(int) { // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, const std::array& indexes) + const Acts::Grid& grid, + const std::array& indexes) : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), m_currentIndex(indexes) { @@ -131,7 +132,8 @@ Acts::GridLocalIterator::GridLocalIterator( template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, const std::array& indexes, + const Acts::Grid& grid, + const std::array& indexes, std::array, DIM> navigation) : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index eabe528b7f8..c4dd087275d 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { std::make_tuple(std::move(xAxis))); BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - + Acts::GridGlobalIterator gridStart = grid.begin(); Acts::GridGlobalIterator gridStop = @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); BOOST_CHECK_EQUAL(itr == gridStop, true); - + itr = gridStart - 1ul; BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 1ul); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { gridStart += std::distance(gridStart, gridStop); BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); BOOST_CHECK_EQUAL(gridStart == gridStop, true); - + gridStart -= 3ul; BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -65,7 +65,8 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { [[maybe_unused]] double value = *gridStart; Acts::GridGlobalIterator gridDefault; - Acts::GridGlobalIterator gridDummy(grid, 0ul); + Acts::GridGlobalIterator gridDummy( + grid, 0ul); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } @@ -75,15 +76,18 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { const std::size_t nBinsY = 5ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); - Acts::Grid grid( - std::make_tuple(std::move(xAxis), std::move(yAxis))); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); BOOST_CHECK_EQUAL(grid.size(true), (nBinsX + 2ul) * (nBinsY + 2ul)); - Acts::GridGlobalIterator gridStart = - grid.begin(); - Acts::GridGlobalIterator gridStop = - grid.end(); + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -121,12 +125,16 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { [[maybe_unused]] double value = *gridStart; - Acts::GridGlobalIterator gridDefault; - Acts::GridGlobalIterator gridDummy(grid, 0ul); + Acts::GridGlobalIterator + gridDefault; + Acts::GridGlobalIterator + gridDummy(grid, 0ul); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } - + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -221,20 +229,23 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { Acts::detail::EquidistantAxis xAxis(0, 100, nBins); Acts::Grid grid( std::make_tuple(std::move(xAxis))); - + std::array, 1ul> navigation; navigation[0ul].resize(nBins); std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); - + // Constructor without navigation - Acts::GridLocalIterator gridIterNoNav(grid, {0ul}); + Acts::GridLocalIterator gridIterNoNav( + grid, {0ul}); // Constructor(s) with navigation - Acts::GridLocalIterator gridStart(grid, {0ul}, navigation); + Acts::GridLocalIterator gridStart( + grid, {0ul}, navigation); BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); - Acts::GridLocalIterator gridStop(grid, {nBins}, std::move(navigation)); + Acts::GridLocalIterator gridStop( + grid, {nBins}, std::move(navigation)); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -256,11 +267,13 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { BOOST_CHECK_EQUAL(locPos[0ul], 3ul); Acts::GridLocalIterator gridDefault; - Acts::GridLocalIterator gridDummy(grid, {0ul}); + Acts::GridLocalIterator gridDummy( + grid, {0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); - // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + // move operation will invalidate gridStart since the grid gets moved and + // replaced with a nullptr itr = std::move(gridStart); BOOST_CHECK_EQUAL(itr == gridStart, false); BOOST_CHECK_EQUAL(itr != gridStart, true); @@ -272,9 +285,10 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { const std::size_t nBinsY = 5ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); - Acts::Grid grid( - std::make_tuple(std::move(xAxis), std::move(yAxis))); - + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + std::array, 2ul> navigation; navigation[0ul].resize(nBinsX); navigation[1ul].resize(nBinsY); @@ -282,14 +296,20 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); // Constructor without navigation - Acts::GridLocalIterator gridIterNoNav(grid, {0ul, 0ul}); + Acts::GridLocalIterator + gridIterNoNav(grid, {0ul, 0ul}); // Constructor(s) with navigation - Acts::GridLocalIterator gridStart(grid, {0ul, 0ul}, navigation); - + Acts::GridLocalIterator + gridStart(grid, {0ul, 0ul}, navigation); + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); - - Acts::GridLocalIterator gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); + + Acts::GridLocalIterator + gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -311,12 +331,17 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { BOOST_CHECK_EQUAL(locPos[0ul], 1ul); BOOST_CHECK_EQUAL(locPos[1ul], 3ul); - Acts::GridLocalIterator gridDefault; - Acts::GridLocalIterator gridDummy(grid, {0ul, 0ul}); + Acts::GridLocalIterator + gridDefault; + Acts::GridLocalIterator + gridDummy(grid, {0ul, 0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); - // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + // move operation will invalidate gridStart since the grid gets moved and + // replaced with a nullptr itr = std::move(gridStart); BOOST_CHECK_EQUAL(itr == gridStart, false); BOOST_CHECK_EQUAL(itr != gridStart, true); @@ -331,15 +356,21 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_notvalid) { // no navigation bins std::array, 1ul> noNavigation; - BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(noNavigation))), std::invalid_argument); + BOOST_CHECK_THROW( + (Acts::GridLocalIterator( + grid, {0ul}, std::move(noNavigation))), + std::invalid_argument); // too many steps in the navigation, there are not enough bins in the axis std::array, 1ul> tooMuchNavigation; tooMuchNavigation[0ul].resize(2 * nBins); std::iota(tooMuchNavigation[0ul].begin(), tooMuchNavigation[0ul].end(), 1ul); - BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(tooMuchNavigation))), std::invalid_argument); + BOOST_CHECK_THROW( + (Acts::GridLocalIterator( + grid, {0ul}, std::move(tooMuchNavigation))), + std::invalid_argument); } - + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); From f7fdcb5b668c10f1362f448865f45d394af42f00 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:19:01 +0100 Subject: [PATCH 024/120] first round of comments --- Core/include/Acts/Utilities/Grid.hpp | 3 --- Core/include/Acts/Utilities/GridIterator.ipp | 2 -- 2 files changed, 5 deletions(-) diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 04c6007447f..3d0913207df 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -476,9 +476,6 @@ class Grid final { local_iterator_t begin( const std::array, DIM>& navigator) const { std::array localBin{}; - for (std::size_t i(0); i < DIM; ++i) { - localBin[i] = 0ul; - } return local_iterator_t(*this, std::move(localBin), navigator); } diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 723d0d4183c..f6b563c1ed8 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -6,8 +6,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include - namespace Acts { // Global Iterator template From d5016b823d5506b13c535c8e4a9ac0925783f2ec Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:20:30 +0100 Subject: [PATCH 025/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3c183c0835d..cc10a493db7 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,9 +117,13 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { return *m_grid.get(); } + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } - std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } private: // grid with ownership of all InternalSpacePoint From ec66bfaecadcb4b0b0e4ac95ff91990fa1421aba Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:58:28 +0100 Subject: [PATCH 026/120] test for checking iterations --- .../Core/Utilities/GridIterationTests.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index c4dd087275d..2f3bf5deb37 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -12,6 +12,7 @@ #include "Acts/Utilities/GridIterator.hpp" #include +#include namespace Acts::Test { @@ -582,4 +583,69 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { BOOST_CHECK_EQUAL(numIterations, expectedIterations); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_norepetitions) { + const std::size_t nBinsX = 5ul; + const std::size_t nBinsY = 5ul; + const std::size_t nBinsZ = 2ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 4ul}; + navigation[1ul] = {4ul, 2ul, 3ul, 5ul, 1ul}; + navigation[2ul] = {2ul, 1ul}; + + std::size_t expectedIterations = + navigation[0ul].size() * navigation[1ul].size() * navigation[2ul].size(); + + // Set the allowed values + std::unordered_set allowed_global_bins; + for (std::size_t x : navigation[0ul]) { + for (std::size_t y : navigation[1ul]) { + for (std::size_t z : navigation[2ul]) { + std::array locPos({x, y, z}); + std::size_t globPos = grid.globalBinFromLocalBins(locPos); + BOOST_CHECK_EQUAL( + allowed_global_bins.find(globPos) != allowed_global_bins.end(), + false); + allowed_global_bins.insert(globPos); + } + } + } + + BOOST_CHECK_EQUAL(expectedIterations, allowed_global_bins.size()); + + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + + // Prepare visited values + std::unordered_set visited_global_bins; + + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + std::array locPos = gridStart.localPosition(); + std::size_t globPos = grid.globalBinFromLocalBins(locPos); + BOOST_CHECK_EQUAL( + visited_global_bins.find(globPos) != visited_global_bins.end(), false); + BOOST_CHECK_EQUAL( + allowed_global_bins.find(globPos) != allowed_global_bins.end(), true); + visited_global_bins.insert(globPos); + } + + BOOST_CHECK_EQUAL(expectedIterations, numIterations); + BOOST_CHECK_EQUAL(visited_global_bins.size(), allowed_global_bins.size()); +} + } // namespace Acts::Test From 9ea63abdd9e4659d1accddf6ad7385d0fc3b3c20 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 09:50:08 +0100 Subject: [PATCH 027/120] clang tidy --- Core/include/Acts/Utilities/GridIterator.ipp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index f6b563c1ed8..e2d358f9394 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -202,7 +202,7 @@ bool Acts::GridLocalIterator::operator!=( template const typename Acts::GridLocalIterator::value_type& Acts::GridLocalIterator::operator*() const { - std::array localPositionBin; + std::array localPositionBin{}; for (std::size_t i(0); i < DIM; ++i) { localPositionBin[i] = m_navigationIndex[i][m_currentIndex[i]]; } @@ -225,8 +225,9 @@ GridLocalIterator GridLocalIterator::operator++(int) { template template void GridLocalIterator::increment() { - if (++m_currentIndex[N] < m_numLocalBins[N]) + if (++m_currentIndex[N] < m_numLocalBins[N]) { return; + } if constexpr (N != 0) { m_currentIndex[N] = 0; increment(); From 4772218c32692d7c37d1e475e0db1d591feb9a7c Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 15 Dec 2023 11:15:14 +0100 Subject: [PATCH 028/120] remove property --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 6 ------ Core/include/Acts/Seeding/BinnedSPGroup.ipp | 11 ++++------- Core/include/Acts/Seeding/SeedFinderConfig.hpp | 5 ----- Examples/Python/python/acts/examples/itk.py | 7 +------ .../Python/python/acts/examples/reconstruction.py | 6 ++---- Examples/Python/src/TrackFinding.cpp | 1 - 6 files changed, 7 insertions(+), 29 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index cc10a493db7..6374d7b1b3f 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -121,10 +121,6 @@ class BinnedSPGroup { return *m_grid.get(); } - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } - private: // grid with ownership of all InternalSpacePoint std::unique_ptr> m_grid{nullptr}; @@ -138,8 +134,6 @@ class BinnedSPGroup { // Order of z bins to loop over when searching for SPs std::array, 2> m_bins{}; - // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin{0ul}; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 4402a8375cc..83d350ea86a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -197,22 +198,18 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_bottomBinFinder = botBinFinder; m_topBinFinder = tBinFinder; - m_skipZMiddleBin = config.skipZMiddleBinSearch; - // phi axis m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1ul); // z axis if (config.zBinsCustomLooping.empty()) { - std::size_t nZbins = m_grid->numLocalBins()[1] - m_skipZMiddleBin; + std::size_t nZbins = m_grid->numLocalBins()[INDEX::Z]; m_bins[INDEX::Z] = std::vector(nZbins); std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), - 1ul + m_skipZMiddleBin); + 1ul); } else { - m_bins[INDEX::Z] = std::vector( - config.zBinsCustomLooping.begin() + m_skipZMiddleBin, - config.zBinsCustomLooping.end()); + m_bins[INDEX::Z] = config.zBinsCustomLooping; } } diff --git a/Core/include/Acts/Seeding/SeedFinderConfig.hpp b/Core/include/Acts/Seeding/SeedFinderConfig.hpp index b4645241b48..fd944b54dc9 100644 --- a/Core/include/Acts/Seeding/SeedFinderConfig.hpp +++ b/Core/include/Acts/Seeding/SeedFinderConfig.hpp @@ -45,11 +45,6 @@ struct SeedFinderConfig { /// Vector containing the z-bin edges for non equidistant binning in z std::vector zBinEdges; - /// Number of z bins to skip during the search for middle space-points. This - /// is useful for removing the outermost bins and speeding up seeding. Should - /// be used in conjunction with zBinsCustomLooping (skipZMiddleBinSearch - /// determines the first N bins in zBinsCustomLooping to be avoided). - std::size_t skipZMiddleBinSearch = 0; /// Order of z bins to loop over when searching for SPs std::vector zBinsCustomLooping = {}; diff --git a/Examples/Python/python/acts/examples/itk.py b/Examples/Python/python/acts/examples/itk.py index 508c525d9fb..1115e79cb68 100644 --- a/Examples/Python/python/acts/examples/itk.py +++ b/Examples/Python/python/acts/examples/itk.py @@ -445,9 +445,7 @@ def itkSeedingAlgConfig( if highOccupancyConfig == True: rMaxGridConfig = 250 * u.mm deltaRMax = 200 * u.mm - zBinsCustomLooping = [1, 11, 2, 10, 3, 9, 6, 4, 8, 5, 7] - # variables that are only used for highOccupancyConfig configuration: - skipZMiddleBinSearch = 2 + zBinsCustomLooping = [2, 10, 3, 9, 6, 4, 8, 5, 7] elif inputSpacePointsType is InputSpacePointsType.StripSpacePoints: outputSeeds = "StripSeeds" @@ -518,8 +516,6 @@ def itkSeedingAlgConfig( [40.0, 80.0], ] useVariableMiddleSPRange = False - else: - skipZMiddleBinSearch = 0 # fill namedtuples seedFinderConfigArg = SeedFinderConfigArg( @@ -535,7 +531,6 @@ def itkSeedingAlgConfig( maxPtScattering=maxPtScattering, zBinEdges=zBinEdges, zBinsCustomLooping=zBinsCustomLooping, - skipZMiddleBinSearch=skipZMiddleBinSearch, rRangeMiddleSP=rRangeMiddleSP, useVariableMiddleSPRange=useVariableMiddleSPRange, binSizeR=binSizeR, diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index d058f6aaac9..aa0e94bbc37 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -41,7 +41,6 @@ "maxPtScattering", "zBinEdges", "zBinsCustomLooping", - "skipZMiddleBinSearch", "rRangeMiddleSP", "useVariableMiddleSPRange", "binSizeR", @@ -57,7 +56,7 @@ "z", # (min,max) "zOutermostLayers", # (min,max) ], - defaults=[None] * 19 + [(None, None)] * 8, + defaults=[None] * 18 + [(None, None)] * 8, ) SeedFinderOptionsArg = namedtuple( "SeedFinderOptions", ["beamPos", "bFieldInZ"], defaults=[(None, None), None] @@ -215,7 +214,7 @@ def addSeeding( initialVarInflation : list List of 6 scale factors to inflate the initial covariance matrix Defaults (all 1) specified in Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/ParticleSmearing.hpp - seedFinderConfigArg : SeedFinderConfigArg(maxSeedsPerSpM, cotThetaMax, sigmaScattering, radLengthPerSeed, minPt, impactMax, deltaPhiMax, interactionPointCut, deltaZMax, maxPtScattering, zBinEdges, zBinsCustomLooping, skipZMiddleBinSearch, rRangeMiddleSP, useVariableMiddleSPRange, binSizeR, seedConfirmation, centralSeedConfirmationRange, forwardSeedConfirmationRange, deltaR, deltaRBottomSP, deltaRTopSP, deltaRMiddleSPRange, collisionRegion, r, z, zOutermostLayers) + seedFinderConfigArg : SeedFinderConfigArg(maxSeedsPerSpM, cotThetaMax, sigmaScattering, radLengthPerSeed, minPt, impactMax, deltaPhiMax, interactionPointCut, deltaZMax, maxPtScattering, zBinEdges, zBinsCustomLooping, rRangeMiddleSP, useVariableMiddleSPRange, binSizeR, seedConfirmation, centralSeedConfirmationRange, forwardSeedConfirmationRange, deltaR, deltaRBottomSP, deltaRTopSP, deltaRMiddleSPRange, collisionRegion, r, z, zOutermostLayers) SeedFinderConfig settings. deltaR, deltaRBottomSP, deltaRTopSP, deltaRMiddleSPRange, collisionRegion, r, z, zOutermostLayers are ranges specified as a tuple of (min,max). beamPos is specified as (x,y). Defaults specified in Core/include/Acts/Seeding/SeedFinderConfig.hpp seedFinderOptionsArg : SeedFinderOptionsArg(bFieldInZ, beamPos) @@ -594,7 +593,6 @@ def addStandardSeeding( maxPtScattering=seedFinderConfigArg.maxPtScattering, zBinEdges=seedFinderConfigArg.zBinEdges, zBinsCustomLooping=seedFinderConfigArg.zBinsCustomLooping, - skipZMiddleBinSearch=seedFinderConfigArg.skipZMiddleBinSearch, rRangeMiddleSP=seedFinderConfigArg.rRangeMiddleSP, useVariableMiddleSPRange=seedFinderConfigArg.useVariableMiddleSPRange, binSizeR=seedFinderConfigArg.binSizeR, diff --git a/Examples/Python/src/TrackFinding.cpp b/Examples/Python/src/TrackFinding.cpp index 3881a6b7e3e..76bfa48f1c6 100644 --- a/Examples/Python/src/TrackFinding.cpp +++ b/Examples/Python/src/TrackFinding.cpp @@ -127,7 +127,6 @@ void addTrackFinding(Context& ctx) { ACTS_PYTHON_MEMBER(zBinEdges); ACTS_PYTHON_MEMBER(interactionPointCut); ACTS_PYTHON_MEMBER(zBinsCustomLooping); - ACTS_PYTHON_MEMBER(skipZMiddleBinSearch); ACTS_PYTHON_MEMBER(useVariableMiddleSPRange); ACTS_PYTHON_MEMBER(deltaRMiddleMinSPRange); ACTS_PYTHON_MEMBER(deltaRMiddleMaxSPRange); From bc0aa7061b1beb303df3c9ee05636f308a8da82d Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 21 Nov 2023 21:57:41 +0100 Subject: [PATCH 029/120] First implementation --- Core/include/Acts/Utilities/GridIterator.hpp | 128 +++++++++ Core/include/Acts/Utilities/GridIterator.ipp | 259 +++++++++++++++++++ 2 files changed, 387 insertions(+) create mode 100644 Core/include/Acts/Utilities/GridIterator.hpp create mode 100644 Core/include/Acts/Utilities/GridIterator.ipp diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp new file mode 100644 index 00000000000..14249846ac8 --- /dev/null +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -0,0 +1,128 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/Holders.hpp" + +#include + +namespace Acts { + + // Using Global iterator, including over/under flow bins + template + class GridGlobalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridGlobalIterator(Acts::Grid&& grid, + std::size_t idx) = delete; + GridGlobalIterator(const Acts::Grid& grid, + std::size_t idx = 0ul); + + GridGlobalIterator(const GridGlobalIterator& other) = default; + GridGlobalIterator& operator=(const GridGlobalIterator& other) = default; + + GridGlobalIterator(GridGlobalIterator&& other) noexcept; + GridGlobalIterator& operator=(GridGlobalIterator&& other) noexcept; + + ~GridGlobalIterator() = default; + + bool operator==(const GridGlobalIterator& other) const; + bool operator!=(const GridGlobalIterator& other) const; + + bool operator<(const GridGlobalIterator& other) const; + bool operator>(const GridGlobalIterator& other) const; + bool operator<=(const GridGlobalIterator& other) const; + bool operator>=(const GridGlobalIterator& other) const; + + GridGlobalIterator& operator+=(const std::size_t offset); + GridGlobalIterator& operator-=(const std::size_t offset); + GridGlobalIterator operator+(const std::size_t offset) const; + GridGlobalIterator operator-(const std::size_t offset) const; + + difference_type operator-(const GridIterator& other) const; + const value_type& operator*() const; + + GridGlobalIterator& operator++(); + GridGlobalIterator operator++(int); + + private: + Acts::detail::RefHolder> m_grid {nullptr}; + std::size_t m_idx {0ul}; + }; + + + // Using Local iterator, excluding over/under flow bins + // Can also allow for custom navigation pattern along axes + template + class GridLocalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridLocalIterator(Acts::Grid&& grid, + std::array indexes) = delete; + GridLocalIterator(Acts::Grid&& grid, + std::array indexes, + std::array, DIM> navigation) = delete; + GridLocalIterator(const Acts::Grid& grid, + std::array indexes); + GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation); + + GridLocalIterator(const GridLocalIterator& other) = default; + GridLocalIterator& operator=(const GridLocalIterator& other) = default; + + GridLocalIterator(GridLocalIterator&& other) noexcept; + GridLocalIterator& operator=(GridLocalIterator&& other) noexcept; + + ~GridLocalIterator() = default; + + bool operator==(const Acts::GridLocalIterator& other) const; + bool operator!=(const Acts::GridLocalIterator& other) const; + + bool operator<(const Acts::GridLocalIterator& other) const; + bool operator>(const Acts::GridLocalIterator& other) const; + bool operator<=(const Acts::GridLocalIterator& other) const; + bool operator>=(const Acts::GridLocalIterator& other) const; + + difference_type operator-(const GridLocalIterator& other) const; + + const value_type& operator*() const; + + GridLocalIterator& operator++(); + GridLocalIterator operator++(int); + + private: + template + void increment(); + + private: + Acts::detail::RefHolder> m_grid {nullptr}; + std::array m_numLocalBins {}; + std::array m_currentIndex {}; + std::array, DIM> m_navigationIndex {}; + }; + +} // namespace Acts + +#include "Acts/Utilities/GridIterator.ipp" diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp new file mode 100644 index 00000000000..ca03adc28b4 --- /dev/null +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -0,0 +1,259 @@ +// -*- C++ -*- +// This file is part of the Acts project. +// +// Copyright (C) 2016-2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +namespace Acts { + // Global Iterator + template + GridGlobalIterator::GridGlobalIterator(const Acts::Grid& grid, + std::size_t idx) + : m_grid( &grid ), + m_idx( idx ) + {} + + template + GridGlobalIterator::GridGlobalIterator(GridGlobalIterator&& other) noexcept + : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), + m_idx( other.m_idx ) + {} + + template + GridGlobalIterator& + GridGlobalIterator::operator=(GridGlobalIterator&& other) noexcept + { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_idx = other.m_idx; + return *this; + } + + template + bool GridGlobalIterator::operator==(const GridGlobalIterator& other) const + { + return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; + } + + template + bool GridGlobalIterator::operator!=(const GridGlobalIterator& other) const + { + return !(*this == other); + } + + template + bool GridGlobalIterator::operator<(const GridGlobalIterator& other) const + { return m_idx < other.m_idx; } + + template + bool GridGlobalIterator::operator>(const GridGlobalIterator& other) const + { return m_idx > other.m_idx; } + + template + bool GridGlobalIterator::operator<=(const GridGlobalIterator& other) const + { return !(*this > other); } + + template + bool GridGlobalIterator::operator>=(const GridGlobalIterator& other) const + { return !(*this < other); } + + template + GridGlobalIterator& + GridGlobalIterator::operator+=(const std::size_t offset) + { + m_idx += offset; + return *this; + } + + template + GridGlobalIterator& + GridGlobalIterator::operator-=(const std::size_t offset) + { + m_idx -= offset; + return *this; + } + + template + GridGlobalIterator + GridGlobalIterator::operator+(const std::size_t offset) const + { + return {m_grid.ptr, m_idx + offset}; + } + + template + GridGlobalIterator + GridGlobalIterator::operator-(const std::size_t offset) const + { + return {m_grid.ptr, m_idx - offset}; + } + + template + typename GridGlobalIterator::difference_type + GridGlobalIterator::operator-(const GridIterator& other) const { + assert(other > *this); + return other.m_idx - m_idx; + } + + template + const typename GridGlobalIterator::value_type& + GridGlobalIterator::operator*() const + { + return m_grid->at(m_idx); + } + + template + GridGlobalIterator& + GridGlobalIterator::operator++() { + ++m_idx; + return *this; + } + + template + GridGlobalIterator + GridGlobalIterator::operator++(int) { + GridGlobalIterator output(m_grid, m_idx++); + return output; + } + + + + + + + // Local Iterator + template + Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, + std::array indexes) + : m_grid( &grid ), + m_numLocalBins( std::move(grid.numLocalBins()) ), + m_currentIndex( std::move(indexes) ) + { + for (std::size_t i(0); i + Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation) + : m_grid( &grid ), + m_numLocalBins( std::move(grid.numLocalBins()) ), + m_currentIndex( std::move(indexes) ), + m_navigationIndex( std::move(navigation) ) + { + // check navigation consistency + for (std::size_t i(0); i + Acts::GridLocalIterator::GridLocalIterator(Acts::GridLocalIterator&& other) noexcept + : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), + m_numLocalBins( std::move(other.m_numLocalBins) ), + m_currentIndex( std::move(other.m_currentIndex) ), + m_navigationIndex( std::move(other.m_navigationIndex) ) + {} + + template + Acts::GridLocalIterator& + Acts::GridLocalIterator::operator=(Acts::GridLocalIterator&& other) noexcept + { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_numLocalBins = std::move(other.m_numLocalBins); + m_currentIndex = std::move(other.m_currentIndex); + m_navigationIndex = std::move(other.m_navigationIndex); + return *this; + } + + template + bool Acts::GridLocalIterator::operator==(const Acts::GridLocalIterator& other) const + { + if (m_grid.ptr != other.m_grid.ptr) { + return false; + } + + for (std::size_t i(0); i + bool Acts::GridLocalIterator::operator!=(const Acts::GridLocalIterator& other) const + { return ! (*this == other); } + + template + bool Acts::GridLocalIterator::operator<(const GridLocalIterator& other) const + { return m_grid.globalBinFromLocalBins(m_currentIndex) < other.m_grid.globalBinFromLocalBins(m_currentIndex); } + + template + bool Acts::GridLocalIterator::operator>(const GridLocalIterator& other) const + { return m_grid.globalBinFromLocalBins(m_currentIndex) > other.m_grid.globalBinFromLocalBins(m_currentIndex); } + + template + bool Acts::GridLocalIterator::operator<=(const GridLocalIterator& other) const + { return ! (*this > other); } + + template + bool Acts::GridLocalIterator::operator>=(const GridLocalIterator& other) const + { return ! (*this < other); } + + template + typename Acts::GridLocalIterator::difference_type + Acts::GridLocalIterator::operator-(const Acts::GridLocalIterator& other) const + { return other.m_grid->globalBinFromLocalBins(m_currentIndex) - m_grid->globalBinFromLocalBins(m_currentIndex); } + + template + const typename Acts::GridLocalIterator::value_type& + Acts::GridLocalIterator::operator*() const + { + std::array localPositionBin; + for (std::size_t i(0); iatLocalBins(localPositionBin); + } + + template + GridLocalIterator& + GridLocalIterator::operator++() + { + increment(); + return *this; + } + + template + GridLocalIterator + GridLocalIterator::operator++(int) + { + GridLocalIterator output(m_grid.ptr, m_currentIndex); + this->operator++(); + return output; + } + + template + template + void GridLocalIterator::increment() { + if (++m_currentIndex[N] < m_numLocalBins[N]) return; + m_currentIndex[N] = 0; + if constexpr (N != 0) { + increment(); + } else { + m_currentIndex = m_numLocalBins; + } + } + +} // namespace Acts + From 167756de342f64f49ab734bb706a9073ae110539 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 22 Nov 2023 09:31:51 +0100 Subject: [PATCH 030/120] changes --- CMakeLists.txt | 4 +- .../Acts/Seeding/FutureBinnedSPGroup.hpp | 140 +++++++++++ .../Acts/Seeding/FutureBinnedSPGroup.ipp | 223 ++++++++++++++++++ Core/include/Acts/Utilities/Grid.hpp | 35 ++- Core/include/Acts/Utilities/GridIterator.hpp | 5 +- Core/include/Acts/Utilities/GridIterator.ipp | 21 +- .../TrackFinding/src/SeedingAlgorithm.cpp | 60 ++++- 7 files changed, 478 insertions(+), 10 deletions(-) create mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp create mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp diff --git a/CMakeLists.txt b/CMakeLists.txt index 352c1303432..6ea55dfa860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,14 @@ option(ACTS_BUILD_FATRAS_GEANT4 "Build Geant4 Fatras package" OFF) # alignment related options option(ACTS_BUILD_ALIGNMENT "Build Alignment package" OFF) # examples related options -option(ACTS_BUILD_EXAMPLES "Build standalone examples" OFF) +option(ACTS_BUILD_EXAMPLES "Build standalone examples" ON) option(ACTS_BUILD_EXAMPLES_DD4HEP "Build DD4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EDM4HEP "Build EDM4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EXATRKX "Build the Exa.TrkX example code" OFF) option(ACTS_BUILD_EXAMPLES_GEANT4 "Build Geant4-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_HEPMC3 "Build HepMC3-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_PYTHIA8 "Build Pythia8-based code in the examples" OFF) -option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" OFF) +option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" ON) option(ACTS_BUILD_EXAMPLES_BINARIES "Build the examples binaries (deprecated)" OFF) option(ACTS_USE_SYSTEM_PYBIND11 "Use a system installation of pybind11" ${ACTS_USE_SYSTEM_LIBS} ) option(ACTS_USE_EXAMPLES_TBB "Use Threading Building Blocks library in the examples" ON) diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp new file mode 100644 index 00000000000..7c6d7f63147 --- /dev/null +++ b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp @@ -0,0 +1,140 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/Extent.hpp" +#include "Acts/Seeding/BinFinder.hpp" +#include "Acts/Seeding/InternalSeed.hpp" +#include "Acts/Seeding/Seed.hpp" +#include "Acts/Seeding/SeedFinderConfig.hpp" +#include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/Holders.hpp" + +#include +#include + +#include + +namespace Acts::future { +template +class BinnedSPGroup; + +/// @c BinnedSPGroupIterator Allows to iterate over all groups of bins +/// a provided BinFinder can generate for each bin of a provided SPGrid + +/// SpacePointGrid is a very specific structure. +/// We know it is 2D and what it contains +/// No need to be too general with this class +template +class BinnedSPGroupIterator { + private: + enum INDEX : int { PHI = 0, Z = 1 }; + +public: + // Never take ownerships + BinnedSPGroupIterator(BinnedSPGroup&& group, + std::array index, + std::array, 2> navigation) = delete; + BinnedSPGroupIterator(BinnedSPGroup& group, + std::array index, + std::array, 2> navigation); + + BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; + BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; + + BinnedSPGroupIterator(BinnedSPGroupIterator&&) noexcept = default; + BinnedSPGroupIterator& operator=(BinnedSPGroupIterator&&) noexcept = default; + + ~BinnedSPGroupIterator() = default; + + BinnedSPGroupIterator& operator++(); + + bool operator==(const BinnedSPGroupIterator& other) const; + bool operator!=(const BinnedSPGroupIterator& other) const; + + std::tuple, std::size_t, + boost::container::small_vector> + operator*() const; + + private: + void findNotEmptyBin(); + + private: + // The group, it contains the grid and the bin finders + Acts::detail::RefHolder> m_group; + // Current grid iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + // End iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; +}; + +/// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator +/// for given BinFinders and SpacePointGrid. +/// Fulfills the range_expression interface. +template +class BinnedSPGroup { +#ifndef DOXYGEN + friend BinnedSPGroupIterator; +#endif + + enum INDEX : int { PHI = 0, Z = 1 }; + + public: + BinnedSPGroup() = delete; + + template + BinnedSPGroup( + spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + std::shared_ptr> + botBinFinder, + std::shared_ptr> tBinFinder, + std::unique_ptr> grid, + Acts::Extent& rRangeSPExtent, + const SeedFinderConfig& _config, + const SeedFinderOptions& _options); + + BinnedSPGroup(const BinnedSPGroup&) = delete; + BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; + + BinnedSPGroup(BinnedSPGroup&&) noexcept = default; + BinnedSPGroup& operator=(BinnedSPGroup&&) noexcept = default; + + ~BinnedSPGroup() = default; + + std::size_t size() const; + + BinnedSPGroupIterator begin(); + BinnedSPGroupIterator end(); + + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } + + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } + + private: + // grid with ownership of all InternalSpacePoint + std::unique_ptr> m_grid {nullptr}; + + // BinFinder must return std::vector with content of + // each bin sorted in r (ascending) + std::shared_ptr> m_topBinFinder {nullptr}; + std::shared_ptr> m_bottomBinFinder {nullptr}; + + // Order of z bins to loop over when searching for SPs + std::array, 2> m_bins {}; + // Number of Z bins to skip the search for middle SP + std::size_t m_skipZMiddleBin {0ul}; +}; + +} // namespace Acts +#include "Acts/Seeding/FutureBinnedSPGroup.ipp" diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp new file mode 100644 index 00000000000..7968ec14963 --- /dev/null +++ b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp @@ -0,0 +1,223 @@ +// -*- C++ -*- +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Binned SP Group Iterator + +#include + +template +Acts::future::BinnedSPGroupIterator::BinnedSPGroupIterator( + Acts::future::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) + : m_group(group), + m_gridItr(*group.m_grid.get(), std::move(index), navigation), + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) +{ + findNotEmptyBin(); +} + +template +inline Acts::future::BinnedSPGroupIterator& +Acts::future::BinnedSPGroupIterator::operator++() { + ++m_gridItr; + findNotEmptyBin(); + return *this; +} + +template +inline bool Acts::future::BinnedSPGroupIterator::operator==( + const Acts::future::BinnedSPGroupIterator& other) const { + return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; +} + +template +inline bool Acts::future::BinnedSPGroupIterator::operator!=( + const Acts::future::BinnedSPGroupIterator& other) const { + return !(*this == other); +} + +template +std::tuple, std::size_t, + boost::container::small_vector> +Acts::future::BinnedSPGroupIterator::operator*() const { + // Global Index + std::array localPosition = m_gridItr.localPosition(); + std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); + + boost::container::small_vector bottoms = + m_group->m_bottomBinFinder->findBins( + localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); + boost::container::small_vector tops = + m_group->m_topBinFinder->findBins( + localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); + + // GCC12+ in Release throws an overread warning here due to the move. + // This is from inside boost code, so best we can do is to suppress it. +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overread" +#endif + return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic pop +#endif +} + +template +inline void +Acts::future::BinnedSPGroupIterator::findNotEmptyBin() { + if (m_gridItr == m_gridItrEnd) return; + // Iterate on the grid till we find a not-empty bin + // We start from the current bin configuration and move forward + std::size_t dimCollection = (*m_gridItr).size(); + while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + dimCollection = (*m_gridItr).size(); + } +} + +// Binned SP Group +template +template +Acts::future::BinnedSPGroup::BinnedSPGroup( + spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + std::shared_ptr> botBinFinder, + std::shared_ptr> tBinFinder, + std::unique_ptr> grid, + Acts::Extent& rRangeSPExtent, + const SeedFinderConfig& config, + const SeedFinderOptions& options) { + if (!config.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); + } + if (!options.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); + } + static_assert( + std::is_same< + typename std::iterator_traits::value_type, + const external_spacepoint_t*>::value, + "Iterator does not contain type this class was templated with"); + + // get region of interest (or full detector if configured accordingly) + float phiMin = config.phiMin; + float phiMax = config.phiMax; + float zMin = config.zMin; + float zMax = config.zMax; + + // sort by radius + // add magnitude of beamPos to rMax to avoid excluding measurements + // create number of bins equal to number of millimeters rMax + // (worst case minR: configured minR + 1mm) + // binSizeR allows to increase or reduce numRBins if needed + std::size_t numRBins = static_cast( + (config.rMax + options.beamPos.norm()) / config.binSizeR); + + // keep track of changed bins while sorting + boost::container::flat_set rBinsIndex; + + std::size_t counter = 0; + for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { + if (*it == nullptr) { + continue; + } + const external_spacepoint_t& sp = **it; + const auto& [spPosition, variance] = + toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); + + float spX = spPosition[0]; + float spY = spPosition[1]; + float spZ = spPosition[2]; + + // store x,y,z values in extent + rRangeSPExtent.extend({spX, spY, spZ}); + + // remove SPs outside z and phi region + if (spZ > zMax || spZ < zMin) { + continue; + } + float spPhi = std::atan2(spY, spX); + if (spPhi > phiMax || spPhi < phiMin) { + continue; + } + + auto isp = std::make_unique>( + counter, sp, spPosition, options.beamPos, variance); + // calculate r-Bin index and protect against overflow (underflow not + // possible) + std::size_t rIndex = + static_cast(isp->radius() / config.binSizeR); + // if index out of bounds, the SP is outside the region of interest + if (rIndex >= numRBins) { + continue; + } + + // fill rbins into grid + Acts::Vector2 spLocation(isp->phi(), isp->z()); + std::vector>>& + rbin = grid->atPosition(spLocation); + rbin.push_back(std::move(isp)); + + // keep track of the bins we modify so that we can later sort the SPs in + // those bins only + if (rbin.size() > 1) { + rBinsIndex.insert(grid->globalBinFromPosition(spLocation)); + } + } + + // sort SPs in R for each filled (z, phi) bin + for (auto& binIndex : rBinsIndex) { + std::vector>>& + rbin = grid->atPosition(binIndex); + std::sort( + rbin.begin(), rbin.end(), + [](std::unique_ptr>& a, + std::unique_ptr>& b) { + return a->radius() < b->radius(); + }); + } + + m_grid = std::move(grid); + m_bottomBinFinder = botBinFinder; + m_topBinFinder = tBinFinder; + + m_skipZMiddleBin = config.skipZMiddleBinSearch; + m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); + m_bins[INDEX::Z] = config.zBinsCustomLooping; + if (m_bins[INDEX::Z].empty()) { + std::size_t nZbins = m_grid->numLocalBins()[1]; + m_bins[INDEX::Z].resize(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); + } +} + +template +inline std::size_t Acts::future::BinnedSPGroup::size() const { + return m_grid->size(); +} + +template +inline Acts::future::BinnedSPGroupIterator +Acts::future::BinnedSPGroup::begin() { + return {*this, {0ul, 0ul}, m_bins}; +} + +template +inline Acts::future::BinnedSPGroupIterator +Acts::future::BinnedSPGroup::end() { + return {*this, m_grid->numLocalBins(), m_bins}; +} diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index f4b1671a077..193c5b74c94 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -20,6 +20,14 @@ #include #include +namespace Acts { + template + class GridGlobalIterator; + + template + class GridLocalIterator; +} + namespace Acts { /// @brief class for describing a regular multi-dimensional grid @@ -48,7 +56,11 @@ class Grid final { using point_t = std::array; /// index type using local bin indices along each axis using index_t = std::array; - + /// global iterator type + using global_iterator_t = Acts::GridGlobalIterator; + /// local iterator type + using local_iterator_t = Acts::GridLocalIterator; + /// @brief default constructor /// /// @param [in] axes actual axis objects spanning the grid @@ -457,6 +469,27 @@ class Grid final { return detail::grid_helper::getAxes(m_axes); } + + global_iterator_t begin() const { + return global_iterator_t(*this, 0); + } + + global_iterator_t end() const { + return global_iterator_t(*this, size()); + } + + local_iterator_t begin(const std::array, DIM>& navigator) const { + std::array localBin; + for (std::size_t i(0); i, DIM>& navigator) const { + return local_iterator_t(*this, numLocalBins(), navigator); + } + private: /// set of axis defining the multi-dimensional grid std::tuple m_axes; diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 14249846ac8..a4cf195730e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -53,7 +53,7 @@ namespace Acts { GridGlobalIterator operator+(const std::size_t offset) const; GridGlobalIterator operator-(const std::size_t offset) const; - difference_type operator-(const GridIterator& other) const; + difference_type operator-(const GridGlobalIterator& other) const; const value_type& operator*() const; GridGlobalIterator& operator++(); @@ -111,6 +111,8 @@ namespace Acts { GridLocalIterator& operator++(); GridLocalIterator operator++(int); + + std::array localPosition() const; private: template @@ -120,6 +122,7 @@ namespace Acts { Acts::detail::RefHolder> m_grid {nullptr}; std::array m_numLocalBins {}; std::array m_currentIndex {}; + std::array m_localPosition {}; std::array, DIM> m_navigationIndex {}; }; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index ca03adc28b4..9ade6910cfe 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -93,7 +93,7 @@ namespace Acts { template typename GridGlobalIterator::difference_type - GridGlobalIterator::operator-(const GridIterator& other) const { + GridGlobalIterator::operator-(const GridGlobalIterator& other) const { assert(other > *this); return other.m_idx - m_idx; } @@ -134,7 +134,8 @@ namespace Acts { { for (std::size_t i(0); i @@ -171,6 +174,7 @@ namespace Acts { m_numLocalBins = std::move(other.m_numLocalBins); m_currentIndex = std::move(other.m_currentIndex); m_navigationIndex = std::move(other.m_navigationIndex); + m_localPosition = std::move(other.m_localPosition); return *this; } @@ -255,5 +259,16 @@ namespace Acts { } } + template + std::array::DIM> + GridLocalIterator::localPosition() const + { + std::array output; + for (std::size_t i(0); i #include @@ -29,6 +32,7 @@ #include #include #include +#include namespace ActsExamples { struct AlgorithmContext; @@ -252,11 +256,19 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( auto grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); + auto futureGrid = Acts::SpacePointGridCreator::createGrid( + m_cfg.gridConfig, m_cfg.gridOptions); + auto spacePointsGrouping = Acts::BinnedSPGroup( spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, m_bottomBinFinder, m_topBinFinder, std::move(grid), rRangeSPExtent, m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); + auto futureSpacePointsGrouping = Acts::future::BinnedSPGroup( + spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, + m_bottomBinFinder, m_topBinFinder, std::move(futureGrid), rRangeSPExtent, + m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); + // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); @@ -303,15 +315,57 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( } } + std::size_t counter = 0ul; + + auto start_nominal = std::chrono::high_resolution_clock::now(); for (const auto [bottom, middle, top] : spacePointsGrouping) { - m_seedFinder.createSeedsForGroup( - m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), - std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); + // m_seedFinder.createSeedsForGroup( + // m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), + // std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); + // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; } + auto stop_nominal = std::chrono::high_resolution_clock::now(); + + counter = 0ul; + auto start_modified = std::chrono::high_resolution_clock::now(); + for (const auto [bottom, middle, top] : futureSpacePointsGrouping) { + // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; + } + auto stop_modified = std::chrono::high_resolution_clock::now(); + + auto duration_nominal = std::chrono::duration_cast(stop_nominal - start_nominal).count(); + auto duration_modified = std::chrono::duration_cast(stop_modified - start_modified).count(); + std::cout << "Nominal: " << duration_nominal << std::endl; + std::cout << "Modified: " << duration_modified << std::endl; + ACTS_DEBUG("Created " << seeds.size() << " track seeds from " << spacePointPtrs.size() << " space points"); + + + + // * ----------------------- + /* + std::cout << "Making iterator for grid" << std::endl; + std::array, 2> navigation; + navigation[0].resize(spacePointsGrouping.grid().numLocalBins()[0]); + for (std::size_t i(0); i Date: Thu, 23 Nov 2023 14:10:29 +0100 Subject: [PATCH 031/120] no future --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 28 ++- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 100 +++----- .../Acts/Seeding/FutureBinnedSPGroup.hpp | 140 ----------- .../Acts/Seeding/FutureBinnedSPGroup.ipp | 223 ------------------ 4 files changed, 48 insertions(+), 443 deletions(-) delete mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp delete mode 100644 Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index b04135c202f..816af19a09a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -36,12 +36,14 @@ class BinnedSPGroupIterator { private: enum INDEX : int { PHI = 0, Z = 1 }; - public: +public: // Never take ownerships BinnedSPGroupIterator(BinnedSPGroup&& group, - std::size_t) = delete; + std::array index, + std::array, 2> navigation) = delete; BinnedSPGroupIterator(BinnedSPGroup& group, - std::size_t index); + std::array index, + std::array, 2> navigation); BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; @@ -66,10 +68,10 @@ class BinnedSPGroupIterator { private: // The group, it contains the grid and the bin finders Acts::detail::RefHolder> m_group; - // Max Local Bins - limits of the grid - std::array m_max_localBins; - // Current Local Bins - std::array m_current_localBins{0, 0}; + // Current grid iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + // End iterator + typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator @@ -81,6 +83,8 @@ class BinnedSPGroup { friend BinnedSPGroupIterator; #endif + enum INDEX : int { PHI = 0, Z = 1 }; + public: BinnedSPGroup() = delete; @@ -119,17 +123,17 @@ class BinnedSPGroup { private: // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid; + std::unique_ptr> m_grid {nullptr}; // BinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder; - std::shared_ptr> m_bottomBinFinder; + std::shared_ptr> m_topBinFinder {nullptr}; + std::shared_ptr> m_bottomBinFinder {nullptr}; // Order of z bins to loop over when searching for SPs - std::vector m_bins; + std::array, 2> m_bins {}; // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin; + std::size_t m_skipZMiddleBin {0ul}; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 0f10a0b3483..36362744b5c 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -12,45 +13,33 @@ template Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::BinnedSPGroup& group, std::size_t index) - : m_group(group), m_max_localBins(m_group->m_grid->numLocalBins()) { - m_max_localBins[INDEX::PHI] += 1; - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); - if (index == m_group->m_grid->size()) { - m_current_localBins = m_max_localBins; - } else { - // Go to the next not-empty bin - findNotEmptyBin(); - } + Acts::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) + : m_group(group), + m_gridItr(*group.m_grid.get(), std::move(index), navigation), + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) +{ + findNotEmptyBin(); } template inline Acts::BinnedSPGroupIterator& Acts::BinnedSPGroupIterator::operator++() { - // Increase the position by one - // if we were on the edge, go up one phi bin and reset z bin - if (++m_current_localBins[INDEX::Z] == m_max_localBins[INDEX::Z]) { - ++m_current_localBins[INDEX::PHI]; - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); - } - - // Get the next not-empty bin in the grid + ++m_gridItr; findNotEmptyBin(); return *this; } template inline bool Acts::BinnedSPGroupIterator::operator==( - const Acts::BinnedSPGroupIterator& other) const { - return m_group.ptr == other.m_group.ptr && - m_current_localBins[INDEX::PHI] == - other.m_current_localBins[INDEX::PHI] && - m_current_localBins[INDEX::Z] == other.m_current_localBins[INDEX::Z]; + const Acts::BinnedSPGroupIterator& other) const { + return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } template inline bool Acts::BinnedSPGroupIterator::operator!=( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return !(*this == other); } @@ -59,19 +48,18 @@ std::tuple, std::size_t, boost::container::small_vector> Acts::BinnedSPGroupIterator::operator*() const { // Global Index - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins( - {m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]]}); - + std::array localPosition = m_gridItr.localPosition(); + std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); + boost::container::small_vector bottoms = m_group->m_bottomBinFinder->findBins( - m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]], + localPosition[INDEX::PHI], + localPosition[INDEX::Z], m_group->m_grid.get()); boost::container::small_vector tops = m_group->m_topBinFinder->findBins( - m_current_localBins[INDEX::PHI], - m_group->m_bins[m_current_localBins[INDEX::Z]], + localPosition[INDEX::PHI], + localPosition[INDEX::Z], m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. @@ -89,37 +77,13 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { + if (m_gridItr == m_gridItrEnd) return; // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward - - for (std::size_t phiBin(m_current_localBins[INDEX::PHI]); - phiBin < m_max_localBins[INDEX::PHI]; ++phiBin) { - // 0 is the underflow - skip - if (phiBin == 0) { - continue; - } - - for (std::size_t zBin(m_current_localBins[INDEX::Z]); - zBin < m_max_localBins[INDEX::Z]; ++zBin) { - std::size_t zBinIndex = m_group->m_bins[zBin]; - std::size_t index = - m_group->m_grid->globalBinFromLocalBins({phiBin, zBinIndex}); - // Check if there are entries in this bin - if (m_group->m_grid->at(index).empty()) { - continue; - } - - // Set the new current bins - m_current_localBins[INDEX::PHI] = phiBin; - m_current_localBins[INDEX::Z] = zBin; - return; - } - // Reset z-index - m_current_localBins[INDEX::Z] = m_group->skipZMiddleBin(); + std::size_t dimCollection = (*m_gridItr).size(); + while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + dimCollection = (*m_gridItr).size(); } - - // Could find nothing ... setting this to end() - m_current_localBins = m_max_localBins; } // Binned SP Group @@ -231,13 +195,13 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_topBinFinder = tBinFinder; m_skipZMiddleBin = config.skipZMiddleBinSearch; - m_bins = config.zBinsCustomLooping; - if (m_bins.empty()) { + m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); + m_bins[INDEX::Z] = config.zBinsCustomLooping; + if (m_bins[INDEX::Z].empty()) { std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins.reserve(nZbins); - for (std::size_t i(0); i < nZbins; ++i) { - m_bins.push_back(i + 1); - } + m_bins[INDEX::Z].resize(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); } } @@ -249,11 +213,11 @@ inline std::size_t Acts::BinnedSPGroup::size() const { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::begin() { - return {*this, 0}; + return {*this, {0ul, 0ul}, m_bins}; } template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - return {*this, m_grid->size()}; + return {*this, m_grid->numLocalBins(), m_bins}; } diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp deleted file mode 100644 index 7c6d7f63147..00000000000 --- a/Core/include/Acts/Seeding/FutureBinnedSPGroup.hpp +++ /dev/null @@ -1,140 +0,0 @@ -// This file is part of the Acts project. -// -// Copyright (C) 2023 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinFinder.hpp" -#include "Acts/Seeding/InternalSeed.hpp" -#include "Acts/Seeding/Seed.hpp" -#include "Acts/Seeding/SeedFinderConfig.hpp" -#include "Acts/Seeding/SpacePointGrid.hpp" -#include "Acts/Utilities/Holders.hpp" - -#include -#include - -#include - -namespace Acts::future { -template -class BinnedSPGroup; - -/// @c BinnedSPGroupIterator Allows to iterate over all groups of bins -/// a provided BinFinder can generate for each bin of a provided SPGrid - -/// SpacePointGrid is a very specific structure. -/// We know it is 2D and what it contains -/// No need to be too general with this class -template -class BinnedSPGroupIterator { - private: - enum INDEX : int { PHI = 0, Z = 1 }; - -public: - // Never take ownerships - BinnedSPGroupIterator(BinnedSPGroup&& group, - std::array index, - std::array, 2> navigation) = delete; - BinnedSPGroupIterator(BinnedSPGroup& group, - std::array index, - std::array, 2> navigation); - - BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; - BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; - - BinnedSPGroupIterator(BinnedSPGroupIterator&&) noexcept = default; - BinnedSPGroupIterator& operator=(BinnedSPGroupIterator&&) noexcept = default; - - ~BinnedSPGroupIterator() = default; - - BinnedSPGroupIterator& operator++(); - - bool operator==(const BinnedSPGroupIterator& other) const; - bool operator!=(const BinnedSPGroupIterator& other) const; - - std::tuple, std::size_t, - boost::container::small_vector> - operator*() const; - - private: - void findNotEmptyBin(); - - private: - // The group, it contains the grid and the bin finders - Acts::detail::RefHolder> m_group; - // Current grid iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItr; - // End iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; -}; - -/// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator -/// for given BinFinders and SpacePointGrid. -/// Fulfills the range_expression interface. -template -class BinnedSPGroup { -#ifndef DOXYGEN - friend BinnedSPGroupIterator; -#endif - - enum INDEX : int { PHI = 0, Z = 1 }; - - public: - BinnedSPGroup() = delete; - - template - BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> - botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& _config, - const SeedFinderOptions& _options); - - BinnedSPGroup(const BinnedSPGroup&) = delete; - BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; - - BinnedSPGroup(BinnedSPGroup&&) noexcept = default; - BinnedSPGroup& operator=(BinnedSPGroup&&) noexcept = default; - - ~BinnedSPGroup() = default; - - std::size_t size() const; - - BinnedSPGroupIterator begin(); - BinnedSPGroupIterator end(); - - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } - - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } - - private: - // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid {nullptr}; - - // BinFinder must return std::vector with content of - // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder {nullptr}; - std::shared_ptr> m_bottomBinFinder {nullptr}; - - // Order of z bins to loop over when searching for SPs - std::array, 2> m_bins {}; - // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin {0ul}; -}; - -} // namespace Acts -#include "Acts/Seeding/FutureBinnedSPGroup.ipp" diff --git a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp b/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp deleted file mode 100644 index 7968ec14963..00000000000 --- a/Core/include/Acts/Seeding/FutureBinnedSPGroup.ipp +++ /dev/null @@ -1,223 +0,0 @@ -// -*- C++ -*- -// This file is part of the Acts project. -// -// Copyright (C) 2023 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -// Binned SP Group Iterator - -#include - -template -Acts::future::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::future::BinnedSPGroup& group, - std::array index, - std::array, 2> navigation) - : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) -{ - findNotEmptyBin(); -} - -template -inline Acts::future::BinnedSPGroupIterator& -Acts::future::BinnedSPGroupIterator::operator++() { - ++m_gridItr; - findNotEmptyBin(); - return *this; -} - -template -inline bool Acts::future::BinnedSPGroupIterator::operator==( - const Acts::future::BinnedSPGroupIterator& other) const { - return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; -} - -template -inline bool Acts::future::BinnedSPGroupIterator::operator!=( - const Acts::future::BinnedSPGroupIterator& other) const { - return !(*this == other); -} - -template -std::tuple, std::size_t, - boost::container::small_vector> -Acts::future::BinnedSPGroupIterator::operator*() const { - // Global Index - std::array localPosition = m_gridItr.localPosition(); - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); - - boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); - boost::container::small_vector tops = - m_group->m_topBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); - - // GCC12+ in Release throws an overread warning here due to the move. - // This is from inside boost code, so best we can do is to suppress it. -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overread" -#endif - return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic pop -#endif -} - -template -inline void -Acts::future::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) return; - // Iterate on the grid till we find a not-empty bin - // We start from the current bin configuration and move forward - std::size_t dimCollection = (*m_gridItr).size(); - while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { - dimCollection = (*m_gridItr).size(); - } -} - -// Binned SP Group -template -template -Acts::future::BinnedSPGroup::BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& config, - const SeedFinderOptions& options) { - if (!config.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); - } - if (!options.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); - } - static_assert( - std::is_same< - typename std::iterator_traits::value_type, - const external_spacepoint_t*>::value, - "Iterator does not contain type this class was templated with"); - - // get region of interest (or full detector if configured accordingly) - float phiMin = config.phiMin; - float phiMax = config.phiMax; - float zMin = config.zMin; - float zMax = config.zMax; - - // sort by radius - // add magnitude of beamPos to rMax to avoid excluding measurements - // create number of bins equal to number of millimeters rMax - // (worst case minR: configured minR + 1mm) - // binSizeR allows to increase or reduce numRBins if needed - std::size_t numRBins = static_cast( - (config.rMax + options.beamPos.norm()) / config.binSizeR); - - // keep track of changed bins while sorting - boost::container::flat_set rBinsIndex; - - std::size_t counter = 0; - for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { - if (*it == nullptr) { - continue; - } - const external_spacepoint_t& sp = **it; - const auto& [spPosition, variance] = - toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); - - float spX = spPosition[0]; - float spY = spPosition[1]; - float spZ = spPosition[2]; - - // store x,y,z values in extent - rRangeSPExtent.extend({spX, spY, spZ}); - - // remove SPs outside z and phi region - if (spZ > zMax || spZ < zMin) { - continue; - } - float spPhi = std::atan2(spY, spX); - if (spPhi > phiMax || spPhi < phiMin) { - continue; - } - - auto isp = std::make_unique>( - counter, sp, spPosition, options.beamPos, variance); - // calculate r-Bin index and protect against overflow (underflow not - // possible) - std::size_t rIndex = - static_cast(isp->radius() / config.binSizeR); - // if index out of bounds, the SP is outside the region of interest - if (rIndex >= numRBins) { - continue; - } - - // fill rbins into grid - Acts::Vector2 spLocation(isp->phi(), isp->z()); - std::vector>>& - rbin = grid->atPosition(spLocation); - rbin.push_back(std::move(isp)); - - // keep track of the bins we modify so that we can later sort the SPs in - // those bins only - if (rbin.size() > 1) { - rBinsIndex.insert(grid->globalBinFromPosition(spLocation)); - } - } - - // sort SPs in R for each filled (z, phi) bin - for (auto& binIndex : rBinsIndex) { - std::vector>>& - rbin = grid->atPosition(binIndex); - std::sort( - rbin.begin(), rbin.end(), - [](std::unique_ptr>& a, - std::unique_ptr>& b) { - return a->radius() < b->radius(); - }); - } - - m_grid = std::move(grid); - m_bottomBinFinder = botBinFinder; - m_topBinFinder = tBinFinder; - - m_skipZMiddleBin = config.skipZMiddleBinSearch; - m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); - std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); - m_bins[INDEX::Z] = config.zBinsCustomLooping; - if (m_bins[INDEX::Z].empty()) { - std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins[INDEX::Z].resize(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); - } -} - -template -inline std::size_t Acts::future::BinnedSPGroup::size() const { - return m_grid->size(); -} - -template -inline Acts::future::BinnedSPGroupIterator -Acts::future::BinnedSPGroup::begin() { - return {*this, {0ul, 0ul}, m_bins}; -} - -template -inline Acts::future::BinnedSPGroupIterator -Acts::future::BinnedSPGroup::end() { - return {*this, m_grid->numLocalBins(), m_bins}; -} From cc20c8d7669df9d140778b17d51ed7f4ea415304 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 23 Nov 2023 14:29:35 +0100 Subject: [PATCH 032/120] minor --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 1 + .../TrackFinding/src/SeedingAlgorithm.cpp | 60 +------------------ 2 files changed, 4 insertions(+), 57 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 816af19a09a..3f12619a03e 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -14,6 +14,7 @@ #include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" #include diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index f64dcaa9690..348f2ecd427 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -13,7 +13,6 @@ #include "Acts/Geometry/Extent.hpp" #include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" -#include "Acts/Seeding/FutureBinnedSPGroup.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Utilities/BinningType.hpp" @@ -22,8 +21,6 @@ #include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Range1D.hpp" #include "ActsExamples/EventData/SimSeed.hpp" -#include "Acts/Utilities/GridIterator.hpp" -#include "Acts/Seeding/InternalSpacePoint.hpp" #include #include @@ -32,7 +29,6 @@ #include #include #include -#include namespace ActsExamples { struct AlgorithmContext; @@ -256,19 +252,11 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( auto grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); - auto futureGrid = Acts::SpacePointGridCreator::createGrid( - m_cfg.gridConfig, m_cfg.gridOptions); - auto spacePointsGrouping = Acts::BinnedSPGroup( spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, m_bottomBinFinder, m_topBinFinder, std::move(grid), rRangeSPExtent, m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); - auto futureSpacePointsGrouping = Acts::future::BinnedSPGroup( - spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, - m_bottomBinFinder, m_topBinFinder, std::move(futureGrid), rRangeSPExtent, - m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); - // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); @@ -315,57 +303,15 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( } } - std::size_t counter = 0ul; - - auto start_nominal = std::chrono::high_resolution_clock::now(); for (const auto [bottom, middle, top] : spacePointsGrouping) { - // m_seedFinder.createSeedsForGroup( - // m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), - // std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); - // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; + m_seedFinder.createSeedsForGroup( + m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(), + std::back_inserter(seeds), bottom, middle, top, rMiddleSPRange); } - auto stop_nominal = std::chrono::high_resolution_clock::now(); - - counter = 0ul; - auto start_modified = std::chrono::high_resolution_clock::now(); - for (const auto [bottom, middle, top] : futureSpacePointsGrouping) { - // std::cout << (counter++) << " : bottom.size, middle, top.size: " << bottom.size() << " " << middle << " " << top.size() << std::endl; - } - auto stop_modified = std::chrono::high_resolution_clock::now(); - - auto duration_nominal = std::chrono::duration_cast(stop_nominal - start_nominal).count(); - auto duration_modified = std::chrono::duration_cast(stop_modified - start_modified).count(); - std::cout << "Nominal: " << duration_nominal << std::endl; - std::cout << "Modified: " << duration_modified << std::endl; - ACTS_DEBUG("Created " << seeds.size() << " track seeds from " << spacePointPtrs.size() << " space points"); - - - - // * ----------------------- - /* - std::cout << "Making iterator for grid" << std::endl; - std::array, 2> navigation; - navigation[0].resize(spacePointsGrouping.grid().numLocalBins()[0]); - for (std::size_t i(0); i Date: Thu, 23 Nov 2023 14:31:29 +0100 Subject: [PATCH 033/120] format --- CMakeLists.txt | 4 +- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 35 +- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 38 +- Core/include/Acts/Utilities/Grid.hpp | 35 +- Core/include/Acts/Utilities/GridIterator.hpp | 225 ++++----- Core/include/Acts/Utilities/GridIterator.ipp | 489 ++++++++++--------- 6 files changed, 413 insertions(+), 413 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea55dfa860..352c1303432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,14 +58,14 @@ option(ACTS_BUILD_FATRAS_GEANT4 "Build Geant4 Fatras package" OFF) # alignment related options option(ACTS_BUILD_ALIGNMENT "Build Alignment package" OFF) # examples related options -option(ACTS_BUILD_EXAMPLES "Build standalone examples" ON) +option(ACTS_BUILD_EXAMPLES "Build standalone examples" OFF) option(ACTS_BUILD_EXAMPLES_DD4HEP "Build DD4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EDM4HEP "Build EDM4hep-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_EXATRKX "Build the Exa.TrkX example code" OFF) option(ACTS_BUILD_EXAMPLES_GEANT4 "Build Geant4-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_HEPMC3 "Build HepMC3-based code in the examples" OFF) option(ACTS_BUILD_EXAMPLES_PYTHIA8 "Build Pythia8-based code in the examples" OFF) -option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" ON) +option(ACTS_BUILD_EXAMPLES_PYTHON_BINDINGS "Build python bindings for the examples" OFF) option(ACTS_BUILD_EXAMPLES_BINARIES "Build the examples binaries (deprecated)" OFF) option(ACTS_USE_SYSTEM_PYBIND11 "Use a system installation of pybind11" ${ACTS_USE_SYSTEM_LIBS} ) option(ACTS_USE_EXAMPLES_TBB "Use Threading Building Blocks library in the examples" ON) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3f12619a03e..3c183c0835d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -37,14 +37,15 @@ class BinnedSPGroupIterator { private: enum INDEX : int { PHI = 0, Z = 1 }; -public: + public: // Never take ownerships BinnedSPGroupIterator(BinnedSPGroup&& group, std::array index, - std::array, 2> navigation) = delete; + std::array, 2> navigation) = + delete; BinnedSPGroupIterator(BinnedSPGroup& group, std::array index, - std::array, 2> navigation); + std::array, 2> navigation); BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; @@ -70,9 +71,11 @@ class BinnedSPGroupIterator { // The group, it contains the grid and the bin finders Acts::detail::RefHolder> m_group; // Current grid iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItr; + typename Acts::SpacePointGrid::local_iterator_t + m_gridItr; // End iterator - typename Acts::SpacePointGrid::local_iterator_t m_gridItrEnd; + typename Acts::SpacePointGrid::local_iterator_t + m_gridItrEnd; }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator @@ -85,7 +88,7 @@ class BinnedSPGroup { #endif enum INDEX : int { PHI = 0, Z = 1 }; - + public: BinnedSPGroup() = delete; @@ -114,27 +117,25 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } + Acts::SpacePointGrid& grid() { return *m_grid.get(); } - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } + std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } private: // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid {nullptr}; + std::unique_ptr> m_grid{nullptr}; // BinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder {nullptr}; - std::shared_ptr> m_bottomBinFinder {nullptr}; + std::shared_ptr> m_topBinFinder{ + nullptr}; + std::shared_ptr> m_bottomBinFinder{ + nullptr}; // Order of z bins to loop over when searching for SPs - std::array, 2> m_bins {}; + std::array, 2> m_bins{}; // Number of Z bins to skip the search for middle SP - std::size_t m_skipZMiddleBin {0ul}; + std::size_t m_skipZMiddleBin{0ul}; }; } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 36362744b5c..85c60ca74a9 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -13,14 +13,14 @@ template Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::BinnedSPGroup& group, - std::array index, - std::array, 2> navigation) + Acts::BinnedSPGroup& group, + std::array index, + std::array, 2> navigation) : m_group(group), m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), std::move(navigation)) -{ - findNotEmptyBin(); + m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), + std::move(navigation)) { + findNotEmptyBin(); } template @@ -33,13 +33,13 @@ Acts::BinnedSPGroupIterator::operator++() { template inline bool Acts::BinnedSPGroupIterator::operator==( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } template inline bool Acts::BinnedSPGroupIterator::operator!=( - const Acts::BinnedSPGroupIterator& other) const { + const Acts::BinnedSPGroupIterator& other) const { return !(*this == other); } @@ -49,18 +49,17 @@ std::tuple, std::size_t, Acts::BinnedSPGroupIterator::operator*() const { // Global Index std::array localPosition = m_gridItr.localPosition(); - std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); - + std::size_t global_index = + m_group->m_grid->globalBinFromLocalBins(localPosition); + boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); + m_group->m_bottomBinFinder->findBins(localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); boost::container::small_vector tops = - m_group->m_topBinFinder->findBins( - localPosition[INDEX::PHI], - localPosition[INDEX::Z], - m_group->m_grid.get()); + m_group->m_topBinFinder->findBins(localPosition[INDEX::PHI], + localPosition[INDEX::Z], + m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. @@ -77,7 +76,8 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) return; + if (m_gridItr == m_gridItrEnd) + return; // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward std::size_t dimCollection = (*m_gridItr).size(); diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 193c5b74c94..cf6e1d39952 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -21,12 +21,12 @@ #include namespace Acts { - template - class GridGlobalIterator; +template +class GridGlobalIterator; - template - class GridLocalIterator; -} +template +class GridLocalIterator; +} // namespace Acts namespace Acts { @@ -57,10 +57,10 @@ class Grid final { /// index type using local bin indices along each axis using index_t = std::array; /// global iterator type - using global_iterator_t = Acts::GridGlobalIterator; + using global_iterator_t = Acts::GridGlobalIterator; /// local iterator type - using local_iterator_t = Acts::GridLocalIterator; - + using local_iterator_t = Acts::GridLocalIterator; + /// @brief default constructor /// /// @param [in] axes actual axis objects spanning the grid @@ -469,27 +469,24 @@ class Grid final { return detail::grid_helper::getAxes(m_axes); } - - global_iterator_t begin() const { - return global_iterator_t(*this, 0); - } + global_iterator_t begin() const { return global_iterator_t(*this, 0); } - global_iterator_t end() const { - return global_iterator_t(*this, size()); - } + global_iterator_t end() const { return global_iterator_t(*this, size()); } - local_iterator_t begin(const std::array, DIM>& navigator) const { + local_iterator_t begin( + const std::array, DIM>& navigator) const { std::array localBin; - for (std::size_t i(0); i, DIM>& navigator) const { + local_iterator_t end( + const std::array, DIM>& navigator) const { return local_iterator_t(*this, numLocalBins(), navigator); } - + private: /// set of axis defining the multi-dimensional grid std::tuple m_axes; diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index a4cf195730e..4bc33755e3e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -15,117 +15,118 @@ namespace Acts { - // Using Global iterator, including over/under flow bins - template - class GridGlobalIterator { - public: - static constexpr std::size_t DIM = sizeof...(Axes); - - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - GridGlobalIterator(Acts::Grid&& grid, - std::size_t idx) = delete; - GridGlobalIterator(const Acts::Grid& grid, - std::size_t idx = 0ul); - - GridGlobalIterator(const GridGlobalIterator& other) = default; - GridGlobalIterator& operator=(const GridGlobalIterator& other) = default; - - GridGlobalIterator(GridGlobalIterator&& other) noexcept; - GridGlobalIterator& operator=(GridGlobalIterator&& other) noexcept; - - ~GridGlobalIterator() = default; - - bool operator==(const GridGlobalIterator& other) const; - bool operator!=(const GridGlobalIterator& other) const; - - bool operator<(const GridGlobalIterator& other) const; - bool operator>(const GridGlobalIterator& other) const; - bool operator<=(const GridGlobalIterator& other) const; - bool operator>=(const GridGlobalIterator& other) const; - - GridGlobalIterator& operator+=(const std::size_t offset); - GridGlobalIterator& operator-=(const std::size_t offset); - GridGlobalIterator operator+(const std::size_t offset) const; - GridGlobalIterator operator-(const std::size_t offset) const; - - difference_type operator-(const GridGlobalIterator& other) const; - const value_type& operator*() const; - - GridGlobalIterator& operator++(); - GridGlobalIterator operator++(int); - - private: - Acts::detail::RefHolder> m_grid {nullptr}; - std::size_t m_idx {0ul}; - }; - - - // Using Local iterator, excluding over/under flow bins - // Can also allow for custom navigation pattern along axes - template - class GridLocalIterator { - public: - static constexpr std::size_t DIM = sizeof...(Axes); - - using iterator_category = std::random_access_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - GridLocalIterator(Acts::Grid&& grid, - std::array indexes) = delete; - GridLocalIterator(Acts::Grid&& grid, - std::array indexes, - std::array, DIM> navigation) = delete; - GridLocalIterator(const Acts::Grid& grid, - std::array indexes); - GridLocalIterator(const Acts::Grid& grid, - std::array indexes, - std::array, DIM> navigation); - - GridLocalIterator(const GridLocalIterator& other) = default; - GridLocalIterator& operator=(const GridLocalIterator& other) = default; - - GridLocalIterator(GridLocalIterator&& other) noexcept; - GridLocalIterator& operator=(GridLocalIterator&& other) noexcept; - - ~GridLocalIterator() = default; - - bool operator==(const Acts::GridLocalIterator& other) const; - bool operator!=(const Acts::GridLocalIterator& other) const; - - bool operator<(const Acts::GridLocalIterator& other) const; - bool operator>(const Acts::GridLocalIterator& other) const; - bool operator<=(const Acts::GridLocalIterator& other) const; - bool operator>=(const Acts::GridLocalIterator& other) const; - - difference_type operator-(const GridLocalIterator& other) const; - - const value_type& operator*() const; - - GridLocalIterator& operator++(); - GridLocalIterator operator++(int); - - std::array localPosition() const; - - private: - template - void increment(); - - private: - Acts::detail::RefHolder> m_grid {nullptr}; - std::array m_numLocalBins {}; - std::array m_currentIndex {}; - std::array m_localPosition {}; - std::array, DIM> m_navigationIndex {}; - }; - -} // namespace Acts +// Using Global iterator, including over/under flow bins +template +class GridGlobalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridGlobalIterator(Acts::Grid&& grid, std::size_t idx) = delete; + GridGlobalIterator(const Acts::Grid& grid, std::size_t idx = 0ul); + + GridGlobalIterator(const GridGlobalIterator& other) = default; + GridGlobalIterator& operator=( + const GridGlobalIterator& other) = default; + + GridGlobalIterator(GridGlobalIterator&& other) noexcept; + GridGlobalIterator& operator=( + GridGlobalIterator&& other) noexcept; + + ~GridGlobalIterator() = default; + + bool operator==(const GridGlobalIterator& other) const; + bool operator!=(const GridGlobalIterator& other) const; + + bool operator<(const GridGlobalIterator& other) const; + bool operator>(const GridGlobalIterator& other) const; + bool operator<=(const GridGlobalIterator& other) const; + bool operator>=(const GridGlobalIterator& other) const; + + GridGlobalIterator& operator+=(const std::size_t offset); + GridGlobalIterator& operator-=(const std::size_t offset); + GridGlobalIterator operator+(const std::size_t offset) const; + GridGlobalIterator operator-(const std::size_t offset) const; + + difference_type operator-(const GridGlobalIterator& other) const; + const value_type& operator*() const; + + GridGlobalIterator& operator++(); + GridGlobalIterator operator++(int); + + private: + Acts::detail::RefHolder> m_grid{nullptr}; + std::size_t m_idx{0ul}; +}; + +// Using Local iterator, excluding over/under flow bins +// Can also allow for custom navigation pattern along axes +template +class GridLocalIterator { + public: + static constexpr std::size_t DIM = sizeof...(Axes); + + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + GridLocalIterator(Acts::Grid&& grid, + std::array indexes) = delete; + GridLocalIterator( + Acts::Grid&& grid, std::array indexes, + std::array, DIM> navigation) = delete; + GridLocalIterator(const Acts::Grid& grid, + std::array indexes); + GridLocalIterator(const Acts::Grid& grid, + std::array indexes, + std::array, DIM> navigation); + + GridLocalIterator(const GridLocalIterator& other) = default; + GridLocalIterator& operator=( + const GridLocalIterator& other) = default; + + GridLocalIterator(GridLocalIterator&& other) noexcept; + GridLocalIterator& operator=( + GridLocalIterator&& other) noexcept; + + ~GridLocalIterator() = default; + + bool operator==(const Acts::GridLocalIterator& other) const; + bool operator!=(const Acts::GridLocalIterator& other) const; + + bool operator<(const Acts::GridLocalIterator& other) const; + bool operator>(const Acts::GridLocalIterator& other) const; + bool operator<=(const Acts::GridLocalIterator& other) const; + bool operator>=(const Acts::GridLocalIterator& other) const; + + difference_type operator-(const GridLocalIterator& other) const; + + const value_type& operator*() const; + + GridLocalIterator& operator++(); + GridLocalIterator operator++(int); + + std::array localPosition() const; + + private: + template + void increment(); + + private: + Acts::detail::RefHolder> m_grid{nullptr}; + std::array m_numLocalBins{}; + std::array m_currentIndex{}; + std::array m_localPosition{}; + std::array, DIM> m_navigationIndex{}; +}; + +} // namespace Acts #include "Acts/Utilities/GridIterator.ipp" diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 9ade6910cfe..bc2af987498 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -10,265 +10,266 @@ #include namespace Acts { - // Global Iterator - template - GridGlobalIterator::GridGlobalIterator(const Acts::Grid& grid, - std::size_t idx) - : m_grid( &grid ), - m_idx( idx ) - {} - - template - GridGlobalIterator::GridGlobalIterator(GridGlobalIterator&& other) noexcept - : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), - m_idx( other.m_idx ) - {} - - template - GridGlobalIterator& - GridGlobalIterator::operator=(GridGlobalIterator&& other) noexcept - { - m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_idx = other.m_idx; - return *this; - } +// Global Iterator +template +GridGlobalIterator::GridGlobalIterator( + const Acts::Grid& grid, std::size_t idx) + : m_grid(&grid), m_idx(idx) {} - template - bool GridGlobalIterator::operator==(const GridGlobalIterator& other) const - { - return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; - } - - template - bool GridGlobalIterator::operator!=(const GridGlobalIterator& other) const - { - return !(*this == other); - } - - template - bool GridGlobalIterator::operator<(const GridGlobalIterator& other) const - { return m_idx < other.m_idx; } - - template - bool GridGlobalIterator::operator>(const GridGlobalIterator& other) const - { return m_idx > other.m_idx; } - - template - bool GridGlobalIterator::operator<=(const GridGlobalIterator& other) const - { return !(*this > other); } - - template - bool GridGlobalIterator::operator>=(const GridGlobalIterator& other) const - { return !(*this < other); } - - template - GridGlobalIterator& - GridGlobalIterator::operator+=(const std::size_t offset) - { - m_idx += offset; - return *this; - } - - template - GridGlobalIterator& - GridGlobalIterator::operator-=(const std::size_t offset) - { - m_idx -= offset; - return *this; - } - - template - GridGlobalIterator - GridGlobalIterator::operator+(const std::size_t offset) const - { - return {m_grid.ptr, m_idx + offset}; - } - - template - GridGlobalIterator - GridGlobalIterator::operator-(const std::size_t offset) const - { - return {m_grid.ptr, m_idx - offset}; - } - - template - typename GridGlobalIterator::difference_type - GridGlobalIterator::operator-(const GridGlobalIterator& other) const { - assert(other > *this); - return other.m_idx - m_idx; - } - - template - const typename GridGlobalIterator::value_type& - GridGlobalIterator::operator*() const - { - return m_grid->at(m_idx); - } - - template - GridGlobalIterator& - GridGlobalIterator::operator++() { - ++m_idx; - return *this; - } +template +GridGlobalIterator::GridGlobalIterator( + GridGlobalIterator&& other) noexcept + : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_idx(other.m_idx) {} - template - GridGlobalIterator - GridGlobalIterator::operator++(int) { - GridGlobalIterator output(m_grid, m_idx++); - return output; - } - - - - - - - // Local Iterator - template - Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, - std::array indexes) - : m_grid( &grid ), - m_numLocalBins( std::move(grid.numLocalBins()) ), - m_currentIndex( std::move(indexes) ) - { - for (std::size_t i(0); i +GridGlobalIterator& GridGlobalIterator::operator=( + GridGlobalIterator&& other) noexcept { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_idx = other.m_idx; + return *this; +} + +template +bool GridGlobalIterator::operator==( + const GridGlobalIterator& other) const { + return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; +} + +template +bool GridGlobalIterator::operator!=( + const GridGlobalIterator& other) const { + return !(*this == other); +} + +template +bool GridGlobalIterator::operator<( + const GridGlobalIterator& other) const { + return m_idx < other.m_idx; +} + +template +bool GridGlobalIterator::operator>( + const GridGlobalIterator& other) const { + return m_idx > other.m_idx; +} + +template +bool GridGlobalIterator::operator<=( + const GridGlobalIterator& other) const { + return !(*this > other); +} + +template +bool GridGlobalIterator::operator>=( + const GridGlobalIterator& other) const { + return !(*this < other); +} + +template +GridGlobalIterator& GridGlobalIterator::operator+=( + const std::size_t offset) { + m_idx += offset; + return *this; +} + +template +GridGlobalIterator& GridGlobalIterator::operator-=( + const std::size_t offset) { + m_idx -= offset; + return *this; +} + +template +GridGlobalIterator GridGlobalIterator::operator+( + const std::size_t offset) const { + return {m_grid.ptr, m_idx + offset}; +} + +template +GridGlobalIterator GridGlobalIterator::operator-( + const std::size_t offset) const { + return {m_grid.ptr, m_idx - offset}; +} + +template +typename GridGlobalIterator::difference_type +GridGlobalIterator::operator-( + const GridGlobalIterator& other) const { + assert(other > *this); + return other.m_idx - m_idx; +} + +template +const typename GridGlobalIterator::value_type& +GridGlobalIterator::operator*() const { + return m_grid->at(m_idx); +} + +template +GridGlobalIterator& GridGlobalIterator::operator++() { + ++m_idx; + return *this; +} + +template +GridGlobalIterator GridGlobalIterator::operator++(int) { + GridGlobalIterator output(m_grid, m_idx++); + return output; +} + +// Local Iterator +template +Acts::GridLocalIterator::GridLocalIterator( + const Acts::Grid& grid, std::array indexes) + : m_grid(&grid), + m_numLocalBins(std::move(grid.numLocalBins())), + m_currentIndex(std::move(indexes)) { + for (std::size_t i(0); i < DIM; ++i) { + m_navigationIndex[i].resize(m_numLocalBins[i]); + std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); + m_localPosition[i] = 1ul; } +} - template - Acts::GridLocalIterator::GridLocalIterator(const Acts::Grid& grid, - std::array indexes, - std::array, DIM> navigation) - : m_grid( &grid ), - m_numLocalBins( std::move(grid.numLocalBins()) ), - m_currentIndex( std::move(indexes) ), - m_navigationIndex( std::move(navigation) ) - { - // check navigation consistency - for (std::size_t i(0); i +Acts::GridLocalIterator::GridLocalIterator( + const Acts::Grid& grid, std::array indexes, + std::array, DIM> navigation) + : m_grid(&grid), + m_numLocalBins(std::move(grid.numLocalBins())), + m_currentIndex(std::move(indexes)), + m_navigationIndex(std::move(navigation)) { + // check navigation consistency + for (std::size_t i(0); i < DIM; ++i) { + if (m_navigationIndex[i].size() != m_numLocalBins[i]) { + throw std::invalid_argument( + "Invalid navigation sequence in local grid iterator."); } + m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } - - template - Acts::GridLocalIterator::GridLocalIterator(Acts::GridLocalIterator&& other) noexcept - : m_grid( std::exchange(other.m_grid.ptr, nullptr) ), - m_numLocalBins( std::move(other.m_numLocalBins) ), - m_currentIndex( std::move(other.m_currentIndex) ), - m_navigationIndex( std::move(other.m_navigationIndex) ), - m_localPosition( std::move(other.m_localPosition) ) - {} - - template - Acts::GridLocalIterator& - Acts::GridLocalIterator::operator=(Acts::GridLocalIterator&& other) noexcept - { - m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_numLocalBins = std::move(other.m_numLocalBins); - m_currentIndex = std::move(other.m_currentIndex); - m_navigationIndex = std::move(other.m_navigationIndex); - m_localPosition = std::move(other.m_localPosition); - return *this; +} + +template +Acts::GridLocalIterator::GridLocalIterator( + Acts::GridLocalIterator&& other) noexcept + : m_grid(std::exchange(other.m_grid.ptr, nullptr)), + m_numLocalBins(std::move(other.m_numLocalBins)), + m_currentIndex(std::move(other.m_currentIndex)), + m_navigationIndex(std::move(other.m_navigationIndex)), + m_localPosition(std::move(other.m_localPosition)) {} + +template +Acts::GridLocalIterator& +Acts::GridLocalIterator::operator=( + Acts::GridLocalIterator&& other) noexcept { + m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); + m_numLocalBins = std::move(other.m_numLocalBins); + m_currentIndex = std::move(other.m_currentIndex); + m_navigationIndex = std::move(other.m_navigationIndex); + m_localPosition = std::move(other.m_localPosition); + return *this; +} + +template +bool Acts::GridLocalIterator::operator==( + const Acts::GridLocalIterator& other) const { + if (m_grid.ptr != other.m_grid.ptr) { + return false; } - - template - bool Acts::GridLocalIterator::operator==(const Acts::GridLocalIterator& other) const - { - if (m_grid.ptr != other.m_grid.ptr) { + + for (std::size_t i(0); i < DIM; ++i) { + if (m_currentIndex[i] != other.m_currentIndex[i]) { return false; } - - for (std::size_t i(0); i - bool Acts::GridLocalIterator::operator!=(const Acts::GridLocalIterator& other) const - { return ! (*this == other); } - - template - bool Acts::GridLocalIterator::operator<(const GridLocalIterator& other) const - { return m_grid.globalBinFromLocalBins(m_currentIndex) < other.m_grid.globalBinFromLocalBins(m_currentIndex); } - - template - bool Acts::GridLocalIterator::operator>(const GridLocalIterator& other) const - { return m_grid.globalBinFromLocalBins(m_currentIndex) > other.m_grid.globalBinFromLocalBins(m_currentIndex); } - - template - bool Acts::GridLocalIterator::operator<=(const GridLocalIterator& other) const - { return ! (*this > other); } - - template - bool Acts::GridLocalIterator::operator>=(const GridLocalIterator& other) const - { return ! (*this < other); } - - template - typename Acts::GridLocalIterator::difference_type - Acts::GridLocalIterator::operator-(const Acts::GridLocalIterator& other) const - { return other.m_grid->globalBinFromLocalBins(m_currentIndex) - m_grid->globalBinFromLocalBins(m_currentIndex); } - - template - const typename Acts::GridLocalIterator::value_type& - Acts::GridLocalIterator::operator*() const - { - std::array localPositionBin; - for (std::size_t i(0); iatLocalBins(localPositionBin); } - template - GridLocalIterator& - GridLocalIterator::operator++() - { - increment(); - return *this; - } + return true; +} + +template +bool Acts::GridLocalIterator::operator!=( + const Acts::GridLocalIterator& other) const { + return !(*this == other); +} + +template +bool Acts::GridLocalIterator::operator<( + const GridLocalIterator& other) const { + return m_grid.globalBinFromLocalBins(m_currentIndex) < + other.m_grid.globalBinFromLocalBins(m_currentIndex); +} + +template +bool Acts::GridLocalIterator::operator>( + const GridLocalIterator& other) const { + return m_grid.globalBinFromLocalBins(m_currentIndex) > + other.m_grid.globalBinFromLocalBins(m_currentIndex); +} + +template +bool Acts::GridLocalIterator::operator<=( + const GridLocalIterator& other) const { + return !(*this > other); +} + +template +bool Acts::GridLocalIterator::operator>=( + const GridLocalIterator& other) const { + return !(*this < other); +} - template - GridLocalIterator - GridLocalIterator::operator++(int) - { - GridLocalIterator output(m_grid.ptr, m_currentIndex); - this->operator++(); - return output; +template +typename Acts::GridLocalIterator::difference_type +Acts::GridLocalIterator::operator-( + const Acts::GridLocalIterator& other) const { + return other.m_grid->globalBinFromLocalBins(m_currentIndex) - + m_grid->globalBinFromLocalBins(m_currentIndex); +} + +template +const typename Acts::GridLocalIterator::value_type& +Acts::GridLocalIterator::operator*() const { + std::array localPositionBin; + for (std::size_t i(0); i < DIM; ++i) { + localPositionBin[i] = m_navigationIndex[i][m_currentIndex[i]]; } + return m_grid->atLocalBins(localPositionBin); +} - template - template - void GridLocalIterator::increment() { - if (++m_currentIndex[N] < m_numLocalBins[N]) return; - m_currentIndex[N] = 0; - if constexpr (N != 0) { - increment(); - } else { - m_currentIndex = m_numLocalBins; - } +template +GridLocalIterator& GridLocalIterator::operator++() { + increment(); + return *this; +} + +template +GridLocalIterator GridLocalIterator::operator++(int) { + GridLocalIterator output(m_grid.ptr, m_currentIndex); + this->operator++(); + return output; +} + +template +template +void GridLocalIterator::increment() { + if (++m_currentIndex[N] < m_numLocalBins[N]) + return; + m_currentIndex[N] = 0; + if constexpr (N != 0) { + increment(); + } else { + m_currentIndex = m_numLocalBins; } +} - template - std::array::DIM> - GridLocalIterator::localPosition() const - { - std::array output; - for (std::size_t i(0); i +std::array::DIM> +GridLocalIterator::localPosition() const { + std::array output; + for (std::size_t i(0); i < DIM; ++i) { + output[i] = m_navigationIndex[i][m_currentIndex[i]]; } - -} // namespace Acts + return output; +} +} // namespace Acts From 7c9d4e4f019c214c18089ec5b90e1473725c89d4 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 24 Nov 2023 15:29:42 +0100 Subject: [PATCH 034/120] first round of tests --- Core/include/Acts/Utilities/GridIterator.ipp | 2 +- Tests/UnitTests/Core/Utilities/CMakeLists.txt | 1 + .../Core/Utilities/GridIterationTests.cpp | 235 ++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 Tests/UnitTests/Core/Utilities/GridIterationTests.cpp diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index bc2af987498..6272da9a16b 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -254,8 +254,8 @@ template void GridLocalIterator::increment() { if (++m_currentIndex[N] < m_numLocalBins[N]) return; - m_currentIndex[N] = 0; if constexpr (N != 0) { + m_currentIndex[N] = 0; increment(); } else { m_currentIndex = m_numLocalBins; diff --git a/Tests/UnitTests/Core/Utilities/CMakeLists.txt b/Tests/UnitTests/Core/Utilities/CMakeLists.txt index 7e75e042034..78e9e6dcf8a 100644 --- a/Tests/UnitTests/Core/Utilities/CMakeLists.txt +++ b/Tests/UnitTests/Core/Utilities/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(ActsUnitTestBoundingBox PRIVATE std::filesystem) add_unittest(Extendable ExtendableTests.cpp) add_unittest(FiniteStateMachine FiniteStateMachineTests.cpp) add_unittest(Frustum FrustumTest.cpp) +add_unittest(GridIteration GridIterationTests.cpp) add_unittest(Grid GridTests.cpp) add_unittest(Helpers HelpersTests.cpp) add_unittest(Interpolation InterpolationTests.cpp) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp new file mode 100644 index 00000000000..761b4d28a9c --- /dev/null +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -0,0 +1,235 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridIterator.hpp" + +#include + +namespace Acts::Test { + + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + Acts::GridGlobalIterator gridStart = grid.begin(); + Acts::GridGlobalIterator gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + for (std::size_t i(0ul); i<2ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); + } + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + navigation[2ul].resize(nBinsZ); + for (std::size_t i(0ul); i<3ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); + } + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + + BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; + navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + } + +} From 5d7e2ab05988a6b4f4e43f0456b5ae59c7a2f4c1 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 10:45:35 +0100 Subject: [PATCH 035/120] sub iteration --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 26 +++++--- Core/include/Acts/Utilities/Grid.hpp | 6 +- Core/include/Acts/Utilities/GridIterator.hpp | 2 + Core/include/Acts/Utilities/GridIterator.ipp | 19 ++++-- .../Core/Utilities/GridIterationTests.cpp | 61 +++++++++++++++++++ 5 files changed, 97 insertions(+), 17 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 85c60ca74a9..692d61877f4 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -17,9 +16,11 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array index, std::array, 2> navigation) : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation), - m_gridItrEnd(*group.m_grid.get(), group.m_grid->numLocalBins(), - std::move(navigation)) { + m_gridItr(*group.m_grid.get(), std::move(index), navigation) { + std::array endline; + endline[0ul] = navigation[0ul].size(); + endline[1ul] = navigation[1ul].size(); + m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t(*group.m_grid.get(), std::move(endline), std::move(navigation)); findNotEmptyBin(); } @@ -195,13 +196,18 @@ Acts::BinnedSPGroup::BinnedSPGroup( m_topBinFinder = tBinFinder; m_skipZMiddleBin = config.skipZMiddleBinSearch; + + // phi axis m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); - std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1); - m_bins[INDEX::Z] = config.zBinsCustomLooping; - if (m_bins[INDEX::Z].empty()) { - std::size_t nZbins = m_grid->numLocalBins()[1]; - m_bins[INDEX::Z].resize(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1); + std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1ul); + + // z axis + if (config.zBinsCustomLooping.empty()) { + std::size_t nZbins = m_grid->numLocalBins()[1] - m_skipZMiddleBin; + m_bins[INDEX::Z] = std::vector(nZbins); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul + m_skipZMiddleBin); + } else { + m_bins[INDEX::Z] = std::vector(config.zBinsCustomLooping.begin() + m_skipZMiddleBin, config.zBinsCustomLooping.end()); } } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index cf6e1d39952..519de1774e3 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -484,7 +484,11 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { - return local_iterator_t(*this, numLocalBins(), navigator); + std::array endline; + for (std::size_t i(0ul); i&& grid, std::size_t idx) = delete; GridGlobalIterator(const Acts::Grid& grid, std::size_t idx = 0ul); @@ -77,6 +78,7 @@ class GridLocalIterator { using pointer = value_type*; using reference = value_type&; + GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, std::array indexes) = delete; GridLocalIterator( diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 6272da9a16b..61106301dae 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project @@ -139,12 +138,20 @@ Acts::GridLocalIterator::GridLocalIterator( m_numLocalBins(std::move(grid.numLocalBins())), m_currentIndex(std::move(indexes)), m_navigationIndex(std::move(navigation)) { - // check navigation consistency - for (std::size_t i(0); i < DIM; ++i) { - if (m_navigationIndex[i].size() != m_numLocalBins[i]) { - throw std::invalid_argument( - "Invalid navigation sequence in local grid iterator."); + // We can allow navigation on only a subset of bins. + // If the number of specified bins in the navigation for one axis is not + // zero then override the maximum number of navigation bins instead of using the + // total number of available bins in the axis + for (std::size_t i(0ul); i m_numLocalBins[i]) { + throw std::invalid_argument("Invalid navigation sequence in local grid iterator. Too many bins specified."); } + m_numLocalBins[i] = m_navigationIndex[i].size(); m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 761b4d28a9c..73b1c4beb19 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -232,4 +232,65 @@ namespace Acts::Test { BOOST_CHECK_EQUAL(numIterations, grid.size(false)); } + BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + const std::size_t nBinsJK = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); + Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); + Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), std::move(jAxis), std::move(kAxis)) ); + + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ * nBinsJK * nBinsJK); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul) * (nBinsJK + 2ul) * (nBinsJK + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); + BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); + + // Iterate only on a few bins + std::array, 5ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; + navigation[2ul] = {1ul, 5ul}; + navigation[3ul] = {5ul, 3ul, 2ul}; + navigation[4ul] = {2ul}; + + Acts::GridLocalIterator gridStart = grid.begin(navigation); + Acts::GridLocalIterator gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + + std::size_t expectedIterations = 1ul; + for (std::size_t i(0ul); i<5ul; ++i) { + expectedIterations *= navigation[i].size(); + } + + BOOST_CHECK_EQUAL(numIterations, expectedIterations); + } + } From e0d0fe79841facc4e49c0777a7cb90ded55cb763 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 10:47:51 +0100 Subject: [PATCH 036/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 11 +- Core/include/Acts/Utilities/Grid.hpp | 2 +- Core/include/Acts/Utilities/GridIterator.ipp | 16 +- .../Core/Utilities/GridIterationTests.cpp | 550 +++++++++--------- 4 files changed, 305 insertions(+), 274 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 692d61877f4..b567343a52a 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -20,7 +20,9 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array endline; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); - m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t(*group.m_grid.get(), std::move(endline), std::move(navigation)); + m_gridItrEnd = + typename Acts::SpacePointGrid::local_iterator_t( + *group.m_grid.get(), std::move(endline), std::move(navigation)); findNotEmptyBin(); } @@ -205,9 +207,12 @@ Acts::BinnedSPGroup::BinnedSPGroup( if (config.zBinsCustomLooping.empty()) { std::size_t nZbins = m_grid->numLocalBins()[1] - m_skipZMiddleBin; m_bins[INDEX::Z] = std::vector(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul + m_skipZMiddleBin); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), + 1ul + m_skipZMiddleBin); } else { - m_bins[INDEX::Z] = std::vector(config.zBinsCustomLooping.begin() + m_skipZMiddleBin, config.zBinsCustomLooping.end()); + m_bins[INDEX::Z] = std::vector( + config.zBinsCustomLooping.begin() + m_skipZMiddleBin, + config.zBinsCustomLooping.end()); } } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 519de1774e3..22d9df902a6 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -485,7 +485,7 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { std::array endline; - for (std::size_t i(0ul); i::GridLocalIterator( m_navigationIndex(std::move(navigation)) { // We can allow navigation on only a subset of bins. // If the number of specified bins in the navigation for one axis is not - // zero then override the maximum number of navigation bins instead of using the - // total number of available bins in the axis - for (std::size_t i(0ul); i m_numLocalBins[i]) { - throw std::invalid_argument("Invalid navigation sequence in local grid iterator. Too many bins specified."); + throw std::invalid_argument( + "Invalid navigation sequence in local grid iterator. Too many bins " + "specified."); } - m_numLocalBins[i] = m_navigationIndex[i].size(); + m_numLocalBins[i] = m_navigationIndex[i].size(); m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 73b1c4beb19..83bd5137258 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -15,282 +15,304 @@ namespace Acts::Test { - BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins); - BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins); + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + + Acts::GridLocalIterator gridStart = + grid.begin(navigation); + Acts::GridLocalIterator gridStop = + grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + for (std::size_t i(0ul); i < 2ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); } - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - Acts::GridGlobalIterator gridStart = grid.begin(); - Acts::GridGlobalIterator gridStop = grid.end(); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(true)); + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins); - BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - - std::array, 1ul> navigation; - navigation[0ul].resize(nBins); - std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul].resize(nBins); + navigation[1ul].resize(nBins); + navigation[2ul].resize(nBinsZ); + for (std::size_t i(0ul); i < 3ul; ++i) { + std::iota(navigation[i].begin(), navigation[i].end(), 1); } - BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { - const std::size_t nBins = 10ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - - std::array, 2ul> navigation; - navigation[0ul].resize(nBins); - navigation[1ul].resize(nBins); - for (std::size_t i(0ul); i<2ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); - } - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - std::array, 3ul> navigation; - navigation[0ul].resize(nBins); - navigation[1ul].resize(nBins); - navigation[2ul].resize(nBinsZ); - for (std::size_t i(0ul); i<3ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); - } - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); + BOOST_CHECK_EQUAL(grid.size(true), + (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; + navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, + 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, + 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; + + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } - - BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_custom_navigation) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis)) ); - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - - std::array, 3ul> navigation; - navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; - navigation[1ul] = {6ul, 8ul, 7ul, 1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul}; - navigation[2ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul, 11ul, 15ul, 13ul, 12ul, 19ul, 20ul, 14ul, 16ul, 18ul, 17ul}; - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - BOOST_CHECK_EQUAL(numIterations, grid.size(false)); + BOOST_CHECK_EQUAL(numIterations, grid.size(false)); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { + const std::size_t nBins = 10ul; + const std::size_t nBinsZ = 20ul; + const std::size_t nBinsJK = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::detail::EquidistantAxis yAxis(0, 100, nBins); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); + Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), + std::move(jAxis), std::move(kAxis))); + + // test general properties + BOOST_CHECK_EQUAL(grid.size(false), + nBins * nBins * nBinsZ * nBinsJK * nBinsJK); + BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * + (nBinsZ + 2ul) * (nBinsJK + 2ul) * + (nBinsJK + 2ul)); + + const std::array numLocalBins = grid.numLocalBins(); + BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); + BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); + BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); + BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); + + // Iterate only on a few bins + std::array, 5ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; + navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; + navigation[2ul] = {1ul, 5ul}; + navigation[3ul] = {5ul, 3ul, 2ul}; + navigation[4ul] = {2ul}; + + Acts::GridLocalIterator< + double, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis> + gridStart = grid.begin(navigation); + Acts::GridLocalIterator< + double, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis> + gridStop = grid.end(navigation); + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; } - BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { - const std::size_t nBins = 10ul; - const std::size_t nBinsZ = 20ul; - const std::size_t nBinsJK = 5ul; - Acts::detail::EquidistantAxis xAxis(0, 100, nBins); - Acts::detail::EquidistantAxis yAxis(0, 100, nBins); - Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); - Acts::detail::EquidistantAxis jAxis(0, 100, nBinsJK); - Acts::detail::EquidistantAxis kAxis(0, 100, nBinsJK); - Acts::Grid grid( std::make_tuple(std::move(xAxis), std::move(yAxis), std::move(zAxis), std::move(jAxis), std::move(kAxis)) ); - - - // test general properties - BOOST_CHECK_EQUAL(grid.size(false), nBins * nBins * nBinsZ * nBinsJK * nBinsJK); - BOOST_CHECK_EQUAL(grid.size(true), (nBins + 2ul) * (nBins + 2ul) * (nBinsZ + 2ul) * (nBinsJK + 2ul) * (nBinsJK + 2ul)); - - const std::array numLocalBins = grid.numLocalBins(); - BOOST_CHECK_EQUAL(numLocalBins[0ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[1ul], nBins); - BOOST_CHECK_EQUAL(numLocalBins[2ul], nBinsZ); - BOOST_CHECK_EQUAL(numLocalBins[3ul], nBinsJK); - BOOST_CHECK_EQUAL(numLocalBins[4ul], nBinsJK); - - // Iterate only on a few bins - std::array, 5ul> navigation; - navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 9ul, 10ul, 4ul, 6ul, 8ul, 7ul}; - navigation[1ul] = {6ul, 8ul, 7ul, 1ul}; - navigation[2ul] = {1ul, 5ul}; - navigation[3ul] = {5ul, 3ul, 2ul}; - navigation[4ul] = {2ul}; - - Acts::GridLocalIterator gridStart = grid.begin(navigation); - Acts::GridLocalIterator gridStop = grid.end(navigation); - std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { - ++numIterations; - } - - std::size_t expectedIterations = 1ul; - for (std::size_t i(0ul); i<5ul; ++i) { - expectedIterations *= navigation[i].size(); - } - - BOOST_CHECK_EQUAL(numIterations, expectedIterations); + std::size_t expectedIterations = 1ul; + for (std::size_t i(0ul); i < 5ul; ++i) { + expectedIterations *= navigation[i].size(); } - + + BOOST_CHECK_EQUAL(numIterations, expectedIterations); } + +} // namespace Acts::Test From 309a0ef1955329a7dfb0c9ba9da50a4a78b4bdc4 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:26:22 +0100 Subject: [PATCH 037/120] changes --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 5 ++++- Core/include/Acts/Utilities/Grid.hpp | 2 +- Core/include/Acts/Utilities/GridIterator.hpp | 1 - Core/include/Acts/Utilities/GridIterator.ipp | 7 ++----- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index b567343a52a..be165a0b79d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -230,5 +230,8 @@ Acts::BinnedSPGroup::begin() { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - return {*this, m_grid->numLocalBins(), m_bins}; + std::array endline; + endline[0ul] = m_bins[0ul].size(); + endline[1ul] = m_bins[1ul].size(); + return {*this, std::move(endline), m_bins}; } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 22d9df902a6..f822441d916 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -488,7 +488,7 @@ class Grid final { for (std::size_t i(0ul); i < DIM; ++i) { endline[i] = navigator[i].size(); } - return local_iterator_t(*this, endline, navigator); + return local_iterator_t(*this, std::move(endline), navigator); } private: diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 5602bdb0d49..98e978dd47e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -125,7 +125,6 @@ class GridLocalIterator { Acts::detail::RefHolder> m_grid{nullptr}; std::array m_numLocalBins{}; std::array m_currentIndex{}; - std::array m_localPosition{}; std::array, DIM> m_navigationIndex{}; }; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 15d1ffab0ec..1542491dd8d 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -126,7 +126,6 @@ Acts::GridLocalIterator::GridLocalIterator( for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); - m_localPosition[i] = 1ul; } } @@ -156,7 +155,6 @@ Acts::GridLocalIterator::GridLocalIterator( "specified."); } m_numLocalBins[i] = m_navigationIndex[i].size(); - m_localPosition[i] = m_navigationIndex[i][m_currentIndex[i]]; } } @@ -166,8 +164,8 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_numLocalBins(std::move(other.m_numLocalBins)), m_currentIndex(std::move(other.m_currentIndex)), - m_navigationIndex(std::move(other.m_navigationIndex)), - m_localPosition(std::move(other.m_localPosition)) {} + m_navigationIndex(std::move(other.m_navigationIndex)) + {} template Acts::GridLocalIterator& @@ -177,7 +175,6 @@ Acts::GridLocalIterator::operator=( m_numLocalBins = std::move(other.m_numLocalBins); m_currentIndex = std::move(other.m_currentIndex); m_navigationIndex = std::move(other.m_navigationIndex); - m_localPosition = std::move(other.m_localPosition); return *this; } From ab158e1d924af0c382fc937383a760cca26d6bee Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:28:28 +0100 Subject: [PATCH 038/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index be165a0b79d..c0fcc2f03f2 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -232,6 +232,6 @@ inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { std::array endline; endline[0ul] = m_bins[0ul].size(); - endline[1ul] = m_bins[1ul].size(); + endline[1ul] = m_bins[1ul].size(); return {*this, std::move(endline), m_bins}; } From 52b90cd51230dfb7e6d0cc3cd1c921dfa968ab2a Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:28:47 +0100 Subject: [PATCH 039/120] format --- Core/include/Acts/Utilities/GridIterator.ipp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 1542491dd8d..9bf57dc321b 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -164,8 +164,7 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(std::exchange(other.m_grid.ptr, nullptr)), m_numLocalBins(std::move(other.m_numLocalBins)), m_currentIndex(std::move(other.m_currentIndex)), - m_navigationIndex(std::move(other.m_navigationIndex)) - {} + m_navigationIndex(std::move(other.m_navigationIndex)) {} template Acts::GridLocalIterator& From 118db393530343e0172490c8ca52dfe202c1a7b6 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 11:48:47 +0100 Subject: [PATCH 040/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3c183c0835d..cc10a493db7 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,9 +117,13 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { return *m_grid.get(); } + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } - std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } private: // grid with ownership of all InternalSpacePoint From 592183bb8fff0ec674e2385c712e9e27e6f5c559 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:43:30 +0100 Subject: [PATCH 041/120] test 1 for cuda --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index f45aca17957..08185cd83a4 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -174,11 +174,18 @@ int main(int argc, char* argv[]) { // Create the result object. std::vector>> seeds_host; + std::array, 2ul> navigation; + navigation[0ul].resize(spGroup.grid().numLocalBins()[0ul]); + navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + // Perform the seed finding. if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, i); + std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; } @@ -214,7 +221,8 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, i); + std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; } From c2ad48bc26fad34481a5238036934a988b33e4e5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:48:00 +0100 Subject: [PATCH 042/120] local, not global --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 08185cd83a4..e09384b6d5e 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) { if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; @@ -221,7 +221,7 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().globalBinFromLocalBins(i); + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; From 57f887684b84bb4cca7fa6ff1f7d56d16b66ed20 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:52:30 +0100 Subject: [PATCH 043/120] agains cuda --- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index d7fd2f8d820..a76dd8792a1 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -261,8 +261,16 @@ int main(int argc, char** argv) { auto start_cpu = std::chrono::system_clock::now(); + std::array, 2ul> navigation; + navigation[0ul].resize(spGroup.grid().numLocalBins()[0ul]); + navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + std::array localPosition = spGroup.grid().localBinsFromGlobalBin(skip); + int group_count; - auto groupIt = Acts::BinnedSPGroupIterator(spGroup, skip); + auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); //----------- CPU ----------// group_count = 0; @@ -298,7 +306,7 @@ int main(int argc, char** argv) { group_count = 0; std::vector>> seedVector_cuda; - groupIt = Acts::BinnedSPGroupIterator(spGroup, skip); + groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); Acts::SpacePointData spacePointData; spacePointData.resize(spVec.size()); From b1abea1ff1a9c0a9507bb081ad156c102810c09f Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 12:54:00 +0100 Subject: [PATCH 044/120] and again format --- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 11 +++++++---- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 14 +++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index a76dd8792a1..edf77868991 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -267,10 +267,12 @@ int main(int argc, char** argv) { std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(skip); - + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(skip); + int group_count; - auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + auto groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, + navigation); //----------- CPU ----------// group_count = 0; @@ -306,7 +308,8 @@ int main(int argc, char** argv) { group_count = 0; std::vector>> seedVector_cuda; - groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + groupIt = Acts::BinnedSPGroupIterator(spGroup, localPosition, + navigation); Acts::SpacePointData spacePointData; spacePointData.resize(spVec.size()); diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index e09384b6d5e..ee85f2bbdfe 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -179,13 +179,15 @@ int main(int argc, char* argv[]) { navigation[1ul].resize(spGroup.grid().numLocalBins()[1ul]); std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); - + // Perform the seed finding. if (!cmdl.onlyGPU) { decltype(seedFinder_host)::SeedingState state; for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(i); + auto spGroup_itr = + Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; } @@ -221,8 +223,10 @@ int main(int argc, char* argv[]) { // Perform the seed finding. for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { - std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + std::array localPosition = + spGroup.grid().localBinsFromGlobalBin(i); + auto spGroup_itr = + Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; } From 3e9599c8f7aa760bcb4a6fde990894d1a64369ff Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 14:30:51 +0100 Subject: [PATCH 045/120] more tests for global iterator --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 15 ++--- Core/include/Acts/Utilities/Grid.hpp | 4 +- Core/include/Acts/Utilities/GridIterator.hpp | 8 +-- Core/include/Acts/Utilities/GridIterator.ipp | 34 ++++++------ .../Core/Utilities/GridIterationTests.cpp | 55 +++++++++++++++++++ 5 files changed, 86 insertions(+), 30 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index c0fcc2f03f2..e9dcf22d311 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -16,13 +16,13 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( std::array index, std::array, 2> navigation) : m_group(group), - m_gridItr(*group.m_grid.get(), std::move(index), navigation) { - std::array endline; + m_gridItr(*group.m_grid.get(), index, navigation) { + std::array endline{}; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); m_gridItrEnd = typename Acts::SpacePointGrid::local_iterator_t( - *group.m_grid.get(), std::move(endline), std::move(navigation)); + *group.m_grid.get(), endline, std::move(navigation)); findNotEmptyBin(); } @@ -79,12 +79,13 @@ Acts::BinnedSPGroupIterator::operator*() const { template inline void Acts::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) + if (m_gridItr == m_gridItrEnd) { return; + } // Iterate on the grid till we find a not-empty bin // We start from the current bin configuration and move forward std::size_t dimCollection = (*m_gridItr).size(); - while (dimCollection == 0ul and ++m_gridItr != m_gridItrEnd) { + while (dimCollection == 0ul && ++m_gridItr != m_gridItrEnd) { dimCollection = (*m_gridItr).size(); } } @@ -230,8 +231,8 @@ Acts::BinnedSPGroup::begin() { template inline Acts::BinnedSPGroupIterator Acts::BinnedSPGroup::end() { - std::array endline; + std::array endline{}; endline[0ul] = m_bins[0ul].size(); endline[1ul] = m_bins[1ul].size(); - return {*this, std::move(endline), m_bins}; + return {*this, endline, m_bins}; } diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index f822441d916..04c6007447f 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -475,7 +475,7 @@ class Grid final { local_iterator_t begin( const std::array, DIM>& navigator) const { - std::array localBin; + std::array localBin{}; for (std::size_t i(0); i < DIM; ++i) { localBin[i] = 0ul; } @@ -484,7 +484,7 @@ class Grid final { local_iterator_t end( const std::array, DIM>& navigator) const { - std::array endline; + std::array endline{}; for (std::size_t i(0ul); i < DIM; ++i) { endline[i] = navigator[i].size(); } diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 98e978dd47e..4c2ef74c34f 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -80,14 +80,14 @@ class GridLocalIterator { GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, - std::array indexes) = delete; + const std::array& indexes) = delete; GridLocalIterator( - Acts::Grid&& grid, std::array indexes, + Acts::Grid&& grid, const std::array& indexes, std::array, DIM> navigation) = delete; GridLocalIterator(const Acts::Grid& grid, - std::array indexes); + const std::array& indexes); GridLocalIterator(const Acts::Grid& grid, - std::array indexes, + const std::array& indexes, std::array, DIM> navigation); GridLocalIterator(const GridLocalIterator& other) = default; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 9bf57dc321b..c37d18298d0 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -81,13 +81,13 @@ GridGlobalIterator& GridGlobalIterator::operator-=( template GridGlobalIterator GridGlobalIterator::operator+( const std::size_t offset) const { - return {m_grid.ptr, m_idx + offset}; + return {*m_grid, m_idx + offset}; } template GridGlobalIterator GridGlobalIterator::operator-( const std::size_t offset) const { - return {m_grid.ptr, m_idx - offset}; + return {*m_grid, m_idx - offset}; } template @@ -95,7 +95,7 @@ typename GridGlobalIterator::difference_type GridGlobalIterator::operator-( const GridGlobalIterator& other) const { assert(other > *this); - return other.m_idx - m_idx; + return m_idx - other.m_idx; } template @@ -112,17 +112,17 @@ GridGlobalIterator& GridGlobalIterator::operator++() { template GridGlobalIterator GridGlobalIterator::operator++(int) { - GridGlobalIterator output(m_grid, m_idx++); + GridGlobalIterator output(*m_grid, m_idx++); return output; } // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, std::array indexes) + const Acts::Grid& grid, const std::array& indexes) : m_grid(&grid), - m_numLocalBins(std::move(grid.numLocalBins())), - m_currentIndex(std::move(indexes)) { + m_numLocalBins(grid.numLocalBins()), + m_currentIndex(indexes) { for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); @@ -131,11 +131,11 @@ Acts::GridLocalIterator::GridLocalIterator( template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, std::array indexes, + const Acts::Grid& grid, const std::array& indexes, std::array, DIM> navigation) : m_grid(&grid), - m_numLocalBins(std::move(grid.numLocalBins())), - m_currentIndex(std::move(indexes)), + m_numLocalBins(grid.numLocalBins()), + m_currentIndex(indexes), m_navigationIndex(std::move(navigation)) { // We can allow navigation on only a subset of bins. // If the number of specified bins in the navigation for one axis is not @@ -162,8 +162,8 @@ template Acts::GridLocalIterator::GridLocalIterator( Acts::GridLocalIterator&& other) noexcept : m_grid(std::exchange(other.m_grid.ptr, nullptr)), - m_numLocalBins(std::move(other.m_numLocalBins)), - m_currentIndex(std::move(other.m_currentIndex)), + m_numLocalBins(other.m_numLocalBins), + m_currentIndex(other.m_currentIndex), m_navigationIndex(std::move(other.m_navigationIndex)) {} template @@ -171,8 +171,8 @@ Acts::GridLocalIterator& Acts::GridLocalIterator::operator=( Acts::GridLocalIterator&& other) noexcept { m_grid.ptr = std::exchange(other.m_grid.ptr, nullptr); - m_numLocalBins = std::move(other.m_numLocalBins); - m_currentIndex = std::move(other.m_currentIndex); + m_numLocalBins = other.m_numLocalBins; + m_currentIndex = other.m_currentIndex; m_navigationIndex = std::move(other.m_navigationIndex); return *this; } @@ -229,8 +229,8 @@ template typename Acts::GridLocalIterator::difference_type Acts::GridLocalIterator::operator-( const Acts::GridLocalIterator& other) const { - return other.m_grid->globalBinFromLocalBins(m_currentIndex) - - m_grid->globalBinFromLocalBins(m_currentIndex); + return m_grid->globalBinFromLocalBins(m_currentIndex) - + other.m_grid->globalBinFromLocalBins(m_currentIndex); } template @@ -272,7 +272,7 @@ void GridLocalIterator::increment() { template std::array::DIM> GridLocalIterator::localPosition() const { - std::array output; + std::array output{}; for (std::size_t i(0); i < DIM; ++i) { output[i] = m_navigationIndex[i][m_currentIndex[i]]; } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 83bd5137258..9d3896e8a06 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -15,6 +15,61 @@ namespace Acts::Test { +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + BOOST_CHECK_EQUAL(gridStart < gridStop, true); + BOOST_CHECK_EQUAL(gridStart <= gridStop, true); + BOOST_CHECK_EQUAL(gridStart > gridStop, false); + BOOST_CHECK_EQUAL(gridStart >= gridStop, false); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 2ul); + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 2ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins + 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + + itr = gridStart + std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); + BOOST_CHECK_EQUAL(itr == gridStop, true); + + itr = gridStart - 1ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 1ul); + + gridStart += std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); + BOOST_CHECK_EQUAL(gridStart == gridStop, true); + + gridStart -= 3ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridGlobalIterator gridDefault; + Acts::GridGlobalIterator gridDummy(grid, 0ul); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); From 0c70d0386a1089b00dd4fc5061035f8d2e084457 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 12 Dec 2023 16:20:46 +0100 Subject: [PATCH 046/120] more tests and some bug fixing --- Core/include/Acts/Utilities/GridIterator.hpp | 9 +- Core/include/Acts/Utilities/GridIterator.ipp | 37 +----- .../Core/Utilities/GridIterationTests.cpp | 106 +++++++++++++++++- 3 files changed, 106 insertions(+), 46 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 4c2ef74c34f..001d460049e 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -72,7 +72,7 @@ class GridLocalIterator { public: static constexpr std::size_t DIM = sizeof...(Axes); - using iterator_category = std::random_access_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using value_type = T; using difference_type = std::ptrdiff_t; using pointer = value_type*; @@ -103,13 +103,6 @@ class GridLocalIterator { bool operator==(const Acts::GridLocalIterator& other) const; bool operator!=(const Acts::GridLocalIterator& other) const; - bool operator<(const Acts::GridLocalIterator& other) const; - bool operator>(const Acts::GridLocalIterator& other) const; - bool operator<=(const Acts::GridLocalIterator& other) const; - bool operator>=(const Acts::GridLocalIterator& other) const; - - difference_type operator-(const GridLocalIterator& other) const; - const value_type& operator*() const; GridLocalIterator& operator++(); diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index c37d18298d0..7bf7b98956a 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project @@ -199,40 +200,6 @@ bool Acts::GridLocalIterator::operator!=( return !(*this == other); } -template -bool Acts::GridLocalIterator::operator<( - const GridLocalIterator& other) const { - return m_grid.globalBinFromLocalBins(m_currentIndex) < - other.m_grid.globalBinFromLocalBins(m_currentIndex); -} - -template -bool Acts::GridLocalIterator::operator>( - const GridLocalIterator& other) const { - return m_grid.globalBinFromLocalBins(m_currentIndex) > - other.m_grid.globalBinFromLocalBins(m_currentIndex); -} - -template -bool Acts::GridLocalIterator::operator<=( - const GridLocalIterator& other) const { - return !(*this > other); -} - -template -bool Acts::GridLocalIterator::operator>=( - const GridLocalIterator& other) const { - return !(*this < other); -} - -template -typename Acts::GridLocalIterator::difference_type -Acts::GridLocalIterator::operator-( - const Acts::GridLocalIterator& other) const { - return m_grid->globalBinFromLocalBins(m_currentIndex) - - other.m_grid->globalBinFromLocalBins(m_currentIndex); -} - template const typename Acts::GridLocalIterator::value_type& Acts::GridLocalIterator::operator*() const { @@ -251,7 +218,7 @@ GridLocalIterator& GridLocalIterator::operator++() { template GridLocalIterator GridLocalIterator::operator++(int) { - GridLocalIterator output(m_grid.ptr, m_currentIndex); + GridLocalIterator output(*this); this->operator++(); return output; } diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 9d3896e8a06..ff2c3824c81 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -70,6 +70,63 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid grid( + std::make_tuple(std::move(xAxis), std::move(yAxis))); + + BOOST_CHECK_EQUAL(grid.size(true), (nBinsX + 2ul) * (nBinsY + 2ul)); + + Acts::GridGlobalIterator gridStart = + grid.begin(); + Acts::GridGlobalIterator gridStop = + grid.end(); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + BOOST_CHECK_EQUAL(gridStart < gridStop, true); + BOOST_CHECK_EQUAL(gridStart <= gridStop, true); + BOOST_CHECK_EQUAL(gridStart > gridStop, false); + BOOST_CHECK_EQUAL(gridStart >= gridStop, false); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true)); + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true)); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + + itr = gridStart + std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); + BOOST_CHECK_EQUAL(itr == gridStop, true); + + itr = gridStart - 1ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(true) - 2ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), grid.size(true) - 1ul); + + gridStart += std::distance(gridStart, gridStop); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); + BOOST_CHECK_EQUAL(gridStart == gridStop, true); + + gridStart -= 3ul; + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridGlobalIterator gridDefault; + Acts::GridGlobalIterator gridDummy(grid, 0ul); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -159,6 +216,49 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { BOOST_CHECK_EQUAL(numIterations, grid.size(true)); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + + // Constructor without navigation + Acts::GridLocalIterator gridIterNoNav(grid, {0ul}); + // Constructor(s) with navigation + Acts::GridLocalIterator gridStart(grid, {0ul}, navigation); + + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); + BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); + + Acts::GridLocalIterator gridStop(grid, {nBins}, std::move(navigation)); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false)); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 2ul); + + [[maybe_unused]] double value = *gridStart; + + Acts::GridLocalIterator gridDefault; + Acts::GridLocalIterator gridDummy(grid, {0ul}); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); +} + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -174,7 +274,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { std::array, 1ul> navigation; navigation[0ul].resize(nBins); - std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); Acts::GridLocalIterator gridStart = grid.begin(navigation); @@ -207,7 +307,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { navigation[0ul].resize(nBins); navigation[1ul].resize(nBins); for (std::size_t i(0ul); i < 2ul; ++i) { - std::iota(navigation[i].begin(), navigation[i].end(), 1); + std::iota(navigation[i].begin(), navigation[i].end(), 1ul); } Acts::GridLocalIterator Date: Tue, 12 Dec 2023 17:21:00 +0100 Subject: [PATCH 047/120] oopsie --- Core/include/Acts/Utilities/GridIterator.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 7bf7b98956a..b640a5faf73 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -95,7 +95,7 @@ template typename GridGlobalIterator::difference_type GridGlobalIterator::operator-( const GridGlobalIterator& other) const { - assert(other > *this); + assert(other <= *this); return m_idx - other.m_idx; } From 63917d9e6abf3599455bd5f64aadf53a4cd7565b Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:56:41 +0100 Subject: [PATCH 048/120] even more tests --- .../Core/Utilities/GridIterationTests.cpp | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index ff2c3824c81..eabe528b7f8 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -252,11 +252,92 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins - 2ul); [[maybe_unused]] double value = *gridStart; + std::array locPos = gridStart.localPosition(); + BOOST_CHECK_EQUAL(locPos[0ul], 3ul); Acts::GridLocalIterator gridDefault; Acts::GridLocalIterator gridDummy(grid, {0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); + + // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + itr = std::move(gridStart); + BOOST_CHECK_EQUAL(itr == gridStart, false); + BOOST_CHECK_EQUAL(itr != gridStart, true); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins - 2ul); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid grid( + std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBinsX); + navigation[1ul].resize(nBinsY); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + // Constructor without navigation + Acts::GridLocalIterator gridIterNoNav(grid, {0ul, 0ul}); + // Constructor(s) with navigation + Acts::GridLocalIterator gridStart(grid, {0ul, 0ul}, navigation); + + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); + BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); + + Acts::GridLocalIterator gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); + + BOOST_CHECK_EQUAL(gridStart == gridStop, false); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), grid.size(false)); + BOOST_CHECK_EQUAL(gridStart != gridStop, true); + + auto itr = gridStart++; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 1ul); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 1ul); + + itr = ++gridStart; + BOOST_CHECK_EQUAL(std::distance(itr, gridStart), 0ul); + BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBinsX * nBinsY - 2ul); + + [[maybe_unused]] double value = *gridStart; + std::array locPos = gridStart.localPosition(); + BOOST_CHECK_EQUAL(locPos[0ul], 1ul); + BOOST_CHECK_EQUAL(locPos[1ul], 3ul); + + Acts::GridLocalIterator gridDefault; + Acts::GridLocalIterator gridDummy(grid, {0ul, 0ul}); + + BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); + + // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + itr = std::move(gridStart); + BOOST_CHECK_EQUAL(itr == gridStart, false); + BOOST_CHECK_EQUAL(itr != gridStart, true); + BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBinsX * nBinsY - 2ul); +} + +BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_notvalid) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + // no navigation bins + std::array, 1ul> noNavigation; + BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(noNavigation))), std::invalid_argument); + + // too many steps in the navigation, there are not enough bins in the axis + std::array, 1ul> tooMuchNavigation; + tooMuchNavigation[0ul].resize(2 * nBins); + std::iota(tooMuchNavigation[0ul].begin(), tooMuchNavigation[0ul].end(), 1ul); + BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(tooMuchNavigation))), std::invalid_argument); } BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { From 3d316311bb7e78cc027547656b3f62930e00365b Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:57:23 +0100 Subject: [PATCH 049/120] remove line --- Core/include/Acts/Utilities/GridIterator.ipp | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index b640a5faf73..1ee5da1f563 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project From 1bba1e9a882b2c2fd92b3917b8ed29e7ce9b7403 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 07:59:17 +0100 Subject: [PATCH 050/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 +- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 3 +- Core/include/Acts/Utilities/GridIterator.hpp | 7 +- Core/include/Acts/Utilities/GridIterator.ipp | 6 +- .../Core/Utilities/GridIterationTests.cpp | 99 ++++++++++++------- 5 files changed, 76 insertions(+), 47 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index cc10a493db7..3c183c0835d 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,13 +117,9 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } + Acts::SpacePointGrid& grid() { return *m_grid.get(); } - std::size_t skipZMiddleBin() { - return m_skipZMiddleBin; - } + std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } private: // grid with ownership of all InternalSpacePoint diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index e9dcf22d311..4402a8375cc 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -15,8 +15,7 @@ Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( Acts::BinnedSPGroup& group, std::array index, std::array, 2> navigation) - : m_group(group), - m_gridItr(*group.m_grid.get(), index, navigation) { + : m_group(group), m_gridItr(*group.m_grid.get(), index, navigation) { std::array endline{}; endline[0ul] = navigation[0ul].size(); endline[1ul] = navigation[1ul].size(); diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 001d460049e..5fd2c687e62 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -81,9 +81,10 @@ class GridLocalIterator { GridLocalIterator() = default; GridLocalIterator(Acts::Grid&& grid, const std::array& indexes) = delete; - GridLocalIterator( - Acts::Grid&& grid, const std::array& indexes, - std::array, DIM> navigation) = delete; + GridLocalIterator(Acts::Grid&& grid, + const std::array& indexes, + std::array, DIM> navigation) = + delete; GridLocalIterator(const Acts::Grid& grid, const std::array& indexes); GridLocalIterator(const Acts::Grid& grid, diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 1ee5da1f563..723d0d4183c 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -119,7 +119,8 @@ GridGlobalIterator GridGlobalIterator::operator++(int) { // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, const std::array& indexes) + const Acts::Grid& grid, + const std::array& indexes) : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), m_currentIndex(indexes) { @@ -131,7 +132,8 @@ Acts::GridLocalIterator::GridLocalIterator( template Acts::GridLocalIterator::GridLocalIterator( - const Acts::Grid& grid, const std::array& indexes, + const Acts::Grid& grid, + const std::array& indexes, std::array, DIM> navigation) : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index eabe528b7f8..c4dd087275d 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { std::make_tuple(std::move(xAxis))); BOOST_CHECK_EQUAL(grid.size(true), nBins + 2ul); - + Acts::GridGlobalIterator gridStart = grid.begin(); Acts::GridGlobalIterator gridStop = @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); BOOST_CHECK_EQUAL(std::distance(itr, gridStop), 0ul); BOOST_CHECK_EQUAL(itr == gridStop, true); - + itr = gridStart - 1ul; BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), nBins); BOOST_CHECK_EQUAL(std::distance(itr, gridStop), nBins + 1ul); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { gridStart += std::distance(gridStart, gridStop); BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 0ul); BOOST_CHECK_EQUAL(gridStart == gridStop, true); - + gridStart -= 3ul; BOOST_CHECK_EQUAL(std::distance(gridStart, gridStop), 3ul); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -65,7 +65,8 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global_operators) { [[maybe_unused]] double value = *gridStart; Acts::GridGlobalIterator gridDefault; - Acts::GridGlobalIterator gridDummy(grid, 0ul); + Acts::GridGlobalIterator gridDummy( + grid, 0ul); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } @@ -75,15 +76,18 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { const std::size_t nBinsY = 5ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); - Acts::Grid grid( - std::make_tuple(std::move(xAxis), std::move(yAxis))); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); BOOST_CHECK_EQUAL(grid.size(true), (nBinsX + 2ul) * (nBinsY + 2ul)); - Acts::GridGlobalIterator gridStart = - grid.begin(); - Acts::GridGlobalIterator gridStop = - grid.end(); + Acts::GridGlobalIterator + gridStart = grid.begin(); + Acts::GridGlobalIterator + gridStop = grid.end(); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -121,12 +125,16 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global_operators) { [[maybe_unused]] double value = *gridStart; - Acts::GridGlobalIterator gridDefault; - Acts::GridGlobalIterator gridDummy(grid, 0ul); + Acts::GridGlobalIterator + gridDefault; + Acts::GridGlobalIterator + gridDummy(grid, 0ul); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); } - + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); @@ -221,20 +229,23 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { Acts::detail::EquidistantAxis xAxis(0, 100, nBins); Acts::Grid grid( std::make_tuple(std::move(xAxis))); - + std::array, 1ul> navigation; navigation[0ul].resize(nBins); std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); - + // Constructor without navigation - Acts::GridLocalIterator gridIterNoNav(grid, {0ul}); + Acts::GridLocalIterator gridIterNoNav( + grid, {0ul}); // Constructor(s) with navigation - Acts::GridLocalIterator gridStart(grid, {0ul}, navigation); + Acts::GridLocalIterator gridStart( + grid, {0ul}, navigation); BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); - Acts::GridLocalIterator gridStop(grid, {nBins}, std::move(navigation)); + Acts::GridLocalIterator gridStop( + grid, {nBins}, std::move(navigation)); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -256,11 +267,13 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { BOOST_CHECK_EQUAL(locPos[0ul], 3ul); Acts::GridLocalIterator gridDefault; - Acts::GridLocalIterator gridDummy(grid, {0ul}); + Acts::GridLocalIterator gridDummy( + grid, {0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); - // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + // move operation will invalidate gridStart since the grid gets moved and + // replaced with a nullptr itr = std::move(gridStart); BOOST_CHECK_EQUAL(itr == gridStart, false); BOOST_CHECK_EQUAL(itr != gridStart, true); @@ -272,9 +285,10 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { const std::size_t nBinsY = 5ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); - Acts::Grid grid( - std::make_tuple(std::move(xAxis), std::move(yAxis))); - + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + std::array, 2ul> navigation; navigation[0ul].resize(nBinsX); navigation[1ul].resize(nBinsY); @@ -282,14 +296,20 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); // Constructor without navigation - Acts::GridLocalIterator gridIterNoNav(grid, {0ul, 0ul}); + Acts::GridLocalIterator + gridIterNoNav(grid, {0ul, 0ul}); // Constructor(s) with navigation - Acts::GridLocalIterator gridStart(grid, {0ul, 0ul}, navigation); - + Acts::GridLocalIterator + gridStart(grid, {0ul, 0ul}, navigation); + BOOST_CHECK_EQUAL(std::distance(gridIterNoNav, gridStart), 0ul); BOOST_CHECK_EQUAL(gridIterNoNav == gridStart, true); - - Acts::GridLocalIterator gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); + + Acts::GridLocalIterator + gridStop(grid, {nBinsX, nBinsY}, std::move(navigation)); BOOST_CHECK_EQUAL(gridStart == gridStop, false); BOOST_CHECK_EQUAL(gridStart != gridStop, true); @@ -311,12 +331,17 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local_operators) { BOOST_CHECK_EQUAL(locPos[0ul], 1ul); BOOST_CHECK_EQUAL(locPos[1ul], 3ul); - Acts::GridLocalIterator gridDefault; - Acts::GridLocalIterator gridDummy(grid, {0ul, 0ul}); + Acts::GridLocalIterator + gridDefault; + Acts::GridLocalIterator + gridDummy(grid, {0ul, 0ul}); BOOST_CHECK_EQUAL(gridDefault == gridDummy, false); - // move operation will invalidate gridStart since the grid gets moved and replaced with a nullptr + // move operation will invalidate gridStart since the grid gets moved and + // replaced with a nullptr itr = std::move(gridStart); BOOST_CHECK_EQUAL(itr == gridStart, false); BOOST_CHECK_EQUAL(itr != gridStart, true); @@ -331,15 +356,21 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_notvalid) { // no navigation bins std::array, 1ul> noNavigation; - BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(noNavigation))), std::invalid_argument); + BOOST_CHECK_THROW( + (Acts::GridLocalIterator( + grid, {0ul}, std::move(noNavigation))), + std::invalid_argument); // too many steps in the navigation, there are not enough bins in the axis std::array, 1ul> tooMuchNavigation; tooMuchNavigation[0ul].resize(2 * nBins); std::iota(tooMuchNavigation[0ul].begin(), tooMuchNavigation[0ul].end(), 1ul); - BOOST_CHECK_THROW( (Acts::GridLocalIterator(grid, {0ul}, std::move(tooMuchNavigation))), std::invalid_argument); + BOOST_CHECK_THROW( + (Acts::GridLocalIterator( + grid, {0ul}, std::move(tooMuchNavigation))), + std::invalid_argument); } - + BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); From bfe8e6146ed51e59c1161edaa31d40d668bc2f6a Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:19:01 +0100 Subject: [PATCH 051/120] first round of comments --- Core/include/Acts/Utilities/Grid.hpp | 3 --- Core/include/Acts/Utilities/GridIterator.ipp | 2 -- 2 files changed, 5 deletions(-) diff --git a/Core/include/Acts/Utilities/Grid.hpp b/Core/include/Acts/Utilities/Grid.hpp index 04c6007447f..3d0913207df 100644 --- a/Core/include/Acts/Utilities/Grid.hpp +++ b/Core/include/Acts/Utilities/Grid.hpp @@ -476,9 +476,6 @@ class Grid final { local_iterator_t begin( const std::array, DIM>& navigator) const { std::array localBin{}; - for (std::size_t i(0); i < DIM; ++i) { - localBin[i] = 0ul; - } return local_iterator_t(*this, std::move(localBin), navigator); } diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index 723d0d4183c..f6b563c1ed8 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -6,8 +6,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include - namespace Acts { // Global Iterator template From 86af08df8b50e166eaed247f0629cbd3b9aceda0 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:20:30 +0100 Subject: [PATCH 052/120] format --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 3c183c0835d..cc10a493db7 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -117,9 +117,13 @@ class BinnedSPGroup { BinnedSPGroupIterator begin(); BinnedSPGroupIterator end(); - Acts::SpacePointGrid& grid() { return *m_grid.get(); } + Acts::SpacePointGrid& grid() { + return *m_grid.get(); + } - std::size_t skipZMiddleBin() { return m_skipZMiddleBin; } + std::size_t skipZMiddleBin() { + return m_skipZMiddleBin; + } private: // grid with ownership of all InternalSpacePoint From d6272558f12e5239977c4bcde68072069e734f70 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 08:58:28 +0100 Subject: [PATCH 053/120] test for checking iterations --- .../Core/Utilities/GridIterationTests.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index c4dd087275d..2f3bf5deb37 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -12,6 +12,7 @@ #include "Acts/Utilities/GridIterator.hpp" #include +#include namespace Acts::Test { @@ -582,4 +583,69 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_5d_local_custom_subnavigation) { BOOST_CHECK_EQUAL(numIterations, expectedIterations); } +BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_local_norepetitions) { + const std::size_t nBinsX = 5ul; + const std::size_t nBinsY = 5ul; + const std::size_t nBinsZ = 2ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + std::array, 3ul> navigation; + navigation[0ul] = {1ul, 5ul, 3ul, 2ul, 4ul}; + navigation[1ul] = {4ul, 2ul, 3ul, 5ul, 1ul}; + navigation[2ul] = {2ul, 1ul}; + + std::size_t expectedIterations = + navigation[0ul].size() * navigation[1ul].size() * navigation[2ul].size(); + + // Set the allowed values + std::unordered_set allowed_global_bins; + for (std::size_t x : navigation[0ul]) { + for (std::size_t y : navigation[1ul]) { + for (std::size_t z : navigation[2ul]) { + std::array locPos({x, y, z}); + std::size_t globPos = grid.globalBinFromLocalBins(locPos); + BOOST_CHECK_EQUAL( + allowed_global_bins.find(globPos) != allowed_global_bins.end(), + false); + allowed_global_bins.insert(globPos); + } + } + } + + BOOST_CHECK_EQUAL(expectedIterations, allowed_global_bins.size()); + + Acts::GridLocalIterator + gridStart = grid.begin(navigation); + Acts::GridLocalIterator + gridStop = grid.end(navigation); + + // Prepare visited values + std::unordered_set visited_global_bins; + + std::size_t numIterations = 0ul; + for (; gridStart != gridStop; ++gridStart) { + ++numIterations; + std::array locPos = gridStart.localPosition(); + std::size_t globPos = grid.globalBinFromLocalBins(locPos); + BOOST_CHECK_EQUAL( + visited_global_bins.find(globPos) != visited_global_bins.end(), false); + BOOST_CHECK_EQUAL( + allowed_global_bins.find(globPos) != allowed_global_bins.end(), true); + visited_global_bins.insert(globPos); + } + + BOOST_CHECK_EQUAL(expectedIterations, numIterations); + BOOST_CHECK_EQUAL(visited_global_bins.size(), allowed_global_bins.size()); +} + } // namespace Acts::Test From bd7bd059a1ed616fed8db83b7f0adfdba20ee412 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 13 Dec 2023 09:50:08 +0100 Subject: [PATCH 054/120] clang tidy --- Core/include/Acts/Utilities/GridIterator.ipp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index f6b563c1ed8..e2d358f9394 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -202,7 +202,7 @@ bool Acts::GridLocalIterator::operator!=( template const typename Acts::GridLocalIterator::value_type& Acts::GridLocalIterator::operator*() const { - std::array localPositionBin; + std::array localPositionBin{}; for (std::size_t i(0); i < DIM; ++i) { localPositionBin[i] = m_navigationIndex[i][m_currentIndex[i]]; } @@ -225,8 +225,9 @@ GridLocalIterator GridLocalIterator::operator++(int) { template template void GridLocalIterator::increment() { - if (++m_currentIndex[N] < m_numLocalBins[N]) + if (++m_currentIndex[N] < m_numLocalBins[N]) { return; + } if constexpr (N != 0) { m_currentIndex[N] = 0; increment(); From ec2fe305bfbfe14fda862b11993d0ad22540b308 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 15 Dec 2023 17:13:12 +0100 Subject: [PATCH 055/120] move and rename --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 16 ++++++++-------- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 4 ++-- .../GridBinFinder.hpp} | 11 ++++------- .../GridBinFinder.ipp} | 4 ++-- .../TrackFinding/SeedingAlgorithm.hpp | 8 ++++---- .../TrackFinding/src/SeedingAlgorithm.cpp | 6 +++--- .../src/PrototracksToParameters.cpp | 1 - Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp | 10 +++++----- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 10 +++++----- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 6 +++--- .../Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 10 +++++----- 11 files changed, 41 insertions(+), 45 deletions(-) rename Core/include/Acts/{Seeding/BinFinder.hpp => Utilities/GridBinFinder.hpp} (88%) rename Core/include/Acts/{Seeding/BinFinder.ipp => Utilities/GridBinFinder.ipp} (91%) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index cc10a493db7..32b04ff634f 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -9,11 +9,11 @@ #pragma once #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/InternalSeed.hpp" #include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" @@ -27,7 +27,7 @@ template class BinnedSPGroup; /// @c BinnedSPGroupIterator Allows to iterate over all groups of bins -/// a provided BinFinder can generate for each bin of a provided SPGrid +/// a provided GridBinFinder can generate for each bin of a provided SPGrid /// SpacePointGrid is a very specific structure. /// We know it is 2D and what it contains @@ -79,7 +79,7 @@ class BinnedSPGroupIterator { }; /// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator -/// for given BinFinders and SpacePointGrid. +/// for given GridBinFinders and SpacePointGrid. /// Fulfills the range_expression interface. template class BinnedSPGroup { @@ -96,9 +96,9 @@ class BinnedSPGroup { BinnedSPGroup( spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, callable_t&& toGlobal, - std::shared_ptr> + std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, + std::shared_ptr> tBinFinder, std::unique_ptr> grid, Acts::Extent& rRangeSPExtent, const SeedFinderConfig& _config, @@ -129,11 +129,11 @@ class BinnedSPGroup { // grid with ownership of all InternalSpacePoint std::unique_ptr> m_grid{nullptr}; - // BinFinder must return std::vector with content of + // GridBinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder{ + std::shared_ptr> m_topBinFinder{ nullptr}; - std::shared_ptr> m_bottomBinFinder{ + std::shared_ptr> m_bottomBinFinder{ nullptr}; // Order of z bins to loop over when searching for SPs diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 4402a8375cc..0bf1b821ead 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -95,8 +95,8 @@ template Acts::BinnedSPGroup::BinnedSPGroup( spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, + std::shared_ptr> botBinFinder, + std::shared_ptr> tBinFinder, std::unique_ptr> grid, Acts::Extent& rRangeSPExtent, const SeedFinderConfig& config, diff --git a/Core/include/Acts/Seeding/BinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp similarity index 88% rename from Core/include/Acts/Seeding/BinFinder.hpp rename to Core/include/Acts/Utilities/GridBinFinder.hpp index 64f04868b6a..214e136b8df 100644 --- a/Core/include/Acts/Seeding/BinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -23,13 +23,10 @@ namespace Acts { /// be top bins, which are assumed to be the same bins. Does not take /// interaction region into account to limit z-bins. template -class BinFinder { +class GridBinFinder { public: - /// constructor - BinFinder() = delete; - - BinFinder(const std::vector>& zBinNeighbors, - int numPhiNeighbors); + GridBinFinder(const std::vector>& zBinNeighbors, + int numPhiNeighbors); /// Return all bins that could contain space points that can be used with the /// space points in the bin with the provided indices to create seeds. @@ -48,4 +45,4 @@ class BinFinder { int m_numPhiNeighbors = 1; }; } // namespace Acts -#include "Acts/Seeding/BinFinder.ipp" +#include "Acts/Utilities/GridBinFinder.ipp" diff --git a/Core/include/Acts/Seeding/BinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp similarity index 91% rename from Core/include/Acts/Seeding/BinFinder.ipp rename to Core/include/Acts/Utilities/GridBinFinder.ipp index 087443c7383..b1b7585ad52 100644 --- a/Core/include/Acts/Seeding/BinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -7,13 +7,13 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. template -Acts::BinFinder::BinFinder( +Acts::GridBinFinder::GridBinFinder( const std::vector>& zBinNeighbors, int numPhiNeighbors) : m_zBinNeighbors(zBinNeighbors), m_numPhiNeighbors(numPhiNeighbors) {} template boost::container::small_vector -Acts::BinFinder::findBins( +Acts::GridBinFinder::findBins( std::size_t phiBin, std::size_t zBin, const Acts::SpacePointGrid* binnedSP) const { // if zBinNeighbors is not defined, get the indices using diff --git a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp index fcb5d5d37a9..7921b7732aa 100644 --- a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp +++ b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp @@ -8,11 +8,11 @@ #pragma once -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/SeedFilterConfig.hpp" #include "Acts/Seeding/SeedFinder.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsExamples/EventData/ProtoTrack.hpp" #include "ActsExamples/EventData/SimSeed.hpp" @@ -29,7 +29,7 @@ namespace Acts { template -class BinFinder; +class GridBinFinder; } // namespace Acts namespace ActsExamples { @@ -83,8 +83,8 @@ class SeedingAlgorithm final : public IAlgorithm { private: Acts::SeedFinder m_seedFinder; - std::shared_ptr> m_bottomBinFinder; - std::shared_ptr> m_topBinFinder; + std::shared_ptr> m_bottomBinFinder; + std::shared_ptr> m_topBinFinder; Config m_cfg; std::vector>> diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 348f2ecd427..b7a6b5cc963 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -11,13 +11,13 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/SpacePointData.hpp" #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Delegate.hpp" #include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/Range1D.hpp" #include "ActsExamples/EventData/SimSeed.hpp" @@ -205,9 +205,9 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( }); } - m_bottomBinFinder = std::make_shared>( + m_bottomBinFinder = std::make_shared>( m_cfg.zBinNeighborsBottom, m_cfg.numPhiNeighbors); - m_topBinFinder = std::make_shared>( + m_topBinFinder = std::make_shared>( m_cfg.zBinNeighborsTop, m_cfg.numPhiNeighbors); m_cfg.seedFinderConfig.seedFilter = diff --git a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp index 2b211f66f10..be65d8eeb36 100644 --- a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp +++ b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp @@ -8,7 +8,6 @@ #include "ActsExamples/TrackFindingExaTrkX/PrototracksToParameters.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/EstimateTrackParamsFromSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 562f70ff64b..316fa37d103 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -9,7 +9,6 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Units.hpp" #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFilter.hpp" @@ -18,6 +17,7 @@ #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/Range1D.hpp" #include @@ -165,10 +165,10 @@ int main(int argc, char** argv) { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index edf77868991..4b85581925b 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -7,7 +7,6 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "Acts/Plugins/Cuda/Seeding/SeedFinder.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/InternalSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" @@ -15,6 +14,7 @@ #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Seeding/SeedFinder.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include #include @@ -213,10 +213,10 @@ int main(int argc, char** argv) { config.nAvgTrplPerSpBLimit = nAvgTrplPerSpBLimit; // binfinder - auto bottomBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index ee85f2bbdfe..733480458ff 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -20,11 +20,11 @@ // Acts include(s). #include "Acts/EventData/SpacePointData.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/SeedFilterConfig.hpp" #include "Acts/Seeding/SeedFinder.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" // System include(s). #include @@ -61,9 +61,9 @@ int main(int argc, char* argv[]) { std::vector> zBinNeighborsBottom; // Create binned groups of these spacepoints. - auto bottomBinFinder = std::make_shared>( + auto bottomBinFinder = std::make_shared>( zBinNeighborsBottom, numPhiNeighbors); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_shared>( zBinNeighborsTop, numPhiNeighbors); // Set up the seedFinder configuration. diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index c835c0b3f08..337dc569713 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -9,7 +9,6 @@ #include "Acts/EventData/SpacePointData.hpp" #include "Acts/Plugins/Sycl/Seeding/SeedFinder.hpp" #include "Acts/Plugins/Sycl/Utilities/QueueWrapper.hpp" -#include "Acts/Seeding/BinFinder.hpp" #include "Acts/Seeding/BinnedSPGroup.hpp" #include "Acts/Seeding/InternalSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" @@ -18,6 +17,7 @@ #include "Acts/Seeding/SeedFinder.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/Logger.hpp" #include @@ -159,10 +159,10 @@ auto main(int argc, char** argv) -> int { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::BinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); auto config = setupSeedFinderConfiguration(); config = config.toInternalUnits().calculateDerivedQuantities(); auto options = setupSeedFinderOptions(); From bcf7ec150dc94bb92a79995f02ef94b2dfafd1d8 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 15 Dec 2023 21:26:22 +0100 Subject: [PATCH 056/120] first working version --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 8 +-- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 10 ++- Core/include/Acts/Utilities/GridBinFinder.hpp | 27 ++++--- Core/include/Acts/Utilities/GridBinFinder.ipp | 70 ++++++++++++++----- .../TrackFinding/SeedingAlgorithm.hpp | 6 +- .../TrackFinding/src/SeedingAlgorithm.cpp | 8 +-- .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 8 +-- 7 files changed, 88 insertions(+), 49 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 32b04ff634f..13e91903d52 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -96,9 +96,9 @@ class BinnedSPGroup { BinnedSPGroup( spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, callable_t&& toGlobal, - std::shared_ptr> + std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, + std::shared_ptr> tBinFinder, std::unique_ptr> grid, Acts::Extent& rRangeSPExtent, const SeedFinderConfig& _config, @@ -131,9 +131,9 @@ class BinnedSPGroup { // GridBinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder{ + std::shared_ptr> m_topBinFinder{ nullptr}; - std::shared_ptr> m_bottomBinFinder{ + std::shared_ptr> m_bottomBinFinder{ nullptr}; // Order of z bins to loop over when searching for SPs diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 0bf1b821ead..c0ee9a33791 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -55,12 +55,10 @@ Acts::BinnedSPGroupIterator::operator*() const { m_group->m_grid->globalBinFromLocalBins(localPosition); boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins(localPosition[INDEX::PHI], - localPosition[INDEX::Z], + m_group->m_bottomBinFinder->findBins(localPosition, m_group->m_grid.get()); boost::container::small_vector tops = - m_group->m_topBinFinder->findBins(localPosition[INDEX::PHI], - localPosition[INDEX::Z], + m_group->m_topBinFinder->findBins(localPosition, m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. @@ -95,8 +93,8 @@ template Acts::BinnedSPGroup::BinnedSPGroup( spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, + std::shared_ptr> botBinFinder, + std::shared_ptr> tBinFinder, std::unique_ptr> grid, Acts::Extent& rRangeSPExtent, const SeedFinderConfig& config, diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index 214e136b8df..fb4972b19cf 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -11,6 +11,7 @@ #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/Holders.hpp" +#include #include #include @@ -22,27 +23,33 @@ namespace Acts { /// used to find both bins that could be bottom bins as well as bins that could /// be top bins, which are assumed to be the same bins. Does not take /// interaction region into account to limit z-bins. -template +template class GridBinFinder { public: - GridBinFinder(const std::vector>& zBinNeighbors, - int numPhiNeighbors); + template + GridBinFinder(args&&... vals); /// Return all bins that could contain space points that can be used with the /// space points in the bin with the provided indices to create seeds. /// @param phiBin phi index of bin with middle space points /// @param zBin z index of bin with middle space points /// @param binnedSP phi-z grid containing all bins + template boost::container::small_vector findBins( - std::size_t phiBin, std::size_t zBin, - const SpacePointGrid* binnedSP) const; + const std::array& locPosition, + const Acts::Grid* grid) const; private: - // This vector is provided by the user and is supposed to be a constant for - // all events. No point in making a copy - Acts::detail::RefHolder>> - m_zBinNeighbors; - int m_numPhiNeighbors = 1; + template + void storeValue(first_value_t&& fv, vals&&... others); + + std::array, DIM> getSizePerAxis( + const std::array& locPosition) const; + + private: + using stored_values_t = std::variant>>; + std::array m_values{}; }; + } // namespace Acts #include "Acts/Utilities/GridBinFinder.ipp" diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index b1b7585ad52..db43a2c1661 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -6,24 +7,57 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -template -Acts::GridBinFinder::GridBinFinder( - const std::vector>& zBinNeighbors, int numPhiNeighbors) - : m_zBinNeighbors(zBinNeighbors), m_numPhiNeighbors(numPhiNeighbors) {} +#include -template -boost::container::small_vector -Acts::GridBinFinder::findBins( - std::size_t phiBin, std::size_t zBin, - const Acts::SpacePointGrid* binnedSP) const { - // if zBinNeighbors is not defined, get the indices using - // neighborHoodIndices - if (m_zBinNeighbors->empty()) { - return binnedSP->neighborHoodIndices({phiBin, zBin}).collect(); +template +template +Acts::GridBinFinder::GridBinFinder(args&&... vals) { + static_assert(sizeof...(args) == DIM); + static_assert(std::conjunction::type>, + std::is_same>, + typename std::decay::type>>...>::value); + storeValue(std::forward(vals)...); +} + +template +template +void Acts::GridBinFinder::storeValue(first_value_t&& fv, + vals&&... others) { + constexpr std::size_t N = sizeof...(vals); + m_values[DIM - N - 1ul] = std::forward(fv); + if constexpr (N != 0ul) { + storeValue(std::forward(others)...); } - // if the zBinNeighbors is defined, get the indices from there - std::array, 2> sizePerAxis; - sizePerAxis.at(0) = std::make_pair(-m_numPhiNeighbors, m_numPhiNeighbors); - sizePerAxis.at(1) = (*m_zBinNeighbors)[zBin - 1]; - return binnedSP->neighborHoodIndices({phiBin, zBin}, sizePerAxis).collect(); +} + +template +std::array, DIM> Acts::GridBinFinder::getSizePerAxis( + const std::array& locPosition) const { + std::array, DIM> output; + for (std::size_t i(0ul); i < DIM; ++i) { + output[i] = std::visit( + [&locPosition, i](const auto& val) -> std::pair { + using value_t = typename std::decay::type; + if constexpr (std::is_same::value) { + return std::make_pair(-val, val); + } else { + return val[locPosition[i] - 1ul]; + } + }, + m_values[i]); + } + return output; +} + +template +template +boost::container::small_vector +Acts::GridBinFinder::findBins( + const std::array& locPosition, + const Acts::Grid* binnedSP) const { + static_assert(sizeof...(Axes) == DIM); + std::array, DIM> sizePerAxis = + getSizePerAxis(locPosition); + return binnedSP->neighborHoodIndices(locPosition, sizePerAxis).collect(); } diff --git a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp index 7921b7732aa..2fcef7f96df 100644 --- a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp +++ b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp @@ -28,7 +28,7 @@ #include namespace Acts { -template +template class GridBinFinder; } // namespace Acts @@ -83,8 +83,8 @@ class SeedingAlgorithm final : public IAlgorithm { private: Acts::SeedFinder m_seedFinder; - std::shared_ptr> m_bottomBinFinder; - std::shared_ptr> m_topBinFinder; + std::shared_ptr> m_bottomBinFinder; + std::shared_ptr> m_topBinFinder; Config m_cfg; std::vector>> diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index b7a6b5cc963..a7c5658c5b5 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -205,10 +205,10 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( }); } - m_bottomBinFinder = std::make_shared>( - m_cfg.zBinNeighborsBottom, m_cfg.numPhiNeighbors); - m_topBinFinder = std::make_shared>( - m_cfg.zBinNeighborsTop, m_cfg.numPhiNeighbors); + m_bottomBinFinder = std::make_shared>( + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); + m_topBinFinder = std::make_shared>( + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 316fa37d103..b7de52592cb 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -165,10 +165,10 @@ int main(int argc, char** argv) { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(zBinNeighborsBottom, numPhiNeighbors)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(zBinNeighborsTop, numPhiNeighbors)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( From edc349be81fa438475833be32786fc42c8ccd8c1 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 15 Dec 2023 21:52:23 +0100 Subject: [PATCH 057/120] changes --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 4 ++-- Core/include/Acts/Utilities/GridBinFinder.hpp | 5 +++-- Core/include/Acts/Utilities/GridBinFinder.ipp | 9 +++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index c0ee9a33791..b7760e3a297 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -56,10 +56,10 @@ Acts::BinnedSPGroupIterator::operator*() const { boost::container::small_vector bottoms = m_group->m_bottomBinFinder->findBins(localPosition, - m_group->m_grid.get()); + *m_group->m_grid.get()); boost::container::small_vector tops = m_group->m_topBinFinder->findBins(localPosition, - m_group->m_grid.get()); + *m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index fb4972b19cf..6114919e155 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -10,6 +10,7 @@ #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/Holders.hpp" +#include "Acts/Utilities/detail/grid_helper.hpp" #include #include @@ -35,9 +36,9 @@ class GridBinFinder { /// @param zBin z index of bin with middle space points /// @param binnedSP phi-z grid containing all bins template - boost::container::small_vector findBins( + boost::container::small_vector findBins( const std::array& locPosition, - const Acts::Grid* grid) const; + const Acts::Grid& grid) const; private: template diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index db43a2c1661..15b2a3c7fc4 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -7,8 +6,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include - template template Acts::GridBinFinder::GridBinFinder(args&&... vals) { @@ -52,12 +49,12 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( template template -boost::container::small_vector +boost::container::small_vector Acts::GridBinFinder::findBins( const std::array& locPosition, - const Acts::Grid* binnedSP) const { + const Acts::Grid& binnedSP) const { static_assert(sizeof...(Axes) == DIM); std::array, DIM> sizePerAxis = getSizePerAxis(locPosition); - return binnedSP->neighborHoodIndices(locPosition, sizePerAxis).collect(); + return binnedSP.neighborHoodIndices(locPosition, sizePerAxis).collect(); } From e39777f426a4629904a635cd4f7dcf322202846b Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Sat, 16 Dec 2023 13:11:38 +0100 Subject: [PATCH 058/120] tests --- Tests/UnitTests/Core/Utilities/CMakeLists.txt | 1 + .../Core/Utilities/GridBinFinderTests.cpp | 280 ++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp diff --git a/Tests/UnitTests/Core/Utilities/CMakeLists.txt b/Tests/UnitTests/Core/Utilities/CMakeLists.txt index 78e9e6dcf8a..6f57916639d 100644 --- a/Tests/UnitTests/Core/Utilities/CMakeLists.txt +++ b/Tests/UnitTests/Core/Utilities/CMakeLists.txt @@ -14,6 +14,7 @@ add_unittest(Extendable ExtendableTests.cpp) add_unittest(FiniteStateMachine FiniteStateMachineTests.cpp) add_unittest(Frustum FrustumTest.cpp) add_unittest(GridIteration GridIterationTests.cpp) +add_unittest(GridBinFinder GridBinFinderTests.cpp) add_unittest(Grid GridTests.cpp) add_unittest(Helpers HelpersTests.cpp) add_unittest(Interpolation InterpolationTests.cpp) diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp new file mode 100644 index 00000000000..f154d4a9bd0 --- /dev/null +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -0,0 +1,280 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" +#include "Acts/Utilities/GridIterator.hpp" + +#include +#include +#include + +namespace Acts::Test { + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_1d_ints) { + const std::size_t nBins = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + std::array locPosition({3ul}); + + Acts::GridBinFinder<1ul> binFinder_1(1); + auto neighbours_1 = binFinder_1.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighbours_1.size(), 3ul); + + for (const std::size_t neighbour : neighbours_1) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + std::size_t distance = locPosition[0ul] <= neighboutLocPosition[0ul] + ? neighboutLocPosition[0ul] - locPosition[0ul] + : locPosition[0ul] - neighboutLocPosition[0ul]; + BOOST_CHECK(distance <= 1ul); + } + + Acts::GridBinFinder<1ul> binFinder_2(2); + auto neighbours_2 = binFinder_2.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighbours_2.size(), 5ul); + + for (const std::size_t neighbour : neighbours_2) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + std::size_t distance = locPosition[0ul] <= neighboutLocPosition[0ul] + ? neighboutLocPosition[0ul] - locPosition[0ul] + : locPosition[0ul] - neighboutLocPosition[0ul]; + BOOST_CHECK(distance <= 2ul); + } +} + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_ints) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 10ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array locPosition({3ul, 6ul}); + + Acts::GridBinFinder<2ul> binFinder_1(1, 3); + std::array dims_1({1, 3}); + auto neighbours_1 = binFinder_1.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighbours_1.size(), 3ul * 7ul); + + for (const std::size_t neighbour : neighbours_1) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + for (std::size_t dim(0ul); dim < 2ul; ++dim) { + std::size_t distance = locPosition[dim] <= neighboutLocPosition[dim] + ? neighboutLocPosition[dim] - locPosition[dim] + : locPosition[dim] - neighboutLocPosition[dim]; + BOOST_CHECK(distance <= dims_1[dim]); + } + } + + Acts::GridBinFinder<2ul> binFinder_2(2, 1); + std::array dims_2({2, 1}); + auto neighbours_2 = binFinder_2.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighbours_2.size(), 5ul * 3ul); + + for (const std::size_t neighbour : neighbours_2) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + for (std::size_t dim(0ul); dim < 2ul; ++dim) { + std::size_t distance = locPosition[dim] <= neighboutLocPosition[dim] + ? neighboutLocPosition[dim] - locPosition[dim] + : locPosition[dim] - neighboutLocPosition[dim]; + BOOST_CHECK(distance <= dims_2[dim]); + } + } +} + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_3d_ints) { + const std::size_t nBinsX = 10ul; + const std::size_t nBinsY = 10ul; + const std::size_t nBinsZ = 3ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::detail::EquidistantAxis zAxis(0, 100, nBinsZ); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis), + std::move(zAxis))); + + std::array locPosition({3ul, 6ul, 2ul}); + + Acts::GridBinFinder<3ul> binFinder(1, 2, 0); + std::array dims({1, 2, 0}); + auto neighbours = binFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighbours.size(), 3ul * 5ul * 1ul); + + for (const std::size_t neighbour : neighbours) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + for (std::size_t dim(0ul); dim < 3ul; ++dim) { + std::size_t distance = locPosition[dim] <= neighboutLocPosition[dim] + ? neighboutLocPosition[dim] - locPosition[dim] + : locPosition[dim] - neighboutLocPosition[dim]; + BOOST_CHECK(distance <= dims[dim]); + } + } +} + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_1d_pattern) { + const std::size_t nBins = 5ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBins); + Acts::Grid grid( + std::make_tuple(std::move(xAxis))); + + std::array, 1ul> navigation; + navigation[0ul].resize(nBins); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + + std::vector> neighbours; + neighbours.push_back(std::make_pair(0, 2)); + neighbours.push_back(std::make_pair(-1, 1)); + neighbours.push_back(std::make_pair(-1, 2)); + neighbours.push_back(std::make_pair(-2, 1)); + neighbours.push_back(std::make_pair(-1, 0)); + + BOOST_CHECK_EQUAL(neighbours.size(), grid.numLocalBins()[0ul]); + + auto startGrid = grid.begin(navigation); + auto stopGrid = grid.end(navigation); + + Acts::GridBinFinder<1ul> binFinder(std::move(neighbours)); + + std::size_t counter = 0ul; + std::vector expectedNeighbours = {3, 3, 4, 4, 2}; + + for (; startGrid != stopGrid; startGrid++) { + std::array locPosition = startGrid.localPosition(); + auto all_neigh = binFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(all_neigh.size(), expectedNeighbours[counter++]); + } + + std::vector> anotherNeighbours; + anotherNeighbours.push_back(std::make_pair(1, 2)); + anotherNeighbours.push_back(std::make_pair(-1, 1)); + anotherNeighbours.push_back(std::make_pair(-1, 2)); + anotherNeighbours.push_back(std::make_pair(-2, 1)); + anotherNeighbours.push_back(std::make_pair(-1, 0)); + + Acts::GridBinFinder<1ul> anotherBinFinder(std::move(anotherNeighbours)); + std::array locPosition = {1ul}; + + auto neighs = anotherBinFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(neighs.size(), 2ul); + + for (const std::size_t neighbour : neighs) { + std::array neighboutLocPosition = + grid.localBinsFromGlobalBin(neighbour); + std::size_t distance = locPosition[0ul] <= neighboutLocPosition[0ul] + ? neighboutLocPosition[0ul] - locPosition[0ul] + : locPosition[0ul] - neighboutLocPosition[0ul]; + BOOST_CHECK(distance <= 2ul); + BOOST_CHECK(distance >= 1ul); + } +} + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_pattern) { + const std::size_t nBinsX = 5ul; + const std::size_t nBinsY = 3ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBinsX); + navigation[1ul].resize(nBinsY); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + std::vector> neighboursX; + neighboursX.push_back(std::make_pair(0, 2)); + neighboursX.push_back(std::make_pair(-1, 1)); + neighboursX.push_back(std::make_pair(-1, 2)); + neighboursX.push_back(std::make_pair(-2, 1)); + neighboursX.push_back(std::make_pair(-1, 0)); + + std::vector> neighboursY; + neighboursY.push_back(std::make_pair(0, 1)); + neighboursY.push_back(std::make_pair(-1, 1)); + neighboursY.push_back(std::make_pair(-1, 0)); + + BOOST_CHECK_EQUAL(neighboursX.size(), grid.numLocalBins()[0ul]); + BOOST_CHECK_EQUAL(neighboursY.size(), grid.numLocalBins()[1ul]); + + auto startGrid = grid.begin(navigation); + auto stopGrid = grid.end(navigation); + + std::size_t counter = 0ul; + std::vector expectedNeighbours = {6, 9, 6, 6, 9, 6, 8, 12, + 8, 8, 12, 8, 4, 6, 4}; + + BOOST_CHECK_EQUAL(expectedNeighbours.size(), + neighboursX.size() * neighboursY.size()); + + Acts::GridBinFinder<2ul> binFinder(std::move(neighboursX), + std::move(neighboursY)); + + for (; startGrid != stopGrid; startGrid++) { + std::array locPosition = startGrid.localPosition(); + auto all_neigh = binFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(all_neigh.size(), expectedNeighbours[counter++]); + } +} + +BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_mixed) { + const std::size_t nBinsX = 5ul; + const std::size_t nBinsY = 3ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBinsX); + navigation[1ul].resize(nBinsY); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + std::vector> neighboursX; + neighboursX.push_back(std::make_pair(0, 2)); + neighboursX.push_back(std::make_pair(-1, 1)); + neighboursX.push_back(std::make_pair(-1, 2)); + neighboursX.push_back(std::make_pair(-2, 1)); + neighboursX.push_back(std::make_pair(-1, 0)); + + BOOST_CHECK_EQUAL(neighboursX.size(), grid.numLocalBins()[0ul]); + + auto startGrid = grid.begin(navigation); + auto stopGrid = grid.end(navigation); + + std::size_t counter = 0ul; + std::vector expectedNeighbours = {9, 9, 9, 9, 9, 9, 12, 12, + 12, 12, 12, 12, 6, 6, 6}; + + BOOST_CHECK_EQUAL(expectedNeighbours.size(), neighboursX.size() * nBinsY); + + Acts::GridBinFinder<2ul> binFinder(std::move(neighboursX), 1); + + for (; startGrid != stopGrid; startGrid++) { + std::array locPosition = startGrid.localPosition(); + auto all_neigh = binFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(all_neigh.size(), expectedNeighbours[counter++]); + } +} + +} // namespace Acts::Test From 73a5600848293a9bd558c38b85614cb3f5c99244 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Sat, 16 Dec 2023 13:25:06 +0100 Subject: [PATCH 059/120] changes --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 4 ++-- .../UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 8 ++++---- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 6 +++--- .../UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 87c06f219ee..b7760e3a297 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -54,10 +54,10 @@ Acts::BinnedSPGroupIterator::operator*() const { std::size_t global_index = m_group->m_grid->globalBinFromLocalBins(localPosition); - auto bottoms = + boost::container::small_vector bottoms = m_group->m_bottomBinFinder->findBins(localPosition, *m_group->m_grid.get()); - auto tops = + boost::container::small_vector tops = m_group->m_topBinFinder->findBins(localPosition, *m_group->m_grid.get()); diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index 4b85581925b..7061dce83bd 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -213,10 +213,10 @@ int main(int argc, char** argv) { config.nAvgTrplPerSpBLimit = nAvgTrplPerSpBLimit; // binfinder - auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 733480458ff..1c9acee7904 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -61,10 +61,10 @@ int main(int argc, char* argv[]) { std::vector> zBinNeighborsBottom; // Create binned groups of these spacepoints. - auto bottomBinFinder = std::make_shared>( - zBinNeighborsBottom, numPhiNeighbors); + auto bottomBinFinder = std::make_shared>( + numPhiNeighbors, zBinNeighborsBottom); auto topBinFinder = std::make_shared>( - zBinNeighborsTop, numPhiNeighbors); + numPhiNeighbors, zBinNeighborsTop); // Set up the seedFinder configuration. Acts::SeedFinderConfig sfConfig; diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index 337dc569713..9ac6d67bde7 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -159,10 +159,10 @@ auto main(int argc, char** argv) -> int { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsBottom, numPhiNeighbors)); - auto topBinFinder = std::make_shared>( - Acts::GridBinFinder(zBinNeighborsTop, numPhiNeighbors)); + auto bottomBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); + auto topBinFinder = std::make_shared>( + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); auto config = setupSeedFinderConfiguration(); config = config.toInternalUnits().calculateDerivedQuantities(); auto options = setupSeedFinderOptions(); From cdce92896ca1ace0527a243d72d5920fbfd564b3 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Sat, 16 Dec 2023 13:32:06 +0100 Subject: [PATCH 060/120] changes --- Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index b7de52592cb..65650f5a90e 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -166,9 +166,9 @@ int main(int argc, char** argv) { std::vector> zBinNeighborsBottom; auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(zBinNeighborsBottom, numPhiNeighbors)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); auto topBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(zBinNeighborsTop, numPhiNeighbors)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( From 65d249ad89a598d1350e6c69e5ee6e6c3e073f1e Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Sat, 16 Dec 2023 13:52:55 +0100 Subject: [PATCH 061/120] formta --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 83d350ea86a..d04d9c9ddd7 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -206,8 +205,7 @@ Acts::BinnedSPGroup::BinnedSPGroup( if (config.zBinsCustomLooping.empty()) { std::size_t nZbins = m_grid->numLocalBins()[INDEX::Z]; m_bins[INDEX::Z] = std::vector(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), - 1ul); + std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul); } else { m_bins[INDEX::Z] = config.zBinsCustomLooping; } From 1c5cc86907319ce8c1d29da349e1c5c4c65e9e8b Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 07:58:57 +0100 Subject: [PATCH 062/120] cuda --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 1c9acee7904..3e45a710d84 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) { // Create binned groups of these spacepoints. auto bottomBinFinder = std::make_shared>( numPhiNeighbors, zBinNeighborsBottom); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_shared>( numPhiNeighbors, zBinNeighborsTop); // Set up the seedFinder configuration. From 4f644371eb3898fa7e8e294a28e12cbf8c1278cc Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 08:26:39 +0100 Subject: [PATCH 063/120] new methods and tests --- Core/include/Acts/Utilities/GridIterator.hpp | 4 ++++ Core/include/Acts/Utilities/GridIterator.ipp | 20 +++++++++++++++++++ .../Core/Utilities/GridIterationTests.cpp | 12 +++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 5fd2c687e62..580814f06f7 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -60,6 +60,9 @@ class GridGlobalIterator { GridGlobalIterator& operator++(); GridGlobalIterator operator++(int); + std::size_t globalPosition() const; + std::array localPosition() const; + private: Acts::detail::RefHolder> m_grid{nullptr}; std::size_t m_idx{0ul}; @@ -109,6 +112,7 @@ class GridLocalIterator { GridLocalIterator& operator++(); GridLocalIterator operator++(int); + std::size_t globalPosition() const; std::array localPosition() const; private: diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index e2d358f9394..ea5b7d863cf 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project @@ -114,6 +115,19 @@ GridGlobalIterator GridGlobalIterator::operator++(int) { return output; } +template +std::size_t GridGlobalIterator::globalPosition() const +{ + return m_idx; +} + +template +std::array::DIM> +GridGlobalIterator::localPosition() const +{ + return m_grid->localBinsFromGlobalBin(m_idx); +} + // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( @@ -236,6 +250,12 @@ void GridLocalIterator::increment() { } } +template +std::size_t GridLocalIterator::globalPosition() const +{ + return m_grid->globalBinFromLocalBins(localPosition()); +} + template std::array::DIM> GridLocalIterator::localPosition() const { diff --git a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp index 2f3bf5deb37..72c4c902516 100644 --- a/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridIterationTests.cpp @@ -154,7 +154,10 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_global) { Acts::GridGlobalIterator gridStop = grid.end(); std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { + for (; gridStart != gridStop; gridStart++) { + BOOST_CHECK_EQUAL(gridStart.globalPosition(), numIterations); + const std::array locPosition = gridStart.localPosition(); + BOOST_CHECK_EQUAL(numIterations, locPosition[0ul]); ++numIterations; } BOOST_CHECK_EQUAL(numIterations, grid.size(true)); @@ -184,6 +187,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_global) { gridStop = grid.end(); std::size_t numIterations = 0ul; for (; gridStart != gridStop; ++gridStart) { + BOOST_CHECK_EQUAL(gridStart.globalPosition(), numIterations); ++numIterations; } BOOST_CHECK_EQUAL(numIterations, grid.size(true)); @@ -220,6 +224,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_3d_global) { gridStop = grid.end(); std::size_t numIterations = 0ul; for (; gridStart != gridStop; ++gridStart) { + BOOST_CHECK_EQUAL(gridStart.globalPosition(), numIterations); ++numIterations; } BOOST_CHECK_EQUAL(numIterations, grid.size(true)); @@ -267,6 +272,9 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_1d_local_operators) { std::array locPos = gridStart.localPosition(); BOOST_CHECK_EQUAL(locPos[0ul], 3ul); + std::size_t globPos = gridStart.globalPosition(); + BOOST_CHECK_EQUAL(globPos, 3ul); + Acts::GridLocalIterator gridDefault; Acts::GridLocalIterator gridDummy( grid, {0ul}); @@ -430,7 +438,7 @@ BOOST_AUTO_TEST_CASE(grid_iteration_test_2d_local) { Acts::detail::EquidistantAxis> gridStop = grid.end(navigation); std::size_t numIterations = 0ul; - for (; gridStart != gridStop; ++gridStart) { + for (; gridStart != gridStop; gridStart++) { ++numIterations; } BOOST_CHECK_EQUAL(numIterations, grid.size(false)); From 601339ee8c3f444dedfe5b577649eb2d8ba57eef Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 09:49:59 +0100 Subject: [PATCH 064/120] Add comments --- Core/include/Acts/Utilities/GridIterator.hpp | 181 ++++++++++++++++++- Core/include/Acts/Utilities/GridIterator.ipp | 33 +++- 2 files changed, 204 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 580814f06f7..37aff8fdbcb 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -15,7 +15,11 @@ namespace Acts { -// Using Global iterator, including over/under flow bins +/// @class GridGlobalIterator +/// Grid iterator using the global position. This iterates on all +/// the bins in the grid, including under- and over-flows +/// @tparam T The type stored in the grid bins +/// @tparam Axes ... The types of the axes in the grid template class GridGlobalIterator { public: @@ -27,49 +31,135 @@ class GridGlobalIterator { using pointer = value_type*; using reference = value_type&; + /// @brief Default constructor GridGlobalIterator() = default; + /// @brief Constructor taking ownership of the grid is not allowed + /// @param [in] grid The grid + /// @param [in] idx The global bin GridGlobalIterator(Acts::Grid&& grid, std::size_t idx) = delete; + /// @brief Constructor not taking ownership of the grid + /// @param [in] grid The grid + /// @param [in] idx The global bin + /// + /// @pre Global bin index must be a valid index for the grid GridGlobalIterator(const Acts::Grid& grid, std::size_t idx = 0ul); + /// @brief Copy constructor + /// @param [in] other The GlobalBinIterator to be copied GridGlobalIterator(const GridGlobalIterator& other) = default; + /// @brief Copy assignment + /// @param [in] other The GlobalBinIterator to be copied + /// @return The new global bin iterator GridGlobalIterator& operator=( const GridGlobalIterator& other) = default; + /// @brief Move constructor + /// @param [in] other The GlobalBinIterator to be moved + /// + /// This will invalidate the other GlobalBinIterator GridGlobalIterator(GridGlobalIterator&& other) noexcept; + /// @brief Move assignment + /// @param [in] other The GlobalBinIterator to be moved + /// @return The new global bin iterator + /// + /// This will invalidate the other GlobalBinIterator GridGlobalIterator& operator=( GridGlobalIterator&& other) noexcept; + /// @brief Default destructor ~GridGlobalIterator() = default; + /// @brief Equality operator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator==(const GridGlobalIterator& other) const; + /// @brief (In-)Equality operator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator!=(const GridGlobalIterator& other) const; + /// @brief Comparison (<) opetator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator<(const GridGlobalIterator& other) const; + /// @brief Comparison (>) opetator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator>(const GridGlobalIterator& other) const; + /// @brief Comparison (<=) opetator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator<=(const GridGlobalIterator& other) const; + /// @brief Comparison (>=) opetator + /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @return The result of the comparison bool operator>=(const GridGlobalIterator& other) const; + /// @brief Increment this interator with an offset + /// @param [in] offset The increment value + /// @return The incremented iterator GridGlobalIterator& operator+=(const std::size_t offset); + /// @brief Decrement this interator with an offset + /// @param [in] offset The decrement value + /// @return The decremented iterator GridGlobalIterator& operator-=(const std::size_t offset); + /// @brief Create incremented iterator + /// @param [in] offset The increment value + /// @return The incremented iterator GridGlobalIterator operator+(const std::size_t offset) const; + /// @brief Create decremented iterator + /// @param [in] offset The decrement value + /// @return The decremented iterator GridGlobalIterator operator-(const std::size_t offset) const; + /// @brief Distance between two GridGlobalIterator + /// @param [in] other The other GridGlobalIterator + /// @return The distance between the two iterators + /// + /// This will compute the distance by comparing the global positions in the + /// two iterators + /// + /// @pre The two iterators must have the same grid difference_type operator-(const GridGlobalIterator& other) const; + /// @brief Return stored value at given global position + /// @return The stored value in the grid from that given global position const value_type& operator*() const; + /// @brief Increment operator (pre) + /// @return The global iterator after the increment + /// + /// This will increase the global position by one GridGlobalIterator& operator++(); + /// @brief Increment operator (post) + /// @return The global iterator before the increment + /// + /// This will increase the global position by one GridGlobalIterator operator++(int); + /// @brief Retrieve the global position + /// @return The current global position in the grid std::size_t globalPosition() const; + /// @brief Retrieve the local position + /// @return The current local position in the grid std::array localPosition() const; private: + /// @brief The grid on which we are iterating + /// + /// The iterator never takes ownership of the grid. If the grid gets + /// invalidated (e.g. in a move operation) we can get undefined behaviours + /// if the iterator gets used after being invalidated Acts::detail::RefHolder> m_grid{nullptr}; + /// @brief The interation index, corresponding to the global bin in the grid std::size_t m_idx{0ul}; }; -// Using Local iterator, excluding over/under flow bins -// Can also allow for custom navigation pattern along axes +/// @class GridLocalIterator +/// Grid iterator using the local position. This iterates on all +/// local bins in the grid, and can exclude under- and over-flows +/// Can also allow for custom navigation pattern along axes +/// @tparam T The type stored in the grid bins +/// @tparam Axes ... The types of the axes in the grid template class GridLocalIterator { public: @@ -81,48 +171,131 @@ class GridLocalIterator { using pointer = value_type*; using reference = value_type&; + /// @brief Default constructor GridLocalIterator() = default; + /// @brief Constructor taking ownership of the grid is not allowed + /// @param [in] grid The grid + /// @param [in] indexes The local position GridLocalIterator(Acts::Grid&& grid, const std::array& indexes) = delete; + /// @brief Constructor taking ownership of the grid is not allowed + /// @param [in] grid The grid + /// @brief [in] indexes The local position + /// @brief [in] navigation The custom navigation pattern for each axis + /// + /// @pre None of the navigation vectors is allowed to be an empty vector GridLocalIterator(Acts::Grid&& grid, const std::array& indexes, std::array, DIM> navigation) = delete; + /// @brief Constructor + /// @param [in] grid The grid + /// @param [in] indexes The local position + /// + /// @pre The local bins representing the local bins must be a valid local position in the grid GridLocalIterator(const Acts::Grid& grid, const std::array& indexes); + /// @brief Constructor with custom navigation pattern + /// @param [in] grid The grid + /// @param [in] indexes The local position + /// @param [in] navigation The custom navigation pattern for each axis + /// + /// @pre The local bins representing the local bins must be a valid local position in the grid. + /// The navigation pattern must be consistent with the local bins (i.e. size <= num bins in the axis) + /// in the grid and have no repetitions. + /// + /// @pre None of the navigation vectors is allowed to be an empty vector GridLocalIterator(const Acts::Grid& grid, const std::array& indexes, std::array, DIM> navigation); + /// @brief Copy constructor + /// @param [in] other The GridLocalIterator to be copied GridLocalIterator(const GridLocalIterator& other) = default; + /// @brief Copy assignemnt operator + /// @param [in] other The GridLocalIterator to be copied + /// @return The copied GridLocalIterator GridLocalIterator& operator=( const GridLocalIterator& other) = default; + /// @brief Move constructor + /// @param [in] other The GridLocalIterator to be moved + /// + /// This will invalidate the other GridLocalIterator GridLocalIterator(GridLocalIterator&& other) noexcept; + /// @brief Move assignment operator + /// @param [in] other The GridLocalIterator to be moved + /// @return The moved GridLocalIterator + /// + /// This will invalidate the other GridLocalIterator GridLocalIterator& operator=( GridLocalIterator&& other) noexcept; + /// @brief Default destructor ~GridLocalIterator() = default; + /// @brief Equality operator + /// @param [in] other The other GridLocalIterator to be compared agains this one + /// @return The result of the comparison bool operator==(const Acts::GridLocalIterator& other) const; + /// @brief (In-)Equality operator + /// @param [in] other The other GridLocalIterator to be compared agains this one + /// @return The result of the comparison bool operator!=(const Acts::GridLocalIterator& other) const; + /// @brief Return stored value at given local position + /// @return The stored value in the grid from that given local position const value_type& operator*() const; - + + /// @brief Increment operator (pre) + /// @return The local iterator after the increment + /// + /// This will increase the local position by one GridLocalIterator& operator++(); + /// @brief Increment operator (post) + /// @return The local iterator before the increment + /// + /// This will increase the local position by one GridLocalIterator operator++(int); + /// @brief Retrieve the global position + /// @return The current global position in the grid std::size_t globalPosition() const; + /// @brief Retrieve the local position + /// @return The current local position in the grid std::array localPosition() const; private: + /// @brief Increment the local position + /// @tparam N Current dimension template void increment(); private: + /// @brief The grid on which we are iterating + /// + /// The iterator never takes ownership of the grid. If the grid gets + /// invalidated (e.g. in a move operation) we can get undefined behaviours + /// if the iterator gets used after being invalidated Acts::detail::RefHolder> m_grid{nullptr}; + /// @brief The maximum number of local bins in the grid. This does not include + /// under- and over-flow bins std::array m_numLocalBins{}; + /// @brief The current iteration position. + /// + /// This represent the position in the navigation pattern. + /// For each axis, the current index goes from 0ul to the size of the + /// corresponding navigation + /// + /// The local position in the gris is then obtained, for each axis i, + /// via m_navigationIndex[m_currentIndex[i]] std::array m_currentIndex{}; + /// @brief The custom navigation pattern in the grid + /// + /// This allows user to define any custom iteration sequence in all the + /// different axes of the grid. If nothing is defined by the user, then + /// a std::iota is used as the default starting with the 1ul bin (0ul) is + /// the under-flow in the axis std::array, DIM> m_navigationIndex{}; }; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index ea5b7d863cf..d97ac8e7fd5 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -30,6 +30,10 @@ GridGlobalIterator& GridGlobalIterator::operator=( template bool GridGlobalIterator::operator==( const GridGlobalIterator& other) const { + /// This will always return false if we are comparing two iterators from + /// different grids. + /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will never complete since + /// itrStop will not be reachable from itrStart return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; } @@ -42,12 +46,18 @@ bool GridGlobalIterator::operator!=( template bool GridGlobalIterator::operator<( const GridGlobalIterator& other) const { + /// This operator only makes sense if the two iterators we are comparing + /// are using the same grid + assert(m_grid.ptr == other.m_grid.ptr); return m_idx < other.m_idx; } template bool GridGlobalIterator::operator>( const GridGlobalIterator& other) const { + /// This operator only makes sense if the two iterators we are comparing + /// are using the same grid + assert(m_grid.ptr == other.m_grid.ptr); return m_idx > other.m_idx; } @@ -93,6 +103,7 @@ template typename GridGlobalIterator::difference_type GridGlobalIterator::operator-( const GridGlobalIterator& other) const { + assert(m_grid.ptr == other.m_grid.ptr); assert(other <= *this); return m_idx - other.m_idx; } @@ -136,6 +147,9 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), m_currentIndex(indexes) { + /// Since the user has not defined a custom navigation pattern, we tell the iterator + /// we want to iterate on all the local bins in ascending order from 1ul to numLocalBin for + /// that specific axis. for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); @@ -151,18 +165,18 @@ Acts::GridLocalIterator::GridLocalIterator( m_numLocalBins(grid.numLocalBins()), m_currentIndex(indexes), m_navigationIndex(std::move(navigation)) { - // We can allow navigation on only a subset of bins. - // If the number of specified bins in the navigation for one axis is not - // zero then override the maximum number of navigation bins instead of using - // the total number of available bins in the axis + /// We can allow navigation on only a subset of bins. + /// If the number of specified bins in the navigation for one axis is not + /// zero then override the maximum number of navigation bins instead of using + /// the total number of available bins in the axis for (std::size_t i(0ul); i < DIM; ++i) { - // We do not allow empty bin sequences + /// We do not allow empty bin sequences if (m_navigationIndex[i].size() == 0) { throw std::invalid_argument( "Invalid navigation sequence in local grid iterator. No bins " "specified."); } - // Too many bins + /// Too many bins if (m_navigationIndex[i].size() > m_numLocalBins[i]) { throw std::invalid_argument( "Invalid navigation sequence in local grid iterator. Too many bins " @@ -194,6 +208,10 @@ Acts::GridLocalIterator::operator=( template bool Acts::GridLocalIterator::operator==( const Acts::GridLocalIterator& other) const { + /// This will always return false if we are comparing two iterators from + /// different grids. + /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will never complete since + /// itrStop will not be reachable from itrStart if (m_grid.ptr != other.m_grid.ptr) { return false; } @@ -239,9 +257,12 @@ GridLocalIterator GridLocalIterator::operator++(int) { template template void GridLocalIterator::increment() { + /// Check if the current local bin can be incremented, or we reached the end of bins in the axis if (++m_currentIndex[N] < m_numLocalBins[N]) { return; } + /// We have reached the last bin in the axis, we set the position to 0ul and try to increment + /// another axis if constexpr (N != 0) { m_currentIndex[N] = 0; increment(); From afa5acf7fc5d9351e341dad07d9e8a61ece8e676 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 09:50:31 +0100 Subject: [PATCH 065/120] format --- Core/include/Acts/Utilities/GridIterator.hpp | 16 +++++----- Core/include/Acts/Utilities/GridIterator.ipp | 32 +++++++++----------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 37aff8fdbcb..16a6afaaeb0 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -19,7 +19,7 @@ namespace Acts { /// Grid iterator using the global position. This iterates on all /// the bins in the grid, including under- and over-flows /// @tparam T The type stored in the grid bins -/// @tparam Axes ... The types of the axes in the grid +/// @tparam Axes ... The types of the axes in the grid template class GridGlobalIterator { public: @@ -142,7 +142,7 @@ class GridGlobalIterator { /// @brief Retrieve the local position /// @return The current local position in the grid std::array localPosition() const; - + private: /// @brief The grid on which we are iterating /// @@ -159,7 +159,7 @@ class GridGlobalIterator { /// local bins in the grid, and can exclude under- and over-flows /// Can also allow for custom navigation pattern along axes /// @tparam T The type stored in the grid bins -/// @tparam Axes ... The types of the axes in the grid +/// @tparam Axes ... The types of the axes in the grid template class GridLocalIterator { public: @@ -201,8 +201,8 @@ class GridLocalIterator { /// @param [in] navigation The custom navigation pattern for each axis /// /// @pre The local bins representing the local bins must be a valid local position in the grid. - /// The navigation pattern must be consistent with the local bins (i.e. size <= num bins in the axis) - /// in the grid and have no repetitions. + /// The navigation pattern must be consistent with the local bins (i.e. size + /// <= num bins in the axis) in the grid and have no repetitions. /// /// @pre None of the navigation vectors is allowed to be an empty vector GridLocalIterator(const Acts::Grid& grid, @@ -210,7 +210,7 @@ class GridLocalIterator { std::array, DIM> navigation); /// @brief Copy constructor - /// @param [in] other The GridLocalIterator to be copied + /// @param [in] other The GridLocalIterator to be copied GridLocalIterator(const GridLocalIterator& other) = default; /// @brief Copy assignemnt operator /// @param [in] other The GridLocalIterator to be copied @@ -246,7 +246,7 @@ class GridLocalIterator { /// @brief Return stored value at given local position /// @return The stored value in the grid from that given local position const value_type& operator*() const; - + /// @brief Increment operator (pre) /// @return The local iterator after the increment /// @@ -255,7 +255,7 @@ class GridLocalIterator { /// @brief Increment operator (post) /// @return The local iterator before the increment /// - /// This will increase the local position by one + /// This will increase the local position by one GridLocalIterator operator++(int); /// @brief Retrieve the global position diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index d97ac8e7fd5..ae3c58a8ec8 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -32,8 +32,8 @@ bool GridGlobalIterator::operator==( const GridGlobalIterator& other) const { /// This will always return false if we are comparing two iterators from /// different grids. - /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will never complete since - /// itrStop will not be reachable from itrStart + /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will + /// never complete since itrStop will not be reachable from itrStart return (m_grid.ptr == other.m_grid.ptr) && m_idx == other.m_idx; } @@ -127,18 +127,16 @@ GridGlobalIterator GridGlobalIterator::operator++(int) { } template -std::size_t GridGlobalIterator::globalPosition() const -{ +std::size_t GridGlobalIterator::globalPosition() const { return m_idx; } template std::array::DIM> -GridGlobalIterator::localPosition() const -{ +GridGlobalIterator::localPosition() const { return m_grid->localBinsFromGlobalBin(m_idx); } - + // Local Iterator template Acts::GridLocalIterator::GridLocalIterator( @@ -147,9 +145,9 @@ Acts::GridLocalIterator::GridLocalIterator( : m_grid(&grid), m_numLocalBins(grid.numLocalBins()), m_currentIndex(indexes) { - /// Since the user has not defined a custom navigation pattern, we tell the iterator - /// we want to iterate on all the local bins in ascending order from 1ul to numLocalBin for - /// that specific axis. + /// Since the user has not defined a custom navigation pattern, we tell the + /// iterator we want to iterate on all the local bins in ascending order from + /// 1ul to numLocalBin for that specific axis. for (std::size_t i(0); i < DIM; ++i) { m_navigationIndex[i].resize(m_numLocalBins[i]); std::iota(m_navigationIndex[i].begin(), m_navigationIndex[i].end(), 1ul); @@ -210,8 +208,8 @@ bool Acts::GridLocalIterator::operator==( const Acts::GridLocalIterator& other) const { /// This will always return false if we are comparing two iterators from /// different grids. - /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will never complete since - /// itrStop will not be reachable from itrStart + /// As such a loop from itrStart (from grid A) to itrStop (from grid B) will + /// never complete since itrStop will not be reachable from itrStart if (m_grid.ptr != other.m_grid.ptr) { return false; } @@ -257,12 +255,13 @@ GridLocalIterator GridLocalIterator::operator++(int) { template template void GridLocalIterator::increment() { - /// Check if the current local bin can be incremented, or we reached the end of bins in the axis + /// Check if the current local bin can be incremented, or we reached the end + /// of bins in the axis if (++m_currentIndex[N] < m_numLocalBins[N]) { return; } - /// We have reached the last bin in the axis, we set the position to 0ul and try to increment - /// another axis + /// We have reached the last bin in the axis, we set the position to 0ul and + /// try to increment another axis if constexpr (N != 0) { m_currentIndex[N] = 0; increment(); @@ -272,8 +271,7 @@ void GridLocalIterator::increment() { } template -std::size_t GridLocalIterator::globalPosition() const -{ +std::size_t GridLocalIterator::globalPosition() const { return m_grid->globalBinFromLocalBins(localPosition()); } From a325bc2e5c9b28babdfdd2a690a37b8923693b67 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 10:31:47 +0100 Subject: [PATCH 066/120] spelling --- Core/include/Acts/Utilities/GridIterator.hpp | 24 ++++++++++---------- Core/include/Acts/Utilities/GridIterator.ipp | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Core/include/Acts/Utilities/GridIterator.hpp b/Core/include/Acts/Utilities/GridIterator.hpp index 16a6afaaeb0..8c3f25dabde 100644 --- a/Core/include/Acts/Utilities/GridIterator.hpp +++ b/Core/include/Acts/Utilities/GridIterator.hpp @@ -70,36 +70,36 @@ class GridGlobalIterator { ~GridGlobalIterator() = default; /// @brief Equality operator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator==(const GridGlobalIterator& other) const; /// @brief (In-)Equality operator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator!=(const GridGlobalIterator& other) const; /// @brief Comparison (<) opetator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator<(const GridGlobalIterator& other) const; /// @brief Comparison (>) opetator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator>(const GridGlobalIterator& other) const; /// @brief Comparison (<=) opetator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator<=(const GridGlobalIterator& other) const; /// @brief Comparison (>=) opetator - /// @param [in] other The other GridGlobalIterator to be compared agains this one + /// @param [in] other The other GridGlobalIterator to be compared against this one /// @return The result of the comparison bool operator>=(const GridGlobalIterator& other) const; - /// @brief Increment this interator with an offset + /// @brief Increment this iterator with an offset /// @param [in] offset The increment value /// @return The incremented iterator GridGlobalIterator& operator+=(const std::size_t offset); - /// @brief Decrement this interator with an offset + /// @brief Decrement this iterator with an offset /// @param [in] offset The decrement value /// @return The decremented iterator GridGlobalIterator& operator-=(const std::size_t offset); @@ -150,7 +150,7 @@ class GridGlobalIterator { /// invalidated (e.g. in a move operation) we can get undefined behaviours /// if the iterator gets used after being invalidated Acts::detail::RefHolder> m_grid{nullptr}; - /// @brief The interation index, corresponding to the global bin in the grid + /// @brief The iteration index, corresponding to the global bin in the grid std::size_t m_idx{0ul}; }; @@ -212,7 +212,7 @@ class GridLocalIterator { /// @brief Copy constructor /// @param [in] other The GridLocalIterator to be copied GridLocalIterator(const GridLocalIterator& other) = default; - /// @brief Copy assignemnt operator + /// @brief Copy assignment operator /// @param [in] other The GridLocalIterator to be copied /// @return The copied GridLocalIterator GridLocalIterator& operator=( @@ -235,11 +235,11 @@ class GridLocalIterator { ~GridLocalIterator() = default; /// @brief Equality operator - /// @param [in] other The other GridLocalIterator to be compared agains this one + /// @param [in] other The other GridLocalIterator to be compared against this one /// @return The result of the comparison bool operator==(const Acts::GridLocalIterator& other) const; /// @brief (In-)Equality operator - /// @param [in] other The other GridLocalIterator to be compared agains this one + /// @param [in] other The other GridLocalIterator to be compared against this one /// @return The result of the comparison bool operator!=(const Acts::GridLocalIterator& other) const; diff --git a/Core/include/Acts/Utilities/GridIterator.ipp b/Core/include/Acts/Utilities/GridIterator.ipp index ae3c58a8ec8..427aefcfd69 100644 --- a/Core/include/Acts/Utilities/GridIterator.ipp +++ b/Core/include/Acts/Utilities/GridIterator.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2016-2023 CERN for the benefit of the Acts project From 8b7374f9018f242acdc012e03e864867612e2805 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:17:36 +0100 Subject: [PATCH 067/120] add protections --- Core/include/Acts/Utilities/GridBinFinder.hpp | 59 ++++++++++++++++++- Core/include/Acts/Utilities/GridBinFinder.ipp | 30 ++++++++++ 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index 6114919e155..105a10739d1 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -20,6 +20,8 @@ namespace Acts { /// @class BinFinder +/// @tparam DIM Dimention of the Grid on which the GridBinFinder will be used +/// /// The BinFinder is used by the ISPGroupSelector. It can be /// used to find both bins that could be bottom bins as well as bins that could /// be top bins, which are assumed to be the same bins. Does not take @@ -27,28 +29,79 @@ namespace Acts { template class GridBinFinder { public: + /// @brief Constructor + /// @tparam args ... Input parameters provided by the user + /// + /// @param [in] vals The input parameters that define how many neighbour we need to find + /// + /// @pre The provided paramers must be of time 'int' or 'std::vector>' + /// no other type is allowed. The order of these parameters must correspond to the same + /// ordering of the axes in the grid template GridBinFinder(args&&... vals); + /// @brief Retrieve the neighbouring bins given a local position in the grid + /// /// Return all bins that could contain space points that can be used with the /// space points in the bin with the provided indices to create seeds. - /// @param phiBin phi index of bin with middle space points - /// @param zBin z index of bin with middle space points - /// @param binnedSP phi-z grid containing all bins + /// + /// @tparam stored_t The type of elements stored in the Grid + /// @tpatam Axes ... The type of the axes of the grid + /// + /// @param [in] locPosition The N-dimentional local position in the grid + /// @param [in] grid The grid + /// @output The list of neighbouring bins + /// + /// @pre The provided local positionmust be a valid local bins configuration in the grid template boost::container::small_vector findBins( const std::array& locPosition, const Acts::Grid& grid) const; private: + /// @brief Store the values provided by the user for each axis in the grid + /// @tparam first_value_t Type of the first value + /// @tparam vals ... values of the remaining values + /// + /// @param [in] fv The first value in the list + /// @param [in] others The remaining values in the list + /// + /// @pre both first_value_t and vals ... can be only int or std::vector> + /// In the second case, the number of entries of the vector of pairs MUST be equal to the number + /// of bins in that specific axis template void storeValue(first_value_t&& fv, vals&&... others); + /// @brief Get the instructions for retrieving the neighbouring bins given a local position + /// + /// @param [in] locPosition The requested local position + /// @return the instructions for retrieving the neighbouring bins for this local position + /// + /// @pre The local position must be a valid local bins configuration for the grid std::array, DIM> getSizePerAxis( const std::array& locPosition) const; + /// @brief Check the GridBinFinder configuration is compatible with the grid + /// by checking the values of m_values against the axes of the grid + /// This function is called only in debug mode + /// + /// @tparam stored_t The type of elements stored in the Grid + /// @tpatam Axes ... The type of the axes of the grid + /// + /// @param [in] grid The Grid + /// @return If the GridBinFinder is compatible with the grid + template + bool isGridCompatible(const Acts::Grid& grid) const; + private: using stored_values_t = std::variant>>; + /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid + /// These values are provided by the user and an be wither ints or a vector of pair of ints. + /// In the first case, the neighbours will be +/- bins from the given local bin + /// In the second case, the user defines how many bins in both directions should be provided + /// + /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific + /// axis std::array m_values{}; }; diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 15b2a3c7fc4..ac185902fe5 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -22,6 +22,7 @@ template void Acts::GridBinFinder::storeValue(first_value_t&& fv, vals&&... others) { constexpr std::size_t N = sizeof...(vals); + static_assert(N < DIM); m_values[DIM - N - 1ul] = std::forward(fv); if constexpr (N != 0ul) { storeValue(std::forward(others)...); @@ -37,8 +38,12 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( [&locPosition, i](const auto& val) -> std::pair { using value_t = typename std::decay::type; if constexpr (std::is_same::value) { + assert(val >= 0); return std::make_pair(-val, val); } else { + assert(locPosition.size() > i); + assert(locPosition[i] > 0ul); + assert(val.size() <= locPosition[i]); return val[locPosition[i] - 1ul]; } }, @@ -54,7 +59,32 @@ Acts::GridBinFinder::findBins( const std::array& locPosition, const Acts::Grid& binnedSP) const { static_assert(sizeof...(Axes) == DIM); + assert(isGridCompatible(binnedSP)); std::array, DIM> sizePerAxis = getSizePerAxis(locPosition); return binnedSP.neighborHoodIndices(locPosition, sizePerAxis).collect(); } + +template +template +bool Acts::GridBinFinder::isGridCompatible(const Acts::Grid& grid) const +{ + const std::array nLocBins = grid.numLocalBins(); + for (std::size_t i(0ul); i bool + { + using value_t = typename std::decay::type; + if constexpr (std::is_same::value) { + return true; + } else { + return val.size() == nBins; + } + }, + m_values[i]); + if (not isCompabile) { + return false; + } + } + return true; +} From 59eb33f830339b2f0eb23350c1dd7cd08f261e21 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:18:19 +0100 Subject: [PATCH 068/120] Core --- Core/include/Acts/Utilities/GridBinFinder.hpp | 25 +++++++------- Core/include/Acts/Utilities/GridBinFinder.ipp | 34 +++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index 105a10739d1..f5c9489b1a1 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -35,8 +35,8 @@ class GridBinFinder { /// @param [in] vals The input parameters that define how many neighbour we need to find /// /// @pre The provided paramers must be of time 'int' or 'std::vector>' - /// no other type is allowed. The order of these parameters must correspond to the same - /// ordering of the axes in the grid + /// no other type is allowed. The order of these parameters must correspond to + /// the same ordering of the axes in the grid template GridBinFinder(args&&... vals); @@ -47,16 +47,16 @@ class GridBinFinder { /// /// @tparam stored_t The type of elements stored in the Grid /// @tpatam Axes ... The type of the axes of the grid - /// + /// /// @param [in] locPosition The N-dimentional local position in the grid /// @param [in] grid The grid /// @output The list of neighbouring bins /// /// @pre The provided local positionmust be a valid local bins configuration in the grid template - boost::container::small_vector findBins( - const std::array& locPosition, - const Acts::Grid& grid) const; + boost::container::small_vector + findBins(const std::array& locPosition, + const Acts::Grid& grid) const; private: /// @brief Store the values provided by the user for each axis in the grid @@ -67,8 +67,8 @@ class GridBinFinder { /// @param [in] others The remaining values in the list /// /// @pre both first_value_t and vals ... can be only int or std::vector> - /// In the second case, the number of entries of the vector of pairs MUST be equal to the number - /// of bins in that specific axis + /// In the second case, the number of entries of the vector of pairs MUST be + /// equal to the number of bins in that specific axis template void storeValue(first_value_t&& fv, vals&&... others); @@ -92,13 +92,14 @@ class GridBinFinder { /// @return If the GridBinFinder is compatible with the grid template bool isGridCompatible(const Acts::Grid& grid) const; - + private: using stored_values_t = std::variant>>; /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid - /// These values are provided by the user and an be wither ints or a vector of pair of ints. - /// In the first case, the neighbours will be +/- bins from the given local bin - /// In the second case, the user defines how many bins in both directions should be provided + /// These values are provided by the user and an be wither ints or a vector of + /// pair of ints. In the first case, the neighbours will be +/- bins from the + /// given local bin In the second case, the user defines how many bins in both + /// directions should be provided /// /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific /// axis diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index ac185902fe5..77ebdf04f95 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -38,12 +38,12 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( [&locPosition, i](const auto& val) -> std::pair { using value_t = typename std::decay::type; if constexpr (std::is_same::value) { - assert(val >= 0); + assert(val >= 0); return std::make_pair(-val, val); } else { - assert(locPosition.size() > i); - assert(locPosition[i] > 0ul); - assert(val.size() <= locPosition[i]); + assert(locPosition.size() > i); + assert(locPosition[i] > 0ul); + assert(val.size() <= locPosition[i]); return val[locPosition[i] - 1ul]; } }, @@ -67,21 +67,21 @@ Acts::GridBinFinder::findBins( template template -bool Acts::GridBinFinder::isGridCompatible(const Acts::Grid& grid) const -{ +bool Acts::GridBinFinder::isGridCompatible( + const Acts::Grid& grid) const { const std::array nLocBins = grid.numLocalBins(); - for (std::size_t i(0ul); i bool - { - using value_t = typename std::decay::type; - if constexpr (std::is_same::value) { - return true; - } else { - return val.size() == nBins; - } - }, - m_values[i]); + bool isCompabile = std::visit( + [nBins](const auto& val) -> bool { + using value_t = typename std::decay::type; + if constexpr (std::is_same::value) { + return true; + } else { + return val.size() == nBins; + } + }, + m_values[i]); if (not isCompabile) { return false; } From c0f32531cfa527d37ecab27570f4a77a6fa4aceb Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:28:14 +0100 Subject: [PATCH 069/120] first input check --- Core/include/Acts/Utilities/GridBinFinder.ipp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 77ebdf04f95..2ad3678f68f 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -23,6 +24,22 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, vals&&... others) { constexpr std::size_t N = sizeof...(vals); static_assert(N < DIM); + /// Check the fist value is reasonable + /// That means that if int -> value is positive + /// If vector of pairs -> it is not an empty vector + using decayed_value_t = typename std::decay(first_value_t)::type; + if constexpr (std::is_same::value) { + if (fv >= 0) { + throw std::invalid_argument( + "Provided value [int] for GridBinFinder must be a positive integer"); + } + } else { + if (fv.empty()) { + throw std::invalid_arguemnt( + "Provided value [vector of pairs] for GridBinFinder must not be " + "empty."); + } + } m_values[DIM - N - 1ul] = std::forward(fv); if constexpr (N != 0ul) { storeValue(std::forward(others)...); From ee18f0f857e2bcd575e73456e2025dfb46ac8654 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:33:02 +0100 Subject: [PATCH 070/120] use asserts --- Core/include/Acts/Utilities/GridBinFinder.ipp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 2ad3678f68f..78fe23e53c3 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -25,20 +25,13 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, constexpr std::size_t N = sizeof...(vals); static_assert(N < DIM); /// Check the fist value is reasonable - /// That means that if int -> value is positive - /// If vector of pairs -> it is not an empty vector using decayed_value_t = typename std::decay(first_value_t)::type; if constexpr (std::is_same::value) { - if (fv >= 0) { - throw std::invalid_argument( - "Provided value [int] for GridBinFinder must be a positive integer"); - } + /// if int -> value is positive + assert(fv >= 0); } else { - if (fv.empty()) { - throw std::invalid_arguemnt( - "Provided value [vector of pairs] for GridBinFinder must not be " - "empty."); - } + /// If vector of pairs -> it is not an empty vector + assert(not fv.empty()); } m_values[DIM - N - 1ul] = std::forward(fv); if constexpr (N != 0ul) { From 072d184b211652c65d809f7bf9f8c4f0d3ca69c7 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:39:00 +0100 Subject: [PATCH 071/120] typo --- Core/include/Acts/Utilities/GridBinFinder.ipp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 78fe23e53c3..b1d737bd23c 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -25,7 +25,7 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, constexpr std::size_t N = sizeof...(vals); static_assert(N < DIM); /// Check the fist value is reasonable - using decayed_value_t = typename std::decay(first_value_t)::type; + using decayed_value_t = typename std::decay::type; if constexpr (std::is_same::value) { /// if int -> value is positive assert(fv >= 0); @@ -54,6 +54,7 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( assert(locPosition.size() > i); assert(locPosition[i] > 0ul); assert(val.size() <= locPosition[i]); + assert(val[locPosition[i] - 1ul].first <= val[locPosition[i] - 1ul].second); return val[locPosition[i] - 1ul]; } }, From 5df2442339b0957d5f9b04c24e52e395499e8ec7 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 11:53:31 +0100 Subject: [PATCH 072/120] bug --- Core/include/Acts/Utilities/GridBinFinder.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index b1d737bd23c..8010a110b6c 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -53,7 +53,7 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( } else { assert(locPosition.size() > i); assert(locPosition[i] > 0ul); - assert(val.size() <= locPosition[i]); + assert(val.size() >= locPosition[i]); assert(val[locPosition[i] - 1ul].first <= val[locPosition[i] - 1ul].second); return val[locPosition[i] - 1ul]; } From 30565d7f483edf6d732b81d7995f6b3540ec3ea1 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 18 Dec 2023 13:24:34 +0100 Subject: [PATCH 073/120] to be reverted change --- .github/workflows/builds.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index af5645db84e..d050328fb58 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -162,7 +162,7 @@ jobs: && export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH && pip3 install -r Examples/Python/tests/requirements.txt && pip3 install pytest-md-report - && pytest -rFsv -k "not exatrkx" -v + && pytest -rFv -k "not exatrkx" -v && cat ${PYTEST_MD_REPORT_OUTPUT} >> $GITHUB_STEP_SUMMARY linux_physmon: From 41a10bd89c286ec8f73897bc19228189dec1908e Mon Sep 17 00:00:00 2001 From: Carlo Varni <75478407+CarloVarni@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:28:06 +0100 Subject: [PATCH 074/120] Update builds.yml --- .github/workflows/builds.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index d050328fb58..73bcf491527 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -162,7 +162,7 @@ jobs: && export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH && pip3 install -r Examples/Python/tests/requirements.txt && pip3 install pytest-md-report - && pytest -rFv -k "not exatrkx" -v + && pytest -rFsv -k "not exatrkx" -v -s && cat ${PYTEST_MD_REPORT_OUTPUT} >> $GITHUB_STEP_SUMMARY linux_physmon: From f0728e0445227d75a0873c21f742336721220daa Mon Sep 17 00:00:00 2001 From: Carlo Varni <75478407+CarloVarni@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:44:23 +0100 Subject: [PATCH 075/120] Protection against empty zbin neighbours in example seeding alg --- Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index a7c5658c5b5..20fdcb460f0 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -206,9 +206,9 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( } m_bottomBinFinder = std::make_shared>( - m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom.empty() ? 1 : m_cfg.zBinNeighborsBottom); m_topBinFinder = std::make_shared>( - m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop.empty() ? 1 : m_cfg.zBinNeighborsTop); m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); From 04c9ba29088864b81d7fa2a2e0b0e98f8ccfc832 Mon Sep 17 00:00:00 2001 From: Carlo Varni <75478407+CarloVarni@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:51:47 +0100 Subject: [PATCH 076/120] Update SeedingAlgorithm.cpp --- .../TrackFinding/src/SeedingAlgorithm.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 20fdcb460f0..c8ea4838ff5 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -205,10 +205,17 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( }); } - m_bottomBinFinder = std::make_shared>( - m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom.empty() ? 1 : m_cfg.zBinNeighborsBottom); - m_topBinFinder = std::make_shared>( - m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop.empty() ? 1 : m_cfg.zBinNeighborsTop); + if (m_cfg.zBinNeighborsBottom.empty()) { + m_bottomBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, 1); + } else { + m_bottomBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); + } + + if (m_cfg.zBinNeighborsTop.empty()) { + m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, 1); + } else { + m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); + } m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); From 1adf1a8414710401f11974d2be137e912cbec6aa Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 09:42:57 +0100 Subject: [PATCH 077/120] test --- Core/include/Acts/Utilities/GridBinFinder.ipp | 17 ++++++++++++++--- .../TrackFinding/src/SeedingAlgorithm.cpp | 14 +++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 8010a110b6c..5976c1c89b0 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -7,6 +7,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include + template template Acts::GridBinFinder::GridBinFinder(args&&... vals) { @@ -29,11 +31,15 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, if constexpr (std::is_same::value) { /// if int -> value is positive assert(fv >= 0); + m_values[DIM - N - 1ul] = std::forward(fv); } else { - /// If vector of pairs -> it is not an empty vector - assert(not fv.empty()); + /// If vector of pairs -> also allow for empty vectors + if (not fv.empty()) { + m_values[DIM - N - 1ul] = std::forward(fv); + } else { + m_values[DIM - N - 1ul] = 1; + } } - m_values[DIM - N - 1ul] = std::forward(fv); if constexpr (N != 0ul) { storeValue(std::forward(others)...); } @@ -73,6 +79,11 @@ Acts::GridBinFinder::findBins( assert(isGridCompatible(binnedSP)); std::array, DIM> sizePerAxis = getSizePerAxis(locPosition); + std::cout << "using sizePerAxis = [ "; + for (std::size_t i(0ul); i>(m_cfg.numPhiNeighbors, 1); - } else { - m_bottomBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); - } - - if (m_cfg.zBinNeighborsTop.empty()) { - m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, 1); - } else { - m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); - } + + m_bottomBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); + m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); From a3a772b65d1573d5be8164fcb70f1ef727c32650 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 10:13:57 +0100 Subject: [PATCH 078/120] set default num phi neighbours to 1 --- .github/workflows/builds.yml | 2 +- Core/include/Acts/Utilities/GridBinFinder.ipp | 9 +-------- .../ActsExamples/TrackFinding/SeedingAlgorithm.hpp | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 73bcf491527..af5645db84e 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -162,7 +162,7 @@ jobs: && export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH && pip3 install -r Examples/Python/tests/requirements.txt && pip3 install pytest-md-report - && pytest -rFsv -k "not exatrkx" -v -s + && pytest -rFsv -k "not exatrkx" -v && cat ${PYTEST_MD_REPORT_OUTPUT} >> $GITHUB_STEP_SUMMARY linux_physmon: diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 5976c1c89b0..11ad72a090a 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -7,8 +7,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include - template template Acts::GridBinFinder::GridBinFinder(args&&... vals) { @@ -31,7 +29,7 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, if constexpr (std::is_same::value) { /// if int -> value is positive assert(fv >= 0); - m_values[DIM - N - 1ul] = std::forward(fv); + m_values[DIM - N - 1ul] = fv; } else { /// If vector of pairs -> also allow for empty vectors if (not fv.empty()) { @@ -79,11 +77,6 @@ Acts::GridBinFinder::findBins( assert(isGridCompatible(binnedSP)); std::array, DIM> sizePerAxis = getSizePerAxis(locPosition); - std::cout << "using sizePerAxis = [ "; - for (std::size_t i(0ul); i> zBinNeighborsBottom; // number of phiBin neighbors at each side of the current bin that will be // used to search for SPs - int numPhiNeighbors = 0; + int numPhiNeighbors = 1; }; /// Construct the seeding algorithm. From dfe672f6481e014fbade3774ac0c8c2f3679ec93 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 10:20:08 +0100 Subject: [PATCH 079/120] update comment --- Core/include/Acts/Utilities/GridBinFinder.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index f5c9489b1a1..9ffef1d17c8 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -68,7 +68,9 @@ class GridBinFinder { /// /// @pre both first_value_t and vals ... can be only int or std::vector> /// In the second case, the number of entries of the vector of pairs MUST be - /// equal to the number of bins in that specific axis + /// equal to the number of bins in that specific axis. Empty vectors are also allowed + /// but in this case the value will be replaced with a 1 (integer), thus instructing the code + /// to look for neighbours in the range {-1 ,1} template void storeValue(first_value_t&& fv, vals&&... others); @@ -102,7 +104,8 @@ class GridBinFinder { /// directions should be provided /// /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific - /// axis + /// axis. Empty vectors are also allowed but in this case the value will be replaced with a 1 (integer), + /// thus instructing the code to look for neighbours in the range {-1 ,1} std::array m_values{}; }; From 3800426a1e50cb2fe4c03b51b8d830f1b1c6a34a Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 10:36:48 +0100 Subject: [PATCH 080/120] format, license and spelling --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 24 ++++++++----------- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 3 +-- Core/include/Acts/Utilities/GridBinFinder.hpp | 15 ++++++------ Core/include/Acts/Utilities/GridBinFinder.ipp | 4 ++-- .../TrackFinding/src/SeedingAlgorithm.cpp | 7 +++--- .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 4 ++-- .../Cuda/Seeding/SeedFinderCudaTest.cpp | 4 ++-- .../UnitTests/Plugins/Cuda/Seeding2/main.cpp | 4 ++-- .../Sycl/Seeding/SeedFinderSyclTest.cpp | 4 ++-- 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 13e91903d52..e5ac6aaa969 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -93,16 +93,14 @@ class BinnedSPGroup { BinnedSPGroup() = delete; template - BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> - botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& _config, - const SeedFinderOptions& _options); + BinnedSPGroup(spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + std::shared_ptr> botBinFinder, + std::shared_ptr> tBinFinder, + std::unique_ptr> grid, + Acts::Extent& rRangeSPExtent, + const SeedFinderConfig& _config, + const SeedFinderOptions& _options); BinnedSPGroup(const BinnedSPGroup&) = delete; BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; @@ -131,10 +129,8 @@ class BinnedSPGroup { // GridBinFinder must return std::vector with content of // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder{ - nullptr}; - std::shared_ptr> m_bottomBinFinder{ - nullptr}; + std::shared_ptr> m_topBinFinder{nullptr}; + std::shared_ptr> m_bottomBinFinder{nullptr}; // Order of z bins to loop over when searching for SPs std::array, 2> m_bins{}; diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index b7760e3a297..661fa777b13 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -58,8 +58,7 @@ Acts::BinnedSPGroupIterator::operator*() const { m_group->m_bottomBinFinder->findBins(localPosition, *m_group->m_grid.get()); boost::container::small_vector tops = - m_group->m_topBinFinder->findBins(localPosition, - *m_group->m_grid.get()); + m_group->m_topBinFinder->findBins(localPosition, *m_group->m_grid.get()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index 9ffef1d17c8..24536ce4f47 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -20,7 +20,7 @@ namespace Acts { /// @class BinFinder -/// @tparam DIM Dimention of the Grid on which the GridBinFinder will be used +/// @tparam DIM Dimension of the Grid on which the GridBinFinder will be used /// /// The BinFinder is used by the ISPGroupSelector. It can be /// used to find both bins that could be bottom bins as well as bins that could @@ -68,9 +68,9 @@ class GridBinFinder { /// /// @pre both first_value_t and vals ... can be only int or std::vector> /// In the second case, the number of entries of the vector of pairs MUST be - /// equal to the number of bins in that specific axis. Empty vectors are also allowed - /// but in this case the value will be replaced with a 1 (integer), thus instructing the code - /// to look for neighbours in the range {-1 ,1} + /// equal to the number of bins in that specific axis. Empty vectors are also + /// allowed but in this case the value will be replaced with a 1 (integer), + /// thus instructing the code to look for neighbours in the range {-1 ,1} template void storeValue(first_value_t&& fv, vals&&... others); @@ -98,14 +98,15 @@ class GridBinFinder { private: using stored_values_t = std::variant>>; /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid - /// These values are provided by the user and an be wither ints or a vector of + /// These values are provided by the user and an be either ints or a vector of /// pair of ints. In the first case, the neighbours will be +/- bins from the /// given local bin In the second case, the user defines how many bins in both /// directions should be provided /// /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific - /// axis. Empty vectors are also allowed but in this case the value will be replaced with a 1 (integer), - /// thus instructing the code to look for neighbours in the range {-1 ,1} + /// axis. Empty vectors are also allowed but in this case the value will be + /// replaced with a 1 (integer), thus instructing the code to look for + /// neighbours in the range {-1 ,1} std::array m_values{}; }; diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index 11ad72a090a..f1c25cc34ba 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -1,4 +1,3 @@ -// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -58,7 +57,8 @@ std::array, DIM> Acts::GridBinFinder::getSizePerAxis( assert(locPosition.size() > i); assert(locPosition[i] > 0ul); assert(val.size() >= locPosition[i]); - assert(val[locPosition[i] - 1ul].first <= val[locPosition[i] - 1ul].second); + assert(val[locPosition[i] - 1ul].first <= + val[locPosition[i] - 1ul].second); return val[locPosition[i] - 1ul]; } }, diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 98909f22c4f..751f6ac71c2 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -205,9 +205,10 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( }); } - - m_bottomBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); - m_topBinFinder = std::make_shared>(m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); + m_bottomBinFinder = std::make_shared>( + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); + m_topBinFinder = std::make_shared>( + m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); m_cfg.seedFinderConfig.seedFilter = std::make_unique>(m_cfg.seedFilterConfig); diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 65650f5a90e..1dad0be93d4 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -166,9 +166,9 @@ int main(int argc, char** argv) { std::vector> zBinNeighborsBottom; auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); auto topBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index 7061dce83bd..b57e6c43cd6 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -214,9 +214,9 @@ int main(int argc, char** argv) { // binfinder auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); auto topBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); config.seedFilter = std::make_unique>( diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 3e45a710d84..fe26039dc6d 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -62,9 +62,9 @@ int main(int argc, char* argv[]) { // Create binned groups of these spacepoints. auto bottomBinFinder = std::make_shared>( - numPhiNeighbors, zBinNeighborsBottom); + numPhiNeighbors, zBinNeighborsBottom); auto topBinFinder = std::make_shared>( - numPhiNeighbors, zBinNeighborsTop); + numPhiNeighbors, zBinNeighborsTop); // Set up the seedFinder configuration. Acts::SeedFinderConfig sfConfig; diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index 9ac6d67bde7..87ccf96040f 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -160,9 +160,9 @@ auto main(int argc, char** argv) -> int { std::vector> zBinNeighborsBottom; auto bottomBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); auto topBinFinder = std::make_shared>( - Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); + Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); auto config = setupSeedFinderConfiguration(); config = config.toInternalUnits().calculateDerivedQuantities(); auto options = setupSeedFinderOptions(); From 63669c191afe7c0142e4851b13a1703a00f8779e Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 11:28:41 +0100 Subject: [PATCH 081/120] test with empty inputs --- .../Core/Utilities/GridBinFinderTests.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp index f154d4a9bd0..23acdcd2624 100644 --- a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -235,6 +235,37 @@ BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_pattern) { } } +BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_empty_pattern) { + const std::size_t nBinsX = 5ul; + const std::size_t nBinsY = 3ul; + Acts::detail::EquidistantAxis xAxis(0, 100, nBinsX); + Acts::detail::EquidistantAxis yAxis(0, 100, nBinsY); + Acts::Grid + grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); + + std::array, 2ul> navigation; + navigation[0ul].resize(nBinsX); + navigation[1ul].resize(nBinsY); + std::iota(navigation[0ul].begin(), navigation[0ul].end(), 1ul); + std::iota(navigation[1ul].begin(), navigation[1ul].end(), 1ul); + + std::vector> neighboursX; + std::vector> neighboursY; + + auto startGrid = grid.begin(navigation); + auto stopGrid = grid.end(navigation); + + Acts::GridBinFinder<2ul> binFinder(std::move(neighboursX), + std::move(neighboursY)); + + for (; startGrid != stopGrid; startGrid++) { + std::array locPosition = startGrid.localPosition(); + auto all_neigh = binFinder.findBins(locPosition, grid); + BOOST_CHECK_EQUAL(all_neigh.size(), 9ul); + } +} + BOOST_AUTO_TEST_CASE(grid_binfinder_test_2d_mixed) { const std::size_t nBinsX = 5ul; const std::size_t nBinsY = 3ul; From 623b3deb98cc128882c00b842e858b52b101367d Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 12:17:11 +0100 Subject: [PATCH 082/120] clang tidy --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 15 +++++++-------- Core/include/Acts/Utilities/GridBinFinder.ipp | 10 +++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 661fa777b13..9f107a8b93f 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -97,7 +97,10 @@ Acts::BinnedSPGroup::BinnedSPGroup( std::unique_ptr> grid, Acts::Extent& rRangeSPExtent, const SeedFinderConfig& config, - const SeedFinderOptions& options) { + const SeedFinderOptions& options) + : m_grid(std::move(grid)), + m_topBinFinder(std::move(tBinFinder)), + m_bottomBinFinder(std::move(botBinFinder)) { if (!config.isInInternalUnits) { throw std::runtime_error( "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); @@ -168,20 +171,20 @@ Acts::BinnedSPGroup::BinnedSPGroup( // fill rbins into grid Acts::Vector2 spLocation(isp->phi(), isp->z()); std::vector>>& - rbin = grid->atPosition(spLocation); + rbin = m_grid->atPosition(spLocation); rbin.push_back(std::move(isp)); // keep track of the bins we modify so that we can later sort the SPs in // those bins only if (rbin.size() > 1) { - rBinsIndex.insert(grid->globalBinFromPosition(spLocation)); + rBinsIndex.insert(m_grid->globalBinFromPosition(spLocation)); } } // sort SPs in R for each filled (z, phi) bin for (auto& binIndex : rBinsIndex) { std::vector>>& - rbin = grid->atPosition(binIndex); + rbin = m_grid->atPosition(binIndex); std::sort( rbin.begin(), rbin.end(), [](std::unique_ptr>& a, @@ -190,10 +193,6 @@ Acts::BinnedSPGroup::BinnedSPGroup( }); } - m_grid = std::move(grid); - m_bottomBinFinder = botBinFinder; - m_topBinFinder = tBinFinder; - m_skipZMiddleBin = config.skipZMiddleBinSearch; // phi axis diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index f1c25cc34ba..cc7a36c2651 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -31,7 +31,7 @@ void Acts::GridBinFinder::storeValue(first_value_t&& fv, m_values[DIM - N - 1ul] = fv; } else { /// If vector of pairs -> also allow for empty vectors - if (not fv.empty()) { + if (!fv.empty()) { m_values[DIM - N - 1ul] = std::forward(fv); } else { m_values[DIM - N - 1ul] = 1; @@ -72,12 +72,12 @@ template boost::container::small_vector Acts::GridBinFinder::findBins( const std::array& locPosition, - const Acts::Grid& binnedSP) const { + const Acts::Grid& grid) const { static_assert(sizeof...(Axes) == DIM); - assert(isGridCompatible(binnedSP)); + assert(isGridCompatible(grid)); std::array, DIM> sizePerAxis = getSizePerAxis(locPosition); - return binnedSP.neighborHoodIndices(locPosition, sizePerAxis).collect(); + return grid.neighborHoodIndices(locPosition, sizePerAxis).collect(); } template @@ -97,7 +97,7 @@ bool Acts::GridBinFinder::isGridCompatible( } }, m_values[i]); - if (not isCompabile) { + if (!isCompabile) { return false; } } From 66f834259c156bfff2b49f9483916fdbd054b722 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 19 Dec 2023 12:57:24 +0100 Subject: [PATCH 083/120] test constructor --- .../Core/Utilities/GridBinFinderTests.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp index 23acdcd2624..8eb151bf3fc 100644 --- a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -18,6 +18,22 @@ namespace Acts::Test { +BOOST_AUTO_TEST_CASE(grid_binfinder_constructor) { + using list_t = std::vector>; + Acts::GridBinFinder<1ul> binFinder_1d_1(1); + Acts::GridBinFinder<1ul> binFinder_1d_2(list_t({})); + Acts::GridBinFinder<1ul> binFinder_1d_3(list_t({{0, 2}, {-1, 1}})); + + Acts::GridBinFinder<2ul> binFinder_2d_1(1, 5); + Acts::GridBinFinder<2ul> binFinder_2d_2(list_t({}), + list_t({{0, 2}, {-1, 1}})); + Acts::GridBinFinder<2ul> binFinder_2d_3(list_t({}), 2); + + Acts::GridBinFinder<3ul> binFinder_3d_1(1, 1, 5); + + Acts::GridBinFinder<10ul> binFinder_10d_1(1, 1, 5, 0, 4, 2, 3, 1, 1, 9); +} + BOOST_AUTO_TEST_CASE(grid_binfinder_test_1d_ints) { const std::size_t nBins = 10ul; Acts::detail::EquidistantAxis xAxis(0, 100, nBins); From 62a0420acfd76ccf4d1a0927d2a15786781f70d0 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 21 Dec 2023 09:31:21 +0100 Subject: [PATCH 084/120] Move objects instead of copying --- Core/include/Acts/Seeding/SpacePointGrid.ipp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index d1e4ccf86f1..5577df32acf 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -115,24 +115,24 @@ Acts::SpacePointGridCreator::createGrid( // seeds // FIXME: zBinSize must include scattering float zBinSize = config.cotThetaMax * config.deltaRMax; - int zBins = - std::max(1, (int)std::floor((config.zMax - config.zMin) / zBinSize)); + float zBins = + std::max(1.f, std::floor((config.zMax - config.zMin) / zBinSize)); - for (int bin = 0; bin <= zBins; bin++) { + for (int bin = 0; bin <= static_cast(zBins); bin++) { AxisScalar edge = - config.zMin + bin * ((config.zMax - config.zMin) / (float)zBins); + config.zMin + bin * ((config.zMax - config.zMin) / zBins); zValues.push_back(edge); } } else { // Use the zBinEdges defined in the config - for (auto& bin : config.zBinEdges) { + for (float bin : config.zBinEdges) { zValues.push_back(bin); } } detail::Axis - zAxis(zValues); + zAxis(std::move(zValues)); return std::make_unique>( - std::make_tuple(phiAxis, zAxis)); + std::make_tuple(std::move(phiAxis), std::move(zAxis))); } From 044bab283f9824e1429a5a08bf6b7deefc221a01 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 21 Dec 2023 10:22:22 +0100 Subject: [PATCH 085/120] reserve --- Core/include/Acts/Seeding/SpacePointGrid.ipp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index 5577df32acf..e65f31c2eb4 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -118,6 +118,7 @@ Acts::SpacePointGridCreator::createGrid( float zBins = std::max(1.f, std::floor((config.zMax - config.zMin) / zBinSize)); + zValues.reserve(static_cast(zBins)); for (int bin = 0; bin <= static_cast(zBins); bin++) { AxisScalar edge = config.zMin + bin * ((config.zMax - config.zMin) / zBins); @@ -126,6 +127,7 @@ Acts::SpacePointGridCreator::createGrid( } else { // Use the zBinEdges defined in the config + zValues.reserve(config.zBinEdges.size()); for (float bin : config.zBinEdges) { zValues.push_back(bin); } From ad408143e726b3308f554c539c163d5ca0bfd20e Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 21 Dec 2023 14:00:22 +0100 Subject: [PATCH 086/120] First implementation --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 183 +++++++---------- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 194 ++++++------------ .../Acts/Seeding/BinnedSPGroupIterator.hpp | 121 +++++++++++ .../Acts/Seeding/BinnedSPGroupIterator.ipp | 91 ++++++++ .../TrackFinding/src/SeedingAlgorithm.cpp | 15 +- 5 files changed, 361 insertions(+), 243 deletions(-) create mode 100644 Core/include/Acts/Seeding/BinnedSPGroupIterator.hpp create mode 100644 Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 391f6f05975..9a3787a396b 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -9,128 +9,95 @@ #pragma once #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/InternalSeed.hpp" -#include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" +#include "Acts/Seeding/BinnedSPGroupIterator.hpp" #include #include -#include - namespace Acts { -template -class BinnedSPGroup; - -/// @c BinnedSPGroupIterator Allows to iterate over all groups of bins -/// a provided GridBinFinder can generate for each bin of a provided SPGrid - -/// SpacePointGrid is a very specific structure. -/// We know it is 2D and what it contains -/// No need to be too general with this class -template -class BinnedSPGroupIterator { - private: - enum INDEX : int { PHI = 0, Z = 1 }; - - public: - // Never take ownerships - BinnedSPGroupIterator(BinnedSPGroup&& group, - std::array index, - std::array, 2> navigation) = - delete; - BinnedSPGroupIterator(BinnedSPGroup& group, - std::array index, - std::array, 2> navigation); - - BinnedSPGroupIterator(const BinnedSPGroupIterator&) = delete; - BinnedSPGroupIterator& operator=(const BinnedSPGroupIterator&) = delete; - - BinnedSPGroupIterator(BinnedSPGroupIterator&&) noexcept = default; - BinnedSPGroupIterator& operator=(BinnedSPGroupIterator&&) noexcept = default; - - ~BinnedSPGroupIterator() = default; - BinnedSPGroupIterator& operator++(); - - bool operator==(const BinnedSPGroupIterator& other) const; - bool operator!=(const BinnedSPGroupIterator& other) const; - - std::tuple, std::size_t, - boost::container::small_vector> - operator*() const; - - private: - void findNotEmptyBin(); - - private: - // The group, it contains the grid and the bin finders - Acts::detail::RefHolder> m_group; - // Current grid iterator - typename Acts::SpacePointGrid::local_iterator_t - m_gridItr; - // End iterator - typename Acts::SpacePointGrid::local_iterator_t - m_gridItrEnd; -}; - -/// @c BinnedSPGroup Provides access to begin and end BinnedSPGroupIterator -/// for given GridBinFinders and SpacePointGrid. -/// Fulfills the range_expression interface. -template -class BinnedSPGroup { +template +class BinnedGroup { +public: #ifndef DOXYGEN - friend BinnedSPGroupIterator; + friend BinnedGroupIterator; #endif - enum INDEX : int { PHI = 0, Z = 1 }; - - public: - BinnedSPGroup() = delete; - - template - BinnedSPGroup(spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& _config, - const SeedFinderOptions& _options); - - BinnedSPGroup(const BinnedSPGroup&) = delete; - BinnedSPGroup& operator=(const BinnedSPGroup&) = delete; - - BinnedSPGroup(BinnedSPGroup&&) noexcept = default; - BinnedSPGroup& operator=(BinnedSPGroup&&) noexcept = default; - - ~BinnedSPGroup() = default; - - std::size_t size() const; - - BinnedSPGroupIterator begin(); - BinnedSPGroupIterator end(); - - Acts::SpacePointGrid& grid() { - return *m_grid.get(); - } - - private: - // grid with ownership of all InternalSpacePoint - std::unique_ptr> m_grid{nullptr}; - - // GridBinFinder must return std::vector with content of - // each bin sorted in r (ascending) - std::shared_ptr> m_topBinFinder{nullptr}; - std::shared_ptr> m_bottomBinFinder{nullptr}; - - // Order of z bins to loop over when searching for SPs - std::array, 2> m_bins{}; + static constexpr std::size_t DIM = grid_t::DIM; + + /// @brief Default constructor + BinnedGroup() = delete; + + /// brief Constructor + BinnedGroup(std::unique_ptr grid, + std::shared_ptr> bottomFinder, + std::shared_ptr> topFinder, + std::array, DIM> navigation = std::array, DIM>()); + + /// @brief Copy constructor + /// @param [in] other The BinnedGroup to copy + BinnedGroup(const BinnedGroup& other) = default; + /// @brief Copy assignment + /// @param [in] other The BinnedGroup to copy + /// @return The copied BinnedGroup + BinnedGroup& operator=(const BinnedGroup& other) = default; + + /// @brief Move Constructor + /// @param [in] other The BinnedGroup to move + BinnedGroup(BinnedGroup&& other) noexcept = default; + /// @brief Move Assignment + /// @param [in] other The BinnedGroup to move + /// @return The moved BinnedGroup + BinnedGroup& operator=(BinnedGroup&& other) noexcept = default; + + /// @brief Default destructor + ~BinnedGroup() = default; + + /// @brief Retrieve const reference to the Grid + /// @return Const reference to the stored grid + const grid_t& grid() const; + /// @brief Retrieve mutable reference to the Grid + /// @return Mutable reference to the stored grid + grid_t& grid(); + + /// @brief Get the begin iterator + /// @return The iterator + Acts::BinnedGroupIterator begin() const; + /// @brief Get the end iterator + /// @return The iterator + Acts::BinnedGroupIterator end() const; + + /// @brief Fill the grid + template < typename external_spacepoint_t, + typename spacepoint_iterator_t, + typename callable_t> + void fill(const Acts::SeedFinderConfig& config, + const SeedFinderOptions& options, + spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent); + +private: + /// @brief The N-dimentional grid + std::unique_ptr m_grid{nullptr}; + /// @brief The Grid Bin Finder for bottom candidates + std::shared_ptr> m_bottomBinFinder{nullptr}; + /// @brief The Grid Bin Finder for top candidates + std::shared_ptr> m_topBinFinder{nullptr}; + /// @brief Order of bins to loop over when searching for SPs + std::array, DIM> m_bins{}; }; -} // namespace Acts +} // namespace Acts + #include "Acts/Seeding/BinnedSPGroup.ipp" + +namespace Acts { + template + using BinnedSPGroup = Acts::BinnedGroup>; +} diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 65f0aea3eef..2134a0afdfc 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2023 CERN for the benefit of the Acts project @@ -10,97 +11,68 @@ #include -template -Acts::BinnedSPGroupIterator::BinnedSPGroupIterator( - Acts::BinnedSPGroup& group, - std::array index, - std::array, 2> navigation) - : m_group(group), m_gridItr(*group.m_grid.get(), index, navigation) { - std::array endline{}; - endline[0ul] = navigation[0ul].size(); - endline[1ul] = navigation[1ul].size(); - m_gridItrEnd = - typename Acts::SpacePointGrid::local_iterator_t( - *group.m_grid.get(), endline, std::move(navigation)); - findNotEmptyBin(); -} - -template -inline Acts::BinnedSPGroupIterator& -Acts::BinnedSPGroupIterator::operator++() { - ++m_gridItr; - findNotEmptyBin(); - return *this; -} - -template -inline bool Acts::BinnedSPGroupIterator::operator==( - const Acts::BinnedSPGroupIterator& other) const { - return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; +namespace Acts { + +template +BinnedGroup::BinnedGroup(std::unique_ptr grid, + std::shared_ptr::DIM>> bottomFinder, + std::shared_ptr::DIM>> topFinder, + std::array, Acts::BinnedGroup::DIM> navigation) + : m_grid(std::move(grid)), + m_bottomBinFinder(std::move(bottomFinder)), + m_topBinFinder(std::move(topFinder)), + m_bins(std::move(navigation)) +{ + assert(m_grid != nullptr); + assert(m_bottomBinFinder != nullptr); + assert(m_topBinFinder != nullptr); + + /// If navigation is now defined for all axes, then we default that to a std::iota from 1ul + std::array numLocBins = m_grid->numLocalBins(); + for (std::size_t i(0ul); i +const grid_t& BinnedGroup::grid() const { return *m_grid.get(); } -template -inline bool Acts::BinnedSPGroupIterator::operator!=( - const Acts::BinnedSPGroupIterator& other) const { - return !(*this == other); -} +template +grid_t& BinnedGroup::grid() { return *m_grid.get(); } -template -std::tuple, std::size_t, - boost::container::small_vector> -Acts::BinnedSPGroupIterator::operator*() const { - // Global Index - std::array localPosition = m_gridItr.localPosition(); - std::size_t global_index = - m_group->m_grid->globalBinFromLocalBins(localPosition); - - boost::container::small_vector bottoms = - m_group->m_bottomBinFinder->findBins(localPosition, - *m_group->m_grid.get()); - boost::container::small_vector tops = - m_group->m_topBinFinder->findBins(localPosition, *m_group->m_grid.get()); - - // GCC12+ in Release throws an overread warning here due to the move. - // This is from inside boost code, so best we can do is to suppress it. -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-overread" -#endif - return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); -#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) -#pragma GCC diagnostic pop -#endif +template +Acts::BinnedGroupIterator BinnedGroup::begin() const { + return Acts::BinnedGroupIterator(*this, std::array::DIM>(), m_bins); } -template -inline void -Acts::BinnedSPGroupIterator::findNotEmptyBin() { - if (m_gridItr == m_gridItrEnd) { - return; - } - // Iterate on the grid till we find a not-empty bin - // We start from the current bin configuration and move forward - std::size_t dimCollection = (*m_gridItr).size(); - while (dimCollection == 0ul && ++m_gridItr != m_gridItrEnd) { - dimCollection = (*m_gridItr).size(); +template +Acts::BinnedGroupIterator BinnedGroup::end() const { + std::array::DIM> endline{}; + for (std::size_t i(0ul); i::DIM; ++i) { + endline[i] = m_bins[i].size(); } + return Acts::BinnedGroupIterator(*this, endline, m_bins); } -// Binned SP Group -template -template -Acts::BinnedSPGroup::BinnedSPGroup( - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - std::shared_ptr> botBinFinder, - std::shared_ptr> tBinFinder, - std::unique_ptr> grid, - Acts::Extent& rRangeSPExtent, - const SeedFinderConfig& config, - const SeedFinderOptions& options) - : m_grid(std::move(grid)), - m_topBinFinder(std::move(tBinFinder)), - m_bottomBinFinder(std::move(botBinFinder)) { +template +template +void BinnedGroup::fill(const Acts::SeedFinderConfig& config, + const Acts::SeedFinderOptions& options, + external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent) { + + using iterated_value_t = typename std::iterator_traits::value_type; + using iterated_t = typename std::remove_const::type>::type; + static_assert(std::is_same::value, + "Iterator does not contain type this class was templated with"); + if (!config.isInInternalUnits) { throw std::runtime_error( "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); @@ -109,11 +81,6 @@ Acts::BinnedSPGroup::BinnedSPGroup( throw std::runtime_error( "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); } - static_assert( - std::is_same< - typename std::iterator_traits::value_type, - const external_spacepoint_t*>::value, - "Iterator does not contain type this class was templated with"); // get region of interest (or full detector if configured accordingly) float phiMin = config.phiMin; @@ -132,8 +99,8 @@ Acts::BinnedSPGroup::BinnedSPGroup( // keep track of changed bins while sorting boost::container::flat_set rBinsIndex; - std::size_t counter = 0; - for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { + std::size_t counter = 0ul; + for (external_spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { if (*it == nullptr) { continue; } @@ -145,7 +112,7 @@ Acts::BinnedSPGroup::BinnedSPGroup( float spY = spPosition[1]; float spZ = spPosition[2]; - // store x,y,z values in extent + // store x,y,z values in extent rRangeSPExtent.extend({spX, spY, spZ}); // remove SPs outside z and phi region @@ -180,49 +147,16 @@ Acts::BinnedSPGroup::BinnedSPGroup( rBinsIndex.insert(m_grid->globalBinFromPosition(spLocation)); } } - - // sort SPs in R for each filled (z, phi) bin + + /// sort SPs in R for each filled bin for (auto& binIndex : rBinsIndex) { - std::vector>>& - rbin = m_grid->atPosition(binIndex); + auto& rbin = m_grid->atPosition(binIndex); std::sort( rbin.begin(), rbin.end(), - [](std::unique_ptr>& a, - std::unique_ptr>& b) { + [](const auto& a, const auto& b) { return a->radius() < b->radius(); }); - } - - // phi axis - m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); - std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1ul); - - // z axis - if (config.zBinsCustomLooping.empty()) { - std::size_t nZbins = m_grid->numLocalBins()[INDEX::Z]; - m_bins[INDEX::Z] = std::vector(nZbins); - std::iota(m_bins[INDEX::Z].begin(), m_bins[INDEX::Z].end(), 1ul); - } else { - m_bins[INDEX::Z] = config.zBinsCustomLooping; - } + } } -template -inline std::size_t Acts::BinnedSPGroup::size() const { - return m_grid->size(); -} - -template -inline Acts::BinnedSPGroupIterator -Acts::BinnedSPGroup::begin() { - return {*this, {0ul, 0ul}, m_bins}; -} - -template -inline Acts::BinnedSPGroupIterator -Acts::BinnedSPGroup::end() { - std::array endline{}; - endline[0ul] = m_bins[0ul].size(); - endline[1ul] = m_bins[1ul].size(); - return {*this, endline, m_bins}; -} +} // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedSPGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedSPGroupIterator.hpp new file mode 100644 index 00000000000..8392bcdf7fa --- /dev/null +++ b/Core/include/Acts/Seeding/BinnedSPGroupIterator.hpp @@ -0,0 +1,121 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridIterator.hpp" +#include "Acts/Utilities/Holders.hpp" +#include "Acts/Utilities/detail/grid_helper.hpp" + +#include +#include + +#include + +namespace Acts { +template +class BinnedGroup; + +template +class BinnedGroupIterator { +public: + static constexpr std::size_t DIM = grid_t::DIM; + + /// @brief Constructor + /// Never take the ownership of the group + /// + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator(Acts::BinnedGroup&& group, + std::array index, + std::array, DIM> navigation) = delete; + + /// @brief Constructor + /// Never take the ownership of the group + /// + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator(const Acts::BinnedGroup&& group, + std::array index, + std::array, DIM> navigation) = delete; + + /// @brief Constructor + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator(const Acts::BinnedGroup& group, + std::array index, + std::array, DIM> navigation); + + /// Do not allow Copy operations + + /// @brief Copy Constructor + /// @param [in] other The BinnedGroupIterator to copy + BinnedGroupIterator(const BinnedGroupIterator& other) = delete; + /// @brief Copy assignment + /// @param [in] other The BinnedGroupIterator to copy + /// @return The copied BinnedGroupIterator + BinnedGroupIterator& operator=(const BinnedGroupIterator& other) = delete; + + /// @brief Move Constructor + /// @param [in] other The BinnedGroupIterator to move + BinnedGroupIterator(BinnedGroupIterator&& other) noexcept = default; + /// @brief Move assignment + /// @param [in] other The BinnedGroupIterator to move + /// @return The moved BinnedGroupIterator + BinnedGroupIterator& operator=(BinnedGroupIterator&& other) noexcept = default; + + /// @brief Default Destructor + ~BinnedGroupIterator() = default; + + + /// @brief Equality operator + /// @param [in] other The BinnedGroupIterator we are comparing against this one + /// @return The result of the comparison + bool operator==(const BinnedGroupIterator& other) const; + /// @brief (In-)Equality operator + /// @param [in] other The BinnedGroupIterator we are comparing against this one + /// @return The result of the comparison + bool operator!=(const BinnedGroupIterator& other) const; + + /// @brief Increment the iterator by one (pre) + /// @return The incremented iterator + BinnedGroupIterator& operator++(); + + /// @brief Return the current bin with the middle candidate, as well as all the + /// bins with the possible bottom and top candidates + /// + /// @return The collection of all the bins in the grid + std::tuple, std::size_t, + boost::container::small_vector> + operator*() const; + +private: + /// @brief Move to the next not-empty bin in the grid + void findNotEmptyBin(); + +private: + /// @brief The group that contains the grid and the bin finders + Acts::detail::RefHolder> m_group{nullptr}; + /// @brief Current N-dimentional grid iterator + typename grid_t::local_iterator_t m_gridItr; + /// @brief End iterator; + typename grid_t::local_iterator_t m_gridItrEnd; +}; + +} // namespace Acts + +#include "Acts/Seeding/BinnedSPGroupIterator.ipp" + +namespace Acts { + template + using BinnedSPGroupIterator = BinnedGroupIterator>>; +} diff --git a/Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp new file mode 100644 index 00000000000..9f7fed162a2 --- /dev/null +++ b/Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp @@ -0,0 +1,91 @@ +// -*- C++ -*- +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +// Binned SP Group Iterator + +namespace Acts { + +template +BinnedGroupIterator::BinnedGroupIterator(const Acts::BinnedGroup& group, + std::array::DIM> index, + std::array, Acts::BinnedGroupIterator::DIM> navigation) + : m_group(group), + m_gridItr(*group.m_grid.get(), index, navigation) +{ + std::array endline{}; + for (std::size_t i(0ul); i +bool BinnedGroupIterator::operator==(const Acts::BinnedGroupIterator& other) const { + return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; +} + +template +bool BinnedGroupIterator::operator!=(const Acts::BinnedGroupIterator& other) const { + return !(*this == other); +} + +template +Acts::BinnedGroupIterator& +BinnedGroupIterator::operator++() { + ++m_gridItr; + findNotEmptyBin(); + return *this; +} + +template +std::tuple::DIM)>, std::size_t, + boost::container::small_vector::DIM)>> +BinnedGroupIterator::operator*() const { + /// Get the global and local position from current iterator. This is the bin with the middle candidate + /// And we know this is not an empty bin + std::array localPosition = m_gridItr.localPosition(); + std::size_t global_index = + m_group->m_grid->globalBinFromLocalBins(localPosition); + + /// Get the neighbouring bins + boost::container::small_vector::DIM)> bottoms = + m_group->m_bottomBinFinder->findBins(localPosition, + *m_group->m_grid.get()); + boost::container::small_vector::DIM)> tops = + m_group->m_topBinFinder->findBins(localPosition, *m_group->m_grid.get()); + + // GCC12+ in Release throws an overread warning here due to the move. + // This is from inside boost code, so best we can do is to suppress it. +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overread" +#endif + return std::make_tuple(std::move(bottoms), global_index, std::move(tops)); +#if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) +#pragma GCC diagnostic pop +#endif +} + +template +void BinnedGroupIterator::findNotEmptyBin() { + if (m_gridItr == m_gridItrEnd) { + return; + } + /// Iterate on the grid till we find a not-empty bin + /// We start from the current bin configuration and move forward + std::size_t dimCollection = (*m_gridItr).size(); + while (dimCollection == 0ul && ++m_gridItr != m_gridItrEnd) { + dimCollection = (*m_gridItr).size(); + } +} + +} // namespace Acts diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 751f6ac71c2..2697729b142 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -252,11 +252,16 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( auto grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); - auto spacePointsGrouping = Acts::BinnedSPGroup( - spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, - m_bottomBinFinder, m_topBinFinder, std::move(grid), rRangeSPExtent, - m_cfg.seedFinderConfig, m_cfg.seedFinderOptions); - + std::array, 2ul> navigation; + navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; + auto spacePointsGrouping = Acts::BinnedSPGroup(std::move(grid), + m_bottomBinFinder, + m_topBinFinder, + std::move(navigation)); + spacePointsGrouping.fill(m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, + spacePointPtrs.begin(), spacePointPtrs.end(), + extractGlobalQuantities, rRangeSPExtent); + // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); From a1f6bae1fa259dc2185cddb47a0f75c4a684ded5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 21 Dec 2023 22:26:59 +0100 Subject: [PATCH 087/120] Implementation and tests --- .../{BinnedSPGroup.hpp => BinnedGroup.hpp} | 24 +- .../{BinnedSPGroup.ipp => BinnedGroup.ipp} | 16 +- ...upIterator.hpp => BinnedGroupIterator.hpp} | 2 +- ...upIterator.ipp => BinnedGroupIterator.ipp} | 0 .../TrackFinding/src/SeedingAlgorithm.cpp | 2 +- .../Core/Seeding/BinnedGroupTest.cpp | 269 ++++++++++++++++++ Tests/UnitTests/Core/Seeding/CMakeLists.txt | 2 + .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 8 +- 8 files changed, 310 insertions(+), 13 deletions(-) rename Core/include/Acts/Seeding/{BinnedSPGroup.hpp => BinnedGroup.hpp} (75%) rename Core/include/Acts/Seeding/{BinnedSPGroup.ipp => BinnedGroup.ipp} (93%) rename Core/include/Acts/Seeding/{BinnedSPGroupIterator.hpp => BinnedGroupIterator.hpp} (98%) rename Core/include/Acts/Seeding/{BinnedSPGroupIterator.ipp => BinnedGroupIterator.ipp} (100%) create mode 100644 Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp similarity index 75% rename from Core/include/Acts/Seeding/BinnedSPGroup.hpp rename to Core/include/Acts/Seeding/BinnedGroup.hpp index 9a3787a396b..c1d3954f00c 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -14,13 +14,19 @@ #include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" -#include "Acts/Seeding/BinnedSPGroupIterator.hpp" +#include "Acts/Seeding/BinnedGroupIterator.hpp" #include #include namespace Acts { +/// @class BinnedGroup +/// @tparam grid_t Type of the grid the group owns +/// +/// The assumption is that the grid has ownership of the space points and +/// that the grid value_type (i.e. T in Grid) is an iterable +/// object of space points, such as a vector< ... > template class BinnedGroup { public: @@ -41,11 +47,11 @@ class BinnedGroup { /// @brief Copy constructor /// @param [in] other The BinnedGroup to copy - BinnedGroup(const BinnedGroup& other) = default; + BinnedGroup(const BinnedGroup& other) = delete; /// @brief Copy assignment /// @param [in] other The BinnedGroup to copy /// @return The copied BinnedGroup - BinnedGroup& operator=(const BinnedGroup& other) = default; + BinnedGroup& operator=(const BinnedGroup& other) = delete; /// @brief Move Constructor /// @param [in] other The BinnedGroup to move @@ -73,6 +79,16 @@ class BinnedGroup { Acts::BinnedGroupIterator end() const; /// @brief Fill the grid + /// @tparam external_spacepoint_t The type of the external space points + /// @tparam spacepoint_iterator_t The type of the iterator on the collection of external space points + /// @tparam callable_t The type of the function for extracting global info + /// + /// @param [in] config Configuration object for the seed finder + /// @param [in] options Seed Finder options + /// @param [in] spBegin First element to be inserted in the grid + /// @param [in] spEnd Last element to be inserted in the grid + /// @param [in] toGlobal User-provided function for extracting global quantities from external space points + /// @param [in] rRangeSPExtent An Acts Extent object template < typename external_spacepoint_t, typename spacepoint_iterator_t, typename callable_t> @@ -95,7 +111,7 @@ class BinnedGroup { } // namespace Acts -#include "Acts/Seeding/BinnedSPGroup.ipp" +#include "Acts/Seeding/BinnedGroup.ipp" namespace Acts { template diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp similarity index 93% rename from Core/include/Acts/Seeding/BinnedSPGroup.ipp rename to Core/include/Acts/Seeding/BinnedGroup.ipp index 2134a0afdfc..d9a44b54673 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -39,10 +39,20 @@ BinnedGroup::BinnedGroup(std::unique_ptr grid, } template -const grid_t& BinnedGroup::grid() const { return *m_grid.get(); } +const grid_t& BinnedGroup::grid() const { + if (m_grid == nullptr) { + throw std::runtime_error("Trying to retrieve grid from Binned Group, but grid is a nullptr!"); + } + return *m_grid.get(); +} template -grid_t& BinnedGroup::grid() { return *m_grid.get(); } +grid_t& BinnedGroup::grid() { + if (m_grid == nullptr) { + throw std::runtime_error("Trying to retrieve grid from Binned Group, but grid is a nullptr!"); + } + return *m_grid.get(); +} template Acts::BinnedGroupIterator BinnedGroup::begin() const { @@ -158,5 +168,5 @@ void BinnedGroup::fill(const Acts::SeedFinderConfig diff --git a/Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp similarity index 100% rename from Core/include/Acts/Seeding/BinnedSPGroupIterator.ipp rename to Core/include/Acts/Seeding/BinnedGroupIterator.ipp diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 2697729b142..a47356e1cf4 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -11,7 +11,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/SpacePointData.hpp" #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Utilities/BinningType.hpp" diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp new file mode 100644 index 00000000000..c27676381d8 --- /dev/null +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -0,0 +1,269 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include "Acts/Geometry/Extent.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" +#include "Acts/Seeding/SeedFilter.hpp" +#include "Acts/Utilities/Grid.hpp" +#include "Acts/Utilities/GridBinFinder.hpp" +#include "Acts/Utilities/GridIterator.hpp" + +#include +#include +#include + +namespace Acts::Test { + +BOOST_AUTO_TEST_CASE(binned_group_constructor) { + Acts::detail::EquidistantAxis xAxis(0, 100, 10); + Acts::detail::EquidistantAxis yAxis(0, 100, 10); + Acts::detail::EquidistantAxis zAxis(0, 100, 10); + + using grid_1d_t = + Acts::Grid, Acts::detail::EquidistantAxis>; + using grid_2d_t = + Acts::Grid, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis>; + using grid_3d_t = + Acts::Grid, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis>; + + std::unique_ptr grid_1d = + std::make_unique(std::make_tuple(xAxis)); + std::unique_ptr grid_2d = + std::make_unique(std::make_tuple(xAxis, yAxis)); + std::unique_ptr grid_3d = + std::make_unique(std::make_tuple(xAxis, yAxis, zAxis)); + + std::shared_ptr> binFinder_1d = + std::make_shared>(1); + std::shared_ptr> binFinder_2d = + std::make_shared>(1, 1); + std::shared_ptr> binFinder_3d = + std::make_shared>(1, 2, 1); + + std::array, 1ul> navigation_1d; + navigation_1d[0ul].resize(10); + std::array, 2ul> navigation_2d; + navigation_2d[1ul].resize(10); + + // Costructors + // We provide a proper navigation + Acts::BinnedGroup group_1d(std::move(grid_1d), binFinder_1d, + binFinder_1d, std::move(navigation_1d)); + // We provide a partial navigation, the constructor will complete it + Acts::BinnedGroup group_2d(std::move(grid_2d), binFinder_2d, + binFinder_2d, std::move(navigation_2d)); + // We do not provide navigation, the constructor will define it + Acts::BinnedGroup group_3d(std::move(grid_3d), binFinder_3d, + binFinder_3d); + + BOOST_CHECK_NO_THROW(group_1d.grid()); + BOOST_CHECK_NO_THROW(group_2d.grid()); + BOOST_CHECK_NO_THROW(group_3d.grid()); + + // Move Constructor/Assignment + const Acts::BinnedGroup group_1d_moved(std::move(group_1d)); + const Acts::BinnedGroup group_2d_moved(std::move(group_2d)); + const Acts::BinnedGroup group_3d_moved = std::move(group_3d); + + BOOST_CHECK_THROW(group_1d.grid(), std::runtime_error); + BOOST_CHECK_THROW(group_2d.grid(), std::runtime_error); + BOOST_CHECK_THROW(group_3d.grid(), std::runtime_error); + + BOOST_CHECK_NO_THROW(group_1d_moved.grid()); + BOOST_CHECK_NO_THROW(group_2d_moved.grid()); + BOOST_CHECK_NO_THROW(group_3d_moved.grid()); + + // With some nullptr inputs + std::unique_ptr grid_1d_nullTest_1 = + std::make_unique(std::make_tuple(xAxis)); + std::unique_ptr grid_1d_nullTest_2 = + std::make_unique(std::make_tuple(xAxis)); + + Acts::BinnedGroup group_1d_nullBotFinder( + std::move(grid_1d_nullTest_1), nullptr, binFinder_1d); + Acts::BinnedGroup group_1d_nullTopFinder( + std::move(grid_1d_nullTest_2), binFinder_1d, nullptr); + + BOOST_CHECK_NO_THROW(group_1d_nullBotFinder.grid()); + BOOST_CHECK_NO_THROW(group_1d_nullTopFinder.grid()); +} + +BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { + using grid_t = + Acts::Grid, Acts::detail::EquidistantAxis>; + using binfinder_t = Acts::GridBinFinder<1ul>; + + Acts::detail::EquidistantAxis xAxis(0, 100, 10); + std::unique_ptr grid = + std::make_unique(std::make_tuple(xAxis)); + std::shared_ptr binfinder = std::make_shared(0); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + + Acts::BinnedGroupIterator itrStart = group.begin(); + Acts::BinnedGroupIterator itrStop = group.end(); + + std::size_t nIterations = 0ul; + for (; itrStart != itrStop; ++itrStart, ++nIterations) { + } + + BOOST_CHECK_EQUAL(nIterations, 0ul); +} + +BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { + using grid_t = + Acts::Grid, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis>; + using binfinder_t = Acts::GridBinFinder<2ul>; + + Acts::detail::EquidistantAxis xAxis(0, 100, 10); + Acts::detail::EquidistantAxis yAxis(0, 100, 10); + std::unique_ptr grid = std::make_unique( + std::make_tuple(std::move(xAxis), std::move(yAxis))); + std::shared_ptr binfinder = std::make_shared(0, 0); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + + Acts::BinnedGroupIterator itrStart = group.begin(); + Acts::BinnedGroupIterator itrStop = group.end(); + + std::size_t nIterations = 0ul; + for (; itrStart != itrStop; ++itrStart, ++nIterations) { + } + + BOOST_CHECK_EQUAL(nIterations, 0ul); +} + +BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { + using grid_t = + Acts::Grid, Acts::detail::EquidistantAxis>; + using binfinder_t = Acts::GridBinFinder<1ul>; + + Acts::detail::EquidistantAxis xAxis(0, 100, 10); + std::unique_ptr grid = + std::make_unique(std::make_tuple(xAxis)); + /// Add some entries to the grid + grid->at(1ul).push_back(4ul); + grid->at(1ul).push_back(1ul); + grid->at(8ul).push_back(7ul); + grid->at(9ul).push_back(2ul); + + std::shared_ptr botBinfinder = std::make_shared(0); + std::shared_ptr topBinfinder = std::make_shared(1); + Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); + + std::size_t nIterations = 0ul; + for (const auto [bottom, middle, top] : group) { + ++nIterations; + BOOST_CHECK_EQUAL(bottom.size(), 1ul); + BOOST_CHECK_EQUAL(top.size(), 3ul); + } + + BOOST_CHECK_EQUAL(nIterations, 3ul); +} + +BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { + using grid_t = + Acts::Grid, Acts::detail::EquidistantAxis, + Acts::detail::EquidistantAxis>; + using binfinder_t = Acts::GridBinFinder<2ul>; + + Acts::detail::EquidistantAxis xAxis(0, 100, 10); + Acts::detail::EquidistantAxis yAxis(0, 100, 10); + std::unique_ptr grid = + std::make_unique(std::make_tuple(xAxis, yAxis)); + /// Add some entries to the grid + grid->atLocalBins({2ul, 4ul}).push_back(4ul); + grid->atLocalBins({4ul, 4ul}).push_back(4ul); + + std::shared_ptr botBinfinder = + std::make_shared(1, 2); + std::shared_ptr topBinfinder = + std::make_shared(1, 1); + Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); + + std::size_t nIterations = 0ul; + for (const auto [bottom, middle, top] : group) { + ++nIterations; + BOOST_CHECK_EQUAL(bottom.size(), 15ul); + BOOST_CHECK_EQUAL(top.size(), 9ul); + } + + BOOST_CHECK_EQUAL(nIterations, 2ul); +} + +BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { + struct point {}; + + using value_t = std::unique_ptr>; + using phiAxis_t = Acts::detail::Axis; + using zAxis_t = detail::Axis; + using grid_t = Acts::Grid, phiAxis_t, zAxis_t>; + using binfinder_t = Acts::GridBinFinder<2ul>; + + phiAxis_t phiAxis(-M_PI, M_PI, 40); + zAxis_t zAxis(0, 100, 10); + + std::unique_ptr grid = std::make_unique( + std::make_tuple(std::move(phiAxis), std::move(zAxis))); + std::shared_ptr binfinder = std::make_shared(1, 1); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + + auto extractionFunction = + [](const point&, float, float, + float) -> std::pair { + return std::make_pair(Acts::Vector3({2, 4, 2}), Acts::Vector2({0, 0})); + }; + Acts::Extent extent; + Acts::SeedFinderConfig config; + Acts::SeedFinderOptions options; + + std::vector collection; + for (std::size_t i(0ul); i < 30ul; ++i) { + collection.push_back(new point()); + } + + BOOST_CHECK_THROW( + group.fill(config.toInternalUnits(), options.toInternalUnits(), + collection.begin(), collection.end(), + std::move(extractionFunction), extent), + std::runtime_error); + + Acts::SeedFilterConfig seedFilterConfig; + config.seedFilter = std::make_shared>( + seedFilterConfig.toInternalUnits()); + + BOOST_CHECK_NO_THROW(group.fill( + config.toInternalUnits(), options.toInternalUnits(), collection.begin(), + collection.end(), std::move(extractionFunction), extent)); + + BOOST_CHECK_THROW( + group.fill(config, options.toInternalUnits(), collection.begin(), + collection.begin(), std::move(extractionFunction), extent), + std::runtime_error); + + BOOST_CHECK_THROW( + group.fill(config.toInternalUnits(), options, collection.begin(), + collection.begin(), std::move(extractionFunction), extent), + std::runtime_error); + + std::size_t nIterations = 0ul; + for (const auto [bottom, middle, top] : group) { + ++nIterations; + const auto& coll = group.grid().at(middle); + BOOST_CHECK_EQUAL(coll.size(), 30ul); + } + + BOOST_CHECK_EQUAL(nIterations, 1ul); +} + +} // namespace Acts::Test diff --git a/Tests/UnitTests/Core/Seeding/CMakeLists.txt b/Tests/UnitTests/Core/Seeding/CMakeLists.txt index 634ff0e26d8..f3f8327d9ac 100644 --- a/Tests/UnitTests/Core/Seeding/CMakeLists.txt +++ b/Tests/UnitTests/Core/Seeding/CMakeLists.txt @@ -2,3 +2,5 @@ add_executable(ActsUnitTestSeedFinder SeedFinderTest.cpp) target_link_libraries(ActsUnitTestSeedFinder PRIVATE ActsCore Boost::boost) add_unittest(EstimateTrackParamsFromSeedTest EstimateTrackParamsFromSeedTest.cpp) +add_unittest(BinnedGroupTest BinnedGroupTest.cpp) + diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 1dad0be93d4..28a56bc418a 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -9,7 +9,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Units.hpp" #include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/Seed.hpp" #include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Seeding/SeedFilterConfig.hpp" @@ -198,9 +198,9 @@ int main(int argc, char** argv) { // create grid with bin sizes according to the configured geometry std::unique_ptr> grid = Acts::SpacePointGridCreator::createGrid(gridConf, gridOpts); - auto spGroup = Acts::BinnedSPGroup( - spVec.begin(), spVec.end(), ct, bottomBinFinder, topBinFinder, - std::move(grid), rRangeSPExtent, config, options); + auto spGroup = Acts::BinnedSPGroup(std::move(grid), + bottomBinFinder, topBinFinder); + spGroup.fill(config, options, spVec.begin(), spVec.end(), ct, rRangeSPExtent); std::vector>> seedVector; decltype(a)::SeedingState state; From 006af4e54470bfb236e9cf32851c16b7b02b2cf9 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 22 Dec 2023 10:19:46 +0100 Subject: [PATCH 088/120] separate Filling --- Core/include/Acts/Seeding/BinnedGroup.hpp | 31 +---- Core/include/Acts/Seeding/BinnedGroup.ipp | 122 +----------------- .../Acts/Seeding/BinnedGroupIterator.ipp | 10 +- Core/include/Acts/Seeding/SpacePointGrid.hpp | 18 ++- Core/include/Acts/Seeding/SpacePointGrid.ipp | 116 ++++++++++++++++- .../TrackFinding/src/SeedingAlgorithm.cpp | 8 +- .../Core/Seeding/BinnedGroupTest.cpp | 110 ++++------------ .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 4 +- 8 files changed, 174 insertions(+), 245 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp index c1d3954f00c..70c94e2c0d9 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -8,8 +8,6 @@ #pragma once -#include "Acts/Geometry/Extent.hpp" -#include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" @@ -40,10 +38,15 @@ class BinnedGroup { BinnedGroup() = delete; /// brief Constructor - BinnedGroup(std::unique_ptr grid, + BinnedGroup(grid_t&& grid, std::shared_ptr> bottomFinder, std::shared_ptr> topFinder, std::array, DIM> navigation = std::array, DIM>()); + + BinnedGroup(grid_t& grid, + std::shared_ptr> bottomFinder, + std::shared_ptr> topFinder, + std::array, DIM> navigation = std::array, DIM>()) = delete; /// @brief Copy constructor /// @param [in] other The BinnedGroup to copy @@ -77,30 +80,10 @@ class BinnedGroup { /// @brief Get the end iterator /// @return The iterator Acts::BinnedGroupIterator end() const; - - /// @brief Fill the grid - /// @tparam external_spacepoint_t The type of the external space points - /// @tparam spacepoint_iterator_t The type of the iterator on the collection of external space points - /// @tparam callable_t The type of the function for extracting global info - /// - /// @param [in] config Configuration object for the seed finder - /// @param [in] options Seed Finder options - /// @param [in] spBegin First element to be inserted in the grid - /// @param [in] spEnd Last element to be inserted in the grid - /// @param [in] toGlobal User-provided function for extracting global quantities from external space points - /// @param [in] rRangeSPExtent An Acts Extent object - template < typename external_spacepoint_t, - typename spacepoint_iterator_t, - typename callable_t> - void fill(const Acts::SeedFinderConfig& config, - const SeedFinderOptions& options, - spacepoint_iterator_t spBegin, spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - Acts::Extent& rRangeSPExtent); private: /// @brief The N-dimentional grid - std::unique_ptr m_grid{nullptr}; + grid_t m_grid; /// @brief The Grid Bin Finder for bottom candidates std::shared_ptr> m_bottomBinFinder{nullptr}; /// @brief The Grid Bin Finder for top candidates diff --git a/Core/include/Acts/Seeding/BinnedGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp index d9a44b54673..3fdbed3d38a 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -7,14 +7,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -// Binned SP Group Iterator - -#include - namespace Acts { template -BinnedGroup::BinnedGroup(std::unique_ptr grid, +BinnedGroup::BinnedGroup(grid_t&& grid, std::shared_ptr::DIM>> bottomFinder, std::shared_ptr::DIM>> topFinder, std::array, Acts::BinnedGroup::DIM> navigation) @@ -23,12 +19,11 @@ BinnedGroup::BinnedGroup(std::unique_ptr grid, m_topBinFinder(std::move(topFinder)), m_bins(std::move(navigation)) { - assert(m_grid != nullptr); assert(m_bottomBinFinder != nullptr); assert(m_topBinFinder != nullptr); - /// If navigation is now defined for all axes, then we default that to a std::iota from 1ul - std::array numLocBins = m_grid->numLocalBins(); + /// If navigation is not defined for all axes, then we default that to a std::iota from 1ul + std::array numLocBins = m_grid.numLocalBins(); for (std::size_t i(0ul); i::BinnedGroup(std::unique_ptr grid, template const grid_t& BinnedGroup::grid() const { - if (m_grid == nullptr) { - throw std::runtime_error("Trying to retrieve grid from Binned Group, but grid is a nullptr!"); - } - return *m_grid.get(); + return m_grid; } template grid_t& BinnedGroup::grid() { - if (m_grid == nullptr) { - throw std::runtime_error("Trying to retrieve grid from Binned Group, but grid is a nullptr!"); - } - return *m_grid.get(); + return m_grid; } template @@ -67,106 +56,5 @@ Acts::BinnedGroupIterator BinnedGroup::end() const { } return Acts::BinnedGroupIterator(*this, endline, m_bins); } - -template -template -void BinnedGroup::fill(const Acts::SeedFinderConfig& config, - const Acts::SeedFinderOptions& options, - external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - Acts::Extent& rRangeSPExtent) { - - using iterated_value_t = typename std::iterator_traits::value_type; - using iterated_t = typename std::remove_const::type>::type; - static_assert(std::is_same::value, - "Iterator does not contain type this class was templated with"); - - if (!config.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); - } - if (!options.isInInternalUnits) { - throw std::runtime_error( - "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); - } - - // get region of interest (or full detector if configured accordingly) - float phiMin = config.phiMin; - float phiMax = config.phiMax; - float zMin = config.zMin; - float zMax = config.zMax; - - // sort by radius - // add magnitude of beamPos to rMax to avoid excluding measurements - // create number of bins equal to number of millimeters rMax - // (worst case minR: configured minR + 1mm) - // binSizeR allows to increase or reduce numRBins if needed - std::size_t numRBins = static_cast( - (config.rMax + options.beamPos.norm()) / config.binSizeR); - - // keep track of changed bins while sorting - boost::container::flat_set rBinsIndex; - - std::size_t counter = 0ul; - for (external_spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { - if (*it == nullptr) { - continue; - } - const external_spacepoint_t& sp = **it; - const auto& [spPosition, variance] = - toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); - - float spX = spPosition[0]; - float spY = spPosition[1]; - float spZ = spPosition[2]; - - // store x,y,z values in extent - rRangeSPExtent.extend({spX, spY, spZ}); - - // remove SPs outside z and phi region - if (spZ > zMax || spZ < zMin) { - continue; - } - float spPhi = std::atan2(spY, spX); - if (spPhi > phiMax || spPhi < phiMin) { - continue; - } - - auto isp = std::make_unique>( - counter, sp, spPosition, options.beamPos, variance); - // calculate r-Bin index and protect against overflow (underflow not - // possible) - std::size_t rIndex = - static_cast(isp->radius() / config.binSizeR); - // if index out of bounds, the SP is outside the region of interest - if (rIndex >= numRBins) { - continue; - } - - // fill rbins into grid - Acts::Vector2 spLocation(isp->phi(), isp->z()); - std::vector>>& - rbin = m_grid->atPosition(spLocation); - rbin.push_back(std::move(isp)); - - // keep track of the bins we modify so that we can later sort the SPs in - // those bins only - if (rbin.size() > 1) { - rBinsIndex.insert(m_grid->globalBinFromPosition(spLocation)); - } - } - - /// sort SPs in R for each filled bin - for (auto& binIndex : rBinsIndex) { - auto& rbin = m_grid->atPosition(binIndex); - std::sort( - rbin.begin(), rbin.end(), - [](const auto& a, const auto& b) { - return a->radius() < b->radius(); - }); - } -} } // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 9f7fed162a2..46e170db390 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -16,7 +16,7 @@ BinnedGroupIterator::BinnedGroupIterator(const Acts::BinnedGroup std::array::DIM> index, std::array, Acts::BinnedGroupIterator::DIM> navigation) : m_group(group), - m_gridItr(*group.m_grid.get(), index, navigation) + m_gridItr(group.grid(), index, navigation) { std::array endline{}; for (std::size_t i(0ul); i::BinnedGroupIterator(const Acts::BinnedGroup } m_gridItrEnd = typename grid_t::local_iterator_t( - *group.m_grid.get(), endline, std::move(navigation)); + m_group->grid(), endline, std::move(navigation)); findNotEmptyBin(); } @@ -54,14 +54,14 @@ BinnedGroupIterator::operator*() const { /// And we know this is not an empty bin std::array localPosition = m_gridItr.localPosition(); std::size_t global_index = - m_group->m_grid->globalBinFromLocalBins(localPosition); + m_group->grid().globalBinFromLocalBins(localPosition); /// Get the neighbouring bins boost::container::small_vector::DIM)> bottoms = m_group->m_bottomBinFinder->findBins(localPosition, - *m_group->m_grid.get()); + m_group->grid()); boost::container::small_vector::DIM)> tops = - m_group->m_topBinFinder->findBins(localPosition, *m_group->m_grid.get()); + m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. diff --git a/Core/include/Acts/Seeding/SpacePointGrid.hpp b/Core/include/Acts/Seeding/SpacePointGrid.hpp index 407ddfe645b..81a2831c4ab 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.hpp +++ b/Core/include/Acts/Seeding/SpacePointGrid.hpp @@ -12,9 +12,13 @@ #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Utilities/Grid.hpp" #include "Acts/Utilities/detail/Axis.hpp" +#include "Acts/Seeding/SeedFinderConfig.hpp" +#include "Acts/Geometry/Extent.hpp" #include +#include + namespace Acts { struct SpacePointGridConfig { @@ -89,7 +93,7 @@ struct SpacePointGridOptions { template using SpacePointGrid = Grid< - std::vector>>, + std::vector>>, detail::Axis, detail::Axis>; @@ -97,9 +101,19 @@ using SpacePointGrid = Grid< class SpacePointGridCreator { public: template - static std::unique_ptr> createGrid( + static Acts::SpacePointGrid createGrid( const Acts::SpacePointGridConfig& _config, const Acts::SpacePointGridOptions& _options); + + template + static void fillGrid(const Acts::SeedFinderConfig& config, + const Acts::SeedFinderOptions& options, + Acts::SpacePointGrid& grid, + external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent); }; } // namespace Acts #include "Acts/Seeding/SpacePointGrid.ipp" diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index e65f31c2eb4..5ebccf1be3b 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -1,3 +1,4 @@ +// -*- C++ -*- // This file is part of the Acts project. // // Copyright (C) 2021 CERN for the benefit of the Acts project @@ -6,12 +7,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include "Acts/Utilities/detail/Axis.hpp" - -#include - template -std::unique_ptr> +Acts::SpacePointGrid Acts::SpacePointGridCreator::createGrid( const Acts::SpacePointGridConfig& config, const Acts::SpacePointGridOptions& options) { @@ -135,6 +132,111 @@ Acts::SpacePointGridCreator::createGrid( detail::Axis zAxis(std::move(zValues)); - return std::make_unique>( - std::make_tuple(std::move(phiAxis), std::move(zAxis))); + return Acts::SpacePointGrid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); +} + +template +void Acts::SpacePointGridCreator::fillGrid(const Acts::SeedFinderConfig& config, + const Acts::SeedFinderOptions& options, + Acts::SpacePointGrid& grid, + external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, + callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent) { + using iterated_value_t = typename std::iterator_traits::value_type; + using iterated_t = typename std::remove_const::type>::type; + static_assert(std::is_pointer::value, + "Iterator must contain pointers to space points"); + static_assert(std::is_same::value, + "Iterator does not contain type this class was templated with"); + + if (!config.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); + } + if (config.seedFilter == nullptr) { + throw std::runtime_error( + "SeedFinderConfig has a null SeedFilter object"); + } + if (!options.isInInternalUnits) { + throw std::runtime_error( + "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); + } + + // get region of interest (or full detector if configured accordingly) + float phiMin = config.phiMin; + float phiMax = config.phiMax; + float zMin = config.zMin; + float zMax = config.zMax; + + // sort by radius + // add magnitude of beamPos to rMax to avoid excluding measurements + // create number of bins equal to number of millimeters rMax + // (worst case minR: configured minR + 1mm) + // binSizeR allows to increase or reduce numRBins if needed + std::size_t numRBins = static_cast( + (config.rMax + options.beamPos.norm()) / config.binSizeR); + + // keep track of changed bins while sorting + boost::container::flat_set rBinsIndex; + + std::size_t counter = 0ul; + for (external_spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { + if (*it == nullptr) { + continue; + } + const external_spacepoint_t& sp = **it; + const auto& [spPosition, variance] = + toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); + + float spX = spPosition[0]; + float spY = spPosition[1]; + float spZ = spPosition[2]; + + // store x,y,z values in extent + rRangeSPExtent.extend({spX, spY, spZ}); + + // remove SPs outside z and phi region + if (spZ > zMax || spZ < zMin) { + continue; + } + float spPhi = std::atan2(spY, spX); + if (spPhi > phiMax || spPhi < phiMin) { + continue; + } + + auto isp = std::make_unique>( + counter, sp, spPosition, options.beamPos, variance); + // calculate r-Bin index and protect against overflow (underflow not + // possible) + std::size_t rIndex = + static_cast(isp->radius() / config.binSizeR); + // if index out of bounds, the SP is outside the region of interest + if (rIndex >= numRBins) { + continue; + } + + // fill rbins into grid + Acts::Vector2 spLocation(isp->phi(), isp->z()); + std::vector>>& + rbin = grid.atPosition(spLocation); + rbin.push_back(std::move(isp)); + + // keep track of the bins we modify so that we can later sort the SPs in + // those bins only + if (rbin.size() > 1) { + rBinsIndex.insert(grid.globalBinFromPosition(spLocation)); + } + } + + /// sort SPs in R for each filled bin + for (auto& binIndex : rBinsIndex) { + auto& rbin = grid.atPosition(binIndex); + std::sort( + rbin.begin(), rbin.end(), + [](const auto& a, const auto& b) { + return a->radius() < b->radius(); + }); + } } diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index a47356e1cf4..a7f3713a7c0 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -249,18 +249,16 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( // extent used to store r range for middle spacepoint Acts::Extent rRangeSPExtent; - auto grid = Acts::SpacePointGridCreator::createGrid( + Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid( m_cfg.gridConfig, m_cfg.gridOptions); - + Acts::SpacePointGridCreator::fillGrid(m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid, spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, rRangeSPExtent); + std::array, 2ul> navigation; navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; auto spacePointsGrouping = Acts::BinnedSPGroup(std::move(grid), m_bottomBinFinder, m_topBinFinder, std::move(navigation)); - spacePointsGrouping.fill(m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, - spacePointPtrs.begin(), spacePointPtrs.end(), - extractGlobalQuantities, rRangeSPExtent); // safely clamp double to float float up = Acts::clampValue( diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index c27676381d8..306dc337451 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -8,9 +8,7 @@ #include -#include "Acts/Geometry/Extent.hpp" #include "Acts/Seeding/BinnedGroup.hpp" -#include "Acts/Seeding/SeedFilter.hpp" #include "Acts/Utilities/Grid.hpp" #include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" @@ -35,12 +33,9 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { Acts::Grid, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis>; - std::unique_ptr grid_1d = - std::make_unique(std::make_tuple(xAxis)); - std::unique_ptr grid_2d = - std::make_unique(std::make_tuple(xAxis, yAxis)); - std::unique_ptr grid_3d = - std::make_unique(std::make_tuple(xAxis, yAxis, zAxis)); + grid_1d_t grid_1d(std::make_tuple(xAxis)); + grid_2d_t grid_2d(std::make_tuple(xAxis, yAxis)); + grid_3d_t grid_3d(std::make_tuple(xAxis, yAxis, zAxis)); std::shared_ptr> binFinder_1d = std::make_shared>(1); @@ -65,36 +60,21 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { Acts::BinnedGroup group_3d(std::move(grid_3d), binFinder_3d, binFinder_3d); - BOOST_CHECK_NO_THROW(group_1d.grid()); - BOOST_CHECK_NO_THROW(group_2d.grid()); - BOOST_CHECK_NO_THROW(group_3d.grid()); - // Move Constructor/Assignment const Acts::BinnedGroup group_1d_moved(std::move(group_1d)); const Acts::BinnedGroup group_2d_moved(std::move(group_2d)); const Acts::BinnedGroup group_3d_moved = std::move(group_3d); - BOOST_CHECK_THROW(group_1d.grid(), std::runtime_error); - BOOST_CHECK_THROW(group_2d.grid(), std::runtime_error); - BOOST_CHECK_THROW(group_3d.grid(), std::runtime_error); - - BOOST_CHECK_NO_THROW(group_1d_moved.grid()); - BOOST_CHECK_NO_THROW(group_2d_moved.grid()); - BOOST_CHECK_NO_THROW(group_3d_moved.grid()); - // With some nullptr inputs - std::unique_ptr grid_1d_nullTest_1 = - std::make_unique(std::make_tuple(xAxis)); - std::unique_ptr grid_1d_nullTest_2 = - std::make_unique(std::make_tuple(xAxis)); + grid_1d_t grid_1d_nullTest_1(std::make_tuple(xAxis)); + grid_1d_t grid_1d_nullTest_2(std::make_tuple(xAxis)); Acts::BinnedGroup group_1d_nullBotFinder( std::move(grid_1d_nullTest_1), nullptr, binFinder_1d); Acts::BinnedGroup group_1d_nullTopFinder( std::move(grid_1d_nullTest_2), binFinder_1d, nullptr); - BOOST_CHECK_NO_THROW(group_1d_nullBotFinder.grid()); - BOOST_CHECK_NO_THROW(group_1d_nullTopFinder.grid()); + [[maybe_unused]] const grid_1d_t& retrievedGrid = group_1d.grid(); } BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { @@ -103,8 +83,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { using binfinder_t = Acts::GridBinFinder<1ul>; Acts::detail::EquidistantAxis xAxis(0, 100, 10); - std::unique_ptr grid = - std::make_unique(std::make_tuple(xAxis)); + grid_t grid(std::make_tuple(std::move(xAxis))); std::shared_ptr binfinder = std::make_shared(0); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); @@ -126,11 +105,10 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); Acts::detail::EquidistantAxis yAxis(0, 100, 10); - std::unique_ptr grid = std::make_unique( - std::make_tuple(std::move(xAxis), std::move(yAxis))); + grid_t grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); std::shared_ptr binfinder = std::make_shared(0, 0); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); - + Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -147,13 +125,12 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { using binfinder_t = Acts::GridBinFinder<1ul>; Acts::detail::EquidistantAxis xAxis(0, 100, 10); - std::unique_ptr grid = - std::make_unique(std::make_tuple(xAxis)); + grid_t grid(std::make_tuple(xAxis)); /// Add some entries to the grid - grid->at(1ul).push_back(4ul); - grid->at(1ul).push_back(1ul); - grid->at(8ul).push_back(7ul); - grid->at(9ul).push_back(2ul); + grid.at(1ul).push_back(4ul); + grid.at(1ul).push_back(1ul); + grid.at(8ul).push_back(7ul); + grid.at(9ul).push_back(2ul); std::shared_ptr botBinfinder = std::make_shared(0); std::shared_ptr topBinfinder = std::make_shared(1); @@ -177,11 +154,10 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); Acts::detail::EquidistantAxis yAxis(0, 100, 10); - std::unique_ptr grid = - std::make_unique(std::make_tuple(xAxis, yAxis)); + grid_t grid(std::make_tuple(xAxis, yAxis)); /// Add some entries to the grid - grid->atLocalBins({2ul, 4ul}).push_back(4ul); - grid->atLocalBins({4ul, 4ul}).push_back(4ul); + grid.atLocalBins({2ul, 4ul}).push_back(4ul); + grid.atLocalBins({4ul, 4ul}).push_back(4ul); std::shared_ptr botBinfinder = std::make_shared(1, 2); @@ -200,62 +176,30 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { } BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { - struct point {}; - - using value_t = std::unique_ptr>; + using value_t = std::size_t; using phiAxis_t = Acts::detail::Axis; using zAxis_t = detail::Axis; using grid_t = Acts::Grid, phiAxis_t, zAxis_t>; using binfinder_t = Acts::GridBinFinder<2ul>; - + phiAxis_t phiAxis(-M_PI, M_PI, 40); zAxis_t zAxis(0, 100, 10); - std::unique_ptr grid = std::make_unique( - std::make_tuple(std::move(phiAxis), std::move(zAxis))); + grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis)) ); std::shared_ptr binfinder = std::make_shared(1, 1); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); - auto extractionFunction = - [](const point&, float, float, - float) -> std::pair { - return std::make_pair(Acts::Vector3({2, 4, 2}), Acts::Vector2({0, 0})); - }; - Acts::Extent extent; - Acts::SeedFinderConfig config; - Acts::SeedFinderOptions options; - - std::vector collection; + /// Fill the grid already owned by the group filling only one bin at a specific local position + std::array locPosition({4ul, 6ul}); + std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition); + + grid_t& storedGrid = group.grid(); for (std::size_t i(0ul); i < 30ul; ++i) { - collection.push_back(new point()); + storedGrid.at(globPos).push_back(1ul); } - - BOOST_CHECK_THROW( - group.fill(config.toInternalUnits(), options.toInternalUnits(), - collection.begin(), collection.end(), - std::move(extractionFunction), extent), - std::runtime_error); - - Acts::SeedFilterConfig seedFilterConfig; - config.seedFilter = std::make_shared>( - seedFilterConfig.toInternalUnits()); - - BOOST_CHECK_NO_THROW(group.fill( - config.toInternalUnits(), options.toInternalUnits(), collection.begin(), - collection.end(), std::move(extractionFunction), extent)); - - BOOST_CHECK_THROW( - group.fill(config, options.toInternalUnits(), collection.begin(), - collection.begin(), std::move(extractionFunction), extent), - std::runtime_error); - - BOOST_CHECK_THROW( - group.fill(config.toInternalUnits(), options, collection.begin(), - collection.begin(), std::move(extractionFunction), extent), - std::runtime_error); - + std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { ++nIterations; diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 28a56bc418a..710c652f5e5 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -196,11 +196,11 @@ int main(int argc, char** argv) { Acts::SpacePointGridOptions gridOpts; gridOpts.bFieldInZ = options.bFieldInZ; // create grid with bin sizes according to the configured geometry - std::unique_ptr> grid = + Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid(gridConf, gridOpts); + Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup(std::move(grid), bottomBinFinder, topBinFinder); - spGroup.fill(config, options, spVec.begin(), spVec.end(), ct, rRangeSPExtent); std::vector>> seedVector; decltype(a)::SeedingState state; From eafbb94ee86e0d8cd908e1c386775c290aa022f5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Fri, 22 Dec 2023 10:26:29 +0100 Subject: [PATCH 089/120] another test --- .../Core/Seeding/BinnedGroupTest.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index 306dc337451..a96f1b8cc3a 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -210,4 +210,42 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { BOOST_CHECK_EQUAL(nIterations, 1ul); } +BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { + using value_t = std::size_t; + using phiAxis_t = Acts::detail::Axis; + using zAxis_t = detail::Axis; + using rAxis_t = detail::Axis; + using grid_t = Acts::Grid, phiAxis_t, zAxis_t, rAxis_t>; + using binfinder_t = Acts::GridBinFinder<3ul>; + + phiAxis_t phiAxis(-M_PI, M_PI, 40); + zAxis_t zAxis(0, 100, 10); + rAxis_t rAxis(0, 11000, 1); + + grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)) ); + std::shared_ptr binfinder = std::make_shared(1, 1, 0); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + + /// Fill the grid already owned by the group filling only one bin at a specific local position + std::array locPosition({4ul, 6ul, 1ul}); + std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition); + + grid_t& storedGrid = group.grid(); + for (std::size_t i(0ul); i < 30ul; ++i) { + storedGrid.at(globPos).push_back(1ul); + } + + std::size_t nIterations = 0ul; + for (const auto [bottom, middle, top] : group) { + ++nIterations; + const auto& coll = group.grid().at(middle); + BOOST_CHECK_EQUAL(coll.size(), 30ul); + } + + BOOST_CHECK_EQUAL(nIterations, 1ul); +} + } // namespace Acts::Test From 3d474f779ec846e147da98cf54c6f8d1c1df941a Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 9 Jan 2024 10:39:18 -0800 Subject: [PATCH 090/120] copyright and typos --- Core/include/Acts/Seeding/BinnedSPGroup.hpp | 2 +- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 2 +- Core/include/Acts/Utilities/GridBinFinder.hpp | 8 ++++---- Core/include/Acts/Utilities/GridBinFinder.ipp | 2 +- .../ActsExamples/TrackFinding/SeedingAlgorithm.hpp | 2 +- Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp | 2 +- .../TrackFindingExaTrkX/src/PrototracksToParameters.cpp | 2 +- Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp | 2 +- Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp | 2 +- .../UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 2 +- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 2 +- .../UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.hpp b/Core/include/Acts/Seeding/BinnedSPGroup.hpp index 391f6f05975..b16dc41f879 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 5ab2e750b98..476b63b861f 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index 24536ce4f47..c5415432a7a 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -32,7 +32,7 @@ class GridBinFinder { /// @brief Constructor /// @tparam args ... Input parameters provided by the user /// - /// @param [in] vals The input parameters that define how many neighbour we need to find + /// @param [in] vals The input parameters that define how many neighbours we need to find /// /// @pre The provided paramers must be of time 'int' or 'std::vector>' /// no other type is allowed. The order of these parameters must correspond to @@ -52,7 +52,7 @@ class GridBinFinder { /// @param [in] grid The grid /// @output The list of neighbouring bins /// - /// @pre The provided local positionmust be a valid local bins configuration in the grid + /// @pre The provided local position must be a valid local bins configuration in the grid template boost::container::small_vector findBins(const std::array& locPosition, @@ -98,7 +98,7 @@ class GridBinFinder { private: using stored_values_t = std::variant>>; /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid - /// These values are provided by the user and an be either ints or a vector of + /// These values are provided by the user and can be either ints or a vector of /// pair of ints. In the first case, the neighbours will be +/- bins from the /// given local bin In the second case, the user defines how many bins in both /// directions should be provided diff --git a/Core/include/Acts/Utilities/GridBinFinder.ipp b/Core/include/Acts/Utilities/GridBinFinder.ipp index cc7a36c2651..974b8636ca0 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.ipp +++ b/Core/include/Acts/Utilities/GridBinFinder.ipp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp index edb4e1765fa..dfddaeaf830 100644 --- a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp +++ b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2020 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 751f6ac71c2..03c5fb9d937 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp index be65d8eeb36..5e160705ef2 100644 --- a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp +++ b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 1dad0be93d4..7a67b11349d 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp index 8eb151bf3fc..1785105e051 100644 --- a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index b57e6c43cd6..33a35d28877 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index fe26039dc6d..d58e22b6a3e 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index 87ccf96040f..18d6e99aa06 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this From 5e3960296a10bfbace9fe103140b29fe2cd7f811 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 9 Jan 2024 11:33:38 -0800 Subject: [PATCH 091/120] test for boundary types --- .../Core/Utilities/GridBinFinderTests.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp index 1785105e051..4683006ad1b 100644 --- a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -18,6 +18,72 @@ namespace Acts::Test { +BOOST_AUTO_TEST_CASE(grid_binfinder_boundTypes) { + const std::size_t nBins = 10ul; + Acts::GridBinFinder<1ul> binFinder(1); + + // take a look at the boundaries of the axes + std::array lowerBound({1ul}); + std::array upperBound({10ul}); + + // For Closed Boundary: out-of-bounds lookups wrap-around to the other side of + // the axis. + Acts::detail::Axis + xAxisClosed(0, 100, nBins); + Acts::Grid gridClosed( + std::make_tuple(std::move(xAxisClosed))); + + auto lowerClosedNeighbours = binFinder.findBins(lowerBound, gridClosed); + BOOST_CHECK_EQUAL(lowerClosedNeighbours.size(), 3ul); + BOOST_CHECK_EQUAL(lowerClosedNeighbours[0ul], 10ul); + BOOST_CHECK_EQUAL(lowerClosedNeighbours[1ul], 1ul); + BOOST_CHECK_EQUAL(lowerClosedNeighbours[2ul], 2ul); + + auto upperClosedNeighbours = binFinder.findBins(upperBound, gridClosed); + BOOST_CHECK_EQUAL(upperClosedNeighbours.size(), 3ul); + BOOST_CHECK_EQUAL(upperClosedNeighbours[0ul], 9ul); + BOOST_CHECK_EQUAL(upperClosedNeighbours[1ul], 10ul); + BOOST_CHECK_EQUAL(upperClosedNeighbours[2ul], 1ul); + + // For Open Boundary [default]: out-of-bounds lookups resolve to dedicated + // underflow and overflow bins. + Acts::detail::Axis + xAxisOpen(0, 100, nBins); + Acts::Grid gridOpen( + std::make_tuple(std::move(xAxisOpen))); + + auto lowerOpenNeighbours = binFinder.findBins(lowerBound, gridOpen); + BOOST_CHECK_EQUAL(lowerOpenNeighbours.size(), 3ul); + BOOST_CHECK_EQUAL(lowerOpenNeighbours[0ul], 0ul); + BOOST_CHECK_EQUAL(lowerOpenNeighbours[1ul], 1ul); + BOOST_CHECK_EQUAL(lowerOpenNeighbours[2ul], 2ul); + + auto upperOpenNeighbours = binFinder.findBins(upperBound, gridOpen); + BOOST_CHECK_EQUAL(upperOpenNeighbours.size(), 3ul); + BOOST_CHECK_EQUAL(upperOpenNeighbours[0ul], 9ul); + BOOST_CHECK_EQUAL(upperOpenNeighbours[1ul], 10ul); + BOOST_CHECK_EQUAL(upperOpenNeighbours[2ul], 11ul); + + // For Bound Boundary: out-of-bounds lookups resolve to the closest valid bin. + Acts::detail::Axis + xAxisBound(0, 100, nBins); + Acts::Grid gridBound( + std::make_tuple(std::move(xAxisBound))); + + auto lowerBoundNeighbours = binFinder.findBins(lowerBound, gridBound); + BOOST_CHECK_EQUAL(lowerBoundNeighbours.size(), 2ul); + BOOST_CHECK_EQUAL(lowerBoundNeighbours[0ul], 1ul); + BOOST_CHECK_EQUAL(lowerBoundNeighbours[1ul], 2ul); + + auto upperBoundNeighbours = binFinder.findBins(upperBound, gridBound); + BOOST_CHECK_EQUAL(upperBoundNeighbours.size(), 2ul); + BOOST_CHECK_EQUAL(upperBoundNeighbours[0ul], 9ul); + BOOST_CHECK_EQUAL(upperBoundNeighbours[1ul], 1ul); +} + BOOST_AUTO_TEST_CASE(grid_binfinder_constructor) { using list_t = std::vector>; Acts::GridBinFinder<1ul> binFinder_1d_1(1); From 86b25eab8af76d72cdb89e10b6211f3570ae43d5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 10 Jan 2024 14:05:35 -0800 Subject: [PATCH 092/120] fix test and format --- Core/include/Acts/Seeding/BinnedSPGroup.ipp | 1 - Core/include/Acts/Utilities/GridBinFinder.hpp | 8 ++++---- Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedSPGroup.ipp b/Core/include/Acts/Seeding/BinnedSPGroup.ipp index 6b494b80ec4..bf473085825 100644 --- a/Core/include/Acts/Seeding/BinnedSPGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedSPGroup.ipp @@ -193,7 +193,6 @@ Acts::BinnedSPGroup::BinnedSPGroup( }); } - // phi axis m_bins[INDEX::PHI].resize(m_grid->numLocalBins()[0]); std::iota(m_bins[INDEX::PHI].begin(), m_bins[INDEX::PHI].end(), 1ul); diff --git a/Core/include/Acts/Utilities/GridBinFinder.hpp b/Core/include/Acts/Utilities/GridBinFinder.hpp index c5415432a7a..7085802e92f 100644 --- a/Core/include/Acts/Utilities/GridBinFinder.hpp +++ b/Core/include/Acts/Utilities/GridBinFinder.hpp @@ -98,10 +98,10 @@ class GridBinFinder { private: using stored_values_t = std::variant>>; /// @brief the instructions for retrieving the nieghbouring bins for each given axis in the grid - /// These values are provided by the user and can be either ints or a vector of - /// pair of ints. In the first case, the neighbours will be +/- bins from the - /// given local bin In the second case, the user defines how many bins in both - /// directions should be provided + /// These values are provided by the user and can be either ints or a vector + /// of pair of ints. In the first case, the neighbours will be +/- bins from + /// the given local bin In the second case, the user defines how many bins in + /// both directions should be provided /// /// @pre The list of entries of the vector of pairs MUST be equal to the number of bins in that specific /// axis. Empty vectors are also allowed but in this case the value will be diff --git a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp index 954cff136e7..dcfaa0dc37c 100644 --- a/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp +++ b/Tests/UnitTests/Core/Utilities/GridBinFinderTests.cpp @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(grid_binfinder_boundTypes) { auto upperBoundNeighbours = binFinder.findBins(upperBound, gridBound); BOOST_CHECK_EQUAL(upperBoundNeighbours.size(), 2ul); BOOST_CHECK_EQUAL(upperBoundNeighbours[0ul], 9ul); - BOOST_CHECK_EQUAL(upperBoundNeighbours[1ul], 1ul); + BOOST_CHECK_EQUAL(upperBoundNeighbours[1ul], 10ul); } BOOST_AUTO_TEST_CASE(grid_binfinder_constructor) { From 78feaee32f79303a9e2f7523097fd84d289d7328 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 10 Jan 2024 14:09:20 -0800 Subject: [PATCH 093/120] copyright --- Core/include/Acts/Seeding/BinnedGroup.ipp | 3 +-- Core/include/Acts/Seeding/BinnedGroupIterator.ipp | 3 +-- Core/include/Acts/Seeding/SpacePointGrid.ipp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp index 3fdbed3d38a..335f1e59e18 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -1,7 +1,6 @@ -// -*- C++ -*- // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 6b740de2e7b..bf0d5bd8cd9 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -1,7 +1,6 @@ -// -*- C++ -*- // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index f4cd21a24f4..44e767c36d8 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -1,7 +1,6 @@ -// -*- C++ -*- // This file is part of the Acts project. // -// Copyright (C) 2021 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this From a5c6e846e070d7ad8bc3ffe9e82fac7f1f6f1825 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 10 Jan 2024 14:10:54 -0800 Subject: [PATCH 094/120] format --- Core/include/Acts/Seeding/BinnedGroup.hpp | 36 ++++++----- Core/include/Acts/Seeding/BinnedGroup.ipp | 37 ++++++----- .../Acts/Seeding/BinnedGroupIterator.hpp | 53 +++++++++------- .../Acts/Seeding/BinnedGroupIterator.ipp | 63 +++++++++++-------- Core/include/Acts/Seeding/SpacePointGrid.hpp | 23 +++---- Core/include/Acts/Seeding/SpacePointGrid.ipp | 55 ++++++++-------- .../TrackFinding/src/SeedingAlgorithm.cpp | 21 ++++--- .../Core/Seeding/BinnedGroupTest.cpp | 32 +++++----- .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 3 +- 9 files changed, 177 insertions(+), 146 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp index 70c94e2c0d9..e23ae4d6a42 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -8,11 +8,11 @@ #pragma once +#include "Acts/Seeding/BinnedGroupIterator.hpp" #include "Acts/Seeding/SpacePointGrid.hpp" #include "Acts/Utilities/GridBinFinder.hpp" #include "Acts/Utilities/GridIterator.hpp" #include "Acts/Utilities/Holders.hpp" -#include "Acts/Seeding/BinnedGroupIterator.hpp" #include #include @@ -21,13 +21,13 @@ namespace Acts { /// @class BinnedGroup /// @tparam grid_t Type of the grid the group owns -/// +/// /// The assumption is that the grid has ownership of the space points and /// that the grid value_type (i.e. T in Grid) is an iterable -/// object of space points, such as a vector< ... > +/// object of space points, such as a vector< ... > template class BinnedGroup { -public: + public: #ifndef DOXYGEN friend BinnedGroupIterator; #endif @@ -39,15 +39,17 @@ class BinnedGroup { /// brief Constructor BinnedGroup(grid_t&& grid, - std::shared_ptr> bottomFinder, - std::shared_ptr> topFinder, - std::array, DIM> navigation = std::array, DIM>()); + std::shared_ptr> bottomFinder, + std::shared_ptr> topFinder, + std::array, DIM> navigation = + std::array, DIM>()); BinnedGroup(grid_t& grid, std::shared_ptr> bottomFinder, std::shared_ptr> topFinder, - std::array, DIM> navigation = std::array, DIM>()) = delete; - + std::array, DIM> navigation = + std::array, DIM>()) = delete; + /// @brief Copy constructor /// @param [in] other The BinnedGroup to copy BinnedGroup(const BinnedGroup& other) = delete; @@ -62,8 +64,9 @@ class BinnedGroup { /// @brief Move Assignment /// @param [in] other The BinnedGroup to move /// @return The moved BinnedGroup - BinnedGroup& operator=(BinnedGroup&& other) noexcept = default; - + BinnedGroup& operator=(BinnedGroup&& other) noexcept = + default; + /// @brief Default destructor ~BinnedGroup() = default; @@ -80,8 +83,8 @@ class BinnedGroup { /// @brief Get the end iterator /// @return The iterator Acts::BinnedGroupIterator end() const; - -private: + + private: /// @brief The N-dimentional grid grid_t m_grid; /// @brief The Grid Bin Finder for bottom candidates @@ -92,11 +95,12 @@ class BinnedGroup { std::array, DIM> m_bins{}; }; -} // namespace Acts +} // namespace Acts #include "Acts/Seeding/BinnedGroup.ipp" namespace Acts { - template - using BinnedSPGroup = Acts::BinnedGroup>; +template +using BinnedSPGroup = + Acts::BinnedGroup>; } diff --git a/Core/include/Acts/Seeding/BinnedGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp index 335f1e59e18..463737ac8c1 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -9,21 +9,25 @@ namespace Acts { template -BinnedGroup::BinnedGroup(grid_t&& grid, - std::shared_ptr::DIM>> bottomFinder, - std::shared_ptr::DIM>> topFinder, - std::array, Acts::BinnedGroup::DIM> navigation) - : m_grid(std::move(grid)), - m_bottomBinFinder(std::move(bottomFinder)), - m_topBinFinder(std::move(topFinder)), - m_bins(std::move(navigation)) -{ +BinnedGroup::BinnedGroup( + grid_t&& grid, + std::shared_ptr::DIM>> + bottomFinder, + std::shared_ptr::DIM>> + topFinder, + std::array, Acts::BinnedGroup::DIM> + navigation) + : m_grid(std::move(grid)), + m_bottomBinFinder(std::move(bottomFinder)), + m_topBinFinder(std::move(topFinder)), + m_bins(std::move(navigation)) { assert(m_bottomBinFinder != nullptr); assert(m_topBinFinder != nullptr); - /// If navigation is not defined for all axes, then we default that to a std::iota from 1ul + /// If navigation is not defined for all axes, then we default that to a + /// std::iota from 1ul std::array numLocBins = m_grid.numLocalBins(); - for (std::size_t i(0ul); i::BinnedGroup(grid_t&& grid, std::iota(m_bins[i].begin(), m_bins[i].end(), 1ul); } } - + template const grid_t& BinnedGroup::grid() const { return m_grid; @@ -44,16 +48,17 @@ grid_t& BinnedGroup::grid() { template Acts::BinnedGroupIterator BinnedGroup::begin() const { - return Acts::BinnedGroupIterator(*this, std::array::DIM>(), m_bins); + return Acts::BinnedGroupIterator( + *this, std::array::DIM>(), m_bins); } template Acts::BinnedGroupIterator BinnedGroup::end() const { std::array::DIM> endline{}; - for (std::size_t i(0ul); i::DIM; ++i) { + for (std::size_t i(0ul); i < Acts::BinnedGroup::DIM; ++i) { endline[i] = m_bins[i].size(); } return Acts::BinnedGroupIterator(*this, endline, m_bins); } - -} // namespace Acts + +} // namespace Acts diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index fbca0290d0a..b10d407a479 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -13,8 +13,8 @@ #include "Acts/Utilities/Holders.hpp" #include "Acts/Utilities/detail/grid_helper.hpp" -#include #include +#include #include @@ -24,7 +24,7 @@ class BinnedGroup; template class BinnedGroupIterator { -public: + public: static constexpr std::size_t DIM = grid_t::DIM; /// @brief Constructor @@ -33,9 +33,9 @@ class BinnedGroupIterator { /// @param [in] group The group we are iterating on /// @param [in] index Current local position in the grid /// @param [in] navigation The navigation pattern in the grid - BinnedGroupIterator(Acts::BinnedGroup&& group, - std::array index, - std::array, DIM> navigation) = delete; + BinnedGroupIterator( + Acts::BinnedGroup&& group, std::array index, + std::array, DIM> navigation) = delete; /// @brief Constructor /// Never take the ownership of the group @@ -45,25 +45,27 @@ class BinnedGroupIterator { /// @param [in] navigation The navigation pattern in the grid BinnedGroupIterator(const Acts::BinnedGroup&& group, std::array index, - std::array, DIM> navigation) = delete; - + std::array, DIM> navigation) = + delete; + /// @brief Constructor /// @param [in] group The group we are iterating on /// @param [in] index Current local position in the grid /// @param [in] navigation The navigation pattern in the grid BinnedGroupIterator(const Acts::BinnedGroup& group, - std::array index, - std::array, DIM> navigation); + std::array index, + std::array, DIM> navigation); /// Do not allow Copy operations - + /// @brief Copy Constructor /// @param [in] other The BinnedGroupIterator to copy BinnedGroupIterator(const BinnedGroupIterator& other) = delete; /// @brief Copy assignment /// @param [in] other The BinnedGroupIterator to copy /// @return The copied BinnedGroupIterator - BinnedGroupIterator& operator=(const BinnedGroupIterator& other) = delete; + BinnedGroupIterator& operator=( + const BinnedGroupIterator& other) = delete; /// @brief Move Constructor /// @param [in] other The BinnedGroupIterator to move @@ -71,12 +73,12 @@ class BinnedGroupIterator { /// @brief Move assignment /// @param [in] other The BinnedGroupIterator to move /// @return The moved BinnedGroupIterator - BinnedGroupIterator& operator=(BinnedGroupIterator&& other) noexcept = default; - + BinnedGroupIterator& operator=(BinnedGroupIterator&& other) noexcept = + default; + /// @brief Default Destructor ~BinnedGroupIterator() = default; - /// @brief Equality operator /// @param [in] other The BinnedGroupIterator we are comparing against this one /// @return The result of the comparison @@ -89,20 +91,22 @@ class BinnedGroupIterator { /// @brief Increment the iterator by one (pre) /// @return The incremented iterator BinnedGroupIterator& operator++(); - + /// @brief Return the current bin with the middle candidate, as well as all the /// bins with the possible bottom and top candidates /// /// @return The collection of all the bins in the grid - std::tuple, std::size_t, - boost::container::small_vector> + std::tuple< + boost::container::small_vector, + std::size_t, + boost::container::small_vector> operator*() const; - -private: + + private: /// @brief Move to the next not-empty bin in the grid void findNotEmptyBin(); - -private: + + private: /// @brief The group that contains the grid and the bin finders Acts::detail::RefHolder> m_group{nullptr}; /// @brief Current N-dimentional grid iterator @@ -111,11 +115,12 @@ class BinnedGroupIterator { typename grid_t::local_iterator_t m_gridItrEnd; }; -} // namespace Acts +} // namespace Acts #include "Acts/Seeding/BinnedGroupIterator.ipp" namespace Acts { - template - using BinnedSPGroupIterator = BinnedGroupIterator>>; +template +using BinnedSPGroupIterator = BinnedGroupIterator< + Acts::BinnedGroup>>; } diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index bf0d5bd8cd9..0176e9e35bc 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -11,56 +11,65 @@ namespace Acts { template -BinnedGroupIterator::BinnedGroupIterator(const Acts::BinnedGroup& group, - std::array::DIM> index, - std::array, Acts::BinnedGroupIterator::DIM> navigation) - : m_group(group), - m_gridItr(group.grid(), index, navigation) -{ +BinnedGroupIterator::BinnedGroupIterator( + const Acts::BinnedGroup& group, + std::array::DIM> index, + std::array, Acts::BinnedGroupIterator::DIM> + navigation) + : m_group(group), m_gridItr(group.grid(), index, navigation) { std::array endline{}; - for (std::size_t i(0ul); igrid(), endline, std::move(navigation)); + m_gridItrEnd = typename grid_t::local_iterator_t(m_group->grid(), endline, + std::move(navigation)); findNotEmptyBin(); } template -bool BinnedGroupIterator::operator==(const Acts::BinnedGroupIterator& other) const { +bool BinnedGroupIterator::operator==( + const Acts::BinnedGroupIterator& other) const { return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } - + template -bool BinnedGroupIterator::operator!=(const Acts::BinnedGroupIterator& other) const { +bool BinnedGroupIterator::operator!=( + const Acts::BinnedGroupIterator& other) const { return !(*this == other); } template -Acts::BinnedGroupIterator& -BinnedGroupIterator::operator++() { +Acts::BinnedGroupIterator& BinnedGroupIterator::operator++() { ++m_gridItr; findNotEmptyBin(); return *this; } template -std::tuple::DIM)>, std::size_t, - boost::container::small_vector::DIM)>> +std::tuple::DIM)>, + std::size_t, + boost::container::small_vector< + std::size_t, + Acts::detail::ipow(3, Acts::BinnedGroupIterator::DIM)>> BinnedGroupIterator::operator*() const { - /// Get the global and local position from current iterator. This is the bin with the middle candidate - /// And we know this is not an empty bin + /// Get the global and local position from current iterator. This is the bin + /// with the middle candidate And we know this is not an empty bin std::array localPosition = m_gridItr.localBinsIndices(); std::size_t global_index = - m_group->grid().globalBinFromLocalBins(localPosition); + m_group->grid().globalBinFromLocalBins(localPosition); /// Get the neighbouring bins - boost::container::small_vector::DIM)> bottoms = - m_group->m_bottomBinFinder->findBins(localPosition, - m_group->grid()); - boost::container::small_vector::DIM)> tops = - m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); + boost::container::small_vector::DIM)> + bottoms = + m_group->m_bottomBinFinder->findBins(localPosition, m_group->grid()); + boost::container::small_vector::DIM)> + tops = m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. @@ -72,7 +81,7 @@ BinnedGroupIterator::operator*() const { #if defined(__GNUC__) && __GNUC__ >= 12 && !defined(__clang__) #pragma GCC diagnostic pop #endif -} +} template void BinnedGroupIterator::findNotEmptyBin() { @@ -87,4 +96,4 @@ void BinnedGroupIterator::findNotEmptyBin() { } } -} // namespace Acts +} // namespace Acts diff --git a/Core/include/Acts/Seeding/SpacePointGrid.hpp b/Core/include/Acts/Seeding/SpacePointGrid.hpp index 81a2831c4ab..dea82d497cc 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.hpp +++ b/Core/include/Acts/Seeding/SpacePointGrid.hpp @@ -9,11 +9,11 @@ #pragma once #include "Acts/Definitions/Units.hpp" +#include "Acts/Geometry/Extent.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" +#include "Acts/Seeding/SeedFinderConfig.hpp" #include "Acts/Utilities/Grid.hpp" #include "Acts/Utilities/detail/Axis.hpp" -#include "Acts/Seeding/SeedFinderConfig.hpp" -#include "Acts/Geometry/Extent.hpp" #include @@ -93,7 +93,8 @@ struct SpacePointGridOptions { template using SpacePointGrid = Grid< - std::vector>>, + std::vector< + std::unique_ptr>>, detail::Axis, detail::Axis>; @@ -106,14 +107,14 @@ class SpacePointGridCreator { const Acts::SpacePointGridOptions& _options); template - static void fillGrid(const Acts::SeedFinderConfig& config, - const Acts::SeedFinderOptions& options, - Acts::SpacePointGrid& grid, - external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - Acts::Extent& rRangeSPExtent); + typename external_spacepoint_iterator_t, typename callable_t> + static void fillGrid( + const Acts::SeedFinderConfig& config, + const Acts::SeedFinderOptions& options, + Acts::SpacePointGrid& grid, + external_spacepoint_iterator_t spBegin, + external_spacepoint_iterator_t spEnd, callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent); }; } // namespace Acts #include "Acts/Seeding/SpacePointGrid.ipp" diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index 44e767c36d8..0c450168236 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -7,8 +7,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. template -Acts::SpacePointGrid -Acts::SpacePointGridCreator::createGrid( +Acts::SpacePointGrid Acts::SpacePointGridCreator::createGrid( const Acts::SpacePointGridConfig& config, const Acts::SpacePointGridOptions& options) { if (!config.isInInternalUnits) { @@ -114,7 +113,6 @@ Acts::SpacePointGridCreator::createGrid( float zBins = std::max(1.f, std::floor((config.zMax - config.zMin) / zBinSize)); - zValues.reserve(static_cast(zBins)); for (int bin = 0; bin <= static_cast(zBins); bin++) { AxisScalar edge = @@ -124,7 +122,7 @@ Acts::SpacePointGridCreator::createGrid( } else { // Use the zBinEdges defined in the config - zValues.reserve(config.zBinEdges.size()); + zValues.reserve(config.zBinEdges.size()); for (float bin : config.zBinEdges) { zValues.push_back(bin); } @@ -132,36 +130,38 @@ Acts::SpacePointGridCreator::createGrid( detail::Axis zAxis(std::move(zValues)); - return Acts::SpacePointGrid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); + return Acts::SpacePointGrid( + std::make_tuple(std::move(phiAxis), std::move(zAxis))); } template -void Acts::SpacePointGridCreator::fillGrid(const Acts::SeedFinderConfig& config, - const Acts::SeedFinderOptions& options, - Acts::SpacePointGrid& grid, - external_spacepoint_iterator_t spBegin, external_spacepoint_iterator_t spEnd, - callable_t&& toGlobal, - Acts::Extent& rRangeSPExtent) { - using iterated_value_t = typename std::iterator_traits::value_type; - using iterated_t = typename std::remove_const::type>::type; + typename external_spacepoint_iterator_t, typename callable_t> +void Acts::SpacePointGridCreator::fillGrid( + const Acts::SeedFinderConfig& config, + const Acts::SeedFinderOptions& options, + Acts::SpacePointGrid& grid, + external_spacepoint_iterator_t spBegin, + external_spacepoint_iterator_t spEnd, callable_t&& toGlobal, + Acts::Extent& rRangeSPExtent) { + using iterated_value_t = + typename std::iterator_traits::value_type; + using iterated_t = typename std::remove_const< + typename std::remove_pointer::type>::type; static_assert(std::is_pointer::value, - "Iterator must contain pointers to space points"); + "Iterator must contain pointers to space points"); static_assert(std::is_same::value, "Iterator does not contain type this class was templated with"); - + if (!config.isInInternalUnits) { throw std::runtime_error( - "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); + "SeedFinderConfig not in ACTS internal units in BinnedSPGroup"); } if (config.seedFilter == nullptr) { - throw std::runtime_error( - "SeedFinderConfig has a null SeedFilter object"); + throw std::runtime_error("SeedFinderConfig has a null SeedFilter object"); } if (!options.isInInternalUnits) { throw std::runtime_error( - "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); + "SeedFinderOptions not in ACTS internal units in BinnedSPGroup"); } // get region of interest (or full detector if configured accordingly) @@ -182,7 +182,8 @@ void Acts::SpacePointGridCreator::fillGrid(const Acts::SeedFinderConfig rBinsIndex; std::size_t counter = 0ul; - for (external_spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) { + for (external_spacepoint_iterator_t it = spBegin; it != spEnd; + it++, ++counter) { if (*it == nullptr) { continue; } @@ -229,14 +230,12 @@ void Acts::SpacePointGridCreator::fillGrid(const Acts::SeedFinderConfigradius() < b->radius(); - }); + std::sort(rbin.begin(), rbin.end(), [](const auto& a, const auto& b) { + return a->radius() < b->radius(); + }); } } diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index fcefc32a15c..aa6acb30177 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -249,17 +249,20 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( // extent used to store r range for middle spacepoint Acts::Extent rRangeSPExtent; - Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid( - m_cfg.gridConfig, m_cfg.gridOptions); - Acts::SpacePointGridCreator::fillGrid(m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid, spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, rRangeSPExtent); - + Acts::SpacePointGrid grid = + Acts::SpacePointGridCreator::createGrid(m_cfg.gridConfig, + m_cfg.gridOptions); + Acts::SpacePointGridCreator::fillGrid( + m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid, + spacePointPtrs.begin(), spacePointPtrs.end(), extractGlobalQuantities, + rRangeSPExtent); + std::array, 2ul> navigation; navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; - auto spacePointsGrouping = Acts::BinnedSPGroup(std::move(grid), - m_bottomBinFinder, - m_topBinFinder, - std::move(navigation)); - + auto spacePointsGrouping = + Acts::BinnedSPGroup(std::move(grid), m_bottomBinFinder, + m_topBinFinder, std::move(navigation)); + // safely clamp double to float float up = Acts::clampValue( std::floor(rRangeSPExtent.max(Acts::binR) / 2) * 2); diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index a96f1b8cc3a..a8997f3996f 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -105,10 +105,10 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); Acts::detail::EquidistantAxis yAxis(0, 100, 10); - grid_t grid( std::make_tuple(std::move(xAxis), std::move(yAxis)) ); + grid_t grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); std::shared_ptr binfinder = std::make_shared(0, 0); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); - + Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -183,23 +183,24 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { detail::AxisBoundaryType::Bound>; using grid_t = Acts::Grid, phiAxis_t, zAxis_t>; using binfinder_t = Acts::GridBinFinder<2ul>; - + phiAxis_t phiAxis(-M_PI, M_PI, 40); zAxis_t zAxis(0, 100, 10); - grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis)) ); + grid_t grid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); std::shared_ptr binfinder = std::make_shared(1, 1); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); - /// Fill the grid already owned by the group filling only one bin at a specific local position + /// Fill the grid already owned by the group filling only one bin at a + /// specific local position std::array locPosition({4ul, 6ul}); std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition); - + grid_t& storedGrid = group.grid(); for (std::size_t i(0ul); i < 30ul; ++i) { storedGrid.at(globPos).push_back(1ul); } - + std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { ++nIterations; @@ -217,27 +218,30 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { using zAxis_t = detail::Axis; using rAxis_t = detail::Axis; + detail::AxisBoundaryType::Bound>; using grid_t = Acts::Grid, phiAxis_t, zAxis_t, rAxis_t>; using binfinder_t = Acts::GridBinFinder<3ul>; - + phiAxis_t phiAxis(-M_PI, M_PI, 40); zAxis_t zAxis(0, 100, 10); rAxis_t rAxis(0, 11000, 1); - grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis)) ); - std::shared_ptr binfinder = std::make_shared(1, 1, 0); + grid_t grid( + std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis))); + std::shared_ptr binfinder = + std::make_shared(1, 1, 0); Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); - /// Fill the grid already owned by the group filling only one bin at a specific local position + /// Fill the grid already owned by the group filling only one bin at a + /// specific local position std::array locPosition({4ul, 6ul, 1ul}); std::size_t globPos = group.grid().globalBinFromLocalBins(locPosition); - + grid_t& storedGrid = group.grid(); for (std::size_t i(0ul); i < 30ul; ++i) { storedGrid.at(globPos).push_back(1ul); } - + std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { ++nIterations; diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 3ac011cb0b2..7bec733043e 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -198,7 +198,8 @@ int main(int argc, char** argv) { // create grid with bin sizes according to the configured geometry Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid(gridConf, gridOpts); - Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); + Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), + spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup(std::move(grid), bottomBinFinder, topBinFinder); From dfb08bd8280a2498c674badee5555c9944c47d26 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:09:46 -0800 Subject: [PATCH 095/120] from shared to unique and always request reference --- Core/include/Acts/Seeding/BinnedGroup.hpp | 12 ++-- Core/include/Acts/Seeding/BinnedGroup.ipp | 11 ++- .../TrackFinding/SeedingAlgorithm.hpp | 4 +- .../TrackFinding/src/SeedingAlgorithm.cpp | 8 +-- .../Core/Seeding/BinnedGroupTest.cpp | 67 ++++++++----------- .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 7 +- 6 files changed, 49 insertions(+), 60 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp index e23ae4d6a42..981c7bfc342 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -39,14 +39,14 @@ class BinnedGroup { /// brief Constructor BinnedGroup(grid_t&& grid, - std::shared_ptr> bottomFinder, - std::shared_ptr> topFinder, + const Acts::GridBinFinder& bottomFinder, + const Acts::GridBinFinder& topFinder, std::array, DIM> navigation = std::array, DIM>()); BinnedGroup(grid_t& grid, - std::shared_ptr> bottomFinder, - std::shared_ptr> topFinder, + const Acts::GridBinFinder& bottomFinder, + const Acts::GridBinFinder& topFinder, std::array, DIM> navigation = std::array, DIM>()) = delete; @@ -88,9 +88,9 @@ class BinnedGroup { /// @brief The N-dimentional grid grid_t m_grid; /// @brief The Grid Bin Finder for bottom candidates - std::shared_ptr> m_bottomBinFinder{nullptr}; + const Acts::GridBinFinder* m_bottomBinFinder{nullptr}; /// @brief The Grid Bin Finder for top candidates - std::shared_ptr> m_topBinFinder{nullptr}; + const Acts::GridBinFinder* m_topBinFinder{nullptr}; /// @brief Order of bins to loop over when searching for SPs std::array, DIM> m_bins{}; }; diff --git a/Core/include/Acts/Seeding/BinnedGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp index 463737ac8c1..bf4c853475e 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -11,19 +11,16 @@ namespace Acts { template BinnedGroup::BinnedGroup( grid_t&& grid, - std::shared_ptr::DIM>> + const Acts::GridBinFinder::DIM>& bottomFinder, - std::shared_ptr::DIM>> + const Acts::GridBinFinder::DIM>& topFinder, std::array, Acts::BinnedGroup::DIM> navigation) : m_grid(std::move(grid)), - m_bottomBinFinder(std::move(bottomFinder)), - m_topBinFinder(std::move(topFinder)), + m_bottomBinFinder(&bottomFinder), + m_topBinFinder(&topFinder), m_bins(std::move(navigation)) { - assert(m_bottomBinFinder != nullptr); - assert(m_topBinFinder != nullptr); - /// If navigation is not defined for all axes, then we default that to a /// std::iota from 1ul std::array numLocBins = m_grid.numLocalBins(); diff --git a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp index dfddaeaf830..73560d74216 100644 --- a/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp +++ b/Examples/Algorithms/TrackFinding/include/ActsExamples/TrackFinding/SeedingAlgorithm.hpp @@ -83,8 +83,8 @@ class SeedingAlgorithm final : public IAlgorithm { private: Acts::SeedFinder m_seedFinder; - std::shared_ptr> m_bottomBinFinder; - std::shared_ptr> m_topBinFinder; + std::unique_ptr> m_bottomBinFinder; + std::unique_ptr> m_topBinFinder; Config m_cfg; std::vector>> diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index aa6acb30177..05438b99e68 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -205,9 +205,9 @@ ActsExamples::SeedingAlgorithm::SeedingAlgorithm( }); } - m_bottomBinFinder = std::make_shared>( + m_bottomBinFinder = std::make_unique>( m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsBottom); - m_topBinFinder = std::make_shared>( + m_topBinFinder = std::make_unique>( m_cfg.numPhiNeighbors, m_cfg.zBinNeighborsTop); m_cfg.seedFinderConfig.seedFilter = @@ -260,8 +260,8 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( std::array, 2ul> navigation; navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; auto spacePointsGrouping = - Acts::BinnedSPGroup(std::move(grid), m_bottomBinFinder, - m_topBinFinder, std::move(navigation)); + Acts::BinnedSPGroup(std::move(grid), *m_bottomBinFinder.get(), + *m_topBinFinder.get(), std::move(navigation)); // safely clamp double to float float up = Acts::clampValue( diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index a8997f3996f..df5ab194233 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -37,12 +37,12 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { grid_2d_t grid_2d(std::make_tuple(xAxis, yAxis)); grid_3d_t grid_3d(std::make_tuple(xAxis, yAxis, zAxis)); - std::shared_ptr> binFinder_1d = - std::make_shared>(1); - std::shared_ptr> binFinder_2d = - std::make_shared>(1, 1); - std::shared_ptr> binFinder_3d = - std::make_shared>(1, 2, 1); + std::unique_ptr> binFinder_1d = + std::make_unique>(1); + std::unique_ptr> binFinder_2d = + std::make_unique>(1, 1); + std::unique_ptr> binFinder_3d = + std::make_unique>(1, 2, 1); std::array, 1ul> navigation_1d; navigation_1d[0ul].resize(10); @@ -51,29 +51,20 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { // Costructors // We provide a proper navigation - Acts::BinnedGroup group_1d(std::move(grid_1d), binFinder_1d, - binFinder_1d, std::move(navigation_1d)); + Acts::BinnedGroup group_1d(std::move(grid_1d), *binFinder_1d.get(), + *binFinder_1d.get(), std::move(navigation_1d)); // We provide a partial navigation, the constructor will complete it - Acts::BinnedGroup group_2d(std::move(grid_2d), binFinder_2d, - binFinder_2d, std::move(navigation_2d)); + Acts::BinnedGroup group_2d(std::move(grid_2d), *binFinder_2d.get(), + *binFinder_2d.get(), std::move(navigation_2d)); // We do not provide navigation, the constructor will define it - Acts::BinnedGroup group_3d(std::move(grid_3d), binFinder_3d, - binFinder_3d); + Acts::BinnedGroup group_3d(std::move(grid_3d), *binFinder_3d.get(), + *binFinder_3d.get()); // Move Constructor/Assignment const Acts::BinnedGroup group_1d_moved(std::move(group_1d)); const Acts::BinnedGroup group_2d_moved(std::move(group_2d)); const Acts::BinnedGroup group_3d_moved = std::move(group_3d); - // With some nullptr inputs - grid_1d_t grid_1d_nullTest_1(std::make_tuple(xAxis)); - grid_1d_t grid_1d_nullTest_2(std::make_tuple(xAxis)); - - Acts::BinnedGroup group_1d_nullBotFinder( - std::move(grid_1d_nullTest_1), nullptr, binFinder_1d); - Acts::BinnedGroup group_1d_nullTopFinder( - std::move(grid_1d_nullTest_2), binFinder_1d, nullptr); - [[maybe_unused]] const grid_1d_t& retrievedGrid = group_1d.grid(); } @@ -84,8 +75,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis))); - std::shared_ptr binfinder = std::make_shared(0); - Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + std::unique_ptr binfinder = std::make_unique(0); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -106,8 +97,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); Acts::detail::EquidistantAxis yAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); - std::shared_ptr binfinder = std::make_shared(0, 0); - Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + std::unique_ptr binfinder = std::make_unique(0, 0); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -132,9 +123,9 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { grid.at(8ul).push_back(7ul); grid.at(9ul).push_back(2ul); - std::shared_ptr botBinfinder = std::make_shared(0); - std::shared_ptr topBinfinder = std::make_shared(1); - Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); + std::unique_ptr botBinfinder = std::make_unique(0); + std::unique_ptr topBinfinder = std::make_unique(1); + Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), *topBinfinder.get()); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -159,11 +150,11 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { grid.atLocalBins({2ul, 4ul}).push_back(4ul); grid.atLocalBins({4ul, 4ul}).push_back(4ul); - std::shared_ptr botBinfinder = - std::make_shared(1, 2); - std::shared_ptr topBinfinder = - std::make_shared(1, 1); - Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); + std::unique_ptr botBinfinder = + std::make_unique(1, 2); + std::unique_ptr topBinfinder = + std::make_unique(1, 1); + Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), *topBinfinder.get()); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -188,8 +179,8 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { zAxis_t zAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); - std::shared_ptr binfinder = std::make_shared(1, 1); - Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + std::unique_ptr binfinder = std::make_unique(1, 1); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); /// Fill the grid already owned by the group filling only one bin at a /// specific local position @@ -228,9 +219,9 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis))); - std::shared_ptr binfinder = - std::make_shared(1, 1, 0); - Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); + std::unique_ptr binfinder = + std::make_unique(1, 1, 0); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); /// Fill the grid already owned by the group filling only one bin at a /// specific local position diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 7bec733043e..930e38a7393 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -165,9 +165,9 @@ int main(int argc, char** argv) { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( + auto bottomBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); @@ -201,7 +201,8 @@ int main(int argc, char** argv) { Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup(std::move(grid), - bottomBinFinder, topBinFinder); + *bottomBinFinder.get(), + *topBinFinder.get()); std::vector>> seedVector; decltype(a)::SeedingState state; From 84335919d6d34d270d12af0141ec6301deb359e5 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:26:02 -0800 Subject: [PATCH 096/120] minor changes --- .../Acts/Seeding/#BinnedGroupIterator.hpp# | 126 ++++++++++++++++++ .../Core/Seeding/BinnedGroupTest.cpp | 2 + .../Sycl/Seeding/SeedFinderSyclTest.cpp | 2 +- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# diff --git a/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# b/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# new file mode 100644 index 00000000000..dd1171060ee --- /dev/null +++ b/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# @@ -0,0 +1,126 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Seeding/SpacePointGrid.hpp" +#include "Acts/Utilities/GridIterator.hpp" +#include "Acts/Utilities/Holders.hpp" +#include "Acts/Utilities/detail/grid_helper.hpp" + +#include +#include + +#include + +namespace Acts { +template +class BinnedGroup; + +template +class BinnedGroupIterator { + public: + static constexpr std::size_t DIM = grid_t::DIM; + + /// @brief Constructor + /// Never take the ownership of the group + /// + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator( + Acts::BinnedGroup&& group, std::array index, + std::array, DIM> navigation) = delete; + + /// @brief Constructor + /// Never take the ownership of the group + /// + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator(const Acts::BinnedGroup&& group, + std::array index, + std::array, DIM> navigation) = + delete; + + /// @brief Constructor + /// @param [in] group The group we are iterating on + /// @param [in] index Current local position in the grid + /// @param [in] navigation The navigation pattern in the grid + BinnedGroupIterator(const Acts::BinnedGroup& group, + std::array index, + std::array, DIM> navigation); + + /// Do not allow Copy operations + + /// @brief Copy Constructor + /// @param [in] other The BinnedGroupIterator to copy + BinnedGroupIterator(const BinnedGroupIterator& other) = delete; + /// @brief Copy assignment + /// @param [in] other The BinnedGroupIterator to copy + /// @return The copied BinnedGroupIterator + BinnedGroupIterator& operator=( + const BinnedGroupIterator& other) = delete; + + /// @brief Move Constructor + /// @param [in] other The BinnedGroupIterator to move + BinnedGroupIterator(BinnedGroupIterator&& other) noexcept = default; + /// @brief Move assignment + /// @param [in] other The BinnedGroupIterator to move + /// @return The moved BinnedGroupIterator + BinnedGroupIterator& operator=(BinnedGroupIterator&& other) noexcept = + default; + + /// @brief Default Destructor + ~BinnedGroupIterator() = default; + + /// @brief Equality operator + /// @param [in] other The BinnedGroupIterator we are comparing against this one + /// @return The result of the comparison + bool operator==(const BinnedGroupIterator& other) const; + /// @brief (In-)Equality operator + /// @param [in] other The BinnedGroupIterator we are comparing against this one + /// @return The result of the comparison + bool operator!=(const BinnedGroupIterator& other) const; + + /// @brief Increment the iterator by one (pre) + /// @return The incremented iterator + BinnedGroupIterator& operator++(); + + /// @brief Return the current bin with the middle candidate, as well as all the + /// bins with the possible bottom and top candidates + /// + /// @return The collection of all the bins in the grid + std::tuple< + boost::container::small_vector, + std::size_t, + boost::container::small_vector> + operator*() const; + + private: + /// @brief Move to the next not-empty bin in the grid + void findNotEmptyBin(); + + private: + /// @brief The group that contains the grid and the bin finders + Acts::detail::RefHolder> m_group{nullptr}; + /// @brief Current N-dimentional grid iterator + typename grid_t::local_iterator_t m_gridItr; + /// @brief End iterator; + typename grid_t::local_iterator_t m_gridItrEnd; +}; + +} // namespace Acts + +#include "Acts/Seeding/BinnedGroupIterator.ipp" + +namespace Acts { +template +using BinnedSPGroupIterator = BinnedGroupIterator< + Acts::BinnedGroup>>; +} diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index df5ab194233..5daa6f50165 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -83,6 +83,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { std::size_t nIterations = 0ul; for (; itrStart != itrStop; ++itrStart, ++nIterations) { + [[maybe_unused]] auto candidates = *itrStart; } BOOST_CHECK_EQUAL(nIterations, 0ul); @@ -105,6 +106,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { std::size_t nIterations = 0ul; for (; itrStart != itrStop; ++itrStart, ++nIterations) { + [[maybe_unused]] auto candidates = *itrStart; } BOOST_CHECK_EQUAL(nIterations, 0ul); diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index 18d6e99aa06..d8051ba997f 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -9,7 +9,7 @@ #include "Acts/EventData/SpacePointData.hpp" #include "Acts/Plugins/Sycl/Seeding/SeedFinder.hpp" #include "Acts/Plugins/Sycl/Utilities/QueueWrapper.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/InternalSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/Seed.hpp" From 96ae87115ba1e7d056128f66f006a6b0d1226312 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:33:15 -0800 Subject: [PATCH 097/120] format round --- Core/include/Acts/Seeding/BinnedGroup.hpp | 6 ++--- Core/include/Acts/Seeding/BinnedGroup.ipp | 6 ++--- .../TrackFinding/src/SeedingAlgorithm.cpp | 6 ++--- .../Core/Seeding/BinnedGroupTest.cpp | 24 ++++++++++++------- .../UnitTests/Core/Seeding/SeedFinderTest.cpp | 5 ++-- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp index 981c7bfc342..23438368640 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -38,14 +38,12 @@ class BinnedGroup { BinnedGroup() = delete; /// brief Constructor - BinnedGroup(grid_t&& grid, - const Acts::GridBinFinder& bottomFinder, + BinnedGroup(grid_t&& grid, const Acts::GridBinFinder& bottomFinder, const Acts::GridBinFinder& topFinder, std::array, DIM> navigation = std::array, DIM>()); - BinnedGroup(grid_t& grid, - const Acts::GridBinFinder& bottomFinder, + BinnedGroup(grid_t& grid, const Acts::GridBinFinder& bottomFinder, const Acts::GridBinFinder& topFinder, std::array, DIM> navigation = std::array, DIM>()) = delete; diff --git a/Core/include/Acts/Seeding/BinnedGroup.ipp b/Core/include/Acts/Seeding/BinnedGroup.ipp index bf4c853475e..640552b6955 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.ipp +++ b/Core/include/Acts/Seeding/BinnedGroup.ipp @@ -11,10 +11,8 @@ namespace Acts { template BinnedGroup::BinnedGroup( grid_t&& grid, - const Acts::GridBinFinder::DIM>& - bottomFinder, - const Acts::GridBinFinder::DIM>& - topFinder, + const Acts::GridBinFinder::DIM>& bottomFinder, + const Acts::GridBinFinder::DIM>& topFinder, std::array, Acts::BinnedGroup::DIM> navigation) : m_grid(std::move(grid)), diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 05438b99e68..e1a2db956e4 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -259,9 +259,9 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( std::array, 2ul> navigation; navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; - auto spacePointsGrouping = - Acts::BinnedSPGroup(std::move(grid), *m_bottomBinFinder.get(), - *m_topBinFinder.get(), std::move(navigation)); + auto spacePointsGrouping = Acts::BinnedSPGroup( + std::move(grid), *m_bottomBinFinder.get(), *m_topBinFinder.get(), + std::move(navigation)); // safely clamp double to float float up = Acts::clampValue( diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index 5daa6f50165..3c591a5bbe1 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -52,10 +52,12 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { // Costructors // We provide a proper navigation Acts::BinnedGroup group_1d(std::move(grid_1d), *binFinder_1d.get(), - *binFinder_1d.get(), std::move(navigation_1d)); + *binFinder_1d.get(), + std::move(navigation_1d)); // We provide a partial navigation, the constructor will complete it Acts::BinnedGroup group_2d(std::move(grid_2d), *binFinder_2d.get(), - *binFinder_2d.get(), std::move(navigation_2d)); + *binFinder_2d.get(), + std::move(navigation_2d)); // We do not provide navigation, the constructor will define it Acts::BinnedGroup group_3d(std::move(grid_3d), *binFinder_3d.get(), *binFinder_3d.get()); @@ -76,7 +78,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis))); std::unique_ptr binfinder = std::make_unique(0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), + *binfinder.get()); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -99,7 +102,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis yAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); std::unique_ptr binfinder = std::make_unique(0, 0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), + *binfinder.get()); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -127,7 +131,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { std::unique_ptr botBinfinder = std::make_unique(0); std::unique_ptr topBinfinder = std::make_unique(1); - Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), *topBinfinder.get()); + Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), + *topBinfinder.get()); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -156,7 +161,8 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { std::make_unique(1, 2); std::unique_ptr topBinfinder = std::make_unique(1, 1); - Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), *topBinfinder.get()); + Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), + *topBinfinder.get()); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -182,7 +188,8 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { grid_t grid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); std::unique_ptr binfinder = std::make_unique(1, 1); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), + *binfinder.get()); /// Fill the grid already owned by the group filling only one bin at a /// specific local position @@ -223,7 +230,8 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis))); std::unique_ptr binfinder = std::make_unique(1, 1, 0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), *binfinder.get()); + Acts::BinnedGroup group(std::move(grid), *binfinder.get(), + *binfinder.get()); /// Fill the grid already owned by the group filling only one bin at a /// specific local position diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index 930e38a7393..8851bc8310b 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -200,9 +200,8 @@ int main(int argc, char** argv) { Acts::SpacePointGridCreator::createGrid(gridConf, gridOpts); Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); - auto spGroup = Acts::BinnedSPGroup(std::move(grid), - *bottomBinFinder.get(), - *topBinFinder.get()); + auto spGroup = Acts::BinnedSPGroup( + std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); std::vector>> seedVector; decltype(a)::SeedingState state; From ee2389622aa44974ad0a27795d682845b50999f4 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:37:34 -0800 Subject: [PATCH 098/120] first change for SYCL --- .../Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index d8051ba997f..f74fdf7be54 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -159,9 +159,9 @@ auto main(int argc, char** argv) -> int { std::vector> zBinNeighborsTop; std::vector> zBinNeighborsBottom; - auto bottomBinFinder = std::make_shared>( + auto bottomBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); auto config = setupSeedFinderConfiguration(); config = config.toInternalUnits().calculateDerivedQuantities(); @@ -193,11 +193,11 @@ auto main(int argc, char** argv) -> int { auto [gridConfig, gridOpts] = setupSpacePointGridConfig(config, options); gridConfig = gridConfig.toInternalUnits(); gridOpts = gridOpts.toInternalUnits(); - std::unique_ptr> grid = - Acts::SpacePointGridCreator::createGrid(gridConfig, gridOpts); + Acts::SpacePointGrid grid = + Acts::SpacePointGridCreator::createGrid(gridConfig, gridOpts); auto spGroup = Acts::BinnedSPGroup( - spVec.begin(), spVec.end(), globalTool, bottomBinFinder, topBinFinder, + spVec.begin(), spVec.end(), globalTool, *bottomBinFinder.get(), *topBinFinder.get(), std::move(grid), rRangeSPExtent, config, options); auto end_prep = std::chrono::system_clock::now(); From 93721f6a4595f27ed01c459229b2fb8585339681 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:49:12 -0800 Subject: [PATCH 099/120] other SYCL changes --- Core/include/Acts/Seeding/BinnedGroupIterator.ipp | 11 ++++------- .../Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 0176e9e35bc..0b2ea2de781 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -46,13 +46,10 @@ Acts::BinnedGroupIterator& BinnedGroupIterator::operator++() { } template -std::tuple::DIM)>, - std::size_t, - boost::container::small_vector< - std::size_t, - Acts::detail::ipow(3, Acts::BinnedGroupIterator::DIM)>> +std::tuple< + boost::container::small_vector::DIM)>, + std::size_t, + boost::container::small_vector::DIM)>> BinnedGroupIterator::operator*() const { /// Get the global and local position from current iterator. This is the bin /// with the middle candidate And we know this is not an empty bin diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index f74fdf7be54..a6f5901b23d 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -195,10 +195,10 @@ auto main(int argc, char** argv) -> int { gridOpts = gridOpts.toInternalUnits(); Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid(gridConfig, gridOpts); + Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), globalTool, rRangeSPExtent); - auto spGroup = Acts::BinnedSPGroup( - spVec.begin(), spVec.end(), globalTool, *bottomBinFinder.get(), *topBinFinder.get(), - std::move(grid), rRangeSPExtent, config, options); + std::array, 2ul> navigation; + auto spGroup = Acts::BinnedSPGroup(std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), std::move(navigation)); auto end_prep = std::chrono::system_clock::now(); From c302d3e19e30aa72a0a01942b4de3fc12b7c7acb Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 10:53:00 -0800 Subject: [PATCH 100/120] no idea --- Core/include/Acts/Seeding/BinnedGroupIterator.ipp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 0b2ea2de781..795bcb321d5 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -47,9 +47,9 @@ Acts::BinnedGroupIterator& BinnedGroupIterator::operator++() { template std::tuple< - boost::container::small_vector::DIM)>, + boost::container::small_vector::DIM)>, std::size_t, - boost::container::small_vector::DIM)>> + boost::container::small_vector::DIM)>> BinnedGroupIterator::operator*() const { /// Get the global and local position from current iterator. This is the bin /// with the middle candidate And we know this is not an empty bin From f273e4ac488a407d27de0f34ac0ebcb769885d15 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 11:19:02 -0800 Subject: [PATCH 101/120] include tuple --- Core/include/Acts/Seeding/BinnedGroupIterator.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index b10d407a479..d79d03757c7 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -15,6 +15,7 @@ #include #include +#include #include From c85782d11719d0d736c9a2815f29480712073e83 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 11:27:36 -0800 Subject: [PATCH 102/120] no general namespace --- .../include/Acts/Seeding/BinnedGroupIterator.ipp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 795bcb321d5..3dd69c0d714 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -8,10 +8,8 @@ // Binned SP Group Iterator -namespace Acts { - template -BinnedGroupIterator::BinnedGroupIterator( +Acts::BinnedGroupIterator::BinnedGroupIterator( const Acts::BinnedGroup& group, std::array::DIM> index, std::array, Acts::BinnedGroupIterator::DIM> @@ -27,19 +25,19 @@ BinnedGroupIterator::BinnedGroupIterator( } template -bool BinnedGroupIterator::operator==( +bool Acts::BinnedGroupIterator::operator==( const Acts::BinnedGroupIterator& other) const { return m_group.ptr == other.m_group.ptr && m_gridItr == other.m_gridItr; } template -bool BinnedGroupIterator::operator!=( +bool Acts::BinnedGroupIterator::operator!=( const Acts::BinnedGroupIterator& other) const { return !(*this == other); } template -Acts::BinnedGroupIterator& BinnedGroupIterator::operator++() { +Acts::BinnedGroupIterator& Acts::BinnedGroupIterator::operator++() { ++m_gridItr; findNotEmptyBin(); return *this; @@ -50,7 +48,7 @@ std::tuple< boost::container::small_vector::DIM)>, std::size_t, boost::container::small_vector::DIM)>> -BinnedGroupIterator::operator*() const { +Acts::BinnedGroupIterator::operator*() const { /// Get the global and local position from current iterator. This is the bin /// with the middle candidate And we know this is not an empty bin std::array localPosition = m_gridItr.localBinsIndices(); @@ -81,7 +79,7 @@ BinnedGroupIterator::operator*() const { } template -void BinnedGroupIterator::findNotEmptyBin() { +void Acts::BinnedGroupIterator::findNotEmptyBin() { if (m_gridItr == m_gridItrEnd) { return; } @@ -92,5 +90,3 @@ void BinnedGroupIterator::findNotEmptyBin() { dimCollection = (*m_gridItr).size(); } } - -} // namespace Acts From 905d418e481c3f405dbc896d933f12fbbf0e7f21 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 11:58:15 -0800 Subject: [PATCH 103/120] minor --- .../Acts/Seeding/#BinnedGroupIterator.hpp# | 126 ------------------ .../Acts/Seeding/BinnedGroupIterator.hpp | 4 +- 2 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# diff --git a/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# b/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# deleted file mode 100644 index dd1171060ee..00000000000 --- a/Core/include/Acts/Seeding/#BinnedGroupIterator.hpp# +++ /dev/null @@ -1,126 +0,0 @@ -// This file is part of the Acts project. -// -// Copyright (C) 2023 CERN for the benefit of the Acts project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Seeding/SpacePointGrid.hpp" -#include "Acts/Utilities/GridIterator.hpp" -#include "Acts/Utilities/Holders.hpp" -#include "Acts/Utilities/detail/grid_helper.hpp" - -#include -#include - -#include - -namespace Acts { -template -class BinnedGroup; - -template -class BinnedGroupIterator { - public: - static constexpr std::size_t DIM = grid_t::DIM; - - /// @brief Constructor - /// Never take the ownership of the group - /// - /// @param [in] group The group we are iterating on - /// @param [in] index Current local position in the grid - /// @param [in] navigation The navigation pattern in the grid - BinnedGroupIterator( - Acts::BinnedGroup&& group, std::array index, - std::array, DIM> navigation) = delete; - - /// @brief Constructor - /// Never take the ownership of the group - /// - /// @param [in] group The group we are iterating on - /// @param [in] index Current local position in the grid - /// @param [in] navigation The navigation pattern in the grid - BinnedGroupIterator(const Acts::BinnedGroup&& group, - std::array index, - std::array, DIM> navigation) = - delete; - - /// @brief Constructor - /// @param [in] group The group we are iterating on - /// @param [in] index Current local position in the grid - /// @param [in] navigation The navigation pattern in the grid - BinnedGroupIterator(const Acts::BinnedGroup& group, - std::array index, - std::array, DIM> navigation); - - /// Do not allow Copy operations - - /// @brief Copy Constructor - /// @param [in] other The BinnedGroupIterator to copy - BinnedGroupIterator(const BinnedGroupIterator& other) = delete; - /// @brief Copy assignment - /// @param [in] other The BinnedGroupIterator to copy - /// @return The copied BinnedGroupIterator - BinnedGroupIterator& operator=( - const BinnedGroupIterator& other) = delete; - - /// @brief Move Constructor - /// @param [in] other The BinnedGroupIterator to move - BinnedGroupIterator(BinnedGroupIterator&& other) noexcept = default; - /// @brief Move assignment - /// @param [in] other The BinnedGroupIterator to move - /// @return The moved BinnedGroupIterator - BinnedGroupIterator& operator=(BinnedGroupIterator&& other) noexcept = - default; - - /// @brief Default Destructor - ~BinnedGroupIterator() = default; - - /// @brief Equality operator - /// @param [in] other The BinnedGroupIterator we are comparing against this one - /// @return The result of the comparison - bool operator==(const BinnedGroupIterator& other) const; - /// @brief (In-)Equality operator - /// @param [in] other The BinnedGroupIterator we are comparing against this one - /// @return The result of the comparison - bool operator!=(const BinnedGroupIterator& other) const; - - /// @brief Increment the iterator by one (pre) - /// @return The incremented iterator - BinnedGroupIterator& operator++(); - - /// @brief Return the current bin with the middle candidate, as well as all the - /// bins with the possible bottom and top candidates - /// - /// @return The collection of all the bins in the grid - std::tuple< - boost::container::small_vector, - std::size_t, - boost::container::small_vector> - operator*() const; - - private: - /// @brief Move to the next not-empty bin in the grid - void findNotEmptyBin(); - - private: - /// @brief The group that contains the grid and the bin finders - Acts::detail::RefHolder> m_group{nullptr}; - /// @brief Current N-dimentional grid iterator - typename grid_t::local_iterator_t m_gridItr; - /// @brief End iterator; - typename grid_t::local_iterator_t m_gridItrEnd; -}; - -} // namespace Acts - -#include "Acts/Seeding/BinnedGroupIterator.ipp" - -namespace Acts { -template -using BinnedSPGroupIterator = BinnedGroupIterator< - Acts::BinnedGroup>>; -} diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index d79d03757c7..51dfffa20f3 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -98,9 +98,9 @@ class BinnedGroupIterator { /// /// @return The collection of all the bins in the grid std::tuple< - boost::container::small_vector, + boost::container::small_vector::DIM)>, std::size_t, - boost::container::small_vector> + boost::container::small_vector::DIM)>> operator*() const; private: From 2bc3bf50545caccb3eb91becab0b543c67da85e6 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:16:01 -0800 Subject: [PATCH 104/120] DIM from grid --- Core/include/Acts/Seeding/BinnedGroupIterator.hpp | 4 ++-- Core/include/Acts/Seeding/BinnedGroupIterator.ipp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index 51dfffa20f3..9c011a7d7f7 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -98,9 +98,9 @@ class BinnedGroupIterator { /// /// @return The collection of all the bins in the grid std::tuple< - boost::container::small_vector::DIM)>, + boost::container::small_vector, std::size_t, - boost::container::small_vector::DIM)>> + boost::container::small_vector> operator*() const; private: diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index 3dd69c0d714..fd971690faf 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -45,9 +45,9 @@ Acts::BinnedGroupIterator& Acts::BinnedGroupIterator::operator++ template std::tuple< - boost::container::small_vector::DIM)>, + boost::container::small_vector, std::size_t, - boost::container::small_vector::DIM)>> + boost::container::small_vector> Acts::BinnedGroupIterator::operator*() const { /// Get the global and local position from current iterator. This is the bin /// with the middle candidate And we know this is not an empty bin @@ -58,12 +58,12 @@ Acts::BinnedGroupIterator::operator*() const { /// Get the neighbouring bins boost::container::small_vector::DIM)> + 3, DIM)> bottoms = m_group->m_bottomBinFinder->findBins(localPosition, m_group->grid()); boost::container::small_vector::DIM)> + 3, DIM)> tops = m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); // GCC12+ in Release throws an overread warning here due to the move. From 8dbb8255aa9b4753f84ae724726105ac8155e4c6 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:19:27 -0800 Subject: [PATCH 105/120] format --- .../Acts/Seeding/BinnedGroupIterator.hpp | 9 ++++---- .../Acts/Seeding/BinnedGroupIterator.ipp | 22 +++++++++---------- .../Sycl/Seeding/SeedFinderSyclTest.cpp | 10 ++++++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index 9c011a7d7f7..9430ed8caec 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -97,10 +97,11 @@ class BinnedGroupIterator { /// bins with the possible bottom and top candidates /// /// @return The collection of all the bins in the grid - std::tuple< - boost::container::small_vector, - std::size_t, - boost::container::small_vector> + std::tuple, + std::size_t, + boost::container::small_vector> operator*() const; private: diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp index fd971690faf..b23010f89fe 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.ipp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.ipp @@ -37,17 +37,19 @@ bool Acts::BinnedGroupIterator::operator!=( } template -Acts::BinnedGroupIterator& Acts::BinnedGroupIterator::operator++() { +Acts::BinnedGroupIterator& +Acts::BinnedGroupIterator::operator++() { ++m_gridItr; findNotEmptyBin(); return *this; } template -std::tuple< - boost::container::small_vector, - std::size_t, - boost::container::small_vector> +std::tuple, + std::size_t, + boost::container::small_vector> Acts::BinnedGroupIterator::operator*() const { /// Get the global and local position from current iterator. This is the bin /// with the middle candidate And we know this is not an empty bin @@ -56,15 +58,11 @@ Acts::BinnedGroupIterator::operator*() const { m_group->grid().globalBinFromLocalBins(localPosition); /// Get the neighbouring bins - boost::container::small_vector + boost::container::small_vector bottoms = m_group->m_bottomBinFinder->findBins(localPosition, m_group->grid()); - boost::container::small_vector - tops = m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); + boost::container::small_vector tops = + m_group->m_topBinFinder->findBins(localPosition, m_group->grid()); // GCC12+ in Release throws an overread warning here due to the move. // This is from inside boost code, so best we can do is to suppress it. diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index a6f5901b23d..6c6d917cbd8 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -194,11 +194,15 @@ auto main(int argc, char** argv) -> int { gridConfig = gridConfig.toInternalUnits(); gridOpts = gridOpts.toInternalUnits(); Acts::SpacePointGrid grid = - Acts::SpacePointGridCreator::createGrid(gridConfig, gridOpts); - Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), globalTool, rRangeSPExtent); + Acts::SpacePointGridCreator::createGrid(gridConfig, gridOpts); + Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), + spVec.end(), globalTool, + rRangeSPExtent); std::array, 2ul> navigation; - auto spGroup = Acts::BinnedSPGroup(std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), std::move(navigation)); + auto spGroup = Acts::BinnedSPGroup( + std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), + std::move(navigation)); auto end_prep = std::chrono::system_clock::now(); From 2659e7eb95e6e1d84603d8ea6b9950d23bbf8a62 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:20:53 -0800 Subject: [PATCH 106/120] cuda first round --- Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index 33a35d28877..33740fac888 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -7,7 +7,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "Acts/Plugins/Cuda/Seeding/SeedFinder.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/InternalSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/Seed.hpp" From bf2e6af1998b570695f86699dc3fd120fe6d2128 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:25:36 -0800 Subject: [PATCH 107/120] another cuda round --- .../Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index 33740fac888..14f99abea44 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -213,9 +213,9 @@ int main(int argc, char** argv) { config.nAvgTrplPerSpBLimit = nAvgTrplPerSpBLimit; // binfinder - auto bottomBinFinder = std::make_shared>( + auto bottomBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsBottom)); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_unique>( Acts::GridBinFinder<2ul>(numPhiNeighbors, zBinNeighborsTop)); Acts::SeedFilterConfig sfconf; Acts::ATLASCuts atlasCuts = Acts::ATLASCuts(); @@ -244,11 +244,15 @@ int main(int argc, char** argv) { Acts::SpacePointGridOptions gridOpts; gridOpts.bFieldInZ = options.bFieldInZ; // create grid with bin sizes according to the configured geometry - std::unique_ptr> grid = + Acts::SpacePointGrid grid = Acts::SpacePointGridCreator::createGrid(gridConf, gridOpts); + Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), + spVec.end(), ct, rRangeSPExtent); + + std::array, 2ul> navigation; auto spGroup = Acts::BinnedSPGroup( - spVec.begin(), spVec.end(), ct, bottomBinFinder, topBinFinder, - std::move(grid), rRangeSPExtent, config, options); + std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), + std::move(navigation)); auto end_pre = std::chrono::system_clock::now(); std::chrono::duration elapsec_pre = end_pre - start_pre; From 7a7bf8e116cbaa6ba8d33bea8a07b097a7a1e3de Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:33:01 -0800 Subject: [PATCH 108/120] third cuda round --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index d58e22b6a3e..3940ccc701d 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -20,7 +20,7 @@ // Acts include(s). #include "Acts/EventData/SpacePointData.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/SeedFilterConfig.hpp" #include "Acts/Seeding/SeedFinder.hpp" #include "Acts/Seeding/SeedFinderConfig.hpp" @@ -61,9 +61,9 @@ int main(int argc, char* argv[]) { std::vector> zBinNeighborsBottom; // Create binned groups of these spacepoints. - auto bottomBinFinder = std::make_shared>( + auto bottomBinFinder = std::make_unique>( numPhiNeighbors, zBinNeighborsBottom); - auto topBinFinder = std::make_shared>( + auto topBinFinder = std::make_unique>( numPhiNeighbors, zBinNeighborsTop); // Set up the seedFinder configuration. @@ -125,9 +125,12 @@ int main(int argc, char* argv[]) { // split the spacepoints into groups according to that grid. auto grid = Acts::SpacePointGridCreator::createGrid( gridConfig, gridOpts); + Acts::SpacePointGridCreator::fillGrid(sfConfig, sfOptions, grid, + spView.begin(), spView.end(), ct, + rRangeSPExtent); + auto spGroup = Acts::BinnedSPGroup( - spView.begin(), spView.end(), ct, bottomBinFinder, topBinFinder, - std::move(grid), rRangeSPExtent, sfConfig, sfOptions); + std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); // Make a convenient iterator that will be used multiple times later on. auto spGroup_end = spGroup.end(); From 754dd24b12615c40037f3759d7ed07b038a6a39a Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:38:18 -0800 Subject: [PATCH 109/120] again cuda --- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index 3940ccc701d..99d6fba39f5 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -189,8 +189,8 @@ int main(int argc, char* argv[]) { for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = - Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + auto spGroup_itr = Acts::BinnedSPGroupIterator( + spGroup, localPosition, navigation); if (spGroup_itr == spGroup.end()) { break; } @@ -228,8 +228,8 @@ int main(int argc, char* argv[]) { for (std::size_t i = 0; i < cmdl.groupsToIterate; ++i) { std::array localPosition = spGroup.grid().localBinsFromGlobalBin(i); - auto spGroup_itr = - Acts::BinnedSPGroupIterator(spGroup, localPosition, navigation); + auto spGroup_itr = Acts::BinnedSPGroupIterator( + spGroup, localPosition, navigation); if (spGroup_itr == spGroup_end) { break; } From 351bb4c7d49734e47cf39e0dccd622d929ef3438 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 12:49:53 -0800 Subject: [PATCH 110/120] oopsie --- Core/include/Acts/Seeding/BinnedGroupIterator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index 9430ed8caec..471ca45cbd3 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -124,5 +124,5 @@ class BinnedGroupIterator { namespace Acts { template using BinnedSPGroupIterator = BinnedGroupIterator< - Acts::BinnedGroup>>; + Acts::SpacePointGrid>; } From 4d3c1275d1b47304ecb67968c6846cad1bc3fe13 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 13:32:09 -0800 Subject: [PATCH 111/120] changes --- Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index 14f99abea44..7ef1ba2d4be 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -249,10 +249,8 @@ int main(int argc, char** argv) { Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); - std::array, 2ul> navigation; auto spGroup = Acts::BinnedSPGroup( - std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), - std::move(navigation)); + std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); auto end_pre = std::chrono::system_clock::now(); std::chrono::duration elapsec_pre = end_pre - start_pre; From 074051b06793ed91bc16c04d4ed31aff9fa72f7f Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 11 Jan 2024 13:36:38 -0800 Subject: [PATCH 112/120] and last format --- Core/include/Acts/Seeding/BinnedGroupIterator.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index 471ca45cbd3..8dcc8c2d597 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -123,6 +123,6 @@ class BinnedGroupIterator { namespace Acts { template -using BinnedSPGroupIterator = BinnedGroupIterator< - Acts::SpacePointGrid>; +using BinnedSPGroupIterator = + BinnedGroupIterator>; } From ec89adb8f3affb93a5575b7f58a058b624cc8269 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Mon, 15 Jan 2024 10:59:25 +0100 Subject: [PATCH 113/120] ops --- .../include/Acts/Geometry/CylinderVolumeBuilder.hpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp b/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp index 677facfea40..4e76eab7f35 100644 --- a/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp +++ b/Core/include/Acts/Geometry/CylinderVolumeBuilder.hpp @@ -261,11 +261,6 @@ struct WrappingConfig { } } - static const Logger& logger() { - static std::unique_ptr logger = getDefaultLogger("WrappingConfig", Logging::INFO); - return *logger; - } - /// wrap, insert, attach void wrapInsertAttach() { // action is only needed if an existing volume @@ -368,11 +363,9 @@ struct WrappingConfig { existingVolumeConfig.rMin < containerVolumeConfig.rMax)) { // The volumes are overlapping this shouldn't be happening return an // error - ACTS_WARNING( - "Volumes are overlapping, this shouldn't be happening. Please " - "check your geometry building." - << "\nexistingVolumeConfig, r = " << existingVolumeConfig.rMin << " - " << existingVolumeConfig.rMax - << "\ncontainerVolumeConfig, r = " << containerVolumeConfig.rMin << " - " << containerVolumeConfig.rMax); + throw std::invalid_argument( + "Volumes are overlapping, this shouldn't be happening. Please " + "check your geometry building."); } // check if gaps are needed From 0f5dfcf90a7595c2b65869ab161424376f80f1ac Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Tue, 16 Jan 2024 21:49:12 +0100 Subject: [PATCH 114/120] ops --- Core/include/Acts/Seeding/SpacePointGrid.ipp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/include/Acts/Seeding/SpacePointGrid.ipp b/Core/include/Acts/Seeding/SpacePointGrid.ipp index 0c450168236..233feccd4ab 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.ipp +++ b/Core/include/Acts/Seeding/SpacePointGrid.ipp @@ -188,7 +188,7 @@ void Acts::SpacePointGridCreator::fillGrid( continue; } const external_spacepoint_t& sp = **it; - const auto& [spPosition, variance] = + const auto& [spPosition, variance, spTime] = toGlobal(sp, config.zAlign, config.rAlign, config.sigmaError); float spX = spPosition[0]; @@ -208,7 +208,7 @@ void Acts::SpacePointGridCreator::fillGrid( } auto isp = std::make_unique>( - counter, sp, spPosition, options.beamPos, variance); + counter, sp, spPosition, options.beamPos, variance, spTime); // calculate r-Bin index and protect against overflow (underflow not // possible) std::size_t rIndex = From 936d8936a18a0a8b9ced8aebbfd394497641f0e7 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 17 Jan 2024 08:57:57 +0100 Subject: [PATCH 115/120] wrong include --- .../TrackFindingExaTrkX/src/PrototracksToParameters.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp index 5e160705ef2..83714f83f46 100644 --- a/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp +++ b/Examples/Algorithms/TrackFindingExaTrkX/src/PrototracksToParameters.cpp @@ -8,7 +8,7 @@ #include "ActsExamples/TrackFindingExaTrkX/PrototracksToParameters.hpp" -#include "Acts/Seeding/BinnedSPGroup.hpp" +#include "Acts/Seeding/BinnedGroup.hpp" #include "Acts/Seeding/EstimateTrackParamsFromSeed.hpp" #include "Acts/Seeding/InternalSpacePoint.hpp" #include "Acts/Seeding/SeedFilter.hpp" From 578303479dd40bcebfe79f62778d410faac995df Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 17 Jan 2024 18:44:12 +0100 Subject: [PATCH 116/120] address comments --- Core/include/Acts/Seeding/BinnedGroup.hpp | 4 +- .../Acts/Seeding/BinnedGroupIterator.hpp | 2 +- Core/include/Acts/Seeding/SpacePointGrid.hpp | 2 +- .../Core/Seeding/BinnedGroupTest.cpp | 66 +++++++++---------- 4 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Core/include/Acts/Seeding/BinnedGroup.hpp b/Core/include/Acts/Seeding/BinnedGroup.hpp index 23438368640..0044e040ae4 100644 --- a/Core/include/Acts/Seeding/BinnedGroup.hpp +++ b/Core/include/Acts/Seeding/BinnedGroup.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -28,9 +28,7 @@ namespace Acts { template class BinnedGroup { public: -#ifndef DOXYGEN friend BinnedGroupIterator; -#endif static constexpr std::size_t DIM = grid_t::DIM; diff --git a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp index 8dcc8c2d597..68b063a4709 100644 --- a/Core/include/Acts/Seeding/BinnedGroupIterator.hpp +++ b/Core/include/Acts/Seeding/BinnedGroupIterator.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Core/include/Acts/Seeding/SpacePointGrid.hpp b/Core/include/Acts/Seeding/SpacePointGrid.hpp index dea82d497cc..643ee681466 100644 --- a/Core/include/Acts/Seeding/SpacePointGrid.hpp +++ b/Core/include/Acts/Seeding/SpacePointGrid.hpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2018 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index 3c591a5bbe1..f6e06862335 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -1,6 +1,6 @@ // This file is part of the Acts project. // -// Copyright (C) 2023 CERN for the benefit of the Acts project +// Copyright (C) 2024 CERN for the benefit of the Acts project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -37,12 +37,9 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { grid_2d_t grid_2d(std::make_tuple(xAxis, yAxis)); grid_3d_t grid_3d(std::make_tuple(xAxis, yAxis, zAxis)); - std::unique_ptr> binFinder_1d = - std::make_unique>(1); - std::unique_ptr> binFinder_2d = - std::make_unique>(1, 1); - std::unique_ptr> binFinder_3d = - std::make_unique>(1, 2, 1); + Acts::GridBinFinder<1ul> binFinder_1d(1); + Acts::GridBinFinder<2ul> binFinder_2d(1, 1); + Acts::GridBinFinder<3ul> binFinder_3d(1, 2 ,1); std::array, 1ul> navigation_1d; navigation_1d[0ul].resize(10); @@ -51,16 +48,16 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { // Costructors // We provide a proper navigation - Acts::BinnedGroup group_1d(std::move(grid_1d), *binFinder_1d.get(), - *binFinder_1d.get(), + Acts::BinnedGroup group_1d(std::move(grid_1d), binFinder_1d, + binFinder_1d, std::move(navigation_1d)); // We provide a partial navigation, the constructor will complete it - Acts::BinnedGroup group_2d(std::move(grid_2d), *binFinder_2d.get(), - *binFinder_2d.get(), + Acts::BinnedGroup group_2d(std::move(grid_2d), binFinder_2d, + binFinder_2d, std::move(navigation_2d)); // We do not provide navigation, the constructor will define it - Acts::BinnedGroup group_3d(std::move(grid_3d), *binFinder_3d.get(), - *binFinder_3d.get()); + Acts::BinnedGroup group_3d(std::move(grid_3d), binFinder_3d, + binFinder_3d); // Move Constructor/Assignment const Acts::BinnedGroup group_1d_moved(std::move(group_1d)); @@ -77,9 +74,9 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis))); - std::unique_ptr binfinder = std::make_unique(0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), - *binfinder.get()); + binfinder_t binfinder(0); + Acts::BinnedGroup group(std::move(grid), binfinder, + binfinder); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -101,9 +98,9 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); Acts::detail::EquidistantAxis yAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); - std::unique_ptr binfinder = std::make_unique(0, 0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), - *binfinder.get()); + binfinder_t binfinder(0, 0); + Acts::BinnedGroup group(std::move(grid), binfinder, + binfinder); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -129,10 +126,10 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { grid.at(8ul).push_back(7ul); grid.at(9ul).push_back(2ul); - std::unique_ptr botBinfinder = std::make_unique(0); - std::unique_ptr topBinfinder = std::make_unique(1); - Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), - *topBinfinder.get()); + binfinder_t botBinfinder(0); + binfinder_t topBinfinder(1); + Acts::BinnedGroup group(std::move(grid), botBinfinder, + topBinfinder); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -157,12 +154,10 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { grid.atLocalBins({2ul, 4ul}).push_back(4ul); grid.atLocalBins({4ul, 4ul}).push_back(4ul); - std::unique_ptr botBinfinder = - std::make_unique(1, 2); - std::unique_ptr topBinfinder = - std::make_unique(1, 1); - Acts::BinnedGroup group(std::move(grid), *botBinfinder.get(), - *topBinfinder.get()); + binfinder_t botBinfinder(1, 2); + binfinder_t topBinfinder(1, 1); + Acts::BinnedGroup group(std::move(grid), botBinfinder, + topBinfinder); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -187,9 +182,9 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { zAxis_t zAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); - std::unique_ptr binfinder = std::make_unique(1, 1); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), - *binfinder.get()); + binfinder_t binfinder(1, 1); + Acts::BinnedGroup group(std::move(grid), binfinder, + binfinder); /// Fill the grid already owned by the group filling only one bin at a /// specific local position @@ -228,10 +223,9 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis))); - std::unique_ptr binfinder = - std::make_unique(1, 1, 0); - Acts::BinnedGroup group(std::move(grid), *binfinder.get(), - *binfinder.get()); + binfinder_t binfinder(1, 1, 0); + Acts::BinnedGroup group(std::move(grid), binfinder, + binfinder); /// Fill the grid already owned by the group filling only one bin at a /// specific local position From 90620c8652284c9415f0a2fa06c3cbb902c59f74 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 17 Jan 2024 18:45:23 +0100 Subject: [PATCH 117/120] format --- .../Core/Seeding/BinnedGroupTest.cpp | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp index f6e06862335..3e2b5afd21a 100644 --- a/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp +++ b/Tests/UnitTests/Core/Seeding/BinnedGroupTest.cpp @@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { Acts::GridBinFinder<1ul> binFinder_1d(1); Acts::GridBinFinder<2ul> binFinder_2d(1, 1); - Acts::GridBinFinder<3ul> binFinder_3d(1, 2 ,1); + Acts::GridBinFinder<3ul> binFinder_3d(1, 2, 1); std::array, 1ul> navigation_1d; navigation_1d[0ul].resize(10); @@ -49,12 +49,10 @@ BOOST_AUTO_TEST_CASE(binned_group_constructor) { // Costructors // We provide a proper navigation Acts::BinnedGroup group_1d(std::move(grid_1d), binFinder_1d, - binFinder_1d, - std::move(navigation_1d)); + binFinder_1d, std::move(navigation_1d)); // We provide a partial navigation, the constructor will complete it Acts::BinnedGroup group_2d(std::move(grid_2d), binFinder_2d, - binFinder_2d, - std::move(navigation_2d)); + binFinder_2d, std::move(navigation_2d)); // We do not provide navigation, the constructor will define it Acts::BinnedGroup group_3d(std::move(grid_3d), binFinder_3d, binFinder_3d); @@ -75,8 +73,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_emptyGrid) { Acts::detail::EquidistantAxis xAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis))); binfinder_t binfinder(0); - Acts::BinnedGroup group(std::move(grid), binfinder, - binfinder); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -99,8 +96,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_emptyGrid) { Acts::detail::EquidistantAxis yAxis(0, 100, 10); grid_t grid(std::make_tuple(std::move(xAxis), std::move(yAxis))); binfinder_t binfinder(0, 0); - Acts::BinnedGroup group(std::move(grid), binfinder, - binfinder); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); Acts::BinnedGroupIterator itrStart = group.begin(); Acts::BinnedGroupIterator itrStop = group.end(); @@ -128,8 +124,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_1d_perFilledGrid) { binfinder_t botBinfinder(0); binfinder_t topBinfinder(1); - Acts::BinnedGroup group(std::move(grid), botBinfinder, - topBinfinder); + Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -156,8 +151,7 @@ BOOST_AUTO_TEST_CASE(binned_group_iterations_2d_perFilledGrid) { binfinder_t botBinfinder(1, 2); binfinder_t topBinfinder(1, 1); - Acts::BinnedGroup group(std::move(grid), botBinfinder, - topBinfinder); + Acts::BinnedGroup group(std::move(grid), botBinfinder, topBinfinder); std::size_t nIterations = 0ul; for (const auto [bottom, middle, top] : group) { @@ -183,8 +177,7 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_2d) { grid_t grid(std::make_tuple(std::move(phiAxis), std::move(zAxis))); binfinder_t binfinder(1, 1); - Acts::BinnedGroup group(std::move(grid), binfinder, - binfinder); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); /// Fill the grid already owned by the group filling only one bin at a /// specific local position @@ -224,8 +217,7 @@ BOOST_AUTO_TEST_CASE(binned_group_fill_3d) { grid_t grid( std::make_tuple(std::move(phiAxis), std::move(zAxis), std::move(rAxis))); binfinder_t binfinder(1, 1, 0); - Acts::BinnedGroup group(std::move(grid), binfinder, - binfinder); + Acts::BinnedGroup group(std::move(grid), binfinder, binfinder); /// Fill the grid already owned by the group filling only one bin at a /// specific local position From 38c01ade894c91a4a630d11170bba33a33d33066 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 17 Jan 2024 18:47:59 +0100 Subject: [PATCH 118/120] cuda test --- Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index c142508a676..b917803287d 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -251,7 +251,7 @@ int main(int argc, char** argv) { spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup( - std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); + std::move(grid), bottomBinFinder, topBinFinder); auto end_pre = std::chrono::system_clock::now(); std::chrono::duration elapsec_pre = end_pre - start_pre; From 96215adc933d1b815c370ddb00e98945c50544eb Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Wed, 17 Jan 2024 20:11:10 +0100 Subject: [PATCH 119/120] ops --- Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp index b917803287d..e69093ea2a0 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding/SeedFinderCudaTest.cpp @@ -251,7 +251,7 @@ int main(int argc, char** argv) { spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup( - std::move(grid), bottomBinFinder, topBinFinder); + std::move(grid), *bottomBinFinder, *topBinFinder); auto end_pre = std::chrono::system_clock::now(); std::chrono::duration elapsec_pre = end_pre - start_pre; From 01e57d88a49403ecca1b74899f5e7b7a0eb143d7 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Thu, 18 Jan 2024 06:07:37 +0100 Subject: [PATCH 120/120] changes --- Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp | 2 +- Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp | 2 +- Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp | 2 +- Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp index 2ead2f450b9..28bbf370b67 100644 --- a/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp +++ b/Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp @@ -259,7 +259,7 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute( std::array, 2ul> navigation; navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping; auto spacePointsGrouping = Acts::BinnedSPGroup( - std::move(grid), *m_bottomBinFinder.get(), *m_topBinFinder.get(), + std::move(grid), *m_bottomBinFinder, *m_topBinFinder, std::move(navigation)); // safely clamp double to float diff --git a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp index f43aace339b..3da78628991 100644 --- a/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp +++ b/Tests/UnitTests/Core/Seeding/SeedFinderTest.cpp @@ -201,7 +201,7 @@ int main(int argc, char** argv) { Acts::SpacePointGridCreator::fillGrid(config, options, grid, spVec.begin(), spVec.end(), ct, rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup( - std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); + std::move(grid), *bottomBinFinder, *topBinFinder); std::vector>> seedVector; decltype(a)::SeedingState state; diff --git a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp index f95f067a91b..818c8a9aa44 100644 --- a/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp +++ b/Tests/UnitTests/Plugins/Cuda/Seeding2/main.cpp @@ -130,7 +130,7 @@ int main(int argc, char* argv[]) { rRangeSPExtent); auto spGroup = Acts::BinnedSPGroup( - std::move(grid), *bottomBinFinder.get(), *topBinFinder.get()); + std::move(grid), *bottomBinFinder, *topBinFinder); // Make a convenient iterator that will be used multiple times later on. auto spGroup_end = spGroup.end(); diff --git a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp index fc0c8c62dbd..7e518691ff6 100644 --- a/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp +++ b/Tests/UnitTests/Plugins/Sycl/Seeding/SeedFinderSyclTest.cpp @@ -202,8 +202,7 @@ auto main(int argc, char** argv) -> int { std::array, 2ul> navigation; auto spGroup = Acts::BinnedSPGroup( - std::move(grid), *bottomBinFinder.get(), *topBinFinder.get(), - std::move(navigation)); + std::move(grid), *bottomBinFinder, *topBinFinder, std::move(navigation)); auto end_prep = std::chrono::system_clock::now();