2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
6#ifndef STRIPCALIBRATORTOOLIMPL_ICC
7#define STRIPCALIBRATORTOOLIMPL_ICC
9#include "InDetReadoutGeometry/SiDetectorElement.h"
10#include "SCT_ReadoutGeometry/StripStereoAnnulusDesign.h"
13namespace ActsTrk::detail{
15 template <typename traj_t>
16 StripCalibratorToolImpl<traj_t>::StripCalibratorToolImpl(const std::string& type,
17 const std::string& name,
18 const IInterface* parent)
19 : base_class(type, name, parent)
22 template <typename traj_t>
23 StatusCode StripCalibratorToolImpl<traj_t>::initialize()
25 ATH_MSG_DEBUG("Initializing " << AthAlgTool::name() << " ...");
27 ATH_MSG_DEBUG(AthAlgTool::name() << " successfully initialized");
29 ATH_MSG_INFO( m_correctCovariance );
30 ATH_MSG_INFO( m_postCalibration );
31 ATH_MSG_INFO( m_errorStrategy );
33 return StatusCode::SUCCESS;
37 template <typename traj_t>
38 const InDetDD::SiDetectorElement& StripCalibrator<traj_t>::getDetectorElement(const Acts::Surface &surface) const
40 const ActsDetectorElement* detElem = dynamic_cast<const ActsDetectorElement*>(surface.surfacePlacement());
41 const InDetDD::SiDetectorElement *siDetElement = detElem ? dynamic_cast<const InDetDD::SiDetectorElement *>(detElem->upstreamDetectorElement()) : nullptr;
43 ATH_MSG_ERROR("Surface without associated SI detector element");
44 throw std::runtime_error("SiDetectorElement is NULL");
49 template <typename traj_t>
50 std::optional<float> StripCalibrator<traj_t>::getCorrectedError(const xAOD::StripCluster& cluster) const
52 std::optional<float> errX {std::nullopt};
53 if (not m_options.m_correctCovariance) {
57 Cov cov = cluster.template localCovariance<1>();
58 int nrows = cluster.channelsInPhi();
60 if (m_options.m_errorStrategy == 0 ) {
62 errX = std::sqrt(cov(0,0));
64 } else if (m_options.m_errorStrategy == 1 ) {
66 errX = std::sqrt(cov(0,0)) / nrows;
74 template <typename traj_t>
76 StripCalibrator<traj_t>::calibrate(
77 const Acts::GeometryContext& gctx,
78 const Acts::CalibrationContext& cctx,
79 const xAOD::StripCluster& cluster,
80 StripCalibrator<traj_t>::TrackStateProxy& trackState) const
82 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(state.referenceSurface());
83 auto [pos,cov,flags] = calibrate(gctx, cctx, cluster);
84 assert( !trackState.hasCalibrated());
85 trackState.allocateCalibrated(1);
86 trackState.template calibrated<1>() = pos.template cast<double>();
87 trackState.template calibratedCovariance<1>() = cov.template cast<double>();
89 trackState.typeFlags().setIsSplitHit();
93 template <typename traj_t>
94 std::tuple<typename StripCalibrator<traj_t>::Pos,
95 typename StripCalibrator<traj_t>::Cov,
97 StripCalibrator<traj_t>::calibrate(
98 const Acts::GeometryContext& gctx,
99 const Acts::CalibrationContext& cctx,
100 [[maybe_unused]] const Acts::Surface& surface,
101 const xAOD::StripCluster& cluster,
102 const Acts::BoundTrackParameters& /*bound_parameters*/) const
104 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(surface);
105 return calibrate(gctx, cctx, cluster);
108 template <typename traj_t>
109 std::tuple<typename StripCalibrator<traj_t>::Pos,
110 typename StripCalibrator<traj_t>::Cov,
112 StripCalibrator<traj_t>::calibrate(
113 const Acts::GeometryContext& /*gctx*/,
114 const Acts::CalibrationContext& /*cctx*/,
115 const xAOD::StripCluster& cluster) const
117 Pos pos = cluster.template localPosition<1>();
118 Cov cov = cluster.template localCovariance<1>();
120 auto errX = getCorrectedError(cluster);
121 if (errX.has_value()) {
122 double newErr = *errX;
123 cov(0, 0) = newErr * newErr;
126 return std::make_tuple(pos, cov,0u);
129 template <typename traj_t>
130 void StripCalibrator<traj_t>::connectOnTrackCalibrator(typename StripCalibrator<traj_t>::BASE::OnTrackCalibrator& stripCalibrator) const
132 using CalibFuncPtr_t =
133 void(StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
134 const Acts::CalibrationContext&,
135 const xAOD::StripCluster&,
136 StripCalibrator<traj_t>::TrackStateProxy&) const;
138 stripCalibrator. template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
141 template <typename traj_t>
142 void StripCalibrator<traj_t>::connectCalibrator(StripOnBoundStateCalibratorBase::Calibrator& stripCalibrator) const
144 using CalibFuncPtr_t =
145 std::tuple<typename StripCalibrator<traj_t>::Pos,
146 typename StripCalibrator<traj_t>::Cov,
148 (StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
149 const Acts::CalibrationContext&,
150 const Acts::Surface &,
151 const xAOD::StripCluster&,
152 const Acts::BoundTrackParameters&) const;
154 stripCalibrator.template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
157 template <typename traj_t>
158 bool StripCalibratorToolImpl<traj_t>::calibrateAfterMeasurementSelection() const
159 { return m_postCalibration.value(); }
161} // namespace ActsTrk::detail