2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
6#ifndef STRIPCALIBRATORTOOLIMPL_ICC
7#define STRIPCALIBRATORTOOLIMPL_ICC
9#include "src/detail/TrackStateFlagHelper.h"
10#include "InDetReadoutGeometry/SiDetectorElement.h"
11#include "SCT_ReadoutGeometry/StripStereoAnnulusDesign.h"
14namespace ActsTrk::detail{
16 template <typename traj_t>
17 StripCalibratorToolImpl<traj_t>::StripCalibratorToolImpl(const std::string& type,
18 const std::string& name,
19 const IInterface* parent)
20 : base_class(type, name, parent)
23 template <typename traj_t>
24 StatusCode StripCalibratorToolImpl<traj_t>::initialize()
26 ATH_MSG_DEBUG("Initializing " << AthAlgTool::name() << " ...");
28 ATH_MSG_DEBUG(AthAlgTool::name() << " successfully initialized");
30 ATH_MSG_INFO( m_correctCovariance );
31 ATH_MSG_INFO( m_postCalibration );
32 ATH_MSG_INFO( m_errorStrategy );
34 return StatusCode::SUCCESS;
38 template <typename traj_t>
39 const InDetDD::SiDetectorElement& StripCalibrator<traj_t>::getDetectorElement(const Acts::Surface &surface) const
41 const auto* detElem = getActsDetectorElement(surface);
42 const InDetDD::SiDetectorElement *siDetElement = detElem ? dynamic_cast<const InDetDD::SiDetectorElement *>(detElem->upstreamDetectorElement()) : nullptr;
44 ATH_MSG_ERROR("Surface without associated SI detector element");
45 throw std::runtime_error("SiDetectorElement is NULL");
50 template <typename traj_t>
51 std::optional<float> StripCalibrator<traj_t>::getCorrectedError(const xAOD::StripCluster& cluster) const
53 std::optional<float> errX {std::nullopt};
54 if (not m_options.m_correctCovariance) {
58 Cov cov = cluster.template localCovariance<1>();
59 int nrows = cluster.channelsInPhi();
61 if (m_options.m_errorStrategy == 0 ) {
63 errX = std::sqrt(cov(0,0));
65 } else if (m_options.m_errorStrategy == 1 ) {
67 errX = std::sqrt(cov(0,0)) / nrows;
75 template <typename traj_t>
77 StripCalibrator<traj_t>::calibrate(
78 const Acts::GeometryContext& gctx,
79 const Acts::CalibrationContext& cctx,
80 const xAOD::StripCluster& cluster,
81 StripCalibrator<traj_t>::TrackStateProxy& trackState) const
83 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(state.referenceSurface());
84 auto [pos,cov,flags] = calibrate(gctx, cctx, cluster);
85 assert( !trackState.hasCalibrated());
86 trackState.allocateCalibrated(1);
87 trackState.template calibrated<1>() = pos.template cast<double>();
88 trackState.template calibratedCovariance<1>() = cov.template cast<double>();
89 if (testTrackStateFlag(Acts::TrackStateFlag::IsSplitHit, flags)) {
90 trackState.typeFlags().setIsSplitHit();
94 template <typename traj_t>
95 std::tuple<typename StripCalibrator<traj_t>::Pos,
96 typename StripCalibrator<traj_t>::Cov,
98 StripCalibrator<traj_t>::calibrate(
99 const Acts::GeometryContext& gctx,
100 const Acts::CalibrationContext& cctx,
101 [[maybe_unused]] const Acts::Surface& surface,
102 const xAOD::StripCluster& cluster,
103 const Acts::BoundTrackParameters& /*bound_parameters*/) const
105 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(surface);
106 return calibrate(gctx, cctx, cluster);
109 template <typename traj_t>
110 std::tuple<typename StripCalibrator<traj_t>::Pos,
111 typename StripCalibrator<traj_t>::Cov,
113 StripCalibrator<traj_t>::calibrate(
114 const Acts::GeometryContext& /*gctx*/,
115 const Acts::CalibrationContext& /*cctx*/,
116 const xAOD::StripCluster& cluster) const
118 Pos pos = cluster.template localPosition<1>();
119 Cov cov = cluster.template localCovariance<1>();
121 auto errX = getCorrectedError(cluster);
122 if (errX.has_value()) {
123 double newErr = *errX;
124 cov(0, 0) = newErr * newErr;
127 return std::make_tuple(pos, cov,0u);
130 template <typename traj_t>
131 void StripCalibrator<traj_t>::connectOnTrackCalibrator(typename StripCalibrator<traj_t>::BASE::OnTrackCalibrator& stripCalibrator) const
133 using CalibFuncPtr_t =
134 void(StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
135 const Acts::CalibrationContext&,
136 const xAOD::StripCluster&,
137 StripCalibrator<traj_t>::TrackStateProxy&) const;
139 stripCalibrator. template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
142 template <typename traj_t>
143 void StripCalibrator<traj_t>::connectCalibrator(StripOnBoundStateCalibratorBase::Calibrator& stripCalibrator) const
145 using CalibFuncPtr_t =
146 std::tuple<typename StripCalibrator<traj_t>::Pos,
147 typename StripCalibrator<traj_t>::Cov,
149 (StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
150 const Acts::CalibrationContext&,
151 const Acts::Surface &,
152 const xAOD::StripCluster&,
153 const Acts::BoundTrackParameters&) const;
155 stripCalibrator.template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
158 template <typename traj_t>
159 bool StripCalibratorToolImpl<traj_t>::calibrateAfterMeasurementSelection() const
160 { return m_postCalibration.value(); }
162} // namespace ActsTrk::detail