ATLAS Offline Software
Loading...
Searching...
No Matches
StripCalibratorToolImpl.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
4*/
5
6#ifndef STRIPCALIBRATORTOOLIMPL_ICC
7#define STRIPCALIBRATORTOOLIMPL_ICC
8
9#include "src/detail/TrackStateFlagHelper.h"
10#include "InDetReadoutGeometry/SiDetectorElement.h"
11#include "SCT_ReadoutGeometry/StripStereoAnnulusDesign.h"
12#include <stdexcept>
13
14namespace ActsTrk::detail{
15
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)
21 {}
22
23 template <typename traj_t>
24 StatusCode StripCalibratorToolImpl<traj_t>::initialize()
25 {
26 ATH_MSG_DEBUG("Initializing " << AthAlgTool::name() << " ...");
27
28 ATH_MSG_DEBUG(AthAlgTool::name() << " successfully initialized");
29
30 ATH_MSG_INFO( m_correctCovariance );
31 ATH_MSG_INFO( m_postCalibration );
32 ATH_MSG_INFO( m_errorStrategy );
33
34 return StatusCode::SUCCESS;
35
36 }
37
38 template <typename traj_t>
39 const InDetDD::SiDetectorElement& StripCalibrator<traj_t>::getDetectorElement(const Acts::Surface &surface) const
40 {
41 const auto* detElem = getActsDetectorElement(surface);
42 const InDetDD::SiDetectorElement *siDetElement = detElem ? dynamic_cast<const InDetDD::SiDetectorElement *>(detElem->upstreamDetectorElement()) : nullptr;
43 if (!siDetElement) {
44 ATH_MSG_ERROR("Surface without associated SI detector element");
45 throw std::runtime_error("SiDetectorElement is NULL");
46 }
47 return *siDetElement;
48 }
49
50 template <typename traj_t>
51 std::optional<float> StripCalibrator<traj_t>::getCorrectedError(const xAOD::StripCluster& cluster) const
52 {
53 std::optional<float> errX {std::nullopt};
54 if (not m_options.m_correctCovariance) {
55 return errX;
56 }
57
58 Cov cov = cluster.template localCovariance<1>();
59 int nrows = cluster.channelsInPhi();
60
61 if (m_options.m_errorStrategy == 0 ) {
62
63 errX = std::sqrt(cov(0,0));
64
65 } else if (m_options.m_errorStrategy == 1 ) {
66
67 errX = std::sqrt(cov(0,0)) / nrows;
68
69 }
70
71
72 return errX;
73 }
74
75 template <typename traj_t>
76 void
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
82 {
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();
91 }
92 }
93
94 template <typename traj_t>
95 std::tuple<typename StripCalibrator<traj_t>::Pos,
96 typename StripCalibrator<traj_t>::Cov,
97 unsigned int>
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
104 {
105 // const InDetDD::SiDetectorElement &detElement = getDetectorElement(surface);
106 return calibrate(gctx, cctx, cluster);
107 }
108
109 template <typename traj_t>
110 std::tuple<typename StripCalibrator<traj_t>::Pos,
111 typename StripCalibrator<traj_t>::Cov,
112 unsigned int>
113 StripCalibrator<traj_t>::calibrate(
114 const Acts::GeometryContext& /*gctx*/,
115 const Acts::CalibrationContext& /*cctx*/,
116 const xAOD::StripCluster& cluster) const
117 {
118 Pos pos = cluster.template localPosition<1>();
119 Cov cov = cluster.template localCovariance<1>();
120
121 auto errX = getCorrectedError(cluster);
122 if (errX.has_value()) {
123 double newErr = *errX;
124 cov(0, 0) = newErr * newErr;
125 }
126
127 return std::make_tuple(pos, cov,0u);
128 }
129
130 template <typename traj_t>
131 void StripCalibrator<traj_t>::connectOnTrackCalibrator(typename StripCalibrator<traj_t>::BASE::OnTrackCalibrator& stripCalibrator) const
132 {
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;
138
139 stripCalibrator. template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
140 }
141
142 template <typename traj_t>
143 void StripCalibrator<traj_t>::connectCalibrator(StripOnBoundStateCalibratorBase::Calibrator& stripCalibrator) const
144 {
145 using CalibFuncPtr_t =
146 std::tuple<typename StripCalibrator<traj_t>::Pos,
147 typename StripCalibrator<traj_t>::Cov,
148 unsigned int>
149 (StripCalibrator<traj_t>:: *)(const Acts::GeometryContext&,
150 const Acts::CalibrationContext&,
151 const Acts::Surface &,
152 const xAOD::StripCluster&,
153 const Acts::BoundTrackParameters&) const;
154
155 stripCalibrator.template connect<static_cast<CalibFuncPtr_t>(&StripCalibrator<traj_t>::calibrate)>(this);
156 }
157
158 template <typename traj_t>
159 bool StripCalibratorToolImpl<traj_t>::calibrateAfterMeasurementSelection() const
160 { return m_postCalibration.value(); }
161
162} // namespace ActsTrk::detail
163
164#endif