ATLAS Offline Software
ChargeSelectorAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 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 
29 
33 
34  return StatusCode::SUCCESS;
35  }
36 
38  for (const auto &sys : m_systematicsList.systematicsVector()) {
39  // retrieve the EventInfo
40  const xAOD::EventInfo *evtInfo = nullptr;
41  ANA_CHECK(m_eventInfoHandle.retrieve(evtInfo, sys));
42 
43  // default-decorate EventInfo
44  m_decoration.setBool(*evtInfo, 0, sys);
45 
46  // check the preselection
47  if (m_preselection && !m_preselection.getBool(*evtInfo, sys))
48  continue;
49 
50  // retrieve the electron container
51  const xAOD::ElectronContainer *electrons = nullptr;
54  // retrieve the muon container
55  const xAOD::MuonContainer *muons = nullptr;
56  if (m_muonsHandle)
58  // retrieve the tau-jet container
59  const xAOD::TauJetContainer *taus = nullptr;
60  if (m_tausHandle)
62  // retrieve the truth electron container
63  const xAOD::TruthParticleContainer *truthElectrons = nullptr;
65  ANA_CHECK(m_electronsTruthHandle.retrieve(truthElectrons, sys));
66  // retrieve the truth muon container
67  const xAOD::TruthParticleContainer *truthMuons = nullptr;
69  ANA_CHECK(m_muonsTruthHandle.retrieve(truthMuons, sys));
70  // retrieve the truth tau container
71  const xAOD::TruthParticleContainer *truthTaus = nullptr;
73  ANA_CHECK(m_tausTruthHandle.retrieve(truthTaus, sys));
74 
75  // apply the requested selection and compute the local charge
76  int total_charge = 0;
77  int total_leptons = 0;
79  if (m_electronsHandle) {
80  for (const xAOD::Electron *el : *electrons) {
82  total_charge += el->charge();
83  total_leptons++;
84  }
85  }
86  }
87  if (m_muonsHandle) {
88  for (const xAOD::Muon *mu : *muons) {
90  total_charge += mu->charge();
91  total_leptons++;
92  }
93  }
94  }
95  if (m_tausHandle) {
96  for (const xAOD::TauJet *tau : *taus) {
97  if (!m_tauSelection || m_tauSelection.getBool(*tau, sys)){
98  total_charge += tau->charge();
99  total_leptons++;
100  }
101  }
102  }
103  }
104  else {
106  for (const xAOD::TruthParticle *el : *truthElectrons) {
108  total_charge += el->charge();
109  total_leptons++;
110  }
111  }
112  }
113  if (m_muonsTruthHandle) {
114  for (const xAOD::TruthParticle *mu : *truthMuons) {
116  total_charge += mu->charge();
117  total_leptons++;
118  }
119  }
120  }
121  if (m_tausTruthHandle) {
122  for (const xAOD::TruthParticle *tau : *truthTaus) {
124  total_charge += tau->charge();
125  total_leptons++;
126  }
127  }
128  }
129  }
130 
131  // check that there are only 2 leptons
132  if (total_leptons != 2 ) {
133  ATH_MSG_ERROR("Exactly two leptons are required to check whether the event is OS or SS!");
134  return StatusCode::FAILURE;
135  }
136 
137  // compare to the requested mode
138  bool decision = m_OSmode ? total_charge == 0 : std::abs(total_charge) == 2;
139  m_decoration.setBool(*evtInfo, decision, sys);
140  }
141  return StatusCode::SUCCESS;
142  }
143 } // namespace CP
CP::ChargeSelectorAlg::m_electronsHandle
CP::SysReadHandle< xAOD::ElectronContainer > m_electronsHandle
the electron input handle
Definition: ChargeSelectorAlg.h:48
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:88
CP::SysReadHandle::retrieve
::StatusCode retrieve(const T *&object, const CP::SystematicSet &sys) const
retrieve the object for the given name
CP::ChargeSelectorAlg::m_tauTruthSelection
CP::SysReadSelectionHandle m_tauTruthSelection
the truth muon selection handle
Definition: ChargeSelectorAlg.h:103
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:49
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:53
CP::ChargeSelectorAlg::m_muonsHandle
CP::SysReadHandle< xAOD::MuonContainer > m_muonsHandle
the muon input handle
Definition: ChargeSelectorAlg.h:58
CP::ChargeSelectorAlg::m_preselection
CP::SysReadSelectionHandle m_preselection
the preselection
Definition: ChargeSelectorAlg.h:113
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
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
CP::ChargeSelectorAlg::execute
virtual StatusCode execute() override
Definition: ChargeSelectorAlg.cxx:37
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AsgComponentFactories.h:16
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
CP::ChargeSelectorAlg::m_decoration
CP::SysWriteSelectionHandle m_decoration
the output decoration handle
Definition: ChargeSelectorAlg.h:118
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:108
CP::ChargeSelectorAlg::m_tauSelection
CP::SysReadSelectionHandle m_tauSelection
the tau-jet selection handle
Definition: ChargeSelectorAlg.h:73
CP::ChargeSelectorAlg::m_muonSelection
CP::SysReadSelectionHandle m_muonSelection
the muon selection handle
Definition: ChargeSelectorAlg.h:63
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:42
CP::ChargeSelectorAlg::m_electronTruthSelection
CP::SysReadSelectionHandle m_electronTruthSelection
the truth electron selection handle
Definition: ChargeSelectorAlg.h:83
CP::ChargeSelectorAlg::m_tausTruthHandle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_tausTruthHandle
the truth tau input handle
Definition: ChargeSelectorAlg.h:98
CP::ChargeSelectorAlg::m_muonTruthSelection
CP::SysReadSelectionHandle m_muonTruthSelection
the truth muon selection handle
Definition: ChargeSelectorAlg.h:93
CP::ChargeSelectorAlg::m_tausHandle
CP::SysReadHandle< xAOD::TauJetContainer > m_tausHandle
the tau-jet input handle
Definition: ChargeSelectorAlg.h:68
CP::ChargeSelectorAlg::m_electronsTruthHandle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_electronsTruthHandle
the truth electron input handle
Definition: ChargeSelectorAlg.h:78
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:51
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CP::ChargeSelectorAlg::m_systematicsList
CP::SysListHandle m_systematicsList
the systematics list
Definition: ChargeSelectorAlg.h:45
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