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
966 {
967 resolvedMuonCandidates.clear();
968 resolvedInDetCandidates.clear();
969
970 std::unique_ptr<const TrackCollection> resolvedTracks;
971 std::vector<std::unique_ptr<Trk::Track>> garbage_collection;
972
977 for (const InDetCandidateToTagMap* tag_map : tagMaps) {
978 if (!tag_map) continue;
979 for (const auto& comb_tag : *tag_map) {
980 const TagBase*
tag = comb_tag.second.get();
984 InDetCandidateTagsMap::iterator itr =
985 std::find_if(inDetCandidateMap.begin(), inDetCandidateMap.end(),
986 [&comb_tag](const InDetCandidateTags& to_test) { return (*to_test.first) == (*comb_tag.first); });
987 if (itr != inDetCandidateMap.end())
988 itr->second.emplace_back(tag);
989 else
990 inDetCandidateMap.emplace_back(std::make_pair(comb_tag.first, std::vector<const TagBase*>{tag}));
991 }
992 }
993
994
995
996
997 if (!inDetCandidateMap.empty()) {
998
999
1001
1002
1003 resolvedInDetCandidates.reserve(inDetCandidateMap.size());
1004 caloMuons.reserve(inDetCandidateMap.size());
1005 for (InDetCandidateTags& comb_tag : inDetCandidateMap) {
1006 std::stable_sort(comb_tag.second.begin(), comb_tag.second.end(), SortTagBasePtr());
1007 if (comb_tag.second.size() == 1 && comb_tag.second.front()->type() == xAOD::Muon::MuonType::CaloTagged) {
1008 caloMuons.emplace_back(std::move(comb_tag));
1009 } else
1010 resolvedInDetCandidates.emplace_back(std::move(comb_tag));
1011 }
1012 inDetCandidateMap.clear();
1013
1014 std::stable_sort(resolvedInDetCandidates.begin(), resolvedInDetCandidates.end(), SortInDetCandidates());
1015 if (msgLvl(MSG::DEBUG)) {
1016 ATH_MSG_DEBUG(
"Found " << resolvedInDetCandidates.size() <<
" inner detector tags in event "
1017 << ctx.eventID().event_number());
1018 for (const InDetCandidateTags& candidate : resolvedInDetCandidates) {
1019 std::stringstream
tags;
1020 for (
const TagBase* tag : candidate.second)
tags <<
" " <<
tag->toString();
1021 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " <<
tags.str());
1022 }
1023 }
1024
1026
1027 to_resolve.reserve(resolvedInDetCandidates.size());
1028 garbage_collection.reserve(resolvedInDetCandidates.size());
1029
1030
1031
1032 std::map<const Trk::Track*, InDetCandidateTags> trackInDetCandLinks;
1033
1034 for (InDetCandidateTags& candidate : resolvedInDetCandidates) {
1035
1036 const TagBase* primaryTag = candidate.second[0];
1037
1038
1039 if (primaryTag->primaryTrack()) {
1041 to_resolve.
push_back(primaryTag->primaryTrack());
1042
1043 trackInDetCandLinks[to_resolve.
back()] = std::move(candidate);
1044 }
1045
1046
1047 else {
1048 std::vector<const Muon::MuonSegment*> segments = primaryTag->associatedSegments();
1049 if (!segments.empty()) {
1051 garbage_collection.emplace_back(
1052 createDummyTrack(ctx, primaryTag->associatedSegments(), *(candidate.first->indetTrackParticle().track())));
1054 to_resolve.
push_back(garbage_collection.back().get());
1056 trackInDetCandLinks[garbage_collection.back().get()] = std::move(candidate);
1057 }
1058 }
1059 }
1060 resolvedInDetCandidates.clear();
1061
1062
1064
1065
1066 for (const Trk::Track* track : *resolvedTracks) {
1067 std::map<const Trk::Track*, InDetCandidateTags>::iterator trackCandLink = trackInDetCandLinks.find(track);
1068 if (trackCandLink == trackInDetCandLinks.end()) {
1069 ATH_MSG_WARNING(
"Unable to find internal link between MS track and ID candidate!");
1070 continue;
1071 }
1072 resolvedInDetCandidates.push_back(std::move(trackCandLink->second));
1073 }
1074
1075
1076 if (msgLvl(MSG::VERBOSE)) {
1078 << resolvedInDetCandidates.size() << " trackCandLinks: " << trackInDetCandLinks.size()
1079 << " to_resolve: " << to_resolve.size() << " resolvedTracks: " << resolvedTracks->size());
1080 for (const InDetCandidateTags& candidate : resolvedInDetCandidates) {
1081 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " << candidate.second[0]->toString());
1082 }
1084 for (const InDetCandidateTags& candidate : caloMuons) {
1085 ATH_MSG_DEBUG(
"ID candidate: " << candidate.first->toString() <<
" " << candidate.second[0]->toString());
1086 }
1087 }
1088
1089 resolvedInDetCandidates.insert(resolvedInDetCandidates.end(), caloMuons.begin(), caloMuons.end());
1090
1091
1092 std::stable_sort(resolvedInDetCandidates.begin(), resolvedInDetCandidates.end(),
1093 [](
const InDetCandidateTags&
a,
const InDetCandidateTags& b) {
1094 return a.first->indetTrackParticle().pt() > b.first->indetTrackParticle().pt();
1095 });
1096 }
1097
1098
1099
1100 if (!muonCandidates) { return; }
1101
1102 if (msgLvl(MSG::DEBUG)) {
1104 for (
const MuonCandidate* candidate : *muonCandidates) {
ATH_MSG_DEBUG(
"Muon candidate: " << candidate->toString()); }
1105 }
1106
1108 if (resolvedTracks) { resolvedTracks2.
assign(resolvedTracks->begin(), resolvedTracks->end()); }
1109
1110 std::set<const MuonCandidate*> used_candidates;
1111 for (const InDetCandidateTags& indet_cand : resolvedInDetCandidates) {
1112 for (const TagBase* tag : indet_cand.second) {
1114 if (
tag->author() == xAOD::Muon::Author::MuidCo) {
1115 const CombinedFitTag* cmb_tag =
dynamic_cast<const CombinedFitTag*
>(
tag);
1116 used_candidates.insert(&cmb_tag->muonCandidate());
1117 }
else if (
tag->author() == xAOD::Muon::Author::STACO && indet_cand.second[0] == tag) {
1118 const StacoTag* staco_tag =
dynamic_cast<const StacoTag*
>(
tag);
1119 used_candidates.insert(&staco_tag->muonCandidate());
1120 }
1121 }
1122 }
1123
1124
1125
1126 std::map<const Trk::Track*, const MuonCandidate*> trackMuonCandLinks;
1127 for (const MuonCandidate* candidate : *muonCandidates) {
1128 const Trk::Track*
track = candidate->primaryTrack();
1129 if (used_candidates.count(candidate)) {
1131 continue;
1132 }
1133 used_candidates.insert(candidate);
1135 trackMuonCandLinks[
track] = candidate;
1136 }
1137
1138
1140
1141
1142 for (const Trk::Track* track : *resolvedTracks) {
1143 auto trackCandLink = trackMuonCandLinks.find(track);
1144 if (trackCandLink != trackMuonCandLinks.end()) resolvedMuonCandidates.push_back(trackCandLink->second);
1145 }
1146
1147
1148 if (msgLvl(MSG::DEBUG)) {
1149 ATH_MSG_DEBUG(
"Muon candidates: " << muonCandidates->size() <<
" after ambiguity solving " << resolvedMuonCandidates.size());
1150 for (const MuonCandidate* candidate : resolvedMuonCandidates) {
1151 msg(MSG::DEBUG) <<
"Muon candidate: " << candidate->toString() <<
endmsg;
1152 }
1153 }
1154 }
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.