7#include "Acts/Surfaces/PerigeeSurface.hpp"
8#include "Acts/Surfaces/PlaneSurface.hpp"
9#include "Acts/Surfaces/detail/PlanarHelper.hpp"
16#include "GaudiKernel/PhysicalConstants.h"
24#include "GaudiKernel/PhysicalConstants.h"
28#include <system_error>
30using namespace Acts::UnitLiterals;
31using namespace Acts::PlanarHelper;
49 return StatusCode::SUCCESS;
55 ATH_MSG_VERBOSE(
"Run track finding in event "<<ctx.eventID().event_number());
58 auto seedContainer = std::make_unique<MsTrackSeedContainer>();
65 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
66 const Acts::MagneticFieldContext mfContext =
m_ctxProvider.getMagneticFieldContext(ctx);
67 const Acts::CalibrationContext calContext{
m_ctxProvider.getCalibrationContext(ctx)};
70 Acts::VectorTrackContainer trackBackend{};
71 Acts::VectorMultiTrajectory trackStateBackend{};
73 std::move(trackStateBackend)};
75 cacheTrkContainer.addColumn<std::size_t>(
"parentSeed");
83 auto lastTrack = cacheTrkContainer.getTrack(cacheTrkContainer.size() -1);
84 lastTrack.component<std::size_t, Acts::hashString(
"parentSeed")>() = seedIdx;
93 Acts::ConstVectorTrackContainer ctrackBackend{std::move(cacheTrkContainer.container())};
94 Acts::ConstVectorMultiTrajectory ctrackStateBackend{std::move(cacheTrkContainer.trackStateContainer())};
95 auto ctc = std::make_unique<ActsTrk::TrackContainer>(std::move(ctrackBackend),
96 std::move(ctrackStateBackend));
100 return StatusCode::SUCCESS;
106 const Acts::CalibrationContext& calContext,
108 const EventContext& ctx{*calContext.get<
const EventContext*>()};
110 auto initialPars =
m_seedingTool->estimateStartParameters(ctx, seed);
111 if (!initialPars.ok()) {
113 <<
" - Start parameter creation failed. ");
114 return std::make_pair(OptBoundPars_t::failure(std::make_error_code(std::errc::invalid_argument)),
115 std::vector<const xAOD::UncalibratedMeasurement_v1*>{});
119 measurements.reserve(100);
124 if (
msgLvl(MSG::VERBOSE)) {
125 std::stringstream sstr{};
129 <<
", "<<m->numDimensions()<<
", "
130 <<
", "<<surf.geometryId()<<
" @ "<<
Amg::toString(surf.localToGlobalTransform(tgContext))<<std::endl;
133 <<
", direction: "<<
Amg::toString(segment->direction()) <<
" eta " << segment->direction().eta() <<
" phi " << segment->direction().phi() <<
"\n"<<sstr.str());
135 measurements.insert(measurements.end(),
136 std::make_move_iterator(segMeasurements.begin()),
137 std::make_move_iterator(segMeasurements.end()));
140 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - "<<measurements.size()<<
" measurements");
141 if (measurements.empty()) {
142 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - No measurements were associated with seed "<<seed);
143 return std::make_pair(OptBoundPars_t::failure(std::make_error_code(std::errc::invalid_argument)),
144 std::vector<const xAOD::UncalibratedMeasurement_v1*>{});
146 return std::make_pair(std::move(initialPars), std::move(measurements));
150 const Acts::MagneticFieldContext& mfContext,
151 const Acts::CalibrationContext& calContext,
155 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Attempt to fit a new track seed \n"<<seed);
156 const EventContext& ctx{*calContext.get<
const EventContext*>()};
157 const auto [initialPars, measurements] =
prepareFit(tgContext, calContext, seed);
159 if (!initialPars.ok()) {
160 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Failed to construct valid parameters for seed \n"<<seed);
167 tgContext, mfContext, calContext,
168 &(*initialPars).referenceSurface());
169 if (!fitTraject || fitTraject->size() == 0) {
170 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Fit failed. Seed was \n"<<seed);
177 ActsTrk::MutableTrackContainer::TrackProxy track = fitTraject->getTrack(0);
181 ATH_MSG_DEBUG(
"Track has " <<
static_cast<std::uint32_t
>(summary.nPrecisionStations()) <<
" precision layers with summary "<< summary);
182 if(summary.nPrecisionStations()<2) {
196 fitTraject->addColumn<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks");
197 auto appendMe = seed.segments();
198 auto& toAppend = track.component<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks");
199 toAppend.insert(toAppend.end(), appendMe.begin(), appendMe.end());
201 outContainer.ensureDynamicColumns(*fitTraject);
202 auto destProxy = outContainer.getTrack(outContainer.addTrack());
203 destProxy.copyFrom(track);
204 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Good track fit...");
207 destProxy.createParametersAtReference(),
"GoodFit");
212 ActsTrk::MutableTrackContainer::TrackProxy track)
const {
216 const Acts::BoundTrackParameters startPars = track.createParametersAtReference();
218 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
219 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Extrapolate "<<startPars<<
", "
220 <<startPars.referenceSurface().toString(tgContext)<<
" to MS entrance: "<<msEntrance->volumeBounds());
224 Acts::Direction::Backward());
226 if (!parsAtEntrance.ok()) {
227 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Failed to extrapolate "<<startPars<<
" to MS entrance");
230 if (parsAtEntrance->referenceSurface().geometryId().withBoundary(0) != msEntrance->geometryId()) {
231 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Parameter extrapolation to "<<(*parsAtEntrance)<<
", @"
232 <<
Amg::toString(parsAtEntrance->referenceSurface().localToGlobalTransform(tgContext))
233 <<
" did not end up at "<<msEntrance->geometryId()<<
".");
236 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Extrapolated start parameters to "<<(*parsAtEntrance)
237 <<
", "<<parsAtEntrance->referenceSurface().toString(tgContext));
238 track.setReferenceSurface(parsAtEntrance->referenceSurface().getSharedPtr());
239 track.parameters() = parsAtEntrance->parameters();
240 track.covariance() = (*parsAtEntrance->covariance());
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
ATLAS-specific HepMC functions.
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
bool fitSeedCandidate(const Acts::GeometryContext &tgContext, const Acts::MagneticFieldContext &mfContext, const Acts::CalibrationContext &calContext, const MsTrackSeed &seed, ActsTrk::MutableTrackContainer &outContainer) const
Attempts to fit the track seed candidate to a full track and returns whether the fit succeeded.
ServiceHandle< ActsTrk::ITrackingGeometrySvc > m_trackingGeometrySvc
Service handle to the tracking geometry service.
bool expressAtCaloExit(const EventContext &ctx, ActsTrk::MutableTrackContainer::TrackProxy track) const
ToolHandle< ITrackSeedingTool > m_seedingTool
The track seeding tool to construct the seed candidates and to estimate the initial parameters.
Acts::Result< Acts::BoundTrackParameters > OptBoundPars_t
std::vector< const xAOD::UncalibratedMeasurement * > MeasVec_t
SG::WriteHandleKey< ActsTrk::TrackContainer > m_writeKey
Key to the output track container.
SG::WriteHandleKey< MsTrackSeedContainer > m_msTrkSeedKey
Temporary container write handle to push the seeds to store gate for later efficiency analysis.
virtual StatusCode execute(const EventContext &ctx) const override final
Standard algorithm execution hook.
std::pair< OptBoundPars_t, MeasVec_t > prepareFit(const Acts::GeometryContext &tgContext, const Acts::CalibrationContext &calContext, const MsTrackSeed &seed) const
Prepares the input to the fit by collecting the measurements on the segment &.
ToolHandle< ISpacePointCalibrator > m_calibTool
Calibration tool to fill the track states.
ToolHandle< MuonValR4::ITrackVisualizationTool > m_visualizationTool
Visualization tool to debug the track finding.
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the MuonDetectorManager.
virtual ~MsTrackFindingAlg()
ToolHandle< ActsTrk::IFitterTool > m_trackFitTool
Track fitting tool.
virtual StatusCode initialize() override final
Standard algorithm hook to setup the extrapolator, retrieve the tools and declare algorithm's data de...
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
Gaudi::Property< bool > m_expressAtMsEntrance
Propagate the track at the MS entry and express its parameters.
ActsTrk::ContextUtility m_ctxProvider
Utility to fetch the geometry, magnetic field and calibration context in the event.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Gaudi::Property< bool > m_ignoreFailedMsEntrance
Ignore failed track extrapolations to the entrance.
ToolHandle< MuonR4::ITrackSummaryTool > m_summaryTool
Handle to the muon summary tool.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
This header ties the generic definitions in this package.
std::vector< const xAOD::UncalibratedMeasurement * > collectMeasurements(const xAOD::MuonSegment &segment, bool skipOutlier=true)
Helper function to extract the measurements from the segment.
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
Summary struct to hold the hit counts on the track per MS layer.