Skip to content

Commit

Permalink
hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
cvarni committed Oct 13, 2024
1 parent 3fa958a commit addfcf4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 56 deletions.
14 changes: 9 additions & 5 deletions Core/include/Acts/Seeding/SeedFinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@

namespace Acts {

template<typename Coll>
concept GridBinCollection = std::ranges::random_access_range<Coll> &&
template <typename Coll>
concept GridBinCollection =
std::ranges::random_access_range<Coll> &&
std::same_as<typename Coll::value_type, std::size_t>;

template<typename Coll, typename external_t, std::size_t N = 3ul>
concept CollectionStoresSeedsTo = std::ranges::output_range<Coll, Acts::Seed<external_t, N>>;

template <typename Coll, typename external_t, std::size_t N = 3ul>
concept CollectionStoresSeedsTo = requires(Coll coll, external_t sp) {
Acts::detail::pushBackOrInsertAtEnd(coll,
Acts::Seed<external_t, N>(sp, sp, sp));
};

enum class SpacePointCandidateType : short { eBottom, eTop };

enum class DetectorMeasurementInfo : short { eDefault, eDetailed };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// -*- C++ -*-
// This file is part of the ACTS project.
//
// Copyright (C) 2016 CERN for the benefit of the ACTS project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class SeedingAlgorithmHashing final : public IAlgorithm {
// Connect custom selections on the space points or to the doublet
// compatibility
bool useExtraCuts = false;

float deltaRMiddleMinSPRange = 10. * Acts::UnitConstants::mm;
float deltaRMiddleMaxSPRange = 10. * Acts::UnitConstants::mm;

/// Order of z bins to loop over when searching for SPs
std::vector<std::size_t> zBinsCustomLooping = {};
};

/// Construct the seeding algorithm.
Expand Down
43 changes: 13 additions & 30 deletions Examples/Algorithms/TrackFinding/src/SeedingAlgorithmHashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,10 @@ ActsExamples::SeedingAlgorithmHashing::SeedingAlgorithmHashing(
m_outputSeeds.initialize(m_cfg.outputSeeds);
m_outputBuckets.initialize(m_cfg.outputBuckets);

if (m_cfg.gridConfig.rMax != m_cfg.seedFinderConfig.rMax &&
m_cfg.allowSeparateRMax == false) {
throw std::invalid_argument(
"Inconsistent config rMax: using different values in gridConfig and "
"seedFinderConfig. If values are intentional set allowSeparateRMax to "
"true");
}

if (m_cfg.seedFilterConfig.deltaRMin != m_cfg.seedFinderConfig.deltaRMin) {
throw std::invalid_argument("Inconsistent config deltaRMin");
}

if (m_cfg.gridConfig.deltaRMax != m_cfg.seedFinderConfig.deltaRMax) {
throw std::invalid_argument("Inconsistent config deltaRMax");
}

static_assert(
std::numeric_limits<
decltype(m_cfg.seedFinderConfig.deltaRMaxTopSP)>::has_quiet_NaN,
Expand All @@ -114,29 +102,21 @@ ActsExamples::SeedingAlgorithmHashing::SeedingAlgorithmHashing(
"Value of deltaRMinBottomSP must support NaN values");

if (std::isnan(m_cfg.seedFinderConfig.deltaRMaxTopSP)) {
m_cfg.seedFinderConfig.deltaRMaxTopSP = m_cfg.seedFinderConfig.deltaRMax;
m_cfg.seedFinderConfig.deltaRMaxTopSP = m_cfg.gridConfig.deltaRMax;
}

if (std::isnan(m_cfg.seedFinderConfig.deltaRMinTopSP)) {
m_cfg.seedFinderConfig.deltaRMinTopSP = m_cfg.seedFinderConfig.deltaRMin;
}

if (std::isnan(m_cfg.seedFinderConfig.deltaRMaxBottomSP)) {
m_cfg.seedFinderConfig.deltaRMaxBottomSP = m_cfg.seedFinderConfig.deltaRMax;
m_cfg.seedFinderConfig.deltaRMaxBottomSP = m_cfg.gridConfig.deltaRMax;
}

if (std::isnan(m_cfg.seedFinderConfig.deltaRMinBottomSP)) {
m_cfg.seedFinderConfig.deltaRMinBottomSP = m_cfg.seedFinderConfig.deltaRMin;
}

if (m_cfg.gridConfig.zMin != m_cfg.seedFinderConfig.zMin) {
throw std::invalid_argument("Inconsistent config zMin");
}

if (m_cfg.gridConfig.zMax != m_cfg.seedFinderConfig.zMax) {
throw std::invalid_argument("Inconsistent config zMax");
}

if (m_cfg.seedFilterConfig.maxSeedsPerSpM !=
m_cfg.seedFinderConfig.maxSeedsPerSpM) {
throw std::invalid_argument("Inconsistent config maxSeedsPerSpM");
Expand Down Expand Up @@ -273,10 +253,12 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithmHashing::execute(
Acts::CylindricalSpacePointGridCreator::createGrid<value_type>(
m_cfg.gridConfig, m_cfg.gridOptions);
Acts::CylindricalSpacePointGridCreator::fillGrid(
m_cfg.seedFinderConfig, m_cfg.seedFinderOptions, grid,
m_cfg.seedFinderConfig, grid,
spContainer.begin(), spContainer.end());

// Compute radius Range
auto localSeedFinderOptions = m_cfg.seedFinderOptions;

// we rely on the fact the grid is storing the proxies
// with a sorting in the radius
float minRange = std::numeric_limits<float>::max();
Expand All @@ -292,24 +274,25 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithmHashing::execute(
}

std::array<std::vector<std::size_t>, 3ul> navigation;
navigation[1ul] = m_cfg.seedFinderConfig.zBinsCustomLooping;
navigation[1ul] = m_cfg.zBinsCustomLooping;

// groups spacepoints
auto spacePointsGrouping = Acts::CylindricalBinnedGroup<value_type>(
std::move(grid), *m_bottomBinFinder, *m_topBinFinder,
std::move(navigation));

/// variable middle SP radial region of interest
const Acts::Range1D<float> rMiddleSPRange(
minRange + m_cfg.seedFinderConfig.deltaRMiddleMinSPRange,
maxRange - m_cfg.seedFinderConfig.deltaRMiddleMaxSPRange);

localSeedFinderOptions.rMinMiddle = std::floor(minRange / 2) * 2 +
m_cfg.deltaRMiddleMinSPRange;
localSeedFinderOptions.rMaxMiddle = std::floor(maxRange / 2) * 2 -
m_cfg.deltaRMiddleMaxSPRange;

// this creates seeds of proxy, we need to convert it to seed of space
// points
for (const auto [bottom, middle, top] : spacePointsGrouping) {
m_seedFinder.createSeedsForGroup(
m_cfg.seedFinderOptions, state, spacePointsGrouping.grid(),
seedsSetForBucket, bottom, middle, top, rMiddleSPRange);
localSeedFinderOptions, state, spacePointsGrouping.grid(),
seedsSetForBucket, bottom, middle, top);
}

// proxies die when the Acts::SpacePointContainer dies, so we need to
Expand Down
36 changes: 16 additions & 20 deletions Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@

HashingAlgorithmConfigArg = namedtuple(
"HashingAlgorithmConfig",
["bucketSize", "zBins", "phiBins"],
defaults=[None] * 3,
["bucketSize",
"zBins",
"phiBins",
"deltaRMiddleMinSPRange",
"deltaRMiddleMaxSPRange",
"zBinsCustomLooping"],
defaults=[None] * 6,
)


Expand Down Expand Up @@ -690,6 +695,7 @@ def addStandardSeeding(
if seedFinderConfigArg.deltaRBottomSP[1] is None
else seedFinderConfigArg.deltaRBottomSP[1]
),
middleRangeStrategy=seedFinderConfigArg.middleRangeStrategy,
collisionRegionMin=seedFinderConfigArg.collisionRegion[0],
collisionRegionMax=seedFinderConfigArg.collisionRegion[1],
maxSeedsPerSpM=seedFinderConfigArg.maxSeedsPerSpM,
Expand Down Expand Up @@ -918,10 +924,7 @@ def addHashingSeeding(
# Same configuration than the standard seeding
seedFinderConfig = acts.SeedFinderConfig(
**acts.examples.defaultKWArgs(
rMin=seedFinderConfigArg.r[0],
rMax=seedFinderConfigArg.r[1],
deltaRMin=seedFinderConfigArg.deltaR[0],
deltaRMax=seedFinderConfigArg.deltaR[1],
deltaRMinTopSP=(
seedFinderConfigArg.deltaR[0]
if seedFinderConfigArg.deltaRTopSP[0] is None
Expand All @@ -942,12 +945,9 @@ def addHashingSeeding(
if seedFinderConfigArg.deltaRBottomSP[1] is None
else seedFinderConfigArg.deltaRBottomSP[1]
),
deltaRMiddleMinSPRange=seedFinderConfigArg.deltaRMiddleSPRange[0],
deltaRMiddleMaxSPRange=seedFinderConfigArg.deltaRMiddleSPRange[1],
middleRangeStrategy=seedFinderConfigArg.middleRangeStrategy,
collisionRegionMin=seedFinderConfigArg.collisionRegion[0],
collisionRegionMax=seedFinderConfigArg.collisionRegion[1],
zMin=seedFinderConfigArg.z[0],
zMax=seedFinderConfigArg.z[1],
maxSeedsPerSpM=seedFinderConfigArg.maxSeedsPerSpM,
cotThetaMax=seedFinderConfigArg.cotThetaMax,
sigmaScattering=seedFinderConfigArg.sigmaScattering,
Expand All @@ -958,10 +958,6 @@ def addHashingSeeding(
deltaZMax=seedFinderConfigArg.deltaZMax,
maxPtScattering=seedFinderConfigArg.maxPtScattering,
zBinEdges=seedFinderConfigArg.zBinEdges,
zBinsCustomLooping=seedFinderConfigArg.zBinsCustomLooping,
rRangeMiddleSP=seedFinderConfigArg.rRangeMiddleSP,
useVariableMiddleSPRange=seedFinderConfigArg.useVariableMiddleSPRange,
binSizeR=seedFinderConfigArg.binSizeR,
seedConfirmation=seedFinderConfigArg.seedConfirmation,
centralSeedConfirmationRange=seedFinderConfigArg.centralSeedConfirmationRange,
forwardSeedConfirmationRange=seedFinderConfigArg.forwardSeedConfirmationRange,
Expand Down Expand Up @@ -1005,13 +1001,10 @@ def addHashingSeeding(
gridConfig = acts.SpacePointGridConfig(
**acts.examples.defaultKWArgs(
minPt=seedFinderConfig.minPt,
rMax=(
seedFinderConfig.rMax
if spacePointGridConfigArg.rMax is None
else spacePointGridConfigArg.rMax
),
zMax=seedFinderConfig.zMax,
zMin=seedFinderConfig.zMin,
rMin=spacePointGridConfigArg.r[0],
rMax=spacePointGridConfigArg.r[1],
zMin=spacePointGridConfigArg.z[0],
zMax=spacePointGridConfigArg.z[1],
deltaRMax=(
seedFinderConfig.deltaRMax
if spacePointGridConfigArg.deltaRMax is None
Expand Down Expand Up @@ -1046,6 +1039,9 @@ def addHashingSeeding(
bucketSize=hashingAlgorithmConfigArg.bucketSize,
zBins=hashingAlgorithmConfigArg.zBins,
phiBins=hashingAlgorithmConfigArg.phiBins,
deltaRMiddleMinSPRange=hashingAlgorithmConfigArg.deltaRMiddleMinSPRange,
deltaRMiddleMaxSPRange=hashingAlgorithmConfigArg.deltaRMiddleMaxSPRange,
zBinsCustomLooping=hashingAlgorithmConfigArg.zBinsCustomLooping,
),
)

Expand Down
3 changes: 2 additions & 1 deletion Examples/Python/src/Hashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void addHashing(Context& ctx) {
"SeedingAlgorithmHashing", inputSpacePoints, outputSeeds, outputBuckets,
seedFilterConfig, seedFinderConfig, seedFinderOptions, gridConfig,
gridOptions, allowSeparateRMax, zBinNeighborsTop, zBinNeighborsBottom,
numPhiNeighbors, hashingConfig, hashingTrainingConfig, useExtraCuts);
numPhiNeighbors, hashingConfig, hashingTrainingConfig, useExtraCuts, deltaRMiddleMinSPRange,
deltaRMiddleMaxSPRange, zBinsCustomLooping);
}

} // namespace Acts::Python

0 comments on commit addfcf4

Please sign in to comment.