ATLAS Offline Software
MeasurementBaseComparisonFunction.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // MeasurementBaseComparisonFunction.h
7 // Header file for struct MeasurementBaseComparisonFunction
9 // (c) ATLAS Detector software
11 // Wolfgang.Liebig@cern.ch / Andreas.Salzburger@cern.ch
13 
14 #ifndef TRKNIRVANA_MEASUREMENTBASECOMPARISONFUNCTION_H
15 #define TRKNIRVANA_MEASUREMENTBASECOMPARISONFUNCTION_H
16 
17 // Trk
22 // extra-maths for cylinder intersections
26 // STL
27 #include <algorithm>
28 #include <stdexcept>
29 
30 // Amg
33 
34 namespace Trk {
35 
40 {
41 public:
46  const Amg::Vector3D& dir)
47  : m_point(sp)
48  , m_direction(dir.unit())
49  {}
50 
51  /*
52  * Default methods
53  */
55  const MeasurementBaseComparisonFunction& MCF) = default;
57  MeasurementBaseComparisonFunction& MCF) = default;
59  default;
61  MeasurementBaseComparisonFunction&& MCF) = default;
62 
66  const Trk::MeasurementBase* two) const
67  {
68 
69  // --- flexible sorting along a predicted direction
70  double path1 = 0;
71  const Trk::Surface& sf1 = one->associatedSurface();
72  const Trk::SurfaceType surfType1 = sf1.type();
73  switch (surfType1) {
75  const Trk::PlaneSurface& opsf =
76  static_cast<const Trk::PlaneSurface&>(sf1);
77  path1 = this->pathIntersectWithPlane(opsf);
78  } break;
80  const Trk::StraightLineSurface& ossf =
81  static_cast<const Trk::StraightLineSurface&>(sf1);
82  path1 = this->pathIntersectWithLine(ossf);
83  } break;
85  const Trk::DiscSurface& odsf =
86  static_cast<const Trk::DiscSurface&>(sf1);
87  path1 = this->pathIntersectWithDisc(odsf);
88  } break;
90  const Trk::CylinderSurface& ocsf =
91  static_cast<const Trk::CylinderSurface&>(sf1);
92  path1 = this->pathIntersectWithCylinder(ocsf, one->globalPosition());
93  } break;
95  const Trk::PerigeeSurface& ogsf =
96  static_cast<const Trk::PerigeeSurface&>(sf1);
97  path1 = this->pathIntersectWithLine(ogsf);
98  } break;
99  default: {
100  throw std::runtime_error(
101  "MeasurementBaseComparisonFunction: surface type error for Sf1!");
102  }
103  }
104 
105  // --- identify the 2nd surface type and get intersection path for surface 1
106  double path2 = 0;
107  const Trk::Surface& sf2 = two->associatedSurface();
108  const Trk::SurfaceType surfType2 = sf2.type();
109  switch (surfType2) {
111  const Trk::PlaneSurface& tpsf =
112  static_cast<const Trk::PlaneSurface&>(sf2);
113  path2 = this->pathIntersectWithPlane(tpsf);
114  } break;
115  case Trk::SurfaceType::Line: {
116  const Trk::StraightLineSurface& tssf =
117  static_cast<const Trk::StraightLineSurface&>(sf2);
118  path2 = this->pathIntersectWithLine(tssf);
119  } break;
120  case Trk::SurfaceType::Disc: {
121  const Trk::DiscSurface& tdsf =
122  static_cast<const Trk::DiscSurface&>(sf2);
123  path2 = this->pathIntersectWithDisc(tdsf);
124  } break;
126  const Trk::CylinderSurface& tcsf =
127  static_cast<const Trk::CylinderSurface&>(sf2);
128  path2 = this->pathIntersectWithCylinder(tcsf, two->globalPosition());
129  } break;
131  const Trk::PerigeeSurface& tgsf =
132  static_cast<const Trk::PerigeeSurface&>(sf2);
133  path2 = this->pathIntersectWithLine(tgsf);
134  } break;
135  default: {
136  throw std::runtime_error(
137  "MeasurementBaseComparisonFunction: surface type error for Sf2!");
138  }
139  }
140  return path1 < path2;
141  }
142 
143 private:
146 
147  double pathIntersectWithPlane(const Trk::PlaneSurface& psf) const
148  {
149  double denom = m_direction.dot(psf.normal());
150  return (denom) ? psf.normal().dot(psf.center() - m_point) / (denom) : denom;
151  }
152 
154  {
155  const Amg::Vector3D& dirWire = lsf.lineDirection().normalized();
156  Amg::Vector3D trackToWire(lsf.center() - m_point);
157  double parallelity = m_direction.dot(dirWire);
158  double denom = 1 - parallelity * parallelity;
159  return (fabs(denom) > 10e-7) ? (trackToWire.dot(m_direction) -
160  trackToWire.dot(dirWire) * parallelity) /
161  denom
162  : 0.;
163  }
164 
165  double pathIntersectWithLine(const Trk::PerigeeSurface& pgsf) const
166  {
167  Amg::Vector3D trackToWire(pgsf.center() - m_point);
168  double parallelity = m_direction.dot(Trk::s_zAxis);
169  double denom = 1 - parallelity * parallelity;
170  return (fabs(denom) > 10e-7)
171  ? (trackToWire.dot(m_direction) -
172  trackToWire.dot(Trk::s_zAxis) * parallelity) /
173  denom
174  : 0.;
175  }
176 
177  double pathIntersectWithDisc(const Trk::DiscSurface& dsf) const
178  {
179  double denom = m_direction.dot(dsf.normal());
180  return (denom) ? dsf.normal().dot(dsf.center() - m_point) / (denom) : denom;
181  }
182 
184  const Amg::Vector3D& globalHit) const
185  { // --- code from TrkExSlPropagator/LineCylinderIntersection.cxx
186 
187  // get the rotation by reference
188  const Amg::Transform3D& locTrans = csf.transform();
189  // take two points of line and calculate them to the 3D frame of the
190  // cylinder
191  Amg::Vector3D point1(locTrans.inverse() * m_point);
192  Amg::Vector3D point2raw = m_point + m_direction;
193  Amg::Vector3D point2(locTrans.inverse() * point2raw); // do it in two steps
194 
195  // new direction in 3D frame of cylinder
196  Amg::Vector3D direc((point2 - point1).unit());
197 
198  if (!direc.x()) {
199  return 0.;
200  } else {
201  // get line and circle constants
202  double k = (direc.y()) / (direc.x());
203  double d = (point2.x() * point1.y() - point1.x() * point2.y()) /
204  (point2.x() - point1.x());
205  double R = csf.bounds().r();
206  double first = 0.;
207  double second = 0.;
208 
209  // and solve the quadratic equation Trk::RealQuadraticEquation
210  // pquad(1+k*k, 2*k*d, d*d-R*R);
211  double a = 1 + k * k;
212  double p = 2 * k * d;
213  double q = d * d - R * R;
214  double discriminant = p * p - 4 * a * q;
215  if (discriminant < 0) {
216  return 0.;
217  } else {
218  // solutions = (discriminant==0) ? one : two;
219  double x0 =
220  -0.5 * (p + (p > 0 ? sqrt(discriminant) : -sqrt(discriminant)));
221  first = x0 / a;
222  second = q / x0;
223  }
224  double t1 = (first - point1.x()) / direc.x();
225  double t2 = (second - point1.x()) / direc.x();
226  // the solutions in the 3D frame of the cylinder
227  Amg::Vector3D dist1raw(point1 + t1 * direc - globalHit);
228  Amg::Vector3D dist2raw(point1 + t2 * direc - globalHit);
229  // return the solution which is closer to Meas'Base's global coordinates
230  if (dist1raw.mag() < dist2raw.mag()) {
231  return t1;
232  } else {
233  return t2;
234  }
235  }
236  }
237 };
238 } // end of namespace
239 
240 #endif // TRKNIRVANA_MEASUREMENTBASECOMPARISONFUNCTION_H
241 
Trk::MeasurementBaseComparisonFunction::m_point
Amg::Vector3D m_point
Definition: MeasurementBaseComparisonFunction.h:144
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
Trk::MeasurementBaseComparisonFunction::pathIntersectWithPlane
double pathIntersectWithPlane(const Trk::PlaneSurface &psf) const
Definition: MeasurementBaseComparisonFunction.h:147
Trk::MeasurementBaseComparisonFunction::operator=
MeasurementBaseComparisonFunction & operator=(MeasurementBaseComparisonFunction &&MCF)=default
StraightLineSurface.h
MeasurementBase.h
PerigeeSurface.h
Trk::MeasurementBaseComparisonFunction::~MeasurementBaseComparisonFunction
~MeasurementBaseComparisonFunction()=default
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::MeasurementBaseComparisonFunction::MeasurementBaseComparisonFunction
MeasurementBaseComparisonFunction(MeasurementBaseComparisonFunction &&MCF)=default
hist_file_dump.d
d
Definition: hist_file_dump.py:137
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
Trk::MeasurementBaseComparisonFunction::MeasurementBaseComparisonFunction
MeasurementBaseComparisonFunction()=delete
Trk::one
@ one
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:22
Trk::MeasurementBaseComparisonFunction::pathIntersectWithDisc
double pathIntersectWithDisc(const Trk::DiscSurface &dsf) const
Definition: MeasurementBaseComparisonFunction.h:177
Trk::CylinderSurface::bounds
virtual const CylinderBounds & bounds() const override final
This method returns the CylinderBounds by reference (NoBounds is not possible for cylinder)
Trk::SurfaceType
SurfaceType
Definition: SurfaceTypes.h:17
Trk::MeasurementBaseComparisonFunction::m_direction
Amg::Vector3D m_direction
Definition: MeasurementBaseComparisonFunction.h:145
Trk::DiscSurface
Definition: DiscSurface.h:54
Trk::Surface::center
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Trk::MeasurementBaseComparisonFunction::pathIntersectWithLine
double pathIntersectWithLine(const Trk::StraightLineSurface &lsf) const
Definition: MeasurementBaseComparisonFunction.h:153
GeoPrimitives.h
SurfaceBounds.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Trk::two
@ two
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:23
Trk::CylinderSurface
Definition: CylinderSurface.h:55
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
CylinderSurface.h
Trk::Surface::normal
virtual const Amg::Vector3D & normal() const
Returns the normal vector of the Surface (i.e.
compute_lumi.denom
denom
Definition: compute_lumi.py:76
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::MeasurementBaseComparisonFunction::MeasurementBaseComparisonFunction
MeasurementBaseComparisonFunction(const Amg::Vector3D &sp, const Amg::Vector3D &dir)
Full relation definition using a straight line propagation.
Definition: MeasurementBaseComparisonFunction.h:45
Trk::MeasurementBase
Definition: MeasurementBase.h:58
EventPrimitives.h
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SurfaceType::Perigee
@ Perigee
TauJetParameters::discriminant
@ discriminant
Definition: TauJetParameters.h:166
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::MeasurementBaseComparisonFunction::pathIntersectWithLine
double pathIntersectWithLine(const Trk::PerigeeSurface &pgsf) const
Definition: MeasurementBaseComparisonFunction.h:165
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
Trk::MeasurementBaseComparisonFunction::MeasurementBaseComparisonFunction
MeasurementBaseComparisonFunction(const MeasurementBaseComparisonFunction &MCF)=default
a
TList * a
Definition: liststreamerinfos.cxx:10
Trk::PlaneSurface
Definition: PlaneSurface.h:64
PlaneSurface.h
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
DeMoScan.first
bool first
Definition: DeMoScan.py:536
Trk::SurfaceType::Disc
@ Disc
Trk::StraightLineSurface::lineDirection
const Amg::Vector3D & lineDirection() const
Special method for StraightLineSurface - provides the Line direction from cache: speedup.
Trk::SurfaceType::Cylinder
@ Cylinder
DiscSurface.h
extractSporadic.q
list q
Definition: extractSporadic.py:98
Trk::MeasurementBaseComparisonFunction::operator()
bool operator()(const Trk::MeasurementBase *one, const Trk::MeasurementBase *two) const
The comparison function defining in what case a Measurement is 'smaller' than a second one.
Definition: MeasurementBaseComparisonFunction.h:65
Trk::SurfaceType::Plane
@ Plane
Trk::MeasurementBaseComparisonFunction::operator=
MeasurementBaseComparisonFunction & operator=(MeasurementBaseComparisonFunction &MCF)=default
Trk::MeasurementBaseComparisonFunction
Class implementing a comparison function for sorting MeasurementBase objects.
Definition: MeasurementBaseComparisonFunction.h:40
Trk::SurfaceType::Line
@ Line
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
Trk::Surface::type
constexpr virtual SurfaceType type() const =0
Returns the Surface type to avoid dynamic casts.
Trk::MeasurementBaseComparisonFunction::pathIntersectWithCylinder
double pathIntersectWithCylinder(const Trk::CylinderSurface &csf, const Amg::Vector3D &globalHit) const
Definition: MeasurementBaseComparisonFunction.h:183
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
fitman.k
k
Definition: fitman.py:528
Trk::CylinderBounds::r
virtual double r() const override final
This method returns the radius.