Skip to content

Commit bf5a3fc

Browse files
authored
refactor!: SSS Seeding: Store dynamic variables instead of constantly copying them (acts-project#1966)
Built on top of acts-project#1948 Dynamic variables are stored in the `SpacePointData` object. It looks like ~95% of the strip space points will have to use these variables during the seed finding process.
1 parent ea1ec0c commit bf5a3fc

File tree

6 files changed

+138
-27
lines changed

6 files changed

+138
-27
lines changed

Core/include/Acts/EventData/SpacePointData.hpp

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#pragma once
1010

11+
#include "Acts/Definitions/Algebra.hpp"
12+
1113
#include <limits>
1214
#include <vector>
1315

@@ -44,18 +46,75 @@ class SpacePointData {
4446
void setQuality(std::size_t idx, const float& value);
4547
void setDeltaR(std::size_t idx, const float& value);
4648

47-
/// @brief Reserve memory
48-
void reserve(std::size_t n);
49-
5049
/// @brief Resize vectors
51-
void resize(std::size_t n);
50+
void resize(std::size_t n, bool resizeDynamic = false);
5251

5352
/// @brief clear vectors
5453
void clear();
5554

55+
///
56+
bool hasDynamicVariable() const { return not m_topHalfStripLength.empty(); }
57+
58+
const float& getTopHalfStripLength(std::size_t idx) const {
59+
return m_topHalfStripLength[idx];
60+
}
61+
62+
const float& getBottomHalfStripLength(std::size_t idx) const {
63+
return m_bottomHalfStripLength[idx];
64+
}
65+
66+
const Acts::Vector3& getTopStripDirection(std::size_t idx) const {
67+
return m_topStripDirection[idx];
68+
}
69+
70+
const Acts::Vector3& getBottomStripDirection(std::size_t idx) const {
71+
return m_bottomStripDirection[idx];
72+
}
73+
74+
const Acts::Vector3& getStripCenterDistance(std::size_t idx) const {
75+
return m_stripCenterDistance[idx];
76+
}
77+
78+
const Acts::Vector3& getTopStripCenterPosition(std::size_t idx) const {
79+
return m_topStripCenterPosition[idx];
80+
}
81+
82+
void setTopHalfStripLength(std::size_t idx, const float& value) {
83+
m_topHalfStripLength[idx] = value;
84+
}
85+
86+
void setBottomHalfStripLength(std::size_t idx, const float& value) {
87+
m_bottomHalfStripLength[idx] = value;
88+
}
89+
90+
void setTopStripDirection(std::size_t idx, const Acts::Vector3& value) {
91+
m_topStripDirection[idx] = value;
92+
}
93+
94+
void setBottomStripDirection(std::size_t idx, const Acts::Vector3& value) {
95+
m_bottomStripDirection[idx] = value;
96+
}
97+
98+
void setStripCenterDistance(std::size_t idx, const Acts::Vector3& value) {
99+
m_stripCenterDistance[idx] = value;
100+
}
101+
102+
void setTopStripCenterPosition(std::size_t idx, const Acts::Vector3& value) {
103+
m_topStripCenterPosition[idx] = value;
104+
}
105+
56106
private:
107+
/// Mutable variables
57108
std::vector<float> m_quality{};
58109
std::vector<float> m_deltaR{};
110+
111+
/// dynamic variables
112+
std::vector<float> m_topHalfStripLength{};
113+
std::vector<float> m_bottomHalfStripLength{};
114+
std::vector<Acts::Vector3> m_topStripDirection{};
115+
std::vector<Acts::Vector3> m_bottomStripDirection{};
116+
std::vector<Acts::Vector3> m_stripCenterDistance{};
117+
std::vector<Acts::Vector3> m_topStripCenterPosition{};
59118
};
60119

61120
inline const float& SpacePointData::quality(std::size_t idx) const {
@@ -76,19 +135,33 @@ inline void SpacePointData::setDeltaR(std::size_t idx, const float& value) {
76135
m_deltaR[idx] = value;
77136
}
78137

79-
inline void SpacePointData::reserve(std::size_t n) {
80-
m_quality.reserve(n);
81-
m_deltaR.reserve(n);
82-
}
138+
inline void SpacePointData::resize(std::size_t n, bool resizeDynamic) {
139+
clear();
83140

84-
inline void SpacePointData::resize(std::size_t n) {
85141
m_quality.resize(n, -std::numeric_limits<float>::infinity());
86142
m_deltaR.resize(n, 0.);
143+
144+
if (resizeDynamic) {
145+
m_topHalfStripLength.resize(n, 0.);
146+
m_bottomHalfStripLength.resize(n, 0.);
147+
m_topStripDirection.resize(n, {0, 0, 0});
148+
m_bottomStripDirection.resize(n, {0, 0, 0});
149+
m_stripCenterDistance.resize(n, {0, 0, 0});
150+
m_topStripCenterPosition.resize(n, {0, 0, 0});
151+
}
87152
}
88153

89154
inline void SpacePointData::clear() {
155+
// mutable variables
90156
m_quality.clear();
91157
m_deltaR.clear();
158+
// dynamicvariables
159+
m_topHalfStripLength.clear();
160+
m_bottomHalfStripLength.clear();
161+
m_topStripDirection.clear();
162+
m_bottomStripDirection.clear();
163+
m_stripCenterDistance.clear();
164+
m_topStripCenterPosition.clear();
92165
}
93166

94167
} // namespace Acts

Core/include/Acts/Seeding/SeedFinder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ class SeedFinder {
138138
out_range_t& outVec, const float& deltaRMinSP, const float& deltaRMaxSP,
139139
bool isBottom) const;
140140

141-
void filterCandidates(const InternalSpacePoint<external_spacepoint_t>& SpM,
141+
void filterCandidates(Acts::SpacePointData& spacePointData,
142+
const InternalSpacePoint<external_spacepoint_t>& SpM,
142143
const Acts::SeedFinderOptions& options,
143144
SeedFilterState& seedFilterState,
144145
SeedingState& state) const;

Core/include/Acts/Seeding/SeedFinder.ipp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ void SeedFinder<external_spacepoint_t, platform_t>::createSeedsForGroup(
161161
}
162162

163163
// filter candidates
164-
filterCandidates(*spM.get(), options, seedFilterState, state);
164+
filterCandidates(state.spacePointData, *spM.get(), options, seedFilterState,
165+
state);
165166

166167
m_config.seedFilter->filterSeeds_1SpFixed(
167168
state.spacePointData, state.candidates_collector,
@@ -297,6 +298,7 @@ SeedFinder<external_spacepoint_t, platform_t>::getCompatibleDoublets(
297298
template <typename external_spacepoint_t, typename platform_t>
298299

299300
inline void SeedFinder<external_spacepoint_t, platform_t>::filterCandidates(
301+
Acts::SpacePointData& spacePointData,
300302
const InternalSpacePoint<external_spacepoint_t>& spM,
301303
const Acts::SeedFinderOptions& options, SeedFilterState& seedFilterState,
302304
SeedingState& state) const {
@@ -435,7 +437,8 @@ inline void SeedFinder<external_spacepoint_t, platform_t>::filterCandidates(
435437
cosTheta * std::sqrt(1 + A0 * A0)};
436438

437439
double rMTransf[3];
438-
if (!xyzCoordinateCheck(m_config, spM, positionMiddle, rMTransf)) {
440+
if (!xyzCoordinateCheck(spacePointData, m_config, spM, positionMiddle,
441+
rMTransf)) {
439442
continue;
440443
}
441444

@@ -450,7 +453,8 @@ inline void SeedFinder<external_spacepoint_t, platform_t>::filterCandidates(
450453

451454
auto spB = state.compatBottomSP[b];
452455
double rBTransf[3];
453-
if (!xyzCoordinateCheck(m_config, *spB, positionBottom, rBTransf)) {
456+
if (!xyzCoordinateCheck(spacePointData, m_config, *spB, positionBottom,
457+
rBTransf)) {
454458
continue;
455459
}
456460

@@ -464,7 +468,8 @@ inline void SeedFinder<external_spacepoint_t, platform_t>::filterCandidates(
464468

465469
auto spT = state.compatTopSP[t];
466470
double rTTransf[3];
467-
if (!xyzCoordinateCheck(m_config, *spT, positionTop, rTTransf)) {
471+
if (!xyzCoordinateCheck(spacePointData, m_config, *spT, positionTop,
472+
rTTransf)) {
468473
continue;
469474
}
470475

Core/include/Acts/Seeding/SeedFinderUtils.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ void transformCoordinates(Acts::SpacePointData& spacePointData,
7676
///
7777
/// @tparam external_spacepoint_t The external spacepoint type.
7878
///
79+
/// @param[in] spacePointData Auxiliary variables used by the seeding
7980
/// @param[in] config SeedFinder config containing the delegates to the strip measurement details.
8081
/// @param[in] sp Input space point used in the check.
8182
/// @param[in] spacepointPosition Spacepoint coordinates in xyz plane.
8283
/// @param[out] outputCoordinates The output vector to write to.
8384
/// @returns Boolean that says if spacepoint is compatible with being inside the detector element.
8485
template <typename external_spacepoint_t>
8586
bool xyzCoordinateCheck(
87+
Acts::SpacePointData& spacePointData,
8688
const Acts::SeedFinderConfig<external_spacepoint_t>& config,
8789
const Acts::InternalSpacePoint<external_spacepoint_t>& sp,
8890
const double* spacepointPosition, double* outputCoordinates);

Core/include/Acts/Seeding/SeedFinderUtils.ipp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,28 @@ inline void transformCoordinates(Acts::SpacePointData& spacePointData,
149149

150150
template <typename external_spacepoint_t>
151151
inline bool xyzCoordinateCheck(
152+
Acts::SpacePointData& spacePointData,
152153
const Acts::SeedFinderConfig<external_spacepoint_t>& m_config,
153154
const Acts::InternalSpacePoint<external_spacepoint_t>& sp,
154155
const double* spacepointPosition, double* outputCoordinates) {
155156
// check the compatibility of SPs coordinates in xyz assuming the
156157
// Bottom-Middle direction with the strip measurement details
157-
const float topHalfStripLength = m_config.getTopHalfStripLength(sp.sp());
158-
const float bottomHalfStripLength =
159-
m_config.getBottomHalfStripLength(sp.sp());
160-
const Acts::Vector3 topStripDirection =
161-
m_config.getTopStripDirection(sp.sp());
162-
const Acts::Vector3 bottomStripDirection =
163-
m_config.getBottomStripDirection(sp.sp());
164-
const Acts::Vector3 stripCenterDistance =
165-
m_config.getStripCenterDistance(sp.sp());
158+
bool hasValueStored = spacePointData.hasDynamicVariable();
159+
if (not hasValueStored) {
160+
return false;
161+
}
162+
163+
std::size_t index = sp.index();
164+
165+
const float& topHalfStripLength = spacePointData.getTopHalfStripLength(index);
166+
const float& bottomHalfStripLength =
167+
spacePointData.getBottomHalfStripLength(index);
168+
const Acts::Vector3& topStripDirection =
169+
spacePointData.getTopStripDirection(index);
170+
const Acts::Vector3& bottomStripDirection =
171+
spacePointData.getBottomStripDirection(index);
172+
const Acts::Vector3& stripCenterDistance =
173+
spacePointData.getStripCenterDistance(index);
166174

167175
// cross product between top strip vector and spacepointPosition
168176
double d1[3] = {
@@ -211,8 +219,8 @@ inline bool xyzCoordinateCheck(
211219
// if arive here spacepointPosition is compatible with strip directions and
212220
// detector elements
213221

214-
const Acts::Vector3 topStripCenterPosition =
215-
m_config.getTopStripCenterPosition(sp.sp());
222+
const Acts::Vector3& topStripCenterPosition =
223+
spacePointData.getTopStripCenterPosition(index);
216224

217225
// spacepointPosition corected with respect to the top strip position and
218226
// direction and the distance between the strips

Examples/Algorithms/TrackFinding/src/SeedingAlgorithm.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,31 @@ ActsExamples::ProcessCode ActsExamples::SeedingAlgorithm::execute(
251251
static thread_local SimSeedContainer seeds;
252252
seeds.clear();
253253
static thread_local decltype(m_seedFinder)::SeedingState state;
254+
state.spacePointData.resize(
255+
spacePointPtrs.size(),
256+
m_cfg.seedFinderConfig.useDetailedDoubleMeasurementInfo);
254257

255-
state.spacePointData.clear();
256-
state.spacePointData.resize(spacePointPtrs.size());
258+
if (m_cfg.seedFinderConfig.useDetailedDoubleMeasurementInfo) {
259+
for (std::size_t grid_glob_bin(0);
260+
grid_glob_bin < spacePointsGrouping.grid().size(); ++grid_glob_bin) {
261+
const auto& collection = spacePointsGrouping.grid().at(grid_glob_bin);
262+
for (const auto& sp : collection) {
263+
std::size_t index = sp->index();
264+
state.spacePointData.setTopHalfStripLength(
265+
index, m_cfg.seedFinderConfig.getTopHalfStripLength(sp->sp()));
266+
state.spacePointData.setBottomHalfStripLength(
267+
index, m_cfg.seedFinderConfig.getBottomHalfStripLength(sp->sp()));
268+
state.spacePointData.setTopStripDirection(
269+
index, m_cfg.seedFinderConfig.getTopStripDirection(sp->sp()));
270+
state.spacePointData.setBottomStripDirection(
271+
index, m_cfg.seedFinderConfig.getBottomStripDirection(sp->sp()));
272+
state.spacePointData.setStripCenterDistance(
273+
index, m_cfg.seedFinderConfig.getStripCenterDistance(sp->sp()));
274+
state.spacePointData.setTopStripCenterPosition(
275+
index, m_cfg.seedFinderConfig.getTopStripCenterPosition(sp->sp()));
276+
}
277+
}
278+
}
257279

258280
for (const auto [bottom, middle, top] : spacePointsGrouping) {
259281
m_seedFinder.createSeedsForGroup(

0 commit comments

Comments
 (0)