ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::GainDecorator Class Reference

#include <GainDecorator.h>

Inheritance diagram for DerivationFramework::GainDecorator:
Collaboration diagram for DerivationFramework::GainDecorator:

Classes

struct  calculation

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode addBranches (const EventContext &ctx) const override final

Static Public Member Functions

static int getLayer (const CaloCell *cell)

Private Member Functions

calculation decorateObject (const xAOD::Egamma *&egamma) const

Private Attributes

SG::ReadHandleKey< xAOD::EgammaContainerm_SGKey_photons
SG::ReadHandleKey< xAOD::EgammaContainerm_SGKey_electrons
Gaudi::Property< std::map< int, std::string > > m_gainNames
Gaudi::Property< std::vector< unsigned int > > m_layers {this, "layers", { 0, 1, 2, 3 }}
std::vector< std::pair< int, int > > m_names_E
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainerm_SGKey_photons_decorations
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainerm_SGKey_electrons_decorations

Detailed Description

Definition at line 26 of file GainDecorator.h.

Member Function Documentation

◆ addBranches()

StatusCode DerivationFramework::GainDecorator::addBranches ( const EventContext & ctx) const
finaloverridevirtual

Definition at line 51 of file GainDecorator.cxx.

52{
53 ATH_MSG_DEBUG("m_gainNames.size() = " << m_gainNames.size() << ", m_layers.size() = "<< m_layers.size() );
54 const size_t limit{m_gainNames.size()*m_layers.size()};
55 if (limit == 0) { return StatusCode::FAILURE; } // FIXME Add ERROR message here
56 // Photon decorations
57
58 if (!m_SGKey_photons.key().empty()) {
59
60 // Retrieve photon container
61 SG::ReadHandle<xAOD::EgammaContainer> photonContainer(m_SGKey_photons, ctx);
62 const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
63
64 // Setup vectors of photon decorations
65 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
66 decorations_E;
67 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
68 decorations_rnoW;
69 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, char>>
70 decorations_nCells;
71 for (unsigned int i = 0; i < limit; ++i) {
72 decorations_E.emplace_back(
73 m_SGKey_photons_decorations[i * 3], ctx);
74 decorations_rnoW.emplace_back(
75 m_SGKey_photons_decorations[i * 3 + 1], ctx);
76 decorations_nCells.emplace_back(
77 m_SGKey_photons_decorations[i * 3 + 2], ctx);
78 }
79 // Decorate photons
80 int i(0);
81 for (const auto* photon : *importedPhotons) {
82 DerivationFramework::GainDecorator::calculation res =
83 decorateObject(photon);
84 i = 0;
85 for (const auto& kv : m_gainNames) {
86 for (const auto layer : m_layers) {
87 std::pair<int, int> key(kv.first, layer);
88 decorations_E[i](*photon) = res.E[key];
89 decorations_rnoW[i](*photon) =
90 res.EnoW[key] != 0 ? res.E[key]/res.EnoW[key] : 1;
91 decorations_nCells[i](*photon) = res.nCells[key];
92 i++;
93 }
94 }
95 }
96 }
97
98 // Electron decorations
99
100 if (!m_SGKey_electrons.key().empty()) {
101
102 // Retrieve electron container
103 SG::ReadHandle<xAOD::EgammaContainer> electronContainer(m_SGKey_electrons,
104 ctx);
105 const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
106
107 // Setup vectors of electron decorations
108 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
109 decorations_E;
110 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>>
111 decorations_rnoW;
112 std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, char>>
113 decorations_nCells;
114 for (unsigned int i = 0; i < limit; ++i) {
115 decorations_E.emplace_back(
117 decorations_rnoW.emplace_back(
118 m_SGKey_electrons_decorations[i * 3 + 1], ctx);
119 decorations_nCells.emplace_back(
120 m_SGKey_electrons_decorations[i * 3 + 2], ctx);
121 }
122 // Decorate electrons
123 int i(0);
124 for (const auto* electron : *importedElectrons) {
125 DerivationFramework::GainDecorator::calculation res =
126 decorateObject(electron);
127 i = 0;
128 for (const auto& kv : m_gainNames) {
129 for (const auto layer : m_layers) {
130 std::pair<int, int> key(kv.first, layer);
131 decorations_E[i](*electron) = res.E[key];
132 decorations_rnoW[i](*electron) =
133 res.EnoW[key] != 0 ? res.E[key]/res.EnoW[key] : 1;
134 decorations_nCells[i](*electron) = res.nCells[key];
135 i++;
136 }
137 }
138 }
139 }
140
141 return StatusCode::SUCCESS;
142}
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
xAOD::ElectronContainer * electronContainer
xAOD::PhotonContainer * photonContainer
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
Gaudi::Property< std::map< int, std::string > > m_gainNames
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
Gaudi::Property< std::vector< unsigned int > > m_layers
calculation decorateObject(const xAOD::Egamma *&egamma) const
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".

◆ decorateObject()

DerivationFramework::GainDecorator::calculation DerivationFramework::GainDecorator::decorateObject ( const xAOD::Egamma *& egamma) const
private

Definition at line 145 of file GainDecorator.cxx.

147{
148
149 // Compute energy and number of cells per gain per layer
150 // Set the initial values to 0 (needed?)
151 DerivationFramework::GainDecorator::calculation result;
152 for (const auto& kv : m_names_E) {
153 result.E[kv] = 0.;
154 result.EnoW[kv] = 0.;
155 result.nCells[kv] = 0;
156 }
157
158 // Skip the computation for missing cell links (like topo-seeded photons)
159 // but decorate anyway
160 const CaloClusterCellLink* cellLinks =
161 egamma->caloCluster() ? egamma->caloCluster()->getCellLinks() : nullptr;
162 if (cellLinks) {
163 CaloClusterCellLink::const_iterator it = cellLinks->begin(),
164 itE = cellLinks->end();
165 for (; it != itE; ++it) {
166 const CaloCell *cell = *it;
167 if (!cell)
168 continue;
169 std::pair<int, int> key(static_cast<int>(cell->gain()), getLayer(cell));
170 // Increment the corresponding entry (not important if it is not
171 // initialised)
172 double weight = it.weight();
173 result.E[key] += cell->energy()*weight;
174 result.EnoW[key] += cell->energy();
175 result.nCells[key]++;
176 }
177 }
178
179 return result;
180}
std::vector< std::pair< int, int > > m_names_E
static int getLayer(const CaloCell *cell)

◆ getLayer()

int DerivationFramework::GainDecorator::getLayer ( const CaloCell * cell)
static

Definition at line 183 of file GainDecorator.cxx.

184{
185 int sampling =
186 (cell && cell->caloDDE() ? cell->caloDDE()->getSampling() : -1);
187 if (sampling == CaloSampling::PreSamplerB ||
188 sampling == CaloSampling::PreSamplerE)
189 return 0;
190 if (sampling == CaloSampling::EMB1 || sampling == CaloSampling::EME1)
191 return 1;
192 if (sampling == CaloSampling::EMB2 || sampling == CaloSampling::EME2)
193 return 2;
194 if (sampling == CaloSampling::EMB3 || sampling == CaloSampling::EME3)
195 return 3;
196 return -1;
197}

◆ initialize()

StatusCode DerivationFramework::GainDecorator::initialize ( )
finaloverridevirtual

Definition at line 18 of file GainDecorator.cxx.

19{
20 ATH_MSG_VERBOSE("initialize() ...");
21
22 if (m_SGKey_photons.key().empty() && m_SGKey_electrons.key().empty()) {
23 ATH_MSG_FATAL("No e-gamma collection provided for thinning. At least one "
24 "egamma collection (photons/electrons) must be provided!");
25 return StatusCode::FAILURE;
26 }
27
28 for (const auto& kv : m_gainNames) {
29 for (const auto layer : m_layers) {
30 m_names_E.emplace_back(kv.first, layer);
31 }
32 }
33
35 if (!m_SGKey_electrons.key().empty()) {
36 ATH_MSG_DEBUG("Using " << m_SGKey_electrons << " for electrons");
37 }
39
41 if (!m_SGKey_photons.key().empty()) {
42 ATH_MSG_DEBUG("Using " << m_SGKey_photons << " for photons");
43 }
44 ATH_CHECK(m_SGKey_photons_decorations.initialize(!m_SGKey_photons.key().empty()));
45
46 return StatusCode::SUCCESS;
47}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)

Member Data Documentation

◆ m_gainNames

Gaudi::Property< std::map<int, std::string> > DerivationFramework::GainDecorator::m_gainNames
private
Initial value:
{this, "gain_names",
{ { CaloGain::LARHIGHGAIN, "Hi" },
{ CaloGain::LARLOWGAIN, "Low" } } }
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARHIGHGAIN
Definition CaloGain.h:18

Definition at line 50 of file GainDecorator.h.

50 {this, "gain_names",
51 { { CaloGain::LARHIGHGAIN, "Hi" },
52 { CaloGain::LARMEDIUMGAIN, "Med" },
53 { CaloGain::LARLOWGAIN, "Low" } } };

◆ m_layers

Gaudi::Property< std::vector<unsigned int> > DerivationFramework::GainDecorator::m_layers {this, "layers", { 0, 1, 2, 3 }}
private

Definition at line 54 of file GainDecorator.h.

54{this, "layers", { 0, 1, 2, 3 }};

◆ m_names_E

std::vector<std::pair<int, int> > DerivationFramework::GainDecorator::m_names_E
private

Definition at line 57 of file GainDecorator.h.

◆ m_SGKey_electrons

SG::ReadHandleKey<xAOD::EgammaContainer> DerivationFramework::GainDecorator::m_SGKey_electrons
private
Initial value:
{
this, "SGKey_electrons", "", "SG key of electron container" }

Definition at line 47 of file GainDecorator.h.

47 {
48 this, "SGKey_electrons", "", "SG key of electron container" };

◆ m_SGKey_electrons_decorations

SG::WriteDecorHandleKeyArray<xAOD::EgammaContainer> DerivationFramework::GainDecorator::m_SGKey_electrons_decorations
private
Initial value:
{
this,
"SGKey_electrons_decorations",
"SG keys for electrons decorations not really configurable"
}
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons

Definition at line 68 of file GainDecorator.h.

68 {
69 this,
70 "SGKey_electrons_decorations",
72 "SG keys for electrons decorations not really configurable"
73 };

◆ m_SGKey_photons

SG::ReadHandleKey<xAOD::EgammaContainer> DerivationFramework::GainDecorator::m_SGKey_photons
private
Initial value:
{
this, "SGKey_photons", "", "SG key of photon container" }

Definition at line 44 of file GainDecorator.h.

44 {
45 this, "SGKey_photons", "", "SG key of photon container" };

◆ m_SGKey_photons_decorations

SG::WriteDecorHandleKeyArray<xAOD::EgammaContainer> DerivationFramework::GainDecorator::m_SGKey_photons_decorations
private
Initial value:
{
this,
"SGKey_photons_decorations",
"SG keys for photon decorations not really configurable"
}
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons

Definition at line 60 of file GainDecorator.h.

60 {
61 this,
62 "SGKey_photons_decorations",
64 "SG keys for photon decorations not really configurable"
65 };

The documentation for this class was generated from the following files: