ATLAS Offline Software
Loading...
Searching...
No Matches
KalmanFitterTool.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
7// ACTS
8#include "Acts/Propagator/SympyStepper.hpp"
9#include "Acts/Propagator/Navigator.hpp"
10#include "Acts/Propagator/Propagator.hpp"
11#include "Acts/Surfaces/PerigeeSurface.hpp"
12#include "Acts/Surfaces/Surface.hpp"
13#include "Acts/TrackFitting/KalmanFitter.hpp"
14#include "Acts/Utilities/Helpers.hpp"
15#include "Acts/Utilities/Logger.hpp"
16#include "Acts/Utilities/CalibrationContext.hpp"
17#include "Acts/EventData/VectorTrackContainer.hpp"
18
21
22// PACKAGE
24#include "ActsInterop/Logger.h"
25
26#include "Acts/Propagator/DirectNavigator.hpp"
27
28namespace ActsTrk {
29
30
32
33 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
35 ATH_CHECK(m_geometryConvTool.retrieve());
36 ATH_CHECK(m_ROTcreator.retrieve(EnableTool{!m_ROTcreator.empty()}));
37 ATH_CHECK(m_muonCalibrator.retrieve(EnableTool{!m_muonCalibrator.empty()}));
38 m_logger = makeActsAthenaLogger(this, "KalmanRefit");
39
40 auto field = std::make_shared<ATLASMagneticFieldWrapper>();
41
42 // Fitter
43 Acts::SympyStepper stepper(field);
45 // Direct Fitter
46 Acts::DirectNavigator directNavigator( logger().cloneWithSuffix("DirectNavigator") );
47 Acts::Propagator<Acts::SympyStepper, Acts::DirectNavigator> directPropagator(std::move(stepper),
48 std::move(directNavigator),
49 logger().cloneWithSuffix("DirectPropagator"));
50
51 m_directFitter = std::make_unique<DirectFitter>(std::move(directPropagator),
52 logger().cloneWithSuffix("DirectKalmanFitter"));
53
54 } else {
55 Acts::Navigator navigator( Acts::Navigator::Config{ m_trackingGeometrySvc->trackingGeometry() },
56 logger().cloneWithSuffix("Navigator"));
57 Acts::Propagator<Acts::SympyStepper, Acts::Navigator> propagator(stepper,
58 std::move(navigator),
59 logger().cloneWithSuffix("Prop"));
60
61 m_fitter = std::make_unique<Fitter>(std::move(propagator),
62 logger().cloneWithSuffix("KalmanFitter"));
63 }
64
66 m_outlierFinder.StateChiSquaredPerNumberDoFCut = m_option_outlierChi2Cut;
68
69 FitterExtension_t extensionTemplate{};
70 extensionTemplate.outlierFinder.connect<&detail::FitterHelperFunctions::ATLASOutlierFinder::operator()<MutableTrackStateBackend>>(&m_outlierFinder);
71 extensionTemplate.reverseFilteringLogic.connect<&detail::FitterHelperFunctions::ReverseFilteringLogic::operator()<MutableTrackStateBackend>>(&m_reverseFilteringLogic);
74
76 {
78
80 configureMe = extensionTemplate;
82 configureMe.surfaceAccessor.connect<&detail::TrkMeasSurfaceAccessor::operator()>(&m_trkSurfAcc);
83 }
85 {
88
90 configureMe = extensionTemplate;
92 configureMe.surfaceAccessor.connect<&detail::TrkPrepRawDataSurfaceAcc::operator()>(&m_prdSurfAcc);
93 }
95 {
97
98
100
102 using enum xAOD::UncalibMeasType;
103 if (m_muonCalibrator.isEnabled()) {
104 for (const auto muonType : {MdtDriftCircleType, RpcStripType, TgcStripType, MMClusterType, sTgcStripType}) {
106 }
107 }
108 for (const auto idType: {PixelClusterType, StripClusterType, HGTDClusterType}) {
110 }
111
113 configureMe = extensionTemplate;
114 configureMe.surfaceAccessor.connect<&detail::xAODUncalibMeasSurfAcc::operator()>(&m_unalibMeasSurfAcc);
116 }
117 return StatusCode::SUCCESS;
118}
119
120
122 KalmanFitterTool::configureFit(const Acts::GeometryContext& tgContext,
123 const Acts::MagneticFieldContext& mfContext,
124 const Acts::CalibrationContext& calContext,
125 const Acts::Surface* surface,
126 detail::SourceLinkType slType) const {
127
128 //slType = 3 is possible
129 const auto& kfExtensions = m_kfExtensions.at(Acts::toUnderlying(slType));
130
131 Acts::PropagatorPlainOptions propagationOption(tgContext, mfContext);
132 propagationOption.maxSteps = m_option_maxPropagationStep;
133 // Set the KalmanFitter options
134 return FitterOptions_t{tgContext, mfContext, calContext,
135 kfExtensions, propagationOption,
136 surface};
137}
138
139// fit a set of PrepRawData objects
140// --------------------------------
141std::unique_ptr< MutableTrackContainer >
142KalmanFitterTool::fit(const std::vector< const xAOD::UncalibratedMeasurement*> & clusterList,
143 const Acts::BoundTrackParameters& initialParams,
144 const Acts::GeometryContext& tgContext,
145 const Acts::MagneticFieldContext& mfContext,
146 const Acts::CalibrationContext& calContext,
147 const Acts::Surface* targetSurface) const{
148 ATH_MSG_DEBUG("--> entering KalmanFitter::fit(xAODMeasure...things,TP,)");
149
150 std::vector<Acts::SourceLink> sourceLinks;
151 sourceLinks.reserve(clusterList.size());
152
153 detail::MeasurementCalibratorBase::pack(clusterList, sourceLinks);
154
155 return fit(sourceLinks, initialParams, tgContext, mfContext, calContext, targetSurface);
156}
157
158std::unique_ptr< MutableTrackContainer >
160 const Acts::BoundTrackParameters& initialParams,
161 const Acts::GeometryContext& tgContext,
162 const Acts::MagneticFieldContext& mfContext,
163 const Acts::CalibrationContext& calContext,
164 const Acts::Surface& targetSurface) const {
165
166 std::vector<const xAOD::UncalibratedMeasurement*> measList;
167 measList.reserve(6);
168
169 const auto& sps = seed.sp();
170 for (const xAOD::SpacePoint* sp : sps) {
171 const auto& measurements = sp->measurements();
172 for (const xAOD::UncalibratedMeasurement *umeas : measurements) {
173 measList.push_back(umeas);
174 }
175 }
176 return fit(measList, initialParams, tgContext, mfContext, calContext, &targetSurface);
177}
178
179 StatusCode
180 KalmanFitterTool::fit(const EventContext& /*ctx*/,
181 const TrackContainer::ConstTrackProxy& /*track*/,
182 MutableTrackContainer& /*trackContainer*/,
183 const Acts::PerigeeSurface& /*pSurface*/) const
184 {
185 ATH_MSG_ERROR("Track refit method not implemented in KalmanFitterTool yet");
186 return StatusCode::FAILURE;
187 }
188
189std::unique_ptr< MutableTrackContainer >
190KalmanFitterTool::fit(const std::vector<Acts::SourceLink>& sourceLinks,
191 const Acts::BoundTrackParameters& initialParams,
192 const Acts::GeometryContext& tgContext,
193 const Acts::MagneticFieldContext& mfContext,
194 const Acts::CalibrationContext& calContext,
195 const Acts::Surface* targetSurface) const {
196
197 if (sourceLinks.empty()) {
198 ATH_MSG_DEBUG("No measurements given. Nothing to do");
199 return nullptr;
200 }
201
202 // Construct a perigee surface as the target surface if none is provided
203 std::shared_ptr<Acts::Surface> pSurface{nullptr};
204 if (!targetSurface){
205 pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3::Zero());
206 targetSurface = pSurface.get();
207 }
208
210
211 Acts::KalmanFitterOptions kfOptions = configureFit(tgContext, mfContext, calContext,
212 targetSurface, slType);
213
214 ActsTrk::MutableTrackBackend trackContainerBackEnd;
215 ActsTrk::MutableTrackStateBackend multiTrajBackEnd;
216 auto tracks = std::make_unique<MutableTrackContainer>(std::move(trackContainerBackEnd),
217 std::move(multiTrajBackEnd));
218
219 bool fitSuccess = false;
221
222 std::vector<const Acts::Surface*> surfaces;
223 surfaces.reserve(sourceLinks.size());
224 switch (slType) {
226 std::ranges::for_each(sourceLinks, [this, &surfaces](const Acts::SourceLink& sl) {
227 surfaces.push_back(m_trkSurfAcc(sl));
228 });
229 break;
230 }
232 std::ranges::for_each(sourceLinks, [this, &surfaces](const Acts::SourceLink& sl) {
233 surfaces.push_back(m_prdSurfAcc(sl));
234 });
235 break;
236 }
238 std::ranges::for_each(sourceLinks, [this, &surfaces](const Acts::SourceLink& sl) {
239 surfaces.push_back(m_unalibMeasSurfAcc(sl));
240 });
241 break;
242 }
243 default:
244 ATH_MSG_ERROR("Unsupported source link type for KalmanFitterTool::fit");
245 return nullptr;
246 }
247
248 fitSuccess = m_directFitter->fit(sourceLinks.begin(), sourceLinks.end(),
249 initialParams, kfOptions, surfaces, *tracks.get()).ok();
250
251 } else {
252
253 fitSuccess = m_fitter->fit(sourceLinks.begin(), sourceLinks.end(),
254 initialParams, kfOptions, *tracks.get()).ok();
255 }
256
257 if (!fitSuccess) {
258 ATH_MSG_VERBOSE("Kalman Fitter on Seed has failed");
259 return nullptr;
260 }
261
263 for (auto trkProxy : *tracks) {
265 }
266
267 return tracks;
268}
269
270}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sp
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Definition Logger.cxx:64
ActsTrk::detail::FitterHelperFunctions::ReverseFilteringLogic m_reverseFilteringLogic
Acts::KalmanFitterExtensions< MutableTrackStateBackend > FitterExtension_t
Abbrivation of the fitter extensions.
ToolHandle< MuonR4::ISpacePointCalibrator > m_muonCalibrator
detail::TrkPrepRawDataCalibrator m_prdCalibrator
Calibrator for the Trk::PrepRawData track states (legacy EDM).
Gaudi::Property< bool > m_useDirectNavigation
detail::TrkPrepRawDataSurfaceAcc m_prdSurfAcc
Surface accessor for the Trk::PrepRawData track states (legacy EDM).
detail::xAODUncalibMeasSurfAcc m_unalibMeasSurfAcc
Accessor to fetch surfaces from the xAOD::UncalibratedMeasurements (Phase-II EDM).
detail::xAODUncalibMeasCalibrator m_uncalibMeasCalibrator
Calibrator for the uncalibrated xAOD::UnCalibratedMeasurement objects.
virtual std::unique_ptr< ActsTrk::MutableTrackContainer > fit(const std::vector< const xAOD::UncalibratedMeasurement * > &clusterList, const Acts::BoundTrackParameters &initialParams, const Acts::GeometryContext &tgContext, const Acts::MagneticFieldContext &mfContext, const Acts::CalibrationContext &calContext, const Acts::Surface *targetSurface=nullptr) const override
fit a set of xAOD uncalibrated Measurements
std::unique_ptr< const Acts::Logger > m_logger
logging instance
std::unique_ptr< Fitter > m_fitter
ActsTrk::detail::FitterHelperFunctions::ATLASOutlierFinder m_outlierFinder
ToolHandle< Trk::IRIO_OnTrackCreator > m_ROTcreator
std::array< FitterExtension_t, s_nExtensions > m_kfExtensions
PublicToolHandle< IGeometryRealmConvTool > m_geometryConvTool
detail::TrkMeasSurfaceAccessor m_trkSurfAcc
Accessor to fetch surfaces from the Trk::MeasurementBase track states (legacy EDM).
Acts::KalmanFitterOptions< MutableTrackStateBackend > FitterOptions_t
Abbrivation of the configuration to launch the fit.
xAODItkCalibrator_t m_idCalibrator
Gaudi::Property< double > m_option_outlierChi2Cut
std::unique_ptr< DirectFitter > m_directFitter
ServiceHandle< ITrackingGeometrySvc > m_trackingGeometrySvc
const Acts::Logger & logger() const
Private access to the logger.
detail::TrkMeasurementCalibrator m_trkCalibrator
Calibrator for the Trk::MeasurementBase track states (legacy EDM).
virtual StatusCode initialize() override
Gaudi::Property< double > m_option_ReverseFilteringPt
Gaudi::Property< int > m_option_maxPropagationStep
FitterOptions_t configureFit(const Acts::GeometryContext &tgContext, const Acts::MagneticFieldContext &mfContext, const Acts::CalibrationContext &calContext, const Acts::Surface *surface, detail::SourceLinkType slType) const
Helper method to pack the last information (Calibration, Alignment, B-Field, etc.) for the fit.
static Acts::SourceLink pack(const Ptr_t &measurement)
Pack the measurement type pointer to an Acts::SourceLink including the intermediate conversion into a...
static SourceLinkType getType(const Acts::SourceLink &sl)
Returns the enumeration corresponding to the object type cached within the Acts::SourceLink.
void calibrate(const Acts::GeometryContext &geoctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &link, TrackStateProxy state) const
static OnTrackCalibrator NoCalibration(const ActsTrk::ITrackingGeometrySvc *trackGeoSvc)
Helper class to access the Acts::Surface for a given Acts::SourceLink which is poiniting to a Trk::Me...
void calibrate(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &sl, proxy_t trackState) const
Calibrator delegate implementation to calibrate the ActsTrk fit from Trk::MeasurementBase objects.
Class to calibrate the Acts track states with uncalibrated Trk::PrepRaw data objects.
void calibrate(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &sl, proxy_t trackState) const
Calibrator delegate implementation to calibrate the ActsTrk fit from Trk::PrepRawData objects.
Helper class to access the Acts::surface associated with a Trk::PrepRawData measurement.
void calibrate(const Acts::GeometryContext &gctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &sl, const MutableTrackStateBackend::TrackStateProxy trackState) const
: Interface method for the Acts fitter to calibrate the trajectory track states from the source link ...
Helper class to access the Acts::surface associated with an Uncalibrated xAOD measurement.
virtual void calibrateSourceLink(const Acts::GeometryContext &geoctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &link, ActsTrk::MutableTrackStateBackend::TrackStateProxy state) const =0
Function that's hooked to the calibration delegate of the implemented Acts fitters.
Acts::Result< void > gainMatrixUpdate(const Acts::GeometryContext &gctx, typename trajectory_t::TrackStateProxy trackState, const Acts::Logger &logger)
Acts::Result< void > mbfSmoother(const Acts::GeometryContext &gctx, trajectory_t &trajectory, size_t entryIndex, const Acts::Logger &logger)
SourceLinkType
Enumeration to distinguish between the ATLAS EDM -> Acts::SourceLink variants.
@ xAODUnCalibMeas
UnCalibrated Trk::PrepRawData objects.
@ TrkPrepRawData
Calibrated Trk::MeasurementBase objects.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Acts::VectorMultiTrajectory MutableTrackStateBackend
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
Acts::VectorTrackContainer MutableTrackBackend
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
@ KalmanFitter
tracks produced by the Kalman Fitter
UncalibMeasType
Define the type of the uncalibrated measurement.
static void addFitterTypeProperty(track_container_t &tracksContainer)
add fitter column to the track container
static void setFitterType(trackproxy_t &trackProxy, xAOD::TrackFitter fitterType)
set fitter type of a track