ATLAS Offline Software
Loading...
Searching...
No Matches
MlMsTrackSeeder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "MlMsTrackSeeder.h"
5
12
13#include <map>
14#include <utility>
15#include <vector>
16
17namespace MuonR4 {
18
19namespace {
20
21struct MlComponent {
22 std::vector<const xAOD::MuonSegment*> segments;
23 std::vector<const xAOD::MuonSegment*> anchors;
24};
25
26} // namespace
27
30 ATH_CHECK(m_segmentKey.initialize());
31 ATH_CHECK(m_candidateDecorKey.initialize());
32 return StatusCode::SUCCESS;
33}
34
36 const EventContext& ctx,
37 std::vector<MsTrackSeed>& outSeeds) const {
38 const xAOD::MuonSegmentContainer* segments{nullptr};
39 ATH_CHECK(SG::get(segments, m_segmentKey, ctx));
40
41 // The decoration payload is [componentId, isSeedAnchor].
43 componentAcc{m_candidateDecorKey, ctx};
44 if (!componentAcc.isAvailable()) {
45 ATH_MSG_DEBUG("No ML candidate decoration found");
46 return StatusCode::SUCCESS;
47 }
48
49 std::map<unsigned int, MlComponent> components;
50
51 for (const xAOD::MuonSegment* segment : *segments) {
52 if (!segment) continue;
53 const std::vector<unsigned int>& payload = componentAcc(*segment);
54 if (payload.size() != 2 || payload[0] == 0) continue;
55 MlComponent& component = components[payload[0]];
56 component.segments.push_back(segment);
57 if (payload[1] != 0) component.anchors.push_back(segment);
58 }
59
60 std::size_t acceptedComponents = 0;
61 std::size_t constructedSeeds = 0;
62 for (const auto& [componentId, component] : components) {
63 if (component.segments.size() < m_minSegmentsPerCandidate.value() ||
64 (m_maxSegmentsPerCandidate.value() != 0 &&
65 component.segments.size() > m_maxSegmentsPerCandidate.value()) ||
66 component.anchors.empty()) {
67 continue;
68 }
69 ++acceptedComponents;
70
71 for (const xAOD::MuonSegment* anchor : component.anchors) {
72 const MsTrackSeed::Location location =
76 MsTrackSeed seed{location, ExpandedSector{anchor->position().phi()}};
77
78 // One segment per layer, best aligned with the anchor: the baseline seeder
79 // only builds seeds that span several layers, and the fit rejects single-layer tracks.
80 const Muon::MuonStationIndex::LayerIndex anchorLayer =
82 std::map<Muon::MuonStationIndex::LayerIndex, std::pair<double, const xAOD::MuonSegment*>> bestPerLayer;
83 for (const xAOD::MuonSegment* segment : component.segments) {
84 if (segment == anchor) continue;
87 if (layer == anchorLayer) continue;
88 const double cosAngle = anchor->direction().dot(segment->direction());
89 if (cosAngle < m_minCosConsistency.value()) continue;
90 auto& best = bestPerLayer[layer];
91 if (!best.second || cosAngle > best.first) best = {cosAngle, segment};
92 }
93 if (bestPerLayer.size() + 1 < m_minLayers.value()) continue;
94
95 seed.addSegment(anchor);
96 for (const auto& [layer, choice] : bestPerLayer) seed.addSegment(choice.second);
97 seed.setPosition(anchor->position());
98 outSeeds.push_back(std::move(seed));
99 ++constructedSeeds;
100 }
101 ATH_MSG_VERBOSE("Constructed " << component.anchors.size()
102 << " seed(s) from ML component " << componentId
103 << " with " << component.segments.size()
104 << " segments");
105 }
106
107 ATH_MSG_DEBUG("Constructed " << constructedSeeds << " seed(s) from "
108 << acceptedComponents << "/" << components.size()
109 << " decorated ML component(s)");
110 return StatusCode::SUCCESS;
111}
112
113Acts::Result<Acts::BoundTrackParameters>
115 const EventContext& ctx,
116 const MsTrackSeed& seed) const {
117 return m_seedParameterEstimator->estimateStartParameters(ctx, seed);
118}
119
120} // namespace MuonR4
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
StatusCode initialize() override final
StatusCode findTrackSeeds(const EventContext &ctx, std::vector< MsTrackSeed > &outSeeds) const override final
Retrieves the segment container from StoreGate and constructs TrackSeeds from them.
Gaudi::Property< unsigned int > m_minSegmentsPerCandidate
Acts::Result< Acts::BoundTrackParameters > estimateStartParameters(const EventContext &ctx, const MsTrackSeed &seed) const override final
Estimate the start track parameters for a given track seed.
Gaudi::Property< double > m_minCosConsistency
ToolHandle< ITrackSeedingTool > m_seedParameterEstimator
SG::ReadDecorHandleKey< xAOD::MuonSegmentContainer > m_candidateDecorKey
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
Gaudi::Property< unsigned int > m_minLayers
Gaudi::Property< unsigned int > m_maxSegmentsPerCandidate
Location
Enum defining whether the seed is made in the endcap / barrel.
Definition MsTrackSeed.h:25
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
::Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
This header ties the generic definitions in this package.
bool isBarrel(const ChIndex index)
Returns true if the chamber index points to a barrel chamber.
LayerIndex
enum to classify the different layers in the muon spectrometer
LayerIndex toLayerIndex(ChIndex index)
convert ChIndex into LayerIndex
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".
MuonSegment_v1 MuonSegment
Reference the current persistent version: