ATLAS Offline Software
Loading...
Searching...
No Matches
TrackToTrackParticleCnvAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
5
7
8namespace ActsTrk
9{
10
12 ISvcLocator *pSvcLocator)
13 : AthReentrantAlgorithm(name, pSvcLocator)
14 {
15 }
16
18 {
19 std::vector<std::string> supportedStrategies {"BeamLine", "Vertex"};
20 bool isAllowedStrategy = false;
21 for (const std::string& strategy : supportedStrategies) {
22 if (m_perigeeExpression != strategy) continue;
23 isAllowedStrategy = true;
24 break;
25 }
26 ATH_MSG_DEBUG("- perigeeExpression: " << m_perigeeExpression.value());
27 if (not isAllowedStrategy) {
28 ATH_MSG_ERROR("Wrong configuration of the Track to Track Particle Cnv algorithm: perigeeExpression is not supported");
29 return StatusCode::FAILURE;
30 }
31
35 else return StatusCode::FAILURE;
36
37 ATH_CHECK( m_cnvTool.retrieve() );
38 ATH_CHECK( m_tracksContainerKey.initialize() );
39 ATH_CHECK( m_trackParticlesOutKey.initialize() );
42
45
46 return StatusCode::SUCCESS;
47 }
48
49 StatusCode TrackToTrackParticleCnvAlg::execute(const EventContext &ctx) const
50 {
52 if (wh_track_particles.record(std::make_unique<xAOD::TrackParticleContainer>(),
53 std::make_unique<xAOD::TrackParticleAuxContainer>()).isFailure()) {
54 ATH_MSG_ERROR("Failed to record track particle container with key " << m_trackParticlesOutKey.key() );
55 return StatusCode::FAILURE;
56 }
57
59
60 xAOD::TrackParticleContainer *track_particles = wh_track_particles.ptr();
61
62 const InDet::BeamSpotData *beamspot_data {nullptr};
63 const xAOD::VertexContainer *vertexContainer {nullptr};
64 const xAOD::Vertex* primaryVertex {nullptr};
65
68 ATH_CHECK(beamSpotHandle.isValid());
69 beamspot_data = beamSpotHandle.cptr();
70 }
71
74 ATH_CHECK( vertexHandle.isValid() );
75 vertexContainer = vertexHandle.cptr();
76 if (vertexContainer->size() == 0) {
77 ATH_MSG_ERROR("Retrieved an empty vertex container. This is totally wrong!");
78 return StatusCode::FAILURE;
79 }
80
81 for(const xAOD::Vertex* vtx : *vertexContainer) {
82 if(vtx->vertexType() == xAOD::VxType::PriVtx) {
83 primaryVertex = vtx;
84 break;
85 }
86 }
87
88 if (not primaryVertex) {
89 ATH_MSG_WARNING("Requested to compute track particles wrt primary vertex, but no primary vertex is found. Using dummy vertex");
90 primaryVertex = vertexContainer->front();
91 }
92 }
93
94 std::size_t nTracks = 0ul;
95 std::vector<const ActsTrk::TrackContainer *> trackContainers;
98 ATH_CHECK(handle.isValid());
99 trackContainers.push_back( handle.cptr() );
100 nTracks += trackContainers.back()->size();
101 }
102
103 // Fast Insertion Trick
104 std::vector<xAOD::TrackParticle*> toAddParticles;
105 toAddParticles.reserve(nTracks);
106 for (std::size_t i(0); i<nTracks; ++i) {
107 toAddParticles.push_back( new xAOD::TrackParticle() );
108 }
109 track_particles->insert(track_particles->end(),
110 toAddParticles.begin(),
111 toAddParticles.end());
112
113 std::shared_ptr<Acts::PerigeeSurface> perigee_surface {nullptr};
115 perigee_surface = makePerigeeSurface(beamspot_data);
117 perigee_surface = makePerigeeSurface(*primaryVertex);
118 }
119
120 std::size_t particleCounter = 0ul;
121 for (const ActsTrk::TrackContainer *tracksContainer : trackContainers) {
122 for (const typename ActsTrk::TrackContainer::ConstTrackProxy track : *tracksContainer) {
123 xAOD::TrackParticle *track_particle = track_particles->at(particleCounter++);
124 ATH_CHECK( m_cnvTool->convert(*track_particle, ctx, track,
125 perigee_surface.get(), beamspot_data) );
126
127 // add element link to the corresponding track
128 trackLink(*track_particle)
129 = ElementLink<ActsTrk::TrackContainer>( tracksContainer,
130 track.index() );
131 ATH_CHECK( (trackLink(*track_particle)).isValid() );
132 }
133 }
134 ATH_MSG_DEBUG( "Converted " << nTracks << " acts tracks into " << track_particles->size() << " track particles.");
135
136 return StatusCode::SUCCESS;
137 }
138
139 std::shared_ptr<Acts::PerigeeSurface> TrackToTrackParticleCnvAlg::makePerigeeSurface(const InDet::BeamSpotData *beamspot_data) {
140 // @from TrackToVertex::trackAtBeamline
141 Acts::Vector3 beamspot(0., 0., 0.);
142 float tiltx = 0.0;
143 float tilty = 0.0;
144 if (beamspot_data) {
145 beamspot = Acts::Vector3(beamspot_data->beamVtx().position());
146 tiltx = beamspot_data->beamTilt(0);
147 tilty = beamspot_data->beamTilt(1);
148 }
149 Acts::Translation3 translation(beamspot);
150 Acts::Transform3 transform( translation * Acts::RotationMatrix3::Identity() );
151 transform *= Acts::AngleAxis3(tilty, Acts::Vector3(0.,1.,0.));
152 transform *= Acts::AngleAxis3(tiltx, Acts::Vector3(1.,0.,0.));
153 return Acts::Surface::makeShared<Acts::PerigeeSurface>(transform);
154 }
155
156 std::shared_ptr<Acts::PerigeeSurface> TrackToTrackParticleCnvAlg::makePerigeeSurface(const xAOD::Vertex& vertex) {
157 Acts::Translation3 translation(Acts::Vector3(vertex.position()));
158 Acts::Transform3 transform( translation * Acts::RotationMatrix3::Identity() );
159 return Acts::Surface::makeShared<Acts::PerigeeSurface>(transform);
160 }
161
162}
#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)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
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::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexHandle
ToolHandle< ActsTrk::ITrackToTrackParticleCnvTool > m_cnvTool
SG::ReadHandleKeyArray< ActsTrk::TrackContainer > m_tracksContainerKey
Gaudi::Property< std::string > m_perigeeExpression
TrackToTrackParticleCnvAlg(const std::string &name, ISvcLocator *pSvcLocator)
An algorithm that can be simultaneously executed in multiple threads.
const T * at(size_type n) const
Access an element, as an rvalue.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past 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
const_pointer_type cptr()
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
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...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
@ 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".