ATLAS Offline Software
Loading...
Searching...
No Matches
EGElectronLikelihoodToolWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Author: Giovanni Marchiori (giovanni.marchiori@cern.ch)
6
8//
10#include "PATCore/AcceptInfo.h"
11//
14#include "xAODEgamma/Electron.h"
15#include "xAODEgamma/Photon.h"
16
17namespace DerivationFramework {
18
21 {
22 ATH_CHECK(m_tool.retrieve());
23
24 if (!(m_fudgeMCTool.name().empty())) {
25 ATH_CHECK(m_fudgeMCTool.retrieve());
26 } else {
27 m_fudgeMCTool.disable();
28 }
29
30 ATH_CHECK(m_ContainerName.initialize());
31 //
32 ATH_CHECK(m_decoratorPass.initialize());
33 ATH_CHECK(m_decoratorIsEM.initialize());
34 //
37 return StatusCode::SUCCESS;
38 }
39
40 StatusCode
41 EGElectronLikelihoodToolWrapper::addBranches(const EventContext& ctx) const
42 {
43 // retrieve container
45
46 // If we're applying corrections, the correction tools will give us
47 // copies that we need to keep track of. (We want to do all the copies
48 // before we start writing decorations, to avoid warnings about having
49 // unlocked decorations in a copy).
50 // The copies we get back from the tool will have standalone aux stores.
51 // We'll put them in a DataVector to get them deleted, but we don't
52 // need to copy the aux data to the container, so construct it with
53 // @c NEVER_TRACK_INDICES.
55 if (!m_fudgeMCTool.empty()) {
56 pCopies.reserve (particles->size());
57 for (const xAOD::Egamma* par : *particles) {
58 xAOD::Type::ObjectType type = par->type();
59 // apply the shower shape corrections
61 xAOD::Egamma* pCopy = nullptr;
63 const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
64 xAOD::Electron* el = nullptr;
65 correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
66 pCopy = el;
67 } else {
68 const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
69 xAOD::Photon* ph = nullptr;
70 correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
71 pCopy = ph;
72 }
73 if (correctionCode == CP::CorrectionCode::Ok) { // All OK
74 } else if (correctionCode == CP::CorrectionCode::Error) {
75 Error("addBranches()",
76 "Error applying fudge factors to current photon");
77 } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
78 Warning(
79 "addBranches()",
80 "Current object has no valid fudge factors due to out-of-range");
81 } else {
82 Warning(
83 "addBranches()",
84 "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
85 (int)correctionCode);
86 }
87 pCopies.push_back (pCopy);
88 }
89 }
90 else {
91 pCopies.resize (particles->size());
92 }
93
94 // Decorators
97 };
100 };
101
102 std::unique_ptr<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
103 decoratorResult = nullptr;
104 if (m_storeTResult) {
105 decoratorResult =
106 std::make_unique<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>(
107 m_decoratorResult, ctx);
108 }
109 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decoratorMultipleOutputs{};
111 decoratorMultipleOutputs = m_decoratorMultipleOutputs.makeHandles(ctx);
112 }
113
114 // Write mask for each element and record to SG for subsequent selection
115 for (size_t ipar = 0; const xAOD::Egamma* par : *particles) {
116 const xAOD::Egamma* pCopy = pCopies[ipar++];
117 if (!pCopy) pCopy = par;
118 // compute the output of the selector
119 asg::AcceptData theAccept(m_tool->accept(ctx, pCopy));
120 const unsigned int isEM =
121 (unsigned int)theAccept.getCutResultInvertedBitSet()
122 .to_ulong(); // this should work for both the
123 // cut-based and the LH selectors
124
125 // decorate the original object
126 if (m_cut.empty()) {
127 const bool pass_selection = (bool)theAccept;
128 if (pass_selection) {
129 decoratorPass(*par) = 1;
130 } else {
131 decoratorPass(*par) = 0;
132 }
133 decoratorIsEM(*par) = isEM;
134 if (decoratorResult) {
135 (*decoratorResult)(*par) =
136 static_cast<float>(m_tool->calculate(ctx, pCopy));
137 }
139 // calculateMultipleOutputs only supports xAOD::Electron as input
140 const xAOD::Electron *eCopy = static_cast<const xAOD::Electron *>(pCopy);
141 std::vector<float> toolOutput = m_tool->calculateMultipleOutputs(ctx, eCopy);
142 for (size_t i = 0; i < toolOutput.size(); i++){
143 decoratorMultipleOutputs.at(i)(*par) = toolOutput.at(i);
144 }
145 }
146 } else {
147 if (theAccept.getCutResult(m_cut)) {
148 decoratorPass(*par) = 1;
149 } else {
150 decoratorPass(*par) = 0;
151 }
152 decoratorIsEM(*par) = isEM;
153 if (decoratorResult) {
154 (*decoratorResult)(*par) =
155 static_cast<float>(m_tool->calculate(ctx, pCopy));
156 }
158 // calculateMultipleOutputs only supports xAOD::Electron as input
159 const xAOD::Electron* eCopy = static_cast<const xAOD::Electron*>(pCopy);
160 std::vector<float> toolOutput = m_tool->calculateMultipleOutputs(ctx, eCopy);
161 for (size_t i = 0; i < toolOutput.size(); i++){
162 decoratorMultipleOutputs.at(i)(*par) = toolOutput.at(i);
163 }
164 }
165 }
166 }
167
168 return StatusCode::SUCCESS;
169 }
170}
#define ATH_CHECK
Evaluate an expression and check for errors.
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
void resize(size_type sz)
Resizes the collection to the specified number of elements.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
virtual StatusCode addBranches(const EventContext &ctx) const override final
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorPass
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorIsEM
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer, float > m_decoratorMultipleOutputs
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorResult
Handle class for adding a decoration to an object.
std::bitset< NBITS > getCutResultInvertedBitSet() const
Get an inverted bitset of the cut result.
Definition AcceptData.h:119
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition AcceptData.h:98
THE reconstruction tool.
::StatusCode StatusCode
StatusCode definition for legacy code.
@ NEVER_TRACK_INDICES
Never track indices, regardless of the setting of the ownership policy.
@ OWN_ELEMENTS
this data object owns its elements
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Electron
The object is an electron.
Definition ObjectType.h:46
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".
Electron_v1 Electron
Definition of the current "egamma version".