2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
6 #ifndef STRIPCALIBRATORIMPL_ICC
7 #define STRIPCALIBRATORIMPL_ICC
9 #include "InDetReadoutGeometry/SiDetectorElement.h"
10 #include "SCT_ReadoutGeometry/StripStereoAnnulusDesign.h"
13 namespace ActsTrk::detail{
15 template <typename traj_t>
16 StripCalibratorImpl<traj_t>::StripCalibratorImpl(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 StripCalibratorImpl<traj_t>::initialize()
25 ATH_MSG_DEBUG("Initializing " << AthAlgTool::name() << " ...");
26 ATH_CHECK(m_stripDetEleCollKey.initialize());
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& StripCalibratorImpl<traj_t>::getDetectorElement(xAOD::DetectorIDHashType id) const
41 const InDetDD::SiDetectorElement* element=nullptr;
42 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> stripDetEleHandle(
44 Gaudi::Hive::currentContext());
46 const InDetDD::SiDetectorElementCollection* detElements(*stripDetEleHandle);
48 if (!stripDetEleHandle.isValid() or detElements == nullptr) {
49 ATH_MSG_ERROR(m_stripDetEleCollKey.fullKey() << " is not available.");
52 element = detElements->getDetectorElement(id);
54 if (element == nullptr) {
55 ATH_MSG_ERROR("No element corresponding to hash " << id << " for " << m_stripDetEleCollKey.fullKey());
56 throw std::runtime_error("SiDetectorElement is NULL");
62 template <typename traj_t>
63 std::optional<float> StripCalibratorImpl<traj_t>::getCorrectedError(const xAOD::StripCluster& cluster) const
65 std::optional<float> errX {std::nullopt};
66 if (not m_correctCovariance) {
70 Cov cov = cluster.template localCovariance<1>();
71 int nrows = cluster.channelsInPhi();
73 if (m_errorStrategy == 0 ) {
75 errX = std::sqrt(cov(0,0));
77 } else if (m_errorStrategy == 1 ) {
79 errX = std::sqrt(cov(0,0)) / nrows;
87 template <typename traj_t>
88 std::pair<typename StripCalibratorImpl<traj_t>::Pos,
89 typename StripCalibratorImpl<traj_t>::Cov>
90 StripCalibratorImpl<traj_t>::calibrate(
91 const Acts::GeometryContext& gctx,
92 const Acts::CalibrationContext& cctx,
93 const xAOD::StripCluster& cluster,
94 const TrackStateProxy& /*state*/) const
96 const InDetDD::SiDetectorElement &detElement = getDetectorElement(cluster.identifierHash());
97 return calibrate(gctx, cctx, cluster, detElement);
100 template <typename traj_t>
101 std::pair<typename StripCalibratorImpl<traj_t>::Pos,
102 typename StripCalibratorImpl<traj_t>::Cov>
103 StripCalibratorImpl<traj_t>::calibrate(
104 const Acts::GeometryContext& gctx,
105 const Acts::CalibrationContext& cctx,
106 const xAOD::StripCluster& cluster,
107 const Acts::BoundTrackParameters& /*bound_parameters*/) const
109 const InDetDD::SiDetectorElement &detElement = getDetectorElement(cluster.identifierHash());
110 return calibrate(gctx, cctx, cluster, detElement);
113 template <typename traj_t>
114 std::pair<typename StripCalibratorImpl<traj_t>::Pos,
115 typename StripCalibratorImpl<traj_t>::Cov>
116 StripCalibratorImpl<traj_t>::calibrate(
117 const Acts::GeometryContext& /*gctx*/,
118 const Acts::CalibrationContext& /*cctx*/,
119 const xAOD::StripCluster& cluster,
120 const InDetDD::SiDetectorElement& /*detElement*/) const
122 Pos pos = cluster.template localPosition<1>();
123 Cov cov = cluster.template localCovariance<1>();
125 auto errX = getCorrectedError(cluster);
126 if (errX.has_value()) {
127 double newErr = *errX;
128 cov(0, 0) = newErr * newErr;
131 return std::make_pair(pos, cov);
134 template <typename traj_t>
135 void StripCalibratorImpl<traj_t>::connect(OnTrackCalibrator<traj_t>& calibrator) const
137 using CalibFuncPtr_t =
138 std::pair<typename StripCalibratorImpl<traj_t>::Pos, typename StripCalibratorImpl<traj_t>::Cov>
139 (StripCalibratorImpl<traj_t>:: *)(const Acts::GeometryContext&,
140 const Acts::CalibrationContext&,
141 const xAOD::StripCluster&,
142 const TrackStateProxy&) const;
144 calibrator.stripCalibrator. template connect<static_cast<CalibFuncPtr_t>(&StripCalibratorImpl<traj_t>::calibrate)>(this);
147 template <typename traj_t>
148 void StripCalibratorImpl<traj_t>::connectStripCalibrator(IOnBoundStateCalibratorTool::StripCalibrator& stripCalibrator) const
150 using CalibFuncPtr_t =
151 std::pair<typename StripCalibratorImpl<traj_t>::Pos,
152 typename StripCalibratorImpl<traj_t>::Cov>
153 (StripCalibratorImpl<traj_t>:: *)(const Acts::GeometryContext&,
154 const Acts::CalibrationContext&,
155 const xAOD::StripCluster&,
156 const Acts::BoundTrackParameters&) const;
158 stripCalibrator.template connect<static_cast<CalibFuncPtr_t>(&StripCalibratorImpl<traj_t>::calibrate)>(this);
161 template <typename traj_t>
162 bool StripCalibratorImpl<traj_t>::calibrateAfterMeasurementSelection() const
163 { return m_postCalibration.value(); }
167 } // namespace ActsTrk::detail