ATLAS Offline Software
ConversionFinderUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /***************************************************************************
6  ConversionFinderUtils.cxx - Description
7  -------------------
8  begin : 01-01-2008
9  authors : Tatjana Lenz, Thomas Koffas
10  email : tatjana.lenz@cern.ch, Thomas.Koffas@cern.ch
11  changes :
12 ***************************************************************************/
15 //Prep raw data
19 #include "TrkTrack/Track.h"
21 #include <cmath>
22 
23 using HepGeom::Point3D;
24 
25 namespace InDet {
26 
27  static const InterfaceID IID_IConversionFinderUtils("InDet::ConversionFinderUtils", 1, 0);
28 
30  const std::string& name,
31  const IInterface* parent)
33  {
34  declareInterface<ConversionFinderUtils>(this);
35  }
36 
38 
40  {
41  return IID_IConversionFinderUtils;
42  }
43 
45  return StatusCode::SUCCESS;
46  }
47 
49  return StatusCode::SUCCESS;
50  }
51 
55  double
57  const Trk::TrackParameters* per2)
58  {
59 
60  const Amg::Vector3D& mom_pos = per1->momentum();
61  const Amg::Vector3D& mom_neg = per2->momentum();
62  double momFraction = mom_pos.mag()/(mom_pos.mag() + mom_neg.mag());
63  return momFraction;
64  }
65 
69  double
71  const Trk::Track* trk_neg) const
72  {
73 
74  //position of the first measurement on the positive track
75  const Trk::MeasurementBase* first_pos_meas = trk_pos->measurementsOnTrack()->front();
76  Amg::Vector3D trk_hit_pos = first_pos_meas->globalPosition();
77 
78  //check if really the first measurement
79  for (const Trk::MeasurementBase* m : *trk_pos->measurementsOnTrack())
80  if(trk_hit_pos.mag() > m->globalPosition().mag()) first_pos_meas = m;
81 
82  trk_hit_pos = first_pos_meas->globalPosition();
83 
84  //position of the first hit--->track2
85  const Trk::MeasurementBase* first_neg_meas = trk_neg->measurementsOnTrack()->front();
86  Amg::Vector3D trk_hit_neg = first_neg_meas->globalPosition();
87 
88  //check if really the first measurement
89  for (const Trk::MeasurementBase* m : *trk_neg->measurementsOnTrack())
90  if(trk_hit_neg.mag() > m->globalPosition().mag()) first_neg_meas = m;
91 
92  trk_hit_neg = first_neg_meas->globalPosition();
93  double distance = 1000.;
94 
95  //check if measurements are on the same surface
96  if (first_pos_meas->associatedSurface() == first_neg_meas->associatedSurface()) distance =
97  std::sqrt(std::pow(trk_hit_pos[0] - trk_hit_neg[0],2.) + std::pow(trk_hit_pos[1] - trk_hit_neg[1],2.) +
98  std::pow(trk_hit_pos[2] - trk_hit_neg[2],2.));
99 
100 
101  //if not choose the track with the fist measurement closest to 000 and calculate the distance
102  //of the closest approach of another track to this measurement
103  else {
104 
105  //define reference point and track parameter (--> perigees) of the second track
106  Amg::Vector3D ref_point;
107  const Trk::Perigee* perigee;
108 
109  if (first_pos_meas->globalPosition().mag() < first_neg_meas->globalPosition().mag()) {
110  ref_point = first_pos_meas->globalPosition();
111  perigee = trk_neg->perigeeParameters();
112  } else {
113  ref_point = first_neg_meas->globalPosition();
114  perigee = trk_pos->perigeeParameters();
115  }
116 
117  // when the helix can be approximated as a straight line, when the
118  // distance of closest approach can be calculated as distance^2 = [momentum
119  // x (ref_point-position)]^2/momentum^2
120  Amg::Vector3D momentum = perigee->momentum();
121  Amg::Vector3D position = perigee->position();
122  double p = momentum.mag();
123  Amg::Vector3D delta = position - ref_point;
124  distance = std::sqrt(std::pow(delta.mag(),2.) - std::pow((delta.adjoint()*momentum)[0]/p,2.));
125  }
126 
127  ATH_MSG_DEBUG("Distance between two tracks = "<<distance);
128  return distance;
129  } // end of distBetweenTracks method
130 
131  /* add recalculated perigees to the track*/
132  std::unique_ptr<Trk::Track>
134  const Trk::Perigee* mp)
135  {
136 
137  // fitQuality from track
138  auto fq = track->fitQuality()->uniqueClone();
139  if(!fq) return nullptr;
140 
141  // output datavector of TSOS
142  auto ntsos = std::make_unique<Trk::TrackStates>();
143  const Trk::TrackStates* tsos = track->trackStateOnSurfaces();
144  if(!tsos) {return nullptr;}
145  Trk::TrackStates::const_iterator its,itse = tsos->end();
146  for(its=tsos->begin();its!=itse;++its) {
147 
148  std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
149  typePattern.set(Trk::TrackStateOnSurface::Perigee);
150  const Trk::TrackStateOnSurface* per_tsos =
151  ((*its)->type(Trk::TrackStateOnSurface::Perigee))
152  ? new Trk::TrackStateOnSurface(nullptr, mp->uniqueClone(), nullptr, typePattern)
153  : (*its)->clone();
154  ntsos->push_back(per_tsos);
155  }
156 
157  //Construct the new track
159  return std::make_unique<Trk::Track>(info, std::move(ntsos), std::move(fq));
160  }
161 
162  xAOD::Vertex*
164  Amg::Vector3D guessVertex)
165  {
166  Amg::Vector3D correctVertex(initVxCandidate->position().x()+guessVertex.x(),
167  initVxCandidate->position().y()+guessVertex.y(),
168  initVxCandidate->position().z()+guessVertex.z());
169 
170  Amg::Vector3D globalVertexPosition(correctVertex.x(),correctVertex.y(),correctVertex.z());
171 
172  std::vector<Trk::VxTrackAtVertex> tmpVTAV;
173 
174  const std::vector<Trk::VxTrackAtVertex> &trkAtVtx = initVxCandidate->vxTrackAtVertex();
175  for (const auto& vtxTrack : trkAtVtx) {
176  const Trk::TrackParameters* vtxPer = vtxTrack.perigeeAtVertex();
177  const AmgVector(5)& iv = vtxPer->parameters();
178  AmgSymMatrix(5) em(*(vtxPer->covariance()));
179  Trk::PerigeeSurface surface (globalVertexPosition);
180 
181  Trk::TrackParameters* tmpMeasPer =
182  surface
184  0., 0., iv[2], iv[3], iv[4], std::move(em))
185  .release();
186 
187  Trk::VxTrackAtVertex trkV(vtxTrack.trackQuality().chiSquared(),
188  tmpMeasPer);
189  tmpVTAV.push_back(trkV);
190  }//end of loop over VxTracksAtVertex
191 
192  if(tmpVTAV.size()!=2) return nullptr;
193 
194  //Create the xAOD::Vertex and set the position and VxTrackAtVertex properly
195  xAOD::Vertex *vx = new xAOD::Vertex(*initVxCandidate);
196  vx->setPosition(correctVertex);
197  vx->vxTrackAtVertex().clear();
198  for (const auto& vtxTrack : tmpVTAV) {
199  vx->vxTrackAtVertex().push_back(vtxTrack);
200  }
201 
202  return vx;
203  }//end of correct vxCandidate method
204 
205 } // end InDet
grepfile.info
info
Definition: grepfile.py:38
Trk::TrackInfo
Contains information about the 'fitter' of this track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:32
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
xAOD::Vertex_v1::setPosition
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Trk::VxTrackAtVertex
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
Definition: VxTrackAtVertex.h:77
MeasurementBase.h
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
InDet::ConversionFinderUtils::initialize
virtual StatusCode initialize() override
Definition: ConversionFinderUtils.cxx:44
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::TrackStateOnSurface::clone
virtual TrackStateOnSurface * clone() const
Pseudo-constructor: needed to avoid excessive RTTI.
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
ConversionFinderUtils.h
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
Trk::PerigeeSurface::createUniqueParameters
std::unique_ptr< ParametersT< DIM, T, PerigeeSurface > > createUniqueParameters(double l1, double l2, double phi, double theta, double qop, std::optional< AmgSymMatrix(DIM)> cov=std::nullopt) const
Use the Surface as a ParametersBase constructor, from local parameters.
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
InDet::ConversionFinderUtils::ConversionFinderUtils
ConversionFinderUtils(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ConversionFinderUtils.cxx:29
InDet::ConversionFinderUtils::~ConversionFinderUtils
virtual ~ConversionFinderUtils()
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:52
Trk::Charged
Definition: Charged.h:27
Track.h
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
InDet::ConversionFinderUtils::interfaceID
static const InterfaceID & interfaceID()
Definition: ConversionFinderUtils.cxx:39
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
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VxTrackAtVertex.h
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector< const Trk::TrackStateOnSurface >
TRT_DriftCircle.h
Trk::MeasurementBase
Definition: MeasurementBase.h:58
InDet::ConversionFinderUtils::correctVxCandidate
static xAOD::Vertex * correctVxCandidate(xAOD::Vertex *, Amg::Vector3D)
Correct VxCandidate with respect to a user defined vertex.
Definition: ConversionFinderUtils.cxx:163
InDet::ConversionFinderUtils::finalize
virtual StatusCode finalize() override
Definition: ConversionFinderUtils.cxx:48
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::MeasurementBase::associatedSurface
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
InDet::ConversionFinderUtils::momFraction
static double momFraction(const Trk::TrackParameters *per1, const Trk::TrackParameters *per2)
helper functions
Definition: ConversionFinderUtils.cxx:56
RIO_OnTrack.h
SiCluster.h
Trk::MeasurementBase::globalPosition
virtual const Amg::Vector3D & globalPosition() const =0
Interface method to get the global Position.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::Track::measurementsOnTrack
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:178
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
InDet::ConversionFinderUtils::distBetweenTracks
double distBetweenTracks(const Trk::Track *trk_pos, const Trk::Track *trk_neg) const
Approximate distance of minimum approach between tracks in pair.
Definition: ConversionFinderUtils.cxx:70
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::Vertex_v1::vxTrackAtVertex
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
Definition: Vertex_v1.cxx:181
AthAlgTool
Definition: AthAlgTool.h:26
InDet::ConversionFinderUtils::addNewPerigeeToTrack
static std::unique_ptr< Trk::Track > addNewPerigeeToTrack(const Trk::Track *track, const Trk::Perigee *mp)
Add new perigee to track.
Definition: ConversionFinderUtils.cxx:133
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.