ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkInDet
src
UFOTrackParticleThinning.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
// UFOTrackParticleThinning.cxx, (c) ATLAS Detector software
8
9
#include "
DerivationFrameworkInDet/UFOTrackParticleThinning.h
"
10
11
#include "
StoreGate/ThinningHandle.h
"
12
13
// Constructor
14
DerivationFramework::UFOTrackParticleThinning::UFOTrackParticleThinning
(
const
std::string& t,
15
const
std::string& n,
16
const
IInterface* p ) :
17
base_class(t,n,p)
18
{
19
}
20
21
// Destructor
22
DerivationFramework::UFOTrackParticleThinning::~UFOTrackParticleThinning
() =
default
;
23
24
// Athena initialize and finalize
25
StatusCode
DerivationFramework::UFOTrackParticleThinning::initialize
()
26
{
27
// Decide which collections need to be checked for ID TrackParticles
28
ATH_MSG_VERBOSE
(
"initialize() ..."
);
29
ATH_CHECK
(
m_inDetSGKey
.initialize(
m_streamName
) );
30
ATH_MSG_INFO
(
"Using "
<<
m_inDetSGKey
.key() <<
" as the source collection for inner detector track particles"
);
31
32
m_PFOChargedSGKey
=
m_PFOSGKey
+
"ChargedParticleFlowObjects"
;
33
m_PFONeutralSGKey
=
m_PFOSGKey
+
"NeutralParticleFlowObjects"
;
34
ATH_CHECK
(
m_PFONeutralSGKey
.initialize(
m_streamName
));
35
ATH_CHECK
(
m_PFOChargedSGKey
.initialize(
m_streamName
));
36
ATH_MSG_INFO
(
"Using "
<<
m_PFONeutralSGKey
.key() <<
"and "
<<
m_PFOChargedSGKey
.key() <<
" as the source collection for the PFlow collection"
);
37
38
for
(
unsigned
int
i = 0; i <
m_addPFOSGKey
.size(); i++){
39
m_tmpAddPFOChargedSGKey
=
m_addPFOSGKey
[i]+
"ChargedParticleFlowObjects"
;
40
ATH_CHECK
(
m_tmpAddPFOChargedSGKey
.initialize(
m_streamName
) );
41
m_addPFOChargedSGKey
.push_back(
m_tmpAddPFOChargedSGKey
);
42
m_tmpAddPFONeutralSGKey
=
m_addPFOSGKey
[i]+
"NeutralParticleFlowObjects"
;
43
ATH_CHECK
(
m_tmpAddPFONeutralSGKey
.initialize(
m_streamName
) );
44
m_addPFONeutralSGKey
.push_back(
m_tmpAddPFONeutralSGKey
);
45
}
46
47
ATH_CHECK
(
m_ufoSGKey
.initialize(
m_streamName
));
48
ATH_MSG_INFO
(
"Using "
<<
m_ufoSGKey
.key()<<
" as the source collection for UFOs"
);
49
50
ATH_CHECK
(
m_jetSGKey
.initialize());
51
ATH_MSG_INFO
(
"Using "
<<
m_jetSGKey
.key() <<
" as the source collection for UFOs"
);
52
53
if
(!
m_selectionString
.empty()){
54
// order must match enum order EJetTrPThinningParser
55
ATH_CHECK
( initializeParser(
m_selectionString
));
56
}
57
58
return
StatusCode::SUCCESS;
59
}
60
61
StatusCode
DerivationFramework::UFOTrackParticleThinning::finalize
()
62
{
63
return
StatusCode::SUCCESS;
64
}
65
66
// The thinning itself
67
StatusCode
DerivationFramework::UFOTrackParticleThinning::doThinning
(
const
EventContext& ctx)
const
68
{
69
70
71
// Retrieve main TrackParticle collection
72
SG::ThinningHandle<xAOD::TrackParticleContainer>
importedTrackParticles(
m_inDetSGKey
, ctx);
73
74
// Retrieve PFO collection if required
75
SG::ThinningHandle<xAOD::FlowElementContainer>
importedPFONeutral(
m_PFONeutralSGKey
, ctx);
76
SG::ThinningHandle<xAOD::FlowElementContainer>
importedPFOCharged(
m_PFOChargedSGKey
, ctx);
77
78
// Retrieve main jet collection
79
SG::ReadHandle<xAOD::JetContainer>
importedJets(
m_jetSGKey
, ctx);
80
unsigned
int
nJets(importedJets->size());
81
std::vector<const xAOD::Jet*> jetToCheck; jetToCheck.clear();
82
83
// Check the event contains tracks
84
unsigned
int
nTracks = importedTrackParticles->size();
85
// Check the event contains calo clusters
86
const
size_t
nPFONeutral = importedPFONeutral->size();
87
const
size_t
nPFOCharged = importedPFOCharged->size() ;
88
unsigned
int
nPFOs = nPFOCharged + nPFONeutral;
89
if
(nPFOs==0 && nTracks==0)
return
StatusCode::SUCCESS;
90
91
// Set up a mask with the same entries as the full TrackParticle collection
92
std::vector<bool> maskTracks;
93
maskTracks.assign(nTracks,
false
);
// default: don't keep any tracks
94
95
// Set up a mask with the same entries as the full PFO collection(s)
96
std::vector< bool > pfomaskNeutral( nPFONeutral,
false
);
97
std::vector< bool > pfomaskCharged( nPFOCharged,
false
);
98
99
// Retrieve containers
100
// ... UFOs
101
SG::ThinningHandle<xAOD::FlowElementContainer>
importedUFOs(
m_ufoSGKey
, ctx);
102
unsigned
int
nUFOs(importedUFOs->size());
103
104
// Set up a mask with the same entries as the full CaloCluster collection
105
std::vector<bool> maskUFOs;
106
maskUFOs.assign(nUFOs,
false
);
// default: don't keep any tracks
107
108
// Execute the text parser if requested
109
if
(
m_selectionString
!=
""
) {
110
std::vector<int>
entries
= m_parser->evaluateAsVector();
111
unsigned
int
nEntries =
entries
.size();
112
// check the sizes are compatible
113
if
(nJets != nEntries ) {
114
ATH_MSG_ERROR
(
"Sizes incompatible! Are you sure your selection string used jets??"
);
115
return
StatusCode::FAILURE;
116
}
else
{
117
// identify which jets to keep for the thinning check
118
for
(
unsigned
int
i=0; i<nJets; ++i)
if
(
entries
[i]==1) jetToCheck.push_back((*importedJets)[i]);
119
}
120
}
121
122
if
(
m_selectionString
==
""
) {
// check all jets as user didn't provide a selection string
123
for
(
const
auto
*
jet
: *importedJets){
124
for
(
size_t
j = 0; j <
jet
->numConstituents(); ++j ) {
125
auto
ufo =
jet
->constituentLinks().at(j);
126
int
index
= ufo.index();
127
maskUFOs[
index
] =
true
;
128
const
xAOD::FlowElement
* ufoO =
dynamic_cast<
const
xAOD::FlowElement
*
>
(*ufo);
129
if
(!ufoO)
continue
;
130
131
// Retrieve the track if UFO is charged or combined object
132
if
(ufoO->
signalType
()==
xAOD::FlowElement::SignalType::Charged
|| ufoO->
signalType
()==
xAOD::FlowElement::SignalType::Combined
){
133
int
index_trk = ufoO->
chargedObject
(0)->index();
134
if
(index_trk>=0) {
135
maskTracks[index_trk] =
true
;
136
}
137
}
138
139
// Loop over charged and neutral PFOs
140
for
(
size_t
n = 0; n < ufoO->
otherObjects
().
size
(); ++n) {
141
int
index_pfo = ufoO->
otherObject
(n)->index();
142
if
(index_pfo<0)
continue
;
143
144
const
xAOD::FlowElement
* fe =
dynamic_cast<
const
xAOD::FlowElement
*
>
(ufoO->
otherObject
(n));
145
146
if
(fe->
signalType
()==
xAOD::FlowElement::SignalType::ChargedPFlow
){
147
pfomaskCharged.at( index_pfo ) =
true
;
148
}
149
else
if
(fe->
signalType
()==
xAOD::FlowElement::SignalType::NeutralPFlow
){
150
pfomaskNeutral.at( index_pfo ) =
true
;
151
}
152
}
153
}
154
}
155
156
}
else
{
157
158
for
(
auto
& jetIt : jetToCheck) {
159
for
(
size_t
j = 0; j < jetIt->numConstituents(); ++j ) {
160
auto
ufo = jetIt->constituentLinks().at(j);
161
int
index
= ufo.index();
162
maskUFOs[
index
] =
true
;
163
164
const
xAOD::FlowElement
* ufoO =
dynamic_cast<
const
xAOD::FlowElement
*
>
(*ufo);
165
if
(!ufoO)
continue
;
166
167
if
(ufoO->
signalType
()==
xAOD::FlowElement::SignalType::Charged
|| ufoO->
signalType
()==
xAOD::FlowElement::SignalType::Combined
){
168
int
index_trk = ufoO->
chargedObject
(0)->index();
169
if
(index_trk>=0) {
170
maskTracks[index_trk] =
true
;
171
}
172
}
173
174
for
(
size_t
n = 0; n < ufoO->
otherObjects
().
size
(); ++n) {
175
int
index_pfo = ufoO->
otherObject
(n)->index();
176
if
(index_pfo<0)
continue
;
177
178
const
xAOD::FlowElement
* fe =
dynamic_cast<
const
xAOD::FlowElement
*
>
(ufoO->
otherObject
(n));
179
180
if
(fe->
signalType
()==
xAOD::FlowElement::SignalType::ChargedPFlow
){
181
pfomaskCharged.at( index_pfo ) =
true
;
182
}
183
else
if
(fe->
signalType
()==
xAOD::FlowElement::SignalType::NeutralPFlow
){
184
pfomaskNeutral.at( index_pfo ) =
true
;
185
}
186
}
187
}
188
}
189
}
190
191
// Execute the thinning service based on the mask. Finish.
192
if
(
m_thinTracks
){
193
importedTrackParticles.
keep
(maskTracks);
194
}
195
importedPFONeutral.
keep
(pfomaskNeutral);
196
importedPFOCharged.
keep
(pfomaskCharged);
197
importedUFOs.
keep
(maskUFOs);
198
199
for
(
unsigned
int
i = 0; i <
m_addPFOChargedSGKey
.size(); i++){
200
SG::ThinningHandle<xAOD::FlowElementContainer>
tempPFOCharged(
m_addPFOChargedSGKey
[i], ctx);
201
SG::ThinningHandle<xAOD::FlowElementContainer>
tempPFONeutral(
m_addPFONeutralSGKey
[i], ctx);
202
203
tempPFOCharged.
keep
(pfomaskCharged);
204
tempPFONeutral.
keep
(pfomaskNeutral);
205
}
206
207
return
StatusCode::SUCCESS;
208
}
209
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_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
size
size_t size() const
Number of registered mappings.
ThinningHandle.h
Handle for requesting thinning for a data object.
UFOTrackParticleThinning.h
DerivationFramework::UFOTrackParticleThinning::m_jetSGKey
SG::ReadHandleKey< xAOD::JetContainer > m_jetSGKey
Definition
UFOTrackParticleThinning.h:51
DerivationFramework::UFOTrackParticleThinning::m_inDetSGKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
Definition
UFOTrackParticleThinning.h:40
DerivationFramework::UFOTrackParticleThinning::finalize
virtual StatusCode finalize() override
Definition
UFOTrackParticleThinning.cxx:61
DerivationFramework::UFOTrackParticleThinning::m_selectionString
StringProperty m_selectionString
Definition
UFOTrackParticleThinning.h:52
DerivationFramework::UFOTrackParticleThinning::m_PFOChargedSGKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_PFOChargedSGKey
Definition
UFOTrackParticleThinning.h:43
DerivationFramework::UFOTrackParticleThinning::m_addPFOChargedSGKey
std::vector< SG::ThinningHandleKey< xAOD::FlowElementContainer > > m_addPFOChargedSGKey
Definition
UFOTrackParticleThinning.h:48
DerivationFramework::UFOTrackParticleThinning::m_thinTracks
Gaudi::Property< bool > m_thinTracks
Definition
UFOTrackParticleThinning.h:41
DerivationFramework::UFOTrackParticleThinning::m_ufoSGKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_ufoSGKey
Definition
UFOTrackParticleThinning.h:50
DerivationFramework::UFOTrackParticleThinning::m_tmpAddPFOChargedSGKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_tmpAddPFOChargedSGKey
Definition
UFOTrackParticleThinning.h:46
DerivationFramework::UFOTrackParticleThinning::m_streamName
StringProperty m_streamName
Definition
UFOTrackParticleThinning.h:39
DerivationFramework::UFOTrackParticleThinning::m_addPFOSGKey
Gaudi::Property< std::vector< std::string > > m_addPFOSGKey
Definition
UFOTrackParticleThinning.h:45
DerivationFramework::UFOTrackParticleThinning::m_PFONeutralSGKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_PFONeutralSGKey
Definition
UFOTrackParticleThinning.h:44
DerivationFramework::UFOTrackParticleThinning::~UFOTrackParticleThinning
virtual ~UFOTrackParticleThinning()
DerivationFramework::UFOTrackParticleThinning::m_tmpAddPFONeutralSGKey
SG::ThinningHandleKey< xAOD::FlowElementContainer > m_tmpAddPFONeutralSGKey
Definition
UFOTrackParticleThinning.h:47
DerivationFramework::UFOTrackParticleThinning::m_PFOSGKey
Gaudi::Property< std::string > m_PFOSGKey
Definition
UFOTrackParticleThinning.h:42
DerivationFramework::UFOTrackParticleThinning::initialize
virtual StatusCode initialize() override
Definition
UFOTrackParticleThinning.cxx:25
DerivationFramework::UFOTrackParticleThinning::doThinning
virtual StatusCode doThinning(const EventContext &ctx) const override
Definition
UFOTrackParticleThinning.cxx:67
DerivationFramework::UFOTrackParticleThinning::m_addPFONeutralSGKey
std::vector< SG::ThinningHandleKey< xAOD::FlowElementContainer > > m_addPFONeutralSGKey
Definition
UFOTrackParticleThinning.h:49
DerivationFramework::UFOTrackParticleThinning::UFOTrackParticleThinning
UFOTrackParticleThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition
UFOTrackParticleThinning.cxx:14
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::ThinningHandle
Handle for requesting thinning for a data object.
Definition
ThinningHandle.h:84
xAOD::FlowElement_v1::otherObjects
std::vector< const xAOD::IParticle * > otherObjects() const
Definition
FlowElement_v1.cxx:163
xAOD::FlowElement_v1::signalType
signal_t signalType() const
xAOD::FlowElement_v1::ChargedPFlow
@ ChargedPFlow
Definition
FlowElement_v1.h:47
xAOD::FlowElement_v1::Combined
@ Combined
Definition
FlowElement_v1.h:39
xAOD::FlowElement_v1::NeutralPFlow
@ NeutralPFlow
Definition
FlowElement_v1.h:46
xAOD::FlowElement_v1::Charged
@ Charged
Definition
FlowElement_v1.h:38
xAOD::FlowElement_v1::chargedObject
const xAOD::IParticle * chargedObject(std::size_t i) const
Definition
FlowElement_v1.cxx:127
xAOD::FlowElement_v1::otherObject
const xAOD::IParticle * otherObject(std::size_t i) const
Definition
FlowElement_v1.cxx:196
entries
double entries
Definition
listroot.cxx:49
index
Definition
index.py:1
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition
FlowElement.h:16
Generated on
for ATLAS Offline Software by
1.17.0