ATLAS Offline Software
Loading...
Searching...
No Matches
EGPhotonBDTToolDecorator.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_observableTool.retrieve());
18
19 if (!(m_fudgeMCTool.name().empty())) {
20 ATH_CHECK(m_fudgeMCTool.retrieve());
21 } else {
22 m_fudgeMCTool.disable();
23 }
24
25 ATH_CHECK(m_ContainerName.initialize());
26 ATH_CHECK(m_decoratorScore.initialize());
27
28 return StatusCode::SUCCESS;
29}
30
31StatusCode
32EGPhotonBDTToolDecorator::addBranches(const EventContext& ctx) const
33{
34 // retrieve container
36
37 // Decorators
40 };
41
42 // If we're applying corrections, the correction tools will give us
43 // copies that we need to keep track of. (We want to do all the copies
44 // before we start writing decorations, to avoid warnings about having
45 // unlocked decorations in a copy).
46 // The copies we get back from the tool will have standalone aux stores.
47 // We'll put them in a DataVector to get them deleted, but we don't
48 // need to copy the aux data to the container, so construct it with
49 // @c NEVER_TRACK_INDICES.
51 if (!m_fudgeMCTool.empty()) {
52 pCopies.reserve (particles->size());
53 for (const xAOD::Egamma* par : *particles) {
54 xAOD::Type::ObjectType type = par->type();
55 // apply the shower shape corrections
57 xAOD::Egamma* pCopy = nullptr;
59 const xAOD::Electron* eg = static_cast<const xAOD::Electron*>(par);
60 xAOD::Electron* el = nullptr;
61 correctionCode = m_fudgeMCTool->correctedCopy(*eg, el);
62 pCopy = el;
63 } else {
64 const xAOD::Photon* eg = static_cast<const xAOD::Photon*>(par);
65 xAOD::Photon* ph = nullptr;
66 correctionCode = m_fudgeMCTool->correctedCopy(*eg, ph);
67 pCopy = ph;
68 }
69 if (correctionCode == CP::CorrectionCode::Ok) {
70 // all OK
71 } else if (correctionCode == CP::CorrectionCode::OutOfValidityRange) {
72 Warning(
73 "addBranches()",
74 "Current photon has no valid fudge factors due to out-of-range");
75 } else {
76 Warning(
77 "addBranches()",
78 "Unknown correction code %d from ElectronPhotonShowerShapeFudgeTool",
79 (int)correctionCode);
80 }
81 pCopies.push_back (pCopy);
82 }
83 }
84 else {
85 pCopies.resize (particles->size());
86 }
87
88 // Write mask for each element and record to SG for subsequent selection
89 for (size_t ipar = 0; ipar < particles->size(); ipar++) {
90 const xAOD::Egamma* par = particles->at(ipar);
91 const xAOD::Egamma* pCopy = pCopies[ipar];
92 if (!pCopy) pCopy = par;
93
94 // compute the BDT score
95 const float score = m_observableTool->evaluate(pCopy);
96
97 decoratorScore(*par) = score;
98 }
99
100 return StatusCode::SUCCESS;
101}
102}
#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.
virtual StatusCode addBranches(const EventContext &ctx) const override final
ToolHandle< IElectronPhotonShowerShapeFudgeTool > m_fudgeMCTool
SG::ReadHandleKey< xAOD::EgammaContainer > m_ContainerName
ToolHandle< IPhotonObservableTool > m_observableTool
SG::WriteDecorHandleKey< xAOD::EgammaContainer > m_decoratorScore
Handle class for adding a decoration to an object.
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".