ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkCalo
src
JetCaloClusterThinning.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
// JetCaloClusterThinning.cxx, (c) ATLAS Detector software
7
// @author Danilo E. Ferreira de Lima <dferreir@cern.ch>
9
10
#include "
DerivationFrameworkCalo/JetCaloClusterThinning.h
"
11
12
#include "
xAODCaloEvent/CaloCluster.h
"
13
#include "
xAODJet/Jet.h
"
14
15
#include "
StoreGate/ThinningHandle.h
"
16
#include "
xAODJet/JetConstituentVector.h
"
17
18
#include <string>
19
#include <vector>
20
21
// Constructor
22
DerivationFramework::JetCaloClusterThinning::JetCaloClusterThinning
(
23
const
std::string& t,
24
const
std::string& n,
25
const
IInterface* p)
26
: base_class(t, n, p)
27
,
m_ntotTopo
(0)
28
,
m_npassTopo
(0)
29
,
m_selectionString
(
""
)
30
{
31
declareProperty(
"SelectionString"
,
m_selectionString
);
32
}
33
34
// Destructor
35
DerivationFramework::JetCaloClusterThinning::~JetCaloClusterThinning
() =
default
;
36
37
// Athena initialize and finalize
38
StatusCode
39
DerivationFramework::JetCaloClusterThinning::initialize
()
40
{
41
// Decide which collections need to be checked for ID TrackParticles
42
ATH_MSG_VERBOSE
(
"initialize() ..."
);
43
ATH_CHECK
(
m_TopoClSGKey
.initialize(
m_streamName
));
44
ATH_MSG_INFO
(
"Using "
<<
m_TopoClSGKey
.key()
45
<<
"as the source collection for topo calo clusters"
);
46
if
(
m_sgKey
.empty()) {
47
ATH_MSG_FATAL
(
"No jet collection provided for thinning."
);
48
return
StatusCode::FAILURE;
49
}
else
{
50
ATH_MSG_INFO
(
51
"Calo clusters associated with objects in "
52
<<
m_sgKey
.key()
53
<<
" will be retained in this format with the rest being thinned away"
);
54
ATH_CHECK
(
m_sgKey
.initialize());
55
}
56
57
for
(
unsigned
int
i=0; i <
m_addClusterSGKey
.size(); i++){
58
m_tmpAddClusterKey
=
m_addClusterSGKey
[i];
59
ATH_CHECK
(
m_tmpAddClusterKey
.initialize(
m_streamName
));
60
m_addClusterKeys
.push_back(
m_tmpAddClusterKey
);
61
}
62
63
// Set up the text-parsing machinery for selectiong the photon directly
64
// according to user cuts
65
if
(!
m_selectionString
.empty()) {
66
ATH_CHECK
(initializeParser(
m_selectionString
));
67
}
68
69
return
StatusCode::SUCCESS;
70
}
71
72
StatusCode
73
DerivationFramework::JetCaloClusterThinning::finalize
()
74
{
75
ATH_MSG_VERBOSE
(
"finalize() ..."
);
76
ATH_MSG_INFO
(
"Processed "
<<
m_ntotTopo
<<
" topo clusters, of which "
77
<<
m_npassTopo
<<
" were retained "
);
78
ATH_CHECK
(finalizeParser());
79
return
StatusCode::SUCCESS;
80
}
81
82
// The thinning itself
83
StatusCode
84
DerivationFramework::JetCaloClusterThinning::doThinning
(
const
EventContext& ctx)
const
85
{
86
87
// Retrieve CalCaloTopo collection if required
88
SG::ThinningHandle<xAOD::CaloClusterContainer>
importedTopoCaloCluster(
89
m_TopoClSGKey
, ctx);
90
91
// Check the event contains tracks
92
unsigned
int
nTopoClusters = importedTopoCaloCluster->size();
93
if
(nTopoClusters == 0)
94
return
StatusCode::SUCCESS;
95
96
// Set up a mask with the same entries as the full CaloCalTopoClusters collection(s)
97
std::vector<bool> topomask;
98
topomask.assign(nTopoClusters,
false
);
99
m_ntotTopo
+= nTopoClusters;
100
101
// Retrieve jet container
102
const
xAOD::JetContainer
* importedJets(
nullptr
);
103
SG::ReadHandle<xAOD::JetContainer>
importedJetsHandle{
m_sgKey
, ctx };
104
importedJets = importedJetsHandle.
ptr
();
105
if
(importedJets ==
nullptr
) {
106
ATH_MSG_ERROR
(
"No jet collection with name "
<<
m_sgKey
.key()
107
<<
" found in StoreGate!"
);
108
return
StatusCode::FAILURE;
109
}
110
unsigned
int
nJets(importedJets->
size
());
111
if
(nJets == 0)
112
return
StatusCode::SUCCESS;
113
std::vector<const xAOD::Jet*> jetToCheck;
114
jetToCheck.clear();
115
116
// Execute the text parsers if requested
117
if
(!
m_selectionString
.empty()) {
118
std::vector<int>
entries
= m_parser->evaluateAsVector();
119
unsigned
int
nEntries =
entries
.size();
120
// check the sizes are compatible
121
if
(nJets != nEntries) {
122
ATH_MSG_ERROR
(
"Sizes incompatible! Are you sure your selection string "
123
"used jets objects??"
);
124
return
StatusCode::FAILURE;
125
}
else
{
126
// identify which e-gammas to keep for the thinning check
127
for
(
unsigned
int
i = 0; i < nJets; ++i)
128
if
(
entries
[i] == 1)
129
jetToCheck.push_back((*importedJets)[i]);
130
}
131
132
if
(jetToCheck.empty())
133
return
StatusCode::SUCCESS;
134
135
for
(
const
xAOD::Jet
*
jet
: jetToCheck){
136
const
auto
& links =
jet
->constituentLinks();
137
for
(
const
auto
& link : links ) {
138
// Check that the link is valid:
139
if
( ! link.isValid() ) {
140
continue
;
141
}
142
topomask.at( link.index() ) =
true
;
143
}
144
}
145
}
146
else
{
147
for
(
const
xAOD::Jet
*
jet
: *importedJets){
148
const
auto
& links =
jet
->constituentLinks();
149
for
(
const
auto
& link : links ) {
150
// Check that the link is valid:
151
if
( ! link.isValid() ) {
152
continue
;
153
}
154
topomask.at( link.index() ) =
true
;
155
}
156
}
157
}
158
159
// Count up the mask contents
160
for
(
unsigned
int
i = 0; i < nTopoClusters; ++i) {
161
if
(topomask[i])
162
++
m_npassTopo
;
163
}
164
165
// Execute the thinning service based on the mask. Finish.
166
importedTopoCaloCluster.
keep
(topomask);
167
168
for
(
const
auto
& addClusterKey :
m_addClusterKeys
){
169
SG::ThinningHandle<xAOD::CaloClusterContainer>
tempClusters(addClusterKey);
170
tempClusters.
keep
(topomask);
171
}
172
173
return
StatusCode::SUCCESS;
174
}
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:47
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x,...)
Definition
AthMsgStreamMacros.h:42
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x,...)
Definition
AthMsgStreamMacros.h:48
CaloCluster.h
Jet.h
JetCaloClusterThinning.h
JetConstituentVector.h
This file defines helper classes to deal with jet constituents.
ThinningHandle.h
Handle for requesting thinning for a data object.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::JetCaloClusterThinning::m_npassTopo
std::atomic< unsigned int > m_npassTopo
Definition
JetCaloClusterThinning.h:42
DerivationFramework::JetCaloClusterThinning::finalize
virtual StatusCode finalize() override
Definition
JetCaloClusterThinning.cxx:73
DerivationFramework::JetCaloClusterThinning::m_sgKey
SG::ReadHandleKey< xAOD::JetContainer > m_sgKey
Definition
JetCaloClusterThinning.h:51
DerivationFramework::JetCaloClusterThinning::m_TopoClSGKey
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_TopoClSGKey
Definition
JetCaloClusterThinning.h:49
DerivationFramework::JetCaloClusterThinning::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Definition
JetCaloClusterThinning.cxx:84
DerivationFramework::JetCaloClusterThinning::JetCaloClusterThinning
JetCaloClusterThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition
JetCaloClusterThinning.cxx:22
DerivationFramework::JetCaloClusterThinning::m_addClusterSGKey
Gaudi::Property< std::vector< std::string > > m_addClusterSGKey
Definition
JetCaloClusterThinning.h:53
DerivationFramework::JetCaloClusterThinning::m_selectionString
std::string m_selectionString
Definition
JetCaloClusterThinning.h:57
DerivationFramework::JetCaloClusterThinning::m_addClusterKeys
std::vector< SG::ThinningHandleKey< xAOD::CaloClusterContainer > > m_addClusterKeys
Definition
JetCaloClusterThinning.h:55
DerivationFramework::JetCaloClusterThinning::initialize
virtual StatusCode initialize() override
Definition
JetCaloClusterThinning.cxx:39
DerivationFramework::JetCaloClusterThinning::m_streamName
StringProperty m_streamName
Definition
JetCaloClusterThinning.h:44
DerivationFramework::JetCaloClusterThinning::m_tmpAddClusterKey
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_tmpAddClusterKey
Definition
JetCaloClusterThinning.h:54
DerivationFramework::JetCaloClusterThinning::~JetCaloClusterThinning
virtual ~JetCaloClusterThinning()
DerivationFramework::JetCaloClusterThinning::m_ntotTopo
std::atomic< unsigned int > m_ntotTopo
Definition
JetCaloClusterThinning.h:41
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
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::ThinningHandle
Handle for requesting thinning for a data object.
Definition
ThinningHandle.h:84
entries
double entries
Definition
listroot.cxx:49
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
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition
JetContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0