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#include <tuple>
37
38namespace ActsTrk {
39 // helper to create map from nound track parameters to measurements
41
42 std::array<unsigned char, 128> m_volumeIdToMeasurementType{};
43 xAOD::UncalibMeasType measurementTypeFromVolumeId(unsigned int volume_id) const {
44 unsigned char shift = (volume_id%2) ? 4 : 0;
45 unsigned char idx = volume_id/2;
46 return static_cast<xAOD::UncalibMeasType>((m_volumeIdToMeasurementType[idx] >> shift) & 0xf);
47 }
49 static_assert( static_cast<unsigned int>(xAOD::UncalibMeasType::nTypes) < 16u );
50 unsigned char shift = (volume_id%2) ? 4 : 0;
51 unsigned char idx = volume_id/2;
52 m_volumeIdToMeasurementType[idx] |= ((static_cast<unsigned int>(type) & 0xf) << shift);
53 }
55 // @TODO get mapping from converter tool ?
56 std::vector<unsigned int> pixel_vol {16, 15, 9, 20, 19, 18, 10, 14, 13, 8};
57 for (unsigned int vol_id : pixel_vol) {
59 }
60 std::vector<unsigned int> strip_vol {23, 22, 24};
61 for (unsigned int vol_id : strip_vol) {
63 }
64 std::vector<unsigned int> hgtd_vol {2, 25};
65 for (unsigned int vol_id : hgtd_vol) {
67 }
68 }
69
70 template <std::size_t DIM>
71 Acts::SubspaceIndices<DIM> parameterMap([[maybe_unused]] const Acts::GeometryContext&,
72 [[maybe_unused]] const Acts::CalibrationContext&,
73 const Acts::Surface &surface) const {
74 // @TODO make interface measurement type aware ?
75 if constexpr(DIM==3) {
76 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::HGTDClusterType );
78 }
79 else if constexpr(DIM==2) {
80 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::PixelClusterType );
82 }
83 else if constexpr(DIM==1) {
84 assert( measurementTypeFromVolumeId(surface.geometryId().volume()) == xAOD::UncalibMeasType::StripClusterType );
85 auto boundType = surface.bounds().type();
86 const std::size_t projector_idx = boundType == Acts::SurfaceBounds::eAnnulus;
87 return s_stripSubspaceIndices[projector_idx];
88 }
89 else {
90 throw std::runtime_error("Unsupported dimension");
91 }
92
93 }
94
95 constexpr static std::array<Acts::SubspaceIndices<1>, 2> s_stripSubspaceIndices = {
96 {{Acts::eBoundLoc0}, // normal strip: x -> l0
97 {Acts::eBoundLoc1}} // annulus strip: y -> l0
98 };
99 constexpr static Acts::SubspaceIndices<2> s_pixelSubspaceIndices = {
100 Acts::eBoundLoc0, Acts::eBoundLoc1
101 };
102 constexpr static Acts::SubspaceIndices<3> s_hgtdSubspaceIndices = {
103 Acts::eBoundLoc0, Acts::eBoundLoc1, Acts::eBoundTime
104 };
105 };
106
107
108 template <typename traj_t>
112 // @TODO should pass through bound state
113 template <typename T_Cluster, std::size_t NDIM>
114 using PreCalibratorDelegate = Acts::Delegate<
115 std::tuple<xAOD::MeasVector<NDIM>, xAOD::MeasMatrix<NDIM>,unsigned int>(const Acts::GeometryContext&,
116 const Acts::CalibrationContext&,
117 const Acts::Surface&,
118 const T_Cluster &,
119 const Acts::BoundTrackParameters &)>;
120
121 template <typename T_Cluster, std::size_t NDIM>
122 using CalibratorDelegate = Acts::Delegate<
123 void(const Acts::GeometryContext&,
124 const Acts::CalibrationContext&,
125 const T_Cluster &,
126 typename traj_t::TrackStateProxy &)>;
127
132
139
146 boost::container::static_vector<std::unique_ptr<ClusterCalibratorBase >, 3> m_calibrators;
147
148 template <typename T_CalibratorTool, typename T_PreDelegate, typename T_PostDelegate>
149 void connect(const EventContext &ctx,
150 const T_CalibratorTool *calibrator_tool,
151 T_PreDelegate &pre_calibrator,
152 T_PostDelegate &post_calibrator) {
153 bool calibrate_after_measurement_selection=true;
154 if (calibrator_tool) {
155 calibrate_after_measurement_selection = calibrator_tool->calibrateAfterMeasurementSelection();
156 auto calibrator = calibrator_tool->createOnTrackCalibrator(ctx);
157 if (calibrate_after_measurement_selection) {
158 calibrator->connectOnTrackCalibrator( post_calibrator);
159 }
160 else {
161 calibrator->connectCalibrator( pre_calibrator );
162 }
163 m_calibrators.push_back(std::move(calibrator));
164 }
165 if (calibrate_after_measurement_selection) {
166 using CalibratorBase_t = typename decltype( calibrator_tool->create(ctx) )::element_type;
167 pre_calibrator.template connect<&MeasurementCalibrator::passthrough<CalibratorBase_t::ClusterDIM,
168 typename CalibratorBase_t::ClusterType>>(this);
169 }
170 }
171
172 MeasurementCalibrator(const EventContext &ctx,
173 const ActsTrk::IPixelOnTrackCalibratorTool<traj_t> *pixelCalibratorTool,
174 const ActsTrk::IStripOnTrackCalibratorTool<traj_t> *stripCalibratorTool,
175 const ActsTrk::IHGTDOnTrackCalibratorTool<traj_t> *hgtdCalibratorTool)
176 {
177 assert( m_calibrators.capacity() >= 3); // if capacity was constexpr should turn into static_assert
178 connect(ctx,pixelCalibratorTool,pixel_preCalibrator,pixel_postCalibrator);
179 connect(ctx,stripCalibratorTool,strip_preCalibrator,strip_postCalibrator);
180 connect(ctx,hgtdCalibratorTool, hgtd_preCalibrator, hgtd_postCalibrator);
181 }
182
189
190
191 template <std::size_t Dim, typename Cluster>
192 std::tuple<xAOD::MeasVector<Dim>, xAOD::MeasMatrix<Dim>, unsigned int>
193 passthrough([[maybe_unused]] const Acts::GeometryContext& gctx,
194 [[maybe_unused]] const Acts::CalibrationContext& cctx,
195 [[maybe_unused]] const Acts::Surface& surface,
196 const Cluster &cluster,
197 const Acts::BoundTrackParameters &) const
198 {
199 auto ret = std::make_tuple<xAOD::MeasVector<Dim>, xAOD::MeasMatrix<Dim>, unsigned int>(cluster.template localPosition<Dim>(),
200 cluster.template localCovariance<Dim>(),
201 0u);
202 if constexpr(std::is_same_v<xAOD::HGTDCluster, std::remove_cvref_t<Cluster> >) {
203 std::get<0>(ret)(2,0) = ActsTrk::timeToActs(std::get<0>(ret)(2,0));
204 assert(std::get<1>(ret)(2,1)==0. && std::get<1>(ret)(2,0)==0.);
205 std::get<1>(ret)(2,2) = ActsTrk::timeCovToActs(std::get<1>(ret)(2,2));
206 }
207 return ret;
208 }
209
210 };
211
212}
213#endif
Wrapper to avoid constant divisions when using units.
Algorithm comparing pixel and strip xAOD clusters and xAOD spacepoint containers to each other.
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.
Eigen::Matrix< float, N, N > MeasMatrix
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
UncalibMeasType
Define the type of the uncalibrated measurement.
const PixelPreCalibrator & pixelPreCalibrator() const
const StripCalibrator & stripPostCalibrator() const
std::tuple< xAOD::MeasVector< Dim >, xAOD::MeasMatrix< Dim >, unsigned int > passthrough(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::Surface &surface, const Cluster &cluster, const Acts::BoundTrackParameters &) const
Acts::Delegate< std::tuple< xAOD::MeasVector< NDIM >, xAOD::MeasMatrix< NDIM >, unsigned int >(const Acts::GeometryContext &, const Acts::CalibrationContext &, const Acts::Surface &, const T_Cluster &, const Acts::BoundTrackParameters &)> PreCalibratorDelegate
CalibratorDelegate< xAOD::HGTDCluster, 3 > HGTDCalibrator
PreCalibratorDelegate< xAOD::HGTDCluster, 3 > HGTDPreCalibrator
CalibratorDelegate< xAOD::StripCluster, 1 > StripCalibrator
const HGTDCalibrator & hgtdPostCalibrator() const
const HGTDPreCalibrator & hgtdPreCalibrator() const
Acts::Delegate< void(const Acts::GeometryContext &, const Acts::CalibrationContext &, const T_Cluster &, typename traj_t::TrackStateProxy &)> CalibratorDelegate
void connect(const EventContext &ctx, const T_CalibratorTool *calibrator_tool, T_PreDelegate &pre_calibrator, T_PostDelegate &post_calibrator)
CalibratorDelegate< xAOD::PixelCluster, 2 > PixelCalibrator
const StripPreCalibrator & stripPreCalibrator() const
PreCalibratorDelegate< xAOD::StripCluster, 1 > StripPreCalibrator
MeasurementCalibrator(const EventContext &ctx, const ActsTrk::IPixelOnTrackCalibratorTool< traj_t > *pixelCalibratorTool, const ActsTrk::IStripOnTrackCalibratorTool< traj_t > *stripCalibratorTool, const ActsTrk::IHGTDOnTrackCalibratorTool< traj_t > *hgtdCalibratorTool)
boost::container::static_vector< std::unique_ptr< ClusterCalibratorBase >, 3 > m_calibrators
const PixelCalibrator & pixelPostCalibrator() const
PreCalibratorDelegate< xAOD::PixelCluster, 2 > PixelPreCalibrator
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