Skip to content

Commit 56aff8b

Browse files
authored
refactor: SP builder uses SourceLinks instead of Measurements (acts-project#1953)
This PR changes the SP builder input from Measurements to SourceLink so that users can avoid unnecessary measurement creation. Some SP builder parameters are moved from the config to the option to allow event/module-dependent parameters.
1 parent cf036b6 commit 56aff8b

File tree

8 files changed

+249
-273
lines changed

8 files changed

+249
-273
lines changed

Core/include/Acts/SpacePointFormation/SpacePointBuilder.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "Acts/Digitization/CartesianSegmentation.hpp"
1313
#include "Acts/Digitization/DigitizationModule.hpp"
1414
#include "Acts/Digitization/Segmentation.hpp"
15-
#include "Acts/EventData/Measurement.hpp"
1615
#include "Acts/Geometry/GeometryContext.hpp"
1716
#include "Acts/Geometry/TrackingGeometry.hpp"
1817
#include "Acts/SpacePointFormation/SpacePointBuilderConfig.hpp"
@@ -29,12 +28,11 @@ namespace Acts {
2928
///
3029
/// After the particle interaction with surfaces are recorded and digitized
3130
/// measurements on the pixel or strip detectors need further treatment. This
32-
/// class takes the measurements and provides the corresponding space points.
31+
/// class takes the SouceLinks and provides the corresponding space points.
3332
///
3433
template <typename spacepoint_t>
3534
class SpacePointBuilder {
3635
public:
37-
using Measurement = Acts::BoundVariantMeasurement;
3836
// Constructor
3937
/// @param cfg The configuration for the space point builder
4038
/// @param func The function that provides user's SP constructor with global pos, global cov, and sourceLinks.
@@ -50,33 +48,32 @@ class SpacePointBuilder {
5048
// Default constructor
5149
SpacePointBuilder() = default;
5250

53-
/// @brief Calculates the space points out of a given collection of measurements
51+
/// @brief Calculates the space points out of a given collection of SourceLinks
5452
/// and stores the results
5553
///
5654
/// @param gctx The current geometry context object, e.g. alignment
57-
/// @param measurements vector of measurements
55+
/// @param sourceLinks vector of Sourcelink
5856
/// @param opt option for the space point bulding. It contains the ends of the strips for strip SP building
5957
/// @param spacePointIt Output iterator for the space point
6058
template <template <typename...> typename container_t>
6159
void buildSpacePoint(
62-
const GeometryContext& gctx,
63-
const std::vector<const Measurement*>& measurements,
60+
const GeometryContext& gctx, const std::vector<SourceLink>& sourceLinks,
6461
const SpacePointBuilderOptions& opt,
6562
std::back_insert_iterator<container_t<spacepoint_t>> spacePointIt) const;
6663

67-
/// @brief Searches possible combinations of two measurements on different
64+
/// @brief Searches possible combinations of two SourceLinks on different
6865
/// surfaces that may come from the same particles
6966
///
7067
/// @param gctx The current geometry context object, e.g. alignment
71-
/// @param measurementsFront vector of measurements on a surface
72-
/// @param measurementsBack vector of measurements on another surface
73-
/// @param measurementPairs storage of the measurement pairs
74-
void makeMeasurementPairs(
75-
const GeometryContext& gctx,
76-
const std::vector<const Measurement*>& measurementsFront,
77-
const std::vector<const Measurement*>& measurementsBack,
78-
std::vector<std::pair<const Measurement*, const Measurement*>>&
79-
measurementPairs) const;
68+
/// @param slinksFront vector of Sourcelinks on a surface
69+
/// @param slinksBack vector of SoruceLinks on another surface
70+
/// @param slinkPairs storage of the SouceLink pairs
71+
/// @param pairOpt pair maker option with paramCovAccessor
72+
void makeSourceLinkPairs(
73+
const GeometryContext& gctx, const std::vector<SourceLink>& slinksFront,
74+
const std::vector<SourceLink>& slinksBack,
75+
std::vector<std::pair<SourceLink, SourceLink>>& slinkPairs,
76+
const StripPairOptions& pairOpt) const;
8077

8178
protected:
8279
// configuration of the single hit space point builder
@@ -88,7 +85,6 @@ class SpacePointBuilder {
8885
std::function<spacepoint_t(Acts::Vector3, Acts::Vector2,
8986
boost::container::static_vector<SourceLink, 2>)>
9087
m_spConstructor;
91-
9288
/// the logging instance
9389
std::unique_ptr<const Acts::Logger> m_logger;
9490

Core/include/Acts/SpacePointFormation/SpacePointBuilderConfig.hpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ namespace Acts {
1515
struct SpacePointBuilderConfig {
1616
/// Tracking geometry
1717
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
18-
/// vertex position
19-
Vector3 vertex = {0., 0., 0.};
20-
/// Accepted squared difference in theta for two clusters
21-
double diffTheta2 = 1.;
22-
/// Accepted squared difference in phi for two clusters
23-
double diffPhi2 = 1.;
24-
/// Accepted distance between two clusters
25-
double diffDist = 100. * UnitConstants::mm;
26-
/// Allowed increase of strip length
27-
double stripLengthTolerance = 0.01;
28-
/// Allowed increase of strip length wrt gaps between strips
29-
double stripLengthGapTolerance = 0.01;
3018
/// Perform the perpendicular projection for space point finding
3119
bool usePerpProj = false;
3220

Core/include/Acts/SpacePointFormation/SpacePointBuilderOptions.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,40 @@
88

99
#pragma once
1010

11+
#include "Acts/EventData/SourceLink.hpp"
12+
1113
namespace Acts {
1214

1315
struct SpacePointBuilderOptions {
16+
// ends of strip pairs
1417
std::pair<const std::pair<Vector3, Vector3>,
1518
const std::pair<Vector3, Vector3>>
1619
stripEndsPair;
20+
// accessor of local position and covariance from soruce link
21+
std::function<std::pair<const BoundVector, const BoundSymMatrix>(SourceLink)>
22+
paramCovAccessor;
23+
/// vertex position
24+
Vector3 vertex = {0., 0., 0.};
25+
/// Allowed increase of strip length
26+
double stripLengthTolerance = 0.01;
27+
/// Allowed increase of strip length wrt gaps between strips
28+
double stripLengthGapTolerance = 0.01;
29+
SpacePointBuilderOptions() = default;
30+
};
31+
32+
struct StripPairOptions {
33+
// accessor of local position and covariance from soruce link
34+
std::function<std::pair<const BoundVector, const BoundSymMatrix>(SourceLink)>
35+
paramCovAccessor;
36+
/// vertex position
37+
Vector3 vertex = {0., 0., 0.};
38+
/// Accepted squared difference in theta for two clusters
39+
double diffTheta2 = 1.;
40+
/// Accepted squared difference in phi for two clusters
41+
double diffPhi2 = 1.;
42+
/// Accepted distance between two clusters
43+
double diffDist = 100. * UnitConstants::mm;
44+
StripPairOptions() = default;
1745
};
1846

1947
} // namespace Acts

Core/include/Acts/SpacePointFormation/detail/SpacePointBuilder.ipp

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// This Source Code Form is subject to the terms of the Mozilla Public
66
// License, v. 2.0. If a copy of the MPL was not distributed with this
77
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
8-
98
namespace Acts {
9+
1010
template <typename spacepoint_t>
1111
SpacePointBuilder<spacepoint_t>::SpacePointBuilder(
1212
const SpacePointBuilderConfig& cfg,
@@ -21,22 +21,21 @@ SpacePointBuilder<spacepoint_t>::SpacePointBuilder(
2121
template <typename spacepoint_t>
2222
template <template <typename...> typename container_t>
2323
void SpacePointBuilder<spacepoint_t>::buildSpacePoint(
24-
const GeometryContext& gctx,
25-
const std::vector<const Measurement*>& measurements,
24+
const GeometryContext& gctx, const std::vector<SourceLink>& sourceLinks,
2625
const SpacePointBuilderOptions& opt,
2726
std::back_insert_iterator<container_t<spacepoint_t>> spacePointIt) const {
28-
const unsigned int num_meas = measurements.size();
27+
const unsigned int num_slinks = sourceLinks.size();
2928

3029
Acts::Vector3 gPos = Acts::Vector3::Zero();
3130
Acts::Vector2 gCov = Acts::Vector2::Zero();
3231

33-
if (num_meas == 1) { // pixel SP formation
34-
35-
auto gPosCov = m_spUtility->globalCoords(gctx, *(measurements[0]));
32+
if (num_slinks == 1) { // pixel SP formation
33+
auto slink = sourceLinks.at(0);
34+
auto [param, cov] = opt.paramCovAccessor(sourceLinks.at(0));
35+
auto gPosCov = m_spUtility->globalCoords(gctx, slink, param, cov);
3636
gPos = gPosCov.first;
3737
gCov = gPosCov.second;
38-
39-
} else if (num_meas == 2) { // strip SP formation
38+
} else if (num_slinks == 2) { // strip SP formation
4039

4140
const auto& ends1 = opt.stripEndsPair.first;
4241
const auto& ends2 = opt.stripEndsPair.second;
@@ -46,12 +45,11 @@ void SpacePointBuilder<spacepoint_t>::buildSpacePoint(
4645
if (!m_config.usePerpProj) { // default strip SP building
4746

4847
auto spFound = m_spUtility->calculateStripSPPosition(
49-
ends1, ends2, m_config.vertex, spParams,
50-
m_config.stripLengthTolerance);
48+
ends1, ends2, opt.vertex, spParams, opt.stripLengthTolerance);
5149

5250
if (!spFound.ok()) {
53-
spFound = m_spUtility->recoverSpacePoint(
54-
spParams, m_config.stripLengthGapTolerance);
51+
spFound = m_spUtility->recoverSpacePoint(spParams,
52+
opt.stripLengthGapTolerance);
5553
}
5654

5755
if (!spFound.ok()) {
@@ -76,75 +74,59 @@ void SpacePointBuilder<spacepoint_t>::buildSpacePoint(
7674
acos(spParams.firstBtmToTop.dot(spParams.secondBtmToTop) /
7775
(spParams.firstBtmToTop.norm() * spParams.secondBtmToTop.norm()));
7876

79-
gCov = m_spUtility->calcRhoZVars(gctx, *(measurements.at(0)),
80-
*(measurements.at(1)), gPos, theta);
77+
gCov = m_spUtility->calcRhoZVars(gctx, sourceLinks.at(0), sourceLinks.at(1),
78+
opt.paramCovAccessor, gPos, theta);
8179

8280
} else {
83-
ACTS_ERROR("More than 2 measurements are given for a space point.");
84-
}
85-
86-
boost::container::static_vector<SourceLink, 2> slinks;
87-
for (const auto& meas : measurements) {
88-
const auto& slink =
89-
std::visit([](const auto& x) { return x.sourceLink(); }, *meas);
90-
slinks.emplace_back(slink);
81+
ACTS_ERROR("More than 2 sourceLinks are given for a space point.");
9182
}
83+
boost::container::static_vector<SourceLink, 2> slinks(sourceLinks.begin(),
84+
sourceLinks.end());
9285

9386
spacePointIt = m_spConstructor(gPos, gCov, std::move(slinks));
9487
}
9588

9689
template <typename spacepoint_t>
97-
void SpacePointBuilder<spacepoint_t>::makeMeasurementPairs(
98-
const GeometryContext& gctx,
99-
const std::vector<const Measurement*>& measurementsFront,
100-
const std::vector<const Measurement*>& measurementsBack,
101-
std::vector<std::pair<const Measurement*, const Measurement*>>&
102-
measurementPairs) const {
103-
// Return if no Measurements are given in a vector
104-
if (measurementsFront.empty() || measurementsBack.empty()) {
90+
void SpacePointBuilder<spacepoint_t>::makeSourceLinkPairs(
91+
const GeometryContext& gctx, const std::vector<SourceLink>& slinksFront,
92+
const std::vector<SourceLink>& slinksBack,
93+
std::vector<std::pair<SourceLink, SourceLink>>& slinkPairs,
94+
const StripPairOptions& pairOpt) const {
95+
if (slinksFront.empty() || slinksBack.empty()) {
10596
return;
10697
}
107-
// Declare helper variables
108-
double currentDiff = 0;
109-
double diffMin = 0;
110-
unsigned int measurementMinDist = 0;
111-
112-
// Walk through all Measurements on both surfaces
113-
for (unsigned int iMeasurementsFront = 0;
114-
iMeasurementsFront < measurementsFront.size(); iMeasurementsFront++) {
115-
// Set the closest distance to the maximum of double
116-
diffMin = std::numeric_limits<double>::max();
117-
// Set the corresponding index to an element not in the list of Measurements
118-
measurementMinDist = measurementsBack.size();
119-
for (unsigned int iMeasurementsBack = 0;
120-
iMeasurementsBack < measurementsBack.size(); iMeasurementsBack++) {
121-
auto [gposFront, gcovFront] = m_spUtility->globalCoords(
122-
gctx, *(measurementsFront[iMeasurementsFront]));
123-
auto [gposBack, gcovBack] = m_spUtility->globalCoords(
124-
gctx, *(measurementsBack[iMeasurementsBack]));
98+
double minDistance = 0;
99+
unsigned int closestIndex = 0;
100+
101+
for (unsigned int i = 0; i < slinksFront.size(); i++) {
102+
const auto& slinkFront = slinksFront[i];
103+
minDistance = std::numeric_limits<double>::max();
104+
closestIndex = slinksBack.size();
105+
for (unsigned int j = 0; j < slinksBack.size(); j++) {
106+
const auto& slinkBack = slinksBack[j];
107+
108+
const auto [paramFront, covFront] = pairOpt.paramCovAccessor(slinkFront);
109+
const auto [gposFront, gcovFront] =
110+
m_spUtility->globalCoords(gctx, slinkFront, paramFront, covFront);
111+
112+
const auto [paramBack, covBack] = pairOpt.paramCovAccessor(slinkBack);
113+
const auto [gposBack, gcovBack] =
114+
m_spUtility->globalCoords(gctx, slinkBack, paramBack, covBack);
125115

126116
auto res = m_spUtility->differenceOfMeasurementsChecked(
127-
gposFront, gposBack, m_config.vertex, m_config.diffDist,
128-
m_config.diffPhi2, m_config.diffTheta2);
117+
gposFront, gposBack, pairOpt.vertex, pairOpt.diffDist,
118+
pairOpt.diffPhi2, pairOpt.diffTheta2);
129119
if (!res.ok()) {
130120
continue;
131121
}
132-
133-
currentDiff = res.value();
134-
135-
// Store the closest Measurements (distance and index) calculated so far
136-
if (currentDiff < diffMin && currentDiff >= 0.) {
137-
diffMin = currentDiff;
138-
measurementMinDist = iMeasurementsBack;
122+
const auto distance = res.value();
123+
if (distance >= 0. && distance < minDistance) {
124+
minDistance = distance;
125+
closestIndex = j;
139126
}
140127
}
141-
142-
// Store the best (=closest) result
143-
if (measurementMinDist < measurementsBack.size()) {
144-
std::pair<const Measurement*, const Measurement*> measurementPair =
145-
std::make_pair(measurementsFront[iMeasurementsFront],
146-
measurementsBack[measurementMinDist]);
147-
measurementPairs.push_back(measurementPair);
128+
if (closestIndex < slinksBack.size()) {
129+
slinkPairs.emplace_back(slinksFront[i], slinksBack[closestIndex]);
148130
}
149131
}
150132
}

0 commit comments

Comments
 (0)