ATLAS Offline Software
Loading...
Searching...
No Matches
MeasurementCalibrator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MEASUREMENTCALIBRATOR2_H
5#define MEASUREMENTCALIBRATOR2_H
6
7#include "Acts/EventData/Types.hpp"
14#include "AthenaKernel/Units.h"
15
16#include "Acts/EventData/MultiTrajectory.hpp"
17#include "Acts/EventData/BoundTrackParameters.hpp"
18#include "Acts/Geometry/GeometryIdentifier.hpp"
19#include "Acts/Surfaces/Surface.hpp"
20#include "Acts/Surfaces/SurfaceBounds.hpp"
21#include "Acts/Definitions/TrackParametrization.hpp"
22#include "Acts/Utilities/AlgebraHelpers.hpp"
23#include <Eigen/Core>
24
30
31#include "boost/container/static_vector.hpp"
32
33#include <stdexcept>
34#include <string>
35#include <cassert>
36
37namespace ActsTrk {
38 // helper to create map from nound track parameters to measurements
40
41 std::array<unsigned char, 128> m_volumeIdToMeasurementType{};
42 xAOD::UncalibMeasType measurementTypeFromVolumeId(unsigned int volume_id) const {
43 unsigned char shift = (volume_id%2) ? 4 : 0;
44 unsigned char idx = volume_id/2;
45 return static_cast<xAOD::UncalibMeasType>((m_volumeIdToMeasurementType[idx] >> shift) & 0xf);
46 }
48 static_assert( static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes) < 16u );
49 unsigned char shift = (volume_id%2) ? 4 : 0;
50 unsigned char idx = volume_id/2;
51 m_volumeIdToMeasurementType[idx] |= ((static_cast<unsigned int>(type) & 0xf) << shift);
52 }
54 // @TODO get mapping from converter tool ?
55 std::vector<unsigned int> pixel_vol {16, 15, 9, 20, 19, 18, 10, 14, 13, 8};
56 for (unsigned int vol_id : pixel_vol) {
58 }
59 std::vector<unsigned int> strip_vol {23, 22, 24};
60 for (unsigned int vol_id : strip_vol) {
62 }
63 std::vector<unsigned int> hgtd_vol {2, 25};
64 for (unsigned int vol_id : hgtd_vol) {
66 }
67 }
68
69 template <std::size_t DIM>
70 Acts::SubspaceIndices<DIM> parameterMap([[maybe_unused]] const Acts::GeometryContext&,
71 [[maybe_unused]] const Acts::CalibrationContext&,
72 const Acts::Surface &surface) const {
73 // @TODO make interface measurement type aware ?
74 if constexpr(DIM==3) {
75 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::HGTDClusterType );
77 }
78 else if constexpr(DIM==2) {
79 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::PixelClusterType );
81 }
82 else if constexpr(DIM==1) {
83 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::StripClusterType );
84 auto boundType = surface.bounds().type();
85 const std::size_t projector_idx = boundType == Acts::SurfaceBounds::eAnnulus;
86 return s_stripSubspaceIndices[projector_idx];
87 }
88 else {
89 throw std::runtime_error("Unsupported dimension");
90 }
91
92 }
93
94 constexpr static std::array<Acts::SubspaceIndices<1>, 2> s_stripSubspaceIndices = {
95 {{Acts::eBoundLoc0}, // normal strip: x -> l0
96 {Acts::eBoundLoc1}} // annulus strip: y -> l0
97 };
98 constexpr static Acts::SubspaceIndices<2> s_pixelSubspaceIndices = {
99 Acts::eBoundLoc0, Acts::eBoundLoc1
100 };
101 constexpr static Acts::SubspaceIndices<3> s_hgtdSubspaceIndices = {
102 Acts::eBoundLoc0, Acts::eBoundLoc1, Acts::eBoundTime
103 };
104 };
105
106
110 // @TODO should pass through bound state
111 using PixelCalibrator = Acts::Delegate<
112 std::pair<PixelPos, PixelCov>(const Acts::GeometryContext&,
113 const Acts::CalibrationContext&,
114 const Acts::Surface&,
115 const xAOD::PixelCluster &,
116 const Acts::BoundTrackParameters &)>;
117
120 using StripCalibrator = Acts::Delegate<
121 std::pair<StripPos, StripCov>(const Acts::GeometryContext&,
122 const Acts::CalibrationContext&,
123 const Acts::Surface&,
124 const xAOD::StripCluster &,
125 const Acts::BoundTrackParameters &)>;
128 using HGTDCalibrator = Acts::Delegate<
129 std::pair<hgtdPos, hgtdCov>(const Acts::GeometryContext&,
130 const Acts::CalibrationContext&,
131 const Acts::Surface&,
132 const xAOD::HGTDCluster &,
133 const Acts::BoundTrackParameters &)>;
134
141 boost::container::static_vector<std::unique_ptr<ClusterCalibratorBase >, 3> m_calibrators;
142
143 template <typename T_CalibratorTool, typename T_Delegate>
144 void connect(const EventContext &ctx,
145 const T_CalibratorTool *calibrator_tool,
146 T_Delegate &pre_calibrator,
147 T_Delegate &post_calibrator) {
148 bool calibrate_after_measurement_selection=true;
149 if (calibrator_tool) {
150 calibrate_after_measurement_selection = calibrator_tool->calibrateAfterMeasurementSelection();
151 auto calibrator = calibrator_tool->create(ctx);
152 calibrator->connectCalibrator( calibrate_after_measurement_selection ?
153 post_calibrator : pre_calibrator );
154 m_calibrators.push_back(std::move(calibrator));
155 }
156 if (calibrate_after_measurement_selection) {
157 using CalibratorBase_t = typename decltype( calibrator_tool->create(ctx) )::element_type;
158 pre_calibrator.template connect<&MeasurementCalibrator::passthrough<CalibratorBase_t::ClusterDIM,
159 typename CalibratorBase_t::ClusterType>>(this);
160 }
161 }
162
163 MeasurementCalibrator(const EventContext &ctx,
164 const IPixelOnBoundStateCalibratorTool *pixelCalibratorTool,
165 const IStripOnBoundStateCalibratorTool *stripCalibratorTool,
166 const IHGTDOnBoundStateCalibratorTool *hgtdCalibratorTool)
167 {
168 assert( m_calibrators.capacity() >= 3); // if capacity was constexpr should turn into static_assert
169 connect(ctx,pixelCalibratorTool,pixel_preCalibrator,pixel_postCalibrator);
170 connect(ctx,stripCalibratorTool,strip_preCalibrator,strip_postCalibrator);
171 connect(ctx,hgtdCalibratorTool, hgtd_preCalibrator, hgtd_postCalibrator);
172 }
173
180
181
182 template <std::size_t Dim, typename Cluster>
183 std::pair<xAOD::MeasVector<Dim>, xAOD::MeasMatrix<Dim>>
184 passthrough([[maybe_unused]] const Acts::GeometryContext& gctx,
185 [[maybe_unused]] const Acts::CalibrationContext& cctx,
186 [[maybe_unused]] const Acts::Surface& surface,
187 const Cluster &cluster,
188 const Acts::BoundTrackParameters &) const
189 {
190 auto ret = std::make_pair<xAOD::MeasVector<Dim>, xAOD::MeasMatrix<Dim>>(cluster.template localPosition<Dim>(),
191 cluster.template localCovariance<Dim>());
192 if constexpr(std::is_same_v<xAOD::HGTDCluster, std::remove_cvref_t<Cluster> >) {
193 ret.first(2,0) = ActsTrk::timeToActs(ret.first(2,0));
194 assert(ret.second(2,1)==0. && ret.second(2,0)==0.);
195 ret.second(2,2) = ActsTrk::timeCovToActs(ret.second(2,2));
196 }
197 return ret;
198 }
199 };
200
201}
202#endif
Wrapper to avoid constant divisions when using units.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
constexpr auto timeCovToActs(T athenaTCov)
Converts a time covariance element from Athena to Acts units.
constexpr auto timeToActs(T athenaT)
Converts a time unit from Athena to Acts units.
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
Eigen::Matrix< float, N, N > MeasMatrix
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
UncalibMeasType
Define the type of the uncalibrated measurement.
HGTDCluster_v1 HGTDCluster
Define the version of the pixel cluster class.
Definition HGTDCluster.h:13
const StripCalibrator & stripPostCalibrator() const
Acts::Delegate< std::pair< StripPos, StripCov >(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &, const xAOD::StripCluster &, const Acts::BoundTrackParameters &)> StripCalibrator
std::pair< xAOD::MeasVector< Dim >, xAOD::MeasMatrix< Dim > > passthrough(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::Surface &surface, const Cluster &cluster, const Acts::BoundTrackParameters &) const
void connect(const EventContext &ctx, const T_CalibratorTool *calibrator_tool, T_Delegate &pre_calibrator, T_Delegate &post_calibrator)
const PixelCalibrator & pixelPreCalibrator() const
const StripCalibrator & stripPreCalibrator() const
Acts::Delegate< std::pair< hgtdPos, hgtdCov >(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &, const xAOD::HGTDCluster &, const Acts::BoundTrackParameters &)> HGTDCalibrator
const PixelCalibrator & pixelPostCalibrator() const
Acts::Delegate< std::pair< PixelPos, PixelCov >(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &, const xAOD::PixelCluster &, const Acts::BoundTrackParameters &)> PixelCalibrator
const HGTDCalibrator & hgtdPreCalibrator() const
MeasurementCalibrator(const EventContext &ctx, const IPixelOnBoundStateCalibratorTool *pixelCalibratorTool, const IStripOnBoundStateCalibratorTool *stripCalibratorTool, const IHGTDOnBoundStateCalibratorTool *hgtdCalibratorTool)
const HGTDCalibrator & hgtdPostCalibrator() const
boost::container::static_vector< std::unique_ptr< ClusterCalibratorBase >, 3 > m_calibrators
void setMeasurementTypeForVolumeId(unsigned int volume_id, xAOD::UncalibMeasType type)
static constexpr Acts::SubspaceIndices< 2 > s_pixelSubspaceIndices
static constexpr std::array< Acts::SubspaceIndices< 1 >, 2 > s_stripSubspaceIndices
Acts::SubspaceIndices< DIM > parameterMap(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &surface) const
std::array< unsigned char, 128 > m_volumeIdToMeasurementType
static constexpr Acts::SubspaceIndices< 3 > s_hgtdSubspaceIndices
xAOD::UncalibMeasType measurementTypeFromVolumeId(unsigned int volume_id) const