ATLAS Offline Software
MsTrackFindingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MsTrackFindingAlg.h"
6 
7 #include "Acts/Surfaces/PerigeeSurface.hpp"
8 
13 
14 #include "GaudiKernel/PhysicalConstants.h"
17 #include "TruthUtils/AtlasPID.h"
18 
19 namespace MuonR4{
22  ATH_CHECK(m_idHelperSvc.retrieve());
24  ATH_CHECK(m_segSelector.retrieve());
26 
27  ATH_CHECK(m_visualizationTool.retrieve(EnableTool{!m_visualizationTool.empty()}));
28 
30  ATH_CHECK(m_extrapolationTool.retrieve());
31  ATH_CHECK(m_trackFitTool.retrieve());
33  return StatusCode::SUCCESS;
34  }
35 
37 
38  StatusCode MsTrackFindingAlg::execute(const EventContext& ctx) const {
39  ATH_MSG_VERBOSE("Run track finding in event "<<ctx.eventID().event_number());
40 
41  const xAOD::MuonSegmentContainer* allEventSegs{nullptr};
42  ATH_CHECK(SG::get(allEventSegs, m_segmentKey, ctx));
43  auto seedContainer = findTrackSeeds(ctx, *allEventSegs);
44 
45 
46  const Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
47  const Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
48  const Acts::CalibrationContext calContext{ActsTrk::getCalibrationContext(ctx)};
49 
50 
51  Acts::VectorTrackContainer trackBackend;
52  Acts::VectorMultiTrajectory trackStateBackend;
53  ActsTrk::MutableTrackContainer cacheTrkContainer{
54  std::move(trackBackend),
55  std::move(trackStateBackend)};
56 
57 
58  for (const MsTrackSeed& seed :*seedContainer) {
59  fitSeedCandidate(tgContext, mfContext, calContext, seed, cacheTrkContainer);
60  }
61 
62  SG::WriteHandle writeHandle{m_msTrkSeedKey, ctx};
63  ATH_CHECK(writeHandle.record(std::move(seedContainer)));
64  return StatusCode::SUCCESS;
65  }
66 
67  std::unique_ptr<MsTrackSeedContainer>
68  MsTrackFindingAlg::findTrackSeeds(const EventContext& ctx,
69  const xAOD::MuonSegmentContainer& segments) const {
70 
71  MsTrackSeeder::Config seederCfg{};
72  seederCfg.seedHalfLength = m_seedHalfLength;
73  seederCfg.selector = m_segSelector.get();
74 
75  MsTrackSeeder seeder{name(), std::move(seederCfg)};
76 
77  auto seedContainer = seeder.findTrackSeeds(ctx, segments);
78 
79  if (!m_visualizationTool.empty()) {
80  m_visualizationTool->displaySeeds(ctx, seeder, segments, *seedContainer, "all seeds");
81  }
82  return seedContainer;
83  }
84  void MsTrackFindingAlg::fitSeedCandidate(const Acts::GeometryContext& tgContext,
85  const Acts::MagneticFieldContext& mfContext,
86  const Acts::CalibrationContext& calContext,
87  const MsTrackSeed& seed,
88  ActsTrk::MutableTrackContainer& outContainer) const {
89  return;
90  ATH_MSG_DEBUG("Attempt to fit a new track seed");
91 
92  std::vector<const xAOD::UncalibratedMeasurement*> measurements{};
93  unsigned int nMeas = 2* std::accumulate(seed.detailedSegments().begin(),
94  seed.detailedSegments().end(), 0,
95  [](const unsigned n, const Segment* segment){
96  return n + segment->measurements().size();
97  });
98  measurements.reserve(nMeas);
99 
100  for (const Segment* segment : seed.detailedSegments()) {
101  ATH_MSG_DEBUG("Fetch measurements from segment: "<<Amg::toString(segment->position())
102  <<", direction: "<<Amg::toString(segment->direction()));
103  auto segMeasuremnts = MuonR4::collectMeasurements(*segment, /*skipOutlier:*/ true);
104  measurements.insert(measurements.end(),
105  std::make_move_iterator(segMeasuremnts.begin()),
106  std::make_move_iterator(segMeasuremnts.end()));
107  }
109  const Segment* innerSeg{seed.detailedSegments().front()};
111  constexpr double propDistance = 5.*Gaudi::Units::cm;
112  const Amg::Vector3D refPos = innerSeg->position() - propDistance * innerSeg->direction();
113  auto target = Acts::Surface::makeShared<Acts::PerigeeSurface>(refPos);
114 
115  Acts::ActsVector<4> fourPos{};
116  fourPos.block<3,1>(Acts::ePos0, 0) = refPos;
117  fourPos[Acts::eTime] = refPos.mag() / Gaudi::Units::c_light;
118  auto initialPars = Acts::BoundTrackParameters::create(tgContext, target, fourPos,
119  innerSeg->direction(),
120  1. / (10.*Gaudi::Units::GeV),
121  Acts::BoundSquareMatrix::Identity(), Acts::ParticleHypothesis::muon());
122  if (!initialPars.ok()) {
123  ATH_MSG_WARNING("Initial estimate of the parameters failed");
124  return;
125  }
126  auto fitTraject = m_trackFitTool->fit(measurements, *initialPars, tgContext, mfContext,calContext, target.get());
127  if (!fitTraject) {
128  return;
129  }
130  auto destProxy = outContainer.getTrack(outContainer.addTrack());
131  destProxy.copyFrom(fitTraject->getTrack(0));
132  ATH_MSG_DEBUG("Good track fit...");
133  for (const auto state : destProxy.trackStates()) {
134  if (!state.hasUncalibratedSourceLink()){
135  continue;
136  }
137  auto meas = ActsTrk::detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
138  ATH_MSG_DEBUG("Accepted measurement "<<m_idHelperSvc->toString(xAOD::identify(meas))
139  <<", "<<xAOD::muonSurface(meas).geometryId());
140  }
141  }
142 
143 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MuonR4::collectMeasurements
std::vector< const xAOD::UncalibratedMeasurement * > collectMeasurements(const Segment &seg, bool skipOutlier=true)
Helper function to extract the measurements from the segment.
Definition: TrackingHelpers.cxx:18
ActsTrk::getCalibrationContext
Acts::CalibrationContext getCalibrationContext(const EventContext &ctx)
The Acts::Calibration context is piped through the Acts fitters to (re)calibrate the Acts::SourceLink...
Definition: CalibrationContext.h:15
MuonSimHitHelpers.h
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:82
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:18
MuonR4::MsTrackFindingAlg::fitSeedCandidate
void fitSeedCandidate(const Acts::GeometryContext &gCtx, const Acts::MagneticFieldContext &mCtx, const Acts::CalibrationContext &cCtx, const MsTrackSeed &seed, ActsTrk::MutableTrackContainer &outContainer) const
Definition: MsTrackFindingAlg.cxx:84
MuonR4::MsTrackFindingAlg::m_msTrkSeedKey
SG::WriteHandleKey< MsTrackSeedContainer > m_msTrkSeedKey
Temporary container write handle to push the seeds to store gate for later efficiency analysis.
Definition: MsTrackFindingAlg.h:69
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
MuonR4::MsTrackSeed
Definition: MsTrackSeed.h:18
MuonR4::MsTrackFindingAlg::m_trackFitTool
ToolHandle< ActsTrk::IFitterTool > m_trackFitTool
Track fitting tool.
Definition: MsTrackFindingAlg.h:73
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
MsTrackSeeder.h
ActsTrk::MutableTrackContainer
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
Definition: TrackContainer.h:26
MuonR4::MsTrackFindingAlg::initialize
virtual StatusCode initialize() override final
Standard algorithm hook to setup the extrapolator, retrieve the tools and declare algorithm's data de...
Definition: MsTrackFindingAlg.cxx:20
xAODUncalibMeasCalibrator.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ActsTrk::MutableTrackContainerHandlesHelper::initialize
StatusCode initialize(const std::string &prefix)
Sets up the handles.
Definition: TrackContainerHandlesHelper.cxx:47
ActsTrk::detail::xAODUncalibMeasCalibrator::unpack
static const xAOD::UncalibratedMeasurement * unpack(const Acts::SourceLink &sl)
Helper method to unpack an Acts source link to an uncalibrated measurement.
Definition: xAODUncalibMeasCalibrator.cxx:12
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
MuonR4::MsTrackFindingAlg::m_trackContKeys
ActsTrk::MutableTrackContainerHandlesHelper m_trackContKeys
Definition: MsTrackFindingAlg.h:84
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
MuonR4::MsTrackFindingAlg::m_trackingGeometryTool
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Tracking geometry tool.
Definition: MsTrackFindingAlg.h:75
MuonR4::MsTrackFindingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Standard algorithm execution hook.
Definition: MsTrackFindingAlg.cxx:38
CalibrationContext.h
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonR4::MsTrackFindingAlg::m_detMgr
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the MuonDetectorManager.
Definition: MsTrackFindingAlg.h:66
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonR4::MsTrackFindingAlg::~MsTrackFindingAlg
virtual ~MsTrackFindingAlg()
MuonR4::MsTrackFindingAlg::m_segmentKey
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment contai...
Definition: MsTrackFindingAlg.h:62
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonR4::MsTrackFindingAlg::m_extrapolationTool
ToolHandle< IActsExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
Definition: MsTrackFindingAlg.h:77
MuonR4::MsTrackFindingAlg::findTrackSeeds
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.
Definition: MsTrackFindingAlg.cxx:68
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MuonR4::MsTrackFindingAlg::m_writePrefix
Gaudi::Property< std::string > m_writePrefix
Output track container prefix.
Definition: MsTrackFindingAlg.h:83
MuonR4::MsTrackFindingAlg::m_seedHalfLength
Gaudi::Property< double > m_seedHalfLength
Maximum search window to search segments for.
Definition: MsTrackFindingAlg.h:81
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TrackingHelpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
MsTrackFindingAlg.h
MuonR4::MsTrackSeeder::Config::seedHalfLength
double seedHalfLength
Maximum separation of point on the cylinder to be picked up onto a seed.
Definition: MsTrackSeeder.h:40
MuonR4::MsTrackSeeder
Helper class to group muon sgements that may belong to a muon trajectory.
Definition: MsTrackSeeder.h:25
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:73
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
xAOD::muonSurface
const Acts::Surface & muonSurface(const xAOD::UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
MuonR4::MsTrackFindingAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Definition: MsTrackFindingAlg.h:64
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
runIDAlign.accumulate
accumulate
Update flags based on parser line args.
Definition: runIDAlign.py:107
MuonR4::MsTrackFindingAlg::m_visualizationTool
ToolHandle< MuonValR4::ITrackVisualizationTool > m_visualizationTool
Visualization tool to debug the track finding.
Definition: MsTrackFindingAlg.h:79
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
copySelective.target
string target
Definition: copySelective.py:36
MuonR4::MsTrackSeeder::Config
Definition: MsTrackSeeder.h:28
MuonR4::MsTrackFindingAlg::m_segSelector
ToolHandle< ISegmentSelectionTool > m_segSelector
Segment selection tool to pick the good quality segments.
Definition: MsTrackFindingAlg.h:71
AtlasPID.h
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5