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"
15#include "GaudiKernel/ThreadLocalContext.h"
20
21namespace Trk {
22
24 const EventContext& ctx,
25 AlignmentCache& alignCache, const Track& trk,
26 const RunOutlierRemoval runOutlier,
27 const ParticleHypothesis matEffects) const {
28 // @TODO ensure the number of iterations is passed through to the fitter
29 // setMinIterations (alignCache.m_minIterations);
30 alignCache.m_derivMatrix.reset();
31 alignCache.m_fullCovarianceMatrix.reset();
32 alignCache.m_iterationsOfLastFit = 0;
33
34 auto [refittedTrack, fitState] =
35 fitWithState(ctx, trk, runOutlier, matEffects);
36
37 if (refittedTrack) {
38 alignCache.m_derivMatrix = derivMatrix(*fitState);
39 alignCache.m_fullCovarianceMatrix = fullCovarianceMatrix(*fitState);
40 alignCache.m_iterationsOfLastFit = iterationsOfLastFit(*fitState);
41 }
42 return refittedTrack.release();
43}
44
45std::unique_ptr<Amg::MatrixX> iPatGlobalFitter::derivMatrix(
46 const FitState& fitState) const {
47 // copy derivatives to a new HepMatrix
48 if (!fitState.hasMeasurements() || !fitState.parameters) {
49 return nullptr;
50 }
51
52 int numberParameters = 5;
53 if (m_allParameters) {
54 numberParameters = fitState.parameters->numberParameters();
55 }
56 int rows = 0;
57
58 for (const FitMeasurement* m : fitState.getMeasurements()) {
59 if (!m->isPositionMeasurement()) {
60 continue;
61 }
62 rows += m->numberDoF();
63 }
64
65 if (!numberParameters || !rows) {
66 return nullptr;
67 }
68
69 ATH_MSG_VERBOSE(" DerivMatrix : " << fitState.getMeasurements().size()
70 << " measurement objects giving " << rows
71 << " rows and " << numberParameters
72 << " columns (parameters)");
73
74 auto derivativeMatrix =
75 std::make_unique<Amg::MatrixX>(rows, numberParameters);
76 int row = 0;
77 for (const FitMeasurement* m : fitState.getMeasurements()) {
78 if (!m->numberDoF() || !m->isPositionMeasurement()) {
79 continue;
80 }
81 double norm = 0.;
82 if (m->weight() > 0.) {
83 norm = 1. / m->weight();
84 }
85
86 for (int col = 0; col < numberParameters; ++col) {
87 (*derivativeMatrix)(row, col) = norm * m->derivative(col);
88 }
89
90 // take care of units for momentum derivs
91 (*derivativeMatrix)(row, 4) *= Gaudi::Units::TeV;
92 if (fitState.parameters->fitEnergyDeposit()) {
93 (*derivativeMatrix)(row, 5) *= Gaudi::Units::TeV;
94 }
95 ++row;
96 if (m->numberDoF() < 2) {
97 continue;
98 }
99
100 // pixel measurements
101 norm = 0.;
102 if (m->weight2() > 0.)
103 norm = 1. / m->weight2();
104 for (int col = 0; col < numberParameters; ++col) {
105 (*derivativeMatrix)(row, col) = norm * m->derivative2(col);
106 }
107 (*derivativeMatrix)(row, 4) *= Gaudi::Units::TeV;
108 if (fitState.parameters->fitEnergyDeposit()) {
109 (*derivativeMatrix)(row, 5) *= Gaudi::Units::TeV;
110 }
111 ++row;
112 }
113
114 if (row != rows) {
115 ATH_MSG_WARNING("iPatGlobalFitter: inconsistent #rows in deriv matrix ");
116 }
117
118 return derivativeMatrix;
119}
120
121std::unique_ptr<Amg::MatrixX> iPatGlobalFitter::fullCovarianceMatrix(
122 const FitState& fitState) const {
123 int numberParameters = 5;
124
125 if (m_allParameters) {
126 numberParameters = fitState.parameters->numberParameters();
127 }
128 ATH_MSG_VERBOSE(" FullCovarianceMatrix for " << numberParameters
129 << " parameters");
130
131 return std::make_unique<Amg::MatrixX>(Trk::FitProcedure::fullCovariance()->block(
132 0, 0, numberParameters, numberParameters));
133}
134
135int iPatGlobalFitter::iterationsOfLastFit(const FitState& fitState) {
136 return fitState.iterations;
137}
138
139void iPatGlobalFitter::setMinIterations(int minIterations) {
140 m_fitProcedure->setMinIterations(minIterations);
141}
142} // 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.