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());
82 if (true == m_storeLeptonCells)
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 xAOD::Muon::Quality muonQuality = theMuon->quality();
127 if (muonQuality <= xAOD::Muon::Medium) {
128 xAOD::Muon::MuonType muonType = theMuon->muonType();
129 if (xAOD::Muon::Combined == muonType) {
130 if (selectedMuonsWriteHandle.isValid())
131 selectedMuonsWriteHandle->push_back(theMuon);
132 else
134 "Do not have valid WriteHandle for MuonContainer with name: " << selectedMuonsWriteHandle.key());
135 if (true == m_storeLeptonCells)
136 this->storeMuonCells(*theMuon, leptonCaloCellsWriteHandle);
137 } // combined muons
138 } // Medium muons
139 } // muon loop
140
141 return StatusCode::SUCCESS;
142}
143
144void
146 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
147{
148
149 const ElementLink<xAOD::CaloClusterContainer>& theLink = muon.clusterLink();
150 if (theLink.isValid()){
151 const xAOD::CaloCluster* muonCluster = *theLink;
152 if (muonCluster){
153 this->storeLeptonCells(*muonCluster,std::move(leptonCaloCellsWriteHandle));
154 }
155 else ATH_MSG_WARNING("This muon has an invalid pointer to its cluster ");
156 }
157 else ATH_MSG_WARNING("This muon has an invalid element link to its cluster");
158}
159
160void
162 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
163{
164
165 const CaloClusterCellLink* theCellLink = theCluster.getCellLinks();
166
167 if (theCellLink){
168 for (const auto *theCaloCell : *theCellLink){
169 if (leptonCaloCellsWriteHandle.isValid()) leptonCaloCellsWriteHandle->push_back(theCaloCell);
170 else ATH_MSG_WARNING(" Do not have valid WriteHandle for CaloCellContaienr with name: " << leptonCaloCellsWriteHandle.key());
171 }//cell loop
172 }
173 else ATH_MSG_WARNING("This cluster has an invalid pointer to its cells, in storeLeptonCells");
174}
175
176StatusCode
178 SG::WriteHandle<ConstDataVector<xAOD::ElectronContainer>>& selectedElectronsWriteHandle,
179 SG::WriteHandle<ConstDataVector<xAOD::MuonContainer>>& selectedMuonsWriteHandle,
180 SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
181{
182
183 StatusCode sc = selectedElectronsWriteHandle.record(std::make_unique<ConstDataVector<xAOD::ElectronContainer >>(SG::VIEW_ELEMENTS));
184
185 if (sc.isFailure()) {
186 ATH_MSG_WARNING("Could not record electron WriteHandle with key: " << selectedElectronsWriteHandle.key());
187 return sc;
188 }
189
190 sc = selectedMuonsWriteHandle.record(std::make_unique<ConstDataVector<xAOD::MuonContainer> >(SG::VIEW_ELEMENTS));
191
192 if (sc.isFailure()) {
193 ATH_MSG_WARNING("Could not record muon WriteHandle with key: " << selectedMuonsWriteHandle.key());
194 return sc;
195 }
196
197 if (true == m_storeLeptonCells) {
198
199 //record the cell container
200 sc = leptonCaloCellsWriteHandle.record(std::make_unique<ConstDataVector<CaloCellContainer> >(SG::VIEW_ELEMENTS));
201
202 if (sc.isFailure()) {
203 ATH_MSG_WARNING("Could not record CaloCell WriteHandle with key: " << leptonCaloCellsWriteHandle);
204 return sc;
205 }
206 }
207
208 return StatusCode::SUCCESS;
209}
#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 AthAlgorithm 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: