ATLAS Offline Software
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 
21 namespace DerivationFramework {
22 
24  {
25  ATH_CHECK(m_vertexContainerKey.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 }
DerivationFramework::AugmentationToolExample::m_exampleDecorKey
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_exampleDecorKey
Definition: AugmentationToolExample.h:26
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
DerivationFramework::AugmentationToolExample::initialize
virtual StatusCode initialize() override final
Definition: AugmentationToolExample.cxx:23
AugmentationToolExample.h
DerivationFramework::AugmentationToolExample::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition: AugmentationToolExample.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:572
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DerivationFramework::AugmentationToolExample::m_decisionKey
SG::WriteHandleKey< std::vector< float > > m_decisionKey
Definition: AugmentationToolExample.h:27
Utils::z0wrtPV
double z0wrtPV(const xAOD::TrackParticle *trk, const xAOD::Vertex *vtx)
Provide the trk DCA w.r.t. the PV.
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/src/Utils.cxx:8
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
DerivationFramework::AugmentationToolExample::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const override final
Definition: AugmentationToolExample.cxx:32
python.changerun.pv
pv
Definition: changerun.py:79
DerivationFramework::AugmentationToolExample::m_trackPartContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_trackPartContainerKey
Definition: AugmentationToolExample.h:25