ATLAS Offline Software
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 47 of file SegmentAmbiSolver.h.

◆ SegmentVec

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

Definition at line 30 of file SegmentAmbiSolver.h.

Member Enumeration Documentation

◆ Resolution

Enumerator
noOverlap 
superSet 
subSet 

Definition at line 35 of file SegmentAmbiSolver.h.

35  {
36  noOverlap,
37  superSet,
38  subSet
39  };

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

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

◆ driftSigns()

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

Definition at line 91 of file SegmentAmbiSolver.cxx.

93  {
94  std::vector<int> signs{};
95  signs.reserve(measurements.size());
96  const auto [locPos, locDir] = makeLine(localSegmentPars(gctx, segment));
97  ATH_MSG_VERBOSE("Fetch drift signs for segment "<<segment.msSector()->identString()<<" -- "<<Amg::toString(locPos)
99  for (const Segment::MeasVec::value_type& hit : measurements) {
100  if (!hit->spacePoint()) {
101  continue;
102  }
103  signs.push_back(SegmentFitHelpers::driftSign(locPos,locDir,*hit, msg()));
104  }
105  return signs;
106  }

◆ extractPrds()

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

Extract the Uncalibrated measurements used to build the segment.

Definition at line 108 of file SegmentAmbiSolver.cxx.

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

◆ 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

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

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 
41  MeasurementSet testMeas{extractPrds(*resolveMe)};
42 
44  unsigned int resolvedIdx{0};
45  for (std::unique_ptr<Segment>& goodSeg : resolved) {
46  ATH_MSG_VERBOSE("Test against segment "<<toString(localSegmentPars(gctx, *goodSeg)));
47  MeasurementSet& resolvedM = segMeasurements[resolvedIdx];
48  std::vector<int>& existSigns{segmentSigns[resolvedIdx++]};
49  unsigned int shared = countShared(resolvedM, testMeas);
50  if (shared < m_cfg.sharedPrecHits) {
51  ATH_MSG_VERBOSE("Too few shared measurements "<<shared<<" (Required: "<<m_cfg.sharedPrecHits<<").");
52  continue;
53  }
54  const std::vector<int> reEvaluatedSigns{driftSigns(gctx, *resolveMe, goodSeg->measurements())};
55 
56  unsigned int sameSides{0};
57  for (unsigned int s =0 ; s < existSigns.size(); ++s) {
58  sameSides += (reEvaluatedSigns[s] == existSigns[s]);
59  }
60  if (sameSides != existSigns.size() && resolveMe->nDoF() == goodSeg->nDoF()) {
61  ATH_MSG_VERBOSE("Reference signs: "<<existSigns<<" / re-evaluated: "<<reEvaluatedSigns);
62  continue;
63  }
64  reso = Resolution::subSet;
65  const double resolvedChi2 = redChi2(*goodSeg);
66  const double resolveMeChi2 = redChi2(*resolveMe);
67  ATH_MSG_VERBOSE("Chi2 good "<<resolvedChi2<<", candidate chi2: "<<resolveMeChi2);
70  if (resolveMeChi2 < m_cfg.selectByNDoFChi2 && resolvedChi2 < m_cfg.selectByNDoFChi2) {
71  if (resolveMe->nDoF() > goodSeg->nDoF()){
72  reso = Resolution::superSet;
73  }
74  } else if (resolveMeChi2 < resolvedChi2) {
75  reso = Resolution::superSet;
76  }
77  if (reso == Resolution::superSet) {
78  std::swap(goodSeg, resolveMe);
79  std::swap(resolvedM, testMeas);
80  existSigns = driftSigns(gctx, *resolveMe, resolveMe->measurements());
81  }
82  }
83  if (reso == Resolution::noOverlap) {
84  segMeasurements.push_back(std::move(testMeas));
85  segmentSigns.push_back(driftSigns(gctx, *resolveMe, resolveMe->measurements()));
86  resolved.push_back(std::move(resolveMe));
87  }
88  }
89  return resolved;
90  }

◆ 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 41 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:
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
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::SegmentAmbiSolver::m_cfg
const Config m_cfg
Definition: SegmentAmbiSolver.h:41
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:30
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::SegmentFitHelpers::driftSign
int driftSign(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const SpacePoint &uncalibHit, MsgStream &msg)
Calculates whether a segement line travereses the tube measurement on the left (-1) or right (1) side...
Definition: SegmentFitHelperFunctions.cxx:221
MuonR4::SegmentAmbiSolver::MeasurementSet
std::unordered_set< const xAOD::UncalibratedMeasurement * > MeasurementSet
Definition: SegmentAmbiSolver.h:47
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:91
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:122
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:108
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:221
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:30
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:36
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:35
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