ATLAS Offline Software
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
AsgFlagSelectionTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
9
//
10
// includes
11
//
12
13
#include <
AsgAnalysisAlgorithms/AsgFlagSelectionTool.h
>
14
15
#include <cmath>
16
17
//
18
// method implementations
19
//
20
21
namespace
CP
22
{
23
24
StatusCode AsgFlagSelectionTool ::
25
initialize ()
26
{
27
if
(
m_invertFlags
.size()!=
m_selFlags
.size() && !
m_invertFlags
.empty()) {
28
ATH_MSG_ERROR
(
"Property invertFlags has different size to selectionFlags. Please check your configuration"
);
29
return
StatusCode::FAILURE;
30
}
31
// Could also warn if there are fewer values, but we don't have to force users to set where irrelevant.
32
// Maybe warn unless the size is 0, in which case assume all default?
33
34
for
(
size_t
index
=0;
index
<
m_selFlags
.size(); ++
index
) {
35
const
std::string& thisflag =
m_selFlags
[
index
];
36
if
(thisflag.empty()) {
37
ATH_MSG_ERROR
(
"Empty string passed as selection flag!"
);
38
return
StatusCode::FAILURE;
39
}
else
{
40
// Extend m_invertFlags until the size matches m_selectionFlags
41
// Only done in the case that m_invert was empty
42
if
(
m_invertFlags
.size()<
index
+1) {
43
std::vector<bool> flags =
m_invertFlags
.value();
44
flags.resize(
index
+ 1,
false
);
45
m_invertFlags
= flags;
46
}
47
std::string doInvertStr =
m_invertFlags
[
index
] ?
"!"
:
""
;
48
m_accept
.addCut (doInvertStr + thisflag, doInvertStr + thisflag);
49
std::unique_ptr<ISelectionReadAccessor> accessor;
50
ATH_CHECK
(
makeSelectionReadAccessor
(thisflag, accessor,
true
));
51
m_acc_selFlags
.push_back (std::move (accessor));
52
}
53
}
54
55
return
StatusCode::SUCCESS;
56
}
57
58
59
60
const
asg::AcceptInfo
& AsgFlagSelectionTool ::
61
getAcceptInfo ()
const
62
{
63
return
m_accept
;
64
}
65
66
67
68
asg::AcceptData
AsgFlagSelectionTool ::
69
accept (
const
xAOD::IParticle
*particle)
const
70
{
71
asg::AcceptData
accept
(&
m_accept
);
72
for
(std::size_t cutIndex=0; cutIndex<
m_accept
.getNCuts(); ++cutIndex) {
73
// Test against the opposite of the invert value
74
bool
testval = !
m_invertFlags
[cutIndex];
75
ATH_MSG_VERBOSE
(
"Now testing flag \""
<<
m_selFlags
[cutIndex] <<
"\" requiring value "
<< testval);
76
accept
.setCutResult (cutIndex,
m_acc_selFlags
[cutIndex]->getBool (*particle)==testval);
77
}
78
79
return
accept
;
80
}
81
}
82
AsgFlagSelectionTool.h
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_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
CP::AsgFlagSelectionTool::m_invertFlags
Gaudi::Property< std::vector< bool > > m_invertFlags
Definition
AsgFlagSelectionTool.h:78
CP::AsgFlagSelectionTool::m_accept
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
Definition
AsgFlagSelectionTool.h:86
CP::AsgFlagSelectionTool::m_selFlags
Gaudi::Property< std::vector< std::string > > m_selFlags
tool properties
Definition
AsgFlagSelectionTool.h:77
CP::AsgFlagSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const override
The main accept method: the actual cuts are applied here.
Definition
AsgFlagSelectionTool.cxx:69
CP::AsgFlagSelectionTool::m_acc_selFlags
std::vector< std::unique_ptr< ISelectionReadAccessor > > m_acc_selFlags
Definition
AsgFlagSelectionTool.h:79
asg::AcceptData
Definition
AcceptData.h:30
asg::AcceptInfo
Definition
AcceptInfo.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
CP::makeSelectionReadAccessor
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
Definition
ISelectionAccessor.cxx:54
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.14.0