ATLAS Offline Software
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 
22 InDet::SCT_ResidualPullCalculator::SCT_ResidualPullCalculator(const std::string& type, const std::string& name, const IInterface* parent)
24  declareInterface<IResidualPullCalculator>(this);
25 }
26 
31  ATH_MSG_DEBUG ("initialise successful in "<<name());
32  return StatusCode::SUCCESS;
33 }
34 
38 std::optional<Trk::ResidualPull> InDet::SCT_ResidualPullCalculator::residualPull(
39  const Trk::MeasurementBase* measurement,
40  const Trk::TrackParameters* trkPar,
41  const Trk::ResidualPull::ResidualType resType,
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) {
64  (*trkPar->covariance())(Trk::loc1,Trk::loc1),
65  resType, pullIsValid);
66  } else {
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)
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
117  transformedROTCov(0,0),
118  transformedTrkCov(0,0),
119  resType, pullIsValid);
120  } else {
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 
139 std::array<double,5>
141  const Trk::MeasurementBase* measurement,
142  const Trk::TrackParameters* trkPar,
144  const Trk::TrackState::MeasurementType) const {
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 }
SCT_ClusterOnTrack.h
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::locX
@ locX
Definition: ParamDefs.h:43
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:44
Trk::LocalParameters::parameterKey
int parameterKey() const
Identifier key for matrix expansion/reduction.
ClusterSeg::residual
@ residual
Definition: ClusterNtuple.h:20
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::ResidualPull::Unbiased
@ Unbiased
RP with track state that has measurement not included.
Definition: ResidualPull.h:57
InDet::SCT_ClusterOnTrack::prepRawData
virtual const InDet::SCT_Cluster * prepRawData() const override final
returns the PrepRawData - is a SCT_Cluster in this scope
Definition: SCT_ClusterOnTrack.h:145
InDet::SCT_ResidualPullCalculator::SCT_ResidualPullCalculator
SCT_ResidualPullCalculator(const std::string &type, const std::string &name, const IInterface *parent)
constructor
Definition: SCT_ResidualPullCalculator.cxx:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::TrackState::MeasurementType
MeasurementType
enum describing the flavour of MeasurementBase
Definition: TrackStateDefs.h:26
InDet::SCT_ResidualPullCalculator::residualPull
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...
Definition: SCT_ResidualPullCalculator.cxx:38
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.StandardJetMods.pull
pull
Definition: StandardJetMods.py:264
InDet::SCT_ClusterOnTrack::detectorElement
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
returns the detector element, assoicated with the PRD of this class
Definition: SCT_ClusterOnTrack.h:158
Trk::ParametersBase
Definition: ParametersBase.h:55
InDet::SCT_Cluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/SCT_Cluster.h:34
InDet::SiCluster::detectorElement
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...
Trk::MeasurementBase::localCovariance
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
Definition: MeasurementBase.h:138
Trk::MeasurementBase
Definition: MeasurementBase.h:58
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::PrepRawData::localPosition
const Amg::Vector2D & localPosition() const
return the local position reference
InDet::SCT_ResidualPullCalculator::initialize
virtual StatusCode initialize() override
initialize
Definition: SCT_ResidualPullCalculator.cxx:30
Trk::MeasurementBase::localParameters
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Definition: MeasurementBase.h:132
Trk::ResidualPull::Biased
@ Biased
RP with track state including the hit.
Definition: ResidualPull.h:55
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_ResidualPullCalculator.h
InDetDD::SiDetectorElement::sinStereoLocal
double sinStereoLocal(const Amg::Vector2D &localPos) const
Angle of strip in local frame with respect to the etaAxis.
Definition: SiDetectorElement.cxx:288
InDet::SCT_ResidualPullCalculator::calcPull
static double calcPull(const double residual, const double locMesCov, const double locTrkCov, const Trk::ResidualPull::ResidualType &, bool &pullIsValid)
calc pull in 1 dimension
Definition: SCT_ResidualPullCalculator.cxx:187
InDet::SCT_ResidualPullCalculator::residuals
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...
Definition: SCT_ResidualPullCalculator.cxx:140
AthAlgTool
Definition: AthAlgTool.h:26
Trk::loc1
@ loc1
Definition: ParamDefs.h:40
Trk::ResidualPull::ResidualType
ResidualType
Definition: ResidualPull.h:53
InDet::SCT_ClusterOnTrack
Definition: SCT_ClusterOnTrack.h:44