ATLAS Offline Software
Loading...
Searching...
No Matches
EGPhotonBDTToolWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10#include "xAODEgamma/Photon.h"
11
12namespace DerivationFramework {
13
16{
17 ATH_CHECK(m_selectorTool.retrieve());
18 ATH_CHECK(m_observableTool.retrieve());
19
20 if (!(m_fudgeMCTool.name().empty())) {
21 ATH_CHECK(m_fudgeMCTool.retrieve());
22 } else {
23 m_fudgeMCTool.disable();
24 }
25
26 ATH_CHECK(m_ContainerName.initialize());
27 ATH_CHECK(m_decoratorPass.initialize());
28 ATH_CHECK(m_decoratorIsEM.initialize());
29 ATH_CHECK(m_decoratorScore.initialize());
30
31 return StatusCode::SUCCESS;
32}
33
34StatusCode
35EGPhotonBDTToolWrapper::addBranches(const EventContext& ctx) const
36{
37 // retrieve container
39
40 // Decorators
43 };
46 };
49 };
50
51 // If we're applying corrections, the correction tools will give us
52 // copies that we need to keep track of. (We want to do all the copies
53 // before we start writing decorations, to avoid warnings about having
54 // unlocked decorations in a copy).
55 // The copies we get back from the tool will have standalone aux stores.
56 // We'll put them in a DataVector to get them deleted, but we don't
57 // need to copy the aux data to the container, so construct it with
58 // @c NEVER_TRACK_INDICES.
60 if (!m_fudgeMCTool.empty()) {
61 pCopies.reserve (particles->size());
62 for (const xAOD::Egamma* par : *particles) {
63 xAOD::Type::ObjectType type = par->type();
64 // apply the shower shape corrections
66 xAOD::Egamma* pCopy = nullptr;
68 const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
69 xAOD::Electron* el = nullptr;
70 correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
71 pCopy = el;
72 } else {
73 const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
74 xAOD::Photon* ph = nullptr;
75 correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
76 pCopy = ph;
77 }
78 if (correctionCode == CP::CorrectionCode::Ok) {
79 // all OK
80 } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
81 Warning(
82 "addBranches()",
83 "Current photon has no valid fudge factors due to out-of-range");
84 } else {
85 Warning(
86 "addBranches()",
87 "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
88 (int)correctionCode);
89 }
90 pCopies.push_back (pCopy);
91 }
92 }
93 else {
94 pCopies.resize (particles->size());
95 }
96
97 // Write mask for each element and record to SG for subsequent selection
98 for (size_t ipar = 0; ipar < particles->size(); ipar++) {
99 const xAOD::Egamma* par = particles->at(ipar);
100 const xAOD::Egamma* pCopy = pCopies[ipar];
101 if (!pCopy) pCopy = par;
102
103 // compute the output of the selector
104 asg::AcceptData theAccept(m_selectorTool->accept(ctx, pCopy));
105 // compute the is EM word
106 unsigned int isEM = 0;
107 ATH_CHECK(m_selectorTool->execute(ctx, pCopy, isEM));
108 // compute the BDT score
109 const float score = m_observableTool->evaluate(pCopy);
110
111 // decorate the original object
112 if (m_cut.empty()) {
113 decoratorPass(*par) = static_cast<bool>(theAccept) ? 1 : 0;
114 } else {
115 decoratorPass(*par) = theAccept.getCutResult(m_cut) ? 1 : 0;
116 }
117 decoratorIsEM(*par) = isEM;
118 decoratorScore(*par) = score;
119 }
120
121 return StatusCode::SUCCESS;
122}
123}
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Return value from object correction CP tools.
@ 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.
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorPass
SG::ReadHandleKey< xAOD::EgammaContainer > m_ContainerName
ToolHandle< IAsgEGammaIsEMSelector > m_selectorTool
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorIsEM
virtual StatusCode initialize() override final
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorScore
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
ToolHandle< IPhotonObservableTool > m_observableTool
Handle class for adding a decoration to an object.
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".