ATLAS Offline Software
TrackToVertex.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 // TrackToVertex.cxx, (c) ATLAS Detector software 2005
8 
9 // Reco & Rec
10 #include "TrackToVertex.h"
11 // Trk
16 #include "VxVertex/VxCandidate.h"
17 #include "VxVertex/RecVertex.h"
18 
19 
21 
22 // constructor
23 Reco::TrackToVertex::TrackToVertex(const std::string& t, const std::string& n, const IInterface* p) :
24  base_class(t,n,p)
25 {
26 }
27 
28 // initialize
30 {
31  ATH_CHECK(m_extrapolator.retrieve());
32  return StatusCode::SUCCESS;
33 }
34 
35 std::unique_ptr<Trk::StraightLineSurface> Reco::TrackToVertex::GetBeamLine(
36  const InDet::BeamSpotData* beamSpotHandle) const {
37  // get the transform
38  Amg::Transform3D beamTransform = Amg::Transform3D(Amg::AngleAxis3D(beamSpotHandle->beamTilt(0),Amg::Vector3D(0.,1.,0.)));
39  beamTransform *= Amg::AngleAxis3D(beamSpotHandle->beamTilt(1),Amg::Vector3D(1.,0.,0.));
40  beamTransform.pretranslate(beamSpotHandle->beamPos());
41  // create the new beam line
42  return std::make_unique< Trk::StraightLineSurface >(beamTransform);
43 }
44 
45 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(
46  const EventContext& ctx, const xAOD::TrackParticle& tp) const {
47  return perigeeAtVertex(ctx, tp, Amg::Vector3D(tp.vx(), tp.vy(), tp.vz()));
48 }
49 
50 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(
51  const EventContext& ctx, const xAOD::TrackParticle& tp,
52  const Amg::Vector3D& gp) const {
53 
54  // preparation
55  Trk::PerigeeSurface persf(gp);
56  std::unique_ptr<Trk::Perigee> vertexPerigee;
57  // retrieve the Perigee from the track particle
58  const Trk::Perigee& trackparPerigee = tp.perigeeParameters();
59  if (trackparPerigee.associatedSurface() == persf) {
60  ATH_MSG_DEBUG("Perigee of TrackParticle is already expressed to given "
61  "vertex, a copy is returned.");
62  return std::unique_ptr<Trk::Perigee>(trackparPerigee.clone());
63  } else {
64  std::unique_ptr<Trk::TrackParameters> extrapResult =
65  m_extrapolator->extrapolateDirectly(ctx,trackparPerigee, persf);
66  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
67  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
68  }
69  }
70  if (!vertexPerigee)
72  "Extrapolation to Perigee failed, a NULL pointer is returned.");
73  return vertexPerigee;
74 }
75 
76 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(
77  const EventContext& ctx, const Trk::Track& track,
78  const Amg::Vector3D& gp) const {
79 
80  Trk::PerigeeSurface persf(gp);
81  std::unique_ptr<Trk::Perigee> vertexPerigee;
82  std::unique_ptr<Trk::TrackParameters> extrapResult =
83  !startAtOriginalPerigee(track)
84  ? m_extrapolator->extrapolateTrack(ctx,track, persf)
85  : m_extrapolator->extrapolate(ctx, *(track.perigeeParameters()), persf);
86  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
87  vertexPerigee.reset( static_cast<Trk::Perigee*>(extrapResult.release()));
88  }
89  if (!vertexPerigee) {
90  const Trk::Perigee* trackPerigee = track.perigeeParameters();
91  if (trackPerigee && trackPerigee->associatedSurface() == persf) {
92  ATH_MSG_DEBUG("Perigee of Track is already expressed to given vertex, a "
93  "copy is returned.");
94  vertexPerigee.reset(trackPerigee->clone());
95  } else{
97  "Extrapolation to Perigee failed, NULL pointer is returned.");
98  }
99  }
100  return (vertexPerigee);
101 }
102 
103 std::unique_ptr<Trk::Perigee>
105  const EventContext& ctx,
106  const Trk::Track& track,
107  const InDet::BeamSpotData* beamspotptr) const
108 {
109 
110  Amg::Vector3D beamspot(s_origin);
111  float tiltx = 0.0;
112  float tilty = 0.0;
113  if (beamspotptr) {
114  beamspot = Amg::Vector3D(beamspotptr->beamVtx().position());
115  tiltx = beamspotptr->beamTilt(0);
116  tilty = beamspotptr->beamTilt(1);
117  }
118  Amg::Translation3D amgtranslation(beamspot);
119  Amg::Transform3D pAmgTransf =
120  amgtranslation * Amg::RotationMatrix3D::Identity();
121  pAmgTransf *= Amg::AngleAxis3D(tilty, Amg::Vector3D(0., 1., 0.));
122  pAmgTransf *= Amg::AngleAxis3D(tiltx, Amg::Vector3D(1., 0., 0.));
123  // preparation
124  Trk::PerigeeSurface persf(pAmgTransf);
125 
126  std::unique_ptr<Trk::Perigee> vertexPerigee;
127  if(track.perigeeParameters() && std::abs(track.perigeeParameters()->position().z())>5000.){
128  ATH_MSG_DEBUG("Perigee well outside of tracking detector, skipping extrapolation");
129  }
130  else{
131  std::unique_ptr<Trk::TrackParameters> extrapResult =
132  !startAtOriginalPerigee(track)
133  ? m_extrapolator->extrapolateTrack(ctx,track, persf)
134  : m_extrapolator->extrapolate(ctx,*(track.perigeeParameters()), persf);
135  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
136  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
137  }
138  }
139  if (!vertexPerigee) {
140  // workaround.
141  // try again using the first track parameter set, since the current extrapolator will
142  // use "the closest" track parameter set which is not necessarily the most useful one to
143  // start the extrapolation with.
144  const DataVector<const Trk::TrackParameters> *track_parameter_list= track.trackParameters();
145  if (track_parameter_list) {
146  for(const Trk::TrackParameters *trk_params: *track_parameter_list) {
147  if (!trk_params || std::abs(trk_params->position().z())>5000.) {
148  continue;
149  }
150  std::unique_ptr<Trk::TrackParameters> extrapResult = m_extrapolator->extrapolate(ctx,*trk_params, persf);
151  if (extrapResult &&
152  extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
153  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
154  }
155  break;
156  }
157  }
158  }
159  if (!vertexPerigee) {
160  const Trk::Perigee* trackPerigee = track.perigeeParameters();
161  if (trackPerigee && trackPerigee->associatedSurface() == persf) {
162  ATH_MSG_DEBUG("Perigee of Track is already expressed to given vertex, a "
163  "copy is returned.");
164  vertexPerigee.reset(trackPerigee->clone());
165  } else {
167  "Extrapolation to Beamline Perigee failed, NULL pointer is returned.");
168  }
169  }
170  return (vertexPerigee);
171 }
172 
173 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(
174  const EventContext& ctx, const xAOD::TrackParticle& tp,
175  const InDet::BeamSpotData* beamspotptr) const {
176 
177  Amg::Vector3D beamspot(s_origin);
178  float tiltx = 0.0;
179  float tilty = 0.0;
180  if (beamspotptr) {
181  beamspot = Amg::Vector3D(beamspotptr->beamVtx().position());
182  tiltx = beamspotptr->beamTilt(0);
183  tilty = beamspotptr->beamTilt(1);
184  }
185  Amg::Transform3D amgTransf;
186  Amg::Translation3D amgtranslation(beamspot);
187  amgTransf = amgtranslation * Amg::RotationMatrix3D::Identity();
188  amgTransf *= Amg::AngleAxis3D(tilty, Amg::Vector3D(0.,1.,0.));
189  amgTransf *= Amg::AngleAxis3D(tiltx, Amg::Vector3D(1.,0.,0.));
190  // preparation
191  Trk::PerigeeSurface persf(amgTransf);
192  std::unique_ptr<Trk::TrackParameters> vertexPerigee;
193  // retrieve the Perigee from the track particle
194  const Trk::Perigee& trackparPerigee = tp.perigeeParameters();
195  if ( trackparPerigee.associatedSurface() == persf) {
196  ATH_MSG_DEBUG("Perigee of TrackParticle is already expressed to given vertex, a copy is returned.");
197  return std::unique_ptr<Trk::TrackParameters>(trackparPerigee.clone());
198  } else
199  vertexPerigee = m_extrapolator->extrapolateDirectly(ctx,trackparPerigee, persf);
200  if (!vertexPerigee){
201  ATH_MSG_DEBUG("Extrapolation to Beam Line failed, a NULL pointer is returned.");
202  }
203  return vertexPerigee;
204 }
205 
206 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(
207  const EventContext& ctx, const Trk::Track& trk,
208  const Trk::StraightLineSurface* beamline) const {
209 
210  return !startAtOriginalPerigee(trk)
211  ? m_extrapolator->extrapolateTrack(ctx, trk, *beamline)
212  : m_extrapolator->extrapolate(ctx,*(trk.perigeeParameters()), *beamline);
213 }
214 
215 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(
216  const EventContext& ctx, const Trk::TrackParameters& tpars,
217  const Trk::StraightLineSurface* beamline) const {
218  return m_extrapolator->extrapolate(ctx, tpars, *beamline);
219 }
RecVertex.h
StraightLineSurface.h
TrackParameters.h
PerigeeSurface.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::ParametersBase::surfaceType
constexpr virtual SurfaceType surfaceType() const override=0
Returns the Surface Type enum for the surface used to define the derived class.
ParticleTest.tp
tp
Definition: ParticleTest.py:25
InDet::BeamSpotData::beamVtx
const Trk::RecVertex & beamVtx() const noexcept
Definition: BeamSpotData.h:79
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::ParametersT::associatedSurface
virtual const S & associatedSurface() const override final
Access to the Surface method.
GeometryStatics.h
Reco::TrackToVertex::s_origin
static const Amg::Vector3D s_origin
static origin
Definition: TrackToVertex.h:120
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
Reco::TrackToVertex::initialize
virtual StatusCode initialize() override final
AlgTool initailize method.
Definition: TrackToVertex.cxx:29
Reco::TrackToVertex::trackAtBeamline
virtual std::unique_ptr< Trk::TrackParameters > trackAtBeamline(const EventContext &ctx, const xAOD::TrackParticle &tp, const InDet::BeamSpotData *) const override final
Interface method for use with TrackParticle and the beamline from the BeamSpotSvc - xAOD.
Definition: TrackToVertex.cxx:173
TrackToVertex.h
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::Vertex::position
const Amg::Vector3D & position() const
return position of vertex
Definition: Vertex.cxx:72
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Reco::TrackToVertex::perigeeAtBeamline
virtual std::unique_ptr< Trk::Perigee > perigeeAtBeamline(const EventContext &ctx, const Trk::Track &trk, const InDet::BeamSpotData *) const override final
Interface method for use with Track and the beamline.
Definition: TrackToVertex.cxx:104
InDet::BeamSpotData::beamPos
const Amg::Vector3D & beamPos() const noexcept
Definition: BeamSpotData.h:68
VxCandidate.h
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
Trk::SurfaceType::Perigee
@ Perigee
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
InDet::BeamSpotData
Definition: BeamSpotData.h:21
Reco::TrackToVertex::GetBeamLine
virtual std::unique_ptr< Trk::StraightLineSurface > GetBeamLine(const InDet::BeamSpotData *) const override final
Use this for MT Coding.
Definition: TrackToVertex.cxx:35
Reco::TrackToVertex::perigeeAtVertex
virtual std::unique_ptr< Trk::Perigee > perigeeAtVertex(const EventContext &ctx, const xAOD::TrackParticle &tp, const Amg::Vector3D &gp) const override final
Interface method for use with xAOD::Trackparticle and given vertex position.
Definition: TrackToVertex.cxx:50
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
Reco::TrackToVertex::TrackToVertex
TrackToVertex(const std::string &, const std::string &, const IInterface *)
AlgTool like constructor.
Definition: TrackToVertex.cxx:23
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
Trk::ParametersT::clone
virtual ParametersT< DIM, T, S > * clone() const override final
Virtual clone.
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
InDet::BeamSpotData::beamTilt
float beamTilt(int i) const noexcept
Returns the beam sigma for the i+3-th error matrix element (the 'tilt')
Definition: BeamSpotData.h:74