ATLAS Offline Software
TruthCaloShowerDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "xAODEgamma/Electron.h"
12 
13 namespace DerivationFramework {
14 
16  const std::string& n,
17  const IInterface* p)
18  : AthAlgTool(t, n, p)
19 {
20  declareInterface<DerivationFramework::IAugmentationTool>(this);
21 }
22 
25 {
26  ATH_MSG_DEBUG("Initializing " << name() << "...");
27 
28  if (m_calibhitToCaloCellTool.retrieve().isFailure()) {
29  ATH_MSG_FATAL("Failed to retrieve tool " << m_calibhitToCaloCellTool);
30  return StatusCode::FAILURE;
31  }
32  ATH_MSG_INFO("Retrieved tool " << m_calibhitToCaloCellTool);
33 
38 
39  const std::string baseName = m_truthParticleContainerName.key();
40  m_linkDecoratorClusterEtot = baseName + ".truthLArClusterEtotLink";
41  m_linkDecoratorClusterEvis = baseName + ".truthLArClusterEvisLink";
42  m_linkDecoratorClusterEem = baseName + ".truthLArClusterEemLink";
43 
47 
48  return StatusCode::SUCCESS;
49 }
50 
53 {
54  return StatusCode::SUCCESS;
55 }
56 
59 {
60  const EventContext& ctx = Gaudi::Hive::currentContext();
61 
62  SG::ReadHandle<xAOD::TruthParticleContainer> truthPartContainerReadHandle{
64  };
65  const xAOD::TruthParticleContainer* truthPartContainer =
66  truthPartContainerReadHandle.ptr();
67 
68  // create truth clusters
69  ATH_MSG_DEBUG("Creating truth clusters");
71  ->processCalibHitsFromParticle(HepMC::SINGLE_PARTICLE)
72  .isSuccess()) {
73  ATH_MSG_FATAL("Tool " << m_calibhitToCaloCellTool << " failed.");
74  return StatusCode::FAILURE;
75  }
76 
77  ATH_MSG_DEBUG("Retrieving truth clusters");
79  truthClusterContainerEtotReadHandle{ m_truthClusterContainerEtot, ctx };
81  truthClusterContainerEvisReadHandle{ m_truthClusterContainerEvis, ctx };
82  SG::ReadHandle<xAOD::CaloClusterContainer> truthClusterContainerEemReadHandle{
84  };
85  const xAOD::CaloClusterContainer* truthClusterContainerEtot =
86  truthClusterContainerEtotReadHandle.ptr();
87  const xAOD::CaloClusterContainer* truthClusterContainerEvis =
88  truthClusterContainerEvisReadHandle.ptr();
89  const xAOD::CaloClusterContainer* truthClusterContainerEem =
90  truthClusterContainerEemReadHandle.ptr();
91 
92  if (!truthClusterContainerEtot || !truthClusterContainerEvis ||
93  !truthClusterContainerEem) {
94  ATH_MSG_ERROR("Failed to retrieve truth cluster container");
95  return StatusCode::FAILURE;
96  }
97 
100  linkDecoratorClusterEtot(m_linkDecoratorClusterEtot, ctx);
103  linkDecoratorClusterEvis(m_linkDecoratorClusterEvis, ctx);
106  linkDecoratorClusterEem(m_linkDecoratorClusterEem, ctx);
107 
109  *truthClusterContainerEtot, 0);
111  *truthClusterContainerEvis, 0);
113  *truthClusterContainerEem, 0);
114 
115  ATH_MSG_DEBUG("Decorating truth parts with truth cluster energy");
116  for (const auto* const truthPart : *truthPartContainer) {
117  if (!truthPart) continue;
118  if (!MC::isSingleParticle(truthPart)) continue;
119  linkDecoratorClusterEtot(*truthPart) = truthClusterEtot;
120  linkDecoratorClusterEvis(*truthPart) = truthClusterEvis;
121  linkDecoratorClusterEem(*truthPart) = truthClusterEem;
122  }
123  return StatusCode::SUCCESS;
124 }
125 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DerivationFramework::TruthCaloShowerDecorator::m_linkDecoratorClusterEem
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_linkDecoratorClusterEem
Definition: TruthCaloShowerDecorator.h:62
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DerivationFramework::TruthCaloShowerDecorator::finalize
StatusCode finalize()
Definition: TruthCaloShowerDecorator.cxx:52
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::TruthCaloShowerDecorator::m_linkDecoratorClusterEvis
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_linkDecoratorClusterEvis
Definition: TruthCaloShowerDecorator.h:60
CalibHitToCaloCellTool.h
Convert energy deposits from calibration hits to CaloCell, xAOD::CaloCluster.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
DerivationFramework::TruthCaloShowerDecorator::m_linkDecoratorClusterEtot
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_linkDecoratorClusterEtot
Definition: TruthCaloShowerDecorator.h:58
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DerivationFramework::TruthCaloShowerDecorator::m_truthClusterContainerEvis
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_truthClusterContainerEvis
Definition: TruthCaloShowerDecorator.h:49
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
DerivationFramework::TruthCaloShowerDecorator::m_truthClusterContainerEtot
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_truthClusterContainerEtot
Definition: TruthCaloShowerDecorator.h:46
ElectronContainer.h
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
TruthCaloShowerDecorator.h
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
DerivationFramework::TruthCaloShowerDecorator::m_truthClusterContainerEem
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_truthClusterContainerEem
Definition: TruthCaloShowerDecorator.h:52
DerivationFramework::TruthCaloShowerDecorator::TruthCaloShowerDecorator
TruthCaloShowerDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: TruthCaloShowerDecorator.cxx:15
DerivationFramework::TruthCaloShowerDecorator::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TruthCaloShowerDecorator.cxx:58
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
MC::isSingleParticle
bool isSingleParticle(const T &p)
Definition: HepMCHelpers.h:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::TruthCaloShowerDecorator::m_calibhitToCaloCellTool
ToolHandle< CalibHitToCaloCellTool > m_calibhitToCaloCellTool
Definition: TruthCaloShowerDecorator.h:64
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
HepMC::SINGLE_PARTICLE
constexpr int SINGLE_PARTICLE
Definition: MagicNumbers.h:53
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
DerivationFramework::TruthCaloShowerDecorator::initialize
StatusCode initialize()
Definition: TruthCaloShowerDecorator.cxx:24
DerivationFramework::TruthCaloShowerDecorator::m_truthParticleContainerName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleContainerName
SG key of the truth particle container.
Definition: TruthCaloShowerDecorator.h:38
Electron.h
AthAlgTool
Definition: AthAlgTool.h:26
TruthParticle.h
EgammaTruthxAODHelpers.h
HepMCHelpers.h