ATLAS Offline Software
Loading...
Searching...
No Matches
MuonFastReconstructionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7namespace {
8 double inDeg(double angle) {
9 return angle / Gaudi::Units::deg;
10 }
11 std::string printMuon(const xAOD::Muon& muon) {
13
14 std::ostringstream oss;
15 oss<<"FastMuonSA, Eta: "<<muon.eta() << ", Phi: "<<inDeg(muon.phi())<< ", Pt: "<<muon.pt() / Gaudi::Units::GeV<<" GeV, Charge: "<<muon.charge() << std::endl
16 <<"Associated GlobalPattern: "<< **acc(muon);
17 return oss.str();
18 }
19 //defined here to avoid repeated string construction in loop
20 const std::string patternLinkStr{"globalPatternLink"};
21}
22
23namespace MuonR4{
24using namespace FastReco;
26
28 if (m_outSpacePoints.size() != m_inSpacePoints.size()) {
29 m_outSpacePoints.clear();
30 for (const auto& key: m_inSpacePoints) {
31 m_outSpacePoints.emplace_back(key.key() + m_outSpacePointSuffix);
32 }
33 }
34 ATH_CHECK(m_inSpacePoints.initialize());
35 ATH_CHECK(m_outSpacePoints.initialize());
36 ATH_CHECK(m_outPatterns.initialize());
37 ATH_CHECK(m_outMuons.initialize());
38
39 ATH_CHECK(m_geoCtxKey.initialize());
40 ATH_CHECK(m_idHelperSvc.retrieve());
41 ATH_CHECK(m_calibTool.retrieve());
42 ATH_CHECK(m_patVisionTool.retrieve(EnableTool{!m_patVisionTool.empty()}));
43 ATH_CHECK(m_segVisionTool.retrieve(EnableTool{!m_segVisionTool.empty()}));
44 ATH_CHECK(m_seedingTool.retrieve());
45
47 patCfg.useMdtHits = m_useMdtHits;
60
61 if (m_seedFromInner) {
62 patCfg.layerSeedings.push_back(LayerIndex::Inner);
63 }
64 patCfg.visionTool = m_patVisionTool.get();
65 patCfg.idHelperSvc = m_idHelperSvc.get();
66 m_globPatFinder = std::make_unique<GlobalPatternFinder>(name(), std::move(patCfg));
67
80 saCfg.maxIter = m_maxIter;
81
82 saCfg.calibrator = m_calibTool.get();
83 saCfg.visionTool = m_segVisionTool.get();
84 saCfg.idHelperSvc = m_idHelperSvc.get();
85 saCfg.trackSeeder = m_seedingTool.get();
86 m_saBuilder = std::make_unique<FastMuonSABuilder>(name(), std::move(saCfg));
87
88 //Print Configuration
89 ATH_MSG_DEBUG("Global Pattern Finder Configuration:\n"
90 << " Theta search window [rad]: " << m_thetaSearchWindow << "\n"
91 << " Base residual sigma [mm]: " << m_baseResidualSigma << "\n"
92 << " Max missed layer hits in station: " << m_maxMissLayersInStation << "\n"
93 << " Min hit distance for line [mm]: " << m_minHitDistance4Line << "\n"
94 << " Phi tolerance [rad]: " << m_phiTolerance << "\n"
95 << " Min trigger layers: " << m_minTriggerLayers << "\n"
96 << " Min precision layers: " << m_minPrecisionLayers << "\n"
97 << " Min phi layers: " << m_minPhiLayers << "\n"
98 << " Min station layers: " << m_minStationLayers << "\n"
99 << " Mean norm residual^2 cut: " << m_meanNormRes2Cut << "\n"
100 << " Seed from inner: " << m_seedFromInner << "\n"
101 << " Use MDT hits: " << m_useMdtHits << "\n"
102 << " Seed from MDT: " << m_seedFromMdt << "\n"
103 << " Max seed attempts: " << m_maxSeedAttempts << "\n");
104
105 ATH_MSG_DEBUG("FastMuonSABuilder Configuration:\n"
106 << " Recalibrate in fit: " << m_recalibInFit << "\n"
107 << " Use Hessian in residual: " << m_hessianResidual << "\n"
108 << " Seed hit chi2: " << m_seedHitChi2 << "\n"
109 << " Recalibrate seed: " << m_recalibSeed << "\n"
110 << " Good segment cut (reduced chi2): " << m_goodSegmentCut << "\n"
111 << " Outlier removal cut (chi2/nDoF): " << m_outlierRemovalCut << "\n"
112 << " Recovery pull: " << m_recoveryPull << "\n"
113 << " Precision hit cut: " << m_precHitCut << "\n"
114 << " Use fast fitter: " << m_useFastFitter << "\n"
115 << " Fast fitter as pre-fitter: " << m_fastPreFitter << "\n"
116 << " Ignore failed pre-fits: " << m_ignoreFailedPreFit << "\n"
117 << " Max iterations: " << m_maxIter);
118
119 return StatusCode::SUCCESS;
120}
121
122StatusCode FastReconstructionAlg::execute(const EventContext& ctx) const {
123 SpacePointContainerVec inSpacePoints{};
124 inSpacePoints.reserve(m_inSpacePoints.size());
125 for (const auto& key: m_inSpacePoints) {
126 auto& spc = inSpacePoints.emplace_back(nullptr);
127 ATH_CHECK(SG::get(spc, key, ctx));
128 ATH_MSG_DEBUG("Reading " << spc->size() << " SP buckets from collection: " << key);
129 }
130
131 const ActsTrk::GeometryContext* gctx{nullptr};
132 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
133
134 using BucketPerContainer = GlobalPatternFinder::BucketPerContainer;
135 BucketPerContainer outBuckets{};
136 for (const SpacePointContainer* inSpc : inSpacePoints) {
137 outBuckets.emplace(inSpc, BucketPerContainer::mapped_type{});
138 }
139 PatternVec patterns {m_globPatFinder->findPatterns(*gctx, inSpacePoints, outBuckets)};
140
142 for (size_t idx = 0; idx < inSpacePoints.size(); ++idx) {
143 const SpacePointContainer* inSpc = inSpacePoints.at(idx);
144 const auto& outBucketVec = outBuckets.at(inSpc);
145
147 ATH_CHECK(writeHandle.record(std::make_unique<SpacePointContainer>()));
148
149 for (const SpacePointBucket* bucket : outBucketVec) {
150 writeHandle->push_back(std::make_unique<SpacePointBucket>(*bucket));
151 }
152
153 ATH_MSG_DEBUG("Written " << writeHandle->size()
154 << " SP Buckets into StoreGate with key "
155 << m_outSpacePoints.at(idx));
156 }
159 ATH_CHECK(patWriteHandle.record(std::make_unique<GlobalPatternContainer>()));
160 for (GlobalPattern& pat : patterns) {
161 patWriteHandle->push_back(std::make_unique<GlobalPattern>(std::move(pat)));
162 }
163 ATH_MSG_DEBUG("Written "<<patWriteHandle->size()<<" GlobalPatterns into StoreGate.");
164
165 /* Build Fast Reco SA muons */
167 ATH_CHECK(fillMuons.record(m_outMuons, ctx));
168 std::size_t patIdx{0};
169 using Patternlink = ElementLink<GlobalPatternContainer>;
170 SG::Accessor<Patternlink> acc{patternLinkStr};
171 for (const GlobalPattern* pat : *patWriteHandle) {
172
173 xAOD::Muon* newMuon {m_saBuilder->buildMuonCandidate(ctx, *gctx, *pat, fillMuons)};
174 if (!newMuon) {
175 ATH_MSG_DEBUG("No muon candidate could be built for pattern " << *pat);
176 patIdx++;
177 continue;
178 }
179 // Add the link to the global pattern to the muon
180 acc(*newMuon) = Patternlink{*patWriteHandle, patIdx};
181 ATH_MSG_DEBUG("Add new muon candidate: " << printMuon(*newMuon));
182 patIdx++;
183 }
184 ATH_MSG_DEBUG("Written "<<fillMuons->size()<<" FastMuonSA into StoreGate.");
185 return StatusCode::SUCCESS;
186}
187
188
189}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
constexpr float inDeg(const float rad)
xAOD::FillContainer< xAOD::MuonContainer, xAOD::MuonAuxContainerR4 > MuonCont_t
Define the muon container type.
std::unordered_map< const SpacePointContainer *, std::vector< const SpacePointBucket * > > BucketPerContainer
Abrivation for a collection of space-point buckets grouped by their corresponding input container.
Muon::MuonStationIndex::LayerIndex LayerIndex
Type alias for the station layer index.
DoubleProperty m_phiTolerance
Maximum phi difference [rad] allowed between two hits belonging to the same pattern.
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKeyArray< SpacePointContainer > m_outSpacePoints
Write handle key for the output buckets.
DoubleProperty m_recoveryPull
Pull value for hit recovery.
ToolHandle< MuonValR4::IFastRecoVisualizationTool > m_patVisionTool
Handle to the visualization tool for global patterns.
DoubleProperty m_outlierRemovalCut
Cut on the segment chi2 / nDoF to launch the outlier removal.
std::unique_ptr< FastReco::FastMuonSABuilder > m_saBuilder
Pointer to the FastMuonSABuilder.
BooleanProperty m_fastPreFitter
The fast fitter is treated as a pre fitter.
BooleanProperty m_recalibInFit
-----------------------— Configuration options for segment fitter ----------------------—
ActsTrk::GeoContextReadKey_t m_geoCtxKey
Geometry context key.
UnsignedIntegerProperty m_maxMissLayersInStation
Maximum number of missed candidate hits in different measurement layers during pattern building allow...
BooleanProperty m_seedFromMdt
Toggle the seeding from MDT hits.
ToolHandle< MuonValR4::IPatternVisualizationTool > m_segVisionTool
Handle to the visualization tool for segments.
UnsignedIntegerProperty m_minTriggerLayers
Requirement on trigger layers in the bending direction to accept a pattern.
SG::ReadHandleKeyArray< SpacePointContainer > m_inSpacePoints
Keys of SpacePoint containers to read.
DoubleProperty m_meanNormRes2Cut
Quality cut on pattern'mean squared normalized residual.
UnsignedIntegerProperty m_precHitCut
Minimum number of precision hits to accept the segment.
BooleanProperty m_useMdtHits
--------------— Configuration options for the global pattern finder --------------—
std::unique_ptr< FastReco::GlobalPatternFinder > m_globPatFinder
Pointer to the actual global pattern finder.
UnsignedIntegerProperty m_minStationLayers
Minimum number of layers in a station to be considered a good station.
StringProperty m_outSpacePointSuffix
Suffix to add to the input space point container names to create the output container names,...
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Handle to the MuonIdHelper service.
DoubleProperty m_goodSegmentCut
Reduced chi2 defining a good segment, stopping the fit of other segments in the same station.
BooleanProperty m_recalibSeed
Toggle seed recalibration.
ToolHandle< ISpacePointCalibrator > m_calibTool
Handle to the space point calibrator tool.
BooleanProperty m_seedFromInner
Activate the seeding from Inner station.
UnsignedIntegerProperty m_maxSeedAttempts
Maximum number of attempts to build a pattern from hits already used in existing patterns.
DoubleProperty m_minHitDistance4Line
Minimum distance [mm] between two hits for being used to compute a reliable pattern line.
DoubleProperty m_seedHitChi2
Two mdt seeds are the same if their defining parameters match wihin.
SG::WriteHandleKey< GlobalPatternContainer > m_outPatterns
Write handle key for the output global patterns.
DoubleProperty m_baseResidualSigma
Effective isotropic position uncertainty [mm], including detector resolution and unmodelled effects.
UnsignedIntegerProperty m_minPhiLayers
Minimum number of phi layers required to accept a pattern.
ToolHandle< ITrackSeedingTool > m_seedingTool
The track seeding tool to construct the seed candidates and to estimate the initial parameters.
UnsignedIntegerProperty m_minPrecisionLayers
Requirement on precision layers in the bending direction to accept a pattern.
FastReco::GlobalPatternFinder::SpacePointContainerVec SpacePointContainerVec
Abrivation for a vector of space-point containers.
SG::WriteHandleKey< xAOD::MuonContainer > m_outMuons
Write handle key for the output Fast Reco SA muons.
BooleanProperty m_ignoreFailedPreFit
Switch to try the full fit when the fast pre-fitter fails.
BooleanProperty m_hessianResidual
Use the expliciit Hessian in the residual calculation.
UnsignedIntegerProperty m_maxIter
Tune the number of iterations.
virtual StatusCode initialize() override
BooleanProperty m_useFastFitter
Use the fast Mdt fitter where possible.
FastReco::GlobalPatternFinder::PatternVec PatternVec
Abrivation for a vector of global patterns.
DoubleProperty m_thetaSearchWindow
Size of theta window [rad] to search for compatible hits with a seed, tailored to the target pt cutof...
Data class to represent an eta maximum in hough space.
: The muon space point bucket represents a collection of points that will bre processed together in t...
Helper class to provide type-safe access to aux data.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
StatusCode record(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
std::vector< std::string > patterns
Definition listroot.cxx:187
This header ties the generic definitions in this package.
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
LayerIndex
enum to classify the different layers in the muon spectrometer
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Muon_v1 Muon
Reference the current persistent version:
bool ignoreFailedPreFit
Whether to ignore failed pre-fits and try the full fit anyway.
double outlierRemovalCut
Cut on the segment chi2 / nDoF to launch the outlier removal.
bool recalibInFit
Whether to recalibrate hits during fitting.
double goodSegmentCut
Reduced chi2 defining a good segment, stopping the fit of other segments in the same station.
bool useHessianResidual
Whether to use Hessian residuals.
const MuonValR4::IPatternVisualizationTool * visionTool
Pointer to the visualization tool.
const Muon::IMuonIdHelperSvc * idHelperSvc
Pointer to the idHelperSvc.
const ISpacePointCalibrator * calibrator
Pointer to the calibrator.
bool fastPreFitter
Whether the fast fitter is used as a pre-fitter.
const ITrackSeedingTool * trackSeeder
Pointer to the track seeder for momentum estimate.
bool useFastFitter
Whether to use the fast fitter.
double seedHitChi2
Two mdt seeds are the same if their defining parameters match within.
double recoveryPull
Pull value for hit recovery.
unsigned precHitCut
Minimum number of precision hits required for a segment.
unsigned maxIter
Maximum number of iterations in the fit.
bool recalibSeed
Toggle seed recalibration.
bool useMdtHits
Toggle the utilization of MDT hits to build patterns.
double thetaSearchWindow
Size of theta window in radians to search for comapatible hits with a pattern, tailored to the target...
bool seedFromMdt
Toggle the seeding from MDT hits.
unsigned int minPhiLayers
Minimum number of phi layers required to accept a pattern.
const Muon::IMuonIdHelperSvc * idHelperSvc
Pointer to the idHelperSvc.
std::vector< LayerIndex > layerSeedings
Vector configuring the seeding layers.
double phiTolerance
Maximum phi difference in radians allowed between two hits.
unsigned int minTriggerLayers
Minimum number of trigger layers in the bending direction required to accept a pattern.
const MuonValR4::IFastRecoVisualizationTool * visionTool
Pointer to the visualization tool.
unsigned int minStationLayers
Minimum number of layers in a station to be considered a good station.
unsigned int maxSeedAttempts
Maximum number of attempts to build a pattern from hits already used in existing patterns.
double minHitDistance4Line
Minimum distance (in mm) between two hits for being used to compute a reliable pattern line.
unsigned int minPrecisionLayers
Minimum number of precision layers in the bending direction required to accept a pattern.
double meanNormRes2Cut
Quality cut on pattern'mean squared normalized residual.
unsigned int maxMissLayersInStation
Maximum number of missed candidate hits in different measurement layers in a station.
double baseResidualSigma
Effective isotropic position uncertainty [mm], including detector resolution and unmodelled effects.