ATLAS Offline Software
Loading...
Searching...
No Matches
GainDecorator.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: Simone Mazza (simone.mazza@mi.infn.it),
6// Bruno Lenzi,
7// Giovanni Marchiori (giovanni.marchiori@cern.ch)
8// Decorate egamma objects with the energy and number of cells per layer per
9// gain
10
12#include "CaloEvent/CaloCell.h"
13
14
15
16// Athena initialize and finalize
17StatusCode
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}
48
49// The decoration itself
50StatusCode
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
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) {
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
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) {
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}
143
146 const xAOD::Egamma*& egamma) const
147{
148
149 // Compute energy and number of cells per gain per layer
150 // Set the initial values to 0 (needed?)
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) {
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}
181
182int
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
std::pair< std::vector< unsigned int >, bool > res
xAOD::ElectronContainer * electronContainer
xAOD::PhotonContainer * photonContainer
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_photons_decorations
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_electrons
std::vector< std::pair< int, int > > m_names_E
static int getLayer(const CaloCell *cell)
SG::ReadHandleKey< xAOD::EgammaContainer > m_SGKey_photons
virtual StatusCode initialize() override final
Gaudi::Property< std::map< int, std::string > > m_gainNames
SG::WriteDecorHandleKeyArray< xAOD::EgammaContainer > m_SGKey_electrons_decorations
virtual StatusCode addBranches(const EventContext &ctx) const override final
Gaudi::Property< std::vector< unsigned int > > m_layers
calculation decorateObject(const xAOD::Egamma *&egamma) const
elec/gamma data class.
Definition egamma.h:58
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".