ATLAS Offline Software
AsgMaskSelectionTool.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 #include <cmath>
16 
17 //
18 // method implementations
19 //
20 
21 namespace CP
22 {
23 
25  initialize ()
26  {
27  if(m_selVars.size() != m_selMasks.size()) {
28  ATH_MSG_ERROR("Property selectionMasks has different size to selectionVars. 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_selVars.size(); ++index) {
35  const std::string& thisVar = m_selVars[index];
36  if (thisVar.empty()) {
37  ATH_MSG_ERROR("Empty string passed as selection variable!");
38  return StatusCode::FAILURE;
39  } else {
40  // Setup acceptInfo and create accessor to read variable on execute
41  m_accept.addCut (thisVar, thisVar);
42  std::unique_ptr<ISelectionReadAccessor> accessor;
44  m_acc_selVars.push_back (std::move (accessor));
45  }
46  }
47 
48  return StatusCode::SUCCESS;
49  }
50 
52  getAcceptInfo () const
53  {
54  return m_accept;
55  }
56 
58  accept (const xAOD::IParticle *particle) const
59  {
61  for(std::size_t cutIndex=0; cutIndex<m_accept.getNCuts(); ++cutIndex) {
62  // Apply mask and test
63  int mask = m_selMasks[cutIndex];
64  ATH_MSG_VERBOSE("Now testing var \"" << m_selVars[cutIndex] << "\" requiring value " << mask);
65  accept.setCutResult (cutIndex, ((m_acc_selVars[cutIndex]->getBits (*particle) & mask ) == 0 ));
66  }
67 
68  return accept;
69  }
70 }
71 
CP::AsgMaskSelectionTool::m_selMasks
Gaudi::Property< std::vector< unsigned int > > m_selMasks
Definition: AsgMaskSelectionTool.h:69
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
CP::AsgMaskSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Declare the interface ID for this pure-virtual interface class to the Athena framework.
Definition: AsgMaskSelectionTool.cxx:52
Trig::FeatureAccessImpl::getBits
const TrigPassBits * getBits(size_t sz, const HLT::TriggerElement *te, const std::string &, const HLT::NavigationCore *navigation)
Definition: FeatureCollectAthena.cxx:21
index
Definition: index.py:1
CP::AsgMaskSelectionTool::accept
virtual asg::AcceptData accept(const xAOD::IParticle *part) const override
The main accept method: the actual cuts are applied here.
Definition: AsgMaskSelectionTool.cxx:58
CP::AsgMaskSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: AsgMaskSelectionTool.cxx:25
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
CP::AsgMaskSelectionTool::m_acc_selVars
std::vector< std::unique_ptr< ISelectionReadAccessor > > m_acc_selVars
Definition: AsgMaskSelectionTool.h:70
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AcceptInfo
Definition: AcceptInfo.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
asg::AcceptInfo::getNCuts
unsigned int getNCuts() const
Get the number of cuts defined.
Definition: AcceptInfo.h:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CP::AsgMaskSelectionTool::m_accept
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
Definition: AsgMaskSelectionTool.h:77
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
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
DeMoScan.index
string index
Definition: DeMoScan.py:362
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
CP::AsgMaskSelectionTool::m_selVars
Gaudi::Property< std::vector< std::string > > m_selVars
tool properties
Definition: AsgMaskSelectionTool.h:68
asg::AcceptData
Definition: AcceptData.h:30
AsgMaskSelectionTool.h
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53