ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkInDet
src
JetGhostThinning.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// JetGhostThinning.cxx, (c) ATLAS Detector software
8
9
#include "
DerivationFrameworkInDet/JetGhostThinning.h
"
10
#include "
StoreGate/ThinningHandle.h
"
11
#include "
xAODBase/IParticle.h
"
12
#include "
AthContainers/AuxElement.h
"
13
14
// Constructor
15
DerivationFramework::JetGhostThinning::JetGhostThinning
(
16
const
std::string &t,
const
std::string &n,
const
IInterface *p)
17
: base_class(t, n, p) {}
18
19
// Destructor
20
DerivationFramework::JetGhostThinning::~JetGhostThinning
() =
default
;
21
22
// Athena initialize
23
StatusCode
DerivationFramework::JetGhostThinning::initialize
() {
24
ATH_MSG_VERBOSE
(
"initialize() ..."
);
25
26
// Check that we have a jet container
27
if
(
m_jetSGKey
.empty()) {
28
ATH_MSG_FATAL
(
"No jet collection provided!"
);
29
return
StatusCode::FAILURE;
30
}
31
32
ATH_CHECK
(
m_jetSGKey
.initialize());
33
ATH_MSG_INFO
(
"Using "
<<
m_jetSGKey
.key() <<
" as the jet collection"
);
34
35
// Initialize the selection string parser if provided
36
if
(!
m_selectionString
.empty()) {
37
ATH_CHECK
(initializeParser(
m_selectionString
));
38
ATH_MSG_INFO
(
"Jet selection string: "
<<
m_selectionString
);
39
}
40
41
// Check that we have a ghost name
42
if
(
m_ghostName
.empty()) {
43
ATH_MSG_FATAL
(
"No ghost name provided!"
);
44
return
StatusCode::FAILURE;
45
}
46
47
// Check that we have a ghost container name
48
if
(
m_ghostContainerName
.empty()) {
49
ATH_MSG_FATAL
(
"No ghost container name provided!"
);
50
return
StatusCode::FAILURE;
51
}
52
53
// Initialize thinning handle key
54
m_ghostContainerKey
=
SG::ThinningHandleKey<xAOD::IParticleContainer>
(
m_ghostContainerName
);
55
ATH_CHECK
(
m_ghostContainerKey
.initialize(
m_streamName
));
56
57
ATH_MSG_INFO
(
"Thinning ghost objects:"
);
58
ATH_MSG_INFO
(
" Ghost name: "
<<
m_ghostName
);
59
ATH_MSG_INFO
(
" Ghost container: "
<<
m_ghostContainerName
);
60
61
return
StatusCode::SUCCESS;
62
}
63
64
StatusCode
DerivationFramework::JetGhostThinning::finalize
() {
65
ATH_MSG_VERBOSE
(
"finalize() ..."
);
66
return
StatusCode::SUCCESS;
67
}
68
69
// The thinning itself
70
StatusCode
DerivationFramework::JetGhostThinning::doThinning
(
const
EventContext& ctx)
const
{
71
72
// Retrieve jet collection
73
SG::ReadHandle<xAOD::JetContainer>
jets(
m_jetSGKey
, ctx);
74
if
(!jets.isValid()) {
75
ATH_MSG_ERROR
(
"Failed to retrieve jet collection "
<<
m_jetSGKey
.key());
76
return
StatusCode::FAILURE;
77
}
78
79
// Get the jets that pass the selection
80
std::vector<const xAOD::Jet*> selectedJets;
81
82
if
(!
m_selectionString
.empty()) {
83
// Use the expression parser
84
std::vector<int>
entries
= m_parser->evaluateAsVector();
85
if
(
entries
.size() != jets->size()) {
86
ATH_MSG_ERROR
(
"Selection string evaluation size mismatch!"
);
87
return
StatusCode::FAILURE;
88
}
89
90
for
(
size_t
i = 0; i < jets->size(); ++i) {
91
if
(
entries
[i] == 1) {
92
selectedJets.push_back((*jets)[i]);
93
}
94
}
95
}
else
{
96
// Keep all jets
97
for
(
const
auto
*
jet
: *jets) {
98
selectedJets.push_back(
jet
);
99
}
100
}
101
102
ATH_MSG_DEBUG
(
"Number of selected jets: "
<< selectedJets.size()
103
<<
" out of "
<< jets->size());
104
105
// Get thinning handle for the ghost container
106
SG::ThinningHandle<xAOD::IParticleContainer>
ghostContainer(
m_ghostContainerKey
, ctx);
107
108
if
(!ghostContainer.isValid()) {
109
ATH_MSG_WARNING
(
"Ghost container "
<<
m_ghostContainerKey
.key() <<
" not valid, skipping"
);
110
return
StatusCode::SUCCESS;
111
}
112
113
size_t
nObjects = ghostContainer->size();
114
std::vector<bool> mask(nObjects,
false
);
115
const
int
maskSize =
static_cast<
int
>
(mask.size());
116
117
// Create accessor for the ghost association
118
SG::AuxElement::ConstAccessor<std::vector<ElementLink<xAOD::IParticleContainer>>> ghostAcc(
m_ghostName
);
119
120
size_t
nGhostLinks = 0;
121
122
// Loop over selected jets and mark ghost objects to keep using their indices
123
for
(
const
auto
*
jet
: selectedJets) {
124
if
(!
jet
)
continue
;
125
126
// Check if this jet has the ghost association
127
if
(!ghostAcc.isAvailable(*
jet
)) {
128
ATH_MSG_VERBOSE
(
"Jet does not have ghost association: "
<<
m_ghostName
);
129
continue
;
130
}
131
132
// Get the ghost links
133
const
std::vector<ElementLink<xAOD::IParticleContainer>>& ghostLinks = ghostAcc(*
jet
);
134
135
ATH_MSG_VERBOSE
(
"Jet has "
<< ghostLinks.size() <<
" ghost objects"
);
136
137
// Mark all valid ghost objects using their indices
138
for
(
const
auto
& link : ghostLinks) {
139
if
(!link.isValid())
continue
;
140
141
int
index
= link.index();
142
if
(
index
< 0) {
143
ATH_MSG_VERBOSE
(
" Ghost link has negative index, skipping"
);
144
continue
;
145
}
146
147
if
(
index
< maskSize) {
148
mask[
index
] =
true
;
149
nGhostLinks++;
150
const
xAOD::IParticle
* ghostObj = *link;
151
if
(ghostObj) {
152
ATH_MSG_VERBOSE
(
" Ghost object at index "
<<
index
<<
": pt="
<< ghostObj->
pt
()
153
<<
", eta="
<< ghostObj->
eta
());
154
}
155
}
156
}
157
}
158
159
size_t
nKept = std::count(mask.begin(), mask.end(),
true
);
160
ATH_MSG_DEBUG
(
"Found "
<< nGhostLinks <<
" ghost links from selected jets"
);
161
ATH_MSG_DEBUG
(
"Ghost container "
<<
m_ghostContainerKey
.key() <<
": keeping "
162
<< nKept <<
" out of "
<< nObjects <<
" objects"
);
163
164
ghostContainer.
keep
(mask);
165
166
return
StatusCode::SUCCESS;
167
}
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_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
AuxElement.h
Base class for elements of a container that can have aux data.
IParticle.h
JetGhostThinning.h
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::JetGhostThinning::finalize
virtual StatusCode finalize() override
Definition
JetGhostThinning.cxx:64
DerivationFramework::JetGhostThinning::m_selectionString
StringProperty m_selectionString
Definition
JetGhostThinning.h:43
DerivationFramework::JetGhostThinning::m_streamName
StringProperty m_streamName
Definition
JetGhostThinning.h:37
DerivationFramework::JetGhostThinning::m_ghostContainerName
StringProperty m_ghostContainerName
Definition
JetGhostThinning.h:49
DerivationFramework::JetGhostThinning::JetGhostThinning
JetGhostThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition
JetGhostThinning.cxx:15
DerivationFramework::JetGhostThinning::m_ghostContainerKey
SG::ThinningHandleKey< xAOD::IParticleContainer > m_ghostContainerKey
Definition
JetGhostThinning.h:52
DerivationFramework::JetGhostThinning::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Definition
JetGhostThinning.cxx:70
DerivationFramework::JetGhostThinning::~JetGhostThinning
virtual ~JetGhostThinning()
DerivationFramework::JetGhostThinning::m_ghostName
StringProperty m_ghostName
Definition
JetGhostThinning.h:46
DerivationFramework::JetGhostThinning::m_jetSGKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetSGKey
Definition
JetGhostThinning.h:40
DerivationFramework::JetGhostThinning::initialize
virtual StatusCode initialize() override
Definition
JetGhostThinning.cxx:23
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition
ThinningHandleBase.cxx:75
SG::ThinningHandleKey
HandleKey object for adding thinning to an object.
Definition
ThinningHandleKey.h:39
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition
ThinningHandle.h:84
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::IParticle::eta
virtual double eta() const =0
The pseudorapidity ( ) of the particle.
xAOD::IParticle::pt
virtual double pt() const =0
The transverse momentum ( ) of the particle.
entries
double entries
Definition
listroot.cxx:49
index
Definition
index.py:1
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
Generated on
for ATLAS Offline Software by
1.17.0