ATLAS Offline Software
Loading...
Searching...
No Matches
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
15#include <vector>
16#include <string>
17
18// Athena initialize and finalize
20{
21 ATH_MSG_VERBOSE("initialize() ...");
22 ATH_CHECK(m_classifier.retrieve());
23
24 ATH_CHECK( m_particlesKey.initialize() );
25 ATH_MSG_INFO("Decorating " << m_particlesKey.key() << " with classification information");
26
27 // Decorators
28 ATH_CHECK(m_originDecoratorKey.initialize());
29 ATH_CHECK(m_typeDecoratorKey.initialize());
30 ATH_CHECK(m_outcomeDecoratorKey.initialize());
32
33 return StatusCode::SUCCESS;
34}
35
37{
38 ATH_MSG_VERBOSE("finalize() ...");
39 ATH_MSG_INFO("Processed and decorated "<< m_ntotpart <<" truth particles");
40 return StatusCode::SUCCESS;
41}
42
43// Selection and collection creation
45{
46
47 // Event context for multi-threading
48
49 // Retrieve truth collections
51 if (!truthParticles.isValid()) {
52 ATH_MSG_ERROR("Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
53 return StatusCode::FAILURE;
54 }
55
56 unsigned int nParticles = truthParticles->size();
57 m_ntotpart += nParticles;
58
59 // Set up decorators
64
65 for (unsigned int i=0; i<nParticles; ++i) {
67 auto classification = m_classifier->particleTruthClassifier((*truthParticles)[i], &info);
68 unsigned int particleOutCome = info.particleOutCome;
69 unsigned int result = (unsigned int)( (*truthParticles)[i] ? std::get<0>(MCTruthPartClassifier::defOrigOfParticle((*truthParticles)[i])) : 0 );
70 unsigned int particleType = classification.first;
71 unsigned int particleOrigin = classification.second;
72 typeDecorator(*((*truthParticles)[i])) = particleType;
73 originDecorator(*((*truthParticles)[i])) = particleOrigin;
74 outcomeDecorator(*((*truthParticles)[i])) = particleOutCome;
75
76 classificationDecorator(*((*truthParticles)[i])) = result;
77 }
78
79 return StatusCode::SUCCESS;
80}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)