ATLAS Offline Software
ElectronLRTMergingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ElectronLRTMergingAlg
7 //
8 // Electron merger algorithm merges the standard and LRT electron containers.
9 // It uses the ElectronLRTOverlapRemovalTool to remove overlaps.
10 // The output merged collection is decorated with isLRT=0/1 to denote
11 // if the electron was from the standard or LRT container. Merging can
12 // be output into a transient view container or copied container written out.
14 
17 #include "AsgTools/AsgToolConfig.h"
18 
19 namespace CP
20 {
21  ElectronLRTMergingAlg::ElectronLRTMergingAlg(const std::string &name, ISvcLocator *svcLoc)
22  : EL::AnaAlgorithm(name, svcLoc)
23  {
24  }
25 
27  {
28  // Greet the user:
29  ATH_MSG_INFO("Initialising");
30 
34 
36  if (m_overlapRemovalTool.empty())
37  {
38  asg::AsgToolConfig config("CP::ElectronLRTOverlapRemovalTool/ElectronLRTOverlapRemovalTool");
39  ATH_CHECK(config.setProperty("overlapStrategy", m_ORstrategy.value()));
40  ATH_CHECK(config.setProperty("isDAOD", m_isDAOD.value()));
41  ATH_CHECK(config.makePrivateTool(m_overlapRemovalTool));
42  }
43 
44  // Retrieve the tools
45  ATH_CHECK(m_overlapRemovalTool.retrieve());
46 
47  // Return gracefully:
48  return StatusCode::SUCCESS;
49  }
50 
51 
53  {
54 
55  const EventContext &ctx = Gaudi::Hive::currentContext();
56 
57  // Setup containers for output, to avoid const conversions setup two different kind of containers
58  std::unique_ptr<ConstDataVector<xAOD::ElectronContainer>> transientContainer = std::make_unique<ConstDataVector<xAOD::ElectronContainer>>(SG::VIEW_ELEMENTS);
59  std::unique_ptr<xAOD::ElectronContainer> outputCol = std::make_unique<xAOD::ElectronContainer>();
60 
61  // Aux container, if needed
62  std::unique_ptr<xAOD::ElectronAuxContainer> outputAuxCol;
63 
64  // Assign the aux in the copy case
66  {
67  outputAuxCol = std::make_unique<xAOD::ElectronAuxContainer>();
68  outputCol->setStore(outputAuxCol.get());
69  }
70 
71  // Retrieve electrons from StoreGate
74  if (!promptCol.isValid())
75  {
76  ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_promptElectronLocation << "\", cannot run the LRT electron merger!");
77  return StatusCode::FAILURE;
78  }
79  if (!lrtCol.isValid())
80  {
81  ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_lrtElectronLocation << "\", cannot run the LRT electron merger!");
82  return StatusCode::FAILURE;
83  }
84 
85 
86  std::set<const xAOD::Electron *> ElectronsToRemove;
87  m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, ElectronsToRemove);
88 
89  ATH_MSG_DEBUG("Size of overlapping electrons to remove: " << ElectronsToRemove.size());
90 
91  // Decorate the electrons with their track type
92  static const SG::AuxElement::Decorator<char> isLRT("isLRT"); // false if prompt, true if LRT
93  for (const xAOD::Electron *el : *promptCol)
94  isLRT(*el) = 0;
95  for (const xAOD::Electron *el : *lrtCol)
96  isLRT(*el) = 1;
97 
98  // merging loop over containers
100  {
101  transientContainer->reserve(promptCol->size() + lrtCol->size());
102 
103  mergeElectron(*promptCol, transientContainer.get(), ElectronsToRemove);
104  mergeElectron(*lrtCol, transientContainer.get(), ElectronsToRemove);
105  }
106  else
107  {
108  outputCol->reserve(promptCol->size() + lrtCol->size());
109 
110  mergeElectron(*promptCol, outputCol.get(), ElectronsToRemove);
111  mergeElectron(*lrtCol, outputCol.get(), ElectronsToRemove);
112  }
113 
116  {
117  ATH_CHECK(evtStore()->record(transientContainer.release(), m_outElectronLocation.key()));
118  }
119  else
120  {
121  ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
122  }
123 
124  ATH_MSG_DEBUG("Done !");
125 
126  return StatusCode::SUCCESS;
127  }
128 
130  // Merge electron collections and remove duplicates, for copy
133  xAOD::ElectronContainer *outputCol,
134  const std::set<const xAOD::Electron *> &ElectronsToRemove) const
135  {
136  // loop over electrons, accept them and add them into association tool
137  if (!electronCol.empty())
138  {
139  ATH_MSG_DEBUG("Size of output electron collection " << electronCol.size());
140 
141  static const SG::AuxElement::Decorator<ElementLink<xAOD::ElectronContainer>> originalElectronLink("originalElectronLink");
142 
143  // loop over electrons
144  for (const auto *const electron : electronCol)
145  {
146  // add electron into output and check if LRT electron failed overlap check
147  if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
148  continue;
149  else
150  {
151  std::unique_ptr<xAOD::Electron> newElectron = std::make_unique<xAOD::Electron>(*electron);
153  eLink.toIndexedElement(electronCol, electron->index());
154  originalElectronLink(*newElectron) = eLink;
155 
156  outputCol->push_back(std::move(newElectron));
157  }
158  }
159  ATH_MSG_DEBUG("Size of merged output electron collection " << outputCol->size());
160  }
161  }
162 
164  // Merge electron collections and remove duplicates, for transient
168  const std::set<const xAOD::Electron *> &ElectronsToRemove) const
169  {
170  // loop over electrons, accept them and add them into association tool
171  if (!electronCol.empty())
172  {
173  ATH_MSG_DEBUG("Size of transient electron collection " << electronCol.size());
174  // loop over electrons
175  for (const auto *const electron : electronCol)
176  {
177  // add electron into output and check if LRT electron failed overlap check
178  if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
179  continue;
180  else
181  {
182  outputCol->push_back(electron);
183  }
184  }
185  ATH_MSG_DEBUG("Size of transient merged electron collection " << outputCol->size());
186  }
187  }
188 
189 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CP::ElectronLRTMergingAlg::m_isDAOD
Gaudi::Property< bool > m_isDAOD
Definition: ElectronLRTMergingAlg.h:60
CP::ElectronLRTMergingAlg::initialize
StatusCode initialize() override
Definition: ElectronLRTMergingAlg.cxx:26
CP::ElectronLRTMergingAlg::m_lrtElectronLocation
SG::ReadHandleKey< xAOD::ElectronContainer > m_lrtElectronLocation
Standard electron collection to be merged.
Definition: ElectronLRTMergingAlg.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::ElectronLRTMergingAlg::m_createViewCollection
Gaudi::Property< bool > m_createViewCollection
Protected data:
Definition: ElectronLRTMergingAlg.h:50
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CP::ElectronLRTMergingAlg::m_doRemoval
Gaudi::Property< bool > m_doRemoval
Create a view to avoid deep copy.
Definition: ElectronLRTMergingAlg.h:52
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CP::ElectronLRTMergingAlg::m_ORstrategy
Gaudi::Property< int > m_ORstrategy
Delta R threshold for matching in overlap removal.
Definition: ElectronLRTMergingAlg.h:58
asg::AsgToolConfig
an object that can create a AsgTool
Definition: AsgToolConfig.h:22
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
ElectronAuxContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AsgToolConfig.h
CP::ElectronLRTMergingAlg::m_outElectronLocation
SG::WriteHandleKey< xAOD::ElectronContainer > m_outElectronLocation
LRT electron collection to be merged.
Definition: ElectronLRTMergingAlg.h:66
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
CP::ElectronLRTMergingAlg::ElectronLRTMergingAlg
ElectronLRTMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
Definition: ElectronLRTMergingAlg.cxx:21
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
ElectronLRTMergingAlg.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::Electron_v1
Definition: Electron_v1.h:34
CP::ElectronLRTMergingAlg::m_overlapRemovalTool
ToolHandle< CP::IElectronLRTOverlapRemovalTool > m_overlapRemovalTool
Combined electron collection.
Definition: ElectronLRTMergingAlg.h:68
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CP::ElectronLRTMergingAlg::execute
StatusCode execute() override
Definition: ElectronLRTMergingAlg.cxx:52
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
python.HLT.Muon.MuonRecoSequences.isLRT
def isLRT(name)
Definition: MuonRecoSequences.py:66
CP::ElectronLRTMergingAlg::mergeElectron
void mergeElectron(const xAOD::ElectronContainer &electronCol, xAOD::ElectronContainer *outputCol, const std::set< const xAOD::Electron * > &LRTElectronsToRemove) const
The lrt electron overlap removal tool.
Definition: ElectronLRTMergingAlg.cxx:132
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
CP::ElectronLRTMergingAlg::m_promptElectronLocation
SG::ReadHandleKey< xAOD::ElectronContainer > m_promptElectronLocation
Switches method for retrieving electron ID.
Definition: ElectronLRTMergingAlg.h:62
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.