ATLAS Offline Software
InDetAccessor.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef _InDetAccessor_H_
5 #define _InDetAccessor_H_
6 
7 #include <tuple>
8 #include <array>
9 #include <stdexcept>
11 
14 #include "xAODTracking/Vertex.h"
15 
16 #ifndef XAOD_ANALYSIS
17 #include "TrkTrack/Track.h"
20 #endif
21 
22 #define IDTRKSEL_MSG(msg_type,the_msg) if (msgHelper.msgLvl(msg_type)) { msgHelper.msg() << the_msg << endmsg; } do {} while (false)
23 #define IDTRKSEL_MSG_DEBUG(the_msg) IDTRKSEL_MSG(MSG::DEBUG,the_msg)
24 #define IDTRKSEL_MSG_WARNING(the_msg) IDTRKSEL_MSG(MSG::WARNING,the_msg)
25 #define IDTRKSEL_MSG_ERROR(the_msg) IDTRKSEL_MSG(MSG::ERROR,the_msg)
26 
27 namespace InDetAccessor {
28 
29  // from TrkEventPrimitives/ParamDefs.h
31  d0 = 0,
32  z0 = 1,
33  phi0 = 2,
34  theta = 3,
35  qOverP = 4,
36  };
37 
38  //cannot use partial spezialisation of function templates
39  // so define functsion for TrackParticles, and TrkTracks
40  class TrackParticleHelper;
41  template <short index>
42  double getDefiningParameters(TrackParticleHelper helper, const asg::AsgMessaging &msgHelper);
43 
44 #ifndef XAOD_ANALYSIS
45  class TrkTrackHelper;
46  template <short index>
47  double getDefiningParameters(TrkTrackHelper helper, const asg::AsgMessaging &msgHelper);
48 #endif
49 
51  public:
53  : m_track(&a_track), m_vtx(a_vtx) {}
54 
55  const xAOD::TrackParticle &track() const { return *m_track;}
56  const xAOD::Vertex *vertex() const { return m_vtx; }
57 
58  double pt(const asg::AsgMessaging &) const { return track().pt(); }
59  double eta(const asg::AsgMessaging &) const { return track().eta(); }
60  double theta(const asg::AsgMessaging &msgHelper)const { return getDefiningParameters<InDetAccessor::theta>(*this,msgHelper); }
61  double qOverP(const asg::AsgMessaging &) const { return track().qOverP(); }
62  double d0(const asg::AsgMessaging &msgHelper) const { return getDefiningParameters<InDetAccessor::d0>(*this,msgHelper);}
63  double z0(const asg::AsgMessaging &msgHelper) const { return getDefiningParameters<InDetAccessor::z0>(*this,msgHelper);}
64 
65  private:
68  };
69 
70 #ifndef XAOD_ANALYSIS
72  public:
73  TrkTrackHelper(const Trk::Track &a_track, const Trk::TrackSummary &summary, const Trk::TrackParameters *a_perigee )
74  : m_track(&a_track), m_summary(&summary), m_perigee(a_perigee) {}
75 
76  const Trk::Track &track() const { return *m_track;}
77  const Trk::TrackSummary &summary() const { return *m_summary;}
78  const Trk::TrackParameters *perigee() const { return m_perigee; }
79 
80  double pt(const asg::AsgMessaging &msgHelper) const {
81  return hasPerigeeOrError(msgHelper) ? perigee()->momentum().perp() : std::nan("");
82  }
83  double eta(const asg::AsgMessaging &msgHelper) const {
84  return hasPerigeeOrError(msgHelper) ? perigee()->momentum().eta() : std::nan("");
85  }
86  double theta(const asg::AsgMessaging &msgHelper) const { return getDefiningParameters<InDetAccessor::theta>(*this,msgHelper);}
87  double qOverP(const asg::AsgMessaging &msgHelper) const {
88  return hasPerigeeOrError(msgHelper) ? 1./perigee()->momentum().mag() : std::nan("");
89  }
90  double d0(const asg::AsgMessaging &msgHelper) const { return getDefiningParameters<InDetAccessor::d0>(*this,msgHelper);}
91  double z0(const asg::AsgMessaging &msgHelper) const { return getDefiningParameters<InDetAccessor::z0>(*this,msgHelper);}
92 
93  bool hasPerigeeOrError(const asg::AsgMessaging &msgHelper) const {
94  bool ret = perigee();
95  if (!ret) {
96  IDTRKSEL_MSG_ERROR( "Received zero pointer to perigee." );
97  }
98  return ret;
99  }
100  bool hasSummaryOrError(const asg::AsgMessaging &msgHelper) const {
101  bool ret = perigee();
102  if (!ret) {
103  IDTRKSEL_MSG_ERROR( "Received null pointer to track summary." );
104  }
105  return ret;
106  }
107  private:
108 
112  };
113 #endif
114 
115 
116  // summary accessor
117  template <typename T_TrkHelper>
118  uint8_t getSummary(const T_TrkHelper & helper, const asg::AsgMessaging &msgHelper, xAOD::SummaryType sumType);
119 
120  template <>
121  inline uint8_t getSummary(const TrackParticleHelper & helper, const asg::AsgMessaging &msgHelper, xAOD::SummaryType summaryType) {
122  uint8_t summaryValue = 0;
123  if (!helper.track().summaryValue(summaryValue, summaryType)) {
124  IDTRKSEL_MSG_DEBUG( "Failed to get SummaryType " << std::to_string(summaryType) << " from xAOD::TrackParticle summary. A value of zero will be used instead." );
125  summaryValue = 0;
126  }
127  return summaryValue;
128  }
129 
130 #ifndef XAOD_ANALYSIS
131  template <>
132  inline uint8_t getSummary(const TrkTrackHelper & helper, const asg::AsgMessaging &msgHelper, xAOD::SummaryType summaryType) {
133  Int_t summaryTypeInt = static_cast<Int_t>(summaryType);
134  Int_t checkSummaryValue = helper.summary().get( static_cast<Trk::SummaryType>(summaryTypeInt) );
135  if (checkSummaryValue < 0) {
136  // Trk::TrackSummary::get() will return -1 if the data cannot be retrieved
137  IDTRKSEL_MSG_DEBUG( "Received " << checkSummaryValue << " for SummaryType " << std::to_string(summaryType) << " from Trk::TrackSummary. A value of zero will be used instead." );
138  checkSummaryValue = 0;
139  }
140  return checkSummaryValue;
141  }
142 #endif
143 
144  template <std::size_t n_summary_types, typename T_TrkHelper>
145  inline uint8_t getSummarySum(const T_TrkHelper helper, const asg::AsgMessaging &msgHelper, std::array<xAOD::SummaryType,n_summary_types> sumTypes) {
146  uint8_t sum=0;
147  for (xAOD::SummaryType sum_type: sumTypes) {
148  sum += getSummary(helper, msgHelper, sum_type);
149  }
150  return sum;
151  }
152 
153 
154  // fit quality accessor
155  template <typename Trk_Helper>
156  double getFitChiSquare(const Trk_Helper & helper, const asg::AsgMessaging &msgHelper);
157 
158  template <>
160  return helper.track().chiSquared();
161  }
162 
163 #ifndef XAOD_ANALYSIS
164  template <>
165  inline double getFitChiSquare(const TrkTrackHelper & helper, const asg::AsgMessaging &msgHelper) {
166  if (!helper.track().fitQuality()) {
167  IDTRKSEL_MSG_WARNING( "Zero pointer to fit quality received." );
168  return std::nan("");
169  }
170  return helper.track().fitQuality()->chiSquared();
171  }
172 #endif
173 
174  template <typename TrkHelper>
175  double getFitNDoF(const TrkHelper & helper, const asg::AsgMessaging &msgHelper);
176 
177  template <>
178  inline double getFitNDoF(const TrackParticleHelper & helper, const asg::AsgMessaging &) {
179  return helper.track().numberDoF();
180  }
181 
182 #ifndef XAOD_ANALYSIS
183  template <>
184  inline double getFitNDoF(const TrkTrackHelper & helper, const asg::AsgMessaging &msgHelper) {
185  if (!helper.track().fitQuality()) {
186  IDTRKSEL_MSG_WARNING( "Zero pointer to fit quality received." );
187  return std::nan("");
188  }
189  return helper.track().fitQuality()->doubleNumberDoF();
190  }
191 #endif
192 
193 
194  // eProbabilityHT accessor
195  template <typename Trk_Helper>
196  float getEProbabilityHT(const Trk_Helper & helper, const asg::AsgMessaging &msgHelper);
197 
198  template <>
199  inline float getEProbabilityHT(const TrackParticleHelper & helper, const asg::AsgMessaging &msgHelper) {
200  float eProbHT =0.f;
201  if (!helper.track().summaryValue(eProbHT, xAOD::SummaryType::eProbabilityHT)) {
202  IDTRKSEL_MSG_DEBUG( "Failed to get eProbabilityHT from xAOD::TrackParticle summary. A value of zero will be used instead." );
203  eProbHT =0.f;
204  }
205  return eProbHT;
206  }
207 
208 #ifndef XAOD_ANALYSIS
209  template <>
210  inline float getEProbabilityHT(const TrkTrackHelper &, const asg::AsgMessaging &) {
211  throw std::runtime_error("eProbabilityHT only available in xAOD::TrackParticle not for Trk::Track.");
212  return 0.f;
213  }
214 #endif
215 
216  //defining parameters accessor
217 
218  template <short index>
220  static_assert(index<5);
221  double param = helper.track().definingParameters()[index];
222  if (index==1) {
223  if (helper.vertex()) {
224  param += helper.track().vz() - helper.vertex()->z();
225  }
226  }
227  return param;
228  }
229 
230 #ifndef XAOD_ANALYSIS
231  template <short index>
232  //cppcheck-suppress passedByValue
234  assert(index<5);
235  return helper.hasPerigeeOrError(msgHelper) ? helper.perigee()->parameters()[index] : std::nan("");
236  }
237 #endif
238 
239  // defining parameters covariance accessor
240  template <typename Trk_Helper>
241  inline double getDefiningParametersCov(Trk_Helper & helper, [[maybe_unused]] const asg::AsgMessaging &msgHelper, unsigned int index_i, unsigned int index_j);
242 
243  template <>
244  inline double getDefiningParametersCov(TrackParticleHelper & helper, [[maybe_unused]] const asg::AsgMessaging &msgHelper, unsigned int index_i, unsigned int index_j) {
245  assert( index_i<5 && index_j<5);
246  return helper.track().definingParametersCovMatrix()(index_i, index_j);
247  }
248 
249 #ifndef XAOD_ANALYSIS
250  template <>
251  inline double getDefiningParametersCov(TrkTrackHelper & helper, const asg::AsgMessaging &msgHelper, unsigned int index_i, unsigned int index_j) {
252  assert( index_i<5 && index_j<5);
253  return helper.hasPerigeeOrError(msgHelper) ? (*helper.perigee()->covariance())(index_i, index_j) : std::nan("");
254  }
255 #endif
256 
257  template <typename Trk_Helper>
258  inline Int_t getNumberOfUsedHitsdEdx(Trk_Helper & helper, const asg::AsgMessaging &msgHelper);
259 
260  template <>
261  inline Int_t getNumberOfUsedHitsdEdx(TrackParticleHelper & helper, [[maybe_unused]] const asg::AsgMessaging &msgHelper) {
262  return helper.track().numberOfUsedHitsdEdx();
263  }
264 
265 #ifndef XAOD_ANALYSIS
266  template <>
268  throw std::runtime_error("umberOfUsedHitsdEdx only available in xAOD::TrackParticle not for Trk::Track.");
269  return 0;
270  }
271 #endif
272 
273  template <typename Trk_Helper>
274  inline Int_t getNumberOfIBLOverflowsdEdx(Trk_Helper & helper, const asg::AsgMessaging &msgHelper);
275 
276  template <>
277  inline Int_t getNumberOfIBLOverflowsdEdx(TrackParticleHelper & helper, [[maybe_unused]] const asg::AsgMessaging &msgHelper) {
278  return helper.track().numberOfUsedHitsdEdx();
279  }
280 
281 #ifndef XAOD_ANALYSIS
282  template <>
284  throw std::runtime_error("NumberOfIBLOverflowsdEdx only available in xAOD::TrackParticle not for Trk::Track.");
285  return 0;
286  }
287 #endif
288 
289 #ifndef XAOD_ANALYSIS
290  std::tuple<uint8_t,uint8_t> getSiHitsTopBottom( const Trk::Track& track, const asg::AsgMessaging &msgHelper);
291 
292  template <typename Trk_Helper>
293  inline std::tuple<uint8_t,uint8_t> getSiHitsTopBottom(Trk_Helper & helper, const asg::AsgMessaging &msgHelper);
294 
295  template <>
296  inline std::tuple<uint8_t,uint8_t> getSiHitsTopBottom(TrackParticleHelper & helper, const asg::AsgMessaging &msgHelper) {
297  const Trk::Track* trkTrack = helper.track().track();
298  if (!trkTrack) {
299  IDTRKSEL_MSG_WARNING( "xAOD::TrackParticle has a null pointer to a Trk::Track." );
300  IDTRKSEL_MSG_WARNING( "Unable to access top/bottom Si hits." );
301  return std::tuple<uint8_t,uint8_t>{};
302  }
303  else {
304  return getSiHitsTopBottom(*trkTrack,msgHelper);
305  }
306  }
307 
308  template <>
309  inline std::tuple<uint8_t,uint8_t> getSiHitsTopBottom(TrkTrackHelper & helper, const asg::AsgMessaging &msgHelper) {
310  return getSiHitsTopBottom(helper.track(),msgHelper);
311  }
312 #endif
313 }
314 #endif
IDTRKSEL_MSG_WARNING
#define IDTRKSEL_MSG_WARNING(the_msg)
Definition: InDetAccessor.h:24
xAOD::TrackParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TrackParticle_v1.cxx:73
IDTRKSEL_MSG_ERROR
#define IDTRKSEL_MSG_ERROR(the_msg)
Definition: InDetAccessor.h:25
InDetAccessor
Definition: InDetTrackSelectionTool.h:33
InDetAccessor::TrkTrackHelper::m_summary
const Trk::TrackSummary * m_summary
Definition: InDetAccessor.h:110
InDetAccessor::TrkTrackHelper::hasPerigeeOrError
bool hasPerigeeOrError(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:93
InDetAccessor::z0
@ z0
Definition: InDetAccessor.h:32
InDetAccessor::TrackParticleHelper::d0
double d0(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:62
InDetAccessor::TrackParticleHelper::m_vtx
const xAOD::Vertex * m_vtx
Definition: InDetAccessor.h:67
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
InDetAccessor::TrkTrackHelper::m_perigee
const Trk::TrackParameters * m_perigee
Definition: InDetAccessor.h:111
index
Definition: index.py:1
xAOD::TrackParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TrackParticle_v1.cxx:77
InDetAccessor::TrkTrackHelper::z0
double z0(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:91
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
InDetAccessor::getSummarySum
uint8_t getSummarySum(const T_TrkHelper helper, const asg::AsgMessaging &msgHelper, std::array< xAOD::SummaryType, n_summary_types > sumTypes)
Definition: InDetAccessor.h:145
InDetAccessor::TrkTrackHelper::perigee
const Trk::TrackParameters * perigee() const
Definition: InDetAccessor.h:78
InDetAccessor::TrackParticleHelper
Definition: InDetAccessor.h:50
InDetAccessor::getSiHitsTopBottom
std::tuple< uint8_t, uint8_t > getSiHitsTopBottom(const Trk::Track &track, const asg::AsgMessaging &msgHelper)
Definition: InDetAccessor.cxx:11
InDetAccessor::TrkTrackHelper::d0
double d0(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:90
InDetAccessor::qOverP
@ qOverP
perigee
Definition: InDetAccessor.h:35
InDetAccessor::TrkTrackHelper::eta
double eta(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:83
InDetAccessor::d0
@ d0
Definition: InDetAccessor.h:31
Track.h
InDetAccessor::TrkTrackHelper::TrkTrackHelper
TrkTrackHelper(const Trk::Track &a_track, const Trk::TrackSummary &summary, const Trk::TrackParameters *a_perigee)
Definition: InDetAccessor.h:73
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
AsgMessaging.h
IDTRKSEL_MSG_DEBUG
#define IDTRKSEL_MSG_DEBUG(the_msg)
Definition: InDetAccessor.h:23
InDetAccessor::getEProbabilityHT
float getEProbabilityHT(const Trk_Helper &helper, const asg::AsgMessaging &msgHelper)
xAOD::SummaryType
SummaryType
Enumerates the different types of information stored in Summary.
Definition: TrackingPrimitives.h:228
InDetAccessor::getFitChiSquare
double getFitChiSquare(const Trk_Helper &helper, const asg::AsgMessaging &msgHelper)
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
InDetAccessor::TrkTrackHelper::summary
const Trk::TrackSummary & summary() const
Definition: InDetAccessor.h:77
InDetAccessor::getDefiningParameters
double getDefiningParameters(TrackParticleHelper helper, const asg::AsgMessaging &msgHelper)
Definition: InDetAccessor.h:219
InDetAccessor::TrkTrackHelper::qOverP
double qOverP(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:87
InDetAccessor::TrkTrackHelper::theta
double theta(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:86
TrackSummary.h
Trk::ParametersBase
Definition: ParametersBase.h:55
Vertex.h
InDetAccessor::TrackParticleHelper::m_track
const xAOD::TrackParticle * m_track
Definition: InDetAccessor.h:66
InDetAccessor::getNumberOfUsedHitsdEdx
Int_t getNumberOfUsedHitsdEdx(Trk_Helper &helper, const asg::AsgMessaging &msgHelper)
xAOD::TrackParticle_v1::qOverP
float qOverP() const
Returns the parameter.
InDetAccessor::getFitNDoF
double getFitNDoF(const TrkHelper &helper, const asg::AsgMessaging &msgHelper)
InDetAccessor::TrackParticleHelper::theta
double theta(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:60
InDetAccessor::TrackParticleHelper::z0
double z0(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:63
Trk::TrackSummary
A summary of the information contained by a track.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:287
InDetAccessor::getNumberOfIBLOverflowsdEdx
Int_t getNumberOfIBLOverflowsdEdx(Trk_Helper &helper, const asg::AsgMessaging &msgHelper)
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InDetAccessor::getDefiningParametersCov
double getDefiningParametersCov(Trk_Helper &helper, [[maybe_unused]] const asg::AsgMessaging &msgHelper, unsigned int index_i, unsigned int index_j)
InDetAccessor::TrackParticleHelper::track
const xAOD::TrackParticle & track() const
Definition: InDetAccessor.h:55
InDetAccessor::theta
@ theta
Definition: InDetAccessor.h:34
InDetAccessor::ETrackParameters
ETrackParameters
Definition: InDetAccessor.h:30
TrackParticle.h
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
DeMoScan.index
string index
Definition: DeMoScan.py:364
InDetAccessor::getSummary
uint8_t getSummary(const T_TrkHelper &helper, const asg::AsgMessaging &msgHelper, xAOD::SummaryType sumType)
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDetAccessor::TrkTrackHelper::track
const Trk::Track & track() const
Definition: InDetAccessor.h:76
InDetAccessor::TrkTrackHelper
Definition: InDetAccessor.h:71
InDetAccessor::TrackParticleHelper::pt
double pt(const asg::AsgMessaging &) const
Definition: InDetAccessor.h:58
InDetAccessor::TrackParticleHelper::qOverP
double qOverP(const asg::AsgMessaging &) const
Definition: InDetAccessor.h:61
xAOD::eProbabilityHT
@ eProbabilityHT
Electron probability from High Threshold (HT) information [float].
Definition: TrackingPrimitives.h:301
InDetAccessor::TrkTrackHelper::hasSummaryOrError
bool hasSummaryOrError(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:100
InDetAccessor::TrackParticleHelper::eta
double eta(const asg::AsgMessaging &) const
Definition: InDetAccessor.h:59
Trk::SummaryType
SummaryType
enumerates the different types of information stored in Summary.
Definition: Tracking/TrkEvent/TrkTrackSummary/TrkTrackSummary/TrackSummary.h:45
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
InDetAccessor::TrackParticleHelper::TrackParticleHelper
TrackParticleHelper(const xAOD::TrackParticle &a_track, const xAOD::Vertex *a_vtx)
Definition: InDetAccessor.h:52
FitQuality.h
InDetAccessor::TrackParticleHelper::vertex
const xAOD::Vertex * vertex() const
Definition: InDetAccessor.h:56
TrackingPrimitives.h
InDetAccessor::TrkTrackHelper::m_track
const Trk::Track * m_track
Definition: InDetAccessor.h:109
InDetAccessor::TrkTrackHelper::pt
double pt(const asg::AsgMessaging &msgHelper) const
Definition: InDetAccessor.h:80