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
16namespace ActsTrk {
18
21
22 TrackFindingBaseAlg::TrackFindingBaseAlg(const std::string &name, ISvcLocator *pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
23
25
27 ATH_MSG_DEBUG("Properties Summary:");
39 ATH_MSG_DEBUG(" " << m_phiMin);
40 ATH_MSG_DEBUG(" " << m_phiMax);
41 ATH_MSG_DEBUG(" " << m_etaMin);
42 ATH_MSG_DEBUG(" " << m_etaMax);
45 ATH_MSG_DEBUG(" " << m_ptMin);
46 ATH_MSG_DEBUG(" " << m_ptMax);
47 ATH_MSG_DEBUG(" " << m_d0Min);
48 ATH_MSG_DEBUG(" " << m_d0Max);
49 ATH_MSG_DEBUG(" " << m_z0Min);
50 ATH_MSG_DEBUG(" " << m_z0Max);
67
68 m_logger = makeActsAthenaLogger(this, "Acts");
69
70 // Read and Write handles
71 ATH_CHECK(m_trackContainerKey.initialize());
73
74 ATH_CHECK(m_monTool.retrieve(EnableTool{not m_monTool.empty()}));
77 ATH_CHECK(m_trackStatePrinter.retrieve(EnableTool{not m_trackStatePrinter.empty()}));
79 ATH_CHECK(m_fitterTool.retrieve());
80 ATH_CHECK(m_pixelCalibTool.retrieve(EnableTool{not m_pixelCalibTool.empty()}));
81 ATH_CHECK(m_stripCalibTool.retrieve(EnableTool{not m_stripCalibTool.empty()}));
82 ATH_CHECK(m_hgtdCalibTool.retrieve(EnableTool{not m_hgtdCalibTool.empty()}));
83
84 auto magneticField = std::make_unique<ATLASMagneticFieldWrapper>();
85 auto trackingGeometry = m_trackingGeometryTool->trackingGeometry();
86
87 detail::Stepper stepper(std::move(magneticField));
88 detail::Navigator::Config config{trackingGeometry};
89 config.resolvePassive = false;
90 config.resolveMaterial = true;
91 config.resolveSensitive = true;
92 detail::Navigator navigator(config, logger().cloneWithSuffix("Navigator"));
93 detail::Propagator propagator(std::move(stepper), std::move(navigator), logger().cloneWithSuffix("Prop"));
94
95 // Using the CKF propagator as extrapolator
96 detail::Extrapolator extrapolator = propagator;
97
98 // m_etaBins (from flags.Tracking.ActiveConfig.etaBins) includes a dummy first and last bin, which we ignore
99 std::vector<double> absEtaEdges;
100 if (m_etaBins.size() <= 2)
101 {
102 absEtaEdges.reserve(2ul);
103 absEtaEdges.push_back(0.0);
104 absEtaEdges.push_back(std::numeric_limits<double>::infinity());
105 }
106 else
107 {
108 absEtaEdges.reserve(m_etaBins.size());
109 absEtaEdges.push_back(m_absEtaMin);
110 absEtaEdges.insert(absEtaEdges.end(), m_etaBins.begin() + 1, m_etaBins.end() - 1);
111 absEtaEdges.push_back(m_absEtaMax);
112 }
113
114 auto setCut = [](auto &cfgVal, const auto &cuts, size_t ind) -> void
115 {
116 if (cuts.empty())
117 return;
118 cfgVal = (ind < cuts.size()) ? cuts[ind] : cuts[cuts.size() - 1];
119 };
120
121 Acts::TrackSelector::EtaBinnedConfig trackSelectorCfg{std::move(absEtaEdges)};
122 if (m_etaBins.size() <= 2)
123 {
124 assert(trackSelectorCfg.cutSets.size() == 1);
125 trackSelectorCfg.cutSets[0].absEtaMin = m_absEtaMin;
126 trackSelectorCfg.cutSets[0].absEtaMax = m_absEtaMax;
127 }
128 size_t cutIndex = 0;
129 for (auto &cfg : trackSelectorCfg.cutSets)
130 {
131 setCut(cfg.phiMin, m_phiMin, cutIndex);
132 setCut(cfg.phiMax, m_phiMax, cutIndex);
133 setCut(cfg.etaMin, m_etaMin, cutIndex);
134 setCut(cfg.etaMax, m_etaMax, cutIndex);
135 setCut(cfg.ptMin, m_ptMin, cutIndex);
136 setCut(cfg.ptMax, m_ptMax, cutIndex);
137 setCut(cfg.loc0Min, m_d0Min, cutIndex);
138 setCut(cfg.loc0Max, m_d0Max, cutIndex);
139 setCut(cfg.loc1Min, m_z0Min, cutIndex);
140 setCut(cfg.loc1Max, m_z0Max, cutIndex);
141 setCut(cfg.minMeasurements, m_minMeasurements, cutIndex);
142 setCut(cfg.maxHoles, m_maxHoles, cutIndex);
143 setCut(cfg.maxOutliers, m_maxOutliers, cutIndex);
144 setCut(cfg.maxSharedHits, m_maxSharedHits, cutIndex);
145 setCut(cfg.maxChi2, m_maxChi2, cutIndex);
146 ++cutIndex;
147 }
148
149 ATH_MSG_DEBUG(trackSelectorCfg);
150
151 // initializer measurement selector and connect it to the delegates of the track finder optins
153
154 detail::CKF_config ckfConfig{
155 std::move(extrapolator),
156 detail::CKF{std::move(propagator), logger().cloneWithSuffix("CKF")},
157 {},
158 Acts::TrackSelector{trackSelectorCfg}};
159
160 m_trackFinder = std::make_unique<CKF_pimpl>(std::move(ckfConfig));
161
163
165
167
168 return StatusCode::SUCCESS;
169 }
170
171 StatusCode TrackFindingBaseAlg::execute(const EventContext &) const {
172 ATH_MSG_FATAL("execute() method from the base class was called! Implement proper execute() method in the derived class!");
173
174 return StatusCode::FAILURE;
175 }
176
179
180 return StatusCode::SUCCESS;
181 }
182
183 std::unique_ptr<ActsTrk::IMeasurementSelector> TrackFindingBaseAlg::setMeasurementSelector(
184 const EventContext &ctx,
185 const detail::TrackFindingMeasurements &measurements,
186 TrackFinderOptions &options) const {
187
188 std::unique_ptr<ActsTrk::IMeasurementSelector> measurementSelector = ActsTrk::detail::getMeasurementSelector(
189 ctx,
190 m_pixelCalibTool.isEnabled() ? &(*m_pixelCalibTool) : nullptr,
191 m_stripCalibTool.isEnabled() ? &(*m_stripCalibTool) : nullptr,
192 m_hgtdCalibTool.isEnabled() ? &(*m_hgtdCalibTool) : nullptr,
193 measurements.measurementRanges(),
195 m_measurementSelectorConfig.m_chi2CutOffOutlier,
197 m_edgeHoleBorderWidth.value());
198
199 measurementSelector->connect(&options.extensions.createTrackStates);
200
201 return measurementSelector;
202 }
203
205 const EventContext &ctx,
206 const DetectorContextHolder &detContext,
207 const detail::TrackFindingMeasurements &measurements,
208 const Acts::PerigeeSurface* pSurface) const {
209 Acts::PropagatorPlainOptions plainOptions{detContext.geometry, detContext.magField};
210 plainOptions.maxSteps = m_maxPropagationStep;
211 plainOptions.direction = Acts::Direction::Forward();
212 plainOptions.endOfWorldVolumeIds = m_endOfWorldVolumeIds;
213
214 // Set the CombinatorialKalmanFilter options
215 TrackFinderOptions options(detContext.geometry, detContext.magField, detContext.calib,
216 trackFinder().ckfExtensions, plainOptions, pSurface);
217
218 std::unique_ptr<ActsTrk::IMeasurementSelector> measurementSelector = setMeasurementSelector(ctx, measurements, options);
219
220 Acts::PropagatorPlainOptions plainSecondOptions{detContext.geometry, detContext.magField};
221 plainSecondOptions.maxSteps = m_maxPropagationStep;
222 plainSecondOptions.direction = plainOptions.direction.invert();
223
224 TrackFinderOptions secondOptions(detContext.geometry, detContext.magField, detContext.calib,
225 options.extensions, plainSecondOptions, pSurface);
226 secondOptions.targetSurface = pSurface;
227 secondOptions.skipPrePropagationUpdate = true;
228
229 return {std::move(options), std::move(secondOptions), std::move(measurementSelector)};
230 };
231
232 const Acts::TrackSelector::Config& TrackFindingBaseAlg::getCuts (double eta) const {
233 const auto &trackSelectorCfg = trackFinder().trackSelector.config();
234 // return the last bin for |eta|>=4 or nan
235 return (!(std::abs(eta) < trackSelectorCfg.absEtaEdges.back())) ? trackSelectorCfg.cutSets.back()
236 : (std::abs(eta) < trackSelectorCfg.absEtaEdges.front()) ? trackSelectorCfg.cutSets.front()
237 : trackSelectorCfg.getCuts(eta);
238 };
239
240 std::vector<typename detail::RecoTrackContainer::TrackProxy>
242 const TrkProxy &trackProxy,
243 detail::RecoTrackContainer &tracksContainerTemp,
244 const TrackFinderOptions &options) const {
245 if (not m_doTwoWay) return {};
246
247 // Create initial parameters for the propagation
248 Acts::BoundTrackParameters secondInitialParameters = trackProxy.createParametersFromState(detail::RecoConstTrackStateContainerProxy{firstMeasurement});
249 if (!secondInitialParameters.referenceSurface().insideBounds(secondInitialParameters.localPosition())) { // #3751
250 return {};
251 }
252
253 auto rootBranch = tracksContainerTemp.makeTrack();
254 rootBranch.copyFromWithoutStates(trackProxy); // #3534
255
256 // perform track finding
257 auto secondResult =
258 trackFinder().ckf.findTracks(secondInitialParameters, options, tracksContainerTemp, rootBranch);
259 if (not secondResult.ok()) {
260 return {};
261 }
262 return secondResult.value();
263 }
264
265 xAOD::UncalibMeasType TrackFindingBaseAlg::measurementType (const detail::RecoTrackContainer::TrackStateProxy &trackState) {
266 if (trackState.hasReferenceSurface()) {
267 if (const auto *actsDetElem = dynamic_cast<const IDetectorElementBase *>(trackState.referenceSurface().surfacePlacement())) {
268 switch (actsDetElem->detectorType()) {
275 default:
276 break;
277 }
278 }
279 }
281 }
282
284 const detail::RecoTrackContainer::TrackProxy &track,
285 const detail::RecoTrackContainer::TrackStateProxy &trackState,
286 const Acts::TrackSelector::EtaBinnedConfig &trackSelectorCfg,
287 const Acts::GeometryContext &tgContext,
288 const detail::MeasurementIndex &measurementIndex,
289 const std::size_t typeIndex,
290 EventStats::value_type &event_stat_category_i) const {
291 if (m_addCounts) {
292 updateCounts(track, trackState.typeFlags(),
293 measurementType(trackState));
294 if (m_checkCounts) {
295 checkCounts(track);
296 }
297 }
298
299 if (m_trackStatePrinter.isSet()) {
300 m_trackStatePrinter->printTrackState(tgContext, trackState,
301 measurementIndex, true);
302 }
303
304 if (!m_doBranchStopper) {
305 return BranchStopperResult::Continue;
306 }
307
308 const auto &parameters = trackState.hasFiltered() ? trackState.filtered()
309 : trackState.predicted();
310 double eta = -std::log(std::tan(0.5 * parameters[Acts::eBoundTheta]));
311 const auto &cutSet = getCuts(eta);
312
313 if (typeIndex < m_ptMinMeasurements.size() &&
314 !(track.nMeasurements() < m_ptMinMeasurements[typeIndex])) {
315 double pT = std::sin(parameters[Acts::eBoundTheta]) /
316 parameters[Acts::eBoundQOverP];
317 if (std::abs(pT) < cutSet.ptMin * m_branchStopperPtMinFactor) {
318 ++event_stat_category_i[kNStoppedTracksMinPt];
319 ATH_MSG_DEBUG("CkfBranchStopper: drop branch with q*pT="
320 << pT << " after " << track.nMeasurements()
321 << " measurements");
322 return BranchStopperResult::StopAndDrop;
323 }
324 }
325
326 if (typeIndex < m_absEtaMaxMeasurements.size() &&
327 !(track.nMeasurements() < m_absEtaMaxMeasurements[typeIndex]) &&
328 !(std::abs(eta) < trackSelectorCfg.absEtaEdges.back() +
330 ++event_stat_category_i[kNStoppedTracksMaxEta];
331 ATH_MSG_DEBUG("CkfBranchStopper: drop branch with eta="
332 << eta << " after " << track.nMeasurements()
333 << " measurements");
334 return BranchStopperResult::StopAndDrop;
335 }
336
337
338 // In the pixel endcap regions relax the requirement for minMeasurements before cutting the branch off
339 auto minMeasurementsBranchStop = std::abs(eta) > m_branchStopperAbsEtaMeasCut ? cutSet.minMeasurements - m_branchStopperMeasCutReduce : cutSet.minMeasurements;
340 bool enoughMeasurements = (track.nMeasurements() >= minMeasurementsBranchStop);
341 bool tooManyHoles = (track.nHoles() > cutSet.maxHoles);
342 bool tooManyOutliers = (track.nOutliers() > cutSet.maxOutliers);
343
344 if (m_addCounts) {
345 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] =
346 selectCounts(track, eta);
347 enoughMeasurements = enoughMeasurements && enoughMeasurementsPS;
348 tooManyHoles = tooManyHoles || tooManyHolesPS;
349 tooManyOutliers = tooManyOutliers || tooManyOutliersPS;
350 }
351
352 if (!(tooManyHoles || tooManyOutliers)) {
353 return BranchStopperResult::Continue;
354 }
355
356 if (!enoughMeasurements) {
357 ++event_stat_category_i[kNStoppedTracksMaxHoles];
358 }
359
360 if (m_addCounts) {
361 ATH_MSG_DEBUG("CkfBranchStopper: stop and "
362 << (enoughMeasurements ? "keep" : "drop")
363 << " branch with nHoles=" << track.nHoles() << " ("
364 << s_branchState.nPixelHoles(track) << " pixel+"
365 << s_branchState.nStripHoles(track) << " strip+"
366 << s_branchState.nHgtdHoles(track)
367 << " hgtd), nOutliers=" << track.nOutliers() << " ("
368 << s_branchState.nPixelOutliers(track) << "+"
369 << s_branchState.nStripOutliers(track) << "+"
370 << s_branchState.nHgtdOutliers(track)
371 << "), nMeasurements=" << track.nMeasurements() << " ("
372 << s_branchState.nPixelHits(track) << "+"
373 << s_branchState.nStripHits(track) << "+"
374 << s_branchState.nHgtdHits(track) << ")");
375 } else {
376 ATH_MSG_DEBUG("CkfBranchStopper: stop and "
377 << (enoughMeasurements ? "keep" : "drop")
378 << " branch with nHoles=" << track.nHoles()
379 << ", nOutliers=" << track.nOutliers()
380 << ", nMeasurements=" << track.nMeasurements());
381 }
382
383 return enoughMeasurements ? BranchStopperResult::StopAndKeep
384 : BranchStopperResult::StopAndDrop;
385 }
386
387
389 {
390 tracksContainer.addColumn<unsigned int>("nPixelHits");
391 tracksContainer.addColumn<unsigned int>("nStripHits");
392 tracksContainer.addColumn<unsigned int>("nHgtdHits");
393 tracksContainer.addColumn<unsigned int>("nPixelHoles");
394 tracksContainer.addColumn<unsigned int>("nStripHoles");
395 tracksContainer.addColumn<unsigned int>("nHgtdHoles");
396 tracksContainer.addColumn<unsigned int>("nPixelOutliers");
397 tracksContainer.addColumn<unsigned int>("nStripOutliers");
398 tracksContainer.addColumn<unsigned int>("nHgtdOutliers");
399 }
400
401 void TrackFindingBaseAlg::initCounts(const detail::RecoTrackContainer::TrackProxy &track)
402 {
403 s_branchState.nPixelHits(track) = 0;
404 s_branchState.nStripHits(track) = 0;
405 s_branchState.nHgtdHits(track) = 0;
406 s_branchState.nPixelHoles(track) = 0;
407 s_branchState.nStripHoles(track) = 0;
408 s_branchState.nHgtdHoles(track) = 0;
409 s_branchState.nPixelOutliers(track) = 0;
410 s_branchState.nStripOutliers(track) = 0;
411 s_branchState.nHgtdOutliers(track) = 0;
412 }
413
415 const detail::RecoTrackContainer::TrackProxy &track,
416 Acts::ConstTrackStateTypeMap typeFlags, xAOD::UncalibMeasType detType) {
418 if (typeFlags.isHole()) {
419 s_branchState.nPixelHoles(track)++;
420 } else if (typeFlags.isOutlier()) {
421 s_branchState.nPixelOutliers(track)++;
422 } else if (typeFlags.isMeasurement()) {
423 s_branchState.nPixelHits(track)++;
424 }
425 } else if (detType == xAOD::UncalibMeasType::StripClusterType) {
426 if (typeFlags.isHole()) {
427 s_branchState.nStripHoles(track)++;
428 } else if (typeFlags.isOutlier()) {
429 s_branchState.nStripOutliers(track)++;
430 } else if (typeFlags.isMeasurement()) {
431 s_branchState.nStripHits(track)++;
432 }
433 } else if (detType == xAOD::UncalibMeasType::HGTDClusterType) {
434 if (typeFlags.isHole()) {
435 s_branchState.nHgtdHoles(track)++;
436 } else if (typeFlags.isOutlier()) {
437 s_branchState.nHgtdOutliers(track)++;
438 } else if (typeFlags.isMeasurement()) {
439 s_branchState.nHgtdHits(track)++;
440 }
441 }
442 }
443
444 void TrackFindingBaseAlg::checkCounts(const detail::RecoTrackContainer::TrackProxy &track) const {
445 // This check will fail if there are other types (HGTD, MS?) of hits, holes, or outliers.
446 // The check can be removed when it is no longer appropriate.
447 if (track.nMeasurements() != s_branchState.nPixelHits(track) + s_branchState.nStripHits(track) + s_branchState.nHgtdHits(track))
448 ATH_MSG_WARNING("mismatched hit count: total (" << track.nMeasurements()
449 << ") != pixel (" << s_branchState.nPixelHits(track)
450 << ") + strip (" << s_branchState.nStripHits(track)
451 << ") + hgtd (" << s_branchState.nHgtdHits(track)
452 << ")");
453 if (track.nHoles() != s_branchState.nPixelHoles(track) + s_branchState.nStripHoles(track) + s_branchState.nHgtdHoles(track))
454 ATH_MSG_WARNING("mismatched hole count: total (" << track.nHoles()
455 << ") < pixel (" << s_branchState.nPixelHoles(track)
456 << ") + strip (" << s_branchState.nStripHoles(track)
457 << ") + hgtd (" << s_branchState.nHgtdHoles(track)
458 << ")");
459 if (track.nOutliers() != s_branchState.nPixelOutliers(track) + s_branchState.nStripOutliers(track) + s_branchState.nHgtdOutliers(track))
460 ATH_MSG_WARNING("mismatched outlier count: total (" << track.nOutliers()
461 << ") != pixel (" << s_branchState.nPixelOutliers(track)
462 << ") + strip (" << s_branchState.nStripOutliers(track)
463 << ") + hgtd (" << s_branchState.nHgtdOutliers(track)
464 << ")");
465 };
466
467 std::array<bool, 3> TrackFindingBaseAlg::selectCounts(const detail::RecoTrackContainer::TrackProxy &track, double eta) const {
468 bool enoughMeasurements = true, tooManyHoles = false, tooManyOutliers = false;
469 const auto &trackSelectorCfg = trackFinder().trackSelector.config();
470 std::size_t etaBin = (std::abs(eta) < trackSelectorCfg.absEtaEdges.front()) ? 0
471 : (std::abs(eta) >= trackSelectorCfg.absEtaEdges.back()) ? trackSelectorCfg.absEtaEdges.size() - 1
472 : trackSelectorCfg.binIndex(eta);
473 auto cutMin = [etaBin](std::size_t val, const std::vector<std::size_t> &cutSet) {
474 return !cutSet.empty() && (val < (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
475 };
476 auto cutMax = [etaBin](std::size_t val, const std::vector<std::size_t> &cutSet) {
477 return !cutSet.empty() && (val > (etaBin < cutSet.size() ? cutSet[etaBin] : cutSet.back()));
478 };
479
480 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nPixelHits(track), m_minPixelHits);
481 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nStripHits(track), m_minStripHits);
482 enoughMeasurements = enoughMeasurements && !cutMin(s_branchState.nHgtdHits(track), m_minHgtdHits);
483 tooManyHoles = tooManyHoles || cutMax(s_branchState.nPixelHoles(track), m_maxPixelHoles);
484 tooManyHoles = tooManyHoles || cutMax(s_branchState.nStripHoles(track), m_maxStripHoles);
485 tooManyHoles = tooManyHoles || cutMax(s_branchState.nHgtdHoles(track), m_maxHgtdHoles);
486 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nPixelOutliers(track), m_maxPixelOutliers);
487 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nStripOutliers(track), m_maxStripOutliers);
488 tooManyOutliers = tooManyOutliers || cutMax(s_branchState.nHgtdOutliers(track), m_maxHgtdOutliers);
489
490 return {enoughMeasurements, tooManyHoles, tooManyOutliers};
491 }
492
494 std::vector<std::pair<float, float> > &chi2CutOffOutlier = m_measurementSelectorConfig.m_chi2CutOffOutlier;
495 chi2CutOffOutlier .reserve( m_chi2CutOff.size() );
496 if (!m_chi2OutlierCutOff.empty()) {
497 if (m_chi2CutOff.size() != m_chi2OutlierCutOff.size()) {
498 ATH_MSG_ERROR("Outlier chi2 cut off provided but number of elements does not agree with"
499 " chi2 cut off for measurements which however is required: "
500 << m_chi2CutOff.size() << " != " << m_chi2OutlierCutOff.size());
501 return StatusCode::FAILURE;
502 }
503 }
504 unsigned int idx=0;
505 for (const auto &elm : m_chi2CutOff) {
506 chi2CutOffOutlier.push_back( std::make_pair(static_cast<float>(elm),
507 idx < m_chi2OutlierCutOff.size()
508 ? static_cast<float>(m_chi2OutlierCutOff[idx])
509 : std::numeric_limits<float>::max()) );
510 ++idx;
511 }
512 if (m_etaBins.size() > 2) {
513 std::vector<float> &etaBinsf = m_measurementSelectorConfig.m_etaBins;
514 etaBinsf.assign(m_etaBins.begin() + 1, m_etaBins.end() - 1);
515 }
516
517 return /*m_measurementSelector ?*/ StatusCode::SUCCESS /*: StatusCode::FAILURE*/;
518 }
519
520 // === Statistics printout =================================================
521
523 if (!m_statEtaBins.empty())
524 {
526 float last_eta = m_statEtaBins[0];
527 for (float eta : m_statEtaBins)
528 {
529 if (eta < last_eta)
530 {
531 ATH_MSG_FATAL("Eta bins for statistics counter not in ascending order.");
532 }
533 last_eta = eta;
534 }
535 }
536 m_stat.resize(nSeedCollections() * seedCollectionStride());
537 }
538
539 // copy statistics
540 void TrackFindingBaseAlg::copyStats(const EventStats &event_stat) const {
541 std::lock_guard<std::mutex> lock(m_mutex);
542 std::size_t category_i = 0;
543 for (const std::array<unsigned int, kNStat> &src_stat : event_stat)
544 {
545 std::array<std::size_t, kNStat> &dest_stat = m_stat[category_i++];
546 for (std::size_t i = 0; i < src_stat.size(); ++i)
547 {
548 assert(i < dest_stat.size());
549 dest_stat[i] += src_stat[i];
550 }
551 }
552 }
553
554 // print statistics
556 if (msgLvl(MSG::INFO))
557 {
558 std::vector<std::string> stat_labels =
560 {
561 std::make_pair(kNTotalSeeds, "Input seeds"),
562 std::make_pair(kNoTrackParam, "No track parameters"),
563 std::make_pair(kNUsedSeeds, "Used seeds"),
564 std::make_pair(kNoTrack, "Cannot find track"),
565 std::make_pair(kNDuplicateSeeds, "Duplicate seeds"),
566 std::make_pair(kNNoEstimatedParams, "Initial param estimation failed"),
567 std::make_pair(kNRejectedRefinedSeeds, "Rejected refined parameters"),
568 std::make_pair(kNOutputTracks, "CKF tracks"),
569 std::make_pair(kNSelectedTracks, "selected tracks"),
570 std::make_pair(kNResolvedTracks, "resolved tracks"),
571 std::make_pair(kNStoppedTracksMaxHoles, "Stopped tracks reaching max holes"),
572 std::make_pair(kMultipleBranches, "Seeds with more than one branch"),
573 std::make_pair(kNoSecond, "Tracks failing second CKF"),
574 std::make_pair(kNStoppedTracksMinPt, "Stopped tracks below pT cut"),
575 std::make_pair(kNStoppedTracksMaxEta, "Stopped tracks above max eta"),
576 std::make_pair(kNTotalSharedHits, "Total shared hits"),
577 std::make_pair(kNForcedSeedMeasurements, "Total forced measurements")
578 });
579 assert(stat_labels.size() == kNStat);
580 std::vector<std::string> categories;
581 categories.reserve(m_seedLabels.size() + 1);
582 categories.insert(categories.end(), m_seedLabels.begin(), m_seedLabels.end());
583 categories.push_back("ALL");
584
585 std::vector<std::string> eta_labels;
586 eta_labels.reserve(m_statEtaBins.size() + 2);
587 for (std::size_t eta_bin_i = 0; eta_bin_i < m_statEtaBins.size() + 2; ++eta_bin_i)
588 {
589 eta_labels.push_back(TableUtils::makeEtaBinLabel(m_statEtaBins, eta_bin_i, m_useAbsEtaForStat));
590 }
591
592 // vector used as 3D array stat[ eta_bin ][ stat_i ][ seed_type]
593 // stat_i = [0, kNStat)
594 // eta_bin = [0, m_statEtaBins.size()+2 ); eta_bin == m_statEtaBinsSize()+1 means sum of all etaBins
595 // seed_type = [0, nSeedCollections()+1) seed_type == nSeedCollections() means sum of all seed collections
596 std::vector<std::size_t> stat =
598 m_statEtaBins.size() + 1,
599 m_stat);
600
601 // the extra columns and rows for the projections are addeded internally:
602 std::size_t stat_stride =
604 m_statEtaBins.size() + 1,
605 kNStat);
606 std::size_t eta_stride =
608 m_statEtaBins.size() + 1,
609 kNStat);
610 std::stringstream table_out;
611
612 if (m_dumpAllStatEtaBins.value())
613 {
614 // dump for each counter a table with one row per eta bin
615 std::size_t max_label_width = TableUtils::maxLabelWidth(stat_labels) + TableUtils::maxLabelWidth(eta_labels);
616 for (std::size_t stat_i = 0; stat_i < kNStat; ++stat_i)
617 {
618 std::size_t dest_idx_offset = stat_i * stat_stride;
619 table_out << makeTable(stat, dest_idx_offset, eta_stride,
620 eta_labels,
621 categories)
622 .columnWidth(10)
623 // only dump the footer for the last eta bin i.e. total
624 .dumpHeader(stat_i == 0)
625 .dumpFooter(stat_i + 1 == kNStat)
626 .separateLastRow(true) // separate the sum of all eta bins
627 .minLabelWidth(max_label_width)
628 .labelPrefix(stat_labels.at(stat_i));
629 }
630 }
631 else
632 {
633 // dump one table with one row per counter showing the total eta range
634 for (std::size_t eta_bin_i = (m_dumpAllStatEtaBins.value() ? 0 : m_statEtaBins.size() + 1);
635 eta_bin_i < m_statEtaBins.size() + 2;
636 ++eta_bin_i)
637 {
638 std::size_t dest_idx_offset = eta_bin_i * eta_stride;
639 table_out << makeTable(stat, dest_idx_offset, stat_stride,
640 stat_labels,
641 categories,
642 eta_labels.at(eta_bin_i))
643 .columnWidth(10)
644 // only dump the footer for the last eta bin i.e. total
645 .dumpFooter(!m_dumpAllStatEtaBins.value() || eta_bin_i == m_statEtaBins.size() + 1);
646 }
647 }
648 ATH_MSG_INFO("statistics:\n"
649 << table_out.str());
650 table_out.str("");
651
652 // define retios first element numerator, second element denominator
653 // each element contains a vector of counter and a multiplier e.g. +- 1
654 // ratios are computed as (sum_i stat[stat_i] * multiplier_i ) / (sum_j stat[stat_j] * multiplier_j )
655 auto [ratio_labels, ratio_def] =
657 std::vector<TableUtils::SummandDefinition>{
661 // no track counted as used but want to include it as failed
663 }, // failed seeds i.e. seeds which are not duplicates but did not produce a track
664 std::vector<TableUtils::SummandDefinition>{TableUtils::defineSummand(kNTotalSeeds, 1)}),
666 TableUtils::defineSimpleRatio("Rejected refined params / seeds", kNRejectedRefinedSeeds, kNTotalSeeds),
668 TableUtils::defineSimpleRatio("selected tracks / used seeds", kNSelectedTracks, kNUsedSeeds),
670 TableUtils::defineSimpleRatio("resolved tracks / used seeds", kNResolvedTracks, kNUsedSeeds),
671 TableUtils::defineSimpleRatio("branched tracks / used seeds", kMultipleBranches, kNUsedSeeds),
672 TableUtils::defineSimpleRatio("no 2nd CKF / CKF tracks", kNoSecond, kNOutputTracks),
674 TableUtils::defineSimpleRatio("forced measurements / used seeds", kNForcedSeedMeasurements, kNUsedSeeds)});
675
676 std::vector<float> ratio = TableUtils::computeRatios(ratio_def,
677 nSeedCollections() + 1,
678 m_statEtaBins.size() + 2,
679 stat);
680
681 // the extra columns and rows for the projections are _not_ added internally
682 std::size_t ratio_stride = TableUtils::ratioStride(nSeedCollections() + 1,
683 m_statEtaBins.size() + 2,
684 ratio_def);
685 std::size_t ratio_eta_stride = TableUtils::subCategoryStride(nSeedCollections() + 1,
686 m_statEtaBins.size() + 2,
687 ratio_def);
688
689 std::size_t max_label_width = TableUtils::maxLabelWidth(ratio_labels) + TableUtils::maxLabelWidth(eta_labels);
690 if (m_dumpAllStatEtaBins.value())
691 {
692 // show for each ratio a table with one row per eta bin
693 for (std::size_t ratio_i = 0; ratio_i < ratio_labels.size(); ++ratio_i)
694 {
695 table_out << makeTable(ratio,
696 ratio_i * ratio_stride,
697 ratio_eta_stride,
698 eta_labels,
699 categories)
700 .columnWidth(10)
701 // only dump the footer for the last eta bin i.e. total
702 .dumpHeader(ratio_i == 0)
703 .dumpFooter(ratio_i + 1 == ratio_labels.size())
704 .separateLastRow(true) // separate the sum of las
705 .minLabelWidth(max_label_width)
706 .labelPrefix(ratio_labels.at(ratio_i));
707 }
708 }
709 else
710 {
711 // dump one table with one row per ratio showing the total eta range
712 table_out << makeTable(ratio,
713 (m_statEtaBins.size() + 1) * ratio_eta_stride + 0 * ratio_stride,
714 ratio_stride,
715 ratio_labels,
716 categories)
717 .columnWidth(10)
718 // only dump the footer for the last eta bin i.e. total
719 .minLabelWidth(max_label_width)
720 .dumpFooter(false);
721
722 // also dump a table for final tracks over used seeds (ratio_i==6 or 4) showing one row per eta bin
723 eta_labels.erase(eta_labels.end() - 1); // drop last line of table which shows again all eta bins summed.
724 std::size_t ratio_i = m_showResolvedStats ? 6 : 4;
725 table_out << makeTable(ratio,
726 ratio_i * ratio_stride,
727 ratio_eta_stride,
728 eta_labels,
729 categories)
730 .columnWidth(10)
731 .dumpHeader(false)
732 // only dump the footer for the last eta bin i.e. total
733 .dumpFooter(!m_dumpAllStatEtaBins.value() || ratio_i + 1 == ratio_labels.size())
734 .separateLastRow(false)
735 .minLabelWidth(max_label_width)
736 .labelPrefix(ratio_labels.at(ratio_i));
737 }
738
739 ATH_MSG_INFO("Ratios:\n"
740 << table_out.str());
741 }
742 }
743
744 std::size_t TrackFindingBaseAlg::getStatCategory(std::size_t seed_collection, float eta) const {
745 std::vector<float>::const_iterator bin_iter = std::upper_bound(m_statEtaBins.begin(),
746 m_statEtaBins.end(),
747 m_useAbsEtaForStat ? std::abs(eta) : eta);
748 std::size_t category_i = seed_collection * seedCollectionStride() + static_cast<std::size_t>(bin_iter - m_statEtaBins.begin());
749 assert(category_i < m_stat.size());
750 return category_i;
751 }
752
753 std::size_t TrackFindingBaseAlg::computeStatSum(std::size_t seed_collection, EStat counter_i, const EventStats &stat) const {
754 std::size_t out = 0u;
755 for (std::size_t category_i = seed_collection * seedCollectionStride();
756 category_i < (seed_collection + 1) * seedCollectionStride();
757 ++category_i)
758 {
759 assert(category_i < stat.size());
760 out += stat[category_i][counter_i];
761 }
762 return out;
763 }
764
765 bool TrackFindingBaseAlg::selectCountsFinal(const detail::RecoTrackContainer::TrackProxy &track) const {
766 if (not m_addCounts) return true;
767 double eta = -std::log(std::tan(0.5 * track.theta()));
768 auto [enoughMeasurementsPS, tooManyHolesPS, tooManyOutliersPS] = selectCounts(track, eta);
769 return enoughMeasurementsPS && !tooManyHolesPS && !tooManyOutliersPS;
770 }
771
772} // 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_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)
base class interface providing the bare minimal interface extension.
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
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
static void addCounts(detail::RecoTrackContainer &tracksContainer)
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
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
ToolHandle< ActsTrk::IActsToTrkConverterTool > m_ATLASConverterTool
Gaudi::Property< std::vector< std::size_t > > m_maxHgtdOutliers
Gaudi::Property< std::vector< double > > m_z0Max
Gaudi::Property< double > m_absEtaMax
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
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
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
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
std::vector< std::array< unsigned int, kNStat > > EventStats
ToolHandle< ActsTrk::IHGTDOnTrackCalibratorTool< detail::RecoTrackStateContainer > > m_hgtdCalibTool
detail::xAODUncalibMeasSurfAcc m_unalibMeasSurfAcc
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< 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
Helper class to access the Acts::surface associated with an Uncalibrated xAOD measurement.
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
Acts::TrackContainer< Acts::VectorTrackContainer, Acts::VectorMultiTrajectory > RecoTrackContainer
RecoTrackStateContainer::ConstTrackStateProxy RecoConstTrackStateContainerProxy
Acts::CombinatorialKalmanFilter< Propagator, RecoTrackContainer > CKF
std::unique_ptr< ActsTrk::IMeasurementSelector > getMeasurementSelector(const EventContext &ctx, const ActsTrk::IPixelOnBoundStateCalibratorTool *pixelOnTrackCalibratorTool, const ActsTrk::IStripOnBoundStateCalibratorTool *stripOnTrackCalibratorTool, const ActsTrk::IHGTDOnBoundStateCalibratorTool *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)
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.
Acts::CombinatorialKalmanFilterExtensions< RecoTrackContainer > ckfExtensions