2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
6 #include "xAODMeasurementBase/UncalibratedMeasurementContainer.h"
7 #include "ActsGeometry/ATLASSourceLink.h"
10 #include "Acts/Geometry/TrackingGeometry.hpp"
11 #include "Acts/EventData/TrackParameters.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 std::cout << std::setw(5) << lastMeasurementIndex << ' '
69 << std::setw(4) << "parm" << ' '
70 << std::setw(21) << actsSurfaceName(per.referenceSurface()) << ' '
71 << std::setw(22) << to_string("#hit=", npixel, '/', nstrip, ", #hole=", track.nHoles()) << ' '
73 printParameters(per.referenceSurface(), tgContext, per.parameters());
74 std::cout << std::fixed << std::setw(8) << ' '
75 << std::setw(7) << std::setprecision(1) << track.chi2() << ' '
77 << "#out=" << track.nOutliers()
78 << ", #sh=" << track.nSharedHits()
79 << (rejected ? " - REJECTED" : "")
80 << std::right << std::defaultfloat << std::setprecision(-1) << '\n';
82 for (auto i = states.size(); i > 0;)
84 printTrackState(tgContext, states[--i], measurementIndexer);
88 template <typename track_state_proxy_t>
90 TrackStatePrinterTool::printTrackState(const Acts::GeometryContext &tgContext,
91 const track_state_proxy_t &state,
92 const detail::MeasurementIndex &measurementIndexer,
96 if (!m_printFilteredStates && useFiltered)
101 if (state.hasUncalibratedSourceLink())
103 ATLASUncalibSourceLink sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
104 const xAOD::UncalibratedMeasurement &umeas = getUncalibratedMeasurement(sl);
105 index = measurementIndexer.index(umeas);
108 std::cout << std::setw(5) << state.index() << ' ';
109 char ptype = !m_printFilteredStates ? ' '
112 if (state.hasCalibrated())
114 std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
116 else if (state.typeFlags().test(Acts::TrackStateFlag::HoleFlag))
118 std::cout << std::setw(4) << "hole";
122 std::cout << ptype << std::setw(3) << " ";
126 << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
129 std::cout << std::setw(22) << index << ' ';
133 std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
135 std::cout << std::right;
136 const auto ¶meters = !useFiltered ? state.parameters()
137 : state.hasFiltered() ? state.filtered()
139 printParameters(state.referenceSurface(), tgContext, parameters);
142 << std::setw(6) << std::setprecision(1) << state.pathLength() << ' '
143 << std::setw(7) << std::setprecision(1) << state.chi2() << ' '
144 << std::defaultfloat << std::setprecision(-1)
145 << std::setw(Acts::TrackStateFlag::NumTrackStateFlags) << trackStateName(state.typeFlags());
151 } // namespace ActsTrk