ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
AnalysisUtils
AnalysisUtils
SelectorBase.h
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
SelectorBase.h: Base class for selectors, the derived class is a template for
7
SelectorBase, ie class Derived: public SelectorBase<Derived>
8
9
10
Expects an InputKey for the branch with objects to be selected
11
and a SelectedParticlesKey for the output branch
12
13
NOTE: Derived class for container XXXContainer must define
14
public:
15
typedef XXXContainer Container;
16
typedef XXX Contained;
17
18
S. Protopopescu 15-Sept-2008
19
20
***********************************************************************/
21
22
#ifndef SELECTORBASE_H
23
#define SELECTORBASE_H
24
25
#include "
AthenaBaseComps/AthAlgorithm.h
"
26
#include "
AthenaKernel/Units.h
"
27
#include "GaudiKernel/MsgStream.h"
28
#include "GaudiKernel/AlgTool.h"
29
#include "GaudiKernel/ToolHandle.h"
30
#include "
ParticleEvent/SelectedParticles.h
"
31
#include "CLHEP/Units/SystemOfUnits.h"
32
#include <string>
33
#include <cmath>
34
35
template
<
class
Derived>
36
class
SelectorBase
:
public
AthAlgorithm
{
37
38
public
:
39
SelectorBase
(
const
std::string& name, ISvcLocator* pSvcLocator);
40
virtual
~SelectorBase
(){;}
41
virtual
StatusCode
initialize
()
override
;
42
virtual
StatusCode
userExecute
(){
return
StatusCode::SUCCESS;}
43
virtual
StatusCode
execute
(
const
EventContext& ctx)
override
;
44
virtual
StatusCode
finalize
()
override
;
45
bool
pt_eta_range
(
double
pt,
double
eta
);
46
// Derived class must supply
47
// bool accept(const Contained*);
48
// it should use pt_eta_range(pt,eta)
49
// For each object that this method returns true
50
// a flag will be set to true in a SelectedParticles branch
51
const
std::string&
getInputKey
(){
return
m_inputKey
;}
52
53
protected
:
54
55
std::string
m_inputKey
;
56
std::string
m_inselectedKey
;
57
std::string
m_selectedKey
;
58
std::string
m_inlinksKey
;
59
std::string
m_linksKey
;
60
bool
m_all
;
61
bool
m_nogood
;
62
bool
m_inSel
;
63
bool
m_inLink
;
64
bool
m_gensel
;
65
bool
m_genlink
;
66
double
m_ptmin
;
67
double
m_ptmax
;
68
double
m_etamin
;
69
double
m_etamax
;
70
double
m_absetamax
;
71
double
m_absetamin
;
72
};
73
//
74
// Templated implementation must go here...
75
//
76
77
template
<
class
Derived>
78
SelectorBase<Derived>::SelectorBase
(
const
std::string& name, ISvcLocator* pSvcLocator)
79
:
AthAlgorithm
(name, pSvcLocator),
80
m_gensel
(false),
81
m_genlink
(false)
82
{
83
declareProperty
(
"InputKey"
,
m_inputKey
=
"NONE"
);
84
declareProperty
(
"InSelectedParticlesKey"
,
m_inselectedKey
=
"NONE"
);
85
declareProperty
(
"OutSelectedParticlesKey"
,
m_selectedKey
=
"NONE"
);
86
declareProperty
(
"InParticleLinksKey"
,
m_inlinksKey
=
"NONE"
);
87
declareProperty
(
"OutParticleLinksKey"
,
m_linksKey
=
"NONE"
);
88
declareProperty
(
"PtMin"
,
m_ptmin
= 15.0*CLHEP::GeV);
89
declareProperty
(
"PtMax"
,
m_ptmax
= 10000.0*CLHEP::GeV);
90
declareProperty
(
"EtaMax"
,
m_etamax
= 2.5);
91
declareProperty
(
"EtaMin"
,
m_etamin
= -2.5);
92
declareProperty
(
"AbsEtaMax"
,
m_absetamax
= 2.5);
93
declareProperty
(
"AbsEtaMin"
,
m_absetamin
=0);
94
declareProperty
(
"SelectAll"
,
m_all
=
false
);
95
m_nogood
=
false
;
96
m_inSel
=
false
;
97
m_inLink
=
false
;
98
}
99
template
<
class
Derived>
100
StatusCode
SelectorBase<Derived>::initialize
()
101
{
102
m_genlink
=
true
;
103
m_gensel
=
true
;
104
ATH_MSG_INFO
(
"Initializing Selector "
<<name() );
105
if
(
m_inputKey
==std::string(
"NONE"
))
m_nogood
=
true
;
106
if
(
m_selectedKey
==std::string(
"NONE"
))
m_gensel
=
false
;
107
if
(
m_inselectedKey
!=std::string(
"NONE"
))
m_inSel
=
true
;
108
if
(
m_linksKey
==std::string(
"NONE"
) )
m_genlink
=
false
;
109
if
(
m_inlinksKey
!=std::string(
"NONE"
))
m_inLink
=
true
;
110
111
ATH_MSG_INFO
(
"InputKey="
<<
m_inputKey
.c_str()<<
", OutSelectedParticlesKey="
<<
m_selectedKey
.c_str()
112
<<
", InSelectedParticlesKey="
<<
m_inselectedKey
.c_str()
113
<<
", InParticlesLinksKey="
<<
m_inlinksKey
.c_str()
114
<<
", OutParticleLinksKey="
<<
m_linksKey
.c_str() );
115
ATH_MSG_INFO
(
", PtMin="
<<
m_ptmin
116
<< MSG::INFO<<
", PtMax="
<<
m_ptmax
117
<< MSG::INFO<<
", EtaMin="
<<
m_etamin
118
<< MSG::INFO<<
", EtaMax="
<<
m_etamax
119
<< MSG::INFO<<
", AbsEtaMin="
<<
m_absetamin
120
<< MSG::INFO<<
", AbsEtaMax="
<<
m_absetamax
121
<< MSG::INFO<<
", SelectAll="
<<
m_all
);
122
if
(
m_all
)
ATH_MSG_INFO
(
" All items will be accepted"
);
123
124
m_nogood
=
m_nogood
&& (!
m_genlink
&& !
m_gensel
);
125
if
(
m_nogood
){
126
ATH_MSG_FATAL
(
"Must supply names for InputKey, OutSelectedParticlesKey and/or OutParticleLinksKey"
);
127
}
128
m_nogood
=
m_inSel
&&
m_inLink
;
129
if
(
m_nogood
){
130
ATH_MSG_FATAL
(
"Cannot have both InSelectedParticlesKey and InParticlesLinksKey, must chose one"
);
131
}
132
133
ATH_MSG_INFO
(
"Done Initializing "
<<name() );
134
return
StatusCode::SUCCESS;
135
}
136
137
template
<
class
Derived>
138
StatusCode
SelectorBase<Derived>::execute
(
const
EventContext&
/*ctx*/
)
139
{
140
typedef
typename
Derived::Container
Container
;
141
//typedef typename Derived::Contained Contained;
142
typedef
typename
Derived::Links Links;
143
144
ATH_MSG_DEBUG
(std::endl );
145
ATH_MSG_DEBUG
(
"Executing Selector "
<<name() );
146
ATH_CHECK
(
userExecute
() );
147
const
Container
* particles = 0;
148
const
SelectedParticles
* inselparts=0;
149
const
Links* inlinks=0;
150
if
(
m_inSel
){
151
ATH_CHECK
(
evtStore
()->retrieve(inselparts,
m_inselectedKey
) );
152
}
153
if
(
m_inLink
){
154
ATH_CHECK
(
evtStore
()->retrieve(inlinks,
m_inlinksKey
) );
155
}
156
157
ATH_CHECK
(
evtStore
()->retrieve(particles,
m_inputKey
) );
158
int
npart=particles->size();
159
ATH_MSG_DEBUG
(
" >>>> got Container, no. of particles="
<<npart );
160
161
SelectedParticles
* selparts=0;
162
if
(
m_gensel
){
163
// SelectedParticles option
164
selparts=
new
SelectedParticles
();
165
ATH_MSG_DEBUG
(
" >>>> Generate SelectedParticles"
);
166
ATH_CHECK
(
evtStore
()->record(selparts,
m_selectedKey
) );
167
typename
Container::const_iterator ipItr = particles->begin();
168
typename
Container::const_iterator ipEnd = particles->end();
169
int
npart=particles->size();
170
selparts->
SetMaxBits
(npart);
171
unsigned
ipart=0;
172
if
(!
m_inLink
){
173
if
(
m_inSel
)
ATH_MSG_DEBUG
(
" using InSelectedParticles("
<<
m_inselectedKey
174
<<
"), no. particles="
<<inselparts->
numGood
()
175
<<
" <<<"
);
176
else
ATH_MSG_DEBUG
(
" looping over whole Container <<<"
);
177
for
(; ipItr != ipEnd; ++ipItr) {
178
if
(
m_inSel
&& !inselparts->
isGood
(ipart)){
179
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
180
ipart++;
181
continue
;
182
}
183
if
(
m_all
||
static_cast<
Derived*
>
(
this
)->accept(*ipItr)){
184
selparts->
SetBit
(ipart);
185
ATH_MSG_DEBUG
(
" accepted ipart="
<<ipart );
186
}
else
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
187
ipart++;
188
}
189
}
else
{
190
// loop over input links
191
typename
Links::const_iterator ilItr = inlinks->begin();
192
typename
Links::const_iterator ilEnd = inlinks->end();
193
ATH_MSG_DEBUG
(
" using input ParticleLinks ("
<<
m_inlinksKey
<<
"), no. of particles="
194
<<inlinks->size()<<
" <<<<<"
);
195
int
ipart=0;
196
for
(; ilItr != ilEnd; ++ilItr) {
197
ipart=(*ilItr).index();
198
//const Contained* cpart=(*inlinks)[ipart];
199
//Contained* part=const_cast<Contained *>(cpart);
200
if
(
m_all
||
static_cast<
Derived*
>
(
this
)->accept(*ilItr) ){
201
selparts->
SetBit
(ipart);
202
ATH_MSG_DEBUG
(
" accepted ipart="
<<ipart );
203
}
else
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
204
}
205
}
206
ATH_MSG_DEBUG
(
" SelectedParticles bits: "
<<selparts->
displayBits
() );
207
}
// end of SelectedParticles option
208
209
// ParticleLinks option
210
if
(
m_genlink
){
211
ATH_MSG_DEBUG
(
" >>>> Generate ParticleLinks"
);
212
Links* links=
new
Links();
213
ATH_CHECK
(
evtStore
()->record(links,
m_linksKey
) );
214
215
if
(
m_gensel
){
216
// selection already done, selparts filled
217
typename
Container::const_iterator ipItr = particles->begin();
218
typename
Container::const_iterator ipEnd = particles->end();
219
unsigned
ipart=0;
220
for
(; ipItr != ipEnd; ++ipItr) {
221
if
(selparts->
isGood
(ipart)){
222
ElementLink<Container>
el(*particles,ipart);
223
links->push_back(el);
224
}
225
ipart++;
226
}
227
return
StatusCode::SUCCESS;
228
}
229
if
(
m_inLink
){
230
typename
Links::const_iterator ilItr = inlinks->begin();
231
typename
Links::const_iterator ilEnd = inlinks->end();
232
ATH_MSG_DEBUG
(
" using input ParticleLinks ("
<<
m_inlinksKey
<<
"), no. of particles="
233
<<inlinks->size()<<
" <<<<<"
);
234
unsigned
ipart=0;
235
for
(; ilItr != ilEnd; ++ilItr) {
236
ipart=(*ilItr).index();
237
//const Contained* cpart=(*inlinks)[ipart];
238
//Contained* part=const_cast<Contained *>(cpart);
239
if
(
m_all
||
static_cast<
Derived*
>
(
this
)->accept(*ilItr) ){
240
links->push_back(*ilItr);
241
ATH_MSG_DEBUG
(
" accepted ipart="
<<ipart );
242
}
else
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
243
}
244
}
else
{
245
if
(
m_inSel
)
ATH_MSG_DEBUG
(
" using InSelectedParticles("
<<
m_inselectedKey
246
<<
"), no. particles="
<<inselparts->
numGood
()
247
<<
" <<<"
);
248
else
ATH_MSG_DEBUG
(
" looping over whole Container <<<"
);
249
typename
Container::const_iterator ipItr = particles->begin();
250
typename
Container::const_iterator ipEnd = particles->end();
251
unsigned
ipart=0;
252
for
(; ipItr != ipEnd; ++ipItr) {
253
if
(
m_inSel
&& !inselparts->
isGood
(ipart)){
254
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
255
ipart++;
256
continue
;
257
}
258
if
(
m_all
||
static_cast<
Derived*
>
(
this
)->accept(*ipItr) ){
259
ElementLink<Container>
el(*particles,ipart);
260
links->push_back(el);
261
ATH_MSG_DEBUG
(
" accepted ipart="
<<ipart<<
", pt="
<<(*el)->pt()/Athena::Units::GeV );
262
}
else
ATH_MSG_DEBUG
(
" rejected ipart="
<<ipart );
263
ipart++;
264
}
265
}
266
}
// end of ParticleLinks option
267
return
StatusCode::SUCCESS;
268
}
269
270
template
<
class
Derived>
271
StatusCode
SelectorBase<Derived>::finalize
() {
272
273
ATH_MSG_INFO
(
"Finalizing Selector "
<< name() );
274
275
return
StatusCode::SUCCESS;
276
}
277
278
template
<
class
Derived>
279
bool
SelectorBase<Derived>::pt_eta_range
(
double
pt,
double
eta
){
280
if
(pt<
m_ptmin
)
return
false
;
281
if
(pt>
m_ptmax
)
return
false
;
282
if
(fabs(
eta
)>
m_absetamax
)
return
false
;
283
if
(fabs(
eta
)<
m_absetamin
)
return
false
;
284
if
(
eta
>
m_etamax
)
return
false
;
285
if
(
eta
<
m_etamin
)
return
false
;
286
return
true
;
287
}
288
#endif
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
AthAlgorithm.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
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_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
SelectedParticles.h
Units.h
Wrapper to avoid constant divisions when using units.
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
ElementLink
ElementLink implementation for ROOT usage.
Definition
A/AthLinks/ElementLink.h:40
Container
storage of the time histories of all the cells
SelectedParticles
Definition
SelectedParticles.h:54
SelectedParticles::SetMaxBits
void SetMaxBits(unsigned maxbits)
Definition
SelectedParticles.cxx:39
SelectedParticles::SetBit
void SetBit(unsigned i, bool good=true)
Definition
SelectedParticles.cxx:19
SelectedParticles::displayBits
std::string displayBits() const
Definition
SelectedParticles.cxx:49
SelectedParticles::isGood
bool isGood(unsigned i) const
Definition
SelectedParticles.cxx:84
SelectedParticles::numGood
unsigned numGood() const
Definition
SelectedParticles.cxx:112
SelectorBase::m_inLink
bool m_inLink
Definition
SelectorBase.h:63
SelectorBase::m_ptmin
double m_ptmin
Definition
SelectorBase.h:66
SelectorBase::SelectorBase
SelectorBase(const std::string &name, ISvcLocator *pSvcLocator)
Definition
SelectorBase.h:78
SelectorBase::m_ptmax
double m_ptmax
Definition
SelectorBase.h:67
SelectorBase::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
SelectorBase.h:138
SelectorBase::m_absetamax
double m_absetamax
Definition
SelectorBase.h:70
SelectorBase::finalize
virtual StatusCode finalize() override
Definition
SelectorBase.h:271
SelectorBase::m_linksKey
std::string m_linksKey
Definition
SelectorBase.h:59
SelectorBase::m_inputKey
std::string m_inputKey
Definition
SelectorBase.h:55
SelectorBase::m_inlinksKey
std::string m_inlinksKey
Definition
SelectorBase.h:58
SelectorBase::m_etamin
double m_etamin
Definition
SelectorBase.h:68
SelectorBase::m_inselectedKey
std::string m_inselectedKey
Definition
SelectorBase.h:56
SelectorBase::m_inSel
bool m_inSel
Definition
SelectorBase.h:62
SelectorBase::m_etamax
double m_etamax
Definition
SelectorBase.h:69
SelectorBase::m_genlink
bool m_genlink
Definition
SelectorBase.h:65
SelectorBase::m_absetamin
double m_absetamin
Definition
SelectorBase.h:71
SelectorBase::pt_eta_range
bool pt_eta_range(double pt, double eta)
Definition
SelectorBase.h:279
SelectorBase::~SelectorBase
virtual ~SelectorBase()
Definition
SelectorBase.h:40
SelectorBase::initialize
virtual StatusCode initialize() override
Definition
SelectorBase.h:100
SelectorBase::m_all
bool m_all
Definition
SelectorBase.h:60
SelectorBase::m_nogood
bool m_nogood
Definition
SelectorBase.h:61
SelectorBase::userExecute
virtual StatusCode userExecute()
Definition
SelectorBase.h:42
SelectorBase::m_selectedKey
std::string m_selectedKey
Definition
SelectorBase.h:57
SelectorBase::getInputKey
const std::string & getInputKey()
Definition
SelectorBase.h:51
SelectorBase::m_gensel
bool m_gensel
Definition
SelectorBase.h:64
Generated on
for ATLAS Offline Software by
1.17.0