ATLAS Offline Software
Loading...
Searching...
No Matches
TgcL0MdtCandidateSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <algorithm>
8#include <cstdint>
9#include <memory>
10#include <utility>
11#include <vector>
12
15
16namespace {
17
18using CandidateGroup = std::pair<std::uint16_t, std::uint16_t>;
19
20CandidateGroup candidateGroup(const xAOD::TGCCandData &candidate) {
21 return {candidate.subdetectorId(), candidate.sectorId()};
22}
23
24} // namespace
25
26namespace L0Muon {
27
28std::unique_ptr<xAOD::TGCCandDataContainer> TgcL0MdtCandidateSelector::select(
29 xAOD::TGCCandDataContainer &candidates) const {
30 auto output = std::make_unique<xAOD::TGCCandDataContainer>(SG::VIEW_ELEMENTS);
31 std::vector<xAOD::TGCCandData *> orderedCandidates;
32 orderedCandidates.reserve(candidates.size());
33 for (xAOD::TGCCandData *candidate : candidates) {
34 if (candidate->tcId() == 0U)
35 continue;
36 orderedCandidates.emplace_back(candidate);
37 }
38
40 orderedCandidates.begin(), orderedCandidates.end(),
41 [](const xAOD::TGCCandData *left, const xAOD::TGCCandData *right) {
42 const CandidateGroup leftGroup = candidateGroup(*left);
43 const CandidateGroup rightGroup = candidateGroup(*right);
44 if (leftGroup != rightGroup)
45 return leftGroup < rightGroup;
46 return left->pt() > right->pt();
47 });
48
49 CandidateGroup currentGroup{};
50 bool haveCurrentGroup{false};
51 std::size_t groupCandidate{0U};
52 for (xAOD::TGCCandData *candidate : orderedCandidates) {
53 const CandidateGroup group = candidateGroup(*candidate);
54 if (!haveCurrentGroup || group != currentGroup) {
55 currentGroup = group;
56 haveCurrentGroup = true;
57 groupCandidate = 0U;
58 }
59 if (groupCandidate >= s_maxCandidatesPerSector)
60 continue;
61
62 ++groupCandidate;
63 output->push_back(candidate);
64 }
65 return output;
66}
67
68} // namespace L0Muon
std::unique_ptr< xAOD::TGCCandDataContainer > select(xAOD::TGCCandDataContainer &candidates) const
Create a non-owning view of the three candidates with the highest encoded pT per sector for one BC pr...
static constexpr std::size_t s_maxCandidatesPerSector
uint16_t sectorId() const
Retrieve the sector id.
uint16_t subdetectorId() const
Retrieve the sub detector id.
uint8_t tcId() const
Retrieve the trigger-candidate identifier.
@ 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.