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  : AthAlgTool(t, n, p)
24 {
25  declareInterface<DerivationFramework::IAugmentationTool>(this);
26  declareProperty("neta", m_eta_size);
27  declareProperty("nphi", m_phi_size);
28  declareProperty("layers", m_layers = { 0, 1, 2, 3 });
29 }
30 
31 // Destructor
34 = default;
35 
36 // Athena initialize and finalize
39 {
40  ATH_MSG_VERBOSE("initialize() ...");
41 
42  if (m_SGKey_photons.empty() and m_SGKey_electrons.empty()) {
43  ATH_MSG_FATAL("No e-gamma collection provided for thinning. At least one "
44  "egamma collection (photons/electrons) must be provided!");
45  return StatusCode::FAILURE;
46  }
47 
48  ATH_CHECK(m_caloFillRectangularTool.retrieve());
49  // how to add a statement to theck that the tool indeed has the size matching
50  // the neta and nphi properties? ATH_MSG_DEBUG("CaloFillRectangularCluster
51  // print size ...
52  m_tool =
53  dynamic_cast<const CaloFillRectangularCluster*>(
54  &(*m_caloFillRectangularTool));
55  if (m_tool==nullptr) {
56  ATH_MSG_ERROR("Pointer to CaloFillRectantularCluster tool is invalid");
57  return StatusCode::FAILURE;
58  }
59 
60  ATH_CHECK(m_SGKey_caloCells.initialize());
61 
62  if (!m_SGKey_electrons.key().empty()) {
63  ATH_MSG_DEBUG("Using " << m_SGKey_electrons << " for electrons");
64  ATH_CHECK(m_SGKey_electrons.initialize());
65 
66  const char* containerKey = m_SGKey_electrons.key().c_str();
67  for (int layer : m_layers) {
68  m_SGKey_electrons_decorations.emplace_back(
69  Form("%s.E%dx%d_Lr%d", containerKey, m_eta_size, m_phi_size, layer));
70  }
71  ATH_CHECK(m_SGKey_electrons_decorations.initialize());
72  }
73 
74  if (!m_SGKey_photons.key().empty()) {
75  ATH_MSG_DEBUG("Using " << m_SGKey_photons << " for photons");
76  ATH_CHECK(m_SGKey_photons.initialize());
77 
78  const char* containerKey = m_SGKey_photons.key().c_str();
79  for (int layer : m_layers) {
80  m_SGKey_photons_decorations.emplace_back(
81  Form("%s.E%dx%d_Lr%d", containerKey, m_eta_size, m_phi_size, layer));
82  }
83  ATH_CHECK(m_SGKey_photons_decorations.initialize());
84  }
85 
86  return StatusCode::SUCCESS;
87 }
88 
91 {
92 
93  return StatusCode::SUCCESS;
94 }
95 
96 // The decoration itself
99 {
100  const EventContext& ctx = Gaudi::Hive::currentContext();
101 
102  // Retrieve cell container
103 
104  SG::ReadHandle<CaloCellContainer> cellContainer(m_SGKey_caloCells, ctx);
105  const CaloCellContainer* cellCont = cellContainer.ptr();
106 
107  // Photon decorations
108 
109  if (!m_SGKey_photons.key().empty()) {
110 
111  // Retrieve photon container
113  const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
114 
115  // Setup vectors of photon decorations
116  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decorations;
117  for (unsigned int i = 0; i < m_layers.size(); i++) {
118  decorations.emplace_back(
119 
120  m_SGKey_photons_decorations[i], ctx);
121  }
122 
123  // Decorate photons
124  for (const auto* photon : *importedPhotons) {
125  std::vector<float> result = decorateObject(ctx, photon, cellCont);
126  for (unsigned int i = 0; i < m_layers.size(); i++) {
127  decorations[i](*photon) = result[i];
128  }
129  }
130  }
131 
132  // Electron decorations
133 
134  if (!m_SGKey_electrons.key().empty()) {
135 
136  // Retrieve electron container
138  ctx);
139  const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
140 
141  // Setup vectors of electron decorations
142  std::vector<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> decorations;
143  for (unsigned int i = 0; i < m_layers.size(); i++) {
144  decorations.emplace_back(
145 
146  m_SGKey_electrons_decorations[i], ctx);
147  }
148 
149  // Decorate electrons
150  for (const auto* electron : *importedElectrons) {
151  std::vector<float> result = decorateObject(ctx, electron, cellCont);
152  for (unsigned int i = 0; i < m_layers.size(); i++) {
153  decorations[i](*electron) = result[i];
154  }
155  }
156  }
157 
158  return StatusCode::SUCCESS;
159 }
160 
161 std::vector<float>
163  const EventContext& ctx,
164  const xAOD::Egamma* egamma,
165  const CaloCellContainer* cellCont) const
166 {
167  std::vector<float> result;
168  result.clear();
169  if (not egamma or not egamma->caloCluster())
170  return result;
171 
172  std::unique_ptr<xAOD::CaloCluster> egcClone;
174  egcClone =
176  egamma->caloCluster()->eta0(),
177  egamma->caloCluster()->phi0(),
178  egamma->caloCluster()->clusterSize());
179  m_tool->makeCorrection(ctx, egcClone.get());
180  }
181 
182  for (unsigned int layer : m_layers) {
183  result.emplace_back(egcClone ? egcClone->energyBE(layer) : 0.);
184  }
185 
186  return result;
187 }
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:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
DerivationFramework::ClusterEnergyPerLayerDecorator::m_phi_size
int m_phi_size
Definition: ClusterEnergyPerLayerDecorator.h:45
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:46
DerivationFramework::ClusterEnergyPerLayerDecorator::decorateObject
std::vector< float > decorateObject(const EventContext &ctx, const xAOD::Egamma *egamma, const CaloCellContainer *cellCont) const
Definition: ClusterEnergyPerLayerDecorator.cxx:162
DerivationFramework::ClusterEnergyPerLayerDecorator::initialize
StatusCode initialize()
Definition: ClusterEnergyPerLayerDecorator.cxx:38
egamma
Definition: egamma.h:58
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
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:731
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:581
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:44
DerivationFramework::ClusterEnergyPerLayerDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: ClusterEnergyPerLayerDecorator.cxx:98
DerivationFramework::ClusterEnergyPerLayerDecorator::finalize
StatusCode finalize()
Definition: ClusterEnergyPerLayerDecorator.cxx:90
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:199
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:630
xAOD::EgammaParameters::electron
@ electron
Definition: EgammaEnums.h:18
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::ClusterEnergyPerLayerDecorator::ClusterEnergyPerLayerDecorator
ClusterEnergyPerLayerDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: ClusterEnergyPerLayerDecorator.cxx:20