ATLAS Offline Software
Loading...
Searching...
No Matches
OnTrackCalibrator.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "ActsCalibrators/xAODUncalibMeasCalibrator.h"
5#include <utility> // for declval
6
7
8namespace ActsTrk::detail {
9
10 template <typename traj_t>
11 template <typename T_CalibratorToolHandle, typename T_Delegate>
12 void OnTrackCalibrator<traj_t>::connectPassThrough(T_Delegate &delegate) {
13 using CalibratorBase_t = typename decltype( std::declval<T_CalibratorToolHandle>()->createOnTrackCalibrator(std::declval<EventContext>()) )::element_type;
14 delegate.template connect<&OnTrackCalibrator<traj_t>::passthrough<CalibratorBase_t::ClusterDIM,
15 typename CalibratorBase_t::ClusterType>>(this);
16 }
17 template <typename traj_t>
18 template <typename T_CalibratorToolHandle, typename T_Delegate>
19 void OnTrackCalibrator<traj_t>::connect(const EventContext &ctx,
20 const T_CalibratorToolHandle &calibrator_tool,
21 T_Delegate &delegate ) {
22 if (calibrator_tool.isEnabled()) {
23 auto calibrator = calibrator_tool->createOnTrackCalibrator(ctx);
24 calibrator->connectOnTrackCalibrator(delegate);
25 m_calibrators.push_back(std::move(calibrator));
26 } else {
27 connectPassThrough<T_CalibratorToolHandle>(delegate);
28 }
29 }
30
31 template <typename traj_t>
32 OnTrackCalibrator<traj_t>::OnTrackCalibrator(const ActsTrk::ITrackingGeometryTool* trackGeoTool)
33 : m_surfAcc{trackGeoTool} {
34 connectPassThrough<ToolHandle<ActsTrk::IPixelOnTrackCalibratorTool<traj_t> > >(pixelCalibrator);
35 connectPassThrough<ToolHandle<ActsTrk::IStripOnTrackCalibratorTool<traj_t> > >(stripCalibrator);
36 connectPassThrough<ToolHandle<ActsTrk::IHGTDOnTrackCalibratorTool<traj_t> > >(hgtdCalibrator);
37 }
38
39 template <typename traj_t>
40 OnTrackCalibrator<traj_t>::OnTrackCalibrator(const EventContext &ctx,
41 const ActsTrk::ITrackingGeometryTool* trackGeoTool,
42 const ToolHandle<IPixelOnTrackCalibratorTool<traj_t>>& pixelTool,
43 const ToolHandle<IStripOnTrackCalibratorTool<traj_t>>& stripTool,
44 const ToolHandle<IHGTDOnTrackCalibratorTool<traj_t>>& hgtdTool)
45 : m_surfAcc{trackGeoTool} {
46 assert( m_calibrators.capacity() >= 3); // if capacity was constexpr should turn into static_assert
47 connect(ctx,pixelTool,pixelCalibrator);
48 connect(ctx,stripTool,stripCalibrator);
49 connect(ctx,hgtdTool,hgtdCalibrator);
50 }
51
52 template <typename traj_t>
53 void OnTrackCalibrator<traj_t>::calibrate(const Acts::GeometryContext& geoctx,
54 const Acts::CalibrationContext& cctx,
55 const Acts::SourceLink& link,
56 TrackStateProxy state) const {
57
58 const xAOD::UncalibratedMeasurement& measurement{*xAODUncalibMeasCalibrator::unpack(link)};
59 // @TODO in principle only need to lookup surface for strips
60 switch (measurement.type()) {
61 using enum xAOD::UncalibMeasType;
62 using enum ProjectorType;
63 case PixelClusterType: {
64 assert(pixelCalibrator.connected());
65 prepareCalibratedState<2>(e2DimNoTime, link, state);
66 pixelCalibrator(geoctx, cctx,static_cast<const xAOD::PixelCluster&>(measurement), state);
67 break;
68 } case StripClusterType: {
69 assert(stripCalibrator.connected());
70 const Acts::Surface *surface = m_surfAcc.get(&measurement);
71 if (!surface) {
72 throw std::runtime_error("OnTrackCalibrator<traj_t>::calibrate() -- No surface for measurement.");
73 }
74 prepareCalibratedState<1>(surface->bounds().type() == Acts::SurfaceBounds::eAnnulus ? e1DimRotNoTime : e1DimNoTime,
75 link, state);
76 stripCalibrator(geoctx, cctx,static_cast<const xAOD::StripCluster&>(measurement), state);
77 break;
78 } case HGTDClusterType: {
79 assert(hgtdCalibrator.connected());
80 prepareCalibratedState<3>(e2DimWithTime, link, state);
81 hgtdCalibrator(geoctx, cctx,static_cast<const xAOD::HGTDCluster&>(measurement), state);
82 break;
83 } default:
84 throw std::domain_error("OnTrackCalibrator can only handle Pixel or Strip measurements");
85 }
86 }
87
88 template <typename traj_t>
89 template <std::size_t Dim, typename Cluster>
90 void
91 OnTrackCalibrator<traj_t>::passthrough(const Acts::GeometryContext& /*gctx*/,
92 const Acts::CalibrationContext& /*cctx*/,
93 const Cluster& cluster,
94 TrackStateProxy& trackState) const {
95 trackState.allocateCalibrated(Dim);
96 auto pos = trackState.template calibrated<Dim>();
97 auto cov = trackState.template calibratedCovariance<Dim>();
98 pos = cluster.template localPosition<Dim>().template cast<double>();
99 cov = cluster.template localCovariance<Dim>().template cast<double>();
100 if constexpr(std::is_same_v<xAOD::HGTDCluster, std::remove_cvref_t<Cluster> >) {
101 pos(2,0) = ActsTrk::timeToActs(pos(2,0));
102 assert(cov(2,1)==0. && cov(2,0)==0.);
103 cov(2,2) = ActsTrk::timeCovToActs(cov(2,2));
104 assert( ActsTrk::timeToActs( cluster.template localPosition<Dim>().template cast<double>()(2,0) ) == trackState.template calibrated<Dim>()(2,0) );
105 assert( ActsTrk::timeToActs( cluster.template localCovariance<Dim>().template cast<double>()(2,0) ) == trackState.template calibratedCovariance<Dim>()(2,0) );
106 }
107 }
108} // namespace ActsTrk
109