ATLAS Offline Software
ChargeSelectorAlg.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 
8 
9 namespace CP {
10 
11  ChargeSelectorAlg::ChargeSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
12  : EL::AnaAlgorithm(name, pSvcLocator)
13  {}
14 
25 
29 
30  return StatusCode::SUCCESS;
31  }
32 
34  for (const auto &sys : m_systematicsList.systematicsVector()) {
35  // retrieve the EventInfo
36  const xAOD::EventInfo *evtInfo = nullptr;
37  ANA_CHECK(m_eventInfoHandle.retrieve(evtInfo, sys));
38 
39  // default-decorate EventInfo
40  m_decoration.setBool(*evtInfo, 0, sys);
41 
42  // check the preselection
43  if (m_preselection && !m_preselection.getBool(*evtInfo, sys))
44  continue;
45 
46  // retrieve the electron container
47  const xAOD::ElectronContainer *electrons = nullptr;
50  // retrieve the muon container
51  const xAOD::MuonContainer *muons = nullptr;
52  if (m_muonsHandle)
54  // retrieve the truth electron container
55  const xAOD::TruthParticleContainer *truthElectrons = nullptr;
57  ANA_CHECK(m_electronsTruthHandle.retrieve(truthElectrons, sys));
58  // retrieve the truth muon container
59  const xAOD::TruthParticleContainer *truthMuons = nullptr;
61  ANA_CHECK(m_muonsTruthHandle.retrieve(truthMuons, sys));
62 
63  // apply the requested selection and compute the local charge
64  int total_charge = 0;
65  int total_leptons = 0;
67  if (m_electronsHandle) {
68  for (const xAOD::Electron *el : *electrons) {
70  total_charge += el->charge();
71  total_leptons++;
72  }
73  }
74  }
75  if (m_muonsHandle) {
76  for (const xAOD::Muon *mu : *muons) {
78  total_charge += mu->charge();
79  total_leptons++;
80  }
81  }
82  }
83  }
84  else {
86  for (const xAOD::TruthParticle *el : *truthElectrons) {
88  total_charge += el->charge();
89  total_leptons++;
90  }
91  }
92  }
93  if (m_muonsTruthHandle) {
94  for (const xAOD::TruthParticle *mu : *truthMuons) {
96  total_charge += mu->charge();
97  total_leptons++;
98  }
99  }
100  }
101  }
102 
103  // check that there are only 2 leptons
104  if (total_leptons != 2 ) {
105  ATH_MSG_ERROR("Exactly two leptons are required to check whether the event is OS or SS!");
106  return StatusCode::FAILURE;
107  }
108 
109  // compare to the requested mode
110  bool decision = m_OSmode ? total_charge == 0 : std::abs(total_charge) == 2;
111  m_decoration.setBool(*evtInfo, decision, sys);
112  }
113  return StatusCode::SUCCESS;
114  }
115 } // namespace CP
CP::ChargeSelectorAlg::m_electronsHandle
CP::SysReadHandle< xAOD::ElectronContainer > m_electronsHandle
the electron input handle
Definition: ChargeSelectorAlg.h:47
CP::ChargeSelectorAlg::initialize
virtual StatusCode initialize() override
Definition: ChargeSelectorAlg.cxx:15
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
CP::ChargeSelectorAlg::m_muonsTruthHandle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_muonsTruthHandle
the truth muon input handle
Definition: ChargeSelectorAlg.h:77
CP::SysReadHandle::retrieve
::StatusCode retrieve(const T *&object, const CP::SystematicSet &sys) const
retrieve the object for the given name
CP::SysListHandle::systematicsVector
const std::vector< CP::SystematicSet > & systematicsVector() const
the list of systematics to loop over
Definition: SysListHandle.cxx:96
ChargeSelectorAlg.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::SysWriteSelectionHandle::setBool
void setBool(const SG::AuxElement &element, bool selection, const CP::SystematicSet &sys) const
set the selection decoration
CP::ChargeSelectorAlg::m_electronSelection
CP::SysReadSelectionHandle m_electronSelection
the electron selection handle
Definition: ChargeSelectorAlg.h:52
CP::ChargeSelectorAlg::m_muonsHandle
CP::SysReadHandle< xAOD::MuonContainer > m_muonsHandle
the muon input handle
Definition: ChargeSelectorAlg.h:57
CP::ChargeSelectorAlg::m_preselection
CP::SysReadSelectionHandle m_preselection
the preselection
Definition: ChargeSelectorAlg.h:92
CP::SysReadHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle)
initialize this handle
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CP::SysListHandle::initialize
::StatusCode initialize()
intialize this property
Definition: SysListHandle.cxx:69
CP::SysReadSelectionHandle::getBool
bool getBool(const SG::AuxElement &element, const CP::SystematicSet &sys) const
get the selection as a bool
CP::ChargeSelectorAlg::ChargeSelectorAlg
ChargeSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: ChargeSelectorAlg.cxx:11
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
CP::ChargeSelectorAlg::execute
virtual StatusCode execute() override
Definition: ChargeSelectorAlg.cxx:33
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CP::ChargeSelectorAlg::m_decoration
CP::SysWriteSelectionHandle m_decoration
the output decoration handle
Definition: ChargeSelectorAlg.h:97
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
CP::ChargeSelectorAlg::m_eventInfoHandle
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the event info handle
Definition: ChargeSelectorAlg.h:87
CP::ChargeSelectorAlg::m_muonSelection
CP::SysReadSelectionHandle m_muonSelection
the muon selection handle
Definition: ChargeSelectorAlg.h:62
CP::SysReadSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysReadSelectionHandle.cxx:34
CP::ChargeSelectorAlg::m_OSmode
Gaudi::Property< bool > m_OSmode
whether or not to select 2 opposite-sign leptons
Definition: ChargeSelectorAlg.h:41
CP::ChargeSelectorAlg::m_electronTruthSelection
CP::SysReadSelectionHandle m_electronTruthSelection
the truth electron selection handle
Definition: ChargeSelectorAlg.h:72
CP::ChargeSelectorAlg::m_muonTruthSelection
CP::SysReadSelectionHandle m_muonTruthSelection
the truth muon selection handle
Definition: ChargeSelectorAlg.h:82
CP::ChargeSelectorAlg::m_electronsTruthHandle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_electronsTruthHandle
the truth electron input handle
Definition: ChargeSelectorAlg.h:67
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::ChargeSelectorAlg::m_systematicsList
CP::SysListHandle m_systematicsList
the systematics list
Definition: ChargeSelectorAlg.h:44
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
CP::SysWriteSelectionHandle::initialize
StatusCode initialize(SysListHandle &sysListHandle, const ISysHandleBase &objectHandle)
initialize the accessor
Definition: SysWriteSelectionHandle.cxx:34