ATLAS Offline Software
Loading...
Searching...
No Matches
TrackStatePrinterTool.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ATHENA
6#include "xAODMeasurementBase/UncalibratedMeasurementContainer.h"
7 #include "ActsCalibrators/xAODUncalibMeasCalibrator.h"
8
9// ACTS CORE
10#include "Acts/Geometry/TrackingGeometry.hpp"
11#include "Acts/EventData/BoundTrackParameters.hpp"
12#include "Acts/Utilities/detail/OstreamStateGuard.hpp"
13// Other
14#include <iostream>
15#include <sstream>
16
17namespace ActsTrk
18{
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)
23 {
24 std::ostringstream os;
25 (os << ... << values);
26 return os.str();
27 }
28
29 template <typename track_container_t>
30 void
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,
35 bool rejected) const
36 {
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(
44 lastMeasurementIndex,
45 [&states, &npixel, &nstrip](const TrackStateProxy &state) -> void
46 {
47 if (state.hasCalibrated())
48 {
49 if (state.calibratedSize() == 1)
50 ++nstrip;
51 else if (state.calibratedSize() == 2)
52 ++npixel;
53 }
54 states.push_back(state);
55 });
56
57 if (track.nMeasurements() + track.nOutliers() != npixel + nstrip)
58 {
59 ATH_MSG_WARNING("Track has " << track.nMeasurements() + track.nOutliers() << " measurements + outliers, but "
60 << npixel + nstrip << " pixel + strip hits");
61 }
62
63 const Acts::BoundTrackParameters per(track.referenceSurface().getSharedPtr(),
64 track.parameters(),
65 track.covariance(),
66 track.particleHypothesis());
67 Acts::detail::OstreamStateGuard s(std::cout);
68 std::cout << std::setw(5) << lastMeasurementIndex << ' '
69 << std::left
70 << std::setw(4) << "parm" << ' '
71 << std::setw(21) << actsSurfaceName(per.referenceSurface()) << ' '
72 << std::setw(22) << to_string("#hit=", npixel, '/', nstrip, ", #hole=", track.nHoles()) << ' '
73 << std::right;
74 printParameters(per.referenceSurface(), tgContext, per.parameters());
75 std::cout << std::fixed << std::setw(8) << ' '
76 << std::setw(7) << std::setprecision(1) << track.chi2() << ' '
77 << std::left
78 << "#out=" << track.nOutliers()
79 << ", #sh=" << track.nSharedHits()
80 << (rejected ? " - REJECTED" : "")
81 << std::right << '\n';
82
83 for (auto i = states.size(); i > 0;)
84 {
85 printTrackState(tgContext, states[--i], measurementIndexer);
86 }
87 }
88
89 template <typename track_state_proxy_t>
90 bool
91 TrackStatePrinterTool::printTrackState(const Acts::GeometryContext &tgContext,
92 const track_state_proxy_t &state,
93 const detail::MeasurementIndex &measurementIndexer,
94 bool useFiltered,
95 bool newLine) const
96 {
97 Acts::detail::OstreamStateGuard s(std::cout);
98 if (!m_printFilteredStates && useFiltered)
99 return false;
100
101 ptrdiff_t index = -1;
102
103 if (state.hasUncalibratedSourceLink())
104 {
105 const xAOD::UncalibratedMeasurement* umeas = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());;
106 index = measurementIndexer.index(*umeas);
107 }
108
109 std::cout << std::setw(5) << state.index() << ' ';
110 char ptype = !m_printFilteredStates ? ' '
111 : useFiltered ? 'F'
112 : 'S';
113 if (state.hasCalibrated())
114 {
115 std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
116 }
117 else if (state.typeFlags().isHole())
118 {
119 std::cout << std::setw(4) << "hole";
120 }
121 else
122 {
123 std::cout << ptype << std::setw(3) << " ";
124 }
125 std::cout << ' '
126 << std::left
127 << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
128 if (index >= 0)
129 {
130 std::cout << std::setw(22) << index << ' ';
131 }
132 else
133 {
134 std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
135 }
136 std::cout << std::right;
137 const auto &parameters = !useFiltered ? state.parameters()
138 : state.hasFiltered() ? state.filtered()
139 : state.predicted();
140 printParameters(state.referenceSurface(), tgContext, parameters);
141 std::cout << ' '
142 << std::fixed
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());
147 if (newLine)
148 std::cout << '\n';
149 return true;
150 }
151
152} // namespace ActsTrk