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
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 std::cout << std::setw(5) << lastMeasurementIndex << ' '
68 << std::left
69 << std::setw(4) << "parm" << ' '
70 << std::setw(21) << actsSurfaceName(per.referenceSurface()) << ' '
71 << std::setw(22) << to_string("#hit=", npixel, '/', nstrip, ", #hole=", track.nHoles()) << ' '
72 << std::right;
73 printParameters(per.referenceSurface(), tgContext, per.parameters());
74 std::cout << std::fixed << std::setw(8) << ' '
75 << std::setw(7) << std::setprecision(1) << track.chi2() << ' '
76 << std::left
77 << "#out=" << track.nOutliers()
78 << ", #sh=" << track.nSharedHits()
79 << (rejected ? " - REJECTED" : "")
80 << std::right << std::defaultfloat << std::setprecision(-1) << '\n';
81
82 for (auto i = states.size(); i > 0;)
83 {
84 printTrackState(tgContext, states[--i], measurementIndexer);
85 }
86 }
87
88 template <typename track_state_proxy_t>
89 bool
90 TrackStatePrinterTool::printTrackState(const Acts::GeometryContext &tgContext,
91 const track_state_proxy_t &state,
92 const detail::MeasurementIndex &measurementIndexer,
93 bool useFiltered,
94 bool newLine) const
95 {
96 if (!m_printFilteredStates && useFiltered)
97 return false;
98
99 ptrdiff_t index = -1;
100
101 if (state.hasUncalibratedSourceLink())
102 {
103 const xAOD::UncalibratedMeasurement* umeas = detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());;
104 index = measurementIndexer.index(*umeas);
105 }
106
107 std::cout << std::setw(5) << state.index() << ' ';
108 char ptype = !m_printFilteredStates ? ' '
109 : useFiltered ? 'F'
110 : 'S';
111 if (state.hasCalibrated())
112 {
113 std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
114 }
115 else if (state.typeFlags().isHole())
116 {
117 std::cout << std::setw(4) << "hole";
118 }
119 else
120 {
121 std::cout << ptype << std::setw(3) << " ";
122 }
123 std::cout << ' '
124 << std::left
125 << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
126 if (index >= 0)
127 {
128 std::cout << std::setw(22) << index << ' ';
129 }
130 else
131 {
132 std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
133 }
134 std::cout << std::right;
135 const auto &parameters = !useFiltered ? state.parameters()
136 : state.hasFiltered() ? state.filtered()
137 : state.predicted();
138 printParameters(state.referenceSurface(), tgContext, parameters);
139 std::cout << ' '
140 << std::fixed
141 << std::setw(6) << std::setprecision(1) << state.pathLength() << ' '
142 << std::setw(7) << std::setprecision(1) << state.chi2() << ' '
143 << std::defaultfloat << std::setprecision(-1)
144 << std::setw(Acts::toUnderlying(Acts::TrackStateFlag::NumFlags)) << trackStateName(state.typeFlags());
145 if (newLine)
146 std::cout << '\n';
147 return true;
148 }
149
150} // namespace ActsTrk