Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MuonR4::SegmentAmbiSolver Class Reference

#include <SegmentAmbiSolver.h>

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

Classes

struct  Config
 

Public Types

enum  Resolution { Resolution::noOverlap, Resolution::superSet, Resolution::subSet }
 
using SegmentVec = std::vector< std::unique_ptr< Segment > >
 

Public Member Functions

 SegmentAmbiSolver (const std::string &name, Config &&config)
 
SegmentVec resolveAmbiguity (const ActsGeometryContext &gctx, SegmentVec &&toResolve) const
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Types

using MeasurementSet = std::unordered_set< const xAOD::UncalibratedMeasurement * >
 

Private Member Functions

std::vector< int > driftSigns (const ActsGeometryContext &gctx, const Segment &segment, const Segment::MeasVec &measurements) const
 
MeasurementSet extractPrds (const Segment &segment) const
 Extract the Uncalibrated measurements used to build the segment. More...
 
unsigned int countShared (const MeasurementSet &measSet1, const MeasurementSet &measSet2) const
 counts the number of measurements that're in both sets More...
 
double redChi2 (const Segment &segment) const
 Returns the reduced chi2 of the segment. More...
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

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

Detailed Description

Definition at line 16 of file SegmentAmbiSolver.h.

Member Typedef Documentation

◆ MeasurementSet

Definition at line 49 of file SegmentAmbiSolver.h.

◆ SegmentVec

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

Definition at line 32 of file SegmentAmbiSolver.h.

Member Enumeration Documentation

◆ Resolution

Enumerator
noOverlap 
superSet 
subSet 

Definition at line 37 of file SegmentAmbiSolver.h.

37  {
38  noOverlap,
39  superSet,
40  subSet
41  };

Constructor & Destructor Documentation

◆ SegmentAmbiSolver()

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

Definition at line 12 of file SegmentAmbiSolver.cxx.

12  :
14  m_cfg{std::move(cfg)} {}

Member Function Documentation

◆ countShared()

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

counts the number of measurements that're in both sets

Definition at line 120 of file SegmentAmbiSolver.cxx.

121  {
122  if (measSet1.size() > measSet2.size()) {
123  return std::count_if(measSet2.begin(),measSet2.end(),[&measSet1](const xAOD::UncalibratedMeasurement* meas){
124  return measSet1.count(meas);
125  });
126  }
127  return std::count_if(measSet1.begin(),measSet1.end(),[&measSet2](const xAOD::UncalibratedMeasurement* meas){
128  return measSet2.count(meas);
129  });
130  }

◆ driftSigns()

std::vector< int > MuonR4::SegmentAmbiSolver::driftSigns ( const ActsGeometryContext gctx,
const Segment segment,
const Segment::MeasVec measurements 
) const
private

Definition at line 97 of file SegmentAmbiSolver.cxx.

99  {
100  const auto [locPos, locDir] = makeLine(localSegmentPars(gctx, segment));
101  ATH_MSG_VERBOSE("Fetch drift signs for segment "<<segment.msSector()->identString()<<" -- "<<Amg::toString(locPos)
102  <<Amg::toString(locDir));
103  return SegmentFitHelpers::driftSigns(locPos, locDir, measurements, msg());
104  }

◆ extractPrds()

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

Extract the Uncalibrated measurements used to build the segment.

Definition at line 106 of file SegmentAmbiSolver.cxx.

106  {
107 
108  MeasurementSet meas{};
109  for (const Segment::MeasVec::value_type& hit : segment.measurements()) {
110  if (!hit->spacePoint() || hit->fitState() != CalibratedSpacePoint::State::Valid || !hit->measuresEta()) {
111  continue;
112  }
113  meas.insert(hit->spacePoint()->primaryMeasurement());
114  if (hit->spacePoint()->secondaryMeasurement()) {
115  meas.insert(hit->spacePoint()->secondaryMeasurement());
116  }
117  }
118  return meas;
119  }

◆ 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  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ 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 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ 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 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ 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_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ redChi2()

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

Returns the reduced chi2 of the segment.

Definition at line 16 of file SegmentAmbiSolver.cxx.

16  {
17  return segment.chi2() / segment.nDoF();
18  }

◆ resolveAmbiguity()

SegmentVec MuonR4::SegmentAmbiSolver::resolveAmbiguity ( const ActsGeometryContext gctx,
SegmentVec &&  toResolve 
) const

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 19 of file SegmentAmbiSolver.cxx.

20  {
21 
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 (std::unique_ptr<Segment>& 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 int resolvedIdx{0};
46  for (std::unique_ptr<Segment>& 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 int 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 int sameSides{0};
61  for (unsigned int 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  }

◆ 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::SegmentAmbiSolver::m_cfg {}
private

Definition at line 43 of file SegmentAmbiSolver.h.

◆ m_imsg

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

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

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

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ 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:
MuonR4::SegmentFitHelpers::driftSigns
std::vector< int > driftSigns(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const std::vector< const SpacePoint * > &uncalibHits, MsgStream &msg)
Calculates whether a segment line travereses the tube measurements on the left (-1) or right (1) side...
Definition: SegmentFitHelperFunctions.cxx:213
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MuonR4::SegmentAmbiSolver::Config::remLeftRightAmbi
bool remLeftRightAmbi
Allow for left-right ambiguities.
Definition: SegmentAmbiSolver.h:25
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::SegmentAmbiSolver::m_cfg
const Config m_cfg
Definition: SegmentAmbiSolver.h:43
MuonR4::SegmentFit::makeLine
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
Definition: SegmentFitterEventData.cxx:26
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
MuonR4::toString
std::string toString(const CalibratedSpacePoint::Covariance_t &mat)
Returns the matrix in string.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx:75
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonR4::SegmentAmbiSolver::MeasurementSet
std::unordered_set< const xAOD::UncalibratedMeasurement * > MeasurementSet
Definition: SegmentAmbiSolver.h:49
MuonR4::SegmentAmbiSolver::redChi2
double redChi2(const Segment &segment) const
Returns the reduced chi2 of the segment.
Definition: SegmentAmbiSolver.cxx:16
MuonR4::SegmentAmbiSolver::Resolution::noOverlap
@ noOverlap
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
MuonR4::SegmentAmbiSolver::driftSigns
std::vector< int > driftSigns(const ActsGeometryContext &gctx, const Segment &segment, const Segment::MeasVec &measurements) const
Definition: SegmentAmbiSolver.cxx:97
MuonR4::SegmentAmbiSolver::countShared
unsigned int countShared(const MeasurementSet &measSet1, const MeasurementSet &measSet2) const
counts the number of measurements that're in both sets
Definition: SegmentAmbiSolver.cxx:120
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonR4::SegmentAmbiSolver::extractPrds
MeasurementSet extractPrds(const Segment &segment) const
Extract the Uncalibrated measurements used to build the segment.
Definition: SegmentAmbiSolver.cxx:106
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
MuonR4::CalibratedSpacePoint::State::Valid
@ Valid
MuonR4::SegmentAmbiSolver::Resolution::subSet
@ subSet
MuonR4::SegmentAmbiSolver::Config::selectByNDoFChi2
double selectByNDoFChi2
If two overlapping segments have both the chi2 below the threshold, the one with more degrees of free...
Definition: SegmentAmbiSolver.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
python.copyTCTOutput.locDir
locDir
Definition: copyTCTOutput.py:113
MuonR4::SegmentAmbiSolver::SegmentVec
std::vector< std::unique_ptr< Segment > > SegmentVec
Definition: SegmentAmbiSolver.h:32
a
TList * a
Definition: liststreamerinfos.cxx:10
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
MuonR4::SegmentFit::localSegmentPars
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
Definition: SegmentFitterEventData.cxx:32
MuonR4::SegmentAmbiSolver::Config::sharedPrecHits
unsigned int sharedPrecHits
Cut on the number of shared precision hits.
Definition: SegmentAmbiSolver.h:23
MuonR4::SegmentAmbiSolver::Resolution
Resolution
Definition: SegmentAmbiSolver.h:37
MuonR4::SegmentAmbiSolver::Resolution::superSet
@ superSet
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5