ATLAS Offline Software
TruthClassificationDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TruthClassificationDecorator.cxx
7 // Decorates truth particles with the output of the MCTruthClassifier
8 
11 #include "StoreGate/ReadHandle.h"
15 #include <vector>
16 #include <string>
17 
18 // Constructor
20  const std::string& n,
21  const IInterface* p ) :
22 base_class(t,n,p),
23 m_ntotpart(0),
24 m_classifier("MCTruthClassifier/MCTruthClassifier")
25 {
26  declareProperty("MCTruthClassifier", m_classifier);
27 }
28 
29 // Destructor
31 }
32 
33 // Athena initialize and finalize
35 {
36  ATH_MSG_VERBOSE("initialize() ...");
37  ATH_CHECK(m_classifier.retrieve());
38 
39  ATH_CHECK( m_particlesKey.initialize() );
40  ATH_MSG_INFO("Decorating " << m_particlesKey.key() << " with classification information");
41 
42  // Decorators
43  ATH_CHECK(m_originDecoratorKey.initialize());
44  ATH_CHECK(m_typeDecoratorKey.initialize());
45  ATH_CHECK(m_outcomeDecoratorKey.initialize());
46  ATH_CHECK(m_classificationDecoratorKey.initialize());
47 
48  return StatusCode::SUCCESS;
49 }
50 
52 {
53  ATH_MSG_VERBOSE("finalize() ...");
54  ATH_MSG_INFO("Processed and decorated "<< m_ntotpart <<" truth particles");
55  return StatusCode::SUCCESS;
56 }
57 
58 // Selection and collection creation
60 {
61 
62  // Event context for multi-threading
63  const EventContext& ctx = Gaudi::Hive::currentContext();
64 
65  // Retrieve truth collections
66  SG::ReadHandle<xAOD::TruthParticleContainer> truthParticles(m_particlesKey,ctx);
67  if (!truthParticles.isValid()) {
68  ATH_MSG_ERROR("Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
69  return StatusCode::FAILURE;
70  }
71 
72  unsigned int nParticles = truthParticles->size();
73  m_ntotpart += nParticles;
74 
75  // Set up decorators
76  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> originDecorator(m_originDecoratorKey, ctx);
77  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> typeDecorator(m_typeDecoratorKey, ctx);
78  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> outcomeDecorator(m_outcomeDecoratorKey, ctx);
79  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> classificationDecorator(m_classificationDecoratorKey, ctx);
80 
81  for (unsigned int i=0; i<nParticles; ++i) {
83  auto classification = m_classifier->particleTruthClassifier((*truthParticles)[i], &info);
84  unsigned int particleOutCome = info.particleOutCome;
85  unsigned int result = (unsigned int)( (*truthParticles)[i] ? std::get<0>(MCTruthPartClassifier::defOrigOfParticle((*truthParticles)[i])) : 0 );
86  unsigned int particleType = classification.first;
87  unsigned int particleOrigin = classification.second;
88  typeDecorator(*((*truthParticles)[i])) = particleType;
89  originDecorator(*((*truthParticles)[i])) = particleOrigin;
90  outcomeDecorator(*((*truthParticles)[i])) = particleOutCome;
91 
92  classificationDecorator(*((*truthParticles)[i])) = result;
93  }
94 
95  return StatusCode::SUCCESS;
96 }
97 
TruthClassificationDecorator.h
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle< xAOD::TruthParticleContainer >
TruthParticleContainer.h
DerivationFramework::TruthClassificationDecorator::TruthClassificationDecorator
TruthClassificationDecorator(const std::string &t, const std::string &n, const IInterface *p)
Definition: TruthClassificationDecorator.cxx:19
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition: TruthClassifiers.h:151
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TruthClassificationDecorator::addBranches
virtual StatusCode addBranches() const
Definition: TruthClassificationDecorator.cxx:59
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
DerivationFramework::TruthClassificationDecorator::initialize
StatusCode initialize()
Definition: TruthClassificationDecorator.cxx:34
DerivationFramework::TruthClassificationDecorator::finalize
StatusCode finalize()
Definition: TruthClassificationDecorator.cxx:51
particleType
Definition: particleType.h:29
TruthParticleAuxContainer.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
IMCTruthClassifier.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
DerivationFramework::TruthClassificationDecorator::m_classifier
ToolHandle< IMCTruthClassifier > m_classifier
Definition: TruthClassificationDecorator.h:42
DerivationFramework::TruthClassificationDecorator::~TruthClassificationDecorator
~TruthClassificationDecorator()
Definition: TruthClassificationDecorator.cxx:30
ReadHandle.h
Handle class for reading from StoreGate.
MCTruthPartClassifier::Info
Definition: IMCTruthClassifier.h:49
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87