ATLAS Offline Software
MaxCellDecorator.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 // MaxCellDecorator.cxx, (c) ATLAS Detector software
8 
12 
13 #include <string>
14 #include <vector>
15 namespace {}
16 
17 // Constructor
19  const std::string& n,
20  const IInterface* p)
21  : AthAlgTool(t, n, p)
22 {
23  declareInterface<DerivationFramework::IAugmentationTool>(this);
24 }
25 
26 // Destructor
28 
29 // Athena initialize and finalize
32 {
33  ATH_MSG_VERBOSE("initialize() ...");
34 
35  ATH_CHECK(m_cablingKey.initialize());
36 
37  if (!m_SGKey_electrons.key().empty()) {
38  const std::string key = m_SGKey_electrons.key();
39  ATH_MSG_INFO("Using " << key << " for electrons");
40  ATH_CHECK(m_SGKey_electrons.initialize());
41 
42  // setup vector of decorators
43  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_time");
44  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_energy");
45  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_gain");
46  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_onlId");
47  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_x");
48  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_y");
49  m_SGKey_electrons_decorations.emplace_back(key + ".maxEcell_z");
50 
51  if (!m_SGKey_egammaClusters.key().empty()) {
52  ATH_MSG_INFO("Using " << m_SGKey_egammaClusters.key() << " to try to match a cluster to the LRT egamma cluster");
53  ATH_CHECK(m_SGKey_egammaClusters.initialize());
54  m_SGKey_electrons_decorations.emplace_back(key + ".dR");
55  }
56 
57  ATH_CHECK(m_SGKey_electrons_decorations.initialize());
58  }
59 
60  if (!m_SGKey_photons.key().empty()) {
61  const std::string key = m_SGKey_photons.key();
62  ATH_MSG_INFO("Using " << key << " for photons");
63  ATH_CHECK(m_SGKey_photons.initialize());
64 
65  // setup vector of decorators
66  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_time");
67  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_energy");
68  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_gain");
69  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_onlId");
70  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_x");
71  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_y");
72  m_SGKey_photons_decorations.emplace_back(key + ".maxEcell_z");
73  ATH_CHECK(m_SGKey_photons_decorations.initialize());
74  }
75 
76  return StatusCode::SUCCESS;
77 }
78 
81 {
82  return StatusCode::SUCCESS;
83 }
84 
85 // The decoration itself
88 {
89  const EventContext& ctx = Gaudi::Hive::currentContext();
90 
91  if (!m_SGKey_photons.key().empty()) {
92  // Retrieve photon container
94  // setup vector of decorators
96  m_SGKey_photons_decorations[0], ctx);
98  m_SGKey_photons_decorations[1], ctx);
100  m_SGKey_photons_decorations[2], ctx);
102  m_SGKey_photons_decorations[3], ctx);
104  m_SGKey_photons_decorations[4], ctx);
106  m_SGKey_photons_decorations[5], ctx);
108  m_SGKey_photons_decorations[6], ctx);
109 
110  const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
111  for (const auto* egamma : *importedPhotons) {
112  const xAOD::CaloCluster *cluster = egamma->caloCluster();
114  decorateObject(cluster, ctx);
115  decorationPh0(*egamma) = res.maxEcell_time;
116  decorationPh1(*egamma) = res.maxEcell_energy;
117  decorationPh2(*egamma) = res.maxEcell_gain;
118  decorationPh3(*egamma) = res.maxEcell_onlId;
119  decorationPh4(*egamma) = res.maxEcell_x;
120  decorationPh5(*egamma) = res.maxEcell_y;
121  decorationPh6(*egamma) = res.maxEcell_z;
122  }
123  }
124 
125  if (!m_SGKey_electrons.key().empty()) {
126  // Retrieve electron container
128  ctx);
129 
130  //
131  std::optional<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> odecorationEl7;
132  const xAOD::CaloClusterContainer* egClContainer(nullptr);
133  if (!m_SGKey_egammaClusters.key().empty()) {
135  m_SGKey_egammaClusters, ctx);
136  egClContainer = egClContainerRH.ptr();
137  odecorationEl7.emplace(m_SGKey_electrons_decorations[7], ctx);
138  }
139 
140  // setup vector of decorators
142  m_SGKey_electrons_decorations[0], ctx);
144  m_SGKey_electrons_decorations[1], ctx);
146  m_SGKey_electrons_decorations[2], ctx);
148  m_SGKey_electrons_decorations[3], ctx);
150  m_SGKey_electrons_decorations[4], ctx);
152  m_SGKey_electrons_decorations[5], ctx);
154  m_SGKey_electrons_decorations[6], ctx);
155 
156  const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
157  for (const auto* egamma : *importedElectrons) {
158  const xAOD::CaloCluster *cluster = egamma->caloCluster();
159  if (!m_SGKey_egammaClusters.key().empty()) {
160  double dRMin = 9e9;
161  const xAOD::CaloCluster *matchedCluster(nullptr);
162  for (const auto *clus : *egClContainer) {
163  double dR = clus->p4().DeltaR(cluster->p4());
164  if (dR < dRMin && dR < m_dRLRTegClusegClusMax) {
165  dRMin = dR;
166  matchedCluster = clus;
167  }
168  }
169  cluster = matchedCluster;
170  odecorationEl7.value()(*egamma) = dRMin;
171  }
173  decorateObject(cluster, ctx);
174  decorationEl0(*egamma) = res.maxEcell_time;
175  decorationEl1(*egamma) = res.maxEcell_energy;
176  decorationEl2(*egamma) = res.maxEcell_gain;
177  decorationEl3(*egamma) = res.maxEcell_onlId;
178  decorationEl4(*egamma) = res.maxEcell_x;
179  decorationEl5(*egamma) = res.maxEcell_y;
180  decorationEl6(*egamma) = res.maxEcell_z;
181  }
182  }
183 
184  return StatusCode::SUCCESS;
185 }
186 
189  const xAOD::CaloCluster* cluster,
190  const EventContext& ctx) const
191 {
192 
194 
195  if (cluster) {
196  if (!cluster->getCellLinks()) {
197  ATH_MSG_WARNING("CellLinks not found");
198  return result;
199  }
200 
201  SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{ m_cablingKey, ctx };
202  const LArOnOffIdMapping* cabling{ *cablingHdl };
203  if (!cabling) {
204  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
205  return result;
206  }
207 
208  float emax = -9999.;
209 
210  const CaloCell* cell_maxE = nullptr;
211  for (const CaloCell* cell : *cluster) {
212  int sampling = cell->caloDDE()->getSampling();
213  if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2) {
214  if ((cell->provenance() & 0x2000)) {
215  if (cell->energy() > emax) {
216  emax = cell->energy();
217  cell_maxE = cell;
218  }
219  }
220  }
221  }
222 
223  if (cell_maxE) {
224  const CaloDetDescrElement* caloDDEl = cell_maxE->caloDDE();
225  result.maxEcell_time = cell_maxE->time();
226  result.maxEcell_energy = cell_maxE->energy();
227  result.maxEcell_gain = (int)cell_maxE->gain();
228  result.maxEcell_onlId =
229  (uint64_t)(cabling->createSignalChannelID(caloDDEl->identify()))
230  .get_compact();
231  result.maxEcell_x = caloDDEl->x();
232  result.maxEcell_y = caloDDEl->y();
233  result.maxEcell_z = caloDDEl->z();
234  }
235  }
236  return result;
237 }
DerivationFramework::MaxCellDecorator::initialize
StatusCode initialize()
Definition: MaxCellDecorator.cxx:31
electronContainer
xAOD::ElectronContainer * electronContainer
Definition: TrigGlobEffCorrValidation.cxx:187
get_generator_info.result
result
Definition: get_generator_info.py:21
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloDetDescrElement::y
float y() const
cell y
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:365
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::MaxCellDecorator::~MaxCellDecorator
~MaxCellDecorator()
CaloCell::time
float time() const
get time (data member)
Definition: CaloCell.h:352
CaloCell_ID.h
egamma
Definition: egamma.h:58
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
DerivationFramework::MaxCellDecorator::MaxCellDecorator
MaxCellDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: MaxCellDecorator.cxx:18
DerivationFramework::MaxCellDecorator::calculation
Definition: MaxCellDecorator.h:42
CaloDetDescrElement::identify
Identifier identify() const override final
cell identifier
Definition: CaloDetDescrElement.cxx:64
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::MaxCellDecorator::finalize
StatusCode finalize()
Definition: MaxCellDecorator.cxx:80
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::MaxCellDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: MaxCellDecorator.cxx:87
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
photonContainer
xAOD::PhotonContainer * photonContainer
Definition: TrigGlobEffCorrValidation.cxx:189
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
CaloCell::gain
CaloGain::CaloGain gain() const
get gain (data member )
Definition: CaloCell.h:345
CaloDetDescrElement::x
float x() const
cell x
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:363
CaloClusterStoreHelper.h
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloDetDescrElement::z
float z() const
cell z
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:367
MaxCellDecorator.h
DerivationFramework::MaxCellDecorator::decorateObject
calculation decorateObject(const xAOD::CaloCluster *cluster, const EventContext &ctx) const
Definition: MaxCellDecorator.cxx:188
DataVector::emplace
iterator emplace(iterator position, value_type pElem)
Add a new element to the collection.
AthAlgTool
Definition: AthAlgTool.h:26
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37