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{
21  ATH_CHECK(m_segmentKeys.initialize());
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 
43  const xAOD::MuonSegmentContainer* partSegments{nullptr};
44  ATH_CHECK(SG::get(partSegments, key, ctx));
45  allEventSegs.insert(allEventSegs.end(), partSegments->begin(), partSegments->end());
46  }
47  auto seedContainer = findTrackSeeds(ctx, *allEventSegs.asDataVector());
48 
49 
50  const Acts::GeometryContext tgContext = m_trackingGeometryTool->getGeometryContext(ctx).context();
51  const Acts::MagneticFieldContext mfContext = m_extrapolationTool->getMagneticFieldContext(ctx);
52  const Acts::CalibrationContext calContext{ActsTrk::getCalibrationContext(ctx)};
53 
54 
55  Acts::VectorTrackContainer trackBackend;
56  Acts::VectorMultiTrajectory trackStateBackend;
57  ActsTrk::MutableTrackContainer cacheTrkContainer{
58  std::move(trackBackend),
59  std::move(trackStateBackend)};
60 
61 
62  for (const MsTrackSeed& seed :*seedContainer) {
63  fitSeedCandidate(tgContext, mfContext, calContext, seed, cacheTrkContainer);
64  }
65 
66  SG::WriteHandle writeHandle{m_msTrkSeedKey, ctx};
67  ATH_CHECK(writeHandle.record(std::move(seedContainer)));
68  return StatusCode::SUCCESS;
69  }
70 
71  std::unique_ptr<MsTrackSeedContainer>
72  MSTrackFindingAlg::findTrackSeeds(const EventContext& ctx,
73  const xAOD::MuonSegmentContainer& segments) const {
74 
75  MsTrackSeeder::Config seederCfg{};
76  seederCfg.seedHalfLength = m_seedHalfLength;
77  seederCfg.selector = m_segSelector.get();
78 
79  MsTrackSeeder seeder{name(), std::move(seederCfg)};
80 
81  auto seedContainer = seeder.findTrackSeeds(ctx, segments);
82 
83  if (!m_visualizationTool.empty()) {
84  m_visualizationTool->displaySeeds(ctx, seeder, segments, *seedContainer, "all seeds");
85  }
86  return seedContainer;
87  }
88  void MSTrackFindingAlg::fitSeedCandidate(const Acts::GeometryContext& tgContext,
89  const Acts::MagneticFieldContext& mfContext,
90  const Acts::CalibrationContext& calContext,
91  const MsTrackSeed& seed,
92  ActsTrk::MutableTrackContainer& outContainer) const {
93  ATH_MSG_DEBUG("Attempt to fit a new track seed");
94 
95  std::vector<const xAOD::UncalibratedMeasurement*> measurements{};
96  unsigned int nMeas = 2* std::accumulate(seed.detailedSegments().begin(),
97  seed.detailedSegments().end(), 0,
98  [](const unsigned n, const Segment* segment){
99  return n + segment->measurements().size();
100  });
101  measurements.reserve(nMeas);
102 
103  for (const Segment* segment : seed.detailedSegments()) {
104  ATH_MSG_DEBUG("Fetch measurements from segment: "<<Amg::toString(segment->position())
105  <<", direction: "<<Amg::toString(segment->direction()));
106  auto segMeasuremnts = MuonR4::collectMeasurements(*segment, /*skipOutlier:*/ true);
107  measurements.insert(measurements.end(),
108  std::make_move_iterator(segMeasuremnts.begin()),
109  std::make_move_iterator(segMeasuremnts.end()));
110  }
112  const Segment* innerSeg{seed.detailedSegments().front()};
114  constexpr double propDistance = 5.*Gaudi::Units::cm;
115  const Amg::Vector3D refPos = innerSeg->position() - propDistance * innerSeg->direction();
116  auto target = Acts::Surface::makeShared<Acts::PerigeeSurface>(refPos);
117 
118  Acts::ActsVector<4> fourPos{};
119  fourPos.block<3,1>(Acts::ePos0, 0) = refPos;
120  fourPos[Acts::eTime] = refPos.mag() / Gaudi::Units::c_light;
121  auto initialPars = Acts::BoundTrackParameters::create(tgContext, target, fourPos,
122  innerSeg->direction(),
123  1. / (10.*Gaudi::Units::GeV),
124  Acts::BoundSquareMatrix::Identity(), Acts::ParticleHypothesis::muon());
125  if (!initialPars.ok()) {
126  ATH_MSG_WARNING("Initial estimate of the parameters failed");
127  return;
128  }
129  auto fitTraject = m_trackFitTool->fit(measurements, *initialPars, tgContext, mfContext,calContext, target.get());
130  if (!fitTraject) {
131  return;
132  }
133  auto destProxy = outContainer.getTrack(outContainer.addTrack());
134  destProxy.copyFrom(fitTraject->getTrack(0));
135  ATH_MSG_DEBUG("Good track fit...");
136  for (const auto state : destProxy.trackStates()) {
137  if (!state.hasUncalibratedSourceLink()){
138  continue;
139  }
140  auto meas = ActsTrk::detail::xAODUncalibMeasCalibrator::unpack(state.getUncalibratedSourceLink());
141  ATH_MSG_DEBUG("Accepted measurement "<<m_idHelperSvc->toString(xAOD::identify(meas))
142  <<", "<<xAOD::muonSurface(meas).geometryId());
143  }
144  }
145 
146 }
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
MuonR4::MSTrackFindingAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Definition: MSTrackFindingAlg.h:64
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::m_seedHalfLength
Gaudi::Property< double > m_seedHalfLength
Maximum search window to search segments for.
Definition: MSTrackFindingAlg.h:81
MuonR4::MSTrackFindingAlg::m_writePrefix
Gaudi::Property< std::string > m_writePrefix
Output track container prefix.
Definition: MSTrackFindingAlg.h:83
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
MuonR4::MsTrackSeed
Definition: MsTrackSeed.h:18
MuonR4::MSTrackFindingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Standard algorithm execution hook.
Definition: MSTrackFindingAlg.cxx:38
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
xAODUncalibMeasCalibrator.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::MSTrackFindingAlg::m_detMgr
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the MuonDetectorManager.
Definition: MSTrackFindingAlg.h:66
SG::ReadHandleKey< xAOD::MuonSegmentContainer >
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::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
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
CalibrationContext.h
MuonR4::MSTrackFindingAlg::m_extrapolationTool
ToolHandle< IActsExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
Definition: MSTrackFindingAlg.h:77
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonR4::MSTrackFindingAlg::m_trackFitTool
ToolHandle< ActsTrk::IFitterTool > m_trackFitTool
Track fitting tool.
Definition: MSTrackFindingAlg.h:73
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:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonR4::MSTrackFindingAlg::m_trackingGeometryTool
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Tracking geometry tool.
Definition: MSTrackFindingAlg.h:75
MuonR4::MSTrackFindingAlg::m_trackContKeys
ActsTrk::MutableTrackContainerHandlesHelper m_trackContKeys
Definition: MSTrackFindingAlg.h:84
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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_segSelector
ToolHandle< ISegmentSelectionTool > m_segSelector
Segment selection tool to pick the good quality segments.
Definition: MSTrackFindingAlg.h:71
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TrackingHelpers.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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
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
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
copySelective.target
string target
Definition: copySelective.py:36
MuonR4::MsTrackSeeder::Config
Definition: MsTrackSeeder.h:28
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:72
MuonR4::MSTrackFindingAlg::m_segmentKeys
SG::ReadHandleKeyArray< xAOD::MuonSegmentContainer > m_segmentKeys
Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment contai...
Definition: MSTrackFindingAlg.h:62
MuonR4::MSTrackFindingAlg::m_visualizationTool
ToolHandle< MuonValR4::ITrackVisualizationTool > m_visualizationTool
Visualization tool to debug the track finding.
Definition: MSTrackFindingAlg.h:79
MSTrackFindingAlg.h
AtlasPID.h
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
MuonR4::MSTrackFindingAlg::~MSTrackFindingAlg
virtual ~MSTrackFindingAlg()
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:88
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37