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
12
13
14namespace ActsTrk {
15
17 ATH_CHECK(m_actsFitterTool.retrieve());
21 ATH_CHECK(m_geometryConvTool.retrieve());
22
23 return StatusCode::SUCCESS;
24}
25
26std::unique_ptr<Trk::Track>
27ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
28 const Trk::Track& track,
29 const Trk::RunOutlierRemoval /*runOutlier*/,
30 const Trk::ParticleHypothesis hypothesis) const {
31
32 bool useScaledCov = std::abs(m_option_seedCovarianceScale - 1.0) > Acts::s_epsilon;
33
34 return reFitImpl(ctx, track, {}, hypothesis, useScaledCov);
35}
36std::unique_ptr<Trk::Track>
37ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
38 const Trk::Track& track,
39 const Trk::MeasurementSet& measSet,
40 const Trk::RunOutlierRemoval /*runOutlier*/,
41 const Trk::ParticleHypothesis hypothesis) const {
42
43 std::vector<Acts::SourceLink> sourceLinks;
44 detail::MeasurementCalibratorBase::pack(measSet, sourceLinks);
45
46 bool useScaledCov = false;
47
48 return reFitImpl(ctx, track, sourceLinks, hypothesis, useScaledCov);
49}
50
51std::unique_ptr<Trk::Track>
52ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
53 const Trk::Track& track,
54 const Trk::PrepRawDataSet& prepRawSet,
55 const Trk::RunOutlierRemoval /*runOutlier*/,
56 const Trk::ParticleHypothesis hypothesis) const {
57
58 std::vector<Acts::SourceLink> sourceLinks;
59 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
60
61 bool useScaledCov = false;
62
63 return reFitImpl(ctx, track, sourceLinks, hypothesis, useScaledCov);
64}
65
66std::unique_ptr<Trk::Track>
67ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
68 const Trk::PrepRawDataSet& prepRawSet,
69 const Trk::TrackParameters& params,
70 const Trk::RunOutlierRemoval /*runOutlier*/,
71 const Trk::ParticleHypothesis /*hypothesis*/) const {
72
73 std::vector<Acts::SourceLink> sourceLinks;
74 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
75
76 const auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, params);
77
78 return fitImpl(ctx, sourceLinks, initialParams);
79}
80
81std::unique_ptr<Trk::Track>
82ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
83 const Trk::MeasurementSet& prepRawSet,
84 const Trk::TrackParameters& params,
85 const Trk::RunOutlierRemoval /*runOutlier*/,
86 const Trk::ParticleHypothesis /*hypothesis*/) const {
87
88 std::vector<Acts::SourceLink> sourceLinks;
89 detail::MeasurementCalibratorBase::pack(prepRawSet, sourceLinks);
90
91 const auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, params);
92
93 return fitImpl(ctx, sourceLinks, initialParams);
94}
95
96std::unique_ptr<Trk::Track>
97ActsToTrkFitterWrapTool::fit(const EventContext& ctx,
98 const Trk::Track& track1,
99 const Trk::Track& track2,
100 const Trk::RunOutlierRemoval /*runOutlier*/,
101 const Trk::ParticleHypothesis hypothesis) const {
102 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::fit(Track,Track,)"
103 << "with Tracks from #1 = " << track1.info().dumpInfo()
104 << " and #2 = " << track2.info().dumpInfo());
105
106 // protection, if empty track2
107 if (!track2.measurementsOnTrack()) {
108 ATH_MSG_DEBUG( "input #2 is empty try to fit track 1 alone" );
109 return fit(ctx,track1);
110 }
111
112 // protection, if empty track1
113 if (!track1.measurementsOnTrack()) {
114 ATH_MSG_DEBUG( "input #1 is empty try to fit track 2 alone" );
115 return fit(ctx,track2);
116 }
117
118 std::vector<Acts::SourceLink> trackSourceLinks2 = m_ATLASConverterTool->trkTrackToSourceLinks(track2);
119
120 bool useScaledCov = std::abs(m_option_seedCovarianceScale - 1.0) > Acts::s_epsilon;
121
122 return reFitImpl(ctx, track1, trackSourceLinks2, hypothesis, useScaledCov);
123}
124
125std::unique_ptr<Trk::Track>
127 const Trk::Track& track,
128 const std::vector<Acts::SourceLink>& measColl,
129 const Trk::ParticleHypothesis hypothesis,
130 const bool useScaledCov) const {
131 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::reFitImpl(Track,measColl,)"
132 << " with Track from author = " << track.info().dumpInfo());
133
134 // protection against not having measurements on the input track
135 if (!track.measurementsOnTrack() || (track.measurementsOnTrack()->size() < 2 && measColl.empty())) {
136 ATH_MSG_DEBUG("called to refit empty track or track with too little information, reject fit");
137 return nullptr;
138 }
139
140 // protection against not having track parameters on the input track
141 if (!track.trackParameters() || track.trackParameters()->empty()) {
142 ATH_MSG_DEBUG("input fails to provide track parameters for seeding the fitter, reject fit");
143 return nullptr;
144 }
145
146 std::vector<Acts::SourceLink> trackSourceLinks = m_ATLASConverterTool->trkTrackToSourceLinks(track);
147 trackSourceLinks.insert(trackSourceLinks.end(), std::make_move_iterator(measColl.begin()),
148 std::make_move_iterator(measColl.end()));
149
150 auto initialParams = m_geometryConvTool->convertTrackParametersToActs(ctx, *track.perigeeParameters());
151 if (useScaledCov) {
152 // The covariance from already fitted track are too small and would result an incorect smoothing.
153 // We scale up the input covaraiance to avoid this.
154 Acts::BoundMatrix scaledCov = m_option_seedCovarianceScale * (*initialParams.covariance());
155 initialParams = Acts::BoundTrackParameters(initialParams.referenceSurface().getSharedPtr(),
156 initialParams.parameters(),
157 scaledCov, ParticleHypothesis::convert(hypothesis));
158 }
159
160 return fitImpl(ctx, trackSourceLinks, initialParams);
161}
162
163std::unique_ptr<Trk::Track>
164ActsToTrkFitterWrapTool::fitImpl(const EventContext& ctx,
165 const std::vector<Acts::SourceLink>& measColl,
166 const Acts::BoundTrackParameters& params) const {
167 ATH_MSG_VERBOSE ("--> enter ActsToTrkFitterWrapTool::fitImpl(measColl,)"
168 << " with nMeas = " << measColl.size());
169
170 // protection against not having measurements on the input track
171 if (measColl.size() < 2) {
172 ATH_MSG_DEBUG("called to refit empty measurement set or a measurement set with too little information, reject fit");
173 return nullptr;
174 }
175
176 // Construct a perigee surface as the target surface
177 auto pSurface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3::Zero());
178
179 const Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
180 const Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
181 const Acts::CalibrationContext calContext{getCalibrationContext(ctx)};
182
183 std::unique_ptr<MutableTrackContainer> outTracks =
184 m_actsFitterTool->fit(measColl, params, tgContext, mfContext, calContext, pSurface.get());
185
186 if (!outTracks || outTracks->size() == 0 ) {
187 ATH_MSG_DEBUG("Acts fitter failed to refit the track, reject fit");
188 return nullptr;
189 }
190
191 // We expect only one track to be returned
192 for (auto trkProxy : *outTracks) {
193
197
198 std::unique_ptr<Trk::Track> convertedTrack =
199 m_ATLASConverterTool->convertActsToTrk(ctx, trkProxy, toTrkFitterType(fitterType));
200
201 if (convertedTrack) {
202 return convertedTrack;
203 }
204 }
205 return nullptr;
206}
207}
#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< IExtrapolationTool > m_extrapolationTool
Acts extrapolation tool.
ToolHandle< IFitterTool > m_actsFitterTool
The underlying Acts fitter tool.
PublicToolHandle< ITrackingGeometryTool > m_trackingGeometryTool
Tracking geometry tool.
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.
virtual std::unique_ptr< Trk::Track > fit(const EventContext &ctx, const Trk::Track &track1, const Trk::Track &track2, const Trk::RunOutlierRemoval runOutlier=false, const Trk::ParticleHypothesis hypothesis=Trk::nonInteracting) const override
Combines two tracks by fitting them together.
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...
Acts::CalibrationContext getCalibrationContext(const EventContext &ctx)
The Acts::Calibration context is piped through the Acts fitters to (re)calibrate the Acts::SourceLink...
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