ATLAS Offline Software
ComparisonFunction.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 // ComparisonFunction, (c) ATLAS Detector software
8 
9 #ifndef TRKEVENTUTILS_COMPARISONFUNCTION_H
10 #define TRKEVENTUTILS_COMPARISONFUNCTION_H
11 
13 #include <cmath>
14 #include <cstdint>
15 
16 namespace Trk {
17 
32 template<class T>
34 {
35 public:
37  ComparisonFunction() = default;
38  ComparisonFunction(const ComparisonFunction& cpf) = default;
42  ~ComparisonFunction() = default;
43 
46  : m_point(sp)
47  , m_line{}
48  , m_radius{ 0 }
49  , m_hasPointAndLine{ 1 }
50  {
51  m_line.setZero();
52  }
53 
56  : m_point(sp)
57  , m_line(dir)
58  , m_radius{ 0. }
59  , m_hasPointAndLine{ 2 }
60  {}
61 
63  ComparisonFunction(double cradius)
64  : m_point{}
65  , m_line{}
66  , m_radius{ std::abs(cradius) }
67  , m_hasPointAndLine{ 0 }
68  {
69  m_point.setZero();
70  m_line.setZero();
71  }
72 
73  bool operator()(const T* one, const T* two) const
74  {
75  if (m_hasPointAndLine == 0) {
76  return (fabs(one->position().perp() - m_radius) <
77  fabs(two->position().perp() - m_radius));
78  }
79  if (m_hasPointAndLine == 1) {
80  return ((one->position() - m_point).mag() <
81  (two->position() - m_point).mag());
82  }
83  Amg::Vector3D distPosOne((one->position()) - m_point);
84  double lmag2 = m_line.mag();
85  lmag2 *= lmag2;
86  double dp1_mag2 = distPosOne.mag();
87  dp1_mag2 *= dp1_mag2;
88  double pl1_2 = m_line.dot(distPosOne);
89  pl1_2 *= pl1_2;
90  double distOne = (lmag2 * dp1_mag2 - pl1_2) / dp1_mag2;
91 
92  Amg::Vector3D distPosTwo((two->position()) - m_point);
93  double dp2_mag2 = distPosTwo.mag();
94  dp1_mag2 *= dp1_mag2;
95  double pl2_2 = m_line.dot(distPosTwo);
96  pl1_2 *= pl1_2;
97  double distTwo = (lmag2 * dp2_mag2 - pl2_2) / dp2_mag2;
98 
99  return (fabs(distOne) < fabs(distTwo));
100  }
101 
102  bool operator()(const std::unique_ptr<T>& one,
103  const std::unique_ptr<T>& two) const {
104  return this->operator()(one.get(), two.get());
105  }
106 
107  private:
110  double m_radius = 0.;
111  // 0 no line no point, 1 only point , 2 has both
112  int8_t m_hasPointAndLine = 0;
113 };
114 
115 } // end of namespace
116 
117 #endif
118 
Trk::ComparisonFunction::~ComparisonFunction
~ComparisonFunction()=default
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction()=default
Default.
Trk::ComparisonFunction::operator=
ComparisonFunction & operator=(ComparisonFunction &&cpf)=default
Trk::ComparisonFunction::m_line
Amg::Vector3D m_line
Definition: ComparisonFunction.h:109
Trk::ComparisonFunction::operator()
bool operator()(const T *one, const T *two) const
Definition: ComparisonFunction.h:73
Trk::ComparisonFunction::m_hasPointAndLine
int8_t m_hasPointAndLine
Definition: ComparisonFunction.h:112
Trk::one
@ one
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:22
Trk::ComparisonFunction::m_point
Amg::Vector3D m_point
Definition: ComparisonFunction.h:108
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction(const ComparisonFunction &cpf)=default
GeoPrimitives.h
Trk::two
@ two
Definition: TrkDetDescr/TrkSurfaces/TrkSurfaces/RealQuadraticEquation.h:23
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction(const Amg::Vector3D &sp)
Constructor for pointlike Search.
Definition: ComparisonFunction.h:45
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction(double cradius)
Search wrt to distance wrt to radius.
Definition: ComparisonFunction.h:63
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction(const Amg::Vector3D &sp, const Amg::Vector3D &dir)
Constructor with point and line, search with direction.
Definition: ComparisonFunction.h:55
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::ComparisonFunction::operator=
ComparisonFunction & operator=(const ComparisonFunction &cpf)=default
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::ComparisonFunction::m_radius
double m_radius
Definition: ComparisonFunction.h:110
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::ComparisonFunction::operator()
bool operator()(const std::unique_ptr< T > &one, const std::unique_ptr< T > &two) const
Definition: ComparisonFunction.h:102
Trk::ComparisonFunction::ComparisonFunction
ComparisonFunction(ComparisonFunction &&cpf)=default
Trk::ComparisonFunction
Definition: ComparisonFunction.h:34