ATLAS Offline Software
Loading...
Searching...
No Matches
EGElectronLikelihoodToolWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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//
15#include "xAODEgamma/Electron.h"
16#include "xAODEgamma/Photon.h"
17
18namespace DerivationFramework {
19
22 {
23 ATH_CHECK(m_tool.retrieve());
24
25 ATH_CHECK(m_ContainerName.initialize());
27 //
28 ATH_CHECK(m_decoratorPass.initialize());
29 ATH_CHECK(m_decoratorIsEM.initialize());
30 //
33 return StatusCode::SUCCESS;
34 }
35
36 StatusCode
37 EGElectronLikelihoodToolWrapper::addBranches(const EventContext& ctx) const
38 {
39 // retrieve container
41 if(!m_fudgedContainerName.empty()){
43 particles = std::move(fudged);
44 } else {
46 particles = std::move(egammas);
47 }
48
49 // Decorators
52 };
55 };
56
57 std::unique_ptr<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
58 decoratorResult = nullptr;
59 if (m_storeTResult) {
60 decoratorResult =
61 std::make_unique<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>(
63 }
64 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decoratorMultipleOutputs{};
66 decoratorMultipleOutputs = m_decoratorMultipleOutputs.makeHandles(ctx);
67 }
68
69 // Write mask for each element and record to SG for subsequent selection
70 for (const auto& egamma : *particles) {
71 // compute the output of the selector
72 asg::AcceptData theAccept(m_tool->accept(ctx, egamma));
73 // this should work for both the
74 // cut-based and the LH selectors
75 const unsigned int isEM =
76 static_cast<unsigned int>(theAccept.getCutResultInvertedBitSet()
77 .to_ulong());
78
79 // decorate the original object
80 const xAOD::IParticle* original = m_fudgedContainerName.empty() ?
82 if (m_cut.empty()) {
83 const bool pass_selection = static_cast<bool>(theAccept);
84 decoratorPass(*original) = pass_selection ? 1 : 0;
85 } else {
86 decoratorPass(*original) = theAccept.getCutResult(m_cut) ? 1 : 0;
87 }
88 decoratorIsEM(*original) = isEM;
89 if (decoratorResult) {
90 (*decoratorResult)(*original) =
91 static_cast<float>(m_tool->calculate(ctx, egamma));
92 }
94 // calculateMultipleOutputs only supports xAOD::Electron as input
95 const xAOD::Electron *eCopy = static_cast<const xAOD::Electron *>(egamma);
96 std::vector<float> toolOutput = m_tool->calculateMultipleOutputs(ctx, eCopy);
97 for (size_t i = 0; i < toolOutput.size(); i++){
98 decoratorMultipleOutputs.at(i)(*original) = toolOutput.at(i);
99 }
100 }
101 }
102
103 return StatusCode::SUCCESS;
104 }
105}
#define ATH_CHECK
Evaluate an expression and check for errors.
SG::ReadHandleKey< xAOD::EgammaContainer > m_fudgedContainerName
virtual StatusCode addBranches(const EventContext &ctx) const override final
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:120
bool getCutResult(std::string_view cutName) const
Get the result of a cut, based on the cut name (safer).
Definition AcceptData.h:99
elec/gamma data class.
Definition egamma.h:59
Class providing the definition of the 4-vector interface.
THE reconstruction tool.
::StatusCode StatusCode
StatusCode definition for legacy code.
const IParticle * getOriginalObject(const IParticle &copy)
This function can be used to conveniently get a pointer back to the original object from which a copy...
Electron_v1 Electron
Definition of the current "egamma version".