ATLAS Offline Software
Loading...
Searching...
No Matches
L1TriggerResultMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10namespace {
11 template<class T> void makeLink(const SG::ReadHandleKey<T>& rhk,
12 xAOD::TrigComposite& target,
13 const std::string& linkName,
14 const EventContext& eventContext) {
15 ElementLink<T> link = ElementLink<T>(rhk.key(), 0, eventContext);
16 target.typelessSetObjectLink(linkName,
17 link.key(),
19 /*beginIndex =*/ 0);
20 }
21 template<class T> void makeLink(const SG::WriteHandleKey<T>& rhk,
22 xAOD::TrigComposite& target,
23 const std::string& linkName,
24 const EventContext& eventContext) {
25 ElementLink<T> link = ElementLink<T>(rhk.key(), 0, eventContext);
26 target.typelessSetObjectLink(linkName,
27 link.key(),
29 /*beginIndex =*/ 0);
30 }
31}
32
33// =============================================================================
34// Standard constructor
35// =============================================================================
36L1TriggerResultMaker::L1TriggerResultMaker(const std::string& name, ISvcLocator* svcLoc)
37: AthReentrantAlgorithm(name, svcLoc) {}
38
39// =============================================================================
40// Implementation of AthReentrantAlgorithm::initialize
41// =============================================================================
59
60// =============================================================================
61// Implementation of AthReentrantAlgorithm::execute
62// =============================================================================
63StatusCode L1TriggerResultMaker::execute(const EventContext& eventContext) const {
64 ATH_MSG_DEBUG("Executing " << name());
65
66 // Create and record the L1TriggerResult container
68 auto cont = std::make_unique<xAOD::TrigCompositeContainer>();
69 auto auxcont = std::make_unique<xAOD::TrigCompositeAuxContainer>();
70 cont->setStore(auxcont.get());
71 ATH_CHECK(l1trHandle.record(std::move(cont), std::move(auxcont)));
72 ATH_MSG_DEBUG("Recorded L1TriggerResult with key " << m_l1TriggerResultWHKey.key());
73
74 // Create new L1TriggerResult in the container
75 l1trHandle->push_back(std::make_unique<xAOD::TrigComposite>());
76
77 // For all RoI types, find it in the event store and link to the L1TriggerResult
78 auto retrieveAndLink = [this, &eventContext, &l1trHandle](auto key) -> StatusCode {
79 // Skip disabled inputs
80 if (key.empty()) {return StatusCode::SUCCESS;}
81 // Retrieve the L1 xAOD container to verify it exists
82 auto handle = SG::makeHandle(key, eventContext);
83 ATH_CHECK(handle.isValid());
84 // Link the L1 xAOD container (actually its first element) to L1TriggerResult
85 ATH_MSG_DEBUG(key.key() << " size: " << handle->size());
86 if (not handle->empty()) {
87 makeLink(key, *(l1trHandle->back()), key.key(), eventContext);
88 }
89 return StatusCode::SUCCESS;
90 };
91
92 ATH_CHECK(retrieveAndLink(m_muRoIKey));
93 ATH_CHECK(retrieveAndLink(m_eFexEMRoIKey));
94 ATH_CHECK(retrieveAndLink(m_eFexTauRoIKey));
95 ATH_CHECK(retrieveAndLink(m_jFexFwdElRoIKey));
96 ATH_CHECK(retrieveAndLink(m_jFexTauRoIKey));
97 ATH_CHECK(retrieveAndLink(m_jFexSRJetRoIKey));
98 ATH_CHECK(retrieveAndLink(m_jFexLRJetRoIKey));
99 ATH_CHECK(retrieveAndLink(m_gFexSRJetRoIKey));
100 ATH_CHECK(retrieveAndLink(m_gFexLRJetRoIKey));
101
102 // Create combined Taus and link them to the L1TR
103 ATH_CHECK(createCombinedTauRoIs(*(l1trHandle->back()), eventContext));
104
105 for (const auto& tool: m_thresholdPatternTools) {
106 ATH_CHECK(tool->decorateThresholds(eventContext));
107 }
108
109 return StatusCode::SUCCESS;
110}
111
112// =============================================================================
113// Create the combined Tau container matching eTau to jTau
114// =============================================================================
115StatusCode L1TriggerResultMaker::createCombinedTauRoIs(xAOD::TrigComposite& l1tr, const EventContext& eventContext) const {
116 // Skip if keys set to empty
117 if (m_cTauRoIKey.empty() or m_cjTauLinkKey.empty()) {return StatusCode::SUCCESS;}
118
119 // Create handles
125 ATH_CHECK(eTauRoIs.isValid());
126 ATH_CHECK(jTauRoIs.isValid());
127
128 // Create and record the new eTau container for cTaus
129 ATH_CHECK(cTauRoIs.record(std::make_unique<xAOD::eFexTauRoIContainer>(),
130 std::make_unique<xAOD::eFexTauRoIAuxContainer>()));
131
132 // Match jTaus to eTaus and add the resulting cTaus to the container
133 // Unmatched eTaus get added as cTau with invalid link to jTau, ATR-25927
134 size_t i_eTau{0};
135 size_t n_matched{0};
136 for (const xAOD::eFexTauRoI* eTau : *eTauRoIs) {
137 // Add new eTau to the cTau container
138 cTauRoIs->push_back(std::make_unique<xAOD::eFexTauRoI>());
139 // Copy over all variables from the original eTau
140 *cTauRoIs->back() = *eTau;
141
142 const size_t i_jTau = TCS::cTauMultiplicity::cTauMatching(*eTau, *jTauRoIs);
143 if (i_jTau==std::numeric_limits<size_t>::max()) {
144 ATH_MSG_DEBUG("No matching jTau for eTau index " << i_eTau);
145 // Add an invalid link to jTau
146 cjTauLink(*cTauRoIs->back()) = jTauLink_t{};
147 } else {
148 ++n_matched;
149 ATH_MSG_DEBUG("Matched jTau index " << i_jTau << " to eTau index " << i_eTau);
150 // Link the matched jTau
151 cjTauLink(*cTauRoIs->back()) = jTauLink_t{m_jFexTauRoIKey.key(), i_jTau, eventContext};
152 }
153 ++i_eTau;
154 }
155
156 // Link the cTaus to the L1TriggerResult
157 ATH_MSG_DEBUG(m_eFexTauRoIKey.key() << " size: " << eTauRoIs->size());
158 ATH_MSG_DEBUG(m_jFexTauRoIKey.key() << " size: " << jTauRoIs->size());
159 ATH_MSG_DEBUG(m_cTauRoIKey.key() << " size: " << cTauRoIs->size() << ", matched: " << n_matched);
160 if (not cTauRoIs->empty()) {
161 makeLink(m_cTauRoIKey, l1tr, m_cTauRoIKey.key(), eventContext);
162 }
163
164 return StatusCode::SUCCESS;
165}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
An algorithm that can be simultaneously executed in multiple threads.
SG::ReadHandleKey< xAOD::jFexTauRoIContainer > m_jFexTauRoIKey
SG::ReadHandleKey< xAOD::jFexFwdElRoIContainer > m_jFexFwdElRoIKey
SG::WriteHandleKey< xAOD::eFexTauRoIContainer > m_cTauRoIKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultWHKey
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::eFexTauRoIContainer > m_eFexTauRoIKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEMRoIKey
SG::ReadHandleKey< xAOD::jFexSRJetRoIContainer > m_jFexSRJetRoIKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexLRJetRoIKey
SG::ReadHandleKey< xAOD::jFexLRJetRoIContainer > m_jFexLRJetRoIKey
SG::ReadHandleKey< xAOD::MuonRoIContainer > m_muRoIKey
L1TriggerResultMaker(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
SG::WriteDecorHandleKey< xAOD::eFexTauRoIContainer > m_cjTauLinkKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexSRJetRoIKey
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)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.
Definition ViewHelper.h:309
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