ATLAS Offline Software
TrackSegmentAssociationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
12 #include "TrkTrack/Track.h"
13 
14 namespace {
15 
16  struct MatchResult {
17  const Muon::MuonSegment* link{nullptr};
19  unsigned int numberOfMatchedMeasurements;
20  bool isSelected{true};
21  MatchResult(const Muon::MuonSegment* link_, const Muon::MuonSegmentKey& key_, unsigned int numberOfMatchedMeasurements_) :
22  link(link_), key(key_), numberOfMatchedMeasurements(numberOfMatchedMeasurements_) {}
23  };
24 } // namespace
25 
26 namespace MuonCombined {
27 
28  TrackSegmentAssociationTool::TrackSegmentAssociationTool(const std::string& t, const std::string& n, const IInterface* p) :
29  AthAlgTool(t, n, p) {
30  declareInterface<IMuonTrackToSegmentAssociationTool>(this);
31  }
32 
34  ATH_CHECK(m_edmHelperSvc.retrieve());
35  ATH_CHECK(m_printer.retrieve());
36  ATH_CHECK(m_idHelperSvc.retrieve());
37  return StatusCode::SUCCESS;
38  }
39 
41  std::vector<const Muon::MuonSegment*>& assoc_segments) const {
42  if (!segments) {
43  ATH_MSG_DEBUG("no segment container passed, returning");
44  return false;
45  }
46  if (segments->empty()) {
47  ATH_MSG_DEBUG("no segments in container, returning");
48  return false;
49  }
50  std::vector<MatchResult> matched_segs;
51  ATH_MSG_DEBUG("track " << m_printer->print(track) << std::endl << m_printer->printStations(track));
52 
53  Muon::MuonSegmentKey trackKeys(track.measurementsOnTrack()->stdcont());
54 
55  Muon::CompareMuonSegmentKeys compareKeys{};
56 
57  for (const Trk::Segment* trk_seg : *segments) {
58  const Muon::MuonSegment* muonSegment = dynamic_cast<const Muon::MuonSegment*>(trk_seg);
59  if (!muonSegment) continue;
60  Muon::MuonSegmentKey segmentKeys(*muonSegment);
61  Muon::CompareMuonSegmentKeys::OverlapResult overlapResult = compareKeys(trackKeys, segmentKeys, true);
62  if (overlapResult == Muon::CompareMuonSegmentKeys::NoOverlap) continue;
63  MatchResult matchResult(muonSegment, segmentKeys, compareKeys.intersectionSize);
64  matched_segs.push_back(matchResult);
65  ATH_MSG_DEBUG("numberOfMatchedMeasurements = " << matchResult.numberOfMatchedMeasurements);
66  }
67  ATH_MSG_DEBUG("Number of matched space-time points = " << matched_segs.size());
68 
69  // refined selection
70  for (unsigned int i = 0; i < matched_segs.size(); i++) {
71  MatchResult& result_i = matched_segs[i];
72  if (!result_i.isSelected) continue;
73 
74  const Muon::MuonSegment* seg_i = result_i.link;
75  int nMatched_i = result_i.numberOfMatchedMeasurements;
76  float chi2PerDof_i = seg_i->fitQuality()->chiSquared() / seg_i->fitQuality()->numberDoF();
77 
78  for (unsigned int j = i + 1; j < matched_segs.size(); j++) {
79  MatchResult& result_j = matched_segs[j];
80  if (!result_j.isSelected) continue;
81 
82  const Muon::MuonSegment* seg_j = result_j.link;
83  int nMatched_j = result_j.numberOfMatchedMeasurements;
84  float chi2PerDof_j = seg_j->fitQuality()->chiSquared() / seg_j->fitQuality()->numberDoF();
85 
86  // In case the two segments have common hits:
87  // 1) choose the one with higher number of matched hits to the track.
88  // 2) if the numbers of matched hits are the same, choose the one with smaller chi2/DoF.
89  Muon::CompareMuonSegmentKeys::OverlapResult overlapResult = compareKeys(result_i.key, result_j.key, true);
90  if (overlapResult == Muon::CompareMuonSegmentKeys::NoOverlap) continue;
91  if (nMatched_j > nMatched_i) {
92  result_i.isSelected = false;
93  } else if (nMatched_j < nMatched_i) {
94  result_j.isSelected = false;
95  } else {
96  if (chi2PerDof_j < chi2PerDof_i)
97  result_i.isSelected = false;
98  else
99  result_j.isSelected = false;
100  }
101 
102  ATH_MSG_VERBOSE("Segments " << i << " and " << j << " have " << compareKeys.intersectionSize << "hit(s) in common.");
103  if (result_i.isSelected)
104  ATH_MSG_VERBOSE("Keeping segment " << i);
105  else
106  ATH_MSG_VERBOSE("Keeping segment " << j);
107  }
108  }
109 
110  for (MatchResult& matches : matched_segs) {
111  if (matches.isSelected) { assoc_segments.push_back(matches.link); }
112  }
113  std::sort(assoc_segments.begin(), assoc_segments.end(), [this](const Muon::MuonSegment* a, const Muon::MuonSegment* b) -> bool {
114  using chamIdx = Muon::MuonStationIndex::ChIndex;
115  chamIdx ch_a = m_idHelperSvc->chamberIndex(m_edmHelperSvc->chamberId(*a));
116  chamIdx ch_b = m_idHelperSvc->chamberIndex(m_edmHelperSvc->chamberId(*b));
117  Muon::MuonStationIndex::StIndex st_a = Muon::MuonStationIndex::toStationIndex(ch_a);
118  Muon::MuonStationIndex::StIndex st_b = Muon::MuonStationIndex::toStationIndex(ch_b);
119  if (st_a != st_b) return st_a < st_b;
121  if (ch_a == chamIdx::CSL || ch_a == chamIdx::CSS || ch_b == chamIdx::CSS || ch_b == chamIdx::CSL)
122  return (ch_a == chamIdx::CSL) + 2 * (ch_a == chamIdx::CSS) > (ch_b == chamIdx::CSL) + 2 * (ch_b == chamIdx::CSS);
123  return ch_a < ch_b;
124  });
125  if (msgLevel(MSG::DEBUG)) {
126  std::stringstream sstr;
127  for (const Muon::MuonSegment*& seg : assoc_segments) {
128  sstr << Muon::MuonStationIndex::chName(m_idHelperSvc->chamberIndex(m_edmHelperSvc->chamberId(*seg))) << " ("
129  << Muon::MuonStationIndex::technologyName(m_idHelperSvc->technologyIndex(m_edmHelperSvc->chamberId(*seg))) << "), ";
130  }
131  ATH_MSG_DEBUG("Selected segments " << assoc_segments.size() << " " << sstr.str());
132  }
133  return true;
134  }
135 
136 } // namespace MuonCombined
Muon::MuonStationIndex::chName
static const std::string & chName(ChIndex index)
convert ChIndex into a string
Definition: MuonStationIndex.cxx:157
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
MuonCombined::TrackSegmentAssociationTool::TrackSegmentAssociationTool
TrackSegmentAssociationTool(const std::string &, const std::string &, const IInterface *)
Definition: TrackSegmentAssociationTool.cxx:28
TrackSegmentAssociationTool.h
TrkDriftCircleMath::MatchResult
std::pair< DCOnTrackVec, DCVec > MatchResult
counts the number of hits shared by the two segments
Definition: MatchCrossedTubes.h:15
Muon::MuonSegmentKey
Class to cache the identifiers on a segment in sets that can later be used to perform an overlap remo...
Definition: MuonSegmentKey.h:24
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MdtDriftCircleOnTrack.h
MuonCombined::TrackSegmentAssociationTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: TrackSegmentAssociationTool.h:39
Track.h
Muon::CompareMuonSegmentKeys::OverlapResult
OverlapResult
enum for the overlap result
Definition: CompareMuonSegmentKeys.h:16
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonCombined::TrackSegmentAssociationTool::m_edmHelperSvc
ServiceHandle< Muon::IMuonEDMHelperSvc > m_edmHelperSvc
Definition: TrackSegmentAssociationTool.h:35
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector< Trk::Segment >
MuonCombined::TrackSegmentAssociationTool::initialize
StatusCode initialize() override
Definition: TrackSegmentAssociationTool.cxx:33
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
a
TList * a
Definition: liststreamerinfos.cxx:10
Muon::CompareMuonSegmentKeys::NoOverlap
@ NoOverlap
Definition: CompareMuonSegmentKeys.h:21
MuonCombined
The MuonTagToSegMap is an auxillary construct that links the MuonSegments associated with a combined ...
Definition: IMuonSystemExtensionTool.h:23
DEBUG
#define DEBUG
Definition: page_access.h:11
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
MuonSegment.h
Trk::FitQuality::numberDoF
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition: FitQuality.h:60
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Muon::MuonSegment
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonSegment/MuonSegment/MuonSegment.h:45
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Segment::fitQuality
const FitQuality * fitQuality() const
return the FitQuality object, returns NULL if no FitQuality is defined
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:160
CompareMuonSegmentKeys.h
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
Muon::CompareMuonSegmentKeys
Definition: CompareMuonSegmentKeys.h:14
SegmentCollection.h
MuonCombined::TrackSegmentAssociationTool::associatedSegments
bool associatedSegments(const Trk::Track &muon, const Trk::SegmentCollection *segments, std::vector< const Muon::MuonSegment * > &assocSegmentVec) const override
IMuonSegmentTagTool interface: build muons from ID and MuonSegments.
Definition: TrackSegmentAssociationTool.cxx:40
MuonSegmentKey.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MuonCombined::TrackSegmentAssociationTool::m_printer
PublicToolHandle< Muon::MuonEDMPrinterTool > m_printer
Definition: TrackSegmentAssociationTool.h:37
Muon::MuonStationIndex::technologyName
static const std::string & technologyName(TechnologyIndex index)
convert LayerIndex into a string
Definition: MuonStationIndex.cxx:209