ATLAS Offline Software
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>
6 
7 PFLeptonSelector::PFLeptonSelector(const std::string& name, ISvcLocator* pSvcLocator):
8  AthReentrantAlgorithm(name, pSvcLocator)
9 {
10 }
11 
14  ATH_CHECK( m_muonsReadHandleKey.initialize() );
15 
18 
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode PFLeptonSelector::execute(const EventContext& ctx) const{
25 
29 
30  if (recordLeptonContainers(selectedElectronsWriteHandle,selectedMuonsWriteHandle,leptonCaloCellsWriteHandle).isFailure()) {
31  return StatusCode::SUCCESS;
32  }
33 
34  /* Select electrons */
35  if (m_selectElectrons) {
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 
51 StatusCode PFLeptonSelector::finalize(){ return StatusCode::SUCCESS; }
52 
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 
95 void
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 
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 
144 void
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 
160 void
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 
178  SG::WriteHandle<ConstDataVector<xAOD::ElectronContainer>>& selectedElectronsWriteHandle,
179  SG::WriteHandle<ConstDataVector<xAOD::MuonContainer>>& selectedMuonsWriteHandle,
180  SG::WriteHandle<ConstDataVector<CaloCellContainer>> leptonCaloCellsWriteHandle) const
181 {
182 
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 }
PFLeptonSelector::selectElectrons
StatusCode selectElectrons(SG::WriteHandle< ConstDataVector< xAOD::ElectronContainer >> &selectedElectronsWriteHandle, const SG::WriteHandle< ConstDataVector< CaloCellContainer >> &leptonCaloCellsWriteHandle) const
Select electrons to use.
Definition: PFLeptonSelector.cxx:54
PFLeptonSelector::PFLeptonSelector
PFLeptonSelector(const std::string &name, ISvcLocator *pSvcLocator)
Default constructor.
Definition: PFLeptonSelector.cxx:7
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
PFLeptonSelector::finalize
StatusCode finalize()
Definition: PFLeptonSelector.cxx:51
PFLeptonSelector.h
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PFLeptonSelector::m_storeLeptonCells
Gaudi::Property< bool > m_storeLeptonCells
Toggle storage of lepton CaloCells.
Definition: PFLeptonSelector.h:102
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
PFLeptonSelector::m_selectedElectronsWriteHandleKey
SG::WriteHandleKey< ConstDataVector< xAOD::ElectronContainer > > m_selectedElectronsWriteHandleKey
WriteHandle for the ElectronContainer, that will be filled with electrons passing the electron ID in ...
Definition: PFLeptonSelector.h:75
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PFLeptonSelector::storeElectronCells
void storeElectronCells(const xAOD::Egamma &electron, SG::WriteHandle< ConstDataVector< CaloCellContainer >> leptonCaloCellsWriteHandle) const
store the cells of the electrons
Definition: PFLeptonSelector.cxx:96
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
PFLeptonSelector::execute
StatusCode execute(const EventContext &ctx) const
Definition: PFLeptonSelector.cxx:24
PFLeptonSelector::initialize
StatusCode initialize()
Gaudi AthAlgorithm hooks.
Definition: PFLeptonSelector.cxx:12
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PFLeptonSelector::m_electronID
Gaudi::Property< std::string > m_electronID
Definition: PFLeptonSelector.h:104
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PFLeptonSelector::m_selectedMuonsWriteHandleKey
SG::WriteHandleKey< ConstDataVector< xAOD::MuonContainer > > m_selectedMuonsWriteHandleKey
WriteHandle for the MuonContainer, that will be filled with muons passing the muon ID in PFLeptonSele...
Definition: PFLeptonSelector.h:85
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
PFLeptonSelector::storeMuonCells
void storeMuonCells(const xAOD::Muon &muon, SG::WriteHandle< ConstDataVector< CaloCellContainer >> leptonCaloCellsWriteHandle) const
store the cells of the muons
Definition: PFLeptonSelector.cxx:145
PFLeptonSelector::recordLeptonContainers
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.
Definition: PFLeptonSelector.cxx:177
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
PFLeptonSelector::m_selectMuons
Gaudi::Property< bool > m_selectMuons
Toggle to determine whether we select any muons or not - if selected then tracks matched to those muo...
Definition: PFLeptonSelector.h:116
PFLeptonSelector::m_leptonCaloCellsWriteHandleKey
SG::WriteHandleKey< ConstDataVector< CaloCellContainer > > m_leptonCaloCellsWriteHandleKey
WriteHandle for the CaloCellContainer, that will store calorimeter cells associated to leptons.
Definition: PFLeptonSelector.h:94
LikeEnum::Medium
@ Medium
Definition: LikelihoodEnums.h:14
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
PFLeptonSelector::selectMuons
StatusCode selectMuons(SG::WriteHandle< ConstDataVector< xAOD::MuonContainer >> &selectedMuonsWriteHandle, const SG::WriteHandle< ConstDataVector< CaloCellContainer >> &leptonCaloCellsWriteHandle) const
select muons to use
Definition: PFLeptonSelector.cxx:108
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
PFLeptonSelector::storeLeptonCells
void storeLeptonCells(const xAOD::CaloCluster &theCluster, SG::WriteHandle< ConstDataVector< CaloCellContainer >> leptonCaloCellsWriteHandle) const
puts set of lepton cells into the lepton container
Definition: PFLeptonSelector.cxx:161
PFLeptonSelector::m_electronsReadHandleKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsReadHandleKey
ReadHandle for the ElectronContainer to be used as input.
Definition: PFLeptonSelector.h:60
PFLeptonSelector::m_muonsReadHandleKey
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsReadHandleKey
ReadHandle for the MuonContainer to be used as input.
Definition: PFLeptonSelector.h:68
PFLeptonSelector::m_selectElectrons
Gaudi::Property< bool > m_selectElectrons
Toggle to determine whether we select any electrons or not - if selected then tracks matched to those...
Definition: PFLeptonSelector.h:110