ATLAS Offline Software
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 
5 #include "L1TriggerResultMaker.h"
9 
10 namespace {
11  template<class T> void makeLink(const SG::ReadHandleKey<T>& rhk,
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,
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 // =============================================================================
36 L1TriggerResultMaker::L1TriggerResultMaker(const std::string& name, ISvcLocator* svcLoc)
37 : AthReentrantAlgorithm(name, svcLoc) {}
38 
39 // =============================================================================
40 // Implementation of AthReentrantAlgorithm::initialize
41 // =============================================================================
43  ATH_MSG_DEBUG("Initialising " << name());
44  ATH_CHECK(m_l1TriggerResultWHKey.initialize());
45  ATH_CHECK(m_muRoIKey.initialize(SG::AllowEmpty));
51  ATH_CHECK(m_cjTauLinkKey.initialize(!m_cjTauLinkKey.empty()));
57  return StatusCode::SUCCESS;
58 }
59 
60 // =============================================================================
61 // Implementation of AthReentrantAlgorithm::execute
62 // =============================================================================
63 StatusCode 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 // =============================================================================
115 StatusCode 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
120  using jTauLink_t = ElementLink<xAOD::jFexTauRoIContainer>;
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 }
L1TriggerResultMaker.h
max
#define max(a, b)
Definition: cfImp.cxx:41
L1TriggerResultMaker::m_jFexLRJetRoIKey
SG::ReadHandleKey< xAOD::jFexLRJetRoIContainer > m_jFexLRJetRoIKey
Definition: L1TriggerResultMaker.h:76
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ViewHelper::makeLink
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:291
L1TriggerResultMaker::m_jFexSRJetRoIKey
SG::ReadHandleKey< xAOD::jFexSRJetRoIContainer > m_jFexSRJetRoIKey
Definition: L1TriggerResultMaker.h:71
L1TriggerResultMaker::m_gFexLRJetRoIKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexLRJetRoIKey
Definition: L1TriggerResultMaker.h:86
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
L1TriggerResultMaker::execute
virtual StatusCode execute(const EventContext &eventContext) const override
Definition: L1TriggerResultMaker.cxx:63
L1TriggerResultMaker::m_jFexFwdElRoIKey
SG::ReadHandleKey< xAOD::jFexFwdElRoIContainer > m_jFexFwdElRoIKey
Definition: L1TriggerResultMaker.h:61
L1TriggerResultMaker::m_cjTauLinkKey
SG::WriteDecorHandleKey< xAOD::eFexTauRoIContainer > m_cjTauLinkKey
Definition: L1TriggerResultMaker.h:96
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
xAOD::eFexTauRoI_v1
Class describing a LVL1 eFEX tau region of interest.
Definition: eFexTauRoI_v1.h:29
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
L1TriggerResultMaker::m_muRoIKey
SG::ReadHandleKey< xAOD::MuonRoIContainer > m_muRoIKey
Definition: L1TriggerResultMaker.h:46
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
L1TriggerResultMaker::m_l1TriggerResultWHKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultWHKey
Definition: L1TriggerResultMaker.h:41
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
cTauMultiplicity.h
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
TrigCompositeAuxContainer.h
L1TriggerResultMaker::m_thresholdPatternTools
ToolHandleArray< IRoIThresholdsTool > m_thresholdPatternTools
Definition: L1TriggerResultMaker.h:101
TCS::cTauMultiplicity::cTauMatching
static size_t cTauMatching(const xAOD::eFexTauRoI &eTau, const xAOD::jFexTauRoIContainer &jTauRoIs)
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:212
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
L1TriggerResultMaker::m_cTauRoIKey
SG::WriteHandleKey< xAOD::eFexTauRoIContainer > m_cTauRoIKey
Definition: L1TriggerResultMaker.h:91
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
L1TriggerResultMaker::m_eFexEMRoIKey
SG::ReadHandleKey< xAOD::eFexEMRoIContainer > m_eFexEMRoIKey
Definition: L1TriggerResultMaker.h:51
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
L1TriggerResultMaker::m_eFexTauRoIKey
SG::ReadHandleKey< xAOD::eFexTauRoIContainer > m_eFexTauRoIKey
Definition: L1TriggerResultMaker.h:56
copySelective.target
string target
Definition: copySelective.py:37
eFexTauRoIAuxContainer.h
L1TriggerResultMaker::initialize
virtual StatusCode initialize() override
Definition: L1TriggerResultMaker.cxx:42
L1TriggerResultMaker::L1TriggerResultMaker
L1TriggerResultMaker(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
Definition: L1TriggerResultMaker.cxx:36
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
L1TriggerResultMaker::createCombinedTauRoIs
StatusCode createCombinedTauRoIs(xAOD::TrigComposite &l1tr, const EventContext &eventContext) const
Create the combined Tau container matching eTau to jTau.
Definition: L1TriggerResultMaker.cxx:115
L1TriggerResultMaker::m_jFexTauRoIKey
SG::ReadHandleKey< xAOD::jFexTauRoIContainer > m_jFexTauRoIKey
Definition: L1TriggerResultMaker.h:66
L1TriggerResultMaker::m_gFexSRJetRoIKey
SG::ReadHandleKey< xAOD::gFexJetRoIContainer > m_gFexSRJetRoIKey
Definition: L1TriggerResultMaker.h:81
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37