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