2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 #ifndef ACTSTRACKRECONSTRUCTION_TRACKSTATEPRINTER_ICC
6 #define ACTSTRACKRECONSTRUCTION_TRACKSTATEPRINTER_ICC 1
9 #include "xAODMeasurementBase/UncalibratedMeasurementContainer.h"
10 #include "ActsGeometry/ATLASSourceLink.h"
13 #include "Acts/Geometry/TrackingGeometry.hpp"
14 #include "Acts/EventData/TrackParameters.hpp"
22 /// format all arguments and return as a string.
23 /// Used here to apply std::setw() to the combination of values.
24 template <typename... Types>
25 static std::string to_string(Types &&...values)
27 std::ostringstream os;
28 (os << ... << values);
32 template <typename track_container_t>
34 TrackStatePrinter::printTrack(const Acts::GeometryContext &tgContext,
35 const track_container_t &tracks,
36 const typename track_container_t::TrackProxy &track,
37 const std::vector<std::pair<const xAOD::UncalibratedMeasurementContainer *, size_t>> &container_offset) const
39 const auto lastMeasurementIndex = track.tipIndex();
40 // to print track states from inside outward, we need to reverse the order of visitBackwards().
41 using PrintTrackStateContainer = std::decay_t<decltype(tracks.trackStateContainer())>;
42 std::vector<typename PrintTrackStateContainer::ConstTrackStateProxy> states;
43 states.reserve(lastMeasurementIndex + 1); // could be an overestimate
44 size_t npixel = 0, nstrip = 0;
45 tracks.trackStateContainer().visitBackwards(
47 [&states, &npixel, &nstrip](const PrintTrackStateContainer::ConstTrackStateProxy &state) -> void
49 if (state.hasCalibrated())
51 if (state.calibratedSize() == 1)
53 else if (state.calibratedSize() == 2)
56 states.push_back(state);
59 if (track.nMeasurements() + track.nOutliers() != npixel + nstrip)
61 ATH_MSG_WARNING("Track has " << track.nMeasurements() + track.nOutliers() << " measurements + outliers, but "
62 << npixel + nstrip << " pixel + strip hits");
65 const Acts::BoundTrackParameters per(track.referenceSurface().getSharedPtr(),
68 track.particleHypothesis());
69 std::cout << std::setw(5) << lastMeasurementIndex << ' '
71 << std::setw(4) << "parm" << ' '
72 << std::setw(21) << actsSurfaceName(per.referenceSurface()) << ' '
73 << std::setw(22) << to_string("#hit=", npixel, '/', nstrip, ", #hole=", track.nHoles()) << ' '
75 printParameters(per.referenceSurface(), tgContext, per.parameters());
76 std::cout << std::fixed << std::setw(8) << ' '
77 << std::setw(7) << std::setprecision(1) << track.chi2() << ' '
79 << "#out=" << track.nOutliers()
80 << ", #sh=" << track.nSharedHits()
81 << std::right << std::defaultfloat << std::setprecision(-1) << '\n';
83 for (auto i = states.size(); i > 0;)
85 printTrackState(tgContext, states[--i], container_offset);
89 template <typename track_state_proxy_t>
91 TrackStatePrinter::printTrackState(const Acts::GeometryContext &tgContext,
92 const track_state_proxy_t &state,
93 const std::vector<std::pair<const xAOD::UncalibratedMeasurementContainer *, size_t>> &container_offset,
94 bool useFiltered) const
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 = umeas.index();
106 for (const auto &[container, offset] : container_offset)
108 if (umeas.container() == container)
116 std::cout << std::setw(5) << state.index() << ' ';
117 char ptype = !m_printFilteredStates ? ' '
120 if (state.hasCalibrated())
122 std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
124 else if (state.typeFlags().test(Acts::TrackStateFlag::HoleFlag))
126 std::cout << std::setw(4) << "hole";
130 std::cout << ptype << std::setw(3) << " ";
134 << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
137 std::cout << std::setw(22) << index << ' ';
141 std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
143 std::cout << std::right;
144 const auto ¶meters = !useFiltered ? state.parameters()
145 : state.hasFiltered() ? state.filtered()
147 printParameters(state.referenceSurface(), tgContext, parameters);
150 << std::setw(6) << std::setprecision(1) << state.pathLength() << ' '
151 << std::setw(7) << std::setprecision(1) << state.chi2() << ' '
152 << std::defaultfloat << std::setprecision(-1)
153 << std::setw(Acts::TrackStateFlag::NumTrackStateFlags) << trackStateName(state.typeFlags()) << '\n';
156 } // namespace ActsTrk