ATLAS Offline Software
Loading...
Searching...
No Matches
ActsToTrkFitterWrapTool.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
11
12
13namespace ActsTrk {
14
16 ATH_CHECK(m_actsFitterTool.retrieve());
18 ATH_CHECK(m_geometryConvTool.retrieve());
19 ATH_CHECK(m_ctxProvider.initialize());
20 return StatusCode::SUCCESS;
21}
22
23std::unique_ptr<Trk::Track>
24ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
25 const Trk::Track& track,
26 const Trk::RunOutlierRemoval /*runOutlier*/,
27 const Trk::ParticleHypothesis hypothesis) const {
28
29 bool useScaledCov = std::abs(m_option_seedCovarianceScale - 1.0) > Acts::s_epsilon;
30
31 return reFitImpl(ctx, track, {}, hypothesis, useScaledCov);
32}
33std::unique_ptr<Trk::Track>
34ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
35 const Trk::Track& track,
36 const Trk::MeasurementSet& measSet,
37 const Trk::RunOutlierRemoval /*runOutlier*/,
38 const Trk::ParticleHypothesis hypothesis) const {
39
40 std::vector<Acts::SourceLink> sourceLinks;
41 detail::MeasurementCalibratorBase::pack(measSet, sourceLinks);
42
43 bool useScaledCov = false;
44
45 return reFitImpl(ctx, track, sourceLinks, hypothesis, useScaledCov);
46}
47
48std::unique_ptr<Trk::Track>
49ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
50 const Trk::Track& track,
51 const Trk::PrepRawDataSet& prepRawSet,
52 const Trk::RunOutlierRemoval /*runOutlier*/,
53 const Trk::ParticleHypothesis hypothesis) const {
54
55 std::vector<Acts::SourceLink> sourceLinks;
56 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
57
58 bool useScaledCov = false;
59
60 return reFitImpl(ctx, track, sourceLinks, hypothesis, useScaledCov);
61}
62
63std::unique_ptr<Trk::Track>
64ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
65 const Trk::PrepRawDataSet& prepRawSet,
66 const Trk::TrackParameters& params,
67 const Trk::RunOutlierRemoval /*runOutlier*/,
68 const Trk::ParticleHypothesis /*hypothesis*/) const {
69
70 std::vector<Acts::SourceLink> sourceLinks;
71 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
72
73 const auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, params);
74
75 return fitImpl(ctx, sourceLinks, initialParams);
76}
77
78std::unique_ptr<Trk::Track>
79ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
80 const Trk::MeasurementSet& prepRawSet,
81 const Trk::TrackParameters& params,
82 const Trk::RunOutlierRemoval /*runOutlier*/,
83 const Trk::ParticleHypothesis /*hypothesis*/) const {
84
85 std::vector<Acts::SourceLink> sourceLinks;
86 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
87
88 const auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, params);
89
90 return fitImpl(ctx, sourceLinks, initialParams);
91}
92
93std::unique_ptr<Trk::Track>
94ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
95 const Trk::Track& track1,
96 const Trk::Track& track2,
97 const Trk::RunOutlierRemoval /*runOutlier*/,
98 const Trk::ParticleHypothesis hypothesis) const {
99 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::fit(Track,Track,)"
100 << "with Tracks from #1 = " << track1.info().dumpInfo()
101 << " and #2 = " << track2.info().dumpInfo());
102
103 // protection, if empty track2
104 if (!track2.measurementsOnTrack()) {
105 ATH_MSG_DEBUG( "input #2 is empty try to fit track 1 alone" );
106 return fit(ctx,track1);
107 }
108
109 // protection, if empty track1
110 if (!track1.measurementsOnTrack()) {
111 ATH_MSG_DEBUG( "input #1 is empty try to fit track 2 alone" );
112 return fit(ctx,track2);
113 }
114
115 std::vector<Acts::SourceLink> trackSourceLinks2 = m_ATLASConverterTool->trkTrackToSourceLinks(track2);
116
117 bool useScaledCov = std::abs(m_option_seedCovarianceScale - 1.0) > Acts::s_epsilon;
118
119 return reFitImpl(ctx, track1, trackSourceLinks2, hypothesis, useScaledCov);
120}
121
122std::unique_ptr<Trk::Track>
124 const Trk::Track& track,
125 const std::vector<Acts::SourceLink>& measColl,
126 const Trk::ParticleHypothesis hypothesis,
127 const bool useScaledCov) const {
128 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::reFitImpl(Track,measColl,)"
129 << " with Track from author = " << track.info().dumpInfo());
130
131 // protection against not having measurements on the input track
132 if (!track.measurementsOnTrack() || (track.measurementsOnTrack()->size() < 2 && measColl.empty())) {
133 ATH_MSG_DEBUG("called to refit empty track or track with too little information, reject fit");
134 return nullptr;
135 }
136
137 // protection against not having track parameters on the input track
138 if (!track.trackParameters() || track.trackParameters()->empty()) {
139 ATH_MSG_DEBUG("input fails to provide track parameters for seeding the fitter, reject fit");
140 return nullptr;
141 }
142
143 std::vector<Acts::SourceLink> trackSourceLinks = m_ATLASConverterTool->trkTrackToSourceLinks(track);
144 trackSourceLinks.insert(trackSourceLinks.end(), std::make_move_iterator(measColl.begin()),
145 std::make_move_iterator(measColl.end()));
146
147 auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, *track.perigeeParameters());
148 if (useScaledCov) {
149 // The covariance from already fitted track are too small and would result an incorect smoothing.
150 // We scale up the input covaraiance to avoid this.
151 Acts::BoundMatrix scaledCov = m_option_seedCovarianceScale * (*initialParams.covariance());
152 initialParams = Acts::BoundTrackParameters(initialParams.referenceSurface().getSharedPtr(),
153 initialParams.parameters(),
154 scaledCov, ParticleHypothesis::convert(hypothesis));
155 }
156
157 return fitImpl(ctx, trackSourceLinks, initialParams);
158}
159
160std::unique_ptr<Trk::Track>
161ActsToTrkFitterWrapTool::fitImpl(const EventContext& ctx,
162 const std::vector<Acts::SourceLink>& measColl,
163 const Acts::BoundTrackParameters& params) const {
164 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::fitImpl(measColl,)"
165 << " with nMeas = " << measColl.size());
166
167 // protection against not having measurements on the input track
168 if (measColl.size() < 2) {
169 ATH_MSG_DEBUG("called to refit empty measurement set or a measurement set with too little information, reject fit");
170 return nullptr;
171 }
172
173 // Construct a perigee surface as the target surface
174 auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3::Zero());
175
176 const Acts::GeometryContext tgContext{m_ctxProvider.getGeometryContext(ctx)};
177 const Acts::MagneticFieldContext mfContext{m_ctxProvider.getMagneticFieldContext(ctx)};
178 const Acts::CalibrationContext calContext{m_ctxProvider.getCalibrationContext(ctx)};
179
180 std::unique_ptr<MutableTrackContainer> outTracks =
181 m_actsFitterTool->fit(measColl, params, tgContext, mfContext, calContext, pSurface.get());
182
183 if (!outTracks || outTracks->size() == 0 ) {
184 ATH_MSG_DEBUG("Acts fitter failed to refit the track, reject fit");
185 return nullptr;
186 }
187
188 // We expect only one track to be returned
189 for (auto trkProxy : *outTracks) {
190
194
195 std::unique_ptr<Trk::Track> convertedTrack =
196 m_ATLASConverterTool->convertActsToTrk(ctx, trkProxy, toTrkFitterType(fitterType));
197
198 if (convertedTrack) {
199 return convertedTrack;
200 }
201 }
202 return nullptr;
203}
204}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Property< double > m_option_seedCovarianceScale
Property for the seed covariance scale factor.
ToolHandle< IFitterTool > m_actsFitterTool
The underlying Acts fitter tool.
ContextUtility m_ctxProvider
Auxiliary class to access the magnetic field, geometry and calibration context.
virtual std::unique_ptr< Trk::Track > fit(const EventContext &ctx, const Trk::Track &track, const Trk::RunOutlierRemoval runOutlier=false, const Trk::ParticleHypothesis hypothesis=Trk::nonInteracting) const override
Re-fit a track using the ACTS fitter tool.
ToolHandle< ITrackConverterTool > m_ATLASConverterTool
Track converter tool for converting Acts tracks to ATLAS tracks.
std::unique_ptr< Trk::Track > fitImpl(const EventContext &ctx, const std::vector< Acts::SourceLink > &measColl, const Acts::BoundTrackParameters &params) const
Implementation of the logic for fitting a track to a set of measurements passed as source links.
std::unique_ptr< Trk::Track > reFitImpl(const EventContext &ctx, const Trk::Track &track, const std::vector< Acts::SourceLink > &measColl, const Trk::ParticleHypothesis hypothesis, const bool useScaledCov=false) const
Implementation of the logic for re-fitting a track adding a set of measurements passed as source link...
PublicToolHandle< IGeometryRealmConvTool > m_geometryConvTool
Geometry realm converter tool.
static Acts::SourceLink pack(const Ptr_t &measurement)
Pack the measurement type pointer to an Acts::SourceLink including the intermediate conversion into a...
std::string dumpInfo() const
Returns a string with the name of the fitter of this track (i.e.
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h)
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Trk::TrackInfo::TrackFitter toTrkFitterType(const xAOD::TrackFitter fType)
Converts xAOD fitter type to Trk fitter type.
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
Definition FitterTypes.h:30
bool RunOutlierRemoval
switch to toggle quality processing after fit
Definition FitterTypes.h:22
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
std::vector< const PrepRawData * > PrepRawDataSet
vector of clusters and drift circles
Definition FitterTypes.h:26
TrackFitter
Enums to identify who created this track and which properties does it have.
@ Unknown
Track fitter not defined.
static xAOD::TrackFitter fitterType(const consttrackproxy_t &trackProxy)
get fitter type of a track
static bool hasFitterType(const consttrackproxy_t &trackProxy)
test whether a track has a fitter type