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

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

#include <GlobalPatternFinderDefs.h>

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

Public Member Functions

 PatternState (const CandidateHit &seed, const std::int8_t expSector, const Config *cfg, const Acts::Logger *logger)
 Constructor taking the seed information.
 PatternState (PatternState &&other) noexcept=default
 Move constructor.
PatternState & operator= (PatternState &&other) noexcept=default
 Move assignment operator.
 PatternState (const PatternState &other)=default
 Copy constructor.
PatternState & operator= (const PatternState &other)=default
 Copy assignment operator.
 ~PatternState ()=default
 Destructor.
void addHit (const CandidateHit &hit, const double residual, const double resSigma)
 Add a hit to the pattern and update the internal state.
void overWriteHit (const CandidateHit &newHit, const double newResidual, const double newResSigma)
 Overwrite the hits on the last layer with the new one.
LineTestRes checkLineComp (const Acts::GeometryContext &gctx, const CandidateHit &testHit, const Amg::Vector3D &beamSpot)
 Method checking line compatibility of a test hit against the pattern.
LineTestRes computeLineResidual (const Acts::GeometryContext &gctx, const CandidateHit &testHit) const
 Method to compute the residual of a test hit against the pattern line.
Amg::Vector3D projToPhiPlane (const Acts::GeometryContext &gctx, const HitPayload &hit) const
 Project a certain hit position onto the bending plane where the pattern is defined.
bool isPhiCompatible (const HitPayload &hit) const
 Method to check the phi compatibility of a test hit with a given pattern.
bool isInPattern (const HitPayload &hit) const
 Check wheter a hit is present in the pattern.
void moveLineAnchorHit (const CandidateHit &refHit)
 Move the line anchor hit given a reference hit.
void updateLineParameters (const Acts::GeometryContext &gctx, const Amg::Vector3D &beamSpot)
 Update the line parameters based on the current hits.
void updatePatternPhi ()
 Helper method to update the pattern phi and bending plane normal.
double getMeanResidual2 () const
 Return the mean normalized residual squared.
uint8_t nBendingLayers () const
 Return the number of layers in bending coordinate.
uint8_t nStations (const bool onlyGoodStations) const
 Method returning the number of stations.
std::vector< const SpacePointBucket * > getParentBuckets () const
 Get the buckets associated with the pattern.
const Acts::Logger & logger () const
 Return the logger.
bool operator== (const PatternState &other) const =delete
 Patterns are considered identical if they have the same hit content.
void print (std::ostream &ostr, bool detailed) const
 Print the pattern candidate.

Public Attributes

const Config * cfg {nullptr}
 Pointer to cfg option.
const Acts::Logger * m_logger {nullptr}
 Logger.
Acts::CloneablePtr< PatHitVisual > visualInfo {nullptr}
 Pointer to Visual Information for pattern visualization.
CandidateHit lastInsertedHit {}
 Last inserted hit.
CandidateHit prevLayerHit {}
 Last hit in the second-to-last layer.
CandidateHit lineAnchorHit {}
 Line anchor hit.
Amg::Vector3D bendPlaneNorm {Amg::Vector3D::Zero()}
 Normal vector to the bending plane where the pattern lies.
Amg::Vector3D linePos {Amg::Vector3D::Zero()}
 Position and direction of the pattern line.
Amg::Vector3D lineDir {Amg::Vector3D::Zero()}
double leverArm {0.}
 Distance between the two points defining the pattern line.
double meanNormResidual2 {0.}
 Mean over eta hits of the square of their residual divided by residual uncertainty.
double lastResidual {0.}
 Residual & residual uncertainty of the last inserted hit (needed when replacing a hit).
double lastResSigma {0.}
double patPhi {0.}
 Pattern phi, which is the phi of the bending plane where the pattern lies.
double patTheta {0.}
 Pattern theta, which is the value of the seed hit.
double patPhiCov {0.}
 Covariance of the pattern phi.
ExpandedSector expSect {static_cast<int8_t>(0)}
 expanded MS sector
uint8_t nPrecisionLayers {0u}
 Counts of precision / non-precision / phi layers.
uint8_t nTriggerLayers {0u}
uint8_t nPhiLayers {0u}
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.
bool useBeamspot {false}
 Whether we used the beamspot to compute the line parameters.
bool needLineUpdate {false}
 Whether we need to update the pattern line the next time we find a hit in a new layer.
std::array< std::vector< CandidateHit >, s_nStations > hitsPerStation {}
 Map collection of hits per station.
std::vector< HitPayload > phiOnlyHits {}
 Array holding phi-only hits.

Detailed Description

Pattern state object storing pattern information during construction.

Definition at line 114 of file GlobalPatternFinderDefs.h.

Constructor & Destructor Documentation

◆ PatternState() [1/3]

MuonR4::FastReco::GlobalPatternFinder::PatternState::PatternState ( const CandidateHit & seed,
const std::int8_t expSector,
const Config * cfg,
const Acts::Logger * logger )
explicit

Constructor taking the seed information.

Parameters
seedseed hit
expSectorexpanded sector coordinate
cfgpointer to configuration object
loggerpointer to messaging object

Add the new hit

Update the hit counts

Definition at line 152 of file GlobalPatternFinderDefs.cxx.

156 : cfg{cfg},
161 patTheta{seed->position.theta()},
162 expSect{ExpandedSector{expSector}} {
163
165 hitsPerStation[Acts::toUnderlying(seed->station)].push_back(seed);
166
168 if (seed->isPrecision) nPrecisionLayers++;
169 else nTriggerLayers++;
170
171 if (seed.sp()->measuresPhi()) nPhiLayers++;
172
174 needLineUpdate = true;
175 }
bool needLineUpdate
Whether we need to update the pattern line the next time we find a hit in a new layer.
CandidateHit prevLayerHit
Last hit in the second-to-last layer.
std::array< std::vector< CandidateHit >, s_nStations > hitsPerStation
Map collection of hits per station.
void updatePatternPhi()
Helper method to update the pattern phi and bending plane normal.
const Acts::Logger & logger() const
Return the logger.
uint8_t nPrecisionLayers
Counts of precision / non-precision / phi layers.
double patTheta
Pattern theta, which is the value of the seed hit.

◆ PatternState() [2/3]

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

Move constructor.

Parameters
otherother pattern state to move from

◆ PatternState() [3/3]

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 CandidateHit & hit,
const double residual,
const double resSigma )

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

Parameters
hithit to be added
residualresidual of the hit
resSigmaresidual uncertainty of the hit

Add the new hit

Update the hit counts

Update the pointers to previous layer hit

If the new compatible hit is in a different station, update the line anchor

Definition at line 442 of file GlobalPatternFinderDefs.cxx.

444 {
446 hitsPerStation[Acts::toUnderlying(hit->station)].push_back(hit);
447
449 if (hit->isPrecision) nPrecisionLayers++;
450 else nTriggerLayers++;
451
452 if (hit.sp()->measuresPhi()) {
453 nPhiLayers++;
455 }
456
458 const bool isNewStation {hit->station != lastInsertedHit->station};
461
462 meanNormResidual2 += Acts::square(residual / resSigma);
463 lastResSigma = resSigma;
465
467 if (isNewStation) {
469 }
470 needLineUpdate = true;
471 }
bool hit(const Container &ids, int pdgId)
void moveLineAnchorHit(const CandidateHit &refHit)
Move the line anchor hit given a reference hit.
double lastResidual
Residual & residual uncertainty of the last inserted hit (needed when replacing a hit).
double meanNormResidual2
Mean over eta hits of the square of their residual divided by residual uncertainty.

◆ checkLineComp()

LineTestRes MuonR4::FastReco::GlobalPatternFinder::PatternState::checkLineComp ( const Acts::GeometryContext & gctx,
const CandidateHit & testHit,
const Amg::Vector3D & beamSpot )

Method checking line compatibility of a test hit against the pattern.

Parameters
testHittest hit information
beamSpotBeam spot position, needed to update the pattern line
Returns
: result of the test, including the computed line residual and acceptance window

Helper function to make the result

Parameters
decisionThe decision for the test result if the residual is within the acceptance window
Returns
The test result

Loosen the window when we use the beamspot or when we are looking for hits in a new station, as the straight line approximation becomes less accurate on large distances. TO DO: investigate this further

Definition at line 176 of file GlobalPatternFinderDefs.cxx.

178 {
179
180 if (testHit.sp()->measuresPhi() && !isPhiCompatible(*testHit)) {
181 ACTS_VERBOSE(__func__<<"() Test hit phi "<<testHit->position.phi()
182 <<" not compatible with "<<brief(*this));
183 return LineTestRes{};
184 }
185
189 auto makeResult = [&](const LineTestDecision decision) -> LineTestRes {
190 LineTestRes res{computeLineResidual(gctx, testHit)};
191 double accWindow {cfg->nResidualSigma * res.sigma};
194 if (useBeamspot || testHit->station != lastInsertedHit->station ||
195 (testHit->station != prevLayerHit->station && testHit.globLayer == lastInsertedHit.globLayer)) {
196 accWindow *= 2.;
197 }
198 if (res.residual < accWindow) {
199 res.result = decision;
200 }
201 if (visualInfo) {
202 visualInfo->hitLineInfo[testHit.sp()] =
203 std::make_pair(std::tan(lineDir.theta()), accWindow);
204 }
205 return res;
206 };
207
208 if(testHit.globLayer != lastInsertedHit.globLayer) {
209 updateLineParameters(gctx, beamSpot);
210 return makeResult(LineTestDecision::eAddHit);
211 }
212 if (testHit == lastInsertedHit) {
213 ACTS_VERBOSE(__func__<<"() Test hit is the same as last inserted hit - reject.");
214 return LineTestRes{};
215 }
216 if (lineAnchorHit.globLayer == lastInsertedHit.globLayer) {
217 ACTS_VERBOSE(__func__<<"() Test hit on same layer as seed with no prior hits - reject.");
218 return LineTestRes{};
219 }
220 return makeResult(LineTestDecision::eBranchPattern);
221 }
std::pair< std::vector< unsigned int >, bool > res
static PatternPrintView brief(const PatternState &p)
Print the pattern state with brief information.
LineTestDecision
: Enum for possible outcomes of pattern line compatibility test
@ eBranchPattern
Test successfull with multiple pattern hits on same layer, branch the pattern.
@ eAddHit
Test successfull, add hit to pattern.
void updateLineParameters(const Acts::GeometryContext &gctx, const Amg::Vector3D &beamSpot)
Update the line parameters based on the current hits.
bool useBeamspot
Whether we used the beamspot to compute the line parameters.
Acts::CloneablePtr< PatHitVisual > visualInfo
Pointer to Visual Information for pattern visualization.
bool isPhiCompatible(const HitPayload &hit) const
Method to check the phi compatibility of a test hit with a given pattern.
LineTestRes computeLineResidual(const Acts::GeometryContext &gctx, const CandidateHit &testHit) const
Method to compute the residual of a test hit against the pattern line.

◆ computeLineResidual()

LineTestRes MuonR4::FastReco::GlobalPatternFinder::PatternState::computeLineResidual ( const Acts::GeometryContext & gctx,
const CandidateHit & testHit ) const

Method to compute the residual of a test hit against the pattern line.

Parameters
testHittest hit information
Returns
: Test result holding the residual and acceptance window. The decision is set later.

We project the test hit onto the phi plane only when the test hit does not measure phi or when we have no phi layers, otherwise we do not project so the residual include the error in the phi direction.

If the residual is very small, it's likely due to bad topology, reject it.

Alpha represents the extrapolation distance along the pattern line

Accumulate the derivatives of the scalar residual with respect to the common phi-plane angle.

Accumulate the covariance contributions of the hits to the residual

Accumulate the covariance contributions of one hit to the residual. Each hit contributes with its intrinsic covariance and, if projected,
with the uncertainty in the common phi-plane angle of the pattern.

Intrinsic covariance: for a projected hit, the residual direction is
transformed with the projection jacobian J^T * dir. dir^T * J * cov * J^T * dir = (J^T * dir)^T * cov * (J^T * dir)

Phi plane uncertainty: for a projected hit, the derivative of the scalar
residual with respect to the common phi-plane angle for the projected hits.

Parameters
hitthe hit for which to compute the covariance
isProjectedflag indicating if the hit is projected
posprojected position (needed for the phi-plane derivative of projected hits)
preFactorfactor, function of alpha, to scale the covariance contributions

Compute the covariance contributions of the first line point

Compute the covariance contributions of the second line point

Compute the covariance contributions of the test hit

Definition at line 272 of file GlobalPatternFinderDefs.cxx.

273 {
274 LineTestRes res{};
275
279 const bool projectTestHit {!testHit.sp()->measuresPhi() || nPhiLayers == 0u};
280 const Amg::Vector3D testPos {projectTestHit ? projToPhiPlane(gctx,*testHit)
281 : testHit->position};
282 const Amg::Vector3D K {testPos - linePos};
283 const double KdotD {K.dot(lineDir)};
284
285 const Amg::Vector3D R {K - KdotD * lineDir}; // Residual vector
286 res.residual = R.mag();
287 if (res.residual < Acts::s_epsilon) {
289 res.residual = std::numeric_limits<double>::max();
290 res.sigma = 0.;
291 return res;
292 }
293 const Amg::Vector3D resDir {R / res.residual}; // Residual direction
295 const double alpha {KdotD / leverArm};
296
298 double phiPlaneDerivativeAcc {0.};
300 double residualCovAcc {0.};
301
317 auto covarianceTerm = [&](const HitPayload& hit,
318 const Amg::Vector3D& pos,
319 const double preFactor,
320 bool isProjected) -> void {
321
322 if (!isProjected) {
323 residualCovAcc += Acts::square(preFactor) *
324 hit.residualVariance(gctx, resDir, /*isProjected=*/false);
325 return;
326 }
327 const Amg::Vector3D sensorDir {hit.sensorDir(gctx)};
328 const double projFactor {sensorDir.dot(resDir) /
329 sensorDir.dot(bendPlaneNorm)};
330 const Amg::Vector3D trfDir {resDir - projFactor * bendPlaneNorm};
331
332 residualCovAcc += Acts::square(preFactor)
333 * hit.residualVariance(gctx, trfDir, /*isProjected=*/true);
334 phiPlaneDerivativeAcc += preFactor * pos.perp() * projFactor;
335 };
336
338 if (useBeamspot) {
339 const double covS1 = cfg->beamSpotLength * Acts::square(resDir.z()) +
340 cfg->beamSpotRadius * (1 - Acts::square(resDir.z()));
341 residualCovAcc += Acts::square(alpha - 1) * covS1;
342 } else {
343 covarianceTerm(*lineAnchorHit, linePos, alpha - 1, /*isProjected=*/true);
344 }
345
347 const Amg::Vector3D pos2 {linePos + leverArm * lineDir};
348 covarianceTerm(*lastInsertedHit, pos2, -alpha, /*isProjected=*/true);
349
351 covarianceTerm(*testHit, testPos, 1., projectTestHit);
352
353 res.sigma = std::sqrt(residualCovAcc + Acts::square(phiPlaneDerivativeAcc) * patPhiCov);
354
355 ACTS_VERBOSE(__func__<<"() "<< brief(*this)<<"\nUse beamspot: "<<useBeamspot
356 <<", alpha: "<<alpha<<", Residual: "<<res.residual<<" +- "<<res.sigma
357 <<", linePos R/theta: "<<linePos.perp()<<" / "<<inDeg(linePos.theta())
358 <<", lineDir theta: "<<inDeg(lineDir.theta())
359 <<", testPos R/theta/phi: "<<testPos.perp()<<" / "<<inDeg(testPos.theta())<<" / "<<inDeg(testPos.phi())
360 <<", resDir theta/phi: "<<inDeg(resDir.theta())<<" / "<<inDeg(resDir.phi())
361 <<", hit pos sigma: "<<std::sqrt(residualCovAcc)
362 <<", phi plane sigma: "<<std::abs(phiPlaneDerivativeAcc)*std::sqrt(patPhiCov));
363 return res;
364 }
Eigen::Matrix< double, 3, 1 > Vector3D
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
constexpr float inDeg(const float rad)
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
Amg::Vector3D projToPhiPlane(const Acts::GeometryContext &gctx, const HitPayload &hit) const
Project a certain hit position onto the bending plane where the pattern is defined.
Amg::Vector3D linePos
Position and direction of the pattern line.
double leverArm
Distance between the two points defining the pattern line.
Amg::Vector3D bendPlaneNorm
Normal vector to the bending plane where the pattern lies.

◆ getMeanResidual2()

double MuonR4::FastReco::GlobalPatternFinder::PatternState::getMeanResidual2 ( ) const

Return the mean normalized residual squared.

Definition at line 558 of file GlobalPatternFinderDefs.cxx.

558 {
559 if (isFinalized) {
560 return meanNormResidual2;
561 }
563 }
bool isFinalized
Flag to indicate if the pattern has been finalized.
uint8_t nBendingLayers() const
Return the number of layers in bending coordinate.

◆ getParentBuckets()

std::vector< const SpacePointBucket * > MuonR4::FastReco::GlobalPatternFinder::PatternState::getParentBuckets ( ) const

Get the buckets associated with the pattern.

Definition at line 565 of file GlobalPatternFinderDefs.cxx.

565 {
566 std::vector<const SpacePointBucket*> buckets{};
567 for (const std::vector<CandidateHit>& hits : hitsPerStation) {
568 for (const auto& hit : hits) {
569 if (std::ranges::find(buckets, hit->bucket) == buckets.end()) {
570 buckets.push_back(hit->bucket);
571 }
572 }
573 }
574 return buckets;
575 }

◆ 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 539 of file GlobalPatternFinderDefs.cxx.

539 {
540 const auto& hits {hitsPerStation[Acts::toUnderlying(hit.station)]};
541 return std::ranges::find_if(hits,
542 [&hit](const CandidateHit& c){ return *c == hit; }) != hits.end();
543 }

◆ isPhiCompatible()

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

Method to check the phi compatibility of a test hit with a given pattern.

Parameters
hithit to be checked
Returns
: true if the test hit is phi compatible with the pattern, false otherwise

We check that the test hit is compatible with the pattern phi, if available, which is given by the first phi measurement in the pattern. If the pattern doesn't have a phi yet, we check that the test hit is in the same pattern sector(s)

Definition at line 415 of file GlobalPatternFinderDefs.cxx.

415 {
419 const double testPhi {hit.position.phi()};
420 if (nPhiLayers) {
421 const double deltaPhiSigma {std::sqrt(patPhiCov + hit.phiCov)};
422 const double deltaPhi {P4Helpers::deltaPhi(patPhi, testPhi)};
423 if (std::abs(deltaPhi) > cfg->nPhiSigma * deltaPhiSigma) {
424 ACTS_VERBOSE(__func__<<"() The pattern with phi = "<<inDeg(patPhi)<<" +- "<<inDeg(std::sqrt(patPhiCov))
425 <<" is not compatible with the test hit with phi "<<inDeg(testPhi) <<" +- "<<inDeg(std::sqrt(hit.phiCov)));
426 return false;
427 }
428 } else {
429 const unsigned sector1 {expSect.msSector()};
430 const unsigned sector2 {expSect.adjacentMsSector()};
431 const bool isCompatible {sector1 == sector2
432 ? sectorMap.insideSector(sector1, testPhi)
433 : sectorMap.insideSector(sector1, testPhi) && sectorMap.insideSector(sector2, testPhi)};
434 if (!isCompatible) {
435 ACTS_VERBOSE(__func__<<"() The test hit with phi = "<<inDeg(testPhi)
436 <<" is not inside the pattern sectors: "<<sector1<<" and "<<sector2);
437 return false;
438 }
439 }
440 return true;
441 }
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34
double patPhi
Pattern phi, which is the phi of the bending plane where the pattern lies.

◆ logger()

const Acts::Logger & MuonR4::FastReco::GlobalPatternFinder::PatternState::logger ( ) const
inline

Return the logger.

Definition at line 200 of file GlobalPatternFinderDefs.h.

200 {
201 return *m_logger;
202 }

◆ moveLineAnchorHit()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::moveLineAnchorHit ( const CandidateHit & refHit)

Move the line anchor hit given a reference hit.

The anchor is defined as the closest hit in the closest station to the referece hit,

Definition at line 222 of file GlobalPatternFinderDefs.cxx.

222 {
223 // Treat first the special case where we have only one station
224 if (nStations(/*onlyGoodStations=*/ false) < 2) {
225 // If we call this method with only one station, it means that we inverted the hit search direction without
226 // finding any hit in other stations beside the initial one. So the anchor is the last added hit.
228 return;
229 }
230 // Find first the closest station to the reference station among the pattern stations
231 const auto& closestStIt = std::ranges::min_element(hitsPerStation, std::ranges::less{},
232 [&refHit](const auto& hits){
233 if (hits.empty() || hits.front()->station == refHit->station) {
234 return std::numeric_limits<int>::max();
235 }
236 return std::abs(hits.front().globLayer - refHit.globLayer);
237 });
238
239 // Then find the closest hit in that station to the reference hit
240 const auto& hits {*closestStIt};
241 lineAnchorHit = *std::ranges::min_element(hits, std::ranges::less{},
242 [&refHit](const CandidateHit& hit){
243 return std::abs(hit.globLayer - refHit.globLayer); });
244 }
uint8_t nStations(const bool onlyGoodStations) const
Method returning the number of stations.

◆ nBendingLayers()

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nBendingLayers ( ) const

Return the number of layers in bending coordinate.

Definition at line 555 of file GlobalPatternFinderDefs.cxx.

555 {
557 }

◆ nStations()

uint8_t MuonR4::FastReco::GlobalPatternFinder::PatternState::nStations ( const bool onlyGoodStations) const

Method returning the number of stations.

Parameters
onlyGoodStationsflag to indicate if only good stations should be counted, i.e. having a minimum number of hits

Definition at line 544 of file GlobalPatternFinderDefs.cxx.

544 {
546 for (uint8_t st{0u}; st < s_nStations; ++st) {
547 const auto& hits {hitsPerStation[st]};
548 if (!hits.empty() &&
549 (!onlyGoodStations || hits.size() >= cfg->minStationLayers)) {
550 nStations++;
551 }
552 }
553 return nStations;
554 }
static const int s_nStations
Number of stations.

◆ 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 CandidateHit & newHit,
const double newResidual,
const double newResSigma )

Overwrite the hits on the last layer with the new one.

Parameters
newHitnew hit to replace with
newResidualresidual of the new hit
newResSigmaresidual uncertainty of the new hit
beamSpotneeded to update line parameters

Update the phi counts

Update the residual

Remove the last inserted hit

Add the new hit

Definition at line 472 of file GlobalPatternFinderDefs.cxx.

474 {
475 const StIndex st {newHit->station};
476 if (st != lastInsertedHit->station || lastInsertedHit.globLayer != newHit.globLayer) {
477 throw std::runtime_error(std::format(
478 "Trying to overwrite a hit in station/layer {}/{} with another one from station/layer {}/{}",
479 stName(lastInsertedHit->station), lastInsertedHit.globLayer, stName(st), newHit.globLayer));
480 }
481 /* We expect to overwrite hits of the same type (precision/trigger), since we only branch when we have
482 * compatible hits in the same layer, except for sTGC hits, where we have pad and strips in the same layer */
483 if (lastInsertedHit->isPrecision != newHit->isPrecision) {
484 if (newHit.sp()->type() != xAOD::UncalibMeasType::sTgcStripType) {
485 std::stringstream ss {};
486 ss << "Trying to overwrite a hit with incompatible type\n";
487 ss << "Old hit: " << **lastInsertedHit << ", isPrecision: " << lastInsertedHit->isPrecision << ", measuresEta: " << lastInsertedHit.sp()->measuresEta() << "\n";
488 ss << "New hit: " << **newHit << ", isPrecision: " << newHit->isPrecision << ", measuresEta: " << newHit.sp()->measuresEta();
489 throw std::runtime_error(ss.str());
490 }
491 if (newHit->isPrecision) {
494 } else {
497 }
498 }
500 bool updatePhi {false};
501 if (lastInsertedHit.sp()->measuresPhi()) {
502 nPhiLayers--;
503 updatePhi = true;
504 }
505 if (newHit.sp()->measuresPhi()) {
506 nPhiLayers++;
507 updatePhi = true;
508 }
510 meanNormResidual2 += Acts::square(newResidual / newResSigma) -
511 Acts::square(lastResidual / lastResSigma);
512 lastResSigma = newResSigma;
513 lastResidual = newResidual;
514
516 if (visualInfo) {
517 visualInfo->replacedHits.push_back(lastInsertedHit.sp());
518 }
519 auto& stHits {hitsPerStation[Acts::toUnderlying(st)]};
520 if (stHits.back() != lastInsertedHit) {
521 std::stringstream ss {};
522 ss << "Trying to overwrite a hit that is not the last inserted hit in station/layer "
523 << stName(st) << "/" << lastInsertedHit.globLayer << "\n";
524 ss << "Last inserted hit: " << **lastInsertedHit << "\n";
525 ss << "Last hit in station: " << **stHits.back();
526 throw std::runtime_error(ss.str());
527 }
528 stHits.pop_back();
529
531 stHits.push_back(newHit);
532 lastInsertedHit = newHit;
533
534 if (updatePhi) {
536 }
537 needLineUpdate = true;
538 }
static Double_t ss
Muon::MuonStationIndex::StIndex StIndex
Type alias for the station index.
const std::string & stName(StIndex index)
convert StIndex into a string

◆ print()

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

Print the pattern candidate.

Definition at line 576 of file GlobalPatternFinderDefs.cxx.

576 {
577 ostr<<"PatternState Exp Sector: "<<static_cast<int>(expSect.sector())
578 <<", Theta: "<<inDeg(patTheta) << ", Phi: "<<inDeg(patPhi)<<" +- "<<inDeg(std::sqrt(patPhiCov));
579 ostr<<", nPrec: "<<static_cast<int>(nPrecisionLayers)<<", nEtaNonPrec: "
580 <<static_cast<int>(nTriggerLayers)<<", nPhi: "<<static_cast<int>(nPhiLayers);
581 ostr<<", mean norma res sq: "<<getMeanResidual2()<<", dirTheta: "<<inDeg(lineDir.theta());
582 ostr<<", Hit per station: \n";
583 for (uint8_t st{0u}; st < s_nStations; ++st) {
584 const auto& hits {hitsPerStation[st]};
585 if (hits.empty()) continue;
586
587 ostr<<" Station "<<static_cast<StIndex>(st)<<" has "<<hits.size()<<" hits ";
588 if (detailed) {
589 ostr<<"\n";
590 for (const auto& hit : hits) {
591 ostr<<" "<<hit<<"\n";
592 }
593 }
594 }
595 if (!detailed) {
596 ostr <<"\n Last hit: "<<lastInsertedHit<<"\n prevLayerHit: "
597 <<prevLayerHit << "\n lineAnchorHit: "<<lineAnchorHit;
598 }
599 }
static PatternPrintView detailed(const PatternState &p)
Print the pattern state with detailed information.
double getMeanResidual2() const
Return the mean normalized residual squared.

◆ projToPhiPlane()

Amg::Vector3D MuonR4::FastReco::GlobalPatternFinder::PatternState::projToPhiPlane ( const Acts::GeometryContext & gctx,
const HitPayload & hit ) const

Project a certain hit position onto the bending plane where the pattern is defined.

The hit is moved along the sensor direction if it does not measure phi, or is rotated around the Z axis if it does.

Parameters
hithit whose position is to be projected
Returns
: projected position

Definition at line 365 of file GlobalPatternFinderDefs.cxx.

366 {
367 return Acts::PlanarHelper::intersectPlane(hit.position, hit.sensorDir(gctx),
368 bendPlaneNorm, Amg::Vector3D::Zero()).position();
369 }

◆ updateLineParameters()

void MuonR4::FastReco::GlobalPatternFinder::PatternState::updateLineParameters ( const Acts::GeometryContext & gctx,
const Amg::Vector3D & beamSpot )

Update the line parameters based on the current hits.

Parameters
beamSpotposition of the beam spot, needed when there are not enough hits

Check whether we have to use the beamspot instead of the anchor hit to draw the line.

Definition at line 245 of file GlobalPatternFinderDefs.cxx.

246 {
247 if (!needLineUpdate) {
248 return;
249 }
252 Amg::Vector3D d {pos2 - pos1};
253 leverArm = d.mag();
254
256 useBeamspot = (lastInsertedHit->station == lineAnchorHit->station) &&
257 leverArm < cfg->minHitDistance4Line;
258 if (useBeamspot) {
260 d = pos2 - beamSpot;
261 leverArm = d.mag();
262 } else {
263 linePos = pos1;
264 }
265 lineDir = d / leverArm;
266 needLineUpdate = false;
267
268 ACTS_VERBOSE(__func__<<"() Updated --> linePos R/z/theta: "<<linePos.perp()<<" / "<<linePos.z()
269 <<" / "<<inDeg(linePos.theta())<<", lineDir theta: "<<inDeg(lineDir.theta())
270 <<", LeverArm: "<<leverArm<<", Use beamspot: "<<useBeamspot);
271 }
AthConfigFlags beamSpot(AthConfigFlags flags, str instanceName, str recoMode)

◆ updatePatternPhi()

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

Helper method to update the pattern phi and bending plane normal.

If there are no phi hits, we just use the central phi of the sector/overlap region, with a standard deviation based on the expanded sector size.

Definition at line 370 of file GlobalPatternFinderDefs.cxx.

370 {
371 if (!nPhiLayers) {
374 patPhi = sectorMap.sectorOverlapPhi(expSect.msSector(),
375 expSect.adjacentMsSector());
376 patPhiCov = Acts::square(expSect.sectorSize()) / 3.;
377 bendPlaneNorm = Acts::makeDirectionFromPhiTheta(patPhi + 90._degree, 90._degree);
378 ACTS_VERBOSE(__func__<<"() No phi hits in the pattern, set pattern phi to "
379 <<inDeg(patPhi)<<" +- "<<inDeg(std::sqrt(patPhiCov)));
380 return;
381 }
382 double sumSin{0.}, sumCos{0.}, sumWeight{0.};
383
384 auto processPhiHit = [&sumSin, &sumCos, &sumWeight](const HitPayload& hit){
385 if (!hit->measuresPhi()) {
386 return;
387 }
388 if (hit.phiCov < Acts::s_epsilon) {
389 std::stringstream ss {};
390 ss << "Unexpected to have a phi hit with zero variance in phi direction: " << *hit.spacePoint << "\n";
391 throw std::runtime_error(ss.str());
392 }
393 const double w = 1./hit.phiCov;
394
395 const double phi {hit.position.phi()};
396 sumSin += w * std::sin(phi);
397 sumCos += w * std::cos(phi);
398 sumWeight += w;
399 };
400 for (const std::vector<CandidateHit>& hits : hitsPerStation) {
401 for (const auto& hit : hits) {
402 processPhiHit(*hit);
403 }
404 }
405 for (const HitPayload& hit : phiOnlyHits) {
406 processPhiHit(hit);
407 }
408
409 patPhi = std::atan2(sumSin, sumCos);
410 patPhiCov = 1./sumWeight;
411 bendPlaneNorm = Acts::makeDirectionFromPhiTheta(patPhi + 90._degree, 90._degree);
412 ACTS_VERBOSE(__func__<<"() Updated pattern phi to "
413 <<inDeg(patPhi)<<" +- "<<inDeg(std::sqrt(patPhiCov)));
414 }
Scalar phi() const
phi method
std::vector< HitPayload > phiOnlyHits
Array holding phi-only hits.

Member Data Documentation

◆ bendPlaneNorm

Amg::Vector3D MuonR4::FastReco::GlobalPatternFinder::PatternState::bendPlaneNorm {Amg::Vector3D::Zero()}

Normal vector to the bending plane where the pattern lies.

Definition at line 217 of file GlobalPatternFinderDefs.h.

217{Amg::Vector3D::Zero()};

◆ cfg

const Config* MuonR4::FastReco::GlobalPatternFinder::PatternState::cfg {nullptr}

Pointer to cfg option.

Definition at line 205 of file GlobalPatternFinderDefs.h.

205{nullptr};

◆ expSect

ExpandedSector MuonR4::FastReco::GlobalPatternFinder::PatternState::expSect {static_cast<int8_t>(0)}

expanded MS sector

Definition at line 237 of file GlobalPatternFinderDefs.h.

237{static_cast<int8_t>(0)};

◆ hitsPerStation

std::array<std::vector<CandidateHit>, s_nStations> MuonR4::FastReco::GlobalPatternFinder::PatternState::hitsPerStation {}

Map collection of hits per station.

A pattern is determined by the hits belonging to it.

Definition at line 252 of file GlobalPatternFinderDefs.h.

252{};

◆ isFinalized

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

Flag to indicate if the pattern has been finalized.

Definition at line 243 of file GlobalPatternFinderDefs.h.

243{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 245 of file GlobalPatternFinderDefs.h.

245{false};

◆ lastInsertedHit

CandidateHit MuonR4::FastReco::GlobalPatternFinder::PatternState::lastInsertedHit {}

Last inserted hit.

Needed to speed-up lookup

Definition at line 211 of file GlobalPatternFinderDefs.h.

211{};

◆ lastResidual

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

Residual & residual uncertainty of the last inserted hit (needed when replacing a hit).

Definition at line 228 of file GlobalPatternFinderDefs.h.

228{0.};

◆ lastResSigma

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

Definition at line 229 of file GlobalPatternFinderDefs.h.

229{0.};

◆ leverArm

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

Distance between the two points defining the pattern line.

Definition at line 224 of file GlobalPatternFinderDefs.h.

224{0.};

◆ lineAnchorHit

CandidateHit MuonR4::FastReco::GlobalPatternFinder::PatternState::lineAnchorHit {}

Line anchor hit.

Definition at line 215 of file GlobalPatternFinderDefs.h.

215{};

◆ lineDir

Amg::Vector3D MuonR4::FastReco::GlobalPatternFinder::PatternState::lineDir {Amg::Vector3D::Zero()}

Definition at line 222 of file GlobalPatternFinderDefs.h.

222{Amg::Vector3D::Zero()};

◆ linePos

Amg::Vector3D MuonR4::FastReco::GlobalPatternFinder::PatternState::linePos {Amg::Vector3D::Zero()}

Position and direction of the pattern line.

Both are constructed to be within the bending plane of the pattern. We store them as vectors to facilitate vector operations and avoid constructing them repeatedly.

Definition at line 221 of file GlobalPatternFinderDefs.h.

221{Amg::Vector3D::Zero()};

◆ m_logger

const Acts::Logger* MuonR4::FastReco::GlobalPatternFinder::PatternState::m_logger {nullptr}

Logger.

Definition at line 207 of file GlobalPatternFinderDefs.h.

207{nullptr};

◆ meanNormResidual2

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

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

Definition at line 226 of file GlobalPatternFinderDefs.h.

226{0.};

◆ needLineUpdate

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

Whether we need to update the pattern line the next time we find a hit in a new layer.

Definition at line 249 of file GlobalPatternFinderDefs.h.

249{false};

◆ nPhiLayers

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

Definition at line 241 of file GlobalPatternFinderDefs.h.

241{0u};

◆ nPrecisionLayers

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

Counts of precision / non-precision / phi layers.

Definition at line 239 of file GlobalPatternFinderDefs.h.

239{0u};

◆ nTriggerLayers

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

Definition at line 240 of file GlobalPatternFinderDefs.h.

240{0u};

◆ patPhi

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

Pattern phi, which is the phi of the bending plane where the pattern lies.

Definition at line 231 of file GlobalPatternFinderDefs.h.

231{0.};

◆ patPhiCov

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

Covariance of the pattern phi.

Definition at line 235 of file GlobalPatternFinderDefs.h.

235{0.};

◆ patTheta

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

Pattern theta, which is the value of the seed hit.

Definition at line 233 of file GlobalPatternFinderDefs.h.

233{0.};

◆ phiOnlyHits

std::vector<HitPayload> MuonR4::FastReco::GlobalPatternFinder::PatternState::phiOnlyHits {}

Array holding phi-only hits.

Definition at line 254 of file GlobalPatternFinderDefs.h.

254{};

◆ prevLayerHit

CandidateHit MuonR4::FastReco::GlobalPatternFinder::PatternState::prevLayerHit {}

Last hit in the second-to-last layer.

Definition at line 213 of file GlobalPatternFinderDefs.h.

213{};

◆ useBeamspot

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

Whether we used the beamspot to compute the line parameters.

Definition at line 247 of file GlobalPatternFinderDefs.h.

247{false};

◆ visualInfo

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

Pointer to Visual Information for pattern visualization.

Definition at line 209 of file GlobalPatternFinderDefs.h.

209{nullptr};

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