ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetValidation
InDetPhysValMonitoring
src
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
11
#include "
TruthClassDecoratorAlg.h
"
12
#include "
safeDecorator.h
"
13
14
15
TruthClassDecoratorAlg::TruthClassDecoratorAlg
(
const
std::string& name, ISvcLocator* pSvcLocator) :
16
AthReentrantAlgorithm
(name,pSvcLocator)
17
{
18
}
19
20
StatusCode
21
TruthClassDecoratorAlg::initialize
() {
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"
;
29
IDPVM::createDecoratorKeys
(*
this
,
m_truthParticleName
,
m_prefix
.value(), decor_names,
m_decor
);
30
assert(
m_decor
.size() ==
kNDecorators
);
31
return
StatusCode::SUCCESS;
32
}
33
34
StatusCode
35
TruthClassDecoratorAlg::finalize
() {
36
return
StatusCode::SUCCESS;
37
}
38
39
40
// to migrate to AthReentrantAlgorithm later
41
StatusCode
42
TruthClassDecoratorAlg::execute
(
const
EventContext &ctx)
const
{
43
SG::ReadHandle<xAOD::TruthParticleContainer>
ptruth(
m_truthParticleName
, ctx);
44
if
((not ptruth.
isValid
())) {
45
return
StatusCode::FAILURE;
46
}
47
48
std::vector< SG::WriteDecorHandle<xAOD::TruthParticleContainer,int> >
49
int_decor(
IDPVM::createDecorators<xAOD::TruthParticleContainer,int>
(
m_decor
, ctx) );
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
65
bool
66
TruthClassDecoratorAlg::decorateTruth
(
const
xAOD::TruthParticle
& particle,
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
TruthClassDecoratorAlg.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
TruthClassDecoratorAlg::kDecorTruthType
@ kDecorTruthType
Definition
TruthClassDecoratorAlg.h:53
TruthClassDecoratorAlg::kDecorTruthOrigin
@ kDecorTruthOrigin
Definition
TruthClassDecoratorAlg.h:54
TruthClassDecoratorAlg::kNDecorators
@ kNDecorators
Definition
TruthClassDecoratorAlg.h:55
TruthClassDecoratorAlg::TruthClassDecoratorAlg
TruthClassDecoratorAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
TruthClassDecoratorAlg.cxx:15
TruthClassDecoratorAlg::decorateTruth
bool decorateTruth(const xAOD::TruthParticle &particle, std::vector< SG::WriteDecorHandle< xAOD::TruthParticleContainer, int > > &int_decor) const
Definition
TruthClassDecoratorAlg.cxx:66
TruthClassDecoratorAlg::finalize
virtual StatusCode finalize() override
Definition
TruthClassDecoratorAlg.cxx:35
TruthClassDecoratorAlg::m_truthClassifier
PublicToolHandle< IMCTruthClassifier > m_truthClassifier
Definition
TruthClassDecoratorAlg.h:41
TruthClassDecoratorAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TruthClassDecoratorAlg.cxx:42
TruthClassDecoratorAlg::m_truthSelectionTool
PublicToolHandle< IAthSelectionTool > m_truthSelectionTool
Definition
TruthClassDecoratorAlg.h:43
TruthClassDecoratorAlg::m_truthParticleName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name needed to create decorators.
Definition
TruthClassDecoratorAlg.h:47
TruthClassDecoratorAlg::initialize
virtual StatusCode initialize() override
Definition
TruthClassDecoratorAlg.cxx:21
TruthClassDecoratorAlg::m_prefix
Gaudi::Property< std::string > m_prefix
Definition
TruthClassDecoratorAlg.h:50
TruthClassDecoratorAlg::m_decor
std::vector< SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > > m_decor
Definition
TruthClassDecoratorAlg.h:57
IDPVM::createDecoratorKeys
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)
Definition
safeDecorator.h:125
IDPVM::createDecorators
std::vector< SG::WriteDecorHandle< T_Cont, T > > createDecorators(const std::vector< SG::WriteDecorHandleKey< T_Cont > > &keys, const EventContext &ctx)
Definition
safeDecorator.h:107
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
safeDecorator.h
implementation file for function of same name
type
Generated on
for ATLAS Offline Software by
1.17.0