ATLAS Offline Software
Loading...
Searching...
No Matches
RPC_ResidualPullCalculator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
9
10//================ Initialisation =================================================
11
13{
14 ATH_CHECK(m_idHelperSvc.retrieve());
15 ATH_MSG_DEBUG ("initialize() successful in " << name());
16 return StatusCode::SUCCESS;
17}
18
19//================ calculate residuals for RPC ==================================
20std::array<double,5>
22 const Trk::MeasurementBase* measurement,
23 const Trk::TrackParameters* trkPar,
24 const Trk::ResidualPull::ResidualType /*resType*/,
26 std::array<double, 5> residuals{};
27 if (!trkPar || !measurement) return residuals;
29
30 if( m_idHelperSvc->isRpc(ID) ) {
31
32 if (measurement->localParameters().parameterKey() == 1) {
33 // convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of RPC
35 - trkPar->parameters()[Trk::loc1];
36 } else {
38 - trkPar->parameters()[Trk::loc1];
40 - trkPar->parameters()[Trk::loc2];
41 }
42
43 } else {
44 ATH_MSG_WARNING( "Input problem measurement is not RPC. "
45 <<m_idHelperSvc->toString(ID) );
46 return residuals;
47 }
48 return residuals;
49}
50
51//================ calculate residuals and pulls for RPC ==================================
52std::optional<Trk::ResidualPull> Muon::RPC_ResidualPullCalculator::residualPull(
53 const Trk::MeasurementBase* measurement,
54 const Trk::TrackParameters* trkPar,
57
58 if (!trkPar || !measurement) {
59 return std::nullopt;
60 }
62
63 if (!m_idHelperSvc->isRpc(ID)) {
64 ATH_MSG_DEBUG ("Input problem measurement is not RPC but "
65 <<m_idHelperSvc->toString(ID));
66 return std::nullopt;
67 }
68
69
70 // if no covariance for the track parameters is given the pull calculation is not valid
71 const AmgSymMatrix(5)* trkCov = trkPar->covariance();
72
73 // calculate residual
74 const auto & localParameters = measurement->localParameters();
75 const std::size_t nParams = localParameters.dimension();
76 std::vector<double> residual(nParams), pull(nParams);
77
78 switch (nParams) {
79 case 1: {
80 residual[Trk::loc1] = localParameters[Trk::loc1]
81 - trkPar->parameters()[Trk::loc1];
82 break;
83 } case 2: {
84 residual[Trk::loc1] = localParameters[Trk::loc1]
85 - trkPar->parameters()[Trk::loc1];
86 residual[Trk::loc2] = localParameters[Trk::loc2]
87 - trkPar->parameters()[Trk::loc2];
88 break;
89 } default:
90 ATH_MSG_WARNING ( "RPC ClusterOnTrack does not carry the expected "
91 << "LocalParameters structure!" );
92 return std::nullopt;
93 }
94
95 // calculate pull
96 for (std::size_t l = 0 ; l < residual.size(); ++l) {
97 pull[l] = calcPull(residual[l], measurement->localCovariance()(l,l),
98 trkCov ? (*trkCov)(l,l) : 0., resType);
99 }
100
101 // create the Trk::ResidualPull.
102 ATH_MSG_DEBUG ( "Calculating Pull for channel " << m_idHelperSvc->toString(ID) << " residual " << residual[Trk::loc1] << " pull " << pull[Trk::loc1] );
103 return std::make_optional<Trk::ResidualPull>(std::move(residual),
104 std::move(pull),
105 trkCov != nullptr,
106 resType, 1);
107}
108
109
114 const double residual,
115 const double locMesCov,
116 const double locTrkCov,
117 const Trk::ResidualPull::ResidualType& resType ) {
118
119 double ErrorSum(0.0);
120 if (resType == Trk::ResidualPull::Unbiased) {
121 if( locMesCov + locTrkCov > 0 ) ErrorSum = std::sqrt(locMesCov + locTrkCov);
122 } else if (resType == Trk::ResidualPull::Biased) {
123 if ((locMesCov - locTrkCov) < 0.) {
124 return 0;
125 }
126 ErrorSum = std::sqrt(locMesCov - locTrkCov);
127 } else ErrorSum = std::sqrt(locMesCov);
128 if (ErrorSum != 0) return residual/ErrorSum;
129 return 0;
130}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
static double calcPull(const double residual, const double locMesCov, const double locTrkCov, const Trk::ResidualPull::ResidualType &)
internal structuring: common method to calculate the hit pull.
virtual std::optional< Trk::ResidualPull > residualPull(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType, const Trk::TrackState::MeasurementType) const override
This function returns (creates!) a Trk::ResidualPull object, which contains the values of residual an...
virtual std::array< double, 5 > residuals(const Trk::MeasurementBase *measurement, const Trk::TrackParameters *trkPar, const Trk::ResidualPull::ResidualType, const Trk::TrackState::MeasurementType) const override
This function is a light-weight version of the function above, designed for track fitters where speed...
static void extract(std::vector< Identifier > &ids, const std::vector< const MeasurementBase * > &measurements)
int parameterKey() const
Identifier key for matrix expansion/reduction.
int dimension() const
Dimension of this localParameters() vector.
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.
@ Biased
RP with track state including the hit.
@ Unbiased
RP with track state that has measurement not included.
MeasurementType
enum describing the flavour of MeasurementBase
@ loc2
generic first and second local coordinate
Definition ParamDefs.h:35
@ loc1
Definition ParamDefs.h:34
ParametersBase< TrackParametersDim, Charged > TrackParameters