ATLAS Offline Software
ClusterEnergyPerLayerDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ClusterEnergyPerLayerDecorator.cxx, (c) ATLAS Detector software
8 // Author: Bruno Lenzi,
9 // Giovanni Marchiori (giovanni.marchiori@cern.ch)
10 // Decorate egamma objects with the energy per layer for a rectangular cluster
11 // of size neta X nphi built on the fly
12 
15 
16 #include <TString.h>
17 
18 // Constructor
20  ClusterEnergyPerLayerDecorator(const std::string& t,
21  const std::string& n,
22  const IInterface* p)
23  : base_class(t, n, p)
24 {
25  declareProperty("neta", m_eta_size);
26  declareProperty("nphi", m_phi_size);
27  declareProperty("layers", m_layers = { 0, 1, 2, 3 });
28 }
29 
30 // Destructor
33 = default;
34 
35 // Athena initialize and finalize
38 {
39  ATH_MSG_VERBOSE("initialize() ...");
40 
41  if (m_SGKey_photons.empty() and m_SGKey_electrons.empty()) {
42  ATH_MSG_FATAL("No e-gamma collection provided for thinning. At least one "
43  "egamma collection (photons/electrons) must be provided!");
44  return StatusCode::FAILURE;
45  }
46 
47  ATH_CHECK(m_caloFillRectangularTool.retrieve());
48  // how to add a statement to theck that the tool indeed has the size matching
49  // the neta and nphi properties? ATH_MSG_DEBUG("CaloFillRectangularCluster
50  // print size ...
51  m_tool =
52  dynamic_cast<const CaloFillRectangularCluster*>(
53  &(*m_caloFillRectangularTool));
54  if (m_tool==nullptr) {
55  ATH_MSG_ERROR("Pointer to CaloFillRectantularCluster tool is invalid");
56  return StatusCode::FAILURE;
57  }
58 
59  ATH_CHECK(m_SGKey_caloCells.initialize());
60 
61  if (!m_SGKey_electrons.key().empty()) {
62  ATH_MSG_DEBUG("Using " << m_SGKey_electrons << " for electrons");
63  ATH_CHECK(m_SGKey_electrons.initialize());
64 
65  const char* containerKey = m_SGKey_electrons.key().c_str();
66  for (int layer : m_layers) {
67  m_SGKey_electrons_decorations.emplace_back(
68  Form("%s.E%dx%d_Lr%d", containerKey, m_eta_size, m_phi_size, layer));
69  }
70  ATH_CHECK(m_SGKey_electrons_decorations.initialize());
71  }
72 
73  if (!m_SGKey_photons.key().empty()) {
74  ATH_MSG_DEBUG("Using " << m_SGKey_photons << " for photons");
75  ATH_CHECK(m_SGKey_photons.initialize());
76 
77  const char* containerKey = m_SGKey_photons.key().c_str();
78  for (int layer : m_layers) {
79  m_SGKey_photons_decorations.emplace_back(
80  Form("%s.E%dx%d_Lr%d", containerKey, m_eta_size, m_phi_size, layer));
81  }
82  ATH_CHECK(m_SGKey_photons_decorations.initialize());
83  }
84 
85  return StatusCode::SUCCESS;
86 }
87 
90 {
91 
92  return StatusCode::SUCCESS;
93 }
94 
95 // The decoration itself
98 {
99  const EventContext& ctx = Gaudi::Hive::currentContext();
100 
101  // Retrieve cell container
102 
103  SG::ReadHandle<CaloCellContainer> cellContainer(m_SGKey_caloCells, ctx);
104  const CaloCellContainer* cellCont = cellContainer.ptr();
105 
106  // Photon decorations
107 
108  if (!m_SGKey_photons.key().empty()) {
109 
110  // Retrieve photon container
112  const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
113 
114  // Setup vectors of photon decorations
115  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decorations;
116  for (unsigned int i = 0; i < m_layers.size(); i++) {
117  decorations.emplace_back(
118 
119  m_SGKey_photons_decorations[i], ctx);
120  }
121 
122  // Decorate photons
123  for (const auto* photon : *importedPhotons) {
124  std::vector<float> result = decorateObject(ctx, photon, cellCont);
125  for (unsigned int i = 0; i < m_layers.size(); i++) {
126  decorations[i](*photon) = result[i];
127  }
128  }
129  }
130 
131  // Electron decorations
132 
133  if (!m_SGKey_electrons.key().empty()) {
134 
135  // Retrieve electron container
137  ctx);
138  const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
139 
140  // Setup vectors of electron decorations
141  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decorations;
142  for (unsigned int i = 0; i < m_layers.size(); i++) {
143  decorations.emplace_back(
144 
145  m_SGKey_electrons_decorations[i], ctx);
146  }
147 
148  // Decorate electrons
149  for (const auto* electron : *importedElectrons) {
150  std::vector<float> result = decorateObject(ctx, electron, cellCont);
151  for (unsigned int i = 0; i < m_layers.size(); i++) {
152  decorations[i](*electron) = result[i];
153  }
154  }
155  }
156 
157  return StatusCode::SUCCESS;
158 }
159 
160 std::vector<float>
162  const EventContext& ctx,
163  const xAOD::Egamma* egamma,
164  const CaloCellContainer* cellCont) const
165 {
166  std::vector<float> result;
167  result.clear();
168  if (not egamma or not egamma->caloCluster())
169  return result;
170 
171  std::unique_ptr<xAOD::CaloCluster> egcClone;
173  egcClone =
175  egamma->caloCluster()->eta0(),
176  egamma->caloCluster()->phi0(),
177  egamma->caloCluster()->clusterSize());
178  m_tool->makeCorrection(ctx, egcClone.get());
179  }
180 
181  for (unsigned int layer : m_layers) {
182  result.emplace_back(egcClone ? egcClone->energyBE(layer) : 0.);
183  }
184 
185  return result;
186 }
CaloClusterStoreHelper::makeCluster
static std::unique_ptr< xAOD::CaloCluster > makeCluster(const CaloCellContainer *cellCont)
Creates a valid CaloCluster with a private Aux-Store and CellLink container.
Definition: CaloClusterStoreHelper.cxx:13
electronContainer
xAOD::ElectronContainer * electronContainer
Definition: TrigGlobEffCorrValidation.cxx:187
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
get_generator_info.result
result
Definition: get_generator_info.py:21
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
DerivationFramework::ClusterEnergyPerLayerDecorator::m_phi_size
int m_phi_size
Definition: ClusterEnergyPerLayerDecorator.h:43
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::ClusterEnergyPerLayerDecorator::m_layers
std::vector< unsigned int > m_layers
Definition: ClusterEnergyPerLayerDecorator.h:44
DerivationFramework::ClusterEnergyPerLayerDecorator::decorateObject
std::vector< float > decorateObject(const EventContext &ctx, const xAOD::Egamma *egamma, const CaloCellContainer *cellCont) const
Definition: ClusterEnergyPerLayerDecorator.cxx:161
DerivationFramework::ClusterEnergyPerLayerDecorator::initialize
StatusCode initialize()
Definition: ClusterEnergyPerLayerDecorator.cxx:37
egamma
Definition: egamma.h:58
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::EgammaParameters::AuthorCaloTopo35
const uint16_t AuthorCaloTopo35
Photon reconstructed by SW CaloTopo35 seeded clusters.
Definition: EgammaDefs.h:38
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloFillRectangularCluster
Definition: CaloFillRectangularCluster.h:63
DerivationFramework::ClusterEnergyPerLayerDecorator::~ClusterEnergyPerLayerDecorator
~ClusterEnergyPerLayerDecorator()
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
photonContainer
xAOD::PhotonContainer * photonContainer
Definition: TrigGlobEffCorrValidation.cxx:189
egamma::author
unsigned int author() const
Reconstruction Author
Definition: egamma.h:244
DerivationFramework::ClusterEnergyPerLayerDecorator::m_eta_size
int m_eta_size
Definition: ClusterEnergyPerLayerDecorator.h:42
DerivationFramework::ClusterEnergyPerLayerDecorator::addBranches
virtual StatusCode addBranches() const
Definition: ClusterEnergyPerLayerDecorator.cxx:97
DerivationFramework::ClusterEnergyPerLayerDecorator::finalize
StatusCode finalize()
Definition: ClusterEnergyPerLayerDecorator.cxx:89
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloClusterStoreHelper.h
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
xAOD::photon
@ photon
Definition: TrackingPrimitives.h:200
ClusterEnergyPerLayerDecorator.h
xAOD::CaloCluster_v1::energyBE
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:623
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
DerivationFramework::ClusterEnergyPerLayerDecorator::ClusterEnergyPerLayerDecorator
ClusterEnergyPerLayerDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: ClusterEnergyPerLayerDecorator.cxx:20