2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
6#include "xAODMeasurementBase/UncalibratedMeasurementContainer.h"
7 #include "ActsCalibrators/xAODUncalibMeasCalibrator.h"
10#include "Acts/Geometry/TrackingGeometry.hpp"
11#include "Acts/EventData/BoundTrackParameters.hpp"
12#include "Acts/Utilities/detail/OstreamStateGuard.hpp"
19 /// format all arguments and return as a string.
20 /// Used here to apply std::setw() to the combination of values.
21 template <typename... Types>
22 static std::string to_string(Types &&...values)
24 std::ostringstream os;
25 (os << ... << values);
29 template <typename track_container_t>
31 TrackStatePrinterTool::printTrack(const Acts::GeometryContext &tgContext,
32 const track_container_t &tracks,
33 const typename track_container_t::TrackProxy &track,
34 const detail::MeasurementIndex &measurementIndexer,
37 const auto lastMeasurementIndex = track.tipIndex();
38 // to print track states from inside outward, we need to reverse the order of visitBackwards().
39 using TrackStateProxy = std::decay_t<decltype(tracks.trackStateContainer())>::ConstTrackStateProxy;
40 std::vector<TrackStateProxy> states;
41 states.reserve(lastMeasurementIndex + 1); // could be an overestimate
42 std::size_t npixel = 0, nstrip = 0;
43 tracks.trackStateContainer().visitBackwards(
45 [&states, &npixel, &nstrip](const TrackStateProxy &state) -> void
47 if (state.hasCalibrated())
49 if (state.calibratedSize() == 1)
51 else if (state.calibratedSize() == 2)
54 states.push_back(state);
57 if (track.nMeasurements() + track.nOutliers() != npixel + nstrip)
59 ATH_MSG_WARNING("Track has " << track.nMeasurements() + track.nOutliers() << " measurements + outliers, but "
60 << npixel + nstrip << " pixel + strip hits");
63 const Acts::BoundTrackParameters per(track.referenceSurface().getSharedPtr(),
66 track.particleHypothesis());
67 Acts::detail::OstreamStateGuard s(std::cout);
68 std::cout << std::setw(5) << lastMeasurementIndex << ' '
70 << std::setw(4) << "parm" << ' '
71 << std::setw(21) << actsSurfaceName(per.referenceSurface()) << ' '
72 << std::setw(22) << to_string("#hit=", npixel, '/', nstrip, ", #hole=", track.nHoles()) << ' '
74 printParameters(per.referenceSurface(), tgContext, per.parameters());
75 std::cout << std::fixed << std::setw(8) << ' '
76 << std::setw(7) << std::setprecision(1) << track.chi2() << ' '
78 << "#out=" << track.nOutliers()
79 << ", #sh=" << track.nSharedHits()
80 << (rejected ? " - REJECTED" : "")
81 << std::right << '\n';
83 for (auto i = states.size(); i > 0;)
85 printTrackState(tgContext, states[--i], measurementIndexer);
89 template <typename track_state_proxy_t>
91 TrackStatePrinterTool::printTrackState(const Acts::GeometryContext &tgContext,
92 const track_state_proxy_t &state,
93 const detail::MeasurementIndex &measurementIndexer,
97 Acts::detail::OstreamStateGuard s(std::cout);
98 if (!m_printFilteredStates && useFiltered)
101 ptrdiff_t index = -1;
103 if (state.hasUncalibratedSourceLink())
105 const xAOD::UncalibratedMeasurement* umeas = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());;
106 index = measurementIndexer.index(*umeas);
109 std::cout << std::setw(5) << state.index() << ' ';
110 char ptype = !m_printFilteredStates ? ' '
113 if (state.hasCalibrated())
115 std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
117 else if (state.typeFlags().isHole())
119 std::cout << std::setw(4) << "hole";
123 std::cout << ptype << std::setw(3) << " ";
127 << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
130 std::cout << std::setw(22) << index << ' ';
134 std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
136 std::cout << std::right;
137 const auto ¶meters = !useFiltered ? state.parameters()
138 : state.hasFiltered() ? state.filtered()
140 printParameters(state.referenceSurface(), tgContext, parameters);
143 << std::setw(6) << std::setprecision(1) << state.pathLength() << ' '
144 << std::setw(7) << std::setprecision(1) << state.chi2() << ' '
145 << std::defaultfloat << std::setprecision(-1)
146 << std::setw(Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)) << trackStateName(state.typeFlags());
152} // namespace ActsTrk