ATLAS Offline Software
Loading...
Searching...
No Matches
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
16namespace Trk {
17
31
32template<class T>
34{
35public:
37 ComparisonFunction() = default;
43
46 : m_point(sp)
47 , m_line{}
48 , m_radius{ 0 }
50 {
51 m_line.setZero();
52 }
53
56 : m_point(sp)
57 , m_line(dir)
58 , m_radius{ 0. }
60 {}
61
63 ComparisonFunction(double cradius)
64 : m_point{}
65 , m_line{}
66 , m_radius{ std::abs(cradius) }
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
113};
114
115} // end of namespace
116
117#endif
118
static Double_t sp
bool operator()(const T *one, const T *two) const
ComparisonFunction(const Amg::Vector3D &sp)
Constructor for pointlike Search.
ComparisonFunction(double cradius)
Search wrt to distance wrt to radius.
ComparisonFunction()=default
Default.
ComparisonFunction(const ComparisonFunction &cpf)=default
ComparisonFunction(const Amg::Vector3D &sp, const Amg::Vector3D &dir)
Constructor with point and line, search with direction.
bool operator()(const std::unique_ptr< T > &one, const std::unique_ptr< T > &two) const
ComparisonFunction & operator=(ComparisonFunction &&cpf)=default
ComparisonFunction & operator=(const ComparisonFunction &cpf)=default
ComparisonFunction(ComparisonFunction &&cpf)=default
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
STL namespace.