ATLAS Offline Software
Loading...
Searching...
No Matches
TrackFindingBaseAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// ActsTrk
14#include "Acts/Surfaces/PerigeeSurface.hpp"
15
17
18namespace ActsTrk {
20
23
24 TrackFindingBaseAlg::TrackFindingBaseAlg(const std::string &name, ISvcLocator *pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
25
27
29 ATH_MSG_DEBUG("Properties Summary:");
41 ATH_MSG_DEBUG(" " << m_phiMin);
42 ATH_MSG_DEBUG(" " << m_phiMax);
43 ATH_MSG_DEBUG(" " << m_etaMin);
44 ATH_MSG_DEBUG(" " << m_etaMax);
47 ATH_MSG_DEBUG(" " << m_ptMin);
48 ATH_MSG_DEBUG(" " << m_ptMax);
49 ATH_MSG_DEBUG(" " << m_d0Min);
50 ATH_MSG_DEBUG(" " << m_d0Max);
51 ATH_MSG_DEBUG(" " << m_z0Min);
52 ATH_MSG_DEBUG(" " << m_z0Max);
70
71 m_logger = makeActsAthenaLogger(this, "Acts");
72
73 // Read and Write handles
74 ATH_CHECK(m_trackContainerKey.initialize());
76
77 ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
79 ATH_CHECK(m_ctxProvider.initialize());
80 ATH_CHECK(m_trackStatePrinter.retrieve(EnableTool{not m_trackStatePrinter.empty()}));
81 ATH_CHECK(m_fitterTool.retrieve());
82 ATH_CHECK(m_pixelCalibTool.retrieve(EnableTool{not m_pixelCalibTool.empty()}));
83 ATH_CHECK(m_stripCalibTool.retrieve(EnableTool{not m_stripCalibTool.empty()}));
84 ATH_CHECK(m_hgtdCalibTool.retrieve(EnableTool{not m_hgtdCalibTool.empty()}));
85
86 auto magneticField = std::make_unique<ATLASMagneticFieldWrapper>();
87 auto trackingGeometry = m_trackingGeometrySvc->trackingGeometry();
88
89 detail::Stepper stepper(std::move(magneticField));
90 detail::Navigator::Config config{trackingGeometry};
91 config.resolvePassive = false;
92 config.resolveMaterial = true;
93 config.resolveSensitive = true;
94 detail::Navigator navigator(config, logger().cloneWithSuffix("Navigator"));
95 detail::Propagator propagator(std::move(stepper), std::move(navigator), logger().cloneWithSuffix("Prop"));
96
97 // Using the CKF propagator as extrapolator
98 detail::Extrapolator extrapolator = propagator;
99
100 // m_etaBins (from flags.Tracking.ActiveConfig.etaBins) includes a dummy first and last bin, which we ignore
101 std::vector<double> absEtaEdges;
102 if (m_etaBins.size() <= 2)
103 {
104 absEtaEdges.reserve(2ul);
105 absEtaEdges.push_back(0.0);
106 absEtaEdges.push_back(std::numeric_limits<double>::infinity());
107 }
108 else
109 {
110 absEtaEdges.reserve(m_etaBins.size());
111 absEtaEdges.push_back(m_absEtaMin);
112 absEtaEdges.insert(absEtaEdges.end(), m_etaBins.begin() + 1, m_etaBins.end() - 1);
113 absEtaEdges.push_back(m_absEtaMax);
114 }
115
116 auto setCut = [](auto &cfgVal, const auto &cuts, size_t ind) -> void
117 {
118 if (cuts.empty())
119 return;
120 cfgVal = (ind < cuts.size()) ? cuts[ind] : cuts[cuts.size() - 1];
121 };
122
123 Acts::TrackSelector::EtaBinnedConfig trackSelectorCfg{std::move(absEtaEdges)};
124 if (m_etaBins.size() <= 2)
125 {
126 assert(trackSelectorCfg.cutSets.size() == 1);
127 trackSelectorCfg.cutSets[0].absEtaMin = m_absEtaMin;
128 trackSelectorCfg.cutSets[0].absEtaMax = m_absEtaMax;
129 }
130 size_t cutIndex = 0;
131 for (auto &cfg : trackSelectorCfg.cutSets)
132 {
133 setCut(cfg.phiMin, m_phiMin, cutIndex);
134 setCut(cfg.phiMax, m_phiMax, cutIndex);
135 setCut(cfg.etaMin, m_etaMin, cutIndex);
136 setCut(cfg.etaMax, m_etaMax, cutIndex);
137 setCut(cfg.ptMin, m_ptMin, cutIndex);
138 setCut(cfg.ptMax, m_ptMax, cutIndex);
139 setCut(cfg.loc0Min, m_d0Min, cutIndex);
140 setCut(cfg.loc0Max, m_d0Max, cutIndex);
141 setCut(cfg.loc1Min, m_z0Min, cutIndex);
142 setCut(cfg.loc1Max, m_z0Max, cutIndex);
143 setCut(cfg.minMeasurements, m_minMeasurements, cutIndex);
144 setCut(cfg.maxHoles, m_maxHoles, cutIndex);
145 setCut(cfg.maxOutliers, m_maxOutliers, cutIndex);
146 setCut(cfg.maxSharedHits, m_maxSharedHits, cutIndex);
147 setCut(cfg.maxChi2, m_maxChi2, cutIndex);
148 ++cutIndex;
149 }
150
151 ATH_MSG_DEBUG(trackSelectorCfg);
152
153 // initializer measurement selector and connect it to the delegates of the track finder optins
155
156 detail::CKF_config ckfConfig{
157 std::move(extrapolator),
158 detail::CKF{std::move(propagator), logger().cloneWithSuffix("CKF")},
159 {},
160 Acts::TrackSelector{trackSelectorCfg}};
161
162 m_trackFinder = std::make_unique<CKF_pimpl>(std::move(ckfConfig));
163
165
166 m_unalibMeasSurfAcc = detail::xAODUncalibMeasSurfAcc {m_trackingGeometrySvc.get()};
167
169
170 return StatusCode::SUCCESS;
171 }
172
173 StatusCode TrackFindingBaseAlg::execute(const EventContext &) const {
174 ATH_MSG_FATAL("execute() method from the base class was called! Implement proper execute() method in the derived class!");
175
176 return StatusCode::FAILURE;
177 }
178
181
182 return StatusCode::SUCCESS;
183 }
184
185 std::unique_ptr<ActsTrk::IMeasurementSelector> TrackFindingBaseAlg::setMeasurementSelector(
186 const EventContext &ctx,
187 const detail::TrackFindingMeasurements &measurements,
188 TrackFinderOptions &options) const {
189
190 std::unique_ptr<ActsTrk::IMeasurementSelector> measurementSelector = ActsTrk::detail::getMeasurementSelector(
191 ctx,
192 m_pixelCalibTool.isEnabled() ? &(*m_pixelCalibTool) : nullptr,
193 m_stripCalibTool.isEnabled() ? &(*m_stripCalibTool) : nullptr,
194 m_hgtdCalibTool.isEnabled() ? &(*m_hgtdCalibTool) : nullptr,
195 measurements.measurementRanges(),
197 m_measurementSelectorConfig.m_chi2CutOffOutlier,
199 m_edgeHoleBorderWidth.value());
200
201 measurementSelector->connect(&options.extensions.createTrackStates);
202
203 return measurementSelector;
204 }
205
207 const EventContext &ctx,
208 const DetectorContextHolder &detContext,
209 const detail::TrackFindingMeasurements &measurements,
210 const Acts::PerigeeSurface* pSurface) const {
211 Acts::PropagatorPlainOptions plainOptions{detContext.geometry, detContext.magField};
212 plainOptions.maxSteps = m_maxPropagationStep;
213 plainOptions.direction = Acts::Direction::Forward();
214 plainOptions.endOfWorldVolumeIds = m_endOfWorldVolumeIds;
215
216 // Set the CombinatorialKalmanFilter options
217 TrackFinderOptions options(detContext.geometry, detContext.magField, detContext.calib,
218 trackFinder().ckfExtensions, plainOptions, pSurface);
219
220 std::unique_ptr<ActsTrk::IMeasurementSelector> measurementSelector = setMeasurementSelector(ctx, measurements, options);
221
222 Acts::PropagatorPlainOptions plainSecondOptions{detContext.geometry, detContext.magField};
223 plainSecondOptions.maxSteps = m_maxPropagationStep;
224 plainSecondOptions.direction = plainOptions.direction.invert();
225
226 TrackFinderOptions secondOptions(detContext.geometry, detContext.magField, detContext.calib,
227 options.extensions, plainSecondOptions, pSurface);
228 secondOptions.targetSurface = pSurface;
229 secondOptions.skipPrePropagationUpdate = true;
230
231 return {std::move(options), std::move(secondOptions), std::move(measurementSelector)};
232 };
233
234 const Acts::TrackSelector::Config& TrackFindingBaseAlg::getCuts (double eta) const {
235 const auto &trackSelectorCfg = trackFinder().trackSelector.config();
236 // return the last bin for |eta|>=4 or nan
237 return (!(std::abs(eta) < trackSelectorCfg.absEtaEdges.back())) ? trackSelectorCfg.cutSets.back()
238 : (std::abs(eta) < trackSelectorCfg.absEtaEdges.front()) ? trackSelectorCfg.cutSets.front()
239 : trackSelectorCfg.getCuts(eta);
240 };
241
242 std::vector<typename detail::RecoTrackContainer::TrackProxy>
244 const TrkProxy &trackProxy,
245 detail::RecoTrackContainer &tracksContainerTemp,
246 const TrackFinderOptions &options) const {
247 if (not m_doTwoWay) return {};
248
249 // Create initial parameters for the propagation
250 Acts::BoundTrackParameters secondInitialParameters = trackProxy.createParametersFromState(detail::RecoConstTrackStateContainerProxy{firstMeasurement});
251 if (!secondInitialParameters.referenceSurface().insideBounds(secondInitialParameters.localPosition())) { // #3751
252 return {};
253 }
254
255 // First, inflate the covariance matrix if configured
257 ATH_MSG_DEBUG("Inflating covariance matrix for second track finding with factor = " << m_twoWayinflateCovarianceFactor.value());
258 ATH_MSG_VERBOSE("Original parameters before inflation: \n" << secondInitialParameters);
259
260 auto inflatedCovariance = secondInitialParameters.covariance().value();
261 inflatedCovariance *= m_twoWayinflateCovarianceFactor;
262
263 const auto& origSurface = secondInitialParameters.referenceSurface();
264 auto surfacePtr = const_cast<Acts::Surface&>(origSurface).shared_from_this();
265
266 Acts::BoundTrackParameters newParams(
267 std::static_pointer_cast<const Acts::Surface>(std::move(surfacePtr)),
268 secondInitialParameters.parameters(),
269 std::make_optional(inflatedCovariance),
270 secondInitialParameters.particleHypothesis());
271 secondInitialParameters = std::move(newParams);
272
273 ATH_MSG_VERBOSE("Inflated covariance matrix : \n" << secondInitialParameters.covariance().value());
274 }
275
276 auto rootBranch = tracksContainerTemp.makeTrack();
277 rootBranch.copyFromWithoutStates(trackProxy); // #3534
278
279 // perform track finding
280 auto secondResult =
281 trackFinder().ckf.findTracks(secondInitialParameters, options, tracksContainerTemp, rootBranch);
282 if (not secondResult.ok()) {
283 return {};
284 }
285 return secondResult.value();
286 }
287
288 xAOD::UncalibMeasType TrackFindingBaseAlg::measurementType (const detail::RecoTrackContainer::TrackStateProxy &trackState) {
289 if (trackState.hasReferenceSurface()) {
290 if (const auto *actsDetElem = dynamic_cast<const ISurfacePlacement*>(trackState.referenceSurface().surfacePlacement())) {
291 switch (actsDetElem->detectorType()) {
298 default:
299 break;
300 }
301 }
302 }
304 }
305
307 const detail::RecoTrackContainer::TrackProxy &track,
308 const detail::RecoTrackContainer::TrackStateProxy &trackState,
309 const Acts::TrackSelector::EtaBinnedConfig &trackSelectorCfg,
310 const Acts::GeometryContext &tgContext,
311 const detail::MeasurementIndex &measurementIndex,
312 const std::size_t typeIndex,
313 EventStats::value_type &event_stat_category_i) const {
314 if (m_addCounts) {
315 updateCounts(track, trackState.typeFlags(),
316 measurementType(trackState));
317 if (m_checkCounts) {
318 checkCounts(track);
319 }
320 }
321
322 if (m_trackStatePrinter.isSet()) {
323 m_trackStatePrinter->printTrackState(tgContext, trackState,
324 measurementIndex, true);
325 }
326
327 if (!m_doBranchStopper) {
328 return BranchStopperResult::Continue;
329 }
330
331 const auto &parameters = trackState.hasFiltered() ? trackState.filtered()
332 : trackState.predicted();
333 double eta = -std::log(std::tan(0.5 * parameters[Acts::eBoundTheta]));
334 const auto &cutSet = getCuts(eta);
335
336 if (typeIndex < m_ptMinMeasurements.size() &&
337 !(track.nMeasurements() < m_ptMinMeasurements[typeIndex])) {
338 double pT = std::sin(parameters[Acts::eBoundTheta]) /
339 parameters[Acts::eBoundQOverP];
340 if (std::abs(pT) < cutSet.ptMin * m_branchStopperPtMinFactor) {
341 ++event_stat_category_i[kNStoppedTracksMinPt];
342 ATH_MSG_DEBUG("CkfBranchStopper: drop branch with q*pT="
343 << pT << " after " << track.nMeasurements()
344 << " measurements");
345 return BranchStopperResult::StopAndDrop;
346 }
347 }
348
349 if (typeIndex < m_absEtaMaxMeasurements.size() &&
350 !(track.nMeasurements() < m_absEtaMaxMeasurements[typeIndex]) &&
351 !(std::abs(eta) < trackSelectorCfg.absEtaEdges.back() +
353 ++event_stat_category_i[kNStoppedTracksMaxEta];
354 ATH_MSG_DEBUG("CkfBranchStopper: drop branch with eta="
355 << eta << " after " << track.nMeasurements()
356 << " measurements");
357 return BranchStopperResult::StopAndDrop;
358 }
359
360
361 // In the pixel endcap regions relax the requirement for minMeasurements before cutting the branch off
362 auto minMeasurementsBranchStop = std::abs(eta) > m_branchStopperAbsEtaMeasCut ? cutSet.minMeasurements - m_branchStopperMeasCutReduce : cutSet.minMeasurements;
363 bool enoughMeasurements = (track.nMeasurements() >= minMeasurementsBranchStop);
364 bool tooManyHoles = (track.nHoles() > cutSet.maxHoles);
365 bool tooManyOutliers = (track.nOutliers() > cutSet.maxOutliers);
366
367 if (m_addCounts) {
368 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] =
369 selectCounts(track, eta);
370 enoughMeasurements = enoughMeasurements && enoughMeasurementsPS;
371 tooManyHoles = tooManyHoles || tooManyHolesPS;
372 tooManyOutliers = tooManyOutliers || tooManyOutliersPS;
373 }
374
375 if (!(tooManyHoles || tooManyOutliers)) {
376 return BranchStopperResult::Continue;
377 }
378
379 if (!enoughMeasurements) {
380 ++event_stat_category_i[kNStoppedTracksMaxHoles];
381 }
382
383 if (m_addCounts) {
384 ATH_MSG_DEBUG("CkfBranchStopper: stop and "
385 << (enoughMeasurements ? "keep" : "drop")
386 << " branch with nHoles=" << track.nHoles() << " ("
387 << s_branchState.nPixelHoles(track) << " pixel+"
388 << s_branchState.nStripHoles(track) << " strip+"
389 << s_branchState.nHgtdHoles(track)
390 << " hgtd), nOutliers=" << track.nOutliers() << " ("
391 << s_branchState.nPixelOutliers(track) << "+"
392 << s_branchState.nStripOutliers(track) << "+"
393 << s_branchState.nHgtdOutliers(track)
394 << "), nMeasurements=" << track.nMeasurements() << " ("
395 << s_branchState.nPixelHits(track) << "+"
396 << s_branchState.nStripHits(track) << "+"
397 << s_branchState.nHgtdHits(track) << ")");
398 } else {
399 ATH_MSG_DEBUG("CkfBranchStopper: stop and "
400 << (enoughMeasurements ? "keep" : "drop")
401 << " branch with nHoles=" << track.nHoles()
402 << ", nOutliers=" << track.nOutliers()
403 << ", nMeasurements=" << track.nMeasurements());
404 }
405
406 return enoughMeasurements ? BranchStopperResult::StopAndKeep
407 : BranchStopperResult::StopAndDrop;
408 }
409
410
412 {
413 if (addCounts) {
414 tracksContainer.addColumn<unsigned int>("nPixelHits");
415 tracksContainer.addColumn<unsigned int>("nStripHits");
416 tracksContainer.addColumn<unsigned int>("nHgtdHits");
417 tracksContainer.addColumn<unsigned int>("nPixelHoles");
418 tracksContainer.addColumn<unsigned int>("nStripHoles");
419 tracksContainer.addColumn<unsigned int>("nHgtdHoles");
420 tracksContainer.addColumn<unsigned int>("nPixelOutliers");
421 tracksContainer.addColumn<unsigned int>("nStripOutliers");
422 tracksContainer.addColumn<unsigned int>("nHgtdOutliers");
423 }
425 }
426
427 void TrackFindingBaseAlg::initCounts(const detail::RecoTrackContainer::TrackProxy &track)
428 {
429 s_branchState.nPixelHits(track) = 0;
430 s_branchState.nStripHits(track) = 0;
431 s_branchState.nHgtdHits(track) = 0;
432 s_branchState.nPixelHoles(track) = 0;
433 s_branchState.nStripHoles(track) = 0;
434 s_branchState.nHgtdHoles(track) = 0;
435 s_branchState.nPixelOutliers(track) = 0;
436 s_branchState.nStripOutliers(track) = 0;
437 s_branchState.nHgtdOutliers(track) = 0;
438 }
439
441 const detail::RecoTrackContainer::TrackProxy &track,
442 Acts::ConstTrackStateTypeMap typeFlags, xAOD::UncalibMeasType detType) {
444 if (typeFlags.isHole()) {
445 s_branchState.nPixelHoles(track)++;
446 } else if (typeFlags.isOutlier()) {
447 s_branchState.nPixelOutliers(track)++;
448 } else if (typeFlags.isMeasurement()) {
449 s_branchState.nPixelHits(track)++;
450 }
451 } else if (detType == xAOD::UncalibMeasType::StripClusterType) {
452 if (typeFlags.isHole()) {
453 s_branchState.nStripHoles(track)++;
454 } else if (typeFlags.isOutlier()) {
455 s_branchState.nStripOutliers(track)++;
456 } else if (typeFlags.isMeasurement()) {
457 s_branchState.nStripHits(track)++;
458 }
459 } else if (detType == xAOD::UncalibMeasType::HGTDClusterType) {
460 if (typeFlags.isHole()) {
461 s_branchState.nHgtdHoles(track)++;
462 } else if (typeFlags.isOutlier()) {
463 s_branchState.nHgtdOutliers(track)++;
464 } else if (typeFlags.isMeasurement()) {
465 s_branchState.nHgtdHits(track)++;
466 }
467 }
468 }
469
470 void TrackFindingBaseAlg::checkCounts(const detail::RecoTrackContainer::TrackProxy &track) const {
471 // This check will fail if there are other types (HGTD, MS?) of hits, holes, or outliers.
472 // The check can be removed when it is no longer appropriate.
473 if (track.nMeasurements() != s_branchState.nPixelHits(track) + s_branchState.nStripHits(track) + s_branchState.nHgtdHits(track))
474 ATH_MSG_WARNING("mismatched hit count: total (" << track.nMeasurements()
475 << ") != pixel (" << s_branchState.nPixelHits(track)
476 << ") + strip (" << s_branchState.nStripHits(track)
477 << ") + hgtd (" << s_branchState.nHgtdHits(track)
478 << ")");
479 if (track.nHoles() != s_branchState.nPixelHoles(track) + s_branchState.nStripHoles(track) + s_branchState.nHgtdHoles(track))
480 ATH_MSG_WARNING("mismatched hole count: total (" << track.nHoles()
481 << ") < pixel (" << s_branchState.nPixelHoles(track)
482 << ") + strip (" << s_branchState.nStripHoles(track)
483 << ") + hgtd (" << s_branchState.nHgtdHoles(track)
484 << ")");
485 if (track.nOutliers() != s_branchState.nPixelOutliers(track) + s_branchState.nStripOutliers(track) + s_branchState.nHgtdOutliers(track))
486 ATH_MSG_WARNING("mismatched outlier count: total (" << track.nOutliers()
487 << ") != pixel (" << s_branchState.nPixelOutliers(track)
488 << ") + strip (" << s_branchState.nStripOutliers(track)
489 << ") + hgtd (" << s_branchState.nHgtdOutliers(track)
490 << ")");
491 };
492
493 std::array<bool, 3> TrackFindingBaseAlg::selectCounts(const detail::RecoTrackContainer::TrackProxy &track, double eta) const {
494 bool enoughMeasurements = true, tooManyHoles = false, tooManyOutliers = false;
495 const auto &trackSelectorCfg = trackFinder().trackSelector.config();
496 std::size_t etaBin = (std::abs(eta) < trackSelectorCfg.absEtaEdges.front()) ? 0
497 : (std::abs(eta) >= trackSelectorCfg.absEtaEdges.back()) ? trackSelectorCfg.absEtaEdges.size() - 1
498 : trackSelectorCfg.binIndex(eta);
499 auto cutMin = [etaBin](std::size_t val, const std::vector<std::size_t> &cutSet) {
500 return !cutSet.empty() && (val < (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
501 };
502 auto cutMax = [etaBin](std::size_t val, const std::vector<std::size_t> &cutSet) {
503 return !cutSet.empty() && (val > (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
504 };
505
506 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nPixelHits(track), m_minPixelHits);
507 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nStripHits(track), m_minStripHits);
508 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nHgtdHits(track), m_minHgtdHits);
509 tooManyHoles = tooManyHoles || cutMax(s_branchState.nPixelHoles(track), m_maxPixelHoles);
510 tooManyHoles = tooManyHoles || cutMax(s_branchState.nStripHoles(track), m_maxStripHoles);
511 tooManyHoles = tooManyHoles || cutMax(s_branchState.nHgtdHoles(track), m_maxHgtdHoles);
512 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nPixelOutliers(track), m_maxPixelOutliers);
513 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nStripOutliers(track), m_maxStripOutliers);
514 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nHgtdOutliers(track), m_maxHgtdOutliers);
515
516 return {enoughMeasurements, tooManyHoles, tooManyOutliers};
517 }
518
520 std::vector<std::pair<float, float> > &chi2CutOffOutlier = m_measurementSelectorConfig.m_chi2CutOffOutlier;
521 chi2CutOffOutlier .reserve( m_chi2CutOff.size() );
522 if (!m_chi2OutlierCutOff.empty()) {
523 if (m_chi2CutOff.size() != m_chi2OutlierCutOff.size()) {
524 ATH_MSG_ERROR("Outlier chi2 cut off provided but number of elements does not agree with"
525 " chi2 cut off for measurements which however is required: "
526 << m_chi2CutOff.size() << " != " << m_chi2OutlierCutOff.size());
527 return StatusCode::FAILURE;
528 }
529 }
530 unsigned int idx=0;
531 for (const auto &elm : m_chi2CutOff) {
532 chi2CutOffOutlier.push_back( std::make_pair(static_cast<float>(elm),
533 idx < m_chi2OutlierCutOff.size()
534 ? static_cast<float>(m_chi2OutlierCutOff[idx])
535 : std::numeric_limits<float>::max()) );
536 ++idx;
537 }
538 if (m_etaBins.size() > 2) {
539 std::vector<float> &etaBinsf = m_measurementSelectorConfig.m_etaBins;
540 etaBinsf.assign(m_etaBins.begin() + 1, m_etaBins.end() - 1);
541 }
542
543 return /*m_measurementSelector ?*/ StatusCode::SUCCESS /*: StatusCode::FAILURE*/;
544 }
545
546 // === Statistics printout =================================================
547
549 if (!m_statEtaBins.empty())
550 {
552 float last_eta = m_statEtaBins[0];
553 for (float eta : m_statEtaBins)
554 {
555 if (eta < last_eta)
556 {
557 ATH_MSG_FATAL("Eta bins for statistics counter not in ascending order.");
558 }
559 last_eta = eta;
560 }
561 }
562 m_stat.resize(nSeedCollections() * seedCollectionStride());
563 }
564
565 // copy statistics
566 void TrackFindingBaseAlg::copyStats(const EventStats &event_stat) const {
567 std::lock_guard<std::mutex> lock(m_mutex);
568 std::size_t category_i = 0;
569 for (const std::array<unsigned int, kNStat> &src_stat : event_stat)
570 {
571 std::array<std::size_t, kNStat> &dest_stat = m_stat[category_i++];
572 for (std::size_t i = 0; i < src_stat.size(); ++i)
573 {
574 assert(i < dest_stat.size());
575 dest_stat[i] += src_stat[i];
576 }
577 }
578 }
579
580 // print statistics
582 if (msgLvl(MSG::INFO))
583 {
584 std::vector<std::string> stat_labels =
586 {
587 std::make_pair(kNTotalSeeds, "Input seeds"),
588 std::make_pair(kNoTrackParam, "No track parameters"),
589 std::make_pair(kNUsedSeeds, "Used seeds"),
590 std::make_pair(kNoTrack, "Cannot find track"),
591 std::make_pair(kNDuplicateSeeds, "Duplicate seeds"),
592 std::make_pair(kNNoEstimatedParams, "Initial param estimation failed"),
593 std::make_pair(kNRejectedRefinedSeeds, "Rejected refined parameters"),
594 std::make_pair(kNSeedRefitFailure, "Seed refit Kalman fit failure"),
595 std::make_pair(kNOutputTracks, "CKF tracks"),
596 std::make_pair(kNSelectedTracks, "selected tracks"),
597 std::make_pair(kNResolvedTracks, "resolved tracks"),
598 std::make_pair(kNStoppedTracksMaxHoles, "Stopped tracks reaching max holes"),
599 std::make_pair(kMultipleBranches, "Seeds with more than one branch"),
600 std::make_pair(kNoSecond, "Tracks failing second CKF"),
601 std::make_pair(kNStoppedTracksMinPt, "Stopped tracks below pT cut"),
602 std::make_pair(kNStoppedTracksMaxEta, "Stopped tracks above max eta"),
603 std::make_pair(kNTotalSharedHits, "Total shared hits"),
604 std::make_pair(kNForcedSeedMeasurements, "Total forced measurements")
605 });
606 assert(stat_labels.size() == kNStat);
607 std::vector<std::string> categories;
608 categories.reserve(m_seedLabels.size() + 1);
609 categories.insert(categories.end(), m_seedLabels.begin(), m_seedLabels.end());
610 categories.push_back("ALL");
611
612 std::vector<std::string> eta_labels;
613 eta_labels.reserve(m_statEtaBins.size() + 2);
614 for (std::size_t eta_bin_i = 0; eta_bin_i < m_statEtaBins.size() + 2; ++eta_bin_i)
615 {
616 eta_labels.push_back(TableUtils::makeEtaBinLabel(m_statEtaBins, eta_bin_i, m_useAbsEtaForStat));
617 }
618
619 // vector used as 3D array stat[ eta_bin ][ stat_i ][ seed_type]
620 // stat_i = [0, kNStat)
621 // eta_bin = [0, m_statEtaBins.size()+2 ); eta_bin == m_statEtaBinsSize()+1 means sum of all etaBins
622 // seed_type = [0, nSeedCollections()+1) seed_type == nSeedCollections() means sum of all seed collections
623 std::vector<std::size_t> stat =
625 m_statEtaBins.size() + 1,
626 m_stat);
627
628 // the extra columns and rows for the projections are addeded internally:
629 std::size_t stat_stride =
631 m_statEtaBins.size() + 1,
632 kNStat);
633 std::size_t eta_stride =
635 m_statEtaBins.size() + 1,
636 kNStat);
637 std::stringstream table_out;
638
639 if (m_dumpAllStatEtaBins.value())
640 {
641 // dump for each counter a table with one row per eta bin
642 std::size_t max_label_width = TableUtils::maxLabelWidth(stat_labels) + TableUtils::maxLabelWidth(eta_labels);
643 for (std::size_t stat_i = 0; stat_i < kNStat; ++stat_i)
644 {
645 std::size_t dest_idx_offset = stat_i * stat_stride;
646 table_out << makeTable(stat, dest_idx_offset, eta_stride,
647 eta_labels,
648 categories)
649 .columnWidth(10)
650 // only dump the footer for the last eta bin i.e. total
651 .dumpHeader(stat_i == 0)
652 .dumpFooter(stat_i + 1 == kNStat)
653 .separateLastRow(true) // separate the sum of all eta bins
654 .minLabelWidth(max_label_width)
655 .labelPrefix(stat_labels.at(stat_i));
656 }
657 }
658 else
659 {
660 // dump one table with one row per counter showing the total eta range
661 for (std::size_t eta_bin_i = (m_dumpAllStatEtaBins.value() ? 0 : m_statEtaBins.size() + 1);
662 eta_bin_i < m_statEtaBins.size() + 2;
663 ++eta_bin_i)
664 {
665 std::size_t dest_idx_offset = eta_bin_i * eta_stride;
666 table_out << makeTable(stat, dest_idx_offset, stat_stride,
667 stat_labels,
668 categories,
669 eta_labels.at(eta_bin_i))
670 .columnWidth(10)
671 // only dump the footer for the last eta bin i.e. total
672 .dumpFooter(!m_dumpAllStatEtaBins.value() || eta_bin_i == m_statEtaBins.size() + 1);
673 }
674 }
675 ATH_MSG_INFO("statistics:\n"
676 << table_out.str());
677 table_out.str("");
678
679 // define retios first element numerator, second element denominator
680 // each element contains a vector of counter and a multiplier e.g. +- 1
681 // ratios are computed as (sum_i stat[stat_i] * multiplier_i ) / (sum_j stat[stat_j] * multiplier_j )
682 auto [ratio_labels, ratio_def] =
684 std::vector<TableUtils::SummandDefinition>{
688 // no track counted as used but want to include it as failed
690 }, // failed seeds i.e. seeds which are not duplicates but did not produce a track
691 std::vector<TableUtils::SummandDefinition>{TableUtils::defineSummand(kNTotalSeeds, 1)}),
693 TableUtils::defineSimpleRatio("Rejected refined params / seeds", kNRejectedRefinedSeeds, kNTotalSeeds),
695 TableUtils::defineSimpleRatio("selected tracks / used seeds", kNSelectedTracks, kNUsedSeeds),
697 TableUtils::defineSimpleRatio("resolved tracks / used seeds", kNResolvedTracks, kNUsedSeeds),
698 TableUtils::defineSimpleRatio("branched tracks / used seeds", kMultipleBranches, kNUsedSeeds),
699 TableUtils::defineSimpleRatio("no 2nd CKF / CKF tracks", kNoSecond, kNOutputTracks),
701 TableUtils::defineSimpleRatio("forced measurements / used seeds", kNForcedSeedMeasurements, kNUsedSeeds)});
702
703 std::vector<float> ratio = TableUtils::computeRatios(ratio_def,
704 nSeedCollections() + 1,
705 m_statEtaBins.size() + 2,
706 stat);
707
708 // the extra columns and rows for the projections are _not_ added internally
709 std::size_t ratio_stride = TableUtils::ratioStride(nSeedCollections() + 1,
710 m_statEtaBins.size() + 2,
711 ratio_def);
712 std::size_t ratio_eta_stride = TableUtils::subCategoryStride(nSeedCollections() + 1,
713 m_statEtaBins.size() + 2,
714 ratio_def);
715
716 std::size_t max_label_width = TableUtils::maxLabelWidth(ratio_labels) + TableUtils::maxLabelWidth(eta_labels);
717 if (m_dumpAllStatEtaBins.value())
718 {
719 // show for each ratio a table with one row per eta bin
720 for (std::size_t ratio_i = 0; ratio_i < ratio_labels.size(); ++ratio_i)
721 {
722 table_out << makeTable(ratio,
723 ratio_i * ratio_stride,
724 ratio_eta_stride,
725 eta_labels,
726 categories)
727 .columnWidth(10)
728 // only dump the footer for the last eta bin i.e. total
729 .dumpHeader(ratio_i == 0)
730 .dumpFooter(ratio_i + 1 == ratio_labels.size())
731 .separateLastRow(true) // separate the sum of las
732 .minLabelWidth(max_label_width)
733 .labelPrefix(ratio_labels.at(ratio_i));
734 }
735 }
736 else
737 {
738 // dump one table with one row per ratio showing the total eta range
739 table_out << makeTable(ratio,
740 (m_statEtaBins.size() + 1) * ratio_eta_stride + 0 * ratio_stride,
741 ratio_stride,
742 ratio_labels,
743 categories)
744 .columnWidth(10)
745 // only dump the footer for the last eta bin i.e. total
746 .minLabelWidth(max_label_width)
747 .dumpFooter(false);
748
749 // also dump a table for final tracks over used seeds (ratio_i==6 or 4) showing one row per eta bin
750 eta_labels.erase(eta_labels.end() - 1); // drop last line of table which shows again all eta bins summed.
751 std::size_t ratio_i = m_showResolvedStats ? 6 : 4;
752 table_out << makeTable(ratio,
753 ratio_i * ratio_stride,
754 ratio_eta_stride,
755 eta_labels,
756 categories)
757 .columnWidth(10)
758 .dumpHeader(false)
759 // only dump the footer for the last eta bin i.e. total
760 .dumpFooter(!m_dumpAllStatEtaBins.value() || ratio_i + 1 == ratio_labels.size())
761 .separateLastRow(false)
762 .minLabelWidth(max_label_width)
763 .labelPrefix(ratio_labels.at(ratio_i));
764 }
765
766 ATH_MSG_INFO("Ratios:\n"
767 << table_out.str());
768 }
769 }
770
771 std::size_t TrackFindingBaseAlg::getStatCategory(std::size_t seed_collection, float eta) const {
772 std::vector<float>::const_iterator bin_iter = std::upper_bound(m_statEtaBins.begin(),
773 m_statEtaBins.end(),
774 m_useAbsEtaForStat ? std::abs(eta) : eta);
775 std::size_t category_i = seed_collection * seedCollectionStride() + static_cast<std::size_t>(bin_iter - m_statEtaBins.begin());
776 assert(category_i < m_stat.size());
777 return category_i;
778 }
779
780 std::size_t TrackFindingBaseAlg::computeStatSum(std::size_t seed_collection, EStat counter_i, const EventStats &stat) const {
781 std::size_t out = 0u;
782 for (std::size_t category_i = seed_collection * seedCollectionStride();
783 category_i < (seed_collection + 1) * seedCollectionStride();
784 ++category_i)
785 {
786 assert(category_i < stat.size());
787 out += stat[category_i][counter_i];
788 }
789 return out;
790 }
791
792 bool TrackFindingBaseAlg::selectCountsFinal(const detail::RecoTrackContainer::TrackProxy &track) const {
793 if (not m_addCounts) return true;
794 double eta = -std::log(std::tan(0.5 * track.theta()));
795 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] = selectCounts(track, eta);
796 return enoughMeasurementsPS && !tooManyHolesPS && !tooManyOutliersPS;
797 }
798
799} // namespace ActsTrk
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
TableUtils::StatTable< T > makeTable(const std::array< T, N > &counter, const std::array< std::string, N > &label)
Definition TableUtils.h:543
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Extension of the interface of the Acts::SurfacePlacementBase for ATLAS.
Gaudi::Property< std::vector< std::size_t > > m_maxStripHoles
Gaudi::Property< double > m_branchStopperAbsEtaMeasCut
Gaudi::Property< std::vector< float > > m_statEtaBins
Gaudi::Property< double > m_branchStopperPtMinFactor
Gaudi::Property< std::vector< std::size_t > > m_maxOutliers
Gaudi::Property< std::vector< std::size_t > > m_maxHgtdHoles
std::unique_ptr< const Acts::Logger > m_logger
logging instance
Gaudi::Property< std::vector< double > > m_etaBins
Gaudi::Property< bool > m_doTwoWay
Gaudi::Property< bool > m_dumpAllStatEtaBins
Gaudi::Property< std::vector< size_t > > m_numMeasurementsCutOff
Gaudi::Property< std::vector< std::size_t > > m_maxSharedHits
Gaudi::Property< unsigned int > m_maxPropagationStep
static xAOD::UncalibMeasType measurementType(const detail::RecoTrackContainer::TrackStateProxy &trackState)
ToolHandle< ActsTrk::TrackStatePrinterTool > m_trackStatePrinter
Gaudi::Property< double > m_edgeHoleBorderWidth
Gaudi::Property< std::vector< double > > m_etaMax
Gaudi::Property< std::vector< double > > m_ptMin
Gaudi::Property< std::vector< std::size_t > > m_minPixelHits
Gaudi::Property< std::vector< std::size_t > > m_maxStripOutliers
SG::WriteHandleKey< ActsTrk::TrackContainer > m_trackContainerKey
Gaudi::Property< std::vector< double > > m_ptMax
Gaudi::Property< std::vector< double > > m_chi2CutOff
Gaudi::Property< double > m_seedRefitPtMinFactor
detail::RecoTrackContainer::TrackProxy TrkProxy
Gaudi::Property< std::vector< std::size_t > > m_maxPixelHoles
static constexpr BranchState s_branchState
void copyStats(const EventStats &event_stat) const
Gaudi::Property< std::vector< double > > m_phiMin
Gaudi::Property< double > m_branchStopperMeasCutReduce
ToolHandle< ActsTrk::IPixelOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_pixelCalibTool
Gaudi::Property< std::vector< std::uint32_t > > m_endOfWorldVolumeIds
Gaudi::Property< std::vector< std::size_t > > m_minStripHits
ActsTrk::MutableTrackContainerHandlesHelper m_tracksBackendHandlesHelper
std::size_t getStatCategory(std::size_t seed_collection, float eta) const
std::size_t seedCollectionStride() const
Gaudi::Property< double > m_branchStopperAbsEtaMaxExtra
ToolHandle< GenericMonitoringTool > m_monTool
std::vector< typename detail::RecoTrackContainer::TrackProxy > doTwoWayTrackFinding(const detail::RecoTrackStateContainerProxy &firstMeasurement, const TrkProxy &trackProxy, detail::RecoTrackContainer &tracksContainerTemp, const TrackFinderOptions &options) const
Perform two-way track finding.
Gaudi::Property< std::vector< std::size_t > > m_absEtaMaxMeasurements
TrackFindingBaseAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::vector< double > > m_etaMin
Gaudi::Property< std::vector< double > > m_d0Min
virtual StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< std::vector< std::size_t > > m_maxHgtdOutliers
Gaudi::Property< std::vector< double > > m_z0Max
Gaudi::Property< double > m_absEtaMax
std::size_t computeStatSum(std::size_t seed_collection, EStat counter_i, const EventStats &stat) const
virtual StatusCode initialize() override
Gaudi::Property< std::vector< double > > m_z0Min
void checkCounts(const detail::RecoTrackContainer::TrackProxy &track) const
Gaudi::Property< bool > m_doBranchStopper
static void addCountsAndProperties(detail::RecoTrackContainer &tracksContainer, bool add_counts)
Gaudi::Property< std::vector< std::size_t > > m_minMeasurements
Gaudi::Property< std::vector< double > > m_maxChi2
const Acts::Logger & logger() const
Private access to the logger.
Gaudi::Property< double > m_absEtaMin
BranchStopperResult stopBranch(const detail::RecoTrackContainer::TrackProxy &track, const detail::RecoTrackContainer::TrackStateProxy &trackState, const Acts::TrackSelector::EtaBinnedConfig &trackSelectorCfg, const Acts::GeometryContext &tgContext, const detail::MeasurementIndex &measurementIndex, const std::size_t typeIndex, EventStats::value_type &event_stat_category_i) const
Branch stopper.
static void initCounts(const detail::RecoTrackContainer::TrackProxy &track)
Gaudi::Property< std::vector< std::size_t > > m_maxPixelOutliers
const Acts::TrackSelector::Config & getCuts(double eta) const
Retrieves track selector configuration for given eta value.
Gaudi::Property< bool > m_checkCounts
Gaudi::Property< std::vector< std::size_t > > m_maxHoles
ToolHandle< ActsTrk::IStripOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_stripCalibTool
std::array< bool, 3 > selectCounts(const detail::RecoTrackContainer::TrackProxy &track, double eta) const
std::unique_ptr< CKF_pimpl > m_trackFinder
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
TrackFindingDefaultOptions getDefaultOptions(const EventContext &ctx, const DetectorContextHolder &detContext, const detail::TrackFindingMeasurements &measurements, const Acts::PerigeeSurface *pSurface) const
Get CKF options for first and second pass + pointer to MeasurementSelector.
Acts::CombinatorialKalmanFilterOptions< detail::RecoTrackContainer > TrackFinderOptions
virtual StatusCode finalize() override
ContextUtility m_ctxProvider
Utility to fetch the geometry, magnetic field and calibration context in the event.
std::vector< std::array< unsigned int, kNStat > > EventStats
ToolHandle< ActsTrk::IHGTDOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_hgtdCalibTool
detail::xAODUncalibMeasSurfAcc m_unalibMeasSurfAcc
Gaudi::Property< double > m_twoWayinflateCovarianceFactor
static void updateCounts(const detail::RecoTrackContainer::TrackProxy &track, Acts::ConstTrackStateTypeMap typeFlags, xAOD::UncalibMeasType detType)
Gaudi::Property< bool > m_addCounts
Gaudi::Property< std::vector< std::size_t > > m_minHgtdHits
struct ActsTrk::TrackFindingBaseAlg::MeasurementSelectorConfig m_measurementSelectorConfig
Gaudi::Property< std::vector< double > > m_phiMax
Gaudi::Property< std::vector< std::size_t > > m_ptMinMeasurements
Gaudi::Property< std::vector< double > > m_d0Max
ToolHandle< ActsTrk::IFitterTool > m_fitterTool
Gaudi::Property< bool > m_inflateCovarianceTwoWay
Gaudi::Property< std::vector< double > > m_chi2OutlierCutOff
Acts::CombinatorialKalmanFilterBranchStopperResult BranchStopperResult
std::unique_ptr< ActsTrk::IMeasurementSelector > setMeasurementSelector(const EventContext &ctx, const detail::TrackFindingMeasurements &measurements, TrackFinderOptions &options) const
Setup and attach measurement selector to KF options.
bool selectCountsFinal(const detail::RecoTrackContainer::TrackProxy &track) const
Gaudi::Property< std::vector< std::string > > m_seedLabels
const MeasurementRangeList & measurementRanges() const
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
Acts::Result< void > gainMatrixUpdate(const Acts::GeometryContext &gctx, typename trajectory_t::TrackStateProxy trackState, const Acts::Logger &logger)
Acts::SympyStepper Stepper
Adapted from Acts Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithmFunction....
RecoTrackStateContainer::TrackStateProxy RecoTrackStateContainerProxy
std::unique_ptr< ActsTrk::IMeasurementSelector > getMeasurementSelector(const EventContext &ctx, const ActsTrk::IPixelOnTrackCalibratorTool< detail::RecoTrackStateContainer > *pixelOnTrackCalibratorTool, const ActsTrk::IStripOnTrackCalibratorTool< detail::RecoTrackStateContainer > *stripOnTrackCalibratorTool, const ActsTrk::IHGTDOnTrackCalibratorTool< detail::RecoTrackStateContainer > *hgtdOnTrackCalibratorTool, const ActsTrk::detail::MeasurementRangeList &measurementRanges, const std::vector< float > &etaBinsf, const std::vector< std::pair< float, float > > &chi2CutOffOutlier, const std::vector< size_t > &numMeasurementsCutOff, double edge_hole_border_width)
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
RecoTrackStateContainer::ConstTrackStateProxy RecoConstTrackStateContainerProxy
Acts::CombinatorialKalmanFilter< Propagator, RecoTrackContainer > CKF
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string prefixFromTrackContainerName(const std::string &tracks)
Parse TrackContainer name to get the prefix for backends The name has to contain XYZTracks,...
@ Pixel
Inner detector legacy.
std::tuple< std::vector< std::string >, std::vector< RatioDefinition > > splitRatioDefinitionsAndLabels(std::initializer_list< std::tuple< std::string, RatioDefinition > > a_ratio_list)
Definition TableUtils.h:468
SummandDefinition defineSummand(T counter_idx, int multiplier)
Definition TableUtils.h:422
std::size_t maxLabelWidth(const T_Collection &col)
Definition TableUtils.h:310
RatioDefinition defineSimpleRatio(T numerator, T denominator)
Definition TableUtils.h:404
std::vector< std::string > makeLabelVector(T_index n_entries, std::initializer_list< std::pair< T_index, T_string > > a_list)
Definition TableUtils.h:295
constexpr std::size_t subCategoryStride(const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
Definition TableUtils.h:324
constexpr std::size_t counterStride(const std::size_t categories, const std::size_t sub_categories, const std::size_t n_counter)
Definition TableUtils.h:329
std::string makeEtaBinLabel(const std::vector< float > &eta_bins, std::size_t eta_bin_i, bool abs_eta=false)
Definition TableUtils.h:534
std::tuple< std::string, RatioDefinition > makeRatioDefinition(std::string &&name, std::vector< SummandDefinition > &&numerator, std::vector< SummandDefinition > &&denominator)
Definition TableUtils.h:458
std::vector< float > computeRatios(const std::vector< RatioDefinition > &ratio_def, const std::size_t categories, const std::size_t sub_categories, const std::vector< std::size_t > &counter)
constexpr std::size_t ratioStride(const std::size_t categories, const std::size_t sub_categories, const std::vector< RatioDefinition > &ratio_def)
Definition TableUtils.h:493
std::vector< T_Output > createCounterArrayWithProjections(const std::size_t categories, const std::size_t sub_categories, const std::vector< std::array< T_Input, N > > &input_counts)
Definition TableUtils.h:342
UncalibMeasType
Define the type of the uncalibrated measurement.
static void addFitterTypeProperty(track_container_t &tracksContainer)
add fitter column to the track container
Acts::CombinatorialKalmanFilterExtensions< RecoTrackContainer > ckfExtensions