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
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 baseRWindow {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 *****************/
80 double minLayerSeparation {40};
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 float R{0.f};
116 float Z{0.f};
118 float phi{0.};
122 uint8_t locLayer{0u};
124 uint8_t sector{0u};
126 bool isPrecision{false};
128 bool isStraw{false};
130 bool operator==(const HitPayload& other) const;
132 const SpacePoint* operator->() const { return hit; }
134 const SpacePoint& operator*() const { return *hit; }
136 const SpacePoint* sp() const { return hit; }
137 };
138
139 using SearchTree_t = Acts::KDTree<2, HitPayload, double, std::array, 5>;
141 enum class SeedCoords : std::uint8_t{
146 };
147
152 const HitPayload* hit{nullptr};
153 float R{0.f};
154 float Z{0.f};
157 uint8_t globLayer{0u};
159 uint8_t sector{0u};
161 bool isStraw{false};
162
163 // Forward commonly used accessors for convenience
164 const HitPayload* operator->() const { return hit; }
165 const HitPayload& operator*() const { return *hit; }
166 const SpacePoint* sp() const { return hit->sp(); }
167 bool operator==(const CandidateHit& other) const { return *hit == *other.hit; }
168 bool operator==(const HitPayload& other) const { return *hit == other; }
169 };
170
183
189
195 PatternState(const CandidateHit& seed,
196 const std::int8_t expSector,
197 const double seedTheta,
198 const Config* cfg,
199 const AthMessaging* logger);
201 PatternState() = delete;
204 PatternState(PatternState&& other) noexcept = default;
207 PatternState& operator=(PatternState&& other) noexcept = default;
210 PatternState(const PatternState& other) = default;
213 PatternState& operator=(const PatternState& other) = default;
215 ~PatternState() =default;
220 void addHit(const CandidateHit& hit,
221 const double residual,
222 const double acceptWindow);
228 void overWriteHit(const CandidateHit& newHit,
229 const double newResidual,
230 const double newAcceptWindow);
236 const Amg::Vector3D& beamSpot);
240 LineTestRes computeLineResidual(const CandidateHit& testHit) const;
244 bool isPhiCompatible(const double testPhi) const;
248 bool isInPattern(const HitPayload& hit) const;
250 void finalizePatternEta();
252 void finalizePatternPhi();
255 void moveLineAnchorHit(const CandidateHit& refHit);
258 void updateLineParameters(const Amg::Vector3D& beamSpot);
260 double getMeanResidual2() const;
262 uint8_t nBendingHits() const;
264 uint8_t nBendingLayers() const;
268 uint8_t nStations(const bool onlyGoodStations) const;
270 uint8_t nMDTLastLayer() const;
272 std::vector<const SpacePointBucket*> getParentBuckets() const;
274 bool isInLastLayer(const CandidateHit& hit) const;
275
277 const Config* cfg{nullptr};
279 const AthMessaging* logger{nullptr};
281 Acts::CloneablePtr<PatternHitVisualInfo> visualInfo{nullptr};
289 double theta{0.};
290 double phi{0.};
294 double lastResidual{0.};
297 double lineSlope{0.};
298 double dZ_slope{0.};
300 double LR_factor{-1.};
302 double anchorZ{0.};
303 double anchorR{0.};
305 ExpandedSector expSect{static_cast<int8_t>(0)};
307 uint8_t nPrecisionLayers{0u};
308 uint8_t nTriggerLayers{0u};
309 uint8_t nPhiLayers{0u};
311 bool isFinalized{false};
313 bool isOverlap{false};
315 bool useBeamspot{false};
317 bool needLineUpdate{false};
318
320 std::array<uint8_t, s_nStations> nMeasurementLayers{};
322 std::array<std::vector<CandidateHit>, s_nStations> hitsPerStation{};
324 std::vector<HitPayload> phiOnlyHits{};
325
327 bool operator==(const PatternState& other) const = delete;
329 void print(std::ostream& ostr, bool detailed) const;
330 };
331 using PatternStateVec = std::vector<PatternState>;
337 const SpacePointContainerVec& spacepoints) const;
343 PatternStateVec findPatternsInEta(const SearchTree_t& orderedSpacepoints,
344 PatternHitVisualInfoVec* visualInfo = nullptr) const;
353 void extendPatterns(PatternStateVec& startPatterns,
354 PatternStateVec& endPatterns,
355 const CandidateHit& testHit,
356 const Amg::Vector3D& beamSpot,
357 PatternHitVisualInfoVec* visualInfo = nullptr) const;
361 bool passPatternCuts(const PatternState& pat) const;
366 static bool isBetter(const PatternState& a,
367 const PatternState& b);
373 PatternHitVisualInfoVec* visualInfo = nullptr) const;
383 GlobalPattern convertToPattern(const PatternState& candidate) const;
387 PatternVec convertToPattern(const PatternStateVec& candidates) const;
399 static LayerOrdering checkLayerOrdering(const HitPayload& hit1,
400 const HitPayload& hit2);
402 static bool areConsecutiveMdt(const CandidateHit& hit1,
403 const CandidateHit& hit2);
408 void addVisualInfo(const PatternState& candidate,
410 PatternHitVisualInfoVec* visualInfo) const;
411
416
420 };
421
422 static PatternPrintView brief(const PatternState& p);
423 static PatternPrintView detailed(const PatternState& p);
424 friend std::ostream& operator<<(std::ostream& os, const PatternPrintView& v);
425 };
426}
427
428
429#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.
const HitPayload * hit
Store locally most frequently accessed data to avoid frequent pointer indirection.
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 minLayerSeparation
Minimum separation (in mm) between the measurement layers of two hits for being used to compute a rel...
double phiTolerance
Maximum phi difference in radians allowed between two hits.
double baseRWindow
Base radial compatibility window (in mm).
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.
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.
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.
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.
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.
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.
bool useBeamspot
Whether we used the beamspot to compute the line parameters.
PatternState(PatternState &&other) noexcept=default
Move constructor.
double theta
Average theta & average phi of the pattern.
PatternState(const PatternState &other)=default
Copy constructor.
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.
void finalizePatternEta()
Finalize the pattern building in eta and update its state.
std::vector< const SpacePointBucket * > getParentBuckets() const
Get the buckets associated with the pattern.
double LR_factor
Simple line model: factor for LR correction to be applied.
bool isFinalized
Flag to indicate if the pattern has been finalized.
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
Pointer to the last hit in the second-to-last layer.
double anchorZ
Simple line model: anchor Z and R.
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.
double lineSlope
Simple line model: slope and associated delta Z, i.e.
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.
PatternState(const CandidateHit &seed, const std::int8_t expSector, const double seedTheta, const Config *cfg, const AthMessaging *logger)
Constructor taking the seed information.
bool isOverlap
Flag to indicate if the pattern is overlapping with another one, used during overlap removal.
CandidateHit lineAnchorHit
Pointer to the line anchor hit.
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.
CandidateHit lastInsertedHit
Pointer to the last inserted hit.
double getMeanResidual2() const
Return the mean normalized residual squared.
uint8_t nMDTLastLayer() const
Gives the number of MDT hits on the last layer.
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.