Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Seeding runs on const inputs #1948

Merged
merged 19 commits into from
Mar 21, 2023
94 changes: 94 additions & 0 deletions Core/include/Acts/EventData/SpacePointData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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 <limits>
#include <vector>

namespace Acts {

/// @class SpacePointData
/// This class contains auxiliary and mutable data associated to the
/// external space points provided by the customers
/// These variables are used internally by the seeding algorithm, that
/// reads and updates them
/// The variables collected here are also dynamic variables only present
/// for strip space points
class SpacePointData {
public:
/// @brief Default constructor
SpacePointData() = default;

/// No copies
SpacePointData(const SpacePointData& other) = delete;
SpacePointData& operator=(const SpacePointData& other) = delete;

/// @brief Move operations
SpacePointData(SpacePointData&& other) noexcept = default;
SpacePointData& operator=(SpacePointData&& other) noexcept = default;

/// @brief Destructor
~SpacePointData() = default;

/// @brief Getters
const float& quality(std::size_t idx) const;
const float& deltaR(std::size_t idx) const;

/// @brief Setters
void setQuality(std::size_t idx, const float& value);
void setDeltaR(std::size_t idx, const float& value);

/// @brief Reserve memory
void reserve(std::size_t n);

/// @brief Resize vectors
void resize(std::size_t n);

/// @brief clear vectors
void clear();

private:
std::vector<float> m_quality{};
std::vector<float> m_deltaR{};
};

inline const float& SpacePointData::quality(std::size_t idx) const {
return m_quality[idx];
}

inline const float& SpacePointData::deltaR(std::size_t idx) const {
return m_deltaR[idx];
}

inline void SpacePointData::setQuality(std::size_t idx, const float& value) {
if (value > m_quality[idx]) {
m_quality[idx] = value;
}
}

inline void SpacePointData::setDeltaR(std::size_t idx, const float& value) {
m_deltaR[idx] = value;
}

inline void SpacePointData::reserve(std::size_t n) {
m_quality.reserve(n);
m_deltaR.reserve(n);
}

inline void SpacePointData::resize(std::size_t n) {
m_quality.resize(n, -std::numeric_limits<float>::infinity());
m_deltaR.resize(n, 0.);
}

inline void SpacePointData::clear() {
m_quality.clear();
m_deltaR.clear();
}

} // namespace Acts
5 changes: 3 additions & 2 deletions Core/include/Acts/Seeding/BinnedSPGroup.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ Acts::BinnedSPGroup<external_spacepoint_t>::BinnedSPGroup(
// keep track of changed bins while sorting
boost::container::flat_set<size_t> rBinsIndex;

for (spacepoint_iterator_t it = spBegin; it != spEnd; it++) {
std::size_t counter = 0;
for (spacepoint_iterator_t it = spBegin; it != spEnd; it++, ++counter) {
if (*it == nullptr) {
continue;
}
Expand All @@ -178,7 +179,7 @@ Acts::BinnedSPGroup<external_spacepoint_t>::BinnedSPGroup(
}

auto isp = std::make_unique<InternalSpacePoint<external_spacepoint_t>>(
sp, spPosition, options.beamPos, variance);
counter, sp, spPosition, options.beamPos, variance);
// calculate r-Bin index and protect against overflow (underflow not
// possible)
size_t rIndex = static_cast<size_t>(isp->radius() / config.binSizeR);
Expand Down
4 changes: 2 additions & 2 deletions Core/include/Acts/Seeding/IExperimentCuts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class IExperimentCuts {
/// space point in a std::tuple format
/// @return vector of seed candidates that pass the cut
virtual std::vector<typename CandidatesForMiddleSp<
InternalSpacePoint<SpacePoint>>::value_type>
const InternalSpacePoint<SpacePoint>>::value_type>
cutPerMiddleSP(std::vector<typename CandidatesForMiddleSp<
InternalSpacePoint<SpacePoint>>::value_type>
const InternalSpacePoint<SpacePoint>>::value_type>
seedCandidates) const = 0;
};
} // namespace Acts
42 changes: 16 additions & 26 deletions Core/include/Acts/Seeding/InternalSpacePoint.hpp
Original file line number Diff line number Diff line change
@@ -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) 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
Expand All @@ -12,6 +12,7 @@

#include <array>
#include <cmath>
#include <functional>
#include <limits>

namespace Acts {
Expand All @@ -23,7 +24,8 @@ class InternalSpacePoint {

public:
InternalSpacePoint() = delete;
InternalSpacePoint(const SpacePoint& sp, const Acts::Vector3& globalPos,
InternalSpacePoint(std::size_t index, const SpacePoint& sp,
const Acts::Vector3& globalPos,
const Acts::Vector2& offsetXY,
const Acts::Vector2& variance);

Expand All @@ -33,36 +35,25 @@ class InternalSpacePoint {
InternalSpacePoint<SpacePoint>& operator=(
const InternalSpacePoint<SpacePoint>&) = delete;

std::size_t index() const { return m_index; }
const float& x() const { return m_x; }
const float& y() const { return m_y; }
const float& z() const { return m_z; }
const float& radius() const { return m_r; }
float phi() const { return atan2f(m_y, m_x); }
const float& varianceR() const { return m_varianceR; }
const float& varianceZ() const { return m_varianceZ; }
const float& deltaR() const { return m_deltaR; }
const float& quality() const { return m_quality; }
void setDeltaR(float deltaR) { m_deltaR = deltaR; }
void setQuality(float quality) {
if (quality >= m_quality) {
m_quality = quality;
}
}
const SpacePoint& sp() const { return m_sp; }

protected:
std::size_t m_index;
float m_x; // x-coordinate in beam system coordinates
float m_y; // y-coordinate in beam system coordinates
float m_z; // z-coordinate in beam system coordinetes
float m_r; // radius in beam system coordinates
float m_varianceR; //
float m_varianceZ; //
float m_deltaR; //
float m_quality = -std::numeric_limits<
double>::infinity(); // Quality score of the seed the space point is used
// for. Quality can be changed if the space point is
// used for a better quality seed.
const SpacePoint& m_sp; // external space point
std::reference_wrapper<const SpacePoint> m_sp; // external space point
};

/////////////////////////////////////////////////////////////////////////////////
Expand All @@ -71,17 +62,16 @@ class InternalSpacePoint {

template <typename SpacePoint>
inline InternalSpacePoint<SpacePoint>::InternalSpacePoint(
const SpacePoint& sp, const Acts::Vector3& globalPos,
std::size_t index, const SpacePoint& sp, const Acts::Vector3& globalPos,
const Acts::Vector2& offsetXY, const Acts::Vector2& variance)
: m_sp(sp) {
m_x = globalPos.x() - offsetXY.x();
m_y = globalPos.y() - offsetXY.y();
m_z = globalPos.z();
m_r = std::sqrt(m_x * m_x + m_y * m_y);
m_varianceR = variance.x();
m_varianceZ = variance.y();
m_deltaR = 0;
}
: m_index(index),
m_x(globalPos.x() - offsetXY.x()),
m_y(globalPos.y() - offsetXY.y()),
m_z(globalPos.z()),
m_r(std::sqrt(m_x * m_x + m_y * m_y)),
m_varianceR(variance.x()),
m_varianceZ(variance.y()),
m_sp(sp) {}

/////////////////////////////////////////////////////////////////////////////////
// Copy constructor
Expand Down
12 changes: 6 additions & 6 deletions Core/include/Acts/Seeding/Neighbour.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ struct Neighbour {
/// @param grid The grid containing the space points
/// @param idx The global index of the bin in the grid
/// @param lowerBound The lower bound of the allowed space point
Neighbour(Acts::SpacePointGrid<external_spacepoint_t>& grid, std::size_t idx,
const float lowerBound);
Neighbour(const Acts::SpacePointGrid<external_spacepoint_t>& grid,
std::size_t idx, const float lowerBound);

/// The global bin index on the grid
std::size_t index;
/// The iterator containing the position of the first space point in the valid
/// radius range
typename Acts::SpacePointGrid<external_spacepoint_t>::value_type::iterator
itr;
typename Acts::SpacePointGrid<
external_spacepoint_t>::value_type::const_iterator itr;
};

template <typename external_spacepoint_t>
Neighbour<external_spacepoint_t>::Neighbour(
Acts::SpacePointGrid<external_spacepoint_t>& grid, std::size_t idx,
const Acts::SpacePointGrid<external_spacepoint_t>& grid, std::size_t idx,
const float lowerBound)
: index(idx) {
/// Get the space points in this specific global bin
auto& collection = grid.at(idx);
const auto& collection = grid.at(idx);
/// If there are no elements in the bin, we simply set the iterator to begin()
/// and return. In this case begin() == end() so we run on nothing
if (collection.size() == 0) {
Expand Down
23 changes: 16 additions & 7 deletions Core/include/Acts/Seeding/SeedFilter.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// This file is part of the Acts project.
//
// Copyright (C) 2018-2020 CERN for the benefit 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/EventData/SpacePointData.hpp"
#include "Acts/Seeding/CandidatesForMiddleSp.hpp"
#include "Acts/Seeding/IExperimentCuts.hpp"
#include "Acts/Seeding/InternalSeed.hpp"
Expand Down Expand Up @@ -51,6 +52,7 @@ class SeedFilter {

/// Create InternalSeeds for the all seeds with the same bottom and middle
/// space point and discard all others.
/// @param spacePointData Auxiliary variables used by the seeding
/// @param bottomSP fixed bottom space point
/// @param middleSP fixed middle space point
/// @param topSpVec vector containing all space points that may be compatible
Expand All @@ -60,35 +62,42 @@ class SeedFilter {
/// @param seedFilterState holds quantities used in seed filter
/// @param candidates_collector container for the seed candidates
virtual void filterSeeds_2SpFixed(
InternalSpacePoint<external_spacepoint_t>& bottomSP,
InternalSpacePoint<external_spacepoint_t>& middleSP,
std::vector<InternalSpacePoint<external_spacepoint_t>*>& topSpVec,
Acts::SpacePointData& spacePointData,
const InternalSpacePoint<external_spacepoint_t>& bottomSP,
const InternalSpacePoint<external_spacepoint_t>& middleSP,
const std::vector<const InternalSpacePoint<external_spacepoint_t>*>&
topSpVec,
const std::vector<float>& invHelixDiameterVec,
const std::vector<float>& impactParametersVec,
SeedFilterState& seedFilterState,
CandidatesForMiddleSp<InternalSpacePoint<external_spacepoint_t>>&
CandidatesForMiddleSp<const InternalSpacePoint<external_spacepoint_t>>&
candidates_collector) const;

/// Filter seeds once all seeds for one middle space point have been created
/// @param spacePointData Auxiliary variables used by the seeding
/// @param candidates_collector collection of seed candidates
/// @param numQualitySeeds number of high quality seeds in seed confirmation
/// @param outIt Output iterator for the seeds
/// for all seeds with the same middle space point
virtual void filterSeeds_1SpFixed(
CandidatesForMiddleSp<InternalSpacePoint<external_spacepoint_t>>&
Acts::SpacePointData& spacePointData,
CandidatesForMiddleSp<const InternalSpacePoint<external_spacepoint_t>>&
candidates_collector,
std::size_t& numQualitySeeds,
std::back_insert_iterator<std::vector<Seed<external_spacepoint_t>>> outIt)
const;

/// Filter seeds once all seeds for one middle space point have been created
/// @param spacePointData Auxiliary variables used by the seeding
/// @param candidates collection of seed candidates
/// @param numQualitySeeds number of high quality seeds in seed confirmation
/// @param outIt Output iterator for the seeds
/// for all seeds with the same middle space point
virtual void filterSeeds_1SpFixed(
Acts::SpacePointData& spacePointData,
std::vector<typename CandidatesForMiddleSp<
InternalSpacePoint<external_spacepoint_t>>::value_type>& candidates,
const InternalSpacePoint<external_spacepoint_t>>::value_type>&
candidates,
std::size_t& numQualitySeeds,
std::back_insert_iterator<std::vector<Seed<external_spacepoint_t>>> outIt)
const;
Expand Down
Loading