ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace CP {
10
11 ChargeSelectorAlg::ChargeSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
12 : EL::AnaAlgorithm(name, pSvcLocator)
13 {}
14
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;
53 ANA_CHECK(m_electronsHandle.retrieve(electrons, sys));
54 // retrieve the muon container
55 const xAOD::MuonContainer *muons = nullptr;
56 if (m_muonsHandle)
57 ANA_CHECK(m_muonsHandle.retrieve(muons, sys));
58 // retrieve the tau-jet container
59 const xAOD::TauJetContainer *taus = nullptr;
60 if (m_tausHandle)
61 ANA_CHECK(m_tausHandle.retrieve(taus, sys));
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;
80 for (const xAOD::Electron *el : *electrons) {
81 if (!m_electronSelection || m_electronSelection.getBool(*el, sys)){
82 total_charge += el->charge();
83 total_leptons++;
84 }
85 }
86 }
87 if (m_muonsHandle) {
88 for (const xAOD::Muon *mu : *muons) {
89 if (!m_muonSelection || m_muonSelection.getBool(*mu, sys)){
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) {
107 if (!m_electronTruthSelection || m_electronTruthSelection.getBool(*el, sys)){
108 total_charge += el->charge();
109 total_leptons++;
110 }
111 }
112 }
113 if (m_muonsTruthHandle) {
114 for (const xAOD::TruthParticle *mu : *truthMuons) {
115 if (!m_muonTruthSelection || m_muonTruthSelection.getBool(*mu, sys)){
116 total_charge += mu->charge();
117 total_leptons++;
118 }
119 }
120 }
121 if (m_tausTruthHandle) {
122 for (const xAOD::TruthParticle *tau : *truthTaus) {
123 if (!m_tauTruthSelection || m_tauTruthSelection.getBool(*tau, sys)){
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
#define ATH_MSG_ERROR(x)
#define ANA_CHECK(EXP)
check whether the given expression was successful
static Double_t taus
CP::SysReadSelectionHandle m_tauSelection
the tau-jet selection handle
CP::SysReadSelectionHandle m_electronTruthSelection
the truth electron selection handle
CP::SysReadSelectionHandle m_muonTruthSelection
the truth muon selection handle
CP::SysReadSelectionHandle m_preselection
the preselection
CP::SysReadSelectionHandle m_tauTruthSelection
the truth muon selection handle
CP::SysReadHandle< xAOD::ElectronContainer > m_electronsHandle
the electron input handle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_electronsTruthHandle
the truth electron input handle
virtual StatusCode execute() override
CP::SysWriteSelectionHandle m_decoration
the output decoration handle
virtual StatusCode initialize() override
CP::SysReadHandle< xAOD::MuonContainer > m_muonsHandle
the muon input handle
CP::SysReadHandle< xAOD::TruthParticleContainer > m_tausTruthHandle
the truth tau input handle
ChargeSelectorAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
CP::SysReadHandle< xAOD::TruthParticleContainer > m_muonsTruthHandle
the truth muon input handle
CP::SysReadHandle< xAOD::TauJetContainer > m_tausHandle
the tau-jet input handle
CP::SysListHandle m_systematicsList
the systematics list
Gaudi::Property< bool > m_OSmode
whether or not to select 2 opposite-sign leptons
CP::SysReadSelectionHandle m_electronSelection
the electron selection handle
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
the event info handle
CP::SysReadSelectionHandle m_muonSelection
the muon selection handle
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Select isolated Photons, Electrons and Muons.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
EventInfo_v1 EventInfo
Definition of the latest event info version.
TauJet_v3 TauJet
Definition of the current "tau version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
Muon_v1 Muon
Reference the current persistent version:
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Electron_v1 Electron
Definition of the current "egamma version".