ATLAS Offline Software
Loading...
Searching...
No Matches
TrackToTrackParticleCnvAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
7
9
10namespace ActsTrk {
12 const std::vector<std::string> supportedStrategies {"BeamLine", "Vertex", "DontRecalculate"};
13 bool isAllowedStrategy = false;
14 for (const std::string& strategy : supportedStrategies) {
15 if (m_perigeeExpression != strategy) continue;
16 isAllowedStrategy = true;
17 break;
18 }
19 ATH_MSG_DEBUG("- perigeeExpression: " << m_perigeeExpression.value());
20 if (not isAllowedStrategy) {
21 ATH_MSG_ERROR("Wrong configuration of the Track to Track Particle Cnv algorithm: perigeeExpression is not supported");
22 return StatusCode::FAILURE;
23 }
24
25 if (m_perigeeExpression == "BeamLine") {
27 } else if (m_perigeeExpression == "Vertex") {
29 } else if (m_perigeeExpression == "DontRecalculate") {
31 }
32
33 ATH_CHECK(m_cnvTool.retrieve() );
34 ATH_CHECK(m_tracksContainerKey.initialize() );
35 ATH_CHECK(m_trackParticlesOutKey.initialize() );
39
40 return StatusCode::SUCCESS;
41 }
42
43 StatusCode TrackToTrackParticleCnvAlg::execute(const EventContext &ctx) const {
44 SG::WriteHandle wh_track_particles( m_trackParticlesOutKey, ctx);
45 ATH_CHECK(wh_track_particles.record(std::make_unique<xAOD::TrackParticleContainer>(),
46 std::make_unique<xAOD::TrackParticleAuxContainer>()));
47
49
50 xAOD::TrackParticleContainer *track_particles = wh_track_particles.ptr();
51
52 const InDet::BeamSpotData *beamspot_data {nullptr};
53 ATH_CHECK(SG::get(beamspot_data, m_beamSpotKey, ctx));
54 const xAOD::VertexContainer *vertexContainer {nullptr};
55 ATH_CHECK(SG::get(vertexContainer, m_vertexKey, ctx));
56 const xAOD::Vertex* primaryVertex {nullptr};
57
58
59
61 if (vertexContainer->size() == 0) {
62 ATH_MSG_ERROR("Retrieved an empty vertex container. This is totally wrong!");
63 return StatusCode::FAILURE;
64 }
65
66 for(const xAOD::Vertex* vtx : *vertexContainer) {
67 if(vtx->vertexType() == xAOD::VxType::PriVtx) {
68 primaryVertex = vtx;
69 break;
70 }
71 }
72
73 if (not primaryVertex) {
74 ATH_MSG_WARNING("Requested to compute track particles wrt primary vertex, but no primary vertex is found. Using dummy vertex");
75 primaryVertex = vertexContainer->front();
76 }
77 }
78
79 std::size_t nTracks = 0ul;
80 std::vector<const ActsTrk::TrackContainer *> trackContainers;
82 ATH_CHECK(SG::get(trackContainers.emplace_back(nullptr), handleKey, ctx));
83 nTracks += trackContainers.back()->size();
84 }
85
86 // Fast Insertion Trick
87 track_particles->reserve(nTracks);
88 for (std::size_t i = 0; i<nTracks; ++i) {
89 track_particles->push_back( std::make_unique<xAOD::TrackParticle>());
90 }
91
92 std::shared_ptr<const Acts::Surface> perigee_surface {nullptr};
94 perigee_surface = makePerigeeSurface(beamspot_data);
96 perigee_surface = makePerigeeSurface(*primaryVertex);
97 }
98
99 std::size_t particleCounter = 0ul;
100 for (const ActsTrk::TrackContainer *tracksContainer : trackContainers) {
101 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
102 xAOD::TrackParticle *track_particle = track_particles->at(particleCounter++);
104 perigee_surface = track.referenceSurface().getSharedPtr();
105 }
106 ATH_CHECK(m_cnvTool->convert(*track_particle, ctx, track, *perigee_surface, beamspot_data));
107
108 // add element link to the corresponding track
109 trackLink(*track_particle) = ElementLink<ActsTrk::TrackContainer>(*tracksContainer, track.index(), ctx);
110 ATH_CHECK( trackLink(*track_particle).isValid() );
111 }
112 }
113 ATH_MSG_DEBUG( "Converted " << nTracks << " acts tracks into " << track_particles->size() << " track particles.");
114
115 return StatusCode::SUCCESS;
116 }
117
118 std::shared_ptr<Acts::PerigeeSurface> TrackToTrackParticleCnvAlg::makePerigeeSurface(const InDet::BeamSpotData *beamspot_data) {
119 // @from TrackToVertex::trackAtBeamline
120 Acts::Vector3 beamspot = Amg::Vector3D::Zero();
121 float tiltx{0.f}, tilty{0.f};
122 if (beamspot_data) {
123 beamspot = beamspot_data->beamVtx().position();
124 tiltx = beamspot_data->beamTilt(0);
125 tilty = beamspot_data->beamTilt(1);
126 }
127 Amg::Transform3D trf = Amg::getTranslate3D(beamspot) *
128 Amg::getRotateY3D(tilty) *
129 Amg::getRotateX3D(tiltx);
130 return Acts::Surface::makeShared<Acts::PerigeeSurface>(trf);
131 }
132
133 std::shared_ptr<Acts::PerigeeSurface> TrackToTrackParticleCnvAlg::makePerigeeSurface(const xAOD::Vertex& vertex) {
134 return Acts::Surface::makeShared<Acts::PerigeeSurface>(Amg::getTranslate3D(vertex.position()));
135 }
136
137}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static std::shared_ptr< Acts::PerigeeSurface > makePerigeeSurface(const InDet::BeamSpotData *beamspotptr)
SG::WriteDecorHandleKey< xAOD::TrackParticleContainer > m_decorator_actsTracks
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_trackParticlesOutKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
ToolHandle< ActsTrk::ITrackToTrackParticleCnvTool > m_cnvTool
SG::ReadHandleKeyArray< ActsTrk::TrackContainer > m_tracksContainerKey
Gaudi::Property< std::string > m_perigeeExpression
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
float beamTilt(int i) const noexcept
Returns the beam sigma for the i+3-th error matrix element (the 'tilt').
const Trk::RecVertex & beamVtx() const noexcept
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for adding a decoration to an object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
const Amg::Vector3D & position() const
return position of vertex
Definition Vertex.cxx:63
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Amg::Transform3D getRotateX3D(double angle)
get a rotation transformation around X-axis
Amg::Transform3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
Eigen::Affine3d Transform3D
Amg::Transform3D getRotateY3D(double angle)
get a rotation transformation around Y-axis
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
@ PriVtx
Primary vertex.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".