ATLAS Offline Software
Loading...
Searching...
No Matches
HitsSelectorAlg.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
10
12#include "xAODJet/Jet.h"
13
14#include "CxxUtils/phihelper.h"
15
16#include <algorithm>
17#include <cmath>
18#include <cstddef>
19#include <vector>
20
21namespace FlavorTagDiscriminants {
22
23 HitsSelectorAlg::HitsSelectorAlg(const std::string& name, ISvcLocator* svcLoc)
24 : AthReentrantAlgorithm(name, svcLoc) {}
25
27 ATH_MSG_DEBUG("Initializing " << name());
28
29 m_usePixel = !m_pixelAssocKey.empty();
30 m_useSCT = !m_sctAssocKey.empty();
31
32 if (!m_usePixel && !m_useSCT) {
33 ATH_MSG_ERROR("No hits to select: set PixelAssociation, SCTAssociation, or both");
34 return StatusCode::FAILURE;
35 }
36 ATH_MSG_INFO("Selecting hits from" << (m_usePixel ? " Pixel" : "")
37 << (m_useSCT ? " SCT" : "") << ", keeping at most "
38 << m_maxHits.value() << " per jet");
39
40 ATH_CHECK(m_jetsKey.initialize());
41
47
48 ATH_CHECK(m_sctAssocKey.initialize(m_useSCT));
49 ATH_CHECK(m_sctHitsKey.initialize(m_useSCT));
50 ATH_CHECK(m_sctHitXKey.initialize(m_useSCT));
51 ATH_CHECK(m_sctHitYKey.initialize(m_useSCT));
52 ATH_CHECK(m_sctCleanKey.initialize(m_useSCT));
53
54 ATH_CHECK(m_hitAssocKey.initialize());
55
56 return StatusCode::SUCCESS;
57 }
58
59 // Append the clean hits of one subdetector to every jet's list, keeping the
60 // |dphi| to the jet axis alongside each link so the merged list can be sorted
62 const EventContext& ctx,
67 const xAOD::JetContainer& jets,
68 std::vector<std::vector<SortedHit>>& hitsPerJet) const {
69
71 const SG::ReadDecorHandle<HitContainer, float> hitX(xKey, ctx);
72 const SG::ReadDecorHandle<HitContainer, float> hitY(yKey, ctx);
73 const SG::ReadDecorHandle<HitContainer, int> isClean(cleanKey, ctx);
74
75 for (std::size_t iJet = 0; iJet < jets.size(); ++iJet) {
76
77 const xAOD::Jet& jet = *jets[iJet];
78 const float jetPhi = jet.phi();
79 std::vector<SortedHit>& out = hitsPerJet[iJet];
80
81 for (const HitLink& el : assoc(jet)) {
82 if (!el.isValid()) {
83 ATH_MSG_ERROR("Invalid hit link in " << assocKey.key() << " on jet " << iJet);
84 return StatusCode::FAILURE;
85 }
87 if (!isClean(hit)) continue;
88
89 const float hitPhi = std::atan2(hitY(hit), hitX(hit));
90 out.push_back({el, std::abs(CxxUtils::wrapToPi(jetPhi - hitPhi))});
91 }
92 }
93
94 return StatusCode::SUCCESS;
95 }
96
97 StatusCode HitsSelectorAlg::execute(const EventContext& ctx) const {
98
100 if (!jets.isValid()) {
101 ATH_MSG_ERROR("Cannot read jets " << m_jetsKey.key());
102 return StatusCode::FAILURE;
103 }
104
105 std::vector<std::vector<SortedHit>> hitsPerJet(jets->size());
106
107 if (m_usePixel) {
109 m_pixelCleanKey, *jets, hitsPerJet));
110 }
111 if (m_useSCT) {
113 m_sctCleanKey, *jets, hitsPerJet));
114 }
115
117 cleanMergedAssoc(m_hitAssocKey, ctx);
118
119 for (std::size_t iJet = 0; iJet < jets->size(); ++iJet) {
120
121 std::vector<SortedHit>& sorted = hitsPerJet[iJet];
122
123 std::sort(sorted.begin(), sorted.end(),
124 [](const SortedHit& a, const SortedHit& b) {
125 return a.dphi < b.dphi;
126 });
127
128 if (sorted.size() > static_cast<std::size_t>(m_maxHits)) {
129 sorted.resize(m_maxHits);
130 }
131
132 std::vector<HitLink> outEL;
133 outEL.reserve(sorted.size());
134 for (const SortedHit& sh : sorted) {
135 outEL.push_back(sh.link);
136 }
137
138 cleanMergedAssoc(*(*jets)[iJet]) = std::move(outEL);
139 }
140
141 return StatusCode::SUCCESS;
142 }
143
144}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
bool hit(const Container &ids, int pdgId)
static Double_t a
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadDecorHandleKey< xAOD::JetContainer > m_pixelAssocKey
SG::ReadDecorHandleKey< HitContainer > m_pixelHitXKey
virtual StatusCode initialize() override
SG::ReadHandleKey< HitContainer > m_sctHitsKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_sctAssocKey
HitsSelectorAlg(const std::string &name, ISvcLocator *svcLoc)
StatusCode collectHits(const EventContext &ctx, const SG::ReadDecorHandleKey< xAOD::JetContainer > &assocKey, const SG::ReadDecorHandleKey< HitContainer > &xKey, const SG::ReadDecorHandleKey< HitContainer > &yKey, const SG::ReadDecorHandleKey< HitContainer > &cleanKey, const xAOD::JetContainer &jets, std::vector< std::vector< SortedHit > > &hitsPerJet) const
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadDecorHandleKey< HitContainer > m_sctCleanKey
SG::ReadDecorHandleKey< HitContainer > m_pixelHitYKey
ElementLink< HitContainer > HitLink
SG::ReadHandleKey< HitContainer > m_pixelHitsKey
SG::ReadDecorHandleKey< HitContainer > m_pixelCleanKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetsKey
SG::ReadDecorHandleKey< HitContainer > m_sctHitXKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_hitAssocKey
SG::ReadDecorHandleKey< HitContainer > m_sctHitYKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
const std::string & key() const
Return the StoreGate ID for the referenced object.
Handle class for adding a decoration to an object.
constexpr T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:31
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
TrackMeasurementValidation_v1 TrackMeasurementValidation
Reference the current persistent version:
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Helper for azimuthal angle calculations.