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 
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  }
91  std::vector<int> SegmentAmbiSolver::driftSigns(const ActsGeometryContext& gctx,
92  const Segment& segment,
93  const Segment::MeasVec& measurements) const {
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  }
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  }
122  unsigned int SegmentAmbiSolver::countShared(const MeasurementSet& measSet1,
123  const MeasurementSet& measSet2) const {
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  }
133 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
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: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
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::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
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
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:108
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: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
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: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
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5