77 template <
typename calibrator_t,
typename source_link_t>
79 const calibrator_t& calibrator,
81 const std::vector<source_link_t>& sourcelinks,
82 std::vector<std::pair<size_t, double>>& sourcelinkChi2,
83 std::vector<size_t>& sourcelinkCandidateIndices,
bool& isOutlier,
88 if (sourcelinks.empty()) {
89 return CombinatorialKalmanFilterError::SourcelinkSelectionFailed;
94 auto geoID =
surface->geometryId();
102 return CombinatorialKalmanFilterError::SourcelinkSelectionFailed;
104 const auto chi2CutOff = cuts->chi2CutOff;
105 const auto numSourcelinksCutOff = cuts->numSourcelinksCutOff;
108 "Allowed maximum number of source links: " << numSourcelinksCutOff);
110 sourcelinkChi2.resize(sourcelinks.size());
114 size_t nInitialCandidates = 0;
116 for (
const auto& sourcelink : sourcelinks) {
118 [&](
const auto& calibrated) {
120 assert(&calibrated.referenceObject() ==
surface);
123 const auto&
H = calibrated.projector();
125 const auto& predictedCovariance = *predictedParams.
covariance();
127 const auto& residual =
128 calibrated.residual(predictedParams.
parameters());
130 double chi2 = (residual.transpose() *
131 ((calibrated.covariance() +
132 H * predictedCovariance * H.transpose()))
139 if (chi2 < chi2CutOff) {
140 sourcelinkChi2.at(nInitialCandidates) = {index, chi2};
141 nInitialCandidates++;
144 if (chi2 < minChi2) {
149 calibrator(sourcelink, predictedParams));
155 size_t nFinalCandidates =
156 std::min(nInitialCandidates, numSourcelinksCutOff);
160 if (nFinalCandidates == 0) {
161 sourcelinkCandidateIndices.resize(1);
162 sourcelinkCandidateIndices.at(0) = minIndex;
163 ACTS_DEBUG(
"No measurement candidate. Return an outlier source link.");
168 ACTS_VERBOSE(
"Number of measurement candidates: " << nFinalCandidates);
169 sourcelinkCandidateIndices.resize(nFinalCandidates);
171 std::sort(sourcelinkChi2.begin(),
172 sourcelinkChi2.begin() + nInitialCandidates,
173 [](
const std::pair<size_t, double>& lchi2,
174 const std::pair<size_t, double>& rchi2) {
175 return lchi2.second < rchi2.second;
179 size_t nRecorded = 0;
180 for (
const auto& [
id, chi2] : sourcelinkChi2) {
181 if (nRecorded >= nFinalCandidates) {
184 sourcelinkCandidateIndices.at(nRecorded) = id;