ATLAS Offline Software
Loading...
Searching...
No Matches
RPC_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
9
10//================ Constructor =================================================
11
12Muon::RPC_ResidualPullCalculator::RPC_ResidualPullCalculator(const std::string& t, const std::string& n, const IInterface* p) :
13 AthAlgTool(t,n,p)
14{
15 declareInterface<IResidualPullCalculator>(this);
16}
17
18//================ Initialisation =================================================
19
21{
22 ATH_CHECK(m_idHelperSvc.retrieve());
23 ATH_MSG_DEBUG ("initialize() successful in " << name());
24 return StatusCode::SUCCESS;
25}
26
27//================ calculate residuals for RPC ==================================
28std::array<double,5>
30 const Trk::MeasurementBase* measurement,
31 const Trk::TrackParameters* trkPar,
32 const Trk::ResidualPull::ResidualType /*resType*/,
34 std::array<double, 5> residuals{};
35 if (!trkPar || !measurement) return residuals;
37
38 if( ID.is_valid() && m_idHelperSvc->isRpc(ID) ) {
39
40 if (measurement->localParameters().parameterKey() == 1) {
41 // convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of RPC
43 - trkPar->parameters()[Trk::loc1];
44 } else {
45 ATH_MSG_WARNING ( "RPC ClusterOnTrack does not carry the expected "
46 << "LocalParameters structure!" );
47 return residuals;
48 }
49
50 } else {
51 ATH_MSG_DEBUG ( "Input problem measurement is not RPC." );
52 return residuals;
53 }
54 return residuals;
55}
56
57//================ calculate residuals and pulls for RPC ==================================
58std::optional<Trk::ResidualPull> Muon::RPC_ResidualPullCalculator::residualPull(
59 const Trk::MeasurementBase* measurement,
60 const Trk::TrackParameters* trkPar,
63
64 if (!trkPar || !measurement) return std::nullopt;
65
67 if( ID.is_valid() && m_idHelperSvc->isRpc(ID) ) {
68
69 // if no covariance for the track parameters is given the pull calculation is not valid
70 const AmgSymMatrix(5)* trkCov = trkPar->covariance();
71 bool pullIsValid = (trkCov);
72
73 // calculate residual
74 std::vector<double> residual(1);
75 std::vector<double> pull(1);
76 if (measurement->localParameters().parameterKey() == 1) {
77 // convention to be interpreted by TrkValTools: 2nd coordinate codes orientation of RPC
78 residual[Trk::loc1] = measurement->localParameters()[Trk::loc1]
79 - trkPar->parameters()[Trk::loc1];
80 } else {
81 ATH_MSG_WARNING ( "RPC ClusterOnTrack does not carry the expected "
82 << "LocalParameters structure!" );
83 return std::nullopt;
84 }
85
86 // calculate pull
87 if (pullIsValid)
88 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
89 measurement->localCovariance()(Trk::loc1,Trk::loc1),
90 (*trkCov)(Trk::loc1,Trk::loc1),
91 resType);
92 else
93 pull[Trk::loc1] = calcPull(residual[Trk::loc1],
94 measurement->localCovariance()(Trk::loc1,Trk::loc1),
95 0,
96 resType);
97
98 // create the Trk::ResidualPull.
99 ATH_MSG_DEBUG ( "Calculating Pull for channel " << m_idHelperSvc->toString(ID) << " residual " << residual[Trk::loc1] << " pull " << pull[Trk::loc1] );
100 return std::make_optional<Trk::ResidualPull>(
101 std::move(residual), std::move(pull), pullIsValid, resType, 1);
102
103 } else {
104 ATH_MSG_DEBUG ( "Input problem measurement is not RPC." );
105 return std::nullopt;
106 }
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 = sqrt(locMesCov + locTrkCov);
122 } else if (resType == Trk::ResidualPull::Biased) {
123 if ((locMesCov - locTrkCov) < 0.) {
124 return 0;
125 }
126 ErrorSum = sqrt(locMesCov - locTrkCov);
127 } else ErrorSum = 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)
std::vector< Identifier > ID
#define AmgSymMatrix(dim)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
RPC_ResidualPullCalculator(const std::string &, const std::string &, const IInterface *)
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.
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
@ loc1
Definition ParamDefs.h:34
ParametersBase< TrackParametersDim, Charged > TrackParameters