7#include "Acts/Surfaces/PerigeeSurface.hpp"
8#include "Acts/Surfaces/PlaneSurface.hpp"
9#include "Acts/Surfaces/detail/PlanarHelper.hpp"
18#include "GaudiKernel/PhysicalConstants.h"
23#include "GaudiKernel/PhysicalConstants.h"
27#include <system_error>
29using namespace Acts::UnitLiterals;
30using namespace Acts::PlanarHelper;
48 Acts::TrackingGeometry::GeometryVersion::Gen3){
49 ATH_MSG_ERROR(
"The MS track fit requires the Gen 3 geometry format");
50 return StatusCode::FAILURE;
58 m_seeder = std::make_unique<MsTrackSeeder>(name(), std::move(seederCfg));
59 return StatusCode::SUCCESS;
65 ATH_MSG_VERBOSE(
"Run track finding in event "<<ctx.eventID().event_number());
73 const Acts::MagneticFieldContext mfContext =
m_extrapolationTool->getMagneticFieldContext(ctx);
77 Acts::VectorTrackContainer trackBackend{};
78 Acts::VectorMultiTrajectory trackStateBackend{};
80 std::move(trackStateBackend)};
82 cacheTrkContainer.addColumn<std::size_t>(
"parentSeed");
90 auto lastTrack = cacheTrkContainer.getTrack(cacheTrkContainer.size() -1);
91 lastTrack.component<std::size_t, Acts::hashString(
"parentSeed")>() = seedIdx;
98 Acts::ConstVectorTrackContainer ctrackBackend{std::move(cacheTrkContainer.container())};
99 Acts::ConstVectorMultiTrajectory ctrackStateBackend{std::move(cacheTrkContainer.trackStateContainer())};
100 auto ctc = std::make_unique<ActsTrk::TrackContainer>(std::move(ctrackBackend),
101 std::move(ctrackStateBackend));
105 return StatusCode::SUCCESS;
108 std::unique_ptr<MsTrackSeedContainer>
117 return seedContainer;
122 const Acts::MagneticFieldContext& mfContext,
123 const Acts::CalibrationContext& calContext,
125 const EventContext& ctx{*calContext.get<
const EventContext*>()};
127 measurements.reserve(100);
134 if (
msgLvl(MSG::VERBOSE)) {
135 std::stringstream sstr{};
139 <<
", "<<m->numDimensions()<<
", "
140 <<
", "<<surf.geometryId()<<
" @ "<<
Amg::toString(surf.localToGlobalTransform(tgContext))<<std::endl;
143 <<
", direction: "<<
Amg::toString(segment->direction())<<
"\n"<<sstr.str());
145 measurements.insert(measurements.end(),
146 std::make_move_iterator(segMeasurements.begin()),
147 std::make_move_iterator(segMeasurements.end()));
153 if (!refSeg || measurements.empty()) {
155 <<
" - No reference segment passing seeding quality "<<
156 (refSeg !=
nullptr)<<
" was found. #"<<measurements.size()<<
" measurements. ");
157 return std::make_pair(Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument)),
158 std::vector<const xAOD::UncalibratedMeasurement_v1*>{});
160 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - "<<measurements.size()<<
" measurements");
166 if (refSeg != seed.segments().front()) {
168 const Acts::PlaneSurface& surf = innerPlane->
surface();
169 const Amg::Transform3D toInnerPlane = surf.localToGlobalTransform(tgContext).inverse();
171 const Amg::Vector3D locSeedDir = toInnerPlane.linear() * seedDir;
173 auto seedOnInner = Acts::PlanarHelper::intersectPlane(locSeedPos, locSeedDir,
174 Amg::Vector3D::UnitZ(), 0.);
178 innerPars[Acts::toUnderlying(x0)] = seedOnInner.position().x();
180 Acts::makeDirectionFromPhiTheta(innerPars[Acts::toUnderlying(
phi)],
181 innerPars[Acts::toUnderlying(
theta)]);
183 Acts::makeDirectionFromAxisTangents(
houghTanAlpha(locSeedDir),
185 seedPos = surf.localToGlobalTransform(tgContext) *
Amg::Vector3D{innerPars[Acts::toUnderlying(x0)],
186 innerPars[Acts::toUnderlying(y0)], 0};
187 seedDir = surf.localToGlobalTransform(tgContext).linear() * combSegDir;
196 const Acts::TrackingVolume* volume{
nullptr};
203 firstVolumeMeas = meas;
210 <<
" - Failed to find tracking volume for any seed measurement");
211 return std::make_pair(Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument)),
212 std::vector<const xAOD::UncalibratedMeasurement_v1*>{});
214 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Using seed measurement "
220 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Failed to find boundary surface for tracking volume");
221 return std::make_pair(Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument)),
222 std::vector<const xAOD::UncalibratedMeasurement_v1*>{});
224 auto targetSurf = boundSurf->getSharedPtr();
225 using namespace Acts::PlanarHelper;
227 auto pIsect = intersectPlane(seedPos, seedDir,
228 targetSurf->localToGlobalTransform(tgContext).linear().col(2),
229 targetSurf->center(tgContext));
234 auto initialPars = Acts::BoundTrackParameters::create(tgContext, targetSurf, fourPos,
236 Acts::BoundMatrix::Identity(),
237 Acts::ParticleHypothesis::muon());
238 return std::make_pair(std::move(initialPars), std::move(measurements));
242 const Acts::MagneticFieldContext& mfContext,
243 const Acts::CalibrationContext& calContext,
247 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Attempt to fit a new track seed \n"<<seed);
248 const EventContext& ctx{*calContext.get<
const EventContext*>()};
249 const auto [initialPars, measurements] =
prepareFit(tgContext, mfContext, calContext, seed);
251 if (!initialPars.ok()) {
252 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - Failed to construct valid parameters for seed \n"<<seed);
259 tgContext, mfContext, calContext,
260 &(*initialPars).referenceSurface());
261 if (!fitTraject || fitTraject->size() == 0) {
273 fitTraject->addColumn<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks");
274 fitTraject->getTrack(0).component<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks") = seed.segments();
276 outContainer.ensureDynamicColumns(*fitTraject);
277 auto destProxy = outContainer.getTrack(outContainer.addTrack());
278 destProxy.copyFrom(fitTraject->getTrack(0));
279 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Good track fit...");
282 destProxy.createParametersAtReference(),
"GoodFit");
Scalar phi() const
phi method
Scalar theta() const
theta method
#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
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
const Acts::PlaneSurface & surface() const
Returns the associated surface.
Acts::Result< Acts::BoundTrackParameters > OptBoundPars_t
Gaudi::Property< double > m_seedHalfLength
Maximum search window to search segments for.
std::unique_ptr< MsTrackSeedContainer > findTrackSeeds(const EventContext &ctx, const xAOD::MuonSegmentContainer &segments) const
Iterates over the search tree and combines close-by segments to a track seed.
std::vector< const xAOD::UncalibratedMeasurement * > MeasVec_t
SG::WriteHandleKey< ActsTrk::TrackContainer > m_writeKey
Key to the output track container.
std::unique_ptr< MsTrackSeeder > m_seeder
Pointer to the actual seeder implementation.
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.
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.
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Tracking geometry tool.
virtual StatusCode initialize() override final
Standard algorithm hook to setup the extrapolator, retrieve the tools and declare algorithm's data de...
ToolHandle< ISegmentSelectionTool > m_segSelector
Segment selection tool to pick the good quality segments.
std::pair< OptBoundPars_t, MeasVec_t > prepareFit(const Acts::GeometryContext &tgContext, const Acts::MagneticFieldContext &mfContext, const Acts::CalibrationContext &calContext, const MsTrackSeed &seed) const
Prepares the input by the fit by collecting the measurements on the segment &.
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment contai...
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
bool fitSeedCandidate(const Acts::GeometryContext &gCtx, const Acts::MagneticFieldContext &mCtx, const Acts::CalibrationContext &cCtx, const MsTrackSeed &seed, ActsTrk::MutableTrackContainer &outContainer) const
Attempts to fit the track seed candidate to a full track and returns whether the fit succeeded.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
constexpr double energyToActs(const double athenaE)
Converts an energy scalar from Athena to Acts units.
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
Acts::CalibrationContext getCalibrationContext(const EventContext &ctx)
The Acts::Calibration context is piped through the Acts fitters to (re)calibrate the Acts::SourceLink...
Acts::Vector4 convertPosToActs(const Amg::Vector3D &athenaPos, const double athenaTime=0.)
Converts a position vector & time from Athena units into Acts units.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
const Acts::Surface * bottomBoundary(const Acts::TrackingVolume &volume)
Returns the boundary surface parallel to the x-y plane at negative local z.
SeedingAux::FitParIndex ParamDefs
Use the same parameter indices as used by the CompSpacePointAuxiliaries.
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
Acts::Experimental::CompositeSpacePointLineFitter::ParamVec_t Parameters
This header ties the generic definitions in this package.
double houghTanBeta(const Amg::Vector3D &v)
Returns the hough tanBeta [y] / [z].
std::vector< const xAOD::UncalibratedMeasurement * > collectMeasurements(const xAOD::MuonSegment &segment, bool skipOutlier=true)
Helper function to extract the measurements from the segment.
Acts::GeometryIdentifier volumeId(const Acts::Surface &surface)
Returns the identifier of the volume in which the surface is embedded.
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
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.
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
const MuonGMR4::MuonDetectorManager * detMgr
Detector manager to fetch the sector enevelope transforms.
double seedHalfLength
Maximum separation of point on the cylinder to be picked up onto a seed.
const ISegmentSelectionTool * selector
Pointer to the segement selection tool which compares two segments for their compatibilitiy.