4#ifndef MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
5#define MUONR4_FASTRECONSTRUCTIONALGS_GLOBALPATTERNFINDER__H
16#include "Acts/Utilities/KDTree.hpp"
41 using BucketPerContainer = std::unordered_map<const SpacePointContainer*, std::vector<const SpacePointBucket*>>;
54 std::vector<LayerIndex>
layerSeedings{LayerIndex::Middle, LayerIndex::Outer};
104 static const int s_nStations{Acts::toUnderlying(StIndex::StIndexMax)};
139 using SearchTree_t = Acts::KDTree<2, HitPayload, double, std::array, 5>;
196 const std::int8_t expSector,
197 const double seedTheta,
221 const double residual,
222 const double acceptWindow);
229 const double newResidual,
230 const double newAcceptWindow);
268 uint8_t
nStations(
const bool onlyGoodStations)
const;
281 Acts::CloneablePtr<PatternHitVisualInfo>
visualInfo{
nullptr};
400 const HitPayload& hit2);
403 const CandidateHit& hit2);
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
@ eRejectHit
Test failed, discard the hit.
@ eBranchPattern
Test successfull with multiple pattern hits on same layer, branch the pattern.
@ eOverwriteLastHit
Test successful, overwrite the hit.
@ eAddHit
Test successfull, add hit to pattern.
@ eConsecutiveMdt
Test hit is a consecutive MDT hit.
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
static const int s_nStations
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...
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
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.
const HitPayload & operator*() const
bool isStraw
Is straw hit.
bool operator==(const CandidateHit &other) const
uint8_t globLayer
Global measurement layer number.
const SpacePoint * sp() const
bool operator==(const HitPayload &other) const
const HitPayload * hit
Store locally most frequently accessed data to avoid frequent pointer indirection.
const HitPayload * operator->() const
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.
bool isPrecision
Is precision hit.
const SpacePointContainer * container
Pointer to the parent container.
bool isStraw
Is straw hit.
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.
: 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.
ExpandedSector expSect
expanded MS sector
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.
const Config * cfg
Pointer to cfg option.
PatternState & operator=(PatternState &&other) noexcept=default
Move assignment operator.
const AthMessaging * logger
Logger.
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.
~PatternState()=default
Destructor.
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.