ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalChiSquareFitterTool.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/EventData/VectorTrackContainer.hpp"
9#include "Acts/Propagator/Navigator.hpp"
10#include "Acts/Propagator/Propagator.hpp"
11#include "Acts/Surfaces/Surface.hpp"
12#include "Acts/TrackFitting/GlobalChiSquareFitter.hpp"
13#include "Acts/Utilities/CalibrationContext.hpp"
14#include "Acts/Utilities/Helpers.hpp"
15#include "Acts/Utilities/Logger.hpp"
18
19// PACKAGE
21#include "ActsInterop/Logger.h"
22
23namespace ActsTrk {
24
26
27 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
30 ATH_CHECK(m_ROTcreator.retrieve(EnableTool{!m_ROTcreator.empty()}));
31 ATH_CHECK(m_geometryConvTool.retrieve());
32 ATH_CHECK(m_muonCalibrator.retrieve(EnableTool{!m_muonCalibrator.empty()}));
33
34 m_logger = makeActsAthenaLogger(this, "Gx2fRefit");
35 if (!m_doStraightLine){
36 // Fitter
37 CurvedPropagator_t::Stepper stepper{std::make_shared<ATLASMagneticFieldWrapper>()};
38 Acts::Navigator::Config navConfig{m_trackingGeometryTool->trackingGeometry()};
39 Acts::Navigator navigator(std::move(navConfig), logger().cloneWithSuffix("Navigator"));
40 CurvedPropagator_t propagator{stepper, std::move(navigator), logger().cloneWithSuffix("Prop")};
41
42 m_fitter = std::make_unique<CurvedFitter_t>(std::move(propagator),
43 logger().cloneWithSuffix("GlobalChiSquareFitter"));
44 } else {
45 Acts::StraightLineStepper stepper{};
46 Acts::Navigator::Config navConfig{m_trackingGeometryTool->trackingGeometry()};
47 Acts::Navigator navigator(std::move(navConfig), logger().cloneWithSuffix("Navigator"));
48 StraightPropagator_t propagator{stepper, std::move(navigator), logger().cloneWithSuffix("Prop")};
49
50 m_slFitter = std::make_unique<StraightFitter_t>(std::move(propagator),
51 logger().cloneWithSuffix("GlobalChiSquareFitter"));
52 }
53
54
55 m_outlierFinder.StateChiSquaredPerNumberDoFCut = m_option_outlierChi2Cut;
56
57 Gx2FitterExtension_t extensionTemplate{};
58 extensionTemplate.outlierFinder.connect<&detail::FitterHelperFunctions::ATLASOutlierFinder::operator()
61
63 {
66
68 configureMe = extensionTemplate;
70 configureMe.surfaceAccessor.connect<&detail::TrkMeasSurfaceAccessor::operator()>(&m_trkMeasSurfAcc);
71 }
73 {
76
78 configureMe = extensionTemplate;
80 configureMe.surfaceAccessor.connect<&detail::TrkPrepRawDataSurfaceAcc::operator()>(&m_prdSurfaceAcc);
81 }
82 {
84
87 configureMe = extensionTemplate;
88 configureMe.surfaceAccessor.connect<&detail::xAODUncalibMeasSurfAcc::operator()>(&m_unalibMeasSurfAcc);
91
93 using enum xAOD::UncalibMeasType;
94 if (m_muonCalibrator.isEnabled()) {
95 for (const auto muonType : {MdtDriftCircleType, RpcStripType, TgcStripType, MMClusterType, sTgcStripType}) {
97 }
98 }
99 for (const auto idType: {PixelClusterType, StripClusterType, Other, HGTDClusterType}) {
101 }
102
103 }
104 return StatusCode::SUCCESS;
105}
106
108 GlobalChiSquareFitterTool::configureFit(const Acts::GeometryContext& tgContext,
109 const Acts::MagneticFieldContext& mfContext,
110 const Acts::CalibrationContext& calContext,
111 const Acts::Surface* surface,
112 detail::SourceLinkType slType) const {
113 Acts::PropagatorPlainOptions propagationOption{tgContext, mfContext};
114 propagationOption.maxSteps = m_option_maxPropagationStep;
115 propagationOption.maxTargetSkipping = m_option_maxNavSurfaces;
116 // Set the Gx2Fitter options
117 return Gx2FitterOptions_t{tgContext, mfContext, calContext,
118 m_gx2fExtensions.at(Acts::toUnderlying(slType)), //slType can be 3
119 std::move(propagationOption),
120 surface, m_option_includeScat,
122 Acts::FreeToBoundCorrection{m_doJacobianCorr},
123 m_nIterMax};
124}
125
126// fit a set of PrepRawData objects
127// --------------------------------
128std::unique_ptr<MutableTrackContainer> GlobalChiSquareFitterTool::fit(
129 const std::vector<const xAOD::UncalibratedMeasurement*>& measList,
130 const Acts::BoundTrackParameters& initialParams,
131 const Acts::GeometryContext& tgContext,
132 const Acts::MagneticFieldContext& mfContext,
133 const Acts::CalibrationContext& calContext,
134 const Acts::Surface* targetSurface) const {
135
136 std::vector<Acts::SourceLink> sourceLinks{};
137 detail::MeasurementCalibratorBase::pack(measList, sourceLinks);
138
139 return fit(sourceLinks, initialParams, tgContext, mfContext, calContext, targetSurface);
140}
141
142std::unique_ptr<MutableTrackContainer> GlobalChiSquareFitterTool::fit(
143 const Seed& seed,
144 const Acts::BoundTrackParameters& initialParams,
145 const Acts::GeometryContext& tgContext,
146 const Acts::MagneticFieldContext& mfContext,
147 const Acts::CalibrationContext& calContext,
148 const Acts::Surface& targetSurface) const {
149
150 std::vector<const xAOD::UncalibratedMeasurement*> sourceLinks;
151 sourceLinks.reserve(6);
152
153 for (const xAOD::SpacePoint* sp : seed.sp()) {
154 sourceLinks.insert(sourceLinks.end(), sp->measurements().begin(), sp->measurements().end());
155 }
156 return fit(sourceLinks, initialParams, tgContext, mfContext, calContext, &targetSurface);
157}
158
159
161 const EventContext& /*ctx*/,
162 const TrackContainer::ConstTrackProxy& /*track*/,
163 MutableTrackContainer& /*trackContainer*/,
164 const Acts::PerigeeSurface& /*pSurface*/) const
165{
166 ATH_MSG_ERROR("Track refit method not implemented in GlobalChiSquareFitterTool yet");
167 return StatusCode::FAILURE;
168}
169
170std::unique_ptr<MutableTrackContainer>
171GlobalChiSquareFitterTool::fit(const std::vector<Acts::SourceLink>& sourceLinks,
172 const Acts::BoundTrackParameters& initialParams,
173 const Acts::GeometryContext& tgContext,
174 const Acts::MagneticFieldContext& mfContext,
175 const Acts::CalibrationContext& calContext,
176 const Acts::Surface* targetSurface) const {
177 if (sourceLinks.empty()) {
178 ATH_MSG_DEBUG("No measurements given. Nothing to do");
179 return nullptr;
180 }
181 // Construct a perigee surface as the target surface
182 std::shared_ptr<Acts::Surface> pSurface{};
183 if (!targetSurface) {
184 pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3::Zero());
185 targetSurface = pSurface.get();
186 }
187
189
190 Gx2FitterOptions_t kfOptions = configureFit(tgContext, mfContext, calContext,
191 targetSurface, slType);
192
193 ActsTrk::MutableTrackBackend trackContainerBackEnd;
194 ActsTrk::MutableTrackStateBackend multiTrajBackEnd;
195 auto tracks = std::make_unique<MutableTrackContainer>(std::move(trackContainerBackEnd),
196 std::move(multiTrajBackEnd));
197
198 // Perform the fit
199 auto result = ATH_LIKELY(m_fitter)
200 ? m_fitter->fit(sourceLinks.begin(), sourceLinks.end(), initialParams, kfOptions, *tracks)
201 : m_slFitter->fit(sourceLinks.begin(), sourceLinks.end(), initialParams, kfOptions, *tracks);
202
203 if (not result.ok()) {
204 ATH_MSG_VERBOSE("Global chi2 fit failed");
205 return nullptr;
206 }
207
209 for (auto trkProxy : *tracks) {
211 }
212
213 return tracks;
214}
215} // namespace ActsTrk
#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)
#define ATH_LIKELY(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)
Acts::Experimental::Gx2FitterOptions< MutableTrackStateBackend > Gx2FitterOptions_t
Abbrivation of the configuration to launch the fit.
Gaudi::Property< double > m_option_outlierChi2Cut
Chi2 cut used by the outlier finder.
ToolHandle< IExtrapolationTool > m_extrapolationTool
std::unique_ptr< const Acts::Logger > m_logger
logging instance
detail::TrkMeasSurfaceAccessor m_trkMeasSurfAcc
Surface accessor delegate for Trk::MeasurementBase objects.
detail::TrkPrepRawDataCalibrator m_prdCalibrator
Calibrator of the uncalibrated Trk::PrepRawData objects to RIO_OnTrack objects.
Acts::Propagator< Acts::StraightLineStepper, Acts::Navigator > StraightPropagator_t
Type erased track fitter function.
const Acts::Logger & logger() const
Private access to the logger.
Gaudi::Property< bool > m_doJacobianCorr
Account for non linear effects from free -> bound jacobian.
ToolHandle< MuonR4::ISpacePointCalibrator > m_muonCalibrator
Acts::Experimental::Gx2FitterExtensions< MutableTrackStateBackend > Gx2FitterExtension_t
Abbrivation of the fitter extensions.
std::array< Gx2FitterExtension_t, s_nExtensions > m_gx2fExtensions
Gaudi::Property< unsigned > m_option_maxPropagationStep
Maximum number of steps per propagation call.
detail::FitterHelperFunctions::ATLASOutlierFinder m_outlierFinder
Gaudi::Property< bool > m_option_includeScat
Consider multiple scattering of the particle.
PublicToolHandle< ITrackingGeometryTool > m_trackingGeometryTool
PublicToolHandle< IGeometryRealmConvTool > m_geometryConvTool
detail::TrkPrepRawDataSurfaceAcc m_prdSurfaceAcc
Surface accessor delegate for Trk::PrepRawData objects.
ToolHandle< Trk::IRIO_OnTrackCreator > m_ROTcreator
std::unique_ptr< StraightFitter_t > m_slFitter
The underlying straight line Acts fitter.
Gaudi::Property< bool > m_option_includeELoss
Consider particle's energy loss in the fit.
virtual std::unique_ptr< 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
Gaudi::Property< unsigned > m_option_maxNavSurfaces
Number of maximum surfaces to be tried before the navigrator aborts.
std::unique_ptr< CurvedFitter_t > m_fitter
The underlying curved Acts fitter.
Gx2FitterOptions_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.
detail::TrkMeasurementCalibrator m_trkMeasCalibrator
Pass through calibrator of the Trk::MeasurementBase objects from the TrackState container.
detail::xAODUncalibMeasSurfAcc m_unalibMeasSurfAcc
Surface accessor delegate for xAOD::UncalibratedMeasurement objects.
Acts::Propagator< Acts::EigenStepper<>, Acts::Navigator > CurvedPropagator_t
Gaudi::Property< unsigned > m_nIterMax
Number of iterations a fit may take.
Gaudi::Property< bool > m_doStraightLine
Option to toggle whether a straight line fitter shall be used.
detail::xAODUncalibMeasCalibrator m_uncalibMeasCalibrator
Calibrator for the uncalibrated xAOD::UnCalibratedMeasurement objects.
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::ITrackingGeometryTool *trackGeoTool)
Helper class to access the Acts::Surface for a given Acts::SourceLink which is poiniting to a Trk::Me...
Calibrator class that links the legacy Trk::MeasurementBase objects with the Acts MultiTrajectory tra...
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)
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
@ GlobalChi2Fitter
Track's from Thijs' global chi^2 fitter or the ACTS implementation.
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