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 // Athena initialize and finalize
20 {
21  ATH_MSG_VERBOSE("initialize() ...");
22  ATH_CHECK(m_classifier.retrieve());
23 
25  ATH_MSG_INFO("Decorating " << m_particlesKey.key() << " with classification information");
26 
27  // Decorators
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
50  SG::ReadHandle<xAOD::TruthParticleContainer> truthParticles(m_particlesKey,ctx);
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
60  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> originDecorator(m_originDecoratorKey, ctx);
61  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> typeDecorator(m_typeDecoratorKey, ctx);
62  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> outcomeDecorator(m_outcomeDecoratorKey, ctx);
63  SG::WriteDecorHandle<xAOD::TruthParticleContainer, unsigned int> classificationDecorator(m_classificationDecoratorKey, ctx);
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 }
TruthClassificationDecorator.h
DerivationFramework::TruthClassificationDecorator::m_classifier
PublicToolHandle< IMCTruthClassifier > m_classifier
Definition: TruthClassificationDecorator.h:43
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 >
DerivationFramework::TruthClassificationDecorator::m_classificationDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
Definition: TruthClassificationDecorator.h:42
TruthParticleContainer.h
DerivationFramework::TruthClassificationDecorator::m_outcomeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
Definition: TruthClassificationDecorator.h:40
DerivationFramework::TruthClassificationDecorator::finalize
virtual StatusCode finalize() override final
Definition: TruthClassificationDecorator.cxx:36
DerivationFramework::TruthClassificationDecorator::m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
Definition: TruthClassificationDecorator.h:36
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition: TruthClassifiers.h:151
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
particleType
Definition: particleType.h:29
TruthParticleAuxContainer.h
DerivationFramework::TruthClassificationDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: TruthClassificationDecorator.cxx:44
IMCTruthClassifier.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
DerivationFramework::TruthClassificationDecorator::m_particlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
Definition: TruthClassificationDecorator.h:33
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework::TruthClassificationDecorator::initialize
virtual StatusCode initialize() override final
Definition: TruthClassificationDecorator.cxx:19
DerivationFramework::TruthClassificationDecorator::m_typeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
Definition: TruthClassificationDecorator.h:38
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
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