ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParametersAtPV.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Author: Tomoe Kishimoto (Tomoe.Kishimoto@cern.ch)
6// Wrapper around the passSelection() method of xAOD egamma
7// Writes result to SG for later selection by string parser
8
10#include <string>
11
12// Athena initialize and finalize
14{
15 if (m_collTrackKey.key().empty() || m_collVertexKey.key().empty()) {
16 ATH_MSG_ERROR("No selection variables for the TrackParametersAtPV tool!");
17 return StatusCode::FAILURE;
18 }
19 ATH_CHECK( m_collTrackKey.initialize() );
20 ATH_CHECK( m_collVertexKey.initialize() );
21
22 if (m_trackZ0PVKey.key().empty()) {
23 ATH_MSG_ERROR("No Store Gate Keys for the TrackParametersAtPV tool!");
24 return StatusCode::FAILURE;
25 }
26 ATH_CHECK( m_trackZ0PVKey.initialize() );
27
28 ATH_MSG_VERBOSE("initialize() ...");
29 return StatusCode::SUCCESS;
30}
31
32// Augmentation
33StatusCode DerivationFramework::TrackParametersAtPV::addBranches(const EventContext& ctx) const
34{
36 ATH_CHECK(track_z0_PV.record(std::make_unique< std::vector<float> >()));
37
38 // Get Primary vertex
40 if(!vertices.isValid()) {
41 ATH_MSG_ERROR ("Couldn't retrieve VertexContainer with key: " << m_collVertexKey.key());
42 return StatusCode::FAILURE;
43 }
44
45 const xAOD::Vertex* pv(nullptr);
46 for (const xAOD::Vertex* vx : *vertices) {
47 if (vx->vertexType() == xAOD::VxType::PriVtx) {
48 pv = vx;
49 break;
50 }
51 }
52
53 // Get the track container
55 if(!tracks.isValid()) {
56 ATH_MSG_ERROR ("Couldn't retrieve TrackParticleContainer with key: " << m_collTrackKey.key());
57 return StatusCode::FAILURE;
58 }
59
60 // Get track z0 w.r.t PV
61 for (const auto *trackIt : *tracks) {
62 if (pv) {
63 float z0wrtPV = trackIt->z0() + trackIt->vz() - pv->z();
64 track_z0_PV->push_back(z0wrtPV);
65
66 } else {
67 track_z0_PV->push_back(999.);
68 }
69 }
70
71 return StatusCode::SUCCESS;
72}
73
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
SG::ReadHandleKey< xAOD::VertexContainer > m_collVertexKey
virtual StatusCode initialize() override final
SG::WriteHandleKey< std::vector< float > > m_trackZ0PVKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_collTrackKey
virtual StatusCode addBranches(const EventContext &ctx) const override final
Check that the current event passes this filter.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.