28 ATH_MSG_FATAL(
"No candidates were given to read the segments from");
29 return StatusCode::FAILURE;
31 ATH_MSG_INFO(
"Use the following Muon tags to dump the segments");
35 ATH_MSG_INFO(
"Use the following combined tags to dump the segments");
45 return StatusCode::SUCCESS;
49 std::unique_ptr<MuonCombined::MuonTagToSegMap> persistency_link = std::make_unique<MuonCombined::MuonTagToSegMap>();
50 std::unique_ptr<Trk::SegmentCollection> out_container = std::make_unique<Trk::SegmentCollection>();
54 if (!candidate_coll.isValid()) {
55 ATH_MSG_FATAL(
"Failed to retrieve Muon segment candidates " << candidate_coll.fullKey());
56 return StatusCode::FAILURE;
58 ATH_MSG_VERBOSE(
"Retrieved "<<candidate_coll.fullKey()<<
" with size "<<candidate_coll->size());
61 const std::vector<const Muon::MuonSegment*>& assoc_segs = ms_cand->getSegments();
62 if (assoc_segs.empty()) {
ATH_MSG_WARNING(
"Muon candidate " << ms_cand->toString() <<
" does not have associated segments."); }
67 std::vector<const MuonCombined::TagBase*> good_tags{};
69 if (!tag_map.isValid()) {
70 ATH_MSG_FATAL(
"Failed to retrieve combined tag map "<<tag_map.fullKey());
71 return StatusCode::FAILURE;
73 ATH_MSG_VERBOSE(
"Retrieved "<<tag_map.fullKey()<<
" with size "<<tag_map->size());
75 good_tags.reserve(tag_map->size() + good_tags.size());
76 for (
const auto& tag_pair : *tag_map) {
77 good_tags.push_back(tag_pair.second.get());
81 if (a->isCommissioning() != b->isCommissioning()) return b->isCommissioning();
83 const int auth_a = MuonCombined::authorRank(a->author());
84 const int auth_b = MuonCombined::authorRank(b->author());
85 if (auth_a != auth_b) return auth_a < auth_b;
86 const Trk::Track* prim_a = a->primaryTrack();
87 const Trk::Track* prim_b = b->primaryTrack();
89 if (prim_a && prim_b) {
90 const Trk::Perigee* per_a = prim_a->perigeeParameters();
91 const Trk::Perigee* per_b = prim_b->perigeeParameters();
92 return per_a->pT() > per_b->pT();
95 if (prim_a || prim_b)
return prim_a !=
nullptr;
96 std::vector<const Muon::MuonSegment*> seg_a =
a->associatedSegments();
97 std::vector<const Muon::MuonSegment*> seg_b =
b->associatedSegments();
98 const size_t n_segs_a = seg_a.size();
99 const size_t n_segs_b = seg_b.size();
100 if (n_segs_a != n_segs_b)
return n_segs_a > n_segs_b;
101 if (!n_segs_a)
return false;
102 return chi2(seg_a[0]) <
chi2(seg_b[0]);
106 std::vector<const Muon::MuonSegment*> assoc_segs = cmb_tag->associatedSegments();
107 if (assoc_segs.empty() && cmb_tag->type() != xAOD::Muon::CaloTagged) {
108 ATH_MSG_WARNING(
"Combined candidate " << cmb_tag->toString() <<
" does not have associated segments");
111 persistency_link->persistify(seg, out_container.get());
116 std::set<const Trk::Segment*> assoc_segs = persistency_link->getPersistifiedSegments();
119 ATH_CHECK(usedSegWriteHandle.record(std::move(out_container)));
121 ATH_CHECK(assocMapWriteHandle.record(std::move(persistency_link)));
123 if (!m_saveUnassocSegs)
return StatusCode::SUCCESS;
125 std::vector<const Trk::Segment*> to_copy{};
129 if (!inputSegColl.isValid()) {
130 ATH_MSG_FATAL(
"Failed to retrieve segment collection " << inputSegColl.fullKey());
131 return StatusCode::FAILURE;
135 if (assoc_segs.count(seg))
continue;
136 to_copy.emplace_back(seg);
140 if (m_solveAmbi && to_copy.size() > 1) {
141 std::map<const Trk::Track*, const Trk::Segment*> track_seg_map{};
145 auto tsos = std::make_unique<Trk::TrackStates>();
150 std::unique_ptr<Trk::Track> trk =
152 track_seg_map[trk.get()] = seg;
153 ambi_tracks.push_back(std::move(trk));
155 std::unique_ptr<const TrackCollection> resolved_trks{m_ambiguityProcessor->process(&ambi_tracks)};
156 std::vector<const Trk::Segment*> resolved_copies{};
161 resolved_copies.emplace_back(seg);
163 ATH_MSG_DEBUG(
"Number of segments before the ambiguity solving " << to_copy.size() <<
" vs. after solving "
164 << resolved_copies.size());
165 to_copy = std::move(resolved_copies);
168 out_container = std::make_unique<Trk::SegmentCollection>();
172 if (!muon_seg)
continue;
173 std::unique_ptr<Muon::MuonSegment>
copy = std::make_unique<Muon::MuonSegment>(*muon_seg);
174 out_container->push_back(std::move(
copy));
177 ATH_CHECK(unUsedSegWriteHandle.record(std::move(out_container)));
178 return StatusCode::SUCCESS;