ATLAS Offline Software
MeasurementCalibrator.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MEASUREMENTCALIBRATOR_H
6 #define MEASUREMENTCALIBRATOR_H
7 
13 
14 #include "Acts/EventData/MultiTrajectory.hpp"
15 #include "Acts/Geometry/GeometryIdentifier.hpp"
16 #include "Acts/Surfaces/Surface.hpp"
17 #include "Acts/Surfaces/SurfaceBounds.hpp"
18 #include "Acts/Definitions/TrackParametrization.hpp"
19 #include "Acts/Utilities/AlgebraHelpers.hpp"
20 #include <Eigen/Core>
21 
25 
27 
28 #include <stdexcept>
29 #include <string>
30 #include <cassert>
31 
32 namespace ActsTrk {
34 {
35 protected:
36  template <typename Derived>
37  static Acts::ProjectorBitset makeProjectorBitset(const Eigen::MatrixBase<Derived> &proj) {
38  constexpr int rows = Eigen::MatrixBase<Derived>::RowsAtCompileTime;
39  constexpr int cols = Eigen::MatrixBase<Derived>::ColsAtCompileTime;
40 
41  Acts::TrackStateTraits<Acts::MultiTrajectoryTraits::MeasurementSizeMax>::Projector fullProjector =
42  decltype(fullProjector)::Zero();
43 
44  fullProjector.template topLeftCorner<rows, cols>() = proj;
45 
46  return Acts::matrixToBitset(fullProjector).to_ullong();
47  }
48 
49  static Acts::ProjectorBitset makeStripProjector(bool annulus_strip) {
50  Acts::ActsMatrix<Acts::MultiTrajectoryTraits::MeasurementSizeMax, 2> proj;
51  proj.setZero();
52  if (annulus_strip) {
53  // transforms predicted[1] -> calibrated[0] in Acts::MeasurementSelector::calculateChi2()
54  proj(Acts::eBoundLoc0, Acts::eBoundLoc1) = 1;
55  } else {
56  proj(Acts::eBoundLoc0, Acts::eBoundLoc0) = 1;
57  }
58  return makeProjectorBitset(proj);
59  }
60  // create strip projector bitsets for normal and annulus bounds
61  static std::array<Acts::ProjectorBitset,2> makeStripProjectorArray() {
62  return std::array<Acts::ProjectorBitset,2>{makeStripProjector(false), makeStripProjector(true) };
63  }
64 
65  // create pixel projector bitsets
66  static Acts::ProjectorBitset makePixelProjector() {
67  Acts::ActsMatrix<Acts::MultiTrajectoryTraits::MeasurementSizeMax, 2> proj;
68  proj.setZero();
69  proj(Acts::eBoundLoc0, Acts::eBoundLoc0) = 1;
70  proj(Acts::eBoundLoc1, Acts::eBoundLoc1) = 1;
71  return makeProjectorBitset(proj);
72  }
73 
74  // unfortunately cannot make static constexpr because of eigen
75  // could make static but usage easier if the projectors are members
76  std::array<Acts::ProjectorBitset,2> m_stripProjector; // strip projector for normal and annulus bounds
77  Acts::ProjectorBitset m_pixelProjector;
78 
80 public:
84  m_converterTool(&converter_tool) { assert(m_converterTool); }
85 
86  template <typename state_t>
88  Acts::SurfaceBounds::BoundsType boundType,
89  state_t &trackState ) const {
90  switch (measType) {
92  const std::size_t projector_idx = boundType == Acts::SurfaceBounds::eAnnulus;
93  trackState.setProjectorBitset(m_stripProjector[projector_idx]);
94  break;
95  }
97  trackState.setProjectorBitset(m_pixelProjector);
98  break;
99  }
100  default:
101  throw std::domain_error("Can only handle measurement type pixel or strip");
102  }
103  }
104 
105  template <size_t Dim, typename pos_t, typename cov_t, typename state_t>
106  inline void setState(xAOD::UncalibMeasType measType,
107  const pos_t& locpos,
108  const cov_t& cov,
109  Acts::SurfaceBounds::BoundsType boundType,
110  state_t &trackState) const {
111  trackState.allocateCalibrated(Dim);
112  setProjectorBitSet(measType, boundType, trackState);
113  trackState.template calibrated<Dim>() = locpos.template cast<Acts::ActsScalar>();
114  trackState.template calibratedCovariance<Dim>() = cov.template cast<Acts::ActsScalar>();
115  }
116 
117 
118  template <class measurement_t, typename trajectory_t>
119  inline void setStateFromMeasurement(const measurement_t &measurement,
120  Acts::SurfaceBounds::BoundsType bound_type,
121  typename Acts::MultiTrajectory<trajectory_t>::TrackStateProxy &trackState ) const {
122  switch (measurement.type()) {
124  setState<1>(
125  measurement.type(),
126  measurement.template localPosition<1>(),
127  measurement.template localCovariance<1>().template topLeftCorner<1, 1>(),
128  bound_type,
129  trackState);
130  break;
131  }
133  setState<2>(
134  measurement.type(),
135  measurement.template localPosition<2>(),
136  measurement.template localCovariance<2>().template topLeftCorner<2, 2>(),
137  bound_type,
138  trackState);
139  break;
140  }
141  default:
142  throw std::domain_error("Can only handle measurement type pixel or strip");
143  }
144  }
145 
146 };
147 
149 public:
151  public:
152  MeasurementAdapter(const Trk::MeasurementBase &measurement) : m_measurement(&measurement) {}
154  switch (m_measurement->localParameters().dimension()) {
155  case 1: {
157  }
158  case 2: {
160  }
161  default: {
163  }
164  }
165  }
166  template <std::size_t DIM>
167  inline const Trk::LocalParameters& localPosition() const {
168  assert( m_measurement && DIM == m_measurement->localParameters().dimension());
169  return m_measurement->localParameters();
170  }
171  template <std::size_t DIM>
172  inline const Amg::MatrixX &localCovariance() const {
173  assert( m_measurement && DIM == m_measurement->localParameters().dimension());
174  return m_measurement->localCovariance();
175  }
176  private:
178  };
179 
181  : MeasurementCalibratorBase(converter_tool) {}
182 
183  template <typename trajectory_t>
184  void calibrate([[maybe_unused]] const Acts::GeometryContext &gctx,
185  [[maybe_unused]] const Acts::CalibrationContext & cctx,
186  const Acts::SourceLink& sl,
187  typename Acts::MultiTrajectory<trajectory_t>::TrackStateProxy trackState) const {
188  auto sourceLink = sl.template get<ATLASSourceLink>();
189  trackState.setUncalibratedSourceLink(sl);
190  assert(sourceLink);
191  const Acts::Surface &surface = this->m_converterTool->trkSurfaceToActsSurface(sourceLink->associatedSurface());
192  this->setStateFromMeasurement<MeasurementAdapter, trajectory_t>(MeasurementAdapter(*sourceLink),
193  surface.bounds().type(),
194  trackState);
195  }
196 };
197 }
198 #endif
StripCluster.h
Trk::LocalParameters
Definition: LocalParameters.h:98
UncalibratedMeasurement.h
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
MeasurementBase.h
ActsTrk::TrkMeasurementCalibrator::TrkMeasurementCalibrator
TrkMeasurementCalibrator(const ActsTrk::IActsToTrkConverterTool &converter_tool)
Definition: MeasurementCalibrator.h:180
xAOD::UncalibMeasType::StripClusterType
@ StripClusterType
IOnTrackCalibratorTool.h
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
ActsTrk::MeasurementCalibratorBase
Definition: MeasurementCalibrator.h:34
ActsTrk::TrkMeasurementCalibrator
Definition: MeasurementCalibrator.h:148
TrackingSurfaceHelper.h
ActsTrk::MeasurementCalibratorBase::makePixelProjector
static Acts::ProjectorBitset makePixelProjector()
Definition: MeasurementCalibrator.h:66
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter::MeasurementAdapter
MeasurementAdapter(const Trk::MeasurementBase &measurement)
Definition: MeasurementCalibrator.h:152
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter::localCovariance
const Amg::MatrixX & localCovariance() const
Definition: MeasurementCalibrator.h:172
ActsTrk::MeasurementCalibratorBase::m_converterTool
const ActsTrk::IActsToTrkConverterTool * m_converterTool
Definition: MeasurementCalibrator.h:79
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter::m_measurement
const Trk::MeasurementBase * m_measurement
Definition: MeasurementCalibrator.h:177
ActsTrk::IActsToTrkConverterTool::trkSurfaceToActsSurface
virtual const Acts::Surface & trkSurfaceToActsSurface(const Trk::Surface &atlasSurface) const =0
beamspotnt.cols
list cols
Definition: bin/beamspotnt.py:1114
ActsTrk::MeasurementCalibratorBase::MeasurementCalibratorBase
MeasurementCalibratorBase(const ActsTrk::IActsToTrkConverterTool &converter_tool)
Definition: MeasurementCalibrator.h:81
ActsTrk::MeasurementCalibratorBase::setStateFromMeasurement
void setStateFromMeasurement(const measurement_t &measurement, Acts::SurfaceBounds::BoundsType bound_type, typename Acts::MultiTrajectory< trajectory_t >::TrackStateProxy &trackState) const
Definition: MeasurementCalibrator.h:119
ActsTrk::TrkMeasurementCalibrator::calibrate
void calibrate([[maybe_unused]] const Acts::GeometryContext &gctx, [[maybe_unused]] const Acts::CalibrationContext &cctx, const Acts::SourceLink &sl, typename Acts::MultiTrajectory< trajectory_t >::TrackStateProxy trackState) const
Definition: MeasurementCalibrator.h:184
ActsTrk::MeasurementCalibratorBase::m_pixelProjector
Acts::ProjectorBitset m_pixelProjector
Definition: MeasurementCalibrator.h:77
ActsTrk::IActsToTrkConverterTool
Definition: IActsToTrkConverterTool.h:43
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter::localPosition
const Trk::LocalParameters & localPosition() const
Definition: MeasurementCalibrator.h:167
PixelCluster.h
xAOD::Other
@ Other
ActsTrk::MeasurementCalibratorBase::makeStripProjectorArray
static std::array< Acts::ProjectorBitset, 2 > makeStripProjectorArray()
Definition: MeasurementCalibrator.h:61
beamspotnt.rows
list rows
Definition: bin/beamspotnt.py:1112
MeasurementDefs.h
make_coralServer_rep.proj
proj
Definition: make_coralServer_rep.py:48
Trk::MeasurementBase::localCovariance
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Definition: MeasurementBase.h:138
Trk::MeasurementBase
Definition: MeasurementBase.h:58
ActsTrk::MeasurementCalibratorBase::setState
void setState(xAOD::UncalibMeasType measType, const pos_t &locpos, const cov_t &cov, Acts::SurfaceBounds::BoundsType boundType, state_t &trackState) const
Definition: MeasurementCalibrator.h:106
ActsTrk::MeasurementCalibratorBase::setProjectorBitSet
void setProjectorBitSet(xAOD::UncalibMeasType measType, Acts::SurfaceBounds::BoundsType boundType, state_t &trackState) const
Definition: MeasurementCalibrator.h:87
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter::type
xAOD::UncalibMeasType type() const
Definition: MeasurementCalibrator.h:153
Trk::MeasurementBase::localParameters
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Definition: MeasurementBase.h:132
Trk::LocalParameters::dimension
int dimension() const
Dimension of this localParameters() vector.
ActsTrk::MeasurementCalibratorBase::makeProjectorBitset
static Acts::ProjectorBitset makeProjectorBitset(const Eigen::MatrixBase< Derived > &proj)
Definition: MeasurementCalibrator.h:37
ActsTrk::MeasurementCalibratorBase::m_stripProjector
std::array< Acts::ProjectorBitset, 2 > m_stripProjector
Definition: MeasurementCalibrator.h:76
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:24
IActsToTrkConverterTool.h
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:34
ActsTrk::MeasurementCalibratorBase::makeStripProjector
static Acts::ProjectorBitset makeStripProjector(bool annulus_strip)
Definition: MeasurementCalibrator.h:49
ActsTrk::TrkMeasurementCalibrator::MeasurementAdapter
Definition: MeasurementCalibrator.h:150
xAOD::UncalibMeasType::PixelClusterType
@ PixelClusterType