ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkMCTruth
src
TruthPVCollectionMaker.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
// TruthPVCollectionMaker.cxx
7
// Makes a small collection of 'primary' vertices, one per event
8
// A bit like a collection of 'reconstructable' vertices
9
// Future option: try to add b-decay vertices, or LLP vertices?
10
11
#include "
DerivationFrameworkMCTruth/TruthPVCollectionMaker.h
"
12
#include "
xAODTruth/TruthVertexAuxContainer.h
"
13
#include "
StoreGate/ReadHandle.h
"
14
#include "
StoreGate/WriteHandle.h
"
15
16
#include "
TruthUtils/HepMCHelpers.h
"
17
18
// Athena initialize
19
StatusCode
DerivationFramework::TruthPVCollectionMaker::initialize
()
20
{
21
ATH_MSG_VERBOSE
(
"initialize() ..."
);
22
23
// Check configuration, print errors, warning, and information for the user
24
ATH_CHECK
(
m_eventsKey
.initialize());
25
ATH_MSG_INFO
(
"Using "
<<
m_eventsKey
.fullKey() <<
" as the source collections for new truth collections"
);
26
ATH_CHECK
(
m_outVtxKey
.initialize());
27
ATH_MSG_INFO
(
"New truth vertex collection key: "
<<
m_outVtxKey
.fullKey() );
28
29
return
StatusCode::SUCCESS;
30
}
31
32
33
// Selection and collection creation
34
StatusCode
DerivationFramework::TruthPVCollectionMaker::addBranches
(
const
EventContext& ctx)
const
35
{
36
// Retrieve truth collections
37
SG::ReadHandle<xAOD::TruthEventContainer>
importedTruthEvents{
m_eventsKey
, ctx};
38
if
(!importedTruthEvents.
isValid
()) {
39
ATH_MSG_ERROR
(
"No TruthEvent collection with name "
<<
m_eventsKey
.fullKey() <<
" found in StoreGate!"
);
40
return
StatusCode::FAILURE;
41
}
42
43
// Create the new vertex containers
44
SG::WriteHandle<xAOD::TruthVertexContainer>
writeHandleVtx{
m_outVtxKey
, ctx};
45
ATH_CHECK
(writeHandleVtx.
record
(std::make_unique<xAOD::TruthVertexContainer>(),
46
std::make_unique<xAOD::TruthVertexAuxContainer>()));
47
xAOD::TruthVertexContainer
* newVertexCollection = writeHandleVtx.
ptr
();
48
ATH_MSG_DEBUG
(
"Recorded new TruthVertexContainer with key: "
<<
m_outVtxKey
.fullKey());
49
50
// Go through the events, add one vertex for each event
51
for
(
const
auto
* event : *importedTruthEvents){
52
// Just in case there is a place-holder
53
if
(!event)
continue
;
54
// Try with the signal process vertex
55
const
xAOD::TruthVertex
* old_vert(event->signalProcessVertex());
56
// If that's not there, grab the first vertex
57
if
(!old_vert && event->nTruthVertices()>0){
58
old_vert =
event
->truthVertex(0);
59
}
60
if
(old_vert){
61
// Hit -- copy it!
62
// Make a new vertex and add it to the container
63
xAOD::TruthVertex
* xTruthVertex =
new
xAOD::TruthVertex
();
64
newVertexCollection->
push_back
( xTruthVertex );
65
// Set properties
66
xTruthVertex->
setStatus
(
HepMC::status
(old_vert));
67
xTruthVertex->
setUid
(
HepMC::uniqueID
(old_vert));
68
xTruthVertex->
setX
(old_vert->
x
());
69
xTruthVertex->
setY
(old_vert->
y
());
70
xTruthVertex->
setZ
(old_vert->
z
());
71
xTruthVertex->
setT
(old_vert->
t
());
72
}
else
{
73
ATH_MSG_WARNING
(
"No signal vertex or vertices associated to an input event!"
);
74
}
75
}
76
return
StatusCode::SUCCESS;
77
}
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
HepMCHelpers.h
ATLAS-specific HepMC functions.
ReadHandle.h
Handle class for reading from StoreGate.
WriteHandle.h
Handle class for recording to StoreGate.
TruthPVCollectionMaker.h
TruthVertexAuxContainer.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DerivationFramework::TruthPVCollectionMaker::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
TruthPVCollectionMaker.cxx:34
DerivationFramework::TruthPVCollectionMaker::m_outVtxKey
SG::WriteHandleKey< xAOD::TruthVertexContainer > m_outVtxKey
Output collection name.
Definition
TruthPVCollectionMaker.h:28
DerivationFramework::TruthPVCollectionMaker::initialize
virtual StatusCode initialize() override final
Definition
TruthPVCollectionMaker.cxx:19
DerivationFramework::TruthPVCollectionMaker::m_eventsKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_eventsKey
Input event collection (navigates to the vertices).
Definition
TruthPVCollectionMaker.h:27
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
xAOD::TruthVertex_v1::z
float z() const
Vertex longitudinal distance along the beam line form the origin.
xAOD::TruthVertex_v1::setStatus
void setStatus(int value)
Set the vertex status.
xAOD::TruthVertex_v1::setZ
void setZ(float value)
Set the vertex's longitudinal distance from the origin.
xAOD::TruthVertex_v1::y
float y() const
Vertex y displacement.
xAOD::TruthVertex_v1::setUid
void setUid(int value)
Set the vertex unique ID.
xAOD::TruthVertex_v1::t
float t() const
Vertex time.
xAOD::TruthVertex_v1::setT
void setT(float value)
Set the vertex time.
xAOD::TruthVertex_v1::x
float x() const
Vertex x displacement.
xAOD::TruthVertex_v1::setX
void setX(float value)
Set the x displacement of the vertex.
xAOD::TruthVertex_v1::setY
void setY(float value)
Set the y displacement of the vertex.
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::status
int status(const T &p)
Definition
MagicNumbers.h:115
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition
TruthVertex.h:15
xAOD::TruthVertexContainer
TruthVertexContainer_v1 TruthVertexContainer
Declare the latest version of the truth vertex container.
Definition
TruthVertexContainer.h:17
Generated on
for ATLAS Offline Software by
1.17.0