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>
75 std::pair<typename StripCalibrator<traj_t>::Pos,
76 typename StripCalibrator<traj_t>::Cov>
77 StripCalibrator<traj_t>::calibrate(
78 const Acts::GeometryContext& gctx,
79 const Acts::CalibrationContext& cctx,
80 const xAOD::StripCluster& cluster,
81 const StripCalibrator<traj_t>::TrackStateProxy& /*state*/) const
83 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(state.referenceSurface());
84 return calibrate(gctx, cctx, cluster);
87 template <typename traj_t>
88 std::pair<typename StripCalibrator<traj_t>::Pos,
89 typename StripCalibrator<traj_t>::Cov>
90 StripCalibrator<traj_t>::calibrate(
91 const Acts::GeometryContext& gctx,
92 const Acts::CalibrationContext& cctx,
93 [[maybe_unused]] const Acts::Surface& surface,
94 const xAOD::StripCluster& cluster,
95 const Acts::BoundTrackParameters& /*bound_parameters*/) const
97 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(surface);
98 return calibrate(gctx, cctx, cluster);
101 template <typename traj_t>
102 std::pair<typename StripCalibrator<traj_t>::Pos,
103 typename StripCalibrator<traj_t>::Cov>
104 StripCalibrator<traj_t>::calibrate(
105 const Acts::GeometryContext& /*gctx*/,
106 const Acts::CalibrationContext& /*cctx*/,
107 const xAOD::StripCluster& cluster) const
109 Pos pos = cluster.template localPosition<1>();
110 Cov cov = cluster.template localCovariance<1>();
112 auto errX = getCorrectedError(cluster);
113 if (errX.has_value()) {
114 double newErr = *errX;
115 cov(0, 0) = newErr * newErr;
118 return std::make_pair(pos, cov);
121 template <typename traj_t>
122 void StripCalibrator<traj_t>::connectOnTrackCalibrator(typename StripCalibrator<traj_t>::BASE::OnTrackCalibrator& stripCalibrator) const
124 using CalibFuncPtr_t =
125 std::pair<typename StripCalibrator<traj_t>::Pos, typename StripCalibrator<traj_t>::Cov>
126 (StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
127 const Acts::CalibrationContext&,
128 const xAOD::StripCluster&,
129 const StripCalibrator<traj_t>::TrackStateProxy&) const;
131 stripCalibrator. template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
134 template <typename traj_t>
135 void StripCalibrator<traj_t>::connectCalibrator(StripOnBoundStateCalibratorBase::Calibrator& stripCalibrator) const
137 using CalibFuncPtr_t =
138 std::pair<typename StripCalibrator<traj_t>::Pos,
139 typename StripCalibrator<traj_t>::Cov>
140 (StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
141 const Acts::CalibrationContext&,
142 const Acts::Surface &,
143 const xAOD::StripCluster&,
144 const Acts::BoundTrackParameters&) const;
146 stripCalibrator.template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
149 template <typename traj_t>
150 bool StripCalibratorToolImpl<traj_t>::calibrateAfterMeasurementSelection() const
151 { return m_postCalibration.value(); }
153} // namespace ActsTrk::detail