ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
32 for(size_t index=0; index<m_selFlags.size(); ++index) {
33 const std::string& thisflag = m_selFlags[index];
34 if (thisflag.empty()) {
35 ATH_MSG_ERROR("Empty string passed as selection flag!");
36 return StatusCode::FAILURE;
37 } else {
38 // Extend m_invertFlags until the size matches m_selectionFlags
39 // Only done in the case that m_invert was empty
40 if(m_invertFlags.size()<index+1) {
41 std::vector<bool> flags = m_invertFlags.value();
42 flags.resize(index + 1, false);
43 m_invertFlags = flags;
44 }
45 std::string doInvertStr = m_invertFlags[index] ? "!" : "";
46 m_accept.addCut (doInvertStr + thisflag, doInvertStr + thisflag);
47 std::unique_ptr<ISelectionReadAccessor> accessor;
48 ATH_CHECK (makeSelectionReadAccessor (thisflag, accessor, true));
49 m_acc_selFlags.push_back (std::move (accessor));
50 }
51 }
52
53 return StatusCode::SUCCESS;
54 }
55
56
57
58 const asg::AcceptInfo& AsgFlagSelectionTool ::
59 getAcceptInfo () const
60 {
61 return m_accept;
62 }
63
64
65
66 asg::AcceptData AsgFlagSelectionTool ::
67 accept (const xAOD::IParticle *particle) const
68 {
70 for(std::size_t cutIndex=0; cutIndex<m_accept.getNCuts(); ++cutIndex) {
71 // Test against the opposite of the invert value
72 bool testval = !m_invertFlags[cutIndex];
73 ATH_MSG_VERBOSE("Now testing flag \"" << m_selFlags[cutIndex] << "\" requiring value " << testval);
74 accept.setCutResult (cutIndex, m_acc_selFlags[cutIndex]->getBool (*particle)==testval);
75 }
76
77 return accept;
78 }
79}
80
#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