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