Check whether the author arises from the comissioning chain The maps are filled in dedicated algorithim. So all tags will fail / satisfy this condition
In principle we can include here STACO as well but that is lower ranked as MuidSA
962 {
963 resolvedMuonCandidates.clear();
964 resolvedInDetCandidates.clear();
965
966 std::unique_ptr<const TrackCollection> resolvedTracks;
967 std::vector<std::unique_ptr<Trk::Track>> garbage_collection;
968
973 for (const InDetCandidateToTagMap* tag_map : tagMaps) {
974 if (!tag_map) continue;
975 for (const auto& comb_tag : *tag_map) {
976 const TagBase*
tag = comb_tag.second.get();
980 InDetCandidateTagsMap::iterator itr =
981 std::find_if(inDetCandidateMap.begin(), inDetCandidateMap.end(),
982 [&comb_tag](const InDetCandidateTags& to_test) { return (*to_test.first) == (*comb_tag.first); });
983 if (itr != inDetCandidateMap.end())
984 itr->second.emplace_back(tag);
985 else
986 inDetCandidateMap.emplace_back(std::make_pair(comb_tag.first, std::vector<const TagBase*>{tag}));
987 }
988 }
989
990
991
992
993 if (!inDetCandidateMap.empty()) {
994
995
997
998
999 resolvedInDetCandidates.reserve(inDetCandidateMap.size());
1000 caloMuons.reserve(inDetCandidateMap.size());
1001 for (InDetCandidateTags& comb_tag : inDetCandidateMap) {
1002 std::stable_sort(comb_tag.second.begin(), comb_tag.second.end(), SortTagBasePtr());
1003 if (comb_tag.second.size() == 1 && comb_tag.second.front()->type() == xAOD::Muon::MuonType::CaloTagged) {
1004 caloMuons.emplace_back(std::move(comb_tag));
1005 } else
1006 resolvedInDetCandidates.emplace_back(std::move(comb_tag));
1007 }
1008 inDetCandidateMap.clear();
1009
1010 std::stable_sort(resolvedInDetCandidates.begin(), resolvedInDetCandidates.end(), SortInDetCandidates());
1011 if (msgLvl(MSG::DEBUG)) {
1012 ATH_MSG_DEBUG(
"Found " << resolvedInDetCandidates.size() <<
" inner detector tags in event "
1013 << ctx.eventID().event_number());
1014 for (const InDetCandidateTags& candidate : resolvedInDetCandidates) {
1015 std::stringstream
tags;
1016 for (
const TagBase* tag : candidate.second)
tags <<
" " <<
tag->toString();
1017 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " <<
tags.str());
1018 }
1019 }
1020
1022
1023 to_resolve.reserve(resolvedInDetCandidates.size());
1024 garbage_collection.reserve(resolvedInDetCandidates.size());
1025
1026
1027
1028 std::map<const Trk::Track*, InDetCandidateTags> trackInDetCandLinks;
1029
1030 for (InDetCandidateTags& candidate : resolvedInDetCandidates) {
1031
1032 const TagBase* primaryTag = candidate.second[0];
1033
1034
1035 if (primaryTag->primaryTrack()) {
1037 to_resolve.
push_back(primaryTag->primaryTrack());
1038
1039 trackInDetCandLinks[to_resolve.
back()] = std::move(candidate);
1040 }
1041
1042
1043 else {
1044 std::vector<const Muon::MuonSegment*> segments = primaryTag->associatedSegments();
1045 if (!segments.empty()) {
1047 garbage_collection.emplace_back(
1048 createDummyTrack(ctx, primaryTag->associatedSegments(), *(candidate.first->indetTrackParticle().track())));
1050 to_resolve.
push_back(garbage_collection.back().get());
1052 trackInDetCandLinks[garbage_collection.back().get()] = std::move(candidate);
1053 }
1054 }
1055 }
1056 resolvedInDetCandidates.clear();
1057
1058
1060
1061
1062 for (const Trk::Track* track : *resolvedTracks) {
1063 std::map<const Trk::Track*, InDetCandidateTags>::iterator trackCandLink = trackInDetCandLinks.find(track);
1064 if (trackCandLink == trackInDetCandLinks.end()) {
1065 ATH_MSG_WARNING(
"Unable to find internal link between MS track and ID candidate!");
1066 continue;
1067 }
1068 resolvedInDetCandidates.push_back(std::move(trackCandLink->second));
1069 }
1070
1071
1072 if (msgLvl(MSG::VERBOSE)) {
1074 << resolvedInDetCandidates.size() << " trackCandLinks: " << trackInDetCandLinks.size()
1075 << " to_resolve: " << to_resolve.size() << " resolvedTracks: " << resolvedTracks->size());
1076 for (const InDetCandidateTags& candidate : resolvedInDetCandidates) {
1077 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " << candidate.second[0]->toString());
1078 }
1080 for (const InDetCandidateTags& candidate : caloMuons) {
1081 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " << candidate.second[0]->toString());
1082 }
1083 }
1084
1085 resolvedInDetCandidates.insert(resolvedInDetCandidates.end(), caloMuons.begin(), caloMuons.end());
1086
1087
1088 std::stable_sort(resolvedInDetCandidates.begin(), resolvedInDetCandidates.end(),
1089 [](
const InDetCandidateTags&
a,
const InDetCandidateTags& b) {
1090 return a.first->indetTrackParticle().pt() > b.first->indetTrackParticle().pt();
1091 });
1092 }
1093
1094
1095
1096 if (!muonCandidates) { return; }
1097
1098 if (msgLvl(MSG::DEBUG)) {
1100 for (
const MuonCandidate* candidate : *muonCandidates) {
ATH_MSG_DEBUG(
"Muon candidate: " << candidate->toString()); }
1101 }
1102
1104 if (resolvedTracks) { resolvedTracks2.
assign(resolvedTracks->begin(), resolvedTracks->end()); }
1105
1106 std::set<const MuonCandidate*> used_candidates;
1107 for (const InDetCandidateTags& indet_cand : resolvedInDetCandidates) {
1108 for (const TagBase* tag : indet_cand.second) {
1110 if (
tag->author() == xAOD::Muon::Author::MuidCo) {
1111 const CombinedFitTag* cmb_tag =
dynamic_cast<const CombinedFitTag*
>(
tag);
1112 used_candidates.insert(&cmb_tag->muonCandidate());
1113 }
else if (
tag->author() == xAOD::Muon::Author::STACO && indet_cand.second[0] == tag) {
1114 const StacoTag* staco_tag =
dynamic_cast<const StacoTag*
>(
tag);
1115 used_candidates.insert(&staco_tag->muonCandidate());
1116 }
1117 }
1118 }
1119
1120
1121
1122 std::map<const Trk::Track*, const MuonCandidate*> trackMuonCandLinks;
1123 for (const MuonCandidate* candidate : *muonCandidates) {
1124 const Trk::Track*
track = candidate->primaryTrack();
1125 if (used_candidates.count(candidate)) {
1127 continue;
1128 }
1129 used_candidates.insert(candidate);
1131 trackMuonCandLinks[
track] = candidate;
1132 }
1133
1134
1136
1137
1138 for (const Trk::Track* track : *resolvedTracks) {
1139 auto trackCandLink = trackMuonCandLinks.find(track);
1140 if (trackCandLink != trackMuonCandLinks.end()) resolvedMuonCandidates.push_back(trackCandLink->second);
1141 }
1142
1143
1144 if (msgLvl(MSG::DEBUG)) {
1145 ATH_MSG_DEBUG(
"Muon candidates: " << muonCandidates->size() <<
" after ambiguity solving " << resolvedMuonCandidates.size());
1146 for (const MuonCandidate* candidate : resolvedMuonCandidates) {
1147 msg(MSG::DEBUG) <<
"Muon candidate: " << candidate->toString() <<
endmsg;
1148 }
1149 }
1150 }
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ElementProxy back()
Access the last element in the collection as an lvalue.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
void assign(InputIterator first, InputIterator last)
Assign from iterators.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.