ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagJetDecorators
src
VectorExploderAlg.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
/****************************************************************
6
* @file VectorExploderAlg.cxx
7
* @brief Algorithm to "explode" a vector<float> jet decoration into
8
* multiple scalar float decorations, one per vector index.
9
*
10
* Ported from TDD FTagDumper/src/VectorExploderAlg.cxx.
11
* Namespace FlavorTagJetDecorators; hardcoded xAOD::JetContainer.
12
****************************************************************/
13
14
#include "
VectorExploderAlg.h
"
15
16
#include "
StoreGate/ReadDecorHandle.h
"
17
#include "
StoreGate/WriteDecorHandle.h
"
18
19
namespace
FlavorTagJetDecorators
{
20
21
VectorExploderAlg::VectorExploderAlg
(
const
std::string& name,
22
ISvcLocator* pSvcLocator)
23
:
AthReentrantAlgorithm
(name, pSvcLocator) {}
24
25
StatusCode
VectorExploderAlg::initialize
() {
26
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
27
28
ATH_CHECK
(
m_collectionKey
.initialize());
29
ATH_CHECK
(
m_inputVectorKey
.initialize());
30
31
if
(
m_outputNamesMap
.value().empty()) {
32
ATH_MSG_ERROR
(
"OutputNamesMap property must contain at least one entry."
);
33
return
StatusCode::FAILURE;
34
}
35
36
// Create and initialize the output decoration keys.
37
// We MUST reserve first: declare(key) saves a pointer to the key object,
38
// so if the vector resizes the pointer is invalidated → segfault.
39
m_maxIndex
= -1;
40
m_outputKeys
.reserve(
m_outputNamesMap
.value().size());
41
for
(
const
auto
& [
index
, outName] :
m_outputNamesMap
.value()) {
42
if
(
index
>
m_maxIndex
)
m_maxIndex
=
index
;
43
m_outputKeys
.emplace_back(
index
,
44
SG::WriteDecorHandleKey<xAOD::JetContainer>
{
45
m_collectionKey
.key() +
"."
+ outName});
46
auto
& key =
m_outputKeys
.back().second;
47
ATH_CHECK
(key.initialize());
48
declare(key);
49
}
50
51
return
StatusCode::SUCCESS;
52
}
53
54
StatusCode
VectorExploderAlg::execute
(
const
EventContext& ctx)
const
{
55
ATH_MSG_DEBUG
(
"Executing "
<< name() <<
"..."
);
56
57
SG::ReadHandle<xAOD::JetContainer>
collection(
m_collectionKey
, ctx);
58
if
(!collection.
isValid
()) {
59
ATH_MSG_ERROR
(
"Could not retrieve jet collection with key "
60
<<
m_collectionKey
.key());
61
return
StatusCode::FAILURE;
62
}
63
64
// Input read-decor handle for the vector<float> decoration.
65
SG::ReadDecorHandle<xAOD::JetContainer, std::vector<float>
>
66
vectorReader(
m_inputVectorKey
, ctx);
67
68
// Build write handles once per event (not per jet).
69
std::vector<std::pair<int, SG::WriteDecorHandle<xAOD::JetContainer, float>>>
70
outHandles;
71
outHandles.reserve(
m_outputKeys
.size());
72
for
(
const
auto
& [
index
, key] :
m_outputKeys
) {
73
outHandles.emplace_back(
index
,
74
SG::WriteDecorHandle<xAOD::JetContainer, float>
(key, ctx));
75
}
76
77
for
(
const
xAOD::Jet
*
jet
: *collection) {
78
if
(!vectorReader.
isAvailable
()) {
79
ATH_MSG_ERROR
(
"Input vector decoration '"
80
<<
m_inputVectorKey
.key()
81
<<
"' not found for the specified jet collection."
);
82
return
StatusCode::FAILURE;
83
}
84
85
const
auto
& inVec = vectorReader(*
jet
);
86
87
if
(inVec.size() <
static_cast<
size_t
>
(
m_maxIndex
+ 1)) {
88
ATH_MSG_ERROR
(
"Input vector size "
<< inVec.size()
89
<<
" is smaller than the maximum index used in "
90
<<
"OutputNamesMap ("
<<
m_maxIndex
<<
")"
);
91
return
StatusCode::FAILURE;
92
}
93
94
for
(
auto
& [
index
, handle] : outHandles) {
95
handle(*
jet
) = inVec.at(
index
);
96
}
97
}
98
99
return
StatusCode::SUCCESS;
100
}
101
102
}
// namespace FlavorTagJetDecorators
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ReadDecorHandle.h
Handle class for reading a decoration on an object.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
VectorExploderAlg.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
FlavorTagJetDecorators::VectorExploderAlg::VectorExploderAlg
VectorExploderAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
VectorExploderAlg.cxx:21
FlavorTagJetDecorators::VectorExploderAlg::m_outputNamesMap
Gaudi::Property< std::map< int, std::string > > m_outputNamesMap
Mapping from vector index to output scalar decoration name.
Definition
VectorExploderAlg.h:53
FlavorTagJetDecorators::VectorExploderAlg::m_collectionKey
SG::ReadHandleKey< xAOD::JetContainer > m_collectionKey
Input jet collection.
Definition
VectorExploderAlg.h:43
FlavorTagJetDecorators::VectorExploderAlg::initialize
virtual StatusCode initialize() override
Definition
VectorExploderAlg.cxx:25
FlavorTagJetDecorators::VectorExploderAlg::m_inputVectorKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_inputVectorKey
Name of the input vector<float> decoration to explode.
Definition
VectorExploderAlg.h:48
FlavorTagJetDecorators::VectorExploderAlg::m_maxIndex
int m_maxIndex
Maximum index used in OutputNamesMap (for bounds check).
Definition
VectorExploderAlg.h:62
FlavorTagJetDecorators::VectorExploderAlg::m_outputKeys
std::vector< std::pair< int, SG::WriteDecorHandleKey< xAOD::JetContainer > > > m_outputKeys
Initialized output keys (index, WriteDecorHandleKey) pairs.
Definition
VectorExploderAlg.h:59
FlavorTagJetDecorators::VectorExploderAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
VectorExploderAlg.cxx:54
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition
StoreGate/StoreGate/ReadDecorHandle.h:94
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition
StoreGate/StoreGate/WriteDecorHandleKey.h:90
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
FlavorTagJetDecorators
Definition
JetOverlapLeptonDecoratorAlg.cxx:25
index
Definition
index.py:1
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
Generated on
for ATLAS Offline Software by
1.17.0