ATLAS Offline Software
TrackToVertex.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 #include "Particle/TrackParticle.h"
12 // Trk
17 #include "VxVertex/VxCandidate.h"
18 #include "VxVertex/RecVertex.h"
19 
20 
22 
23 // constructor
24 Reco::TrackToVertex::TrackToVertex(const std::string& t, const std::string& n, const IInterface* p) :
25  base_class(t,n,p)
26 {
27 }
28 
29 // initialize
31 {
32  // Get the GeometryBuilder AlgTool
33  ATH_CHECK(m_extrapolator.retrieve());
34  ATH_MSG_DEBUG( name() << " initialize() successful");
35  return StatusCode::SUCCESS;
36 }
37 
38 
39 // incident listener waiting for BeginEvent
40 std::unique_ptr<Trk::StraightLineSurface> Reco::TrackToVertex::GetBeamLine(const InDet::BeamSpotData* beamSpotHandle) const {
41  // get the transform
42  Amg::Transform3D beamTransform = Amg::Transform3D(Amg::AngleAxis3D(beamSpotHandle->beamTilt(0),Amg::Vector3D(0.,1.,0.)));
43  beamTransform *= Amg::AngleAxis3D(beamSpotHandle->beamTilt(1),Amg::Vector3D(1.,0.,0.));
44  beamTransform.pretranslate(beamSpotHandle->beamPos());
45  // create the new beam line
46  return std::make_unique< Trk::StraightLineSurface >(beamTransform);
47 }
48 
49 // finalize
51 {
52  ATH_MSG_DEBUG( name() << " finalize() successful");
53  return StatusCode::SUCCESS;
54 }
55 
56 
57 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(const EventContext& ctx, const Rec::TrackParticle& tp) const {
58 
59  // retrieve the reconstructed Vertex from the TrackParticle
60  const Trk::VxCandidate* vxCandidate = tp.reconstructedVertex();
61  if (vxCandidate!=nullptr) {
62  // create a global position from this
63  const Trk::RecVertex& reconVertex = vxCandidate->recVertex();
64  const Amg::Vector3D& vertexPosition = reconVertex.position();
65  Amg::Vector3D persfPosition(vertexPosition.x(), vertexPosition.y(), vertexPosition.z());
66  return(this->perigeeAtVertex(ctx, tp, persfPosition));
67  }
68  ATH_MSG_DEBUG("No reconstructed vertex found in TrackParticle, perigee will be expressed to (0.,0.,0.).");
69  return (perigeeAtVertex(ctx, tp,Trk::s_origin));
70 }
71 
72 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(const EventContext& ctx, const xAOD::TrackParticle& tp) const {
73  return perigeeAtVertex(ctx, tp, Amg::Vector3D(tp.vx(),tp.vy(),tp.vz()));
74 }
75 
76 
77 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(const EventContext& ctx, const xAOD::TrackParticle& tp, const Amg::Vector3D& gp) const {
78 
79  // preparation
80  Trk::PerigeeSurface persf(gp);
81  std::unique_ptr<Trk::Perigee> vertexPerigee;
82  // retrieve the Perigee from the track particle
83  const Trk::Perigee& trackparPerigee = tp.perigeeParameters();
84  if (trackparPerigee.associatedSurface() == persf) {
85  ATH_MSG_DEBUG("Perigee of TrackParticle is already expressed to given "
86  "vertex, a copy is returned.");
87  return std::unique_ptr<Trk::Perigee>(trackparPerigee.clone());
88  } else {
89  std::unique_ptr<Trk::TrackParameters> extrapResult =
90  m_extrapolator->extrapolateDirectly(ctx,trackparPerigee, persf);
91  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
92  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
93  }
94  }
95  if (!vertexPerigee)
97  "Extrapolation to Perigee failed, a NULL pointer is returned.");
98  return vertexPerigee;
99 }
100 
101 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(const EventContext& ctx, const Rec::TrackParticle& tp, const Amg::Vector3D& gp) const {
102 
103  // preparation
104  Trk::PerigeeSurface persf(gp);
105  std::unique_ptr<Trk::Perigee> vertexPerigee = nullptr;
106  // retrieve the Perigee from the track particle
107  const Trk::Perigee* trackparPerigee = tp.measuredPerigee();
108  if (trackparPerigee){
109  if ( trackparPerigee->associatedSurface() == persf)
110  {
111  ATH_MSG_DEBUG("Perigee of TrackParticle is already expressed to given vertex, a copy is returned.");
112  return std::unique_ptr<Trk::Perigee>(trackparPerigee->clone());
113  } else {
114  auto extrapResult =
115  m_extrapolator->extrapolateDirectly(ctx,*trackparPerigee, persf);
116  if (extrapResult &&
117  extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
118  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
119  }
120  }
121  } else {
123  "No Perigee found in TrackParticle, a NULL pointer is returned.");
124  return nullptr;
125  }
126  if (!vertexPerigee){
128  "Extrapolation to Perigee failed, a NULL pointer is returned.");
129  }
130  return vertexPerigee;
131 }
132 
133 
134 std::unique_ptr<Trk::Perigee> Reco::TrackToVertex::perigeeAtVertex(const EventContext& ctx, const Trk::Track& track, const Amg::Vector3D& gp) const {
135 
136  Trk::PerigeeSurface persf(gp);
137  std::unique_ptr<Trk::Perigee> vertexPerigee;
138  std::unique_ptr<Trk::TrackParameters> extrapResult =
139  !startAtOriginalPerigee(track)
140  ? m_extrapolator->extrapolateTrack(ctx,track, persf)
141  : m_extrapolator->extrapolate(ctx, *(track.perigeeParameters()), persf);
142  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
143  vertexPerigee.reset( static_cast<Trk::Perigee*>(extrapResult.release()));
144  }
145  if (!vertexPerigee) {
146  const Trk::Perigee* trackPerigee = track.perigeeParameters();
147  if (trackPerigee && trackPerigee->associatedSurface() == persf) {
148  ATH_MSG_DEBUG("Perigee of Track is already expressed to given vertex, a "
149  "copy is returned.");
150  vertexPerigee.reset(trackPerigee->clone());
151  } else{
153  "Extrapolation to Perigee failed, NULL pointer is returned.");
154  }
155  }
156  return (vertexPerigee);
157 }
158 
159 
160 std::unique_ptr<Trk::Perigee>
162  const EventContext& ctx,
163  const Trk::Track& track,
164  const InDet::BeamSpotData* beamspotptr) const
165 {
166 
167  Amg::Vector3D beamspot(s_origin);
168  float tiltx = 0.0;
169  float tilty = 0.0;
170  if (beamspotptr) {
171  beamspot = Amg::Vector3D(beamspotptr->beamVtx().position());
172  tiltx = beamspotptr->beamTilt(0);
173  tilty = beamspotptr->beamTilt(1);
174  }
175  Amg::Translation3D amgtranslation(beamspot);
176  Amg::Transform3D pAmgTransf =
177  amgtranslation * Amg::RotationMatrix3D::Identity();
178  pAmgTransf *= Amg::AngleAxis3D(tilty, Amg::Vector3D(0., 1., 0.));
179  pAmgTransf *= Amg::AngleAxis3D(tiltx, Amg::Vector3D(1., 0., 0.));
180  // preparation
181  Trk::PerigeeSurface persf(pAmgTransf);
182 
183  std::unique_ptr<Trk::Perigee> vertexPerigee;
184  std::unique_ptr<Trk::TrackParameters> extrapResult =
185  !startAtOriginalPerigee(track)
186  ? m_extrapolator->extrapolateTrack(ctx,track, persf)
187  : m_extrapolator->extrapolate(ctx,*(track.perigeeParameters()), persf);
188  if (extrapResult && extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
189  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
190  }
191  if (!vertexPerigee) {
192  // workaround.
193  // try again using the first track parameter set, since the current extrapolator will
194  // use "the closest" track parameterset which is not necessarily the mostuseful one to
195  // start the extrapolation with.
196  const DataVector<const Trk::TrackParameters> *track_parameter_list= track.trackParameters();
197  if (track_parameter_list) {
198  for(const Trk::TrackParameters *trk_params: *track_parameter_list) {
199  if (!trk_params) {
200  continue;
201  }
202  extrapResult = m_extrapolator->extrapolate(ctx,*trk_params, persf);
203  if (extrapResult &&
204  extrapResult->surfaceType() == Trk::SurfaceType::Perigee) {
205  vertexPerigee.reset(static_cast<Trk::Perigee*>(extrapResult.release()));
206  }
207  break;
208  }
209  }
210  }
211  if (!vertexPerigee) {
212  const Trk::Perigee* trackPerigee = track.perigeeParameters();
213  if (trackPerigee && trackPerigee->associatedSurface() == persf) {
214  ATH_MSG_DEBUG("Perigee of Track is already expressed to given vertex, a "
215  "copy is returned.");
216  vertexPerigee.reset(trackPerigee->clone());
217  } else {
219  "Extrapolation to Beamline Perigee failed, NULL pointer is returned.");
220  }
221  }
222  return (vertexPerigee);
223 }
224 
225 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(const EventContext&, const Rec::TrackParticle& /*tp*/) const
226 {
227  ATH_MSG_WARNING(" Method not implemented!! ");
228  return {};
229  //return m_extrapolator->extrapolate(tp, *m_beamLine);
230 }
231 
232 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(const EventContext& ctx, const xAOD::TrackParticle& tp,
233  const InDet::BeamSpotData* beamspotptr) const
234 {
235 
236  Amg::Vector3D beamspot(s_origin);
237  float tiltx = 0.0;
238  float tilty = 0.0;
239  if (beamspotptr) {
240  beamspot = Amg::Vector3D(beamspotptr->beamVtx().position());
241  tiltx = beamspotptr->beamTilt(0);
242  tilty = beamspotptr->beamTilt(1);
243  }
244  Amg::Transform3D amgTransf;
245  Amg::Translation3D amgtranslation(beamspot);
246  amgTransf = amgtranslation * Amg::RotationMatrix3D::Identity();
247  amgTransf *= Amg::AngleAxis3D(tilty, Amg::Vector3D(0.,1.,0.));
248  amgTransf *= Amg::AngleAxis3D(tiltx, Amg::Vector3D(1.,0.,0.));
249  // preparation
250  Trk::PerigeeSurface persf(amgTransf);
251  std::unique_ptr<Trk::TrackParameters> vertexPerigee;
252  // retrieve the Perigee from the track particle
253  const Trk::Perigee& trackparPerigee = tp.perigeeParameters();
254  if ( trackparPerigee.associatedSurface() == persf) {
255  ATH_MSG_DEBUG("Perigee of TrackParticle is already expressed to given vertex, a copy is returned.");
256  return std::unique_ptr<Trk::TrackParameters>(trackparPerigee.clone());
257  } else
258  vertexPerigee = m_extrapolator->extrapolateDirectly(ctx,trackparPerigee, persf);
259  if (!vertexPerigee){
260  ATH_MSG_DEBUG("Extrapolation to Beam Line failed, a NULL pointer is returned.");
261  }
262  return vertexPerigee;
263 
264 }
265 
266 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(const EventContext& ctx, const Trk::Track& trk,
267  const Trk::StraightLineSurface* beamline) const
268 {
269  return !startAtOriginalPerigee(trk)
270  ? m_extrapolator->extrapolateTrack(ctx, trk, *beamline)
271  : m_extrapolator->extrapolate(ctx,*(trk.perigeeParameters()), *beamline);
272 }
273 
274 std::unique_ptr<Trk::TrackParameters> Reco::TrackToVertex::trackAtBeamline(const EventContext& ctx, const Trk::TrackParameters& tpars,
275  const Trk::StraightLineSurface* beamline) const
276 {
277  return m_extrapolator->extrapolate(ctx, tpars, *beamline);
278 }
279 
280 
RecVertex.h
Trk::VxCandidate::recVertex
const Trk::RecVertex & recVertex(void) const
Returns a reference to reconstructed vertex.
Definition: VxCandidate.h:132
StraightLineSurface.h
TrackParameters.h
TrackParticle.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
Reco::TrackToVertex::finalize
virtual StatusCode finalize() override final
AlgTool finalize method.
Definition: TrackToVertex.cxx:50
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::RecVertex
Trk::RecVertex inherits from Trk::Vertex.
Definition: RecVertex.h:44
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:142
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Reco::TrackToVertex::initialize
virtual StatusCode initialize() override final
AlgTool initailize method.
Definition: TrackToVertex.cxx:30
TrackToVertex.h
Reco::TrackToVertex::trackAtBeamline
virtual std::unique_ptr< Trk::TrackParameters > trackAtBeamline(const EventContext &ctx, const Rec::TrackParticle &tp) const override final
Interface method for use with TrackParticle and the beamline from the BeamSpotSvc - AOD.
Definition: TrackToVertex.cxx:225
beamspotman.n
n
Definition: beamspotman.py:731
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 from the BeamSpotSvc - ESD.
Definition: TrackToVertex.cxx:161
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Reco::TrackToVertex::perigeeAtVertex
virtual std::unique_ptr< Trk::Perigee > perigeeAtVertex(const EventContext &ctx, const Rec::TrackParticle &tp, const Amg::Vector3D &gp) const override final
Interface method for use with TrackParticle and given vertex position.
Definition: TrackToVertex.cxx:101
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Rec::TrackParticle
Definition: Reconstruction/Particle/Particle/TrackParticle.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:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::VxCandidate
Definition: VxCandidate.h:27
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:24
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
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