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  if (!m_SGKey_taus.key().empty()) {
77  const std::string key = m_SGKey_taus.key();
78  ATH_MSG_INFO("Using " << key << " for taus");
79  ATH_CHECK(m_SGKey_taus.initialize());
80 
81  // setup vector of decorators
82  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_time");
83  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_energy");
84  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_gain");
85  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_onlId");
86  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_x");
87  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_y");
88  m_SGKey_taus_decorations.emplace_back(key + ".maxEcell_z");
89  ATH_CHECK(m_SGKey_taus_decorations.initialize());
90  }
91 
92  if (!m_SGKey_jets.key().empty()) {
93  const std::string key = m_SGKey_jets.key();
94  ATH_MSG_INFO("Using " << key << " for jets");
95  ATH_CHECK(m_SGKey_jets.initialize());
96 
97  // setup vector of decorators
98  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_time");
99  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_energy");
100  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_gain");
101  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_onlId");
102  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_x");
103  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_y");
104  m_SGKey_jets_decorations.emplace_back(key + ".maxEcell_z");
105  ATH_CHECK(m_SGKey_jets_decorations.initialize());
106  }
107 
108  return StatusCode::SUCCESS;
109 }
110 
113 {
114  return StatusCode::SUCCESS;
115 }
116 
117 // The decoration itself
120 {
121  const EventContext& ctx = Gaudi::Hive::currentContext();
122 
123  if (!m_SGKey_photons.key().empty()) {
124  // Retrieve photon container
126  // setup vector of decorators
128  m_SGKey_photons_decorations[0], ctx);
130  m_SGKey_photons_decorations[1], ctx);
132  m_SGKey_photons_decorations[2], ctx);
134  m_SGKey_photons_decorations[3], ctx);
136  m_SGKey_photons_decorations[4], ctx);
138  m_SGKey_photons_decorations[5], ctx);
140  m_SGKey_photons_decorations[6], ctx);
141 
142  const xAOD::EgammaContainer* importedPhotons = photonContainer.ptr();
143  for (const auto* egamma : *importedPhotons) {
144  const xAOD::CaloCluster *cluster = egamma->caloCluster();
146  decorateObject(cluster, ctx);
147  decorationPh0(*egamma) = res.maxEcell_time;
148  decorationPh1(*egamma) = res.maxEcell_energy;
149  decorationPh2(*egamma) = res.maxEcell_gain;
150  decorationPh3(*egamma) = res.maxEcell_onlId;
151  decorationPh4(*egamma) = res.maxEcell_x;
152  decorationPh5(*egamma) = res.maxEcell_y;
153  decorationPh6(*egamma) = res.maxEcell_z;
154  }
155  }
156 
157  if (!m_SGKey_electrons.key().empty()) {
158  // Retrieve electron container
160  ctx);
161 
162  //
163  std::optional<SG::WriteDecorHandle<xAOD::EgammaContainer, float>> odecorationEl7;
164  const xAOD::CaloClusterContainer* egClContainer(nullptr);
165  if (!m_SGKey_egammaClusters.key().empty()) {
167  m_SGKey_egammaClusters, ctx);
168  egClContainer = egClContainerRH.ptr();
169  odecorationEl7.emplace(m_SGKey_electrons_decorations[7], ctx);
170  }
171 
172  // setup vector of decorators
174  m_SGKey_electrons_decorations[0], ctx);
176  m_SGKey_electrons_decorations[1], ctx);
178  m_SGKey_electrons_decorations[2], ctx);
180  m_SGKey_electrons_decorations[3], ctx);
182  m_SGKey_electrons_decorations[4], ctx);
184  m_SGKey_electrons_decorations[5], ctx);
186  m_SGKey_electrons_decorations[6], ctx);
187 
188  const xAOD::EgammaContainer* importedElectrons = electronContainer.ptr();
189  for (const auto* egamma : *importedElectrons) {
190  const xAOD::CaloCluster *cluster = egamma->caloCluster();
191  if (!m_SGKey_egammaClusters.key().empty()) {
192  double dRMin = 9e9;
193  const xAOD::CaloCluster *matchedCluster(nullptr);
194  for (const auto *clus : *egClContainer) {
195  double dR = clus->p4().DeltaR(cluster->p4());
196  if (dR < dRMin && dR < m_dRLRTegClusegClusMax) {
197  dRMin = dR;
198  matchedCluster = clus;
199  }
200  }
201  cluster = matchedCluster;
202  odecorationEl7.value()(*egamma) = dRMin;
203  }
205  decorateObject(cluster, ctx);
206  decorationEl0(*egamma) = res.maxEcell_time;
207  decorationEl1(*egamma) = res.maxEcell_energy;
208  decorationEl2(*egamma) = res.maxEcell_gain;
209  decorationEl3(*egamma) = res.maxEcell_onlId;
210  decorationEl4(*egamma) = res.maxEcell_x;
211  decorationEl5(*egamma) = res.maxEcell_y;
212  decorationEl6(*egamma) = res.maxEcell_z;
213  }
214  }
215 
216  if (!m_SGKey_taus.key().empty()) {
217  // Retrieve tau container
218  SG::ReadHandle<xAOD::TauJetContainer> tauJetContainer(m_SGKey_taus, ctx);
219  // setup vector of decorators
221  m_SGKey_taus_decorations[0], ctx);
223  m_SGKey_taus_decorations[1], ctx);
225  m_SGKey_taus_decorations[2], ctx);
227  m_SGKey_taus_decorations[3], ctx);
229  m_SGKey_taus_decorations[4], ctx);
231  m_SGKey_taus_decorations[5], ctx);
233  m_SGKey_taus_decorations[6], ctx);
234 
235  const xAOD::TauJetContainer* importedTaus = tauJetContainer.ptr();
236  for (const auto* tau : *importedTaus) {
238  res.maxEcell_energy = -9999.;
239  for (size_t i = 0;i<tau->nClusters();++i) {
240  // get particle
241  const xAOD::IParticle* part = tau->cluster(i);
242  if ( not part ) {
243  ATH_MSG_WARNING("Tau particle link invalid");
244  continue;
245  }
246 
247  const xAOD::CaloCluster* cluster=dynamic_cast<const xAOD::CaloCluster*> (part);
248  if ( not cluster ) {
249  ATH_MSG_WARNING("Tau cluster link invalid");
250  continue;
251  }
252 
254  decorateObject(cluster, ctx);
255  if (resCand.maxEcell_energy > res.maxEcell_energy) {
256  res = resCand;
257  }
258  }
259 
260  decorationTau0(*tau) = res.maxEcell_time;
261  decorationTau1(*tau) = res.maxEcell_energy;
262  decorationTau2(*tau) = res.maxEcell_gain;
263  decorationTau3(*tau) = res.maxEcell_onlId;
264  decorationTau4(*tau) = res.maxEcell_x;
265  decorationTau5(*tau) = res.maxEcell_y;
266  decorationTau6(*tau) = res.maxEcell_z;
267  }
268  }
269 
270  if (!m_SGKey_jets.key().empty()) {
271  // Retrieve jet container
272  SG::ReadHandle<xAOD::JetContainer> jetContainer(m_SGKey_jets, ctx);
273  // setup vector of decorators
275  m_SGKey_jets_decorations[0], ctx);
277  m_SGKey_jets_decorations[1], ctx);
279  m_SGKey_jets_decorations[2], ctx);
281  m_SGKey_jets_decorations[3], ctx);
283  m_SGKey_jets_decorations[4], ctx);
285  m_SGKey_jets_decorations[5], ctx);
287  m_SGKey_jets_decorations[6], ctx);
288 
289  const xAOD::JetContainer* importedJets = jetContainer.ptr();
290  for (const auto* jet : *importedJets) {
292  res.maxEcell_energy = -9999.;
293  std::vector<const xAOD::CaloCluster*> clusterList;
294  clusterList.clear();
295  for (auto part : jet->getConstituents()) {
296  // get particle
297  if ( not part ) {
298  ATH_MSG_WARNING("Jet particle link invalid");
299  continue;
300  }
301 
302  const xAOD::CaloCluster* cluster=dynamic_cast<const xAOD::CaloCluster*> (part->rawConstituent());
303  if ( cluster) {
304  clusterList.push_back(cluster);
305  } else {
306  const xAOD::IParticle* ipart = dynamic_cast<const xAOD::IParticle*> (part->rawConstituent());
307  if ( ipart ) {
308  const xAOD::PFO* iPFO = dynamic_cast<const xAOD::PFO*>(ipart);
309  if ( iPFO ) {
310  for (unsigned int cidx=0;cidx<iPFO->nCaloCluster();++cidx) {
311  if ( iPFO->cluster(cidx) ) {
312  clusterList.push_back(iPFO->cluster(cidx));
313  }
314  }
315  }
316  }
317  }
318  }
319 
320  for (auto cluster : clusterList) {
322  decorateObject(cluster, ctx);
323  if (resCand.maxEcell_energy > res.maxEcell_energy) {
324  res = resCand;
325  }
326  }
327 
328  decorationJet0(*jet) = res.maxEcell_time;
329  decorationJet1(*jet) = res.maxEcell_energy;
330  decorationJet2(*jet) = res.maxEcell_gain;
331  decorationJet3(*jet) = res.maxEcell_onlId;
332  decorationJet4(*jet) = res.maxEcell_x;
333  decorationJet5(*jet) = res.maxEcell_y;
334  decorationJet6(*jet) = res.maxEcell_z;
335  }
336  }
337 
338  return StatusCode::SUCCESS;
339 }
340 
343  const xAOD::CaloCluster* cluster,
344  const EventContext& ctx) const
345 {
346 
348 
349  if (cluster) {
350  if (!cluster->getCellLinks()) {
351  ATH_MSG_WARNING("CellLinks not found");
352  return result;
353  }
354 
355  SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{ m_cablingKey, ctx };
356  const LArOnOffIdMapping* cabling{ *cablingHdl };
357  if (!cabling) {
358  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
359  return result;
360  }
361 
362  float emax = -9999.;
363 
364  const CaloCell* cell_maxE = nullptr;
365  for (const CaloCell* cell : *cluster) {
366  int sampling = cell->caloDDE()->getSampling();
367  if (sampling == CaloCell_ID::EMB2 || sampling == CaloCell_ID::EME2) {
368  if ((cell->provenance() & 0x2000)) {
369  if (cell->energy() > emax) {
370  emax = cell->energy();
371  cell_maxE = cell;
372  }
373  }
374  }
375  }
376 
377  if (cell_maxE) {
378  const CaloDetDescrElement* caloDDEl = cell_maxE->caloDDE();
379  result.maxEcell_time = cell_maxE->time();
380  result.maxEcell_energy = cell_maxE->energy();
381  result.maxEcell_gain = (int)cell_maxE->gain();
382  result.maxEcell_onlId =
383  (uint64_t)(cabling->createSignalChannelID(caloDDEl->identify()))
384  .get_compact();
385  result.maxEcell_x = caloDDEl->x();
386  result.maxEcell_y = caloDDEl->y();
387  result.maxEcell_z = caloDDEl->z();
388  }
389  }
390  return result;
391 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
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
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
DerivationFramework::MaxCellDecorator::calculation::maxEcell_energy
float maxEcell_energy
Definition: MaxCellDecorator.h:46
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
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
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:44
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
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::PFO_v1::nCaloCluster
unsigned int nCaloCluster() const
Find out how many CaloCluster are linked.
Definition: PFO_v1.cxx:659
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:112
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:100
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:794
DerivationFramework::MaxCellDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: MaxCellDecorator.cxx:119
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
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
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:342
xAOD::PFO_v1::cluster
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition: PFO_v1.cxx:669
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