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