ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalPatternFinder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
5#define MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
6
14
15#include "Acts/Utilities/KDTree.hpp"
16
17
19
28
30 public:
36 using SpacePointContainerVec = std::vector<const SpacePointContainer*>;
38 using PatternVec = std::vector<GlobalPattern>;
40 using BucketPerContainer = std::unordered_map<const SpacePointContainer*, std::vector<const SpacePointBucket*>>;
44 using PatternHitVisualInfoVec = std::vector<PatternHitVisualInfo>;
45
47 struct Config {
49 bool useMdtHits {true};
51 bool seedFromMdt {false};
53 std::vector<LayerIndex> layerSeedings{LayerIndex::Middle, LayerIndex::Outer};
54 /********* Pattern bulding acceptance **********/
56 double thetaSearchWindow {0.033};
58 double baseRWindow {25};
60 double phiTolerance {0.1};
61 /********* Pile-up & Fake rate suppression *****/
63 unsigned int minBendingTriggerHits {3};
65 unsigned int minBendingPrecisionHits {0};
67 unsigned int minPhiHits {1};
69 double meanNormRes2Cut {0.2};
70 /********* Pattern recovery power **************/
72 unsigned int maxSeedAttempts {2};
74 unsigned int maxMissedLayerHits {2};
75 /********* Numerical stability *****************/
77 double minLayerSeparation {40};
78 /********* Pattern quality evaluation **********/
80 double precisionWeight {0.75};
82 double hitScoreSaturation {10.0};
84 double residualPenalty {1.5};
86 double phiBonusSaturation {4.0};
91 };
92
96 GlobalPatternFinder(const std::string& name,
97 Config&& config);
98
106 const SpacePointContainerVec& spacepoints,
107 BucketPerContainer& outBuckets) const;
108
109 private:
121 HitPayload(const SpacePoint* hit,
125 uint8_t layerNum,
126 double R,
127 double Z,
128 double phi);
134 HitPayload(const SpacePoint* hit,
136 uint8_t layerNum,
137 double phi);
139 const SpacePoint* hit{nullptr};
141 const SpacePointBucket* bucket{nullptr};
145 double R{0.};
147 double Z{0.};
149 double phi{0.};
153 uint8_t layerNum{0u};
157 bool operator==(const HitPayload& other) const;
159 const SpacePoint* operator->() const { return hit; }
161 const SpacePoint& operator*() const { return *hit; }
162 };
163
164 using SearchTree_t = Acts::KDTree<2, HitPayload, double, std::array, 5>;
166 using TreeNode = std::pair<SearchTree_t::coordinate_t, HitPayload>;
168 enum class SeedCoords : std::uint8_t{
173 };
174
180 PatternState(const HitPayload& seed,
181 const uint8_t sectorCoord,
182 const double seedTheta);
184 PatternState() = delete;
187 PatternState(PatternState&& other) noexcept = default;
190 PatternState& operator=(PatternState&& other) noexcept = default;
193 PatternState(const PatternState& other) = default;
196 PatternState& operator=(const PatternState& other) = default;
198 ~PatternState() =default;
203 void addHit(const HitPayload& hit,
204 const double residual,
205 const double acceptWindow);
211 void overWriteHit(const HitPayload& oldHit,
212 const HitPayload& newHit,
213 const double newResidual,
214 const double newAcceptWindow);
218 const HitPayload& getNthLastHit(const uint8_t n) const;
222 bool isInPattern(const HitPayload& hit) const;
224 void finalizePatternEta();
226 void finalizePatternPhi();
227
229 Acts::CloneablePtr<PatternHitVisualInfo> visualInfo{nullptr};
233 const SpacePoint* prevLayerHit{nullptr};
235 double theta{0.};
236 double phi{0.};
240 double lastResidual{0.};
243 uint8_t nPrecisionHits{0u};
245 uint8_t nPhiHits{0u};
247 uint8_t nMissedLayerHits{0u};
249 uint8_t sectorCoord{0};
250 uint8_t sector1{0};
251 uint8_t sector2{0};
253 bool isFinalized{false};
255 bool isOverlap{false};
256
258 std::unordered_map<StIndex, std::vector<HitPayload>> hitsPerStation{};
261 std::vector<StIndex> stations{};
264
266 bool operator==(const PatternState& other) const = delete;
268 void print(std::ostream& ostr) const;
269 friend std::ostream& operator<<(std::ostream& ostr, const PatternState& candidate) {
270 candidate.print(ostr);
271 return ostr;
272 }
273 };
274 using PatternStateVec = std::vector<PatternState>;
275
276
282 const SpacePointContainerVec& spacepoints) const;
288 PatternStateVec findPatternsInEta(const SearchTree_t& orderedSpacepoints,
289 PatternHitVisualInfoVec* visualInfo = nullptr) const;
297 void extendPatterns(PatternStateVec& activePatterns,
298 const HitPayload& test,
299 const HitPayload& seed,
300 const HitPayload& prevCandidate,
301 PatternHitVisualInfoVec* visualInfo = nullptr) const;
303 enum class CompatibilityResult : std::int8_t{
310 };
311
317
322 LineCompatibilityResult checkLineCompatibility(const HitPayload& seed,
323 const HitPayload& test,
324 const PatternState& pat) const;
334 LineCompatibilityResult computeResidual(const HitPayload& seed,
335 const HitPayload& test,
336 const PatternState& pat,
337 const uint8_t patHitIdx,
338 const Amg::Vector3D& beamSpot) const;
343 bool isBetter(const PatternState& a, const PatternState& b) const;
349 PatternHitVisualInfoVec* visualInfo = nullptr) const;
360 bool isPhiCompatible(const double testPhi,
361 const PatternState& pattern) const;
365 GlobalPattern convertToPattern(const PatternState& candidate) const;
369 PatternVec convertToPattern(const PatternStateVec& candidates) const;
381 static LayerOrdering checkLayerOrdering(const HitPayload& hit1,
382 const HitPayload& hit2);
387 void addVisualInfo(const PatternState& candidate,
389 PatternHitVisualInfoVec* visualInfo) const;
390
395 };
396}
397
398
399#endif
static Double_t a
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
std::vector< const SpacePointContainer * > SpacePointContainerVec
Abrivation for a vector of space-point containers.
std::pair< SearchTree_t::coordinate_t, HitPayload > TreeNode
Type alias for a tree node, formed by a hit payload and its indexing coordinates.
CompatibilityResult
: Enum for the possible outcomes of the line compatibility test of one pattern against one test hit
@ eBranchPattern
Test successfull with multiple pattern hits in the same logical measurement layer,...
@ eAddHit
Test successfull, add the hit to the pattern.
PatternStateVec resolveOverlaps(PatternStateVec &&toResolve, PatternHitVisualInfoVec *visualInfo=nullptr) const
Method to remove overlapping patterns.
std::vector< PatternHitVisualInfo > PatternHitVisualInfoVec
Abrivation for a vector of visual information objects.
static LayerOrdering checkLayerOrdering(const HitPayload &hit1, const HitPayload &hit2)
Method to check the logical layer ordering of two hits.
MuonValR4::IFastRecoVisualizationTool::PatternHitVisualInfo PatternHitVisualInfo
Type alias for the visual information of a pattern.
SearchTree_t constructTree(const ActsTrk::GeometryContext &gctx, const SpacePointContainerVec &spacepoints) const
Method to construct the search tree by filling it up with spacepoints from the given containers.
void addVisualInfo(const PatternState &candidate, PatternHitVisualInfo::PatternStatus status, PatternHitVisualInfoVec *visualInfo) const
Helper function to add visual information of a given pattern (which is usually going to be destroyed)...
void extendPatterns(PatternStateVec &activePatterns, const HitPayload &test, const HitPayload &seed, const HitPayload &prevCandidate, PatternHitVisualInfoVec *visualInfo=nullptr) const
Function testing pattern compatibility of a set of active patterns (patterns produced from the same s...
Config m_cfg
Global Pattern Recognition configuration.
bool isBetter(const PatternState &a, const PatternState &b) const
Operator to compare two patterns.
bool isPhiCompatible(const double testPhi, const PatternState &pattern) const
Method to check the phi compatibility of a test hit with a given pattern.
LineCompatibilityResult checkLineCompatibility(const HitPayload &seed, const HitPayload &test, const PatternState &pat) const
Method to check the line compatibility of a test hit with a given pattern.
std::vector< GlobalPattern > PatternVec
Abrivation for a vector of global patterns.
Muon::MuonStationIndex::StIndex StIndex
Type alias for the station index.
LayerOrdering
Enum to express the logical measurement layer ordering given two hits.
void addPhiOnlyHits(const ActsTrk::GeometryContext &gctx, PatternStateVec &patterns) const
Method to add phi-only measurements to existing PatternStates.
GlobalPatternFinder(const std::string &name, Config &&config)
Standard constructor.
std::vector< PatternState > PatternStateVec
PatternVec findPatterns(const ActsTrk::GeometryContext &gctx, const SpacePointContainerVec &spacepoints, BucketPerContainer &outBuckets) const
Main methods steering the pattern finding.
SeedCoords
Abrivation of the seed coordinates.
@ eSector
Expanded sector coordinate of the associated spectrometer sector
SpacePointPerLayerSorter m_spSorter
Spacepoint sorter per logical measurement layer.
LineCompatibilityResult computeResidual(const HitPayload &seed, const HitPayload &test, const PatternState &pat, const uint8_t patHitIdx, const Amg::Vector3D &beamSpot) const
Helper method to compute the residual of a test hit against a reference pattern hit and check whether...
GlobalPattern convertToPattern(const PatternState &candidate) const
Method to convert a PatternState into a GlobalPattern object.
std::unordered_map< const SpacePointContainer *, std::vector< const SpacePointBucket * > > BucketPerContainer
Abrivation for a collection of space-point buckets grouped by their corresponding input container.
PatternStateVec findPatternsInEta(const SearchTree_t &orderedSpacepoints, PatternHitVisualInfoVec *visualInfo=nullptr) const
Method steering the building of patterns in eta.
Acts::KDTree< 2, HitPayload, double, std::array, 5 > SearchTree_t
Definition of the search tree class.
Muon::MuonStationIndex::LayerIndex LayerIndex
Type alias for the station layer index.
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...
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Helper tool to visualize a pattern recogntion incident or a certain stage of the segment fit.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
std::vector< std::string > patterns
Definition listroot.cxx:187
Eigen::Matrix< double, 3, 1 > Vector3D
bool isPrecisionHit(const SpacePoint &hit)
Returns whether the uncalibrated spacepoint is a precision hit (Mdt, micromegas, stgc strips).
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
StIndex
enum to classify the different station layers in the muon spectrometer
LayerIndex
enum to classify the different layers in the muon spectrometer
bool useMdtHits
Toggle the utilization of MDT hits to build patterns.
unsigned int minBendingTriggerHits
Minimum number of trigger hits in the bending direction required to accept a pattern.
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.
const Muon::IMuonIdHelperSvc * idHelperSvc
Pointer to the idHelperSvc.
std::vector< LayerIndex > layerSeedings
Vector configuring the seeding layers.
double minLayerSeparation
Minimum separation (in mm) between the measurement layers of two hits for being used to compute a rel...
double precisionWeight
Weight of precision hits in the score, w.r.t trigger hits.
double phiTolerance
Maximum phi difference in radians allowed between two hits.
double baseRWindow
Base radial compatibility window (in mm).
double phiBonusSaturation
Saturation for phi bonus — beyond this many phi hits the bonus is maxed.
double hitScoreSaturation
Hit counts saturates at nStations * this value.
unsigned int maxMissedLayerHits
Maximum number of missed candidate hits in different measurement layers during pattern building.
const MuonValR4::IFastRecoVisualizationTool * visionTool
Pointer to the visualization tool.
unsigned int minPhiHits
Minimum number of phi measurements required to accept a pattern.
unsigned int maxSeedAttempts
Maximum number of attempts to build a pattern from hits already used in existing patterns.
double meanNormRes2Cut
Quality cut on pattern'mean squared normalized residual.
unsigned int minBendingPrecisionHits
Minimum number of precision hits in the bending direction required to accept a pattern.
double residualPenalty
How strongly to penalize residual — higher = stricter quality requirement.
Hit information stored during pattern building.
HitPayload(const SpacePoint *hit, const SpacePointBucket *bucket, const SpacePointContainer *container, StIndex station, uint8_t layerNum, double R, double Z, double phi)
Full constructor for eta hits.
const SpacePoint * hit
Pointer to the underlying hit.
const SpacePoint & operator*() const
Dereference operator: it allows to access the underlying hit.
const SpacePointBucket * bucket
Pointer to the parent bucket.
const SpacePointContainer * container
Pointer to the parent container.
bool operator==(const HitPayload &other) const
Equal operator: it compares the underlying hit.
const SpacePoint * operator->() const
Arrow operator: it allows to access the underlying hit.
uint8_t layerNum
Logical layer number in the sector frame.
: Small struct to encapsulate the checkLineCompatibility result
Acts::CloneablePtr< PatternHitVisualInfo > visualInfo
Pointer to Visual Information for pattern visualization.
double lastResidual
Residual & acceptance window of the last inserted hit (needed when replacing a hit).
void addHit(const HitPayload &hit, const double residual, const double acceptWindow)
Add a hit to the pattern and update the internal state.
BucketPerContainer bucketsPerContainer
Map of spacepoint buckets per spacepoint container associated to the pattern.
double meanNormResidual2
Mean over eta hits of the square of their residual divided by acceptance window.
bool isInPattern(const HitPayload &hit) const
Check wheter a hit is present in the pattern.
PatternState(PatternState &&other) noexcept=default
Move constructor.
double theta
Average theta & average phi of the pattern.
PatternState(const PatternState &other)=default
Copy constructor.
const SpacePoint * lastInsertedHit
Pointer to the last inserted hit.
std::vector< StIndex > stations
Pattern hit stations to save the filling order.
void print(std::ostream &ostr) const
Print the pattern candidate and stream operator.
void finalizePatternEta()
Finalize the pattern building in eta and update its state.
bool isFinalized
Flag to indicate if the pattern has been finalized.
void finalizePatternPhi()
Finalize the pattern building in phi and update its state.
uint8_t nPrecisionHits
Counts of precision measurements / non-precision in bending direction / phi measurements.
PatternState()=delete
Delete default destructor - ensure patterns are always constructed from a seed or another pattern.
PatternState & operator=(const PatternState &other)=default
Copy assignment operator.
std::unordered_map< StIndex, std::vector< HitPayload > > hitsPerStation
Map collection of hits per station.
uint8_t nMissedLayerHits
Number of missed candidate hits in different measurement layers during pattern building.
PatternState(const HitPayload &seed, const uint8_t sectorCoord, const double seedTheta)
Constructor taking the seed information.
bool isOverlap
Flag to indicate if the pattern is overlapping with another one, used during overlap removal.
friend std::ostream & operator<<(std::ostream &ostr, const PatternState &candidate)
PatternState & operator=(PatternState &&other) noexcept=default
Move assignment operator.
const SpacePoint * prevLayerHit
Pointer to the last hit in the second-to-last layer.
uint8_t sectorCoord
expanded sector coordinate & the two corresponding physical sectors
void overWriteHit(const HitPayload &oldHit, const HitPayload &newHit, const double newResidual, const double newAcceptWindow)
Overwrite a hit in the pattern and update the internal state.
const HitPayload & getNthLastHit(const uint8_t n) const
Get the n-th last inserted hit.
bool operator==(const PatternState &other) const =delete
Patterns are considered identical if they have the same hit content.
Structure to hold visual information about a pattern.