ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
DerivationFramework
DerivationFrameworkExamples
src
AugmentationToolExample.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
// AugmentationToolExample.cxx
8
// Author: Thomas Gillam (thomas.gillam@cern.ch)
9
//
10
// This is a trivial example of tool that creates extra information
11
// and places it in the StoreGate.
12
// The example shows how to do it with (a) simple vectors and (b) dressing
13
// of objects (tracks in this case).
14
// The same information is written into both.
15
16
#include "
AugmentationToolExample.h
"
17
#include "
StoreGate/WriteDecorHandle.h
"
18
#include <vector>
19
#include <string>
20
21
namespace
DerivationFramework
{
22
23
StatusCode
AugmentationToolExample::initialize
()
24
{
25
ATH_CHECK
(
m_vertexContainerKey
.initialize());
26
ATH_CHECK
(
m_trackPartContainerKey
.initialize());
27
ATH_CHECK
(
m_exampleDecorKey
.initialize());
28
ATH_CHECK
(
m_decisionKey
.initialize());
29
return
StatusCode::SUCCESS;
30
}
31
32
StatusCode
AugmentationToolExample::addBranches
(
const
EventContext& ctx)
const
33
{
34
// Set up the vector
35
std::unique_ptr<std::vector<float> > track_z0_PV(
new
std::vector<float>());
36
37
// Set up the decorators
38
SG::WriteDecorHandle< xAOD::TrackParticleContainer, float >
decorator(
m_exampleDecorKey
, ctx);
39
40
// CALCULATION OF THE NEW VARIABLE
41
// Get Primary vertex
42
SG::ReadHandle<xAOD::VertexContainer>
vertices(
m_vertexContainerKey
, ctx);
43
if
(!vertices.
isValid
()) {
44
ATH_MSG_ERROR
(
"Couldn't retrieve VertexContainer with key PrimaryVertices"
);
45
return
StatusCode::FAILURE;
46
}
47
48
const
xAOD::Vertex
* pv{};
49
for
(
const
xAOD::Vertex
* vx : *vertices) {
50
if
(vx->vertexType() ==
xAOD::VxType::PriVtx
) {
51
pv = vx;
52
break
;
53
}
54
}
55
56
// Get the track container
57
SG::ReadHandle<xAOD::TrackParticleContainer>
tracks(
m_trackPartContainerKey
, ctx);
58
if
(!tracks.
isValid
()) {
59
ATH_MSG_ERROR
(
"Couldn't retrieve TrackParticleContainer with key InDetTrackParticles"
);
60
return
StatusCode::FAILURE;
61
}
62
63
// Get track z0 w.r.t PV: this is what we're adding
64
for
(
const
auto
*trackParticle : *tracks) {
65
if
(pv) {
66
float
z0wrtPV = trackParticle->z0() + trackParticle->vz() - pv->z();
// CALCULATE THE QUANTITY
67
track_z0_PV->push_back(z0wrtPV);
// ADD TO VECTOR
68
decorator(*trackParticle) = z0wrtPV;
// DECORATE THE TRACK
69
}
else
{
70
track_z0_PV->push_back(999.);
71
decorator(*trackParticle) = 999.;
72
}
73
}
74
75
// Write decision to SG for access by downstream algs
76
SG::WriteHandle<std::vector<float>
> decision(
m_decisionKey
, ctx);
77
if
(!decision.
isValid
()) {
78
ATH_MSG_ERROR
(
"Tool is attempting to write StoreGate keys which already exists. Please use a different key"
);
79
return
StatusCode::FAILURE;
80
}
else
{
81
decision = std::move(track_z0_PV);
82
}
83
84
return
StatusCode::SUCCESS;
85
}
86
}
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
AugmentationToolExample.h
WriteDecorHandle.h
Handle class for adding a decoration to an object.
DerivationFramework::AugmentationToolExample::m_trackPartContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackPartContainerKey
Definition
AugmentationToolExample.h:25
DerivationFramework::AugmentationToolExample::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition
AugmentationToolExample.cxx:32
DerivationFramework::AugmentationToolExample::m_exampleDecorKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_exampleDecorKey
Definition
AugmentationToolExample.h:26
DerivationFramework::AugmentationToolExample::m_decisionKey
SG::WriteHandleKey< std::vector< float > > m_decisionKey
Definition
AugmentationToolExample.h:27
DerivationFramework::AugmentationToolExample::initialize
virtual StatusCode initialize() override final
Definition
AugmentationToolExample.cxx:23
DerivationFramework::AugmentationToolExample::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition
AugmentationToolExample.h:24
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
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
DerivationFramework
THE reconstruction tool.
Definition
CascadeTools.h:16
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition
TrackingPrimitives.h:590
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition
Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Generated on
for ATLAS Offline Software by
1.17.0