ATLAS Offline Software
Loading...
Searching...
No Matches
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
18#include <vector>
19#include <string>
20
21namespace DerivationFramework {
22
24 {
25 ATH_CHECK(m_vertexContainerKey.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
39
40 // CALCULATION OF THE NEW VARIABLE
41 // Get Primary vertex
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
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Handle class for adding a decoration to an object.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackPartContainerKey
virtual StatusCode addBranches(const EventContext &ctx) const override final
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_exampleDecorKey
SG::WriteHandleKey< std::vector< float > > m_decisionKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
THE reconstruction tool.
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.