ATLAS Offline Software
Loading...
Searching...
No Matches
ElectronLRTMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
20
21namespace CP
22{
24 {
26 ANA_CHECK(m_lrtElectronLocation.initialize());
27 ANA_CHECK(m_outElectronLocation.initialize());
30 ANA_CHECK(m_lrtIsLRTKey.initialize());
31 ANA_CHECK(m_promptIsLRTKey.initialize());
32
34 if (m_overlapRemovalTool.empty())
35 {
36 asg::AsgToolConfig config("CP::ElectronLRTOverlapRemovalTool/ElectronLRTOverlapRemovalTool");
37 ANA_CHECK(config.setProperty("overlapStrategy", m_ORstrategy.value()));
38 ANA_CHECK(config.setProperty("ORThreshold", m_ORThreshold.value()));
39 ANA_CHECK(config.setProperty("isDAOD", m_isDAOD.value()));
40 ANA_CHECK(config.makePrivateTool(m_overlapRemovalTool));
41 }
42
43 // Retrieve the tools
45
46 // Return gracefully:
47 return StatusCode::SUCCESS;
48 }
49
50
51 StatusCode ElectronLRTMergingAlg::execute(const EventContext &ctx) const
52 {
53
54 // Retrieve electrons from StoreGate
57 if (!promptCol.isValid())
58 {
59 ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_promptElectronLocation << "\", cannot run the LRT electron merger!");
60 return StatusCode::FAILURE;
61 }
62 if (!lrtCol.isValid())
63 {
64 ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_lrtElectronLocation << "\", cannot run the LRT electron merger!");
65 return StatusCode::FAILURE;
66 }
67
68
69 std::set<const xAOD::Electron *> ElectronsToRemove;
70 m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, ElectronsToRemove);
71
72 ATH_MSG_DEBUG("Size of overlapping electrons to remove: " << ElectronsToRemove.size());
73
74 // Decorate the electrons with their track type
75 // 0 if prompt, 1 if LRT
78 for (const xAOD::Electron *el : *promptCol)
79 promptIsLRT(*el) = 0;
80 for (const xAOD::Electron *el : *lrtCol)
81 lrtIsLRT(*el) = 1;
82
83 // merging loop over containers and write, using a view container or a deep copy
85 {
86 auto transientContainer = std::make_unique<ConstDataVector<xAOD::ElectronContainer>>(SG::VIEW_ELEMENTS);
87 transientContainer->reserve(promptCol->size() + lrtCol->size());
88
89 mergeElectron(*promptCol, transientContainer.get(), ElectronsToRemove);
90 mergeElectron(*lrtCol, transientContainer.get(), ElectronsToRemove);
91
93 ATH_CHECK(h_write.record(std::move(transientContainer)));
94 }
95 else
96 {
97 auto outputCol = std::make_unique<xAOD::ElectronContainer>();
98 auto outputAuxCol = std::make_unique<xAOD::ElectronAuxContainer>();
99 outputCol->setStore(outputAuxCol.get());
100 outputCol->reserve(promptCol->size() + lrtCol->size());
101
102 mergeElectron(*promptCol, outputCol.get(), ElectronsToRemove);
103 mergeElectron(*lrtCol, outputCol.get(), ElectronsToRemove);
104
106 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
107 }
108
109 ATH_MSG_DEBUG("Done !");
110
111 return StatusCode::SUCCESS;
112 }
113
115 // Merge electron collections and remove duplicates, for copy
117
119 xAOD::ElectronContainer *outputCol,
120 const std::set<const xAOD::Electron *> &ElectronsToRemove) const
121 {
122 // loop over electrons, accept them and add them into association tool
123 if (!electronCol.empty())
124 {
125 ATH_MSG_DEBUG("Size of output electron collection " << electronCol.size());
126
127 static const SG::Decorator<ElementLink<xAOD::ElectronContainer>> originalElectronLink("originalElectronLink");
128
129 // loop over electrons
130 for (const auto *const electron : electronCol)
131 {
132 // add electron into output and check if LRT electron failed overlap check
133 if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
134 continue;
135 else
136 {
137 std::unique_ptr<xAOD::Electron> newElectron = std::make_unique<xAOD::Electron>(*electron);
139 eLink.toIndexedElement(electronCol, electron->index());
140 originalElectronLink(*newElectron) = eLink;
141 setOriginalObjectLink(*electron, *newElectron);
142 static const SG::Accessor<char> isLRT("isLRT");
143 isLRT(*newElectron) = isLRT(*electron);
144 outputCol->push_back(std::move(newElectron));
145
146
147 }
148 }
149 ATH_MSG_DEBUG("Size of merged output electron collection " << outputCol->size());
150 }
151 }
152
154 // Merge electron collections and remove duplicates, for transient
158 const std::set<const xAOD::Electron *> &ElectronsToRemove) const
159 {
160 // loop over electrons, accept them and add them into association tool
161 if (!electronCol.empty())
162 {
163 ATH_MSG_DEBUG("Size of transient electron collection " << electronCol.size());
164 // loop over electrons
165 for (const auto *const electron : electronCol)
166 {
167 // add electron into output and check if LRT electron failed overlap check
168 if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
169 continue;
170 else
171 {
172 outputCol->push_back(electron);
173 }
174 }
175 ATH_MSG_DEBUG("Size of transient merged electron collection " << outputCol->size());
176 }
177 }
178
179}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_FATAL(x,...)
Handle class for adding a decoration to an object.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SG::WriteHandleKey< ConstDataVector< xAOD::ElectronContainer > > m_outElectronViewLocation
Combined electron collection.
Gaudi::Property< float > m_ORThreshold
Remove overlapping electrons from output collection.
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_lrtIsLRTKey
SG::ReadHandleKey< xAOD::ElectronContainer > m_lrtElectronLocation
Standard electron collection to be merged.
Gaudi::Property< bool > m_isDAOD
StatusCode execute(const EventContext &ctx) const override
Gaudi::Property< int > m_ORstrategy
Delta R threshold for matching in overlap removal.
ToolHandle< CP::IElectronLRTOverlapRemovalTool > m_overlapRemovalTool
Combined electron view collection, set from m_outElectronLocation in initialize().
SG::WriteDecorHandleKey< xAOD::ElectronContainer > m_promptIsLRTKey
Gaudi::Property< bool > m_doRemoval
Create a view to avoid deep copy.
void mergeElectron(const xAOD::ElectronContainer &electronCol, xAOD::ElectronContainer *outputCol, const std::set< const xAOD::Electron * > &LRTElectronsToRemove) const
The lrt electron overlap removal tool.
SG::WriteHandleKey< xAOD::ElectronContainer > m_outElectronLocation
LRT electron collection to be merged.
SG::ReadHandleKey< xAOD::ElectronContainer > m_promptElectronLocation
Switches method for retrieving electron ID.
Gaudi::Property< bool > m_createViewCollection
Protected data:
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Helper class to provide type-safe access to aux data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
an object that can create a AsgTool
Select isolated Photons, Electrons and Muons.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
Definition AuxElement.h:576
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Electron_v1 Electron
Definition of the current "egamma version".