ATLAS Offline Software
Loading...
Searching...
No Matches
ElectronLRTMergingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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{
23 ElectronLRTMergingAlg::ElectronLRTMergingAlg(const std::string &name, ISvcLocator *svcLoc)
24 : EL::AnaReentrantAlgorithm(name, svcLoc)
25 {
26 }
27
29 {
30 // Greet the user:
31 ATH_MSG_INFO("Initialising");
32
34 ATH_CHECK(m_lrtElectronLocation.initialize());
35 ATH_CHECK(m_outElectronLocation.initialize());
36 ATH_CHECK(m_lrtIsLRTKey.initialize());
37 ATH_CHECK(m_promptIsLRTKey.initialize());
38
40 if (m_overlapRemovalTool.empty())
41 {
42 asg::AsgToolConfig config("CP::ElectronLRTOverlapRemovalTool/ElectronLRTOverlapRemovalTool");
43 ATH_CHECK(config.setProperty("overlapStrategy", m_ORstrategy.value()));
44 ATH_CHECK(config.setProperty("isDAOD", m_isDAOD.value()));
45 ATH_CHECK(config.makePrivateTool(m_overlapRemovalTool));
46 }
47
48 // Retrieve the tools
50
51 // Return gracefully:
52 return StatusCode::SUCCESS;
53 }
54
55
56 StatusCode ElectronLRTMergingAlg::execute(const EventContext &ctx) const
57 {
58
59 // Setup containers for output, to avoid const conversions setup two different kind of containers
60 std::unique_ptr<ConstDataVector<xAOD::ElectronContainer>> transientContainer = std::make_unique<ConstDataVector<xAOD::ElectronContainer>>(SG::VIEW_ELEMENTS);
61 std::unique_ptr<xAOD::ElectronContainer> outputCol = std::make_unique<xAOD::ElectronContainer>();
62
63 // Aux container, if needed
64 std::unique_ptr<xAOD::ElectronAuxContainer> outputAuxCol;
65
66 // Assign the aux in the copy case
68 {
69 outputAuxCol = std::make_unique<xAOD::ElectronAuxContainer>();
70 outputCol->setStore(outputAuxCol.get());
71 }
72
73 // Retrieve electrons from StoreGate
76 if (!promptCol.isValid())
77 {
78 ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_promptElectronLocation << "\", cannot run the LRT electron merger!");
79 return StatusCode::FAILURE;
80 }
81 if (!lrtCol.isValid())
82 {
83 ATH_MSG_FATAL("Unable to retrieve xAOD::ElectronContainer, \"" << m_lrtElectronLocation << "\", cannot run the LRT electron merger!");
84 return StatusCode::FAILURE;
85 }
86
87
88 std::set<const xAOD::Electron *> ElectronsToRemove;
89 m_overlapRemovalTool->checkOverlap(*promptCol, *lrtCol, ElectronsToRemove);
90
91 ATH_MSG_DEBUG("Size of overlapping electrons to remove: " << ElectronsToRemove.size());
92
93 // Decorate the electrons with their track type
94 // 0 if prompt, 1 if LRT
97 for (const xAOD::Electron *el : *promptCol)
98 promptIsLRT(*el) = 0;
99 for (const xAOD::Electron *el : *lrtCol)
100 lrtIsLRT(*el) = 1;
101
102 // merging loop over containers
104 {
105 transientContainer->reserve(promptCol->size() + lrtCol->size());
106
107 mergeElectron(*promptCol, transientContainer.get(), ElectronsToRemove);
108 mergeElectron(*lrtCol, transientContainer.get(), ElectronsToRemove);
109 }
110 else
111 {
112 outputCol->reserve(promptCol->size() + lrtCol->size());
113
114 mergeElectron(*promptCol, outputCol.get(), ElectronsToRemove);
115 mergeElectron(*lrtCol, outputCol.get(), ElectronsToRemove);
116 }
117
118 //write
121 {
122 ATH_CHECK(evtStore()->record(transientContainer.release(), m_outElectronLocation.key()));
123 }
124 else
125 {
126 ATH_CHECK(h_write.record(std::move(outputCol), std::move(outputAuxCol)));
127 }
128
129 ATH_MSG_DEBUG("Done !");
130
131 return StatusCode::SUCCESS;
132 }
133
135 // Merge electron collections and remove duplicates, for copy
137
139 xAOD::ElectronContainer *outputCol,
140 const std::set<const xAOD::Electron *> &ElectronsToRemove) const
141 {
142 // loop over electrons, accept them and add them into association tool
143 if (!electronCol.empty())
144 {
145 ATH_MSG_DEBUG("Size of output electron collection " << electronCol.size());
146
147 static const SG::Decorator<ElementLink<xAOD::ElectronContainer>> originalElectronLink("originalElectronLink");
148
149 // loop over electrons
150 for (const auto *const electron : electronCol)
151 {
152 // add electron into output and check if LRT electron failed overlap check
153 if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
154 continue;
155 else
156 {
157 std::unique_ptr<xAOD::Electron> newElectron = std::make_unique<xAOD::Electron>(*electron);
159 eLink.toIndexedElement(electronCol, electron->index());
160 originalElectronLink(*newElectron) = eLink;
161 setOriginalObjectLink(*electron, *newElectron);
162 static const SG::Accessor<char> isLRT("isLRT");
163 isLRT(*newElectron) = isLRT(*electron);
164 outputCol->push_back(std::move(newElectron));
165
166
167 }
168 }
169 ATH_MSG_DEBUG("Size of merged output electron collection " << outputCol->size());
170 }
171 }
172
174 // Merge electron collections and remove duplicates, for transient
178 const std::set<const xAOD::Electron *> &ElectronsToRemove) const
179 {
180 // loop over electrons, accept them and add them into association tool
181 if (!electronCol.empty())
182 {
183 ATH_MSG_DEBUG("Size of transient electron collection " << electronCol.size());
184 // loop over electrons
185 for (const auto *const electron : electronCol)
186 {
187 // add electron into output and check if LRT electron failed overlap check
188 if (m_doRemoval && ElectronsToRemove.find(electron) != ElectronsToRemove.end())
189 continue;
190 else
191 {
192 outputCol->push_back(electron);
193 }
194 }
195 ATH_MSG_DEBUG("Size of transient merged electron collection " << outputCol->size());
196 }
197 }
198
199}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
ElectronLRTMergingAlg(const std::string &name, ISvcLocator *pSvcLocator)
the standard constructor
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 collection.
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.
AnaReentrantAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
Helper class to provide type-safe access to aux data.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
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.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
@ 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".