Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TrackStatePrinterTool.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ATHENA
6 #include "xAODMeasurementBase/UncalibratedMeasurementContainer.h"
7 #include "ActsGeometry/ATLASSourceLink.h"
8 
9 // ACTS CORE
10 #include "Acts/Geometry/TrackingGeometry.hpp"
11 #include "Acts/EventData/TrackParameters.hpp"
12 
13 // Other
14 #include <iostream>
15 #include <sstream>
16 
17 namespace 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  ATLASUncalibSourceLink sl = state.getUncalibratedSourceLink().template get<ATLASUncalibSourceLink>();
104  const xAOD::UncalibratedMeasurement &umeas = getUncalibratedMeasurement(sl);
105  index = measurementIndexer.index(umeas);
106  }
107 
108  std::cout << std::setw(5) << state.index() << ' ';
109  char ptype = !m_printFilteredStates ? ' '
110  : useFiltered ? 'F'
111  : 'S';
112  if (state.hasCalibrated())
113  {
114  std::cout << ptype << std::setw(2) << state.calibratedSize() << 'D';
115  }
116  else if (state.typeFlags().test(Acts::TrackStateFlag::HoleFlag))
117  {
118  std::cout << std::setw(4) << "hole";
119  }
120  else
121  {
122  std::cout << ptype << std::setw(3) << " ";
123  }
124  std::cout << ' '
125  << std::left
126  << std::setw(21) << actsSurfaceName(state.referenceSurface()) << ' ';
127  if (index >= 0)
128  {
129  std::cout << std::setw(22) << index << ' ';
130  }
131  else
132  {
133  std::cout << std::setw(22) << to_string(state.referenceSurface().geometryId()) << ' ';
134  }
135  std::cout << std::right;
136  const auto &parameters = !useFiltered ? state.parameters()
137  : state.hasFiltered() ? state.filtered()
138  : state.predicted();
139  printParameters(state.referenceSurface(), tgContext, parameters);
140  std::cout << ' '
141  << std::fixed
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());
146  if (newLine)
147  std::cout << '\n';
148  return true;
149  }
150 
151 } // namespace ActsTrk