ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkMCTruth
src
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
9
#include "
DerivationFrameworkMCTruth/TruthClassificationDecorator.h
"
10
#include "
MCTruthClassifier/IMCTruthClassifier.h
"
11
#include "
StoreGate/ReadHandle.h
"
12
#include "
StoreGate/WriteDecorHandle.h
"
13
#include "
xAODTruth/TruthParticleContainer.h
"
14
#include "
xAODTruth/TruthParticleAuxContainer.h
"
15
#include <vector>
16
#include <string>
17
18
// Athena initialize and finalize
19
StatusCode
DerivationFramework::TruthClassificationDecorator::initialize
()
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());
31
ATH_CHECK
(
m_classificationDecoratorKey
.initialize());
32
33
return
StatusCode::SUCCESS;
34
}
35
36
StatusCode
DerivationFramework::TruthClassificationDecorator::finalize
()
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
44
StatusCode
DerivationFramework::TruthClassificationDecorator::addBranches
(
const
EventContext& ctx)
const
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) {
66
unsigned
int
particleType
;
67
unsigned
int
particleOrigin;
68
unsigned
int
particleOutCome;
69
std::tie(
particleType
, particleOrigin, std::ignore, particleOutCome) =
m_classifier
->particleTruthClassifier_full((*truthParticles)[i]);
70
unsigned
int
result = (
unsigned
int)( (*truthParticles)[i] ? std::get<0>(
MCTruthPartClassifier::defOrigOfParticle
((*truthParticles)[i])) : 0 );
71
typeDecorator(*((*truthParticles)[i])) =
particleType
;
72
originDecorator(*((*truthParticles)[i])) = particleOrigin;
73
outcomeDecorator(*((*truthParticles)[i])) = particleOutCome;
74
75
classificationDecorator(*((*truthParticles)[i])) = result;
76
}
77
78
return
StatusCode::SUCCESS;
79
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
TruthParticleContainer.h
IMCTruthClassifier.h
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TruthClassificationDecorator.h
TruthParticleAuxContainer.h
DerivationFramework::TruthClassificationDecorator::m_originDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_originDecoratorKey
Definition
TruthClassificationDecorator.h:36
DerivationFramework::TruthClassificationDecorator::m_outcomeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_outcomeDecoratorKey
Definition
TruthClassificationDecorator.h:40
DerivationFramework::TruthClassificationDecorator::m_typeDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_typeDecoratorKey
Definition
TruthClassificationDecorator.h:38
DerivationFramework::TruthClassificationDecorator::m_classifier
PublicToolHandle< IMCTruthClassifier > m_classifier
Definition
TruthClassificationDecorator.h:43
DerivationFramework::TruthClassificationDecorator::finalize
virtual StatusCode finalize() override final
Definition
TruthClassificationDecorator.cxx:36
DerivationFramework::TruthClassificationDecorator::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
TruthClassificationDecorator.cxx:44
DerivationFramework::TruthClassificationDecorator::m_classificationDecoratorKey
SG::WriteDecorHandleKey< xAOD::TruthParticleContainer > m_classificationDecoratorKey
Definition
TruthClassificationDecorator.h:42
DerivationFramework::TruthClassificationDecorator::m_ntotpart
std::atomic< unsigned int > m_ntotpart
Definition
TruthClassificationDecorator.h:31
DerivationFramework::TruthClassificationDecorator::initialize
virtual StatusCode initialize() override final
Definition
TruthClassificationDecorator.cxx:19
DerivationFramework::TruthClassificationDecorator::m_particlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_particlesKey
Definition
TruthClassificationDecorator.h:33
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
particleType
Definition
particleType.h:29
MCTruthPartClassifier::defOrigOfParticle
std::tuple< unsigned int, T > defOrigOfParticle(T thePart)
Definition
TruthClassifiers.h:149
Generated on
for ATLAS Offline Software by
1.17.0