ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCandSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "MdtCandSelector.h"
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::L1TGCCandData &candidate) {
21 return {candidate.l1SubdetectorId(), candidate.l1SectorId()};
22}
23
24} // namespace
25
26namespace L1Muon::L1TGC {
27
28std::unique_ptr<xAOD::L1TGCCandDataContainer> MdtCandSelector::select(
29 xAOD::L1TGCCandDataContainer &candidates) const {
30 auto output = std::make_unique<xAOD::L1TGCCandDataContainer>(SG::VIEW_ELEMENTS);
31 std::vector<xAOD::L1TGCCandData *> orderedCandidates;
32 orderedCandidates.reserve(candidates.size());
33 for (xAOD::L1TGCCandData *candidate : candidates) {
34 if (candidate->tcId() == 0U)
35 continue;
36 orderedCandidates.emplace_back(candidate);
37 }
38
40 orderedCandidates.begin(), orderedCandidates.end(),
41 [](const xAOD::L1TGCCandData *left, const xAOD::L1TGCCandData *right) {
42 const CandidateGroup leftGroup = candidateGroup(*left);
43 const CandidateGroup rightGroup = candidateGroup(*right);
44 if (leftGroup != rightGroup)
45 return leftGroup < rightGroup;
46 return left->l1Pt() > right->l1Pt();
47 });
48
49 CandidateGroup currentGroup{};
50 bool haveCurrentGroup{false};
51 std::size_t groupCandidate{0U};
52 for (xAOD::L1TGCCandData *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 L1Muon::L1TGC
std::unique_ptr< xAOD::L1TGCCandDataContainer > select(xAOD::L1TGCCandDataContainer &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 l1SectorId() const
Retrieve the sector id.
uint8_t tcId() const
Retrieve the trigger-candidate identifier.
uint16_t l1SubdetectorId() const
Retrieve the sub detector id.
@ 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.
L1TGCCandData_v1 L1TGCCandData
L1TGCCandDataContainer_v1 L1TGCCandDataContainer