ATLAS Offline Software
Loading...
Searching...
No Matches
MuonR4::SegmentFit::SegmentAmbiSolver Class Reference

The SegmentAmbiSolver removes ambiguities between segment candidates from the fit. More...

#include <SegmentAmbiSolver.h>

Inheritance diagram for MuonR4::SegmentFit::SegmentAmbiSolver:
Collaboration diagram for MuonR4::SegmentFit::SegmentAmbiSolver:

Classes

struct  Config
 Configuration object to stree the ambiguties. More...

Public Types

using SegmentVec = std::vector<std::unique_ptr<Segment>>
 Abrivation of the temporary segment container.

Public Member Functions

 SegmentAmbiSolver (const std::string &name, Config &&config)
 Constructor.
SegmentVec resolveAmbiguity (const ActsTrk::GeometryContext &gctx, SegmentVec &&toResolve) const
 Launches the ambiguity resoltuion and returns a new temporary contained containing the good candidates only.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Types

enum class  Resolution : std::uint8_t { noOverlap , superSet , subSet }
 Auxiliary enum to indicate the ambiguity status of the segment candidates. More...
using MeasurementSet = std::unordered_set<const xAOD::UncalibratedMeasurement*>
 List of measurements out of which the segment is made of.

Private Member Functions

std::vector< int > driftSigns (const ActsTrk::GeometryContext &gctx, const Segment &segment, const Segment::MeasVec &measurements) const
 Calculates the left-right ambiguities of the segment w.r.t each measurement.
MeasurementSet extractPrds (const Segment &segment) const
 Extract the Uncalibrated measurements used to build the segment.
unsigned int countShared (const MeasurementSet &measSet1, const MeasurementSet &measSet2) const
 Counts the number of measurements that're in both sets.
double redChi2 (const Segment &segment) const
 Returns the reduced chi2 of the segment.
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

const Config m_cfg {}
 Configuration object.
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Detailed Description

The SegmentAmbiSolver removes ambiguities between segment candidates from the fit.

They typically arise from the sharing of hits between two candidates. The resolution happens in the following steps 1) The passed segment candidates are sorted by the reduced chi2 in increasing order Candidates which already have a sufficiently good chi2 are internally sorted by the degress of freedom in decreasing order 2) The first segment in the list has the most degrees of freedom with an acceptable chi2. Is is added to the list of good candidates. 3) The other segments are compared with the good candidates. If the segment shares at minimum 3 hits with a good candidate and has a worse chi2 and fewer hits it is marked for removal. If the good candidate has worse chi2 the segment takes over the place of the good candidate

Definition at line 27 of file SegmentAmbiSolver.h.

Member Typedef Documentation

◆ MeasurementSet

List of measurements out of which the segment is made of.

Definition at line 72 of file SegmentAmbiSolver.h.

◆ SegmentVec

using MuonR4::SegmentFit::SegmentAmbiSolver::SegmentVec = std::vector<std::unique_ptr<Segment>>

Abrivation of the temporary segment container.

Definition at line 47 of file SegmentAmbiSolver.h.

Member Enumeration Documentation

◆ Resolution

enum class MuonR4::SegmentFit::SegmentAmbiSolver::Resolution : std::uint8_t
strongprivate

Auxiliary enum to indicate the ambiguity status of the segment candidates.

Enumerator
noOverlap 
superSet 

No ambiguity with other candidates detected.

subSet 

Ambiguity detected and the candidate is of better quality.

Ambiguity detected but the candidate is of poorer quality

Definition at line 58 of file SegmentAmbiSolver.h.

58 : std::uint8_t{
59 noOverlap,
60 superSet,
61 subSet
62 };

Constructor & Destructor Documentation

◆ SegmentAmbiSolver()

MuonR4::SegmentFit::SegmentAmbiSolver::SegmentAmbiSolver ( const std::string & name,
Config && config )

Constructor.

Parameters
nameName of the algorithm to synchronize the msg output
configAmbiguity resolver configuration object

Definition at line 10 of file SegmentAmbiSolver.cxx.

10 :
12 m_cfg{std::move(cfg)} {}
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
const Config m_cfg
Configuration object.

Member Function Documentation

◆ countShared()

unsigned MuonR4::SegmentFit::SegmentAmbiSolver::countShared ( const MeasurementSet & measSet1,
const MeasurementSet & measSet2 ) const
private

Counts the number of measurements that're in both sets.

Parameters
measSet1First set of measurements to compare
measSet2Second set of measurements to compare

Definition at line 121 of file SegmentAmbiSolver.cxx.

122 {
123 if (measSet1.size() > measSet2.size()) {
124 return std::count_if(measSet2.begin(),measSet2.end(),[&measSet1](const xAOD::UncalibratedMeasurement* meas){
125 return measSet1.count(meas);
126 });
127 }
128 return std::count_if(measSet1.begin(),measSet1.end(),[&measSet2](const xAOD::UncalibratedMeasurement* meas){
129 return measSet2.count(meas);
130 });
131 }
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.

◆ driftSigns()

std::vector< int > MuonR4::SegmentFit::SegmentAmbiSolver::driftSigns ( const ActsTrk::GeometryContext & gctx,
const Segment & segment,
const Segment::MeasVec & measurements ) const
private

Calculates the left-right ambiguities of the segment w.r.t each measurement.

Parameters
gctxGeometry context to construct the local segment parameters
segmentThe segment from which the line parameters are extracted
measurementsList of segment measurments w.r. the left-right signs need to be evaluated

Definition at line 97 of file SegmentAmbiSolver.cxx.

99 {
100 const auto [pos, dir] = makeLine(localSegmentPars(gctx, segment));
101
102 ATH_MSG_VERBOSE("Fetch drift signs for segment "<<segment.msSector()->identString()
103 <<" -- "<<Amg::toString(pos)<<" + " <<Amg::toString(dir));
104 return SeedingAux::strawSigns(pos, dir, measurements);
105 }
#define ATH_MSG_VERBOSE(x)
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.

◆ extractPrds()

SegmentAmbiSolver::MeasurementSet MuonR4::SegmentFit::SegmentAmbiSolver::extractPrds ( const Segment & segment) const
private

Extract the Uncalibrated measurements used to build the segment.

Parameters
segmentThe segment from which the raw measurements should be fetched

Definition at line 107 of file SegmentAmbiSolver.cxx.

107 {
108
109 MeasurementSet meas{};
110 for (const Segment::MeasVec::value_type& hit : segment.measurements()) {
111 if (!hit->spacePoint() || hit->fitState() != CalibratedSpacePoint::State::Valid || !hit->measuresEta()) {
112 continue;
113 }
114 meas.insert(hit->spacePoint()->primaryMeasurement());
115 if (hit->spacePoint()->secondaryMeasurement()) {
116 meas.insert(hit->spacePoint()->secondaryMeasurement());
117 }
118 }
119 return meas;
120 }
std::unordered_set< const xAOD::UncalibratedMeasurement * > MeasurementSet
List of measurements out of which the segment is made of.

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 163 of file AthMessaging.h.

164{
165 MsgStream* ms = m_msg_tls.get();
166 if (!ms) {
167 if (!m_initialized.test_and_set()) initMessaging();
168 ms = new MsgStream(m_imsg,m_nm);
169 m_msg_tls.reset( ms );
170 }
171
172 ms->setLevel (m_lvl);
173 return *ms;
174}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 178 of file AthMessaging.h.

179{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 if (m_lvl <= lvl) {
154 msg() << lvl;
155 return true;
156 } else {
157 return false;
158 }
159}

◆ redChi2()

double MuonR4::SegmentFit::SegmentAmbiSolver::redChi2 ( const Segment & segment) const
private

Returns the reduced chi2 of the segment.

Parameters
segmentSegment of interest

Definition at line 14 of file SegmentAmbiSolver.cxx.

14 {
15 return segment.chi2() / std::max(segment.nDoF(), 1u);
16 }

◆ resolveAmbiguity()

SegmentVec MuonR4::SegmentFit::SegmentAmbiSolver::resolveAmbiguity ( const ActsTrk::GeometryContext & gctx,
SegmentVec && toResolve ) const

Launches the ambiguity resoltuion and returns a new temporary contained containing the good candidates only.

Parameters
gctxGeometry context to construct the local segment parameters
toResolveCollection of segments which need to be ambiguity resolved

Sort segments with a reduced chi2 better than 5 (normmaly) by the degrees of freedom, otherwise by the reduced chi2 itself

Mark the first object as resolved

Fetch first the Prds

Check whether the two segments share hits at all

Re-evaluate the drift signs of the accepted measurement w.r.t. good one

Left-right solutions differ & the two segments have the same nDOF

Segments below that threshold are not considered for outlier removal Take the one which has more degrees of freedom

No overlap detected thus far

Definition at line 17 of file SegmentAmbiSolver.cxx.

18 {
19
22 std::ranges::stable_sort(toResolve,[this](const SegmentVec::value_type& a,
23 const SegmentVec::value_type& b){
24 const double redChi2A = redChi2(*a);
25 const double redChi2B = redChi2(*b);
26 if (redChi2A < m_cfg.selectByNDoFChi2 && redChi2B < m_cfg.selectByNDoFChi2){
27 return a->nDoF() > b->nDoF();
28 }
29 return redChi2A < redChi2B;
30 });
31 SegmentVec resolved{};
32
34 resolved.push_back(std::move(toResolve[0]));
35 toResolve.erase(toResolve.begin());
36 std::vector<std::vector<int>> segmentSigns{driftSigns(gctx, *resolved.front(), resolved.front()->measurements())};
37 std::vector<MeasurementSet> segMeasurements{extractPrds(*resolved.front())};
38
39 for (SegmentVec::value_type& resolveMe : toResolve) {
40 ATH_MSG_VERBOSE("Try to resolve new segment "<<toString(localSegmentPars(gctx, *resolveMe))
41 <<" redChi2: "<<redChi2(*resolveMe)<<" nDoF: "<<resolveMe->nDoF());
43 MeasurementSet testMeas{extractPrds(*resolveMe)};
45 unsigned resolvedIdx{0};
46 for (SegmentVec::value_type& goodSeg : resolved) {
47 ATH_MSG_VERBOSE("Test against segment "<<toString(localSegmentPars(gctx, *goodSeg))
48 <<" redChi2: "<<redChi2(*goodSeg)<<" nDoF: "<<goodSeg->nDoF());
49 MeasurementSet& resolvedM = segMeasurements[resolvedIdx];
50 std::vector<int>& existSigns{segmentSigns[resolvedIdx++]};
52 unsigned shared = countShared(resolvedM, testMeas);
53 if (shared < m_cfg.sharedPrecHits) {
54 ATH_MSG_VERBOSE("Too few shared measurements "<<shared<<" (Required: "<<m_cfg.sharedPrecHits<<").");
55 continue;
56 }
58 const std::vector<int> reEvaluatedSigns{driftSigns(gctx, *resolveMe, goodSeg->measurements())};
59
60 unsigned sameSides{0};
61 for (unsigned s =0 ; s < existSigns.size(); ++s) {
62 sameSides += (reEvaluatedSigns[s] == existSigns[s]);
63 }
65 if (!m_cfg.remLeftRightAmbi && sameSides != existSigns.size() && resolveMe->nDoF() == goodSeg->nDoF()) {
66 ATH_MSG_VERBOSE("Reference signs: "<<existSigns<<" / re-evaluated: "<<reEvaluatedSigns);
67 continue;
68 }
69 const double resolvedChi2 = redChi2(*goodSeg);
70 const double resolveMeChi2 = redChi2(*resolveMe);
71 reso = resolveMeChi2 < resolvedChi2 ? Resolution::superSet : Resolution::subSet;
72
73 ATH_MSG_VERBOSE("Chi2 good "<<resolvedChi2<<", candidate chi2: "<<resolveMeChi2);
76 if (resolveMeChi2 < m_cfg.selectByNDoFChi2 && resolvedChi2 < m_cfg.selectByNDoFChi2) {
77 reso = goodSeg->nDoF() > resolveMe->nDoF() ? Resolution::subSet : Resolution::superSet;
78 }
79 if (reso == Resolution::superSet) {
80 std::swap(goodSeg, resolveMe);
81 std::swap(resolvedM, testMeas);
82 existSigns = driftSigns(gctx, *resolveMe, resolveMe->measurements());
83 break;
84 } else if (reso == Resolution::subSet) {
85 break;
86 }
87 }
89 if (reso == Resolution::noOverlap) {
90 segMeasurements.push_back(std::move(testMeas));
91 segmentSigns.push_back(driftSigns(gctx, *resolveMe, resolveMe->measurements()));
92 resolved.push_back(std::move(resolveMe));
93 }
94 }
95 return resolved;
96 }
static Double_t a
Resolution
Auxiliary enum to indicate the ambiguity status of the segment candidates.
@ superSet
No ambiguity with other candidates detected.
@ subSet
Ambiguity detected and the candidate is of better quality.
unsigned int countShared(const MeasurementSet &measSet1, const MeasurementSet &measSet2) const
Counts the number of measurements that're in both sets.
MeasurementSet extractPrds(const Segment &segment) const
Extract the Uncalibrated measurements used to build the segment.
double redChi2(const Segment &segment) const
Returns the reduced chi2 of the segment.
std::vector< std::unique_ptr< Segment > > SegmentVec
Abrivation of the temporary segment container.
std::vector< int > driftSigns(const ActsTrk::GeometryContext &gctx, const Segment &segment, const Segment::MeasVec &measurements) const
Calculates the left-right ambiguities of the segment w.r.t each measurement.
std::string toString(const Parameters &pars)
Dumps the parameters into a string with labels in front of each number.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_cfg

const Config MuonR4::SegmentFit::SegmentAmbiSolver::m_cfg {}
private

Configuration object.

Definition at line 56 of file SegmentAmbiSolver.h.

56{};

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


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