ATLAS Offline Software
Loading...
Searching...
No Matches
PFLeptonSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4#include <utility>
5#include "PFLeptonSelector.h"
6
7PFLeptonSelector::PFLeptonSelector(const std::string& name, ISvcLocator* pSvcLocator):
8 AthReentrantAlgorithm(name, pSvcLocator)
9{
10}
11
13 ATH_CHECK( m_electronsReadHandleKey.initialize() );
14 ATH_CHECK( m_muonsReadHandleKey.initialize() );
15
18
20
21 return StatusCode::SUCCESS;
22}
23
24StatusCode PFLeptonSelector::execute(const EventContext& ctx) const{
25
29
30 if (recordLeptonContainers(selectedElectronsWriteHandle,selectedMuonsWriteHandle,leptonCaloCellsWriteHandle).isFailure()) {
31 return StatusCode::SUCCESS;
32 }
33
34 /* Select electrons */
36 StatusCode sc = this->selectElectrons(selectedElectronsWriteHandle,leptonCaloCellsWriteHandle);
37 //if fail to select electrons issue warning, but carry on processing event
38 if (sc.isFailure()) ATH_MSG_WARNING(" Problem selecting electrons");
39 }
40
41 /* Select muons */
42 if (m_selectMuons){
43 StatusCode sc = this->selectMuons(selectedMuonsWriteHandle,leptonCaloCellsWriteHandle);
44 //if fail to select muons issue warning, but carry on processing event
45 if (sc.isFailure()) ATH_MSG_WARNING("Problem selecting muons ");
46 }
47
48 return StatusCode::SUCCESS;
49}
50
51StatusCode PFLeptonSelector::finalize(){ return StatusCode::SUCCESS; }
52
53StatusCode
55 SG::WriteHandle<ConstDataVector<xAOD::ElectronContainer>>& selectedElectronsWriteHandle,
56 const SG::WriteHandle<ConstDataVector<CaloCellContainer>>& leptonCaloCellsWriteHandle) const
57{
58
60
61 if (!electronsReadHandle.isValid()){
62 ATH_MSG_WARNING("Invalid read handle to electron container with name: " << electronsReadHandle.key());
63 return StatusCode::FAILURE;
64 }
65
66 for (const auto* theElectron : *electronsReadHandle) {
67
68 if (theElectron) {
69 if (theElectron->pt() > 10000) {
70 bool passElectronID = false;
71 bool gotID = theElectron->passSelection(passElectronID, m_electronID);
72 if (!gotID) {
73 ATH_MSG_WARNING("Could not get Electron ID");
74 continue;
75 }
76 if (passElectronID) {
77 if (selectedElectronsWriteHandle.isValid())
78 selectedElectronsWriteHandle->push_back(theElectron);
79 else
81 "Do not have valid WriteHandle for ElectronContainer with name: " << selectedElectronsWriteHandle.key());
83 this->storeElectronCells(*theElectron, leptonCaloCellsWriteHandle);
84 } // mediumPP
85 } // 10GeV pt cut
86 } // valid egamma pointer
87 else
88 ATH_MSG_WARNING("This electron is a NULL pointer");
89
90 } // electron loop
91
92 return StatusCode::SUCCESS;
93}
94
95void
97 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
98{
99
100 const xAOD::CaloCluster* electronCluster = electron.caloCluster();
101 if (electronCluster){
102 this->storeLeptonCells(*electronCluster,std::move(leptonCaloCellsWriteHandle));
103 }
104 else ATH_MSG_WARNING("This electron has an invalid pointer to its cluster");
105}
106
107StatusCode
109 const SG::WriteHandle<ConstDataVector<CaloCellContainer>>& leptonCaloCellsWriteHandle) const
110{
111
113
114 if (!muonsReadHandle.isValid()) {
115 ATH_MSG_WARNING("Invalid read handle to muon container with name: " << muonsReadHandle.key());
116 return StatusCode::FAILURE;
117 }
118
119 for (const auto *theMuon : *muonsReadHandle){
120
121 // Details of medium muons are here:
122 // https://twiki.cern.ch/twiki/bin/view/Atlas/MuonSelectionTool
123 // We only care about muons with ID tracks. Of the muon types which could be medium, only Combined have ID tracks
124 // (for looser selections other muon types could have ID tracks)
125
126 if (theMuon->quality() <= xAOD::Muon::Quality::Medium) {
127 if (xAOD::Muon::MuonType::Combined == theMuon->muonType()) {
128 if (selectedMuonsWriteHandle.isValid())
129 selectedMuonsWriteHandle->push_back(theMuon);
130 else
132 "Do not have valid WriteHandle for MuonContainer with name: " << selectedMuonsWriteHandle.key());
134 this->storeMuonCells(*theMuon, leptonCaloCellsWriteHandle);
135 } // combined muons
136 } // Medium muons
137 } // muon loop
138
139 return StatusCode::SUCCESS;
140}
141
142void
144 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
145{
146
147 if (const xAOD::CaloCluster* muonCluster = muon.cluster(); muonCluster != nullptr){
148 this->storeLeptonCells(*muonCluster,std::move(leptonCaloCellsWriteHandle));
149
150 }
151 else ATH_MSG_WARNING("This muon has an invalid element link to its cluster");
152}
153
154void
156 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
157{
158
159 const CaloClusterCellLink* theCellLink = theCluster.getCellLinks();
160
161 if (theCellLink){
162 for (const auto *theCaloCell : *theCellLink){
163 if (leptonCaloCellsWriteHandle.isValid()) leptonCaloCellsWriteHandle->push_back(theCaloCell);
164 else ATH_MSG_WARNING(" Do not have valid WriteHandle for CaloCellContaienr with name: " << leptonCaloCellsWriteHandle.key());
165 }//cell loop
166 }
167 else ATH_MSG_WARNING("This cluster has an invalid pointer to its cells, in storeLeptonCells");
168}
169
170StatusCode
172 SG::WriteHandle<ConstDataVector<xAOD::ElectronContainer>>& selectedElectronsWriteHandle,
173 SG::WriteHandle<ConstDataVector<xAOD::MuonContainer>>& selectedMuonsWriteHandle,
174 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
175{
176
177 StatusCode sc = selectedElectronsWriteHandle.record(std::make_unique<ConstDataVector<xAOD::ElectronContainer >>(SG::VIEW_ELEMENTS));
178
179 if (sc.isFailure()) {
180 ATH_MSG_WARNING("Could not record electron WriteHandle with key: " << selectedElectronsWriteHandle.key());
181 return sc;
182 }
183
184 sc = selectedMuonsWriteHandle.record(std::make_unique<ConstDataVector<xAOD::MuonContainer> >(SG::VIEW_ELEMENTS));
185
186 if (sc.isFailure()) {
187 ATH_MSG_WARNING("Could not record muon WriteHandle with key: " << selectedMuonsWriteHandle.key());
188 return sc;
189 }
190
191 if (m_storeLeptonCells) {
192
193 //record the cell container
194 sc = leptonCaloCellsWriteHandle.record(std::make_unique<ConstDataVector<CaloCellContainer> >(SG::VIEW_ELEMENTS));
195
196 if (sc.isFailure()) {
197 ATH_MSG_WARNING("Could not record CaloCell WriteHandle with key: " << leptonCaloCellsWriteHandle);
198 return sc;
199 }
200 }
201
202 return StatusCode::SUCCESS;
203}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static Double_t sc
An algorithm that can be simultaneously executed in multiple threads.
DataVector adapter that acts like it holds const pointers.
StatusCode selectElectrons(SG::WriteHandle< ConstDataVector< xAOD::ElectronContainer > > &selectedElectronsWriteHandle, const SG::WriteHandle< ConstDataVector< CaloCellContainer > > &leptonCaloCellsWriteHandle) const
Select electrons to use.
StatusCode execute(const EventContext &ctx) const
void storeLeptonCells(const xAOD::CaloCluster &theCluster, SG::WriteHandle< ConstDataVector< CaloCellContainer > > leptonCaloCellsWriteHandle) const
puts set of lepton cells into the lepton container
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsReadHandleKey
ReadHandle for the ElectronContainer to be used as input.
StatusCode initialize()
Gaudi AthReentrantAlgorithm hooks.
void storeMuonCells(const xAOD::Muon &muon, SG::WriteHandle< ConstDataVector< CaloCellContainer > > leptonCaloCellsWriteHandle) const
store the cells of the muons
SG::WriteHandleKey< ConstDataVector< xAOD::ElectronContainer > > m_selectedElectronsWriteHandleKey
WriteHandle for the ElectronContainer, that will be filled with electrons passing the electron ID in ...
StatusCode selectMuons(SG::WriteHandle< ConstDataVector< xAOD::MuonContainer > > &selectedMuonsWriteHandle, const SG::WriteHandle< ConstDataVector< CaloCellContainer > > &leptonCaloCellsWriteHandle) const
select muons to use
SG::WriteHandleKey< ConstDataVector< CaloCellContainer > > m_leptonCaloCellsWriteHandleKey
WriteHandle for the CaloCellContainer, that will store calorimeter cells associated to leptons.
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_selectedMuonsWriteHandleKey
WriteHandle for the MuonContainer, that will be filled with muons passing the muon ID in PFLeptonSele...
StatusCode recordLeptonContainers(SG::WriteHandle< ConstDataVector< xAOD::ElectronContainer > > &selectedElectronsWriteHandle, SG::WriteHandle< ConstDataVector< xAOD::MuonContainer > > &selectedMuonsWriteHandle, SG::WriteHandle< ConstDataVector< CaloCellContainer > > leptonCaloCellsWriteHandle) const
Put lepton containers and list of lepton cells into Storegate.
Gaudi::Property< std::string > m_electronID
Gaudi::Property< bool > m_storeLeptonCells
Toggle storage of lepton CaloCells.
Gaudi::Property< bool > m_selectElectrons
Toggle to determine whether we select any electrons or not - if selected then tracks matched to those...
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsReadHandleKey
ReadHandle for the MuonContainer to be used as input.
PFLeptonSelector(const std::string &name, ISvcLocator *pSvcLocator)
Default constructor.
void storeElectronCells(const xAOD::Egamma &electron, SG::WriteHandle< ConstDataVector< CaloCellContainer > > leptonCaloCellsWriteHandle) const
store the cells of the electrons
Gaudi::Property< bool > m_selectMuons
Toggle to determine whether we select any muons or not - if selected then tracks matched to those muo...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version).
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Muon_v1 Muon
Reference the current persistent version: