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__);
29 ATH_CHECK(m_ROTcreator.retrieve(EnableTool{!m_ROTcreator.empty()}));
30 ATH_CHECK(m_geometryConvTool.retrieve());
31 ATH_CHECK(m_muonCalibrator.retrieve(EnableTool{!m_muonCalibrator.empty()}));
32
33 m_logger = makeActsAthenaLogger(this, "Gx2fRefit");
34 if (!m_doStraightLine){
35 // Fitter
36 CurvedPropagator_t::Stepper stepper{std::make_shared<ATLASMagneticFieldWrapper>()};
37 Acts::Navigator::Config navConfig{m_trackingGeometrySvc->trackingGeometry()};
38 Acts::Navigator navigator(std::move(navConfig), logger().cloneWithSuffix("Navigator"));
39 CurvedPropagator_t propagator{stepper, std::move(navigator), logger().cloneWithSuffix("Prop")};
40
41 m_fitter = std::make_unique<CurvedFitter_t>(std::move(propagator),
42 logger().cloneWithSuffix("GlobalChiSquareFitter"));
43 } else {
44 Acts::StraightLineStepper stepper{};
45 Acts::Navigator::Config navConfig{m_trackingGeometrySvc->trackingGeometry()};
46 Acts::Navigator navigator(std::move(navConfig), logger().cloneWithSuffix("Navigator"));
47 StraightPropagator_t propagator{stepper, std::move(navigator), logger().cloneWithSuffix("Prop")};
48
49 m_slFitter = std::make_unique<StraightFitter_t>(std::move(propagator),
50 logger().cloneWithSuffix("GlobalChiSquareFitter"));
51 }
52
53
54 m_outlierFinder.StateChiSquaredPerNumberDoFCut = m_option_outlierChi2Cut;
55
56 Gx2FitterExtension_t extensionTemplate{};
57 extensionTemplate.outlierFinder.connect<&detail::FitterHelperFunctions::ATLASOutlierFinder::operator()
59
61 {
64
66 configureMe = extensionTemplate;
68 configureMe.surfaceAccessor.connect<&detail::TrkMeasSurfaceAccessor::operator()>(&m_trkMeasSurfAcc);
69 }
71 {
74
76 configureMe = extensionTemplate;
78 configureMe.surfaceAccessor.connect<&detail::TrkPrepRawDataSurfaceAcc::operator()>(&m_prdSurfaceAcc);
79 }
80 {
82
85 configureMe = extensionTemplate;
86 configureMe.surfaceAccessor.connect<&detail::xAODUncalibMeasSurfAcc::operator()>(&m_unalibMeasSurfAcc);
89
91 using enum xAOD::UncalibMeasType;
92 if (m_muonCalibrator.isEnabled()) {
93 for (const auto muonType : {MdtDriftCircleType, RpcStripType, TgcStripType, MMClusterType, sTgcStripType}) {
95 }
96 }
97 for (const auto idType: {PixelClusterType, StripClusterType, HGTDClusterType}) {
99 }
100
101 }
102 return StatusCode::SUCCESS;
103}
104
106 GlobalChiSquareFitterTool::configureFit(const Acts::GeometryContext& tgContext,
107 const Acts::MagneticFieldContext& mfContext,
108 const Acts::CalibrationContext& calContext,
109 const Acts::Surface* surface,
110 detail::SourceLinkType slType) const {
111 Acts::PropagatorPlainOptions propagationOption{tgContext, mfContext};
112 propagationOption.maxSteps = m_option_maxPropagationStep;
113 propagationOption.maxTargetSkipping = m_option_maxNavSurfaces;
114 // Set the Gx2Fitter options
115 return Gx2FitterOptions_t{tgContext, mfContext, calContext,
116 m_gx2fExtensions.at(Acts::toUnderlying(slType)), //slType can be 3
117 std::move(propagationOption),
118 surface, m_option_includeScat,
120 Acts::FreeToBoundCorrection{m_doJacobianCorr},
121 m_nIterMax};
122}
123
124// fit a set of PrepRawData objects
125// --------------------------------
126std::unique_ptr<MutableTrackContainer> GlobalChiSquareFitterTool::fit(
127 const std::vector<const xAOD::UncalibratedMeasurement*>& measList,
128 const Acts::BoundTrackParameters& initialParams,
129 const Acts::GeometryContext& tgContext,
130 const Acts::MagneticFieldContext& mfContext,
131 const Acts::CalibrationContext& calContext,
132 const Acts::Surface* targetSurface) const {
133
134 std::vector<Acts::SourceLink> sourceLinks{};
135 detail::MeasurementCalibratorBase::pack(measList, sourceLinks);
136
137 return fit(sourceLinks, initialParams, tgContext, mfContext, calContext, targetSurface);
138}
139
140std::unique_ptr<MutableTrackContainer> GlobalChiSquareFitterTool::fit(
141 const Seed& seed,
142 const Acts::BoundTrackParameters& initialParams,
143 const Acts::GeometryContext& tgContext,
144 const Acts::MagneticFieldContext& mfContext,
145 const Acts::CalibrationContext& calContext,
146 const Acts::Surface& targetSurface) const {
147
148 std::vector<const xAOD::UncalibratedMeasurement*> sourceLinks;
149 sourceLinks.reserve(6);
150
151 for (const xAOD::SpacePoint* sp : seed.sp()) {
152 sourceLinks.insert(sourceLinks.end(), sp->measurements().begin(), sp->measurements().end());
153 }
154 return fit(sourceLinks, initialParams, tgContext, mfContext, calContext, &targetSurface);
155}
156
157
159 const EventContext& /*ctx*/,
160 const TrackContainer::ConstTrackProxy& /*track*/,
161 MutableTrackContainer& /*trackContainer*/,
162 const Acts::PerigeeSurface& /*pSurface*/) const
163{
164 ATH_MSG_ERROR("Track refit method not implemented in GlobalChiSquareFitterTool yet");
165 return StatusCode::FAILURE;
166}
167
168std::unique_ptr<MutableTrackContainer>
169GlobalChiSquareFitterTool::fit(const std::vector<Acts::SourceLink>& sourceLinks,
170 const Acts::BoundTrackParameters& initialParams,
171 const Acts::GeometryContext& tgContext,
172 const Acts::MagneticFieldContext& mfContext,
173 const Acts::CalibrationContext& calContext,
174 const Acts::Surface* targetSurface) const {
175 if (sourceLinks.empty()) {
176 ATH_MSG_DEBUG("No measurements given. Nothing to do");
177 return nullptr;
178 }
179 // Construct a perigee surface as the target surface
180 std::shared_ptr<Acts::Surface> pSurface{};
181 if (!targetSurface) {
182 pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3::Zero());
183 targetSurface = pSurface.get();
184 }
185
187
188 Gx2FitterOptions_t kfOptions = configureFit(tgContext, mfContext, calContext,
189 targetSurface, slType);
190
191 ActsTrk::MutableTrackBackend trackContainerBackEnd;
192 ActsTrk::MutableTrackStateBackend multiTrajBackEnd;
193 auto tracks = std::make_unique<MutableTrackContainer>(std::move(trackContainerBackEnd),
194 std::move(multiTrajBackEnd));
195
196 // Perform the fit
197 auto result = ATH_LIKELY(m_fitter)
198 ? m_fitter->fit(sourceLinks.begin(), sourceLinks.end(), initialParams, kfOptions, *tracks)
199 : m_slFitter->fit(sourceLinks.begin(), sourceLinks.end(), initialParams, kfOptions, *tracks);
200
201 if (not result.ok()) {
202 ATH_MSG_VERBOSE("Global chi2 fit failed");
203 return nullptr;
204 }
205
207 for (auto trkProxy : *tracks) {
209 }
210
211 return tracks;
212}
213} // 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)
Definition Logger.cxx:64
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.
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.
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
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< 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::ITrackingGeometrySvc *trackGeoSvc)
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.
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