ATLAS Offline Software
Loading...
Searching...
No Matches
L1TriggerResultMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9#include <limits>
10
11namespace {
12 template<class T> void makeLink(const SG::ReadHandleKey<T>& rhk,
13 xAOD::TrigComposite& target,
14 const std::string& linkName,
15 const EventContext& eventContext) {
16 ElementLink<T> link = ElementLink<T>(rhk.key(), 0, eventContext);
17 target.typelessSetObjectLink(linkName,
18 link.key(),
20 /*beginIndex =*/ 0);
21 }
22 template<class T> void makeLink(const SG::WriteHandleKey<T>& rhk,
23 xAOD::TrigComposite& target,
24 const std::string& linkName,
25 const EventContext& eventContext) {
26 ElementLink<T> link = ElementLink<T>(rhk.key(), 0, eventContext);
27 target.typelessSetObjectLink(linkName,
28 link.key(),
30 /*beginIndex =*/ 0);
31 }
32}
33
34// =============================================================================
35// Standard constructor
36// =============================================================================
37L1TriggerResultMaker::L1TriggerResultMaker(const std::string& name, ISvcLocator* svcLoc)
38: AthReentrantAlgorithm(name, svcLoc) {}
39
40// =============================================================================
41// Implementation of AthReentrantAlgorithm::initialize
42// =============================================================================
63
64// =============================================================================
65// Implementation of AthReentrantAlgorithm::execute
66// =============================================================================
67StatusCode L1TriggerResultMaker::execute(const EventContext& eventContext) const {
68 ATH_MSG_DEBUG("Executing " << name());
69
70 // Create and record the L1TriggerResult container
72 auto cont = std::make_unique<xAOD::TrigCompositeContainer>();
73 auto auxcont = std::make_unique<xAOD::TrigCompositeAuxContainer>();
74 cont->setStore(auxcont.get());
75 ATH_CHECK(l1trHandle.record(std::move(cont), std::move(auxcont)));
76 ATH_MSG_DEBUG("Recorded L1TriggerResult with key " << m_l1TriggerResultWHKey.key());
77
78 // Create new L1TriggerResult in the container
79 l1trHandle->push_back(std::make_unique<xAOD::TrigComposite>());
80
81 // For all RoI types, find it in the event store and link to the L1TriggerResult
82 auto retrieveAndLink = [this, &eventContext, &l1trHandle](const auto &keys) -> StatusCode {
83 for(const auto& key : keys) {
84 // Skip disabled inputs
85 if (key.empty()) { continue; }
86 // Retrieve the L1 xAOD container to verify it exists
87 auto handle = SG::makeHandle(key, eventContext);
88 ATH_CHECK(handle.isValid());
89 // Link the L1 xAOD container (actually its first element) to L1TriggerResult
90 ATH_MSG_DEBUG(key.key() << " size: " << handle->size());
91 if (not handle->empty()) {
92 makeLink(key, *(l1trHandle->back()), key.key(), eventContext);
93 }
94 }
95 return StatusCode::SUCCESS;
96 };
97
98 ATH_CHECK(retrieveAndLink(m_muRoIKeys));
99 ATH_CHECK(retrieveAndLink(m_eFexEMRoIKeys));
100 ATH_CHECK(retrieveAndLink(m_eFexTauRoIKeys));
101 ATH_CHECK(retrieveAndLink(m_jFexFwdElRoIKeys));
102 ATH_CHECK(retrieveAndLink(m_jFexTauRoIKeys));
103 ATH_CHECK(retrieveAndLink(m_jFexSRJetRoIKeys));
104 ATH_CHECK(retrieveAndLink(m_jFexLRJetRoIKeys));
105 ATH_CHECK(retrieveAndLink(m_gFexSRJetRoIKeys));
106 ATH_CHECK(retrieveAndLink(m_gFexLRJetRoIKeys));
107 ATH_CHECK(retrieveAndLink(m_gScalarEJwojKeys));
108 ATH_CHECK(retrieveAndLink(m_gMETComponentsJwojKeys));
109
110 // If including CTPResult, need to treat it separately as it is not stored using a DataVector
111 if (!m_CTPKey.empty()) {
112 SG::ReadHandle<xAOD::CTPResult> ctpReadHandle(m_CTPKey, eventContext);
113 ATH_CHECK(ctpReadHandle.isValid());
114 ATH_CHECK(l1trHandle->back()->setDetail<std::string>("CTPResultKey", m_CTPKey.key()));
115 }
116
117 // Create combined Taus and link them to the L1TR
118 ATH_CHECK(createCombinedTauRoIs(*(l1trHandle->back()), eventContext));
119
120 for (const auto& tool: m_thresholdPatternTools) {
121 ATH_CHECK(tool->decorateThresholds(eventContext));
122 }
123
124 return StatusCode::SUCCESS;
125}
126
127// =============================================================================
128// Create the combined Tau container matching eTau to jTau
129// =============================================================================
130StatusCode L1TriggerResultMaker::createCombinedTauRoIs(xAOD::TrigComposite& l1tr, const EventContext& eventContext) const {
131 // Skip if keys set to empty
132 if (m_cTauRoIKey.empty() or m_cjTauLinkKey.empty()) {return StatusCode::SUCCESS;}
133
134 // Create handles
136
139
140
141 // Create and record the new eTau container for cTaus
142 ATH_CHECK(cTauRoIs.record(std::make_unique<xAOD::eFexTauRoIContainer>(),
143 std::make_unique<xAOD::eFexTauRoIAuxContainer>()));
144
145 size_t n_matched{0};
146 for(auto& jTauKey : m_jFexTauRoIKeys) {
147 SG::ReadHandle <xAOD::jFexTauRoIContainer> jTauRoIs{jTauKey, eventContext};
148 ATH_CHECK(jTauRoIs.isValid());
149 for (auto &eTauKey: m_eFexTauRoIKeys) {
150 SG::ReadHandle <xAOD::eFexTauRoIContainer> eTauRoIs{eTauKey, eventContext};
151 ATH_CHECK(eTauRoIs.isValid());
152 // Match jTaus to eTaus and add the resulting cTaus to the container
153 // Unmatched eTaus get added as cTau with invalid link to jTau, ATR-25927
154 size_t i_eTau{0};
155 for (const xAOD::eFexTauRoI *eTau: *eTauRoIs) {
156 // Add new eTau to the cTau container
157 cTauRoIs->push_back(std::make_unique<xAOD::eFexTauRoI>());
158 // Copy over all variables from the original eTau
159 *cTauRoIs->back() = *eTau;
160
161 const size_t i_jTau = TCS::cTauMultiplicity::cTauMatching(*eTau, *jTauRoIs);
162 if (i_jTau == std::numeric_limits<size_t>::max()) {
163 ATH_MSG_DEBUG("No matching jTau for eTau index " << i_eTau);
164 // Add an invalid link to jTau
165 cjTauLink(*cTauRoIs->back()) = jTauLink_t{};
166 } else {
167 ++n_matched;
168 ATH_MSG_DEBUG("Matched jTau index " << i_jTau << " to eTau index " << i_eTau);
169 // Link the matched jTau
170 cjTauLink(*cTauRoIs->back()) = jTauLink_t{jTauKey.key(), i_jTau, eventContext};
171 }
172 ++i_eTau;
173 }
174
175
176 ATH_MSG_DEBUG(eTauKey.key() << " size: " << eTauRoIs->size());
177 }
178 ATH_MSG_DEBUG(jTauKey.key() << " size: " << jTauRoIs->size());
179 }
180 ATH_MSG_DEBUG(m_cTauRoIKey.key() << " size: " << cTauRoIs->size() << ", matched: " << n_matched);
181 // Link the cTaus to the L1TriggerResult
182 if (not cTauRoIs->empty()) {
183 makeLink(m_cTauRoIKey, l1tr, m_cTauRoIKey.key(), eventContext);
184 }
185
186 return StatusCode::SUCCESS;
187}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
ElementLink< xAOD::TrackParticleContainer > makeLink(const xAOD::TrackParticle *track)
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteHandleKey< xAOD::eFexTauRoIContainer > m_cTauRoIKey
SG::ReadHandleKeyArray< xAOD::jFexSRJetRoIContainer > m_jFexSRJetRoIKeys
SG::ReadHandleKeyArray< xAOD::jFexTauRoIContainer > m_jFexTauRoIKeys
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultWHKey
SG::ReadHandleKeyArray< xAOD::gFexGlobalRoIContainer > m_gMETComponentsJwojKeys
SG::ReadHandleKeyArray< xAOD::gFexJetRoIContainer > m_gFexSRJetRoIKeys
SG::ReadHandleKeyArray< xAOD::jFexFwdElRoIContainer > m_jFexFwdElRoIKeys
StatusCode createCombinedTauRoIs(xAOD::TrigComposite &l1tr, const EventContext &eventContext) const
Create the combined Tau container matching eTau to jTau.
ToolHandleArray< IRoIThresholdsTool > m_thresholdPatternTools
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::CTPResult > m_CTPKey
SG::ReadHandleKeyArray< xAOD::eFexTauRoIContainer > m_eFexTauRoIKeys
SG::ReadHandleKeyArray< xAOD::gFexJetRoIContainer > m_gFexLRJetRoIKeys
SG::ReadHandleKeyArray< xAOD::eFexEMRoIContainer > m_eFexEMRoIKeys
SG::ReadHandleKeyArray< xAOD::gFexGlobalRoIContainer > m_gScalarEJwojKeys
L1TriggerResultMaker(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
SG::ReadHandleKeyArray< xAOD::MuonRoIContainer > m_muRoIKeys
SG::ReadHandleKeyArray< xAOD::jFexLRJetRoIContainer > m_jFexLRJetRoIKeys
SG::WriteDecorHandleKey< xAOD::eFexTauRoIContainer > m_cjTauLinkKey
virtual StatusCode execute(const EventContext &eventContext) const override
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const std::string & key() const
Return the StoreGate ID for the referenced object.
Handle class for adding a decoration to an object.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static size_t cTauMatching(const xAOD::eFexTauRoI &eTau, const xAOD::jFexTauRoIContainer &jTauRoIs)
pointer & link(pointer p) const
Return a reference to the link for an element.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
eFexTauRoI_v1 eFexTauRoI
Define the latest version of the eFexTauRoI class.
Definition eFexTauRoI.h:16