ATLAS Offline Software
Loading...
Searching...
No Matches
MuonR4::FastReco::GlobalPatternFinder::PatternState Struct Reference

Pattern state object storing pattern information during construction. More...

Collaboration diagram for MuonR4::FastReco::GlobalPatternFinder::PatternState:

Public Member Functions

 PatternState (const HitPayload &seed, const uint8_t sectorCoord, const double seedTheta)
 Constructor taking the seed information.
 PatternState ()=delete
 Delete default destructor - ensure patterns are always constructed from a seed or another pattern.
 PatternState (PatternState &&other) noexcept=default
 Move constructor.
PatternStateoperator= (PatternState &&other) noexcept=default
 Move assignment operator.
 PatternState (const PatternState &other)=default
 Copy constructor.
PatternStateoperator= (const PatternState &other)=default
 Copy assignment operator.
 ~PatternState ()=default
 Destructor.
void addHit (const HitPayload &hit, const double residual, const double acceptWindow)
 Add a hit to the pattern and update the internal state.
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 HitPayloadgetNthLastHit (const uint8_t n) const
 Get the n-th last inserted hit.
bool isInPattern (const HitPayload &hit) const
 Check wheter a hit is present in the pattern.
void finalizePatternEta ()
 Finalize the pattern building in eta and update its state.
void finalizePatternPhi ()
 Finalize the pattern building in phi and update its state.
bool operator== (const PatternState &other) const =delete
 Patterns are considered identical if they have the same hit content.
void print (std::ostream &ostr) const
 Print the pattern candidate and stream operator.

Public Attributes

Acts::CloneablePtr< PatternHitVisualInfovisualInfo {nullptr}
 Pointer to Visual Information for pattern visualization.
const SpacePointlastInsertedHit {nullptr}
 Pointer to the last inserted hit.
const SpacePointprevLayerHit {nullptr}
 Pointer to the last hit in the second-to-last layer.
double theta {0.}
 Average theta & average phi of the pattern.
double phi {0.}
double meanNormResidual2 {0.}
 Mean over eta hits of the square of their residual divided by acceptance window.
double lastResidual {0.}
 Residual & acceptance window of the last inserted hit (needed when replacing a hit).
double lastAcceptWindow {0.}
uint8_t nPrecisionHits {0u}
 Counts of precision measurements / non-precision in bending direction / phi measurements.
uint8_t nBendingTriggerHits {0u}
uint8_t nPhiHits {0u}
uint8_t nMissedLayerHits {0u}
 Number of missed candidate hits in different measurement layers during pattern building.
uint8_t sectorCoord {0}
 expanded sector coordinate & the two corresponding physical sectors
uint8_t sector1 {0}
uint8_t sector2 {0}
bool isFinalized {false}
 Flag to indicate if the pattern has been finalized.
bool isOverlap {false}
 Flag to indicate if the pattern is overlapping with another one, used during overlap removal.
std::unordered_map< StIndex, std::vector< HitPayload > > hitsPerStation {}
 Map collection of hits per station.
std::vector< StIndexstations {}
 Pattern hit stations to save the filling order.
BucketPerContainer bucketsPerContainer {}
 Map of spacepoint buckets per spacepoint container associated to the pattern.

Friends

std::ostream & operator<< (std::ostream &ostr, const PatternState &candidate)

Detailed Description

Pattern state object storing pattern information during construction.

Definition at line 175 of file GlobalPatternFinder.h.

Constructor & Destructor Documentation

◆ PatternState() [1/4]

MuonR4::FastReco::GlobalPatternFinder::PatternState::PatternState ( const HitPayload & seed,
const uint8_t sectorCoord,
const double seedTheta )

Constructor taking the seed information.

Parameters
seedseed hit
sectorCoordexpanded sector coordinate
seedThetaglobal theta of the seed

Definition at line 900 of file GlobalPatternFinder.cxx.

903 : lastInsertedHit{seed.hit},
904 prevLayerHit{seed.hit},
905 theta{seedTheta},
909
910 StIndex stationHit {seed.station};
911 hitsPerStation[stationHit].push_back(seed);
912 stations.push_back(stationHit);
913
914 if (seed.isPrecision) nPrecisionHits++;
915 else if (seed->measuresEta()) nBendingTriggerHits++;
916
917 if (seed->measuresPhi()) {
918 phi = seed.phi;
919 nPhiHits++;
920 }
921}
Muon::MuonStationIndex::StIndex StIndex
Type alias for the station index.
static int ringSector(const int sector)
Ensure that the parsed sector number is following the MS sector schema 0 is mapped to 16 and 17 is ma...
double theta
Average theta & average phi of the pattern.
const SpacePoint * lastInsertedHit
Pointer to the last inserted hit.
std::vector< StIndex > stations
Pattern hit stations to save the filling order.
uint8_t nPrecisionHits
Counts of precision measurements / non-precision in bending direction / phi measurements.
std::unordered_map< StIndex, std::vector< HitPayload > > hitsPerStation
Map collection of hits per station.
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() [2/4]

MuonR4::FastReco::GlobalPatternFinder::PatternState::PatternState ( )
delete

Delete default destructor - ensure patterns are always constructed from a seed or another pattern.

◆ PatternState() [3/4]

MuonR4::FastReco::GlobalPatternFinder::PatternState::PatternState ( PatternState && other)
defaultnoexcept

Move constructor.

Parameters
otherother pattern state to move from

◆ PatternState() [4/4]

MuonR4::FastReco::GlobalPatternFinder::PatternState::PatternState ( const PatternState & other)
default

Copy constructor.

Parameters
otherother pattern state to copy from

◆ ~PatternState()

MuonR4::FastReco::GlobalPatternFinder::PatternState::~PatternState ( )
default

Destructor.

Member Function Documentation

◆ addHit()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::addHit ( const HitPayload & hit,
const double residual,
const double acceptWindow )

Add a hit to the pattern and update the internal state.

Parameters
hithit to be added
residualresidual of the hit
acceptWindowacceptance window

Update the pointers to last hit and previous layer hit

Add now the new hit

Reset the number of missed layer hits

Update the hit counts in bending direction

Update the phi of the pattern if there are no phi hits yet

Update the residual. Since we can also add phi-only hits without updating the residual, we need to check the accept window

Definition at line 922 of file GlobalPatternFinder.cxx.

924 {
926 lastInsertedHit = hit.hit;
927 if (const HitPayload& previousHit {getNthLastHit(1u)};
928 checkLayerOrdering(hit, previousHit) != eSameLayer) {
929 prevLayerHit = previousHit.hit;
930 }
932 StIndex stationHit {hit.station};
933 hitsPerStation[stationHit].push_back(hit);
934 if (stations.empty() || stations.back() != stationHit) {
935 stations.push_back(stationHit);
936 }
940 if (hit.isPrecision) nPrecisionHits++;
941 else if (hit->measuresEta()) nBendingTriggerHits++;
943 if (hit->measuresPhi()) {
944 if (nPhiHits == 0) phi = hit.phi;
945 nPhiHits++;
946 }
948 if (acceptWindow > Acts::s_epsilon) {
949 meanNormResidual2 += Acts::square(residual / acceptWindow);
950 lastAcceptWindow = acceptWindow;
952 }
953}
static LayerOrdering checkLayerOrdering(const HitPayload &hit1, const HitPayload &hit2)
Method to check the logical layer ordering of two hits.
double lastResidual
Residual & acceptance window of the last inserted hit (needed when replacing a hit).
double meanNormResidual2
Mean over eta hits of the square of their residual divided by acceptance window.
uint8_t nMissedLayerHits
Number of missed candidate hits in different measurement layers during pattern building.
const HitPayload & getNthLastHit(const uint8_t n) const
Get the n-th last inserted hit.

◆ finalizePatternEta()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::finalizePatternEta ( )

Finalize the pattern building in eta and update its state.

This method is called at the end of pattern building in eta, so we don't have phi-only hits yet

Update the bucket map

Update eta

Definition at line 1006 of file GlobalPatternFinder.cxx.

1006 {
1008 theta = 0.;
1009 for (const auto& [_, hits] : hitsPerStation) {
1010 for (const auto& hit : hits) {
1012 auto& bucketVec {bucketsPerContainer[hit.container]};
1013 if (std::ranges::find(bucketVec, hit.bucket) == bucketVec.end()){
1014 bucketVec.push_back(hit.bucket);
1015 }
1017 theta += atan2(hit.R, hit.Z);
1018 }
1019 }
1020 assert(nPrecisionHits + nBendingTriggerHits > Acts::s_epsilon);
1022}
BucketPerContainer bucketsPerContainer
Map of spacepoint buckets per spacepoint container associated to the pattern.

◆ finalizePatternPhi()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::finalizePatternPhi ( )

Finalize the pattern building in phi and update its state.

If there are no phi hits, we just use the central phi of the sector/overlap region

Definition at line 1023 of file GlobalPatternFinder.cxx.

1023 {
1024 if (!nPhiHits) {
1026 phi = sectorMap.sectorOverlapPhi(sector1, sector2);
1027 return;
1028 }
1029 double deltaPhiAcc {0.};
1030 std::optional<double> centralPhi {};
1031 for (const auto& [_, hits] : hitsPerStation) {
1032 for (const auto& hit : hits) {
1033 if (!hit->measuresPhi()) {
1034 continue;
1035 }
1036 if (!centralPhi) {
1037 centralPhi = hit.phi;
1038 }
1039 deltaPhiAcc += CxxUtils::deltaPhi(hit.phi, *centralPhi);
1040 }
1041 }
1042 phi = CxxUtils::wrapToPi(centralPhi.value_or(0.) + deltaPhiAcc / nPhiHits);
1043}
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:24
T deltaPhi(T phiA, T phiB)
Return difference phiA - phiB in range [-pi, pi].
Definition phihelper.h:42

◆ getNthLastHit()

const GlobalPatternFinder::HitPayload & MuonR4::FastReco::GlobalPatternFinder::PatternState::getNthLastHit ( const uint8_t n) const

Get the n-th last inserted hit.

Parameters
nthe index of the hit to retrieve
Returns
: reference to the n-th last inserted hit

Definition at line 1066 of file GlobalPatternFinder.cxx.

1066 {
1068 // If we have not yet inserted n hits, we return the seed hit
1069 return hitsPerStation.at(stations.front()).front();
1070 }
1071 std::size_t remaining {n};
1072 for (auto stIt = stations.rbegin(); stIt != stations.rend(); ++stIt) {
1073 const std::vector<HitPayload>& hits {hitsPerStation.at(*stIt)};
1074 const size_t nHits {hits.size()};
1075 if (remaining <= nHits) {
1076 return hits.at(nHits - remaining);
1077 }
1078 remaining -= nHits;
1079 }
1080 // Fall-back return, should not happen if the input n is consistent with hit counts
1081 return hitsPerStation.at(stations.front()).front();
1082}
static const uint32_t nHits

◆ isInPattern()

bool MuonR4::FastReco::GlobalPatternFinder::PatternState::isInPattern ( const HitPayload & hit) const

Check wheter a hit is present in the pattern.

Parameters
hithit to be checked
Returns
: boolean indicating if the hit is in the pattern

Definition at line 1083 of file GlobalPatternFinder.cxx.

1083 {
1084 const auto seedStationIt {hitsPerStation.find(hit.station)};
1085 return seedStationIt != hitsPerStation.end() &&
1086 std::ranges::find(seedStationIt->second, hit) != seedStationIt->second.end();
1087}

◆ operator=() [1/2]

PatternState & MuonR4::FastReco::GlobalPatternFinder::PatternState::operator= ( const PatternState & other)
default

Copy assignment operator.

Parameters
otherother pattern state to copy from

◆ operator=() [2/2]

PatternState & MuonR4::FastReco::GlobalPatternFinder::PatternState::operator= ( PatternState && other)
defaultnoexcept

Move assignment operator.

Parameters
otherother pattern state to move from

◆ operator==()

bool MuonR4::FastReco::GlobalPatternFinder::PatternState::operator== ( const PatternState & other) const
delete

Patterns are considered identical if they have the same hit content.

However, map comparison is very expensive

◆ overWriteHit()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::overWriteHit ( const HitPayload & oldHit,
const HitPayload & newHit,
const double newResidual,
const double newAcceptWindow )

Overwrite a hit in the pattern and update the internal state.

Parameters
oldHithit to be replaced
newHitnew hit to replace with
newResidualresidual of the new hit
accepWindowacceptance window of the new hit

MDT hits in the same layer are added with the same residual

Update the phi count and the pattern phi if needed

Update the residual. When we replace a hit, we have always the new residual & accept window, so no checks are needed.

Update the pointers to last hit. Since we overwrite hits in the same layer, prevLayerHit remains unchanged

Definition at line 954 of file GlobalPatternFinder.cxx.

957 {
958 if (oldHit.station != newHit.station) {
959 throw std::runtime_error(std::format("Trying to overwrite a hit in station {} with another one from station {}", stName(oldHit.station), stName(newHit.station)));
960 }
961 // We expect to overwrite hits of the same type (precision/trigger), since we only branch when we have
962 // compatible hits in the same layer, except for sTGC hits, where we have pad and strips in the same layer
963 if ((oldHit.isPrecision != newHit.isPrecision ||
964 oldHit->measuresEta() != newHit->measuresEta()) && newHit->type() != xAOD::UncalibMeasType::sTgcStripType) {
965 std::stringstream ss {"Trying to overwrite a hit with incompatible type\n"};
966 ss << "Old hit: " << *oldHit << ", isPrecision: " << oldHit.isPrecision << ", measuresEta: " << oldHit->measuresEta() << "\n";
967 ss << "New hit: " << *newHit << ", isPrecision: " << newHit.isPrecision << ", measuresEta: " << newHit->measuresEta();
968 throw std::runtime_error(ss.str());
969 }
970 assert(newAcceptWindow > Acts::s_epsilon && lastAcceptWindow > Acts::s_epsilon);
971 StIndex lastStation {oldHit.station};
972 auto it {hitsPerStation.find(lastStation)};
973 if (it == hitsPerStation.end() || lastStation != stations.back()) {
974 throw std::runtime_error("Trying to remove a hit from an invalid station");
975 }
976 std::vector<HitPayload>& hitsInStation {it->second};
977 // Remove ALL hits in the same layer
978 while (!hitsInStation.empty()) {
979 HitPayload& lastHit {hitsInStation.back()};
980 if (checkLayerOrdering(lastHit, oldHit) != eSameLayer) {
981 break;
982 }
983 if (lastHit.isPrecision) nPrecisionHits--;
984 else nBendingTriggerHits--; //This method is called only in pattern building in eta, so we don't have phi-only hits yet
985 if (lastHit->measuresPhi()) nPhiHits--;
986 hitsInStation.pop_back();
989 }
990 // then insert the new hit
991 hitsInStation.push_back(newHit);
992 if (newHit.isPrecision) nPrecisionHits++;
993 else nBendingTriggerHits++; //This method is called only in pattern building in eta, so we don't have phi-only hits yet
995 if (newHit->measuresPhi()) {
996 if (nPhiHits == 0) phi = newHit.phi;
997 nPhiHits++;
998 }
1000 meanNormResidual2 += Acts::square(newResidual / newAcceptWindow);
1001 lastResidual = newResidual;
1002 lastAcceptWindow = newAcceptWindow;
1004 lastInsertedHit = newHit.hit;
1005}
static Double_t ss
const std::string & stName(StIndex index)
convert StIndex into a string

◆ print()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::print ( std::ostream & ostr) const

Print the pattern candidate and stream operator.

Definition at line 1106 of file GlobalPatternFinder.cxx.

1106 {
1107 ostr<<"Pattern state, Expanded Sector: "<<sectorCoord<<", Theta: "<<theta << ", Phi: "<<phi;
1108 ostr<<", nPrecisionHits: "<<nPrecisionHits<<", nEtaNonPrecisionHits: "<<nBendingTriggerHits<<", nPhiHits: "<<nPhiHits;
1109 ostr<<", mean normalized residual squared: "<<meanNormResidual2;
1110 ostr<<", Hit per station: \n";
1111 for (const auto& [station,hits] : hitsPerStation) {
1112 ostr<<" Station "<<Muon::MuonStationIndex::stName(station)<<" has "<<hits.size()<<" hits\n";
1113 for (const auto& hit : hits) {
1114 ostr<<" "<<*hit<<", R: "<<hit.R<<", Phi:"<<hit.phi<<"\n";
1115 }
1116 }
1117}

◆ operator<<

std::ostream & operator<< ( std::ostream & ostr,
const PatternState & candidate )
friend

Definition at line 269 of file GlobalPatternFinder.h.

269 {
270 candidate.print(ostr);
271 return ostr;
272 }

Member Data Documentation

◆ bucketsPerContainer

BucketPerContainer MuonR4::FastReco::GlobalPatternFinder::PatternState::bucketsPerContainer {}

Map of spacepoint buckets per spacepoint container associated to the pattern.

Definition at line 263 of file GlobalPatternFinder.h.

263{};

◆ hitsPerStation

std::unordered_map<StIndex, std::vector<HitPayload> > MuonR4::FastReco::GlobalPatternFinder::PatternState::hitsPerStation {}

Map collection of hits per station.

A pattern is determined by the hits belonging to it.

Definition at line 258 of file GlobalPatternFinder.h.

258{};

◆ isFinalized

bool MuonR4::FastReco::GlobalPatternFinder::PatternState::isFinalized {false}

Flag to indicate if the pattern has been finalized.

Definition at line 253 of file GlobalPatternFinder.h.

253{false};

◆ isOverlap

bool MuonR4::FastReco::GlobalPatternFinder::PatternState::isOverlap {false}

Flag to indicate if the pattern is overlapping with another one, used during overlap removal.

Definition at line 255 of file GlobalPatternFinder.h.

255{false};

◆ lastAcceptWindow

double MuonR4::FastReco::GlobalPatternFinder::PatternState::lastAcceptWindow {0.}

Definition at line 241 of file GlobalPatternFinder.h.

241{0.};

◆ lastInsertedHit

const SpacePoint* MuonR4::FastReco::GlobalPatternFinder::PatternState::lastInsertedHit {nullptr}

Pointer to the last inserted hit.

Needed to speed-up lookup

Definition at line 231 of file GlobalPatternFinder.h.

231{nullptr};

◆ lastResidual

double MuonR4::FastReco::GlobalPatternFinder::PatternState::lastResidual {0.}

Residual & acceptance window of the last inserted hit (needed when replacing a hit).

Definition at line 240 of file GlobalPatternFinder.h.

240{0.};

◆ meanNormResidual2

double MuonR4::FastReco::GlobalPatternFinder::PatternState::meanNormResidual2 {0.}

Mean over eta hits of the square of their residual divided by acceptance window.

Definition at line 238 of file GlobalPatternFinder.h.

238{0.};

◆ nBendingTriggerHits

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nBendingTriggerHits {0u}

Definition at line 244 of file GlobalPatternFinder.h.

244{0u};
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77

◆ nMissedLayerHits

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nMissedLayerHits {0u}

Number of missed candidate hits in different measurement layers during pattern building.

Definition at line 247 of file GlobalPatternFinder.h.

247{0u};

◆ nPhiHits

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nPhiHits {0u}

Definition at line 245 of file GlobalPatternFinder.h.

245{0u};

◆ nPrecisionHits

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nPrecisionHits {0u}

Counts of precision measurements / non-precision in bending direction / phi measurements.

Definition at line 243 of file GlobalPatternFinder.h.

243{0u};

◆ phi

double MuonR4::FastReco::GlobalPatternFinder::PatternState::phi {0.}

Definition at line 236 of file GlobalPatternFinder.h.

236{0.};

◆ prevLayerHit

const SpacePoint* MuonR4::FastReco::GlobalPatternFinder::PatternState::prevLayerHit {nullptr}

Pointer to the last hit in the second-to-last layer.

Definition at line 233 of file GlobalPatternFinder.h.

233{nullptr};

◆ sector1

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::sector1 {0}

Definition at line 250 of file GlobalPatternFinder.h.

250{0};

◆ sector2

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::sector2 {0}

Definition at line 251 of file GlobalPatternFinder.h.

251{0};

◆ sectorCoord

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::sectorCoord {0}

expanded sector coordinate & the two corresponding physical sectors

Definition at line 249 of file GlobalPatternFinder.h.

249{0};

◆ stations

std::vector<StIndex> MuonR4::FastReco::GlobalPatternFinder::PatternState::stations {}

Pattern hit stations to save the filling order.

Stations can be repeated when we invert the search direction (e.g. from seed ourward -> BM BO, then from seed inward BM BI)

Definition at line 261 of file GlobalPatternFinder.h.

261{};

◆ theta

double MuonR4::FastReco::GlobalPatternFinder::PatternState::theta {0.}

Average theta & average phi of the pattern.

Definition at line 235 of file GlobalPatternFinder.h.

235{0.};

◆ visualInfo

Acts::CloneablePtr<PatternHitVisualInfo> MuonR4::FastReco::GlobalPatternFinder::PatternState::visualInfo {nullptr}

Pointer to Visual Information for pattern visualization.

Definition at line 229 of file GlobalPatternFinder.h.

229{nullptr};

The documentation for this struct was generated from the following files: