ATLAS Offline Software
Loading...
Searching...
No Matches
iPatGlobalFitter.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// iPatGlobalFitter.cxx
7// access full derivative and covariance matrices
8//
9// (c) ATLAS Detector software
11
13
14#include "GaudiKernel/SystemOfUnits.h"
19
20namespace Trk {
21
23 const EventContext& ctx,
24 AlignmentCache& alignCache, const Track& trk,
25 const RunOutlierRemoval runOutlier,
26 const ParticleHypothesis matEffects) const {
27 // @TODO ensure the number of iterations is passed through to the fitter
28 // setMinIterations (alignCache.m_minIterations);
29 alignCache.m_derivMatrix.reset();
30 alignCache.m_fullCovarianceMatrix.reset();
31 alignCache.m_iterationsOfLastFit = 0;
32
33 auto [refittedTrack, fitState] =
34 fitWithState(ctx, trk, runOutlier, matEffects);
35
36 if (refittedTrack) {
37 alignCache.m_derivMatrix = derivMatrix(*fitState);
38 alignCache.m_fullCovarianceMatrix = fullCovarianceMatrix(*fitState);
39 alignCache.m_iterationsOfLastFit = iterationsOfLastFit(*fitState);
40 }
41 return refittedTrack.release();
42}
43
44std::unique_ptr<Amg::MatrixX> iPatGlobalFitter::derivMatrix(
45 const FitState& fitState) const {
46 // copy derivatives to a new HepMatrix
47 if (!fitState.hasMeasurements() || !fitState.parameters) {
48 return nullptr;
49 }
50
51 int numberParameters = 5;
52 if (m_allParameters) {
53 numberParameters = fitState.parameters->numberParameters();
54 }
55 int rows = 0;
56
57 for (const FitMeasurement* m : fitState.getMeasurements()) {
58 if (!m->isPositionMeasurement()) {
59 continue;
60 }
61 rows += m->numberDoF();
62 }
63
64 if (!numberParameters || !rows) {
65 return nullptr;
66 }
67
68 ATH_MSG_VERBOSE(" DerivMatrix : " << fitState.getMeasurements().size()
69 << " measurement objects giving " << rows
70 << " rows and " << numberParameters
71 << " columns (parameters)");
72
73 auto derivativeMatrix =
74 std::make_unique<Amg::MatrixX>(rows, numberParameters);
75 int row = 0;
76 for (const FitMeasurement* m : fitState.getMeasurements()) {
77 if (!m->numberDoF() || !m->isPositionMeasurement()) {
78 continue;
79 }
80 double norm = 0.;
81 if (m->weight() > 0.) {
82 norm = 1. / m->weight();
83 }
84
85 for (int col = 0; col < numberParameters; ++col) {
86 (*derivativeMatrix)(row, col) = norm * m->derivative(col);
87 }
88
89 // take care of units for momentum derivs
90 (*derivativeMatrix)(row, 4) *= Gaudi::Units::TeV;
91 if (fitState.parameters->fitEnergyDeposit()) {
92 (*derivativeMatrix)(row, 5) *= Gaudi::Units::TeV;
93 }
94 ++row;
95 if (m->numberDoF() < 2) {
96 continue;
97 }
98
99 // pixel measurements
100 norm = 0.;
101 if (m->weight2() > 0.)
102 norm = 1. / m->weight2();
103 for (int col = 0; col < numberParameters; ++col) {
104 (*derivativeMatrix)(row, col) = norm * m->derivative2(col);
105 }
106 (*derivativeMatrix)(row, 4) *= Gaudi::Units::TeV;
107 if (fitState.parameters->fitEnergyDeposit()) {
108 (*derivativeMatrix)(row, 5) *= Gaudi::Units::TeV;
109 }
110 ++row;
111 }
112
113 if (row != rows) {
114 ATH_MSG_WARNING("iPatGlobalFitter: inconsistent #rows in deriv matrix ");
115 }
116
117 return derivativeMatrix;
118}
119
120std::unique_ptr<Amg::MatrixX> iPatGlobalFitter::fullCovarianceMatrix(
121 const FitState& fitState) const {
122 int numberParameters = 5;
123
124 if (m_allParameters) {
125 numberParameters = fitState.parameters->numberParameters();
126 }
127 ATH_MSG_VERBOSE(" FullCovarianceMatrix for " << numberParameters
128 << " parameters");
129
130 return std::make_unique<Amg::MatrixX>(Trk::FitProcedure::fullCovariance()->block(
131 0, 0, numberParameters, numberParameters));
132}
133
134int iPatGlobalFitter::iterationsOfLastFit(const FitState& fitState) {
135 return fitState.iterations;
136}
137
138void iPatGlobalFitter::setMinIterations(int minIterations) {
139 m_fitProcedure->setMinIterations(minIterations);
140}
141} // namespace Trk
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static Amg::MatrixX * fullCovariance()
Track * alignmentFit(const EventContext &ctx, AlignmentCache &, const Track &, const RunOutlierRemoval runOutlier=false, const ParticleHypothesis matEffects=Trk::nonInteracting) const
std::unique_ptr< Amg::MatrixX > derivMatrix(const FitState &fitState) const
GlobalTrackFitter methods: access to the matrix of derivatives used during the latest track fit.
static int iterationsOfLastFit(const FitState &fitState)
access to the number of iterations taken by the latest track fit
void setMinIterations(int minIterations)
set method for the minimum number of iterations for (alignment) friend
std::unique_ptr< Amg::MatrixX > fullCovarianceMatrix(const FitState &fitState) const
access to the global fitter's full covariance matrix
Gaudi::Property< bool > m_allParameters
Ensure that the ATLAS eigen extensions are properly loaded.
bool RunOutlierRemoval
switch to toggle quality processing after fit
Definition FitterTypes.h:22
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.