46 std::unique_ptr<MuonCombined::MuonTagToSegMap> persistency_link = std::make_unique<MuonCombined::MuonTagToSegMap>();
47 std::unique_ptr<Trk::SegmentCollection> out_container = std::make_unique<Trk::SegmentCollection>();
51 if (!candidate_coll.isValid()) {
52 ATH_MSG_FATAL(
"Failed to retrieve Muon segment candidates " << candidate_coll.fullKey());
53 return StatusCode::FAILURE;
55 ATH_MSG_VERBOSE(
"Retrieved "<<candidate_coll.fullKey()<<
" with size "<<candidate_coll->size());
58 const std::vector<const Muon::MuonSegment*>& assoc_segs = ms_cand->getSegments();
59 if (assoc_segs.empty()) {
ATH_MSG_WARNING(
"Muon candidate " << ms_cand->toString() <<
" does not have associated segments."); }
60 for (
const Muon::MuonSegment* seg : assoc_segs) { persistency_link->persistify(seg, out_container.get()); }
64 std::vector<const MuonCombined::TagBase*> good_tags{};
66 if (!tag_map.isValid()) {
67 ATH_MSG_FATAL(
"Failed to retrieve combined tag map "<<tag_map.fullKey());
68 return StatusCode::FAILURE;
70 ATH_MSG_VERBOSE(
"Retrieved "<<tag_map.fullKey()<<
" with size "<<tag_map->size());
72 good_tags.reserve(tag_map->size() + good_tags.size());
73 for (
const auto& tag_pair : *tag_map) {
74 good_tags.push_back(tag_pair.second.get());
79 const int auth_a = MuonCombined::authorRank(a->author());
80 const int auth_b = MuonCombined::authorRank(b->author());
81 if (auth_a != auth_b) return auth_a < auth_b;
82 const Trk::Track* prim_a = a->primaryTrack();
83 const Trk::Track* prim_b = b->primaryTrack();
85 if (prim_a && prim_b) {
86 const Trk::Perigee* per_a = prim_a->perigeeParameters();
87 const Trk::Perigee* per_b = prim_b->perigeeParameters();
88 return per_a->pT() > per_b->pT();
91 if (prim_a || prim_b)
return prim_a !=
nullptr;
92 std::vector<const Muon::MuonSegment*> seg_a =
a->associatedSegments();
93 std::vector<const Muon::MuonSegment*> seg_b = b->associatedSegments();
94 const size_t n_segs_a = seg_a.size();
95 const size_t n_segs_b = seg_b.size();
96 if (n_segs_a != n_segs_b)
return n_segs_a > n_segs_b;
97 if (!n_segs_a)
return false;
98 return chi2(seg_a[0]) <
chi2(seg_b[0]);
102 std::vector<const Muon::MuonSegment*> assoc_segs = cmb_tag->associatedSegments();
103 if (assoc_segs.empty() && cmb_tag->type() != xAOD::Muon::MuonType::CaloTagged) {
104 ATH_MSG_WARNING(
"Combined candidate " << cmb_tag->toString() <<
" does not have associated segments");
107 persistency_link->persistify(seg, out_container.get());
112 std::set<const Trk::Segment*> assoc_segs = persistency_link->getPersistifiedSegments();
119 if (!m_saveUnassocSegs)
return StatusCode::SUCCESS;
121 std::vector<const Trk::Segment*> to_copy{};
125 if (!inputSegColl.isValid()) {
126 ATH_MSG_FATAL(
"Failed to retrieve segment collection " << inputSegColl.fullKey());
127 return StatusCode::FAILURE;
131 if (assoc_segs.count(seg))
continue;
132 to_copy.emplace_back(seg);
136 if (m_solveAmbi && to_copy.size() > 1) {
137 std::map<const Trk::Track*, const Trk::Segment*> track_seg_map{};
141 auto tsos = std::make_unique<Trk::TrackStates>();
146 std::unique_ptr<Trk::Track> trk =
148 track_seg_map[trk.get()] = seg;
151 std::unique_ptr<const TrackCollection> resolved_trks{m_ambiguityProcessor->process(ctx, &ambi_tracks)};
152 std::vector<const Trk::Segment*> resolved_copies{};
157 resolved_copies.emplace_back(seg);
159 ATH_MSG_DEBUG(
"Number of segments before the ambiguity solving " << to_copy.size() <<
" vs. after solving "
160 << resolved_copies.size());
161 to_copy = std::move(resolved_copies);
164 out_container = std::make_unique<Trk::SegmentCollection>();
168 if (!muon_seg)
continue;
169 std::unique_ptr<Muon::MuonSegment>
copy = std::make_unique<Muon::MuonSegment>(*muon_seg);
170 out_container->push_back(std::move(copy));
174 return StatusCode::SUCCESS;