4#ifndef MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
5#define MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
15#include "Acts/Utilities/KDTree.hpp"
40 using BucketPerContainer = std::unordered_map<const SpacePointContainer*, std::vector<const SpacePointBucket*>>;
53 std::vector<LayerIndex>
layerSeedings{LayerIndex::Middle, LayerIndex::Outer};
164 using SearchTree_t = Acts::KDTree<2, HitPayload, double, std::array, 5>;
166 using TreeNode = std::pair<SearchTree_t::coordinate_t, HitPayload>;
182 const double seedTheta);
204 const double residual,
205 const double acceptWindow);
213 const double newResidual,
214 const double newAcceptWindow);
229 Acts::CloneablePtr<PatternHitVisualInfo>
visualInfo{
nullptr};
268 void print(std::ostream& ostr)
const;
270 candidate.
print(ostr);
323 const HitPayload& test,
324 const PatternState& pat)
const;
335 const HitPayload& test,
336 const PatternState& pat,
337 const uint8_t patHitIdx,
343 bool isBetter(
const PatternState&
a,
const PatternState& b)
const;
361 const PatternState& pattern)
const;
382 const HitPayload& hit2);
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
@ eRejectHit
Test failed, discard the 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...
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
std::vector< std::string > patterns
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.
bool isPrecision
Is precision hit.
const SpacePointContainer * container
Pointer to the parent container.
StIndex station
Station index.
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
CompatibilityResult 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.
uint8_t nBendingTriggerHits
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
~PatternState()=default
Destructor.
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.