ATLAS Offline Software
Loading...
Searching...
No Matches
TruthClassDecoratorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
10
12#include "safeDecorator.h"
13
14
15TruthClassDecoratorAlg::TruthClassDecoratorAlg(const std::string& name, ISvcLocator* pSvcLocator) :
16 AthReentrantAlgorithm(name,pSvcLocator)
17{
18}
19
20StatusCode
22 ATH_CHECK(m_truthClassifier.retrieve());
23 ATH_CHECK( m_truthSelectionTool.retrieve( EnableTool { not m_truthSelectionTool.name().empty() } ) );
24 ATH_CHECK( m_truthParticleName.initialize() );
25
26 std::vector<std::string> decor_names(kNDecorators);
27 decor_names[kDecorTruthType]="truthType";
28 decor_names[kDecorTruthOrigin]="truthOrigin";
30 assert( m_decor.size() == kNDecorators);
31 return StatusCode::SUCCESS;
32}
33
34StatusCode
36 return StatusCode::SUCCESS;
37}
38
39
40// to migrate to AthReentrantAlgorithm later
41StatusCode
42TruthClassDecoratorAlg::execute(const EventContext &ctx) const {
44 if ((not ptruth.isValid())) {
45 return StatusCode::FAILURE;
46 }
47
48 std::vector< SG::WriteDecorHandle<xAOD::TruthParticleContainer,int> >
50
51 if (m_truthSelectionTool.get()) {
52 for (const xAOD::TruthParticle *truth_particle : *ptruth) {
53 if (not m_truthSelectionTool->accept(truth_particle)) continue;
54 if (not decorateTruth(*truth_particle, int_decor) ) return StatusCode::FAILURE;
55 }
56 }
57 else {
58 for (const xAOD::TruthParticle *truth_particle : *ptruth) {
59 if (not decorateTruth(*truth_particle, int_decor) ) return StatusCode::FAILURE;
60 }
61 }
62 return StatusCode::SUCCESS;
63}
64
65bool
67 std::vector< SG::WriteDecorHandle<xAOD::TruthParticleContainer,int> > &int_decor) const {
68 bool success(false);
69
70 if (not m_truthClassifier.empty()) {
71 auto truthClass = m_truthClassifier->particleTruthClassifier(&particle);
72 int type = static_cast<int>(truthClass.first);
73 int origin = static_cast<int>(truthClass.second);
74 int_decor[kDecorTruthType](particle) = type;
75 int_decor[kDecorTruthOrigin](particle) = origin;
76 success = true;
77 }
78 return success;
79}
#define ATH_CHECK
Evaluate an expression and check for errors.
An algorithm that can be simultaneously executed in multiple threads.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
TruthClassDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
bool decorateTruth(const xAOD::TruthParticle &particle, std::vector< SG::WriteDecorHandle< xAOD::TruthParticleContainer, int > > &int_decor) const
virtual StatusCode finalize() override
PublicToolHandle< IMCTruthClassifier > m_truthClassifier
virtual StatusCode execute(const EventContext &ctx) const override
PublicToolHandle< IAthSelectionTool > m_truthSelectionTool
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name needed to create decorators.
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_prefix
std::vector< SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > > m_decor
void createDecoratorKeys(T_Parent &parent, const SG::ReadHandleKey< T_Cont > &container_key, const std::string &prefix, const std::vector< std::string > &decor_names, std::vector< SG::WriteDecorHandleKey< T_Cont > > &decor_out)
std::vector< SG::WriteDecorHandle< T_Cont, T > > createDecorators(const std::vector< SG::WriteDecorHandleKey< T_Cont > > &keys, const EventContext &ctx)
TruthParticle_v1 TruthParticle
Typedef to implementation.
implementation file for function of same name