ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_ResidualPullCalculator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SCT_ResidualPullCalculator.cxx
7// Source file for class SCT_ResidualPullCalculator
9// (c) ATLAS Detector software
11// Sebastian.Fleischmann@cern.ch
13
15
17
18
22InDet::SCT_ResidualPullCalculator::SCT_ResidualPullCalculator(const std::string& type, const std::string& name, const IInterface* parent)
23 : AthAlgTool(type,name,parent) {
24 declareInterface<IResidualPullCalculator>(this);
25}
26
31 ATH_MSG_DEBUG ("initialise successful in "<<name());
32 return StatusCode::SUCCESS;
33}
34
38std::optional<Trk::ResidualPull> InDet::SCT_ResidualPullCalculator::residualPull(
39 const Trk::MeasurementBase* measurement,
40 const Trk::TrackParameters* trkPar,
43
44 // check the input:
45 const InDet::SCT_ClusterOnTrack *sctROT = dynamic_cast<const InDet::SCT_ClusterOnTrack*>(measurement);
46 if (!sctROT) return std::nullopt;
47 if (!trkPar) return std::nullopt;
48
49 // if no covariance for the track parameters is given the pull calculation is not valid
50 bool pullIsValid = trkPar->covariance()!=nullptr;
51
52 // residual and pull are always 1-dim in the end
53 std::vector<double> residual(1);
54 std::vector<double> pull(1);
55 double sinAlpha = 0.0;
56
57 // check if we have a 2-dim SCT cluster
58 if (sctROT->localParameters().parameterKey() == 1) {
59 // the (easy) 1-dim case:
60 residual[Trk::loc1] = sctROT->localParameters()[Trk::loc1] - trkPar->parameters()[Trk::loc1];
61 if (pullIsValid) {
62 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
64 (*trkPar->covariance())(Trk::loc1,Trk::loc1),
65 resType, pullIsValid);
66 } else {
67 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
69 0,
70 resType, pullIsValid);
71 }
72 } else {
73 // the 2-dim case:
74 // get the stereo angle (preferrably) from the PrepRawData
75 const InDet::SCT_Cluster *sctRIO = sctROT->prepRawData();
76 if (!sctRIO) {
78 sctROT->localParameters()[Trk::locY]);
79 sinAlpha = sctROT->detectorElement()->sinStereoLocal(p);
80 } else {
81 // Get angle of strip in local frame with respect to the etaAxis
82 // the position of the ROT is lorentz-drift corrected by up to 3 micron,
83 // leading to a strip frame slightly (~5murad) different than the original one
84 sinAlpha = sctRIO->detectorElement()->sinStereoLocal(sctRIO->localPosition());
85 }
86 double cosAlpha = sqrt(1 - sinAlpha*sinAlpha);
87
88 // Calculate Residual for hit: res = (vec(x_track) - vec(x_hit)) * vec(n_perpendicular)
89 residual[Trk::loc1] =
90 (measurement->localParameters()[Trk::locX] -
91 trkPar->parameters()[Trk::locX]) * cosAlpha
92 + (measurement->localParameters()[Trk::locY] -
93 trkPar->parameters()[Trk::locY]) * sinAlpha;
94
95 // Fill transformation matrix to transform covariance matrices
96 Amg::MatrixX RotMat(2,2);
97 RotMat(0,0) = cosAlpha;
98 RotMat(0,1) = sinAlpha;
99 RotMat(1,0) = -sinAlpha;
100 RotMat(1,1) = cosAlpha;
101 // get the covariance matrix of the ROT and rotate it by stereo angle
102 Amg::MatrixX transformedROTCov = sctROT->localCovariance().similarity(RotMat);
103
104 if (trkPar->covariance()) {
105 // Get local error matrix for track to calc pull
106 // Just use first local coordinates
107 // and rotate by the stereo angle
108 Amg::MatrixX RotMatTrk(2,2);
109 RotMatTrk(0,0) = (*trkPar->covariance())(0,0);
110 RotMatTrk(0,1) = (*trkPar->covariance())(0,1);
111 RotMatTrk(1,0) = (*trkPar->covariance())(1,0);
112 RotMatTrk(1,1) = (*trkPar->covariance())(1,1);
113
114 Amg::MatrixX transformedTrkCov = RotMatTrk.similarity(RotMat);
115 // calc pull now
116 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
117 transformedROTCov(0,0),
118 transformedTrkCov(0,0),
119 resType, pullIsValid);
120 } else {
121 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
122 transformedROTCov(0,0),
123 0.,
124 resType, pullIsValid);
125 }
126
127 }
128
129 // create the Trk::ResidualPull:
130 // ParameterKey is always 1, because otherwise we rotated it back
131 return std::make_optional<Trk::ResidualPull>(std::move(residual),
132 std::move(pull), pullIsValid,
133 resType, 1, sinAlpha);
134}
135
139std::array<double,5>
141 const Trk::MeasurementBase* measurement,
142 const Trk::TrackParameters* trkPar,
145 std::array<double,5> residuals{};
146 // check the input:
147 const InDet::SCT_ClusterOnTrack *sctROT = dynamic_cast<const InDet::SCT_ClusterOnTrack*>(measurement);
148 if (!sctROT) return residuals;
149 if (!trkPar) return residuals;
150 double sinAlpha = 0.0;
151
152 // check if we have a 2-dim SCT cluster
153 if (sctROT->localParameters().parameterKey() == 1) {
154 // the (easy) 1-dim case:
155 residuals[Trk::loc1] = sctROT->localParameters()[Trk::loc1] - trkPar->parameters()[Trk::loc1];
156 } else {
157 // the 2-dim case:
158 // get the stereo angle (preferrably) from the PrepRawData
159 const InDet::SCT_Cluster *sctRIO = sctROT->prepRawData();
160 if (!sctRIO) {
162 sctROT->localParameters()[Trk::locY]);
163 sinAlpha = sctROT->detectorElement()->sinStereoLocal(p);
164 } else {
165 // Get angle of strip in local frame with respect to the etaAxis
166 // the position of the ROT is lorentz-drift corrected by up to 3 micron,
167 // leading to a strip frame slightly (~5murad) different than the original one
168 sinAlpha = sctRIO->detectorElement()->sinStereoLocal(sctRIO->localPosition());
169 }
170 double cosAlpha = sqrt(1 - sinAlpha*sinAlpha);
171
172 // Calculate Residual for hit: res = (vec(x_track) - vec(x_hit)) * vec(n_perpendicular)
174 (measurement->localParameters()[Trk::locX] -
175 trkPar->parameters()[Trk::locX]) * cosAlpha
176 + (measurement->localParameters()[Trk::locY] -
177 trkPar->parameters()[Trk::locY]) * sinAlpha;
178
179 }
180 return residuals;
181}
182
183
188 const double residual,
189 const double locMesCov,
190 const double locTrkCov,
191 const Trk::ResidualPull::ResidualType& resType,
192 bool& pullIsValid ) {
193
194 double ErrorSum;
195 if (resType == Trk::ResidualPull::Unbiased) {
196 if ((locMesCov + locTrkCov) < 0.) {
197 pullIsValid=false;
198 return 0;
199 }
200 ErrorSum = sqrt(locMesCov + locTrkCov);
201 } else if (resType == Trk::ResidualPull::Biased) {
202 if ((locMesCov - locTrkCov) < 0.) {
203 pullIsValid=false;
204 return 0;
205 }
206 ErrorSum = sqrt(locMesCov - locTrkCov);
207 } else {
208 if (locMesCov < 0.) {
209 pullIsValid=false;
210 return 0;
211 }
212 ErrorSum = sqrt(locMesCov);
213 }
214 if (ErrorSum != 0) {
215 return residual/ErrorSum;
216 }
217 pullIsValid=false;
218 return 0;
219}
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
double sinStereoLocal(const Amg::Vector2D &localPos) const
Angle of strip in local frame with respect to the etaAxis.
Specific class to represent the SCT measurements.
virtual const InDet::SCT_Cluster * prepRawData() const override final
returns the PrepRawData - is a SCT_Cluster in this scope
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
returns the detector element, assoicated with the PRD of this class
virtual StatusCode initialize() override
initialize
static double calcPull(const double residual, const double locMesCov, const double locTrkCov, const Trk::ResidualPull::ResidualType &, bool &pullIsValid)
calc pull in 1 dimension
virtual std::array< double, 5 > residuals(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType resType, const Trk::TrackState::MeasurementType) const override
This function is a light-weight version of the function above, designed for track fitters where speed...
SCT_ResidualPullCalculator(const std::string &type, const std::string &name, const IInterface *parent)
constructor
virtual std::optional< Trk::ResidualPull > residualPull(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType resType, const Trk::TrackState::MeasurementType) const override
This function returns (creates!) a Trk::ResidualPull object, which contains the values of residual an...
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
int parameterKey() const
Identifier key for matrix expansion/reduction.
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
const Amg::Vector2D & localPosition() const
return the local position reference
@ Biased
RP with track state including the hit.
@ Unbiased
RP with track state that has measurement not included.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
MeasurementType
enum describing the flavour of MeasurementBase
@ locY
local cartesian
Definition ParamDefs.h:38
@ locX
Definition ParamDefs.h:37
@ loc1
Definition ParamDefs.h:34
ParametersBase< TrackParametersDim, Charged > TrackParameters