ATLAS Offline Software
SegmentAmbiSolver.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
6 #include <Acts/Utilities/Enumerate.hpp>
7 
8 namespace MuonR4 {
9  using namespace SegmentFit;
11 
14  m_cfg{std::move(cfg)} {}
15 
17  return segment.chi2() / segment.nDoF();
18  }
20  SegmentVec&& toResolve) const {
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  } else if (reso == Resolution::subSet) {
84  break;
85  }
86  }
88  if (reso == Resolution::noOverlap) {
89  segMeasurements.push_back(std::move(testMeas));
90  segmentSigns.push_back(driftSigns(gctx, *resolveMe, resolveMe->measurements()));
91  resolved.push_back(std::move(resolveMe));
92  }
93  }
94  return resolved;
95  }
96  std::vector<int> SegmentAmbiSolver::driftSigns(const ActsGeometryContext& gctx,
97  const Segment& segment,
98  const Segment::MeasVec& measurements) const {
99  const auto [locPos, locDir] = makeLine(localSegmentPars(gctx, segment));
100  ATH_MSG_VERBOSE("Fetch drift signs for segment "<<segment.msSector()->identString()<<" -- "<<Amg::toString(locPos)
101  <<Amg::toString(locDir));
102  return SegmentFitHelpers::driftSigns(locPos, locDir, measurements, msg());
103  }
106 
107  MeasurementSet meas{};
108  for (const Segment::MeasVec::value_type& hit : segment.measurements()) {
109  if (!hit->spacePoint() || hit->fitState() != CalibratedSpacePoint::State::Valid || !hit->measuresEta()) {
110  continue;
111  }
112  meas.insert(hit->spacePoint()->primaryMeasurement());
113  if (hit->spacePoint()->secondaryMeasurement()) {
114  meas.insert(hit->spacePoint()->secondaryMeasurement());
115  }
116  }
117  return meas;
118  }
119  unsigned int SegmentAmbiSolver::countShared(const MeasurementSet& measSet1,
120  const MeasurementSet& measSet2) const {
121  if (measSet1.size() > measSet2.size()) {
122  return std::count_if(measSet2.begin(),measSet2.end(),[&measSet1](const xAOD::UncalibratedMeasurement* meas){
123  return measSet1.count(meas);
124  });
125  }
126  return std::count_if(measSet1.begin(),measSet1.end(),[&measSet2](const xAOD::UncalibratedMeasurement* meas){
127  return measSet2.count(meas);
128  });
129  }
130 }
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:210
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MuonR4::SegmentAmbiSolver::Config::remLeftRightAmbi
bool remLeftRightAmbi
Allow for left-right ambiguities.
Definition: SegmentAmbiSolver.h:25
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::SegmentAmbiSolver::Config
Definition: SegmentAmbiSolver.h:18
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
MuonR4::toString
std::string toString(const CalibratedSpacePoint::Covariance_t &mat)
Returns the matrix in string.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/UtilFunctions.cxx:75
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
MuonR4::SegmentAmbiSolver::driftSigns
std::vector< int > driftSigns(const ActsGeometryContext &gctx, const Segment &segment, const Segment::MeasVec &measurements) const
Definition: SegmentAmbiSolver.cxx:96
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:119
MuonR4::Segment::MeasVec
std::vector< MeasType > MeasVec
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:23
SegmentFitHelperFunctions.h
MuonR4::SegmentAmbiSolver::resolveAmbiguity
SegmentVec resolveAmbiguity(const ActsGeometryContext &gctx, SegmentVec &&toResolve) const
Definition: SegmentAmbiSolver.cxx:19
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:105
MuonR4::SegmentAmbiSolver::SegmentAmbiSolver
SegmentAmbiSolver(const std::string &name, Config &&config)
Definition: SegmentAmbiSolver.cxx:12
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
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:228
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
SegmentAmbiSolver.h
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::SegmentVec
SegmentAmbiSolver::SegmentVec SegmentVec
Definition: SegmentAmbiSolver.cxx:10
a
TList * a
Definition: liststreamerinfos.cxx:10
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
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5