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
15
16#include "Acts/Utilities/KDTree.hpp"
17
18
19namespace MuonR4::FastReco{
20
29
31 public:
37 using SpacePointContainerVec = std::vector<const SpacePointContainer*>;
39 using PatternVec = std::vector<GlobalPattern>;
41 using BucketPerContainer = std::unordered_map<const SpacePointContainer*, std::vector<const SpacePointBucket*>>;
45 using PatternHitVisualInfoVec = std::vector<PatternHitVisualInfo>;
46
48 struct Config {
50 bool useMdtHits {true};
52 bool seedFromMdt {false};
54 std::vector<LayerIndex> layerSeedings{LayerIndex::Middle, LayerIndex::Outer};
55 /********* Pattern bulding acceptance **********/
57 double thetaSearchWindow {0.05};
59 double baseResidualSigma {25};
61 double phiTolerance {0.1};
62 /********* Pile-up & Fake rate suppression *****/
64 unsigned int minTriggerLayers {3};
66 unsigned int minPrecisionLayers {0};
68 unsigned int minPhiLayers {1};
70 unsigned int minStationLayers {4};
72 double meanNormRes2Cut {0.2};
73 /********* Pattern recovery power **************/
75 unsigned int maxSeedAttempts {2};
77 unsigned int maxMissLayersInStation {2};
78 /********* Numerical stability *****************/
85 };
86
90 GlobalPatternFinder(const std::string& name,
91 Config&& config);
92
100 const SpacePointContainerVec& spacepoints,
101 BucketPerContainer& outBuckets) const;
102
103 private:
104 static const int s_nStations{Acts::toUnderlying(StIndex::StIndexMax)};
108 const SpacePoint* hit{nullptr};
110 const SpacePointBucket* bucket{nullptr};
114 Amg::Vector3D position{Amg::Vector3D::Zero()};
116 Amg::Vector3D sensorDir{Amg::Vector3D::Zero()};
120 uint8_t locLayer{0u};
122 uint8_t sector{0u};
124 bool isPrecision{false};
126 bool isStraw{false};
128 bool operator==(const HitPayload& other) const;
130 const SpacePoint* operator->() const { return hit; }
132 const SpacePoint& operator*() const { return *hit; }
134 const SpacePoint* sp() const { return hit; }
135 };
136
137 using SearchTree_t = Acts::KDTree<2, HitPayload, double, std::array, 5>;
139 enum class SeedCoords : std::uint8_t{
144 };
145
151 const HitPayload* hit{nullptr};
155 uint8_t globLayer{0u};
157 uint8_t sector{0u};
159 bool isStraw{false};
160
161 // Forward commonly used accessors for convenience
162 const HitPayload* operator->() const { return hit; }
163 const HitPayload& operator*() const { return *hit; }
164 const SpacePoint* sp() const { return hit->sp(); }
165 bool operator==(const CandidateHit& other) const { return *hit == *other.hit; }
166 bool operator==(const HitPayload& other) const { return *hit == other; }
167 // Print and stream operator
168 friend std::ostream& operator<<(std::ostream& ostr, const CandidateHit& c) {
169 c.print(ostr);
170 return ostr;
171 }
172 void print(std::ostream& ostr) const;
173 };
174
187
193
200 PatternState(const CandidateHit& seed,
201 const std::int8_t expSector,
202 const Config* cfg,
203 const AthMessaging* logger);
205 PatternState() = delete;
208 PatternState(PatternState&& other) noexcept = default;
211 PatternState& operator=(PatternState&& other) noexcept = default;
214 PatternState(const PatternState& other) = default;
217 PatternState& operator=(const PatternState& other) = default;
219 ~PatternState() =default;
224 void addHit(const CandidateHit& hit,
225 const double residual,
226 const double acceptWindow);
232 void overWriteHit(const CandidateHit& newHit,
233 const double newResidual,
234 const double newAcceptWindow);
240 const Amg::Vector3D& beamSpot);
244 LineTestRes computeLineResidual(const CandidateHit& testHit) const;
250 Amg::Vector3D projToPhiPlane(const HitPayload& hit) const;
254 bool isPhiCompatible(const double testPhi) const;
258 bool isInPattern(const HitPayload& hit) const;
260 void finalizePatternPhi();
263 void moveLineAnchorHit(const CandidateHit& refHit);
266 void updateLineParameters(const Amg::Vector3D& beamSpot);
268 void updatePatternPhi(const double newPhi);
270 double getMeanResidual2() const;
272 uint8_t nBendingHits() const;
274 uint8_t nBendingLayers() const;
278 uint8_t nStations(const bool onlyGoodStations) const;
280 std::vector<const SpacePointBucket*> getParentBuckets() const;
282 bool isInLastLayer(const CandidateHit& hit) const;
283
285 const Config* cfg{nullptr};
287 const AthMessaging* logger{nullptr};
289 Acts::CloneablePtr<PatternHitVisualInfo> visualInfo{nullptr};
299 Amg::Vector3D bendPlaneNorm{Amg::Vector3D::Zero()};
302 Amg::Vector3D linePos{Amg::Vector3D::Zero()};
303 Amg::Vector3D lineDir{Amg::Vector3D::Zero()};
305 double leverArm{0.};
309 double lastResidual{0.};
312 double patPhi{0.};
314 ExpandedSector expSect{static_cast<int8_t>(0)};
316 uint8_t nPrecisionLayers{0u};
317 uint8_t nTriggerLayers{0u};
318 uint8_t nPhiLayers{0u};
320 bool isFinalized{false};
322 bool isOverlap{false};
324 bool useBeamspot{false};
326 bool needLineUpdate{false};
327
329 std::array<uint8_t, s_nStations> nMeasurementLayers{};
331 std::array<std::vector<CandidateHit>, s_nStations> hitsPerStation{};
333 std::vector<HitPayload> phiOnlyHits{};
334
336 bool operator==(const PatternState& other) const = delete;
338 void print(std::ostream& ostr, bool detailed) const;
339 };
340 using PatternStateVec = std::vector<PatternState>;
346 const SpacePointContainerVec& spacepoints) const;
352 PatternStateVec findPatternsInEta(const SearchTree_t& orderedSpacepoints,
353 PatternHitVisualInfoVec* visualInfo = nullptr) const;
362 void extendPatterns(PatternStateVec& startPatterns,
363 PatternStateVec& endPatterns,
364 const CandidateHit& testHit,
365 const Amg::Vector3D& beamSpot,
366 PatternHitVisualInfoVec* visualInfo = nullptr) const;
370 bool passPatternCuts(const PatternState& pat) const;
375 static bool isBetter(const PatternState& a,
376 const PatternState& b);
382 PatternHitVisualInfoVec* visualInfo = nullptr) const;
392 GlobalPattern convertToPattern(const PatternState& candidate) const;
396 PatternVec convertToPattern(const PatternStateVec& candidates) const;
408 static LayerOrdering checkLayerOrdering(const HitPayload& hit1,
409 const HitPayload& hit2);
411 static bool areConsecutiveMdt(const CandidateHit& hit1,
412 const CandidateHit& hit2);
417 void addVisualInfo(const PatternState& candidate,
419 PatternHitVisualInfoVec* visualInfo) const;
420
425
428 bool detailed = false;
429 };
430
431 static PatternPrintView brief(const PatternState& p);
432 static PatternPrintView detailed(const PatternState& p);
433 friend std::ostream& operator<<(std::ostream& os, const PatternPrintView& v);
434 };
435}
436
437
438#endif
static Double_t a
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
void extendPatterns(PatternStateVec &startPatterns, PatternStateVec &endPatterns, const CandidateHit &testHit, const Amg::Vector3D &beamSpot, PatternHitVisualInfoVec *visualInfo=nullptr) const
Main function controlling the development of patterns, including pattern branching when necessary.
std::vector< const SpacePointContainer * > SpacePointContainerVec
Abrivation for a vector of space-point containers.
PatternStateVec resolveOverlaps(PatternStateVec &toResolve, PatternHitVisualInfoVec *visualInfo=nullptr) const
Method to remove overlapping patterns.
static bool areConsecutiveMdt(const CandidateHit &hit1, const CandidateHit &hit2)
Helper function to check whether two hits are consecutive MDT measurements.
friend std::ostream & operator<<(std::ostream &os, const PatternPrintView &v)
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)...
Config m_cfg
Global Pattern Recognition configuration.
static PatternPrintView brief(const PatternState &p)
Print the pattern candidate and stream operator.
std::vector< GlobalPattern > PatternVec
Abrivation for a vector of global patterns.
static bool isBetter(const PatternState &a, const PatternState &b)
Method to compare two patterns and define which one is better.
LineTestDecision
: Enum for possible outcomes of pattern line compatibility test
@ eBranchPattern
Test successfull with multiple pattern hits on same layer, branch the pattern.
bool passPatternCuts(const PatternState &pat) const
Method to check if a pattern passes the quality cuts.
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.
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 global pattern building in the bending plane.
Acts::KDTree< 2, HitPayload, double, std::array, 5 > SearchTree_t
Definition of the search tree class.
static PatternPrintView detailed(const PatternState &p)
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
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
Small wrapper for candidate hits used to build patterns.
bool operator==(const CandidateHit &other) const
uint8_t globLayer
Global measurement layer number.
friend std::ostream & operator<<(std::ostream &ostr, const CandidateHit &c)
const HitPayload * hit
Pointer to the underlying hit.
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.
Hit information stored during pattern building.
const SpacePoint * hit
Pointer to the underlying hit.
const SpacePoint * sp() const
Get the pointer to the underlying hit.
uint8_t locLayer
Layer number in the sector frame.
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.
Amg::Vector3D sensorDir
Sensor direction in global frame.
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.
: Small struct to encapsulate the result of the line compatibility test
Pattern state object storing pattern information during construction.
Acts::CloneablePtr< PatternHitVisualInfo > visualInfo
Pointer to Visual Information for pattern visualization.
void moveLineAnchorHit(const CandidateHit &refHit)
Move the line anchor hit given a reference hit.
void updatePatternPhi(const double newPhi)
Helper method to update the pattern phi and bending plane normal.
double lastResidual
Residual & acceptance window of the last inserted hit (needed when replacing a hit).
std::array< uint8_t, s_nStations > nMeasurementLayers
Counts of measurement layers per station.
Amg::Vector3D projToPhiPlane(const HitPayload &hit) const
Project a certain hit position onto the bending plane where the pattern is defined.
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.
uint8_t nStations(const bool onlyGoodStations) const
Method returning the number of stations.
uint8_t nBendingHits() const
Return the number of hits in bending coordinate.
Amg::Vector3D linePos
Position and direction of the pattern line.
bool useBeamspot
Whether we used the beamspot to compute the line parameters.
PatternState(PatternState &&other) noexcept=default
Move constructor.
PatternState(const PatternState &other)=default
Copy constructor.
double leverArm
Distance between the two points defining the pattern line.
bool needLineUpdate
Whether we need to update the pattern line the next time we find a hit in a new layer.
void overWriteHit(const CandidateHit &newHit, const double newResidual, const double newAcceptWindow)
Overwrite the hits on the last layer with the new one.
std::vector< HitPayload > phiOnlyHits
Array holding phi-only hits.
LineTestRes checkLineComp(const CandidateHit &testHit, const Amg::Vector3D &beamSpot)
Method checking line compatibility of a test hit against the pattern.
LineTestRes computeLineResidual(const CandidateHit &testHit) const
Method to compute the residual of a test hit against the pattern line.
std::vector< const SpacePointBucket * > getParentBuckets() const
Get the buckets associated with the pattern.
bool isFinalized
Flag to indicate if the pattern has been finalized.
Amg::Vector3D bendPlaneNorm
Normal vector to the bending plane where the pattern lies.
void updateLineParameters(const Amg::Vector3D &beamSpot)
Update the line parameters based on the current hits.
uint8_t nBendingLayers() const
Return the number of layers in bending coordinate.
void finalizePatternPhi()
Finalize the pattern building in phi and update its state.
CandidateHit prevLayerHit
Last hit in the second-to-last layer.
PatternState()=delete
Delete default destructor - ensure patterns are always constructed from a seed or another pattern.
bool isPhiCompatible(const double testPhi) const
Method to check the phi compatibility of a test hit with a given pattern.
PatternState & operator=(const PatternState &other)=default
Copy assignment operator.
std::array< std::vector< CandidateHit >, s_nStations > hitsPerStation
Map collection of hits per station.
void print(std::ostream &ostr, bool detailed) const
Print the pattern candidate.
bool isOverlap
Flag to indicate if the pattern is overlapping with another one, used during overlap removal.
double patPhi
Pattern phi, which is the phi of the bending plane where the pattern lies.
PatternState & operator=(PatternState &&other) noexcept=default
Move assignment operator.
void addHit(const CandidateHit &hit, const double residual, const double acceptWindow)
Add a hit to the pattern and update the internal state.
bool isInLastLayer(const CandidateHit &hit) const
Check whether a given hit is in the last layer.
uint8_t nPrecisionLayers
Counts of precision / non-precision / phi layers.
double getMeanResidual2() const
Return the mean normalized residual squared.
PatternState(const CandidateHit &seed, const std::int8_t expSector, const Config *cfg, const AthMessaging *logger)
Constructor taking the seed information.
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.