ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
AnalysisCommon
ParticleJetTools
Root
CopyTruthParticles.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
ParticleJetTools/CopyTruthParticles.h
"
6
#include <memory>
7
#include "
TruthUtils/HepMCHelpers.h
"
8
#include "
AsgMessaging/Check.h
"
9
#include "
AsgDataHandles/ReadHandle.h
"
10
#include "
AsgDataHandles/WriteHandle.h
"
11
12
using namespace
std
;
13
14
15
CopyTruthParticles::CopyTruthParticles
(
const
std::string& name)
16
:
AsgTool
(name) {}
17
18
StatusCode
CopyTruthParticles::initialize
() {
19
20
ATH_CHECK
(
m_truthEventKey
.initialize());
21
ATH_CHECK
(
m_outTruthPartKey
.initialize());
22
23
return
StatusCode::SUCCESS;
24
}
25
26
int
CopyTruthParticles::execute
()
const
{
27
// Retrieve the xAOD truth objects
28
auto
truthEvents =
SG::makeHandle
(
m_truthEventKey
);
29
if
( !truthEvents.isValid() ) {
30
ATH_MSG_ERROR
(
"Failed to retrieve truth event container "
<<
m_truthEventKey
.key());
31
return
1;
32
}
33
34
// Classify particles for tagging and add to the TruthParticleContainer
35
std::unique_ptr<ConstDataVector<xAOD::TruthParticleContainer> > ptruth(
new
ConstDataVector<xAOD::TruthParticleContainer>
(
SG::VIEW_ELEMENTS
));
36
size_t
numCopied = 0;
37
const
xAOD::TruthEvent
* hsevt = truthEvents->front();
38
if
(!hsevt) {
39
ATH_MSG_ERROR
(
"Null pointer received for first truth event!"
);
40
return
1;
41
}
42
for
(
size_t
itp(0); itp<hsevt->
nTruthParticles
(); ++itp) {
43
const
xAOD::TruthParticle
* tp = hsevt->
truthParticle
(itp);
44
if
(!tp) {
45
// This might result from a thinned truth collection, so is not
46
// an error state.
47
ATH_MSG_VERBOSE
(
"Null pointer received for truth particle to be copied"
);
48
continue
;
49
}
50
if
(tp->
pt
() <
m_ptmin
)
51
continue
;
52
53
if
(
classify
(tp)) {
54
ptruth->push_back(tp);
55
numCopied += 1;
56
}
57
}
58
59
ATH_MSG_DEBUG
(
"Copied "
<< numCopied <<
" truth particles into "
<<
m_outTruthPartKey
.key() <<
" TruthParticle container"
);
60
61
// record
62
auto
truthParticles_out =
SG::makeHandle
(
m_outTruthPartKey
);
63
ATH_MSG_DEBUG
(
"Recorded truth particle collection "
<<
m_outTruthPartKey
.key());
64
// notify
65
if
(!truthParticles_out.put(std::move(ptruth))) {
66
ATH_MSG_ERROR
(
"Unable to write new TruthParticleContainer to event store: "
67
<<
m_outTruthPartKey
.key());
68
}
else
{
69
ATH_MSG_DEBUG
(
"Created new TruthParticleContainer in event store: "
70
<<
m_outTruthPartKey
.key());
71
}
72
73
return
0;
74
}
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_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
ReadHandle.h
Handle class for reading from StoreGate.
WriteHandle.h
Handle class for recording to StoreGate.
Check.h
CopyTruthParticles.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition
ConstDataVector.h:76
CopyTruthParticles::m_outTruthPartKey
SG::WriteHandleKey< ConstDataVector< xAOD::TruthParticleContainer > > m_outTruthPartKey
Key for output truth particles.
Definition
CopyTruthParticles.h:46
CopyTruthParticles::classify
virtual bool classify(const xAOD::TruthParticle *tp) const =0
Classifier function(s).
CopyTruthParticles::CopyTruthParticles
CopyTruthParticles(const std::string &name)
Constructor.
Definition
CopyTruthParticles.cxx:15
CopyTruthParticles::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition
CopyTruthParticles.cxx:18
CopyTruthParticles::m_ptmin
Gaudi::Property< float > m_ptmin
Minimum pT for particle selection (in MeV).
Definition
CopyTruthParticles.h:40
CopyTruthParticles::execute
virtual int execute() const
Method to be called for each event.
Definition
CopyTruthParticles.cxx:26
CopyTruthParticles::m_truthEventKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventKey
Key for input truth event.
Definition
CopyTruthParticles.h:43
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
xAOD::TruthEventBase_v1::truthParticle
const TruthParticle * truthParticle(size_t index) const
Get a pointer to one of the truth particles.
Definition
TruthEventBase_v1.cxx:50
xAOD::TruthEventBase_v1::nTruthParticles
size_t nTruthParticles() const
Get the number of truth particles.
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition
TruthParticle_v1.cxx:161
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition
OwnershipPolicy.h:18
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition
ReadCondHandle.h:269
std
STL namespace.
xAOD::TruthEvent
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition
TruthEvent.h:17
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
Generated on
for ATLAS Offline Software by
1.17.0