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