ATLAS Offline Software
Loading...
Searching...
No Matches
TruthDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9
11#include "TruthDecoratorAlg.h"
12
13
18 const std::string& name,
19 ISvcLocator* pSvcLocator ) :
20 AthReentrantAlgorithm( name, pSvcLocator ) { }
21
22
27
29 not m_truthParticlesName.key().empty() ) );
30
31 ATH_CHECK( m_truthClassifier.retrieve() );
32
37
38 if( m_decor_truth.size() != NDecorations ) {
39 ATH_MSG_ERROR( "Incorrect booking of truth class decorations" );
40 return StatusCode::FAILURE;
41 }
42
43 return StatusCode::SUCCESS;
44}
45
46
50StatusCode IDTPM::TruthDecoratorAlg::execute( const EventContext& ctx ) const {
51
54 if( not ptruths.isValid() ) {
55 ATH_MSG_ERROR( "Failed to retrieve truth particles container" );
56 return StatusCode::FAILURE;
57 }
58
60 if( IDTPM::decorationsAllExist( *ptruths, m_decor_truth ) ) {
61 ATH_MSG_DEBUG( "All decorations already exist. Exiting gracefully" );
62 return StatusCode::SUCCESS;
63 }
64
66 std::vector< IDTPM::OptionalDecoration<xAOD::TruthParticleContainer, int> >
67 truth_decor( IDTPM::createDecoratorsIfNeeded( *ptruths, m_decor_truth, ctx ) );
68
69 if( truth_decor.empty() ) {
70 ATH_MSG_ERROR( "Failed to book truth class decorations" );
71 return StatusCode::FAILURE;
72 }
73
74 for( const xAOD::TruthParticle* truth : *ptruths ) {
76 ATH_CHECK( decorateTruthParticle( *truth, truth_decor ) );
77 }
78
79 return StatusCode::SUCCESS;
80}
81
82
87 const xAOD::TruthParticle& truth,
89 int>>& truth_decor) const {
90
92 auto truthClass = m_truthClassifier->particleTruthClassifier( &truth );
93 int type = static_cast<int>( truthClass.first );
94 int origin = static_cast<int>( truthClass.second );
95
97 IDTPM::decorateOrRejectQuietly( truth, truth_decor[Type], type );
98 IDTPM::decorateOrRejectQuietly( truth, truth_decor[Origin], origin );
99
100 return StatusCode::SUCCESS;
101}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Algorithm to decorate truth particles with their origin and type classes from MCTruthClassifier.
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
TruthDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Local includes.
std::vector< IDTPM::WriteKeyAccessorPair< xAOD::TruthParticleContainer, int > > m_decor_truth
StatusCode decorateTruthParticle(const xAOD::TruthParticle &truth, std::vector< IDTPM::OptionalDecoration< xAOD::TruthParticleContainer, int > > &truth_decor) const
PublicToolHandle< IMCTruthClassifier > m_truthClassifier
virtual StatusCode execute(const EventContext &ctx) const override
const std::vector< std::string > m_decor_truth_names
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticlesName
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::pair< SG::WriteDecorHandle< ContainerType, VariableType >, bool > OptionalDecoration
bool decorationsAllExist(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, bool verbose=false)
Like above - FIXME: maybe not needed.
void createDecoratorKeysAndAccessor(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< WriteKeyAccessorPair< T_Cont, T > > &decor_out)
create a pair composed of a WriteDecorHandleKey to create a decorator handle and an accessor to check...
std::vector< OptionalDecoration< T_Cont, T > > createDecoratorsIfNeeded(const T_Cont &container, const std::vector< WriteKeyAccessorPair< T_Cont, T > > &keys, const EventContext &ctx, bool verbose=false)
create/book the decorations if they do not exist already
void decorateOrRejectQuietly(const T_Cont_Elm &particle, OptionalDecoration< T_Cont, T > &decorator, const T &value)
Safe method to fill the decoration if decor flag is true.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.