CMS 3D CMS Logo

CircleEq.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexingPixelTripletsCircleEq_H
2 #define RecoPixelVertexingPixelTripletsCircleEq_H
3 
21 #include <cmath>
22 
23 template <typename T>
24 class CircleEq {
25 public:
26  CircleEq() {}
27 
28  constexpr CircleEq(T x1, T y1, T x2, T y2, T x3, T y3) { compute(x1, y1, x2, y2, x3, y3); }
29 
30  constexpr void compute(T x1, T y1, T x2, T y2, T x3, T y3);
31 
32  // dca to origin divided by curvature
33  constexpr T dca0() const {
34  auto x = m_c * m_xp + m_alpha;
35  auto y = m_c * m_yp + m_beta;
36  return std::sqrt(x * x + y * y) - T(1);
37  }
38 
39  // dca to given point (divided by curvature)
40  constexpr T dca(T x, T y) const {
41  x = m_c * (m_xp - x) + m_alpha;
42  y = m_c * (m_yp - y) + m_beta;
43  return std::sqrt(x * x + y * y) - T(1);
44  }
45 
46  // curvature
47  constexpr auto curvature() const { return m_c; }
48 
49  // alpha and beta
50  constexpr std::pair<T, T> cosdir() const { return std::make_pair(m_alpha, m_beta); }
51 
52  // alpha and beta af given point
53  constexpr std::pair<T, T> cosdir(T x, T y) const {
54  return std::make_pair(m_alpha - m_c * (x - m_xp), m_beta - m_c * (y - m_yp));
55  }
56 
57  // center
58  constexpr std::pair<T, T> center() const { return std::make_pair(m_xp + m_alpha / m_c, m_yp + m_beta / m_c); }
59 
60  constexpr auto radius() const { return T(1) / m_c; }
61 
62  T m_xp = 0;
63  T m_yp = 0;
64  T m_c = 0;
65  T m_alpha = 0;
66  T m_beta = 0;
67 };
68 
69 template <typename T>
70 constexpr void CircleEq<T>::compute(T x1, T y1, T x2, T y2, T x3, T y3) {
71  bool noflip = std::abs(x3 - x1) < std::abs(y3 - y1);
72 
73  auto x1p = noflip ? x1 - x2 : y1 - y2;
74  auto y1p = noflip ? y1 - y2 : x1 - x2;
75  auto d12 = x1p * x1p + y1p * y1p;
76  auto x3p = noflip ? x3 - x2 : y3 - y2;
77  auto y3p = noflip ? y3 - y2 : x3 - x2;
78  auto d32 = x3p * x3p + y3p * y3p;
79 
80  auto num = x1p * y3p - y1p * x3p; // num also gives correct sign for CT
81  auto det = d12 * y3p - d32 * y1p;
82 
83  auto st2 = (d12 * x3p - d32 * x1p);
84  auto seq = det * det + st2 * st2;
85  auto al2 = T(1.) / std::sqrt(seq);
86  auto be2 = -st2 * al2;
87  auto ct = T(2.) * num * al2;
88  al2 *= det;
89 
90  m_xp = x2;
91  m_yp = y2;
92  m_c = noflip ? ct : -ct;
93  m_alpha = noflip ? al2 : -be2;
94  m_beta = noflip ? be2 : -al2;
95 }
96 
97 #endif
DDAxes::y
cmsswSequenceInfo.seq
seq
Definition: cmsswSequenceInfo.py:536
CircleEq::m_xp
T m_xp
Definition: CircleEq.h:62
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
CircleEq::m_c
T m_c
Definition: CircleEq.h:64
CircleEq::dca0
constexpr T dca0() const
Definition: CircleEq.h:33
DDAxes::x
CircleEq::m_yp
T m_yp
Definition: CircleEq.h:63
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
CircleEq::cosdir
constexpr std::pair< T, T > cosdir() const
Definition: CircleEq.h:50
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CircleEq::CircleEq
CircleEq()
Definition: CircleEq.h:26
CircleEq::cosdir
constexpr std::pair< T, T > cosdir(T x, T y) const
Definition: CircleEq.h:53
CircleEq::m_beta
T m_beta
Definition: CircleEq.h:66
CircleEq
Definition: CircleEq.h:24
CircleEq::curvature
constexpr auto curvature() const
Definition: CircleEq.h:47
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
CircleEq::CircleEq
constexpr CircleEq(T x1, T y1, T x2, T y2, T x3, T y3)
Definition: CircleEq.h:28
CircleEq::compute
constexpr void compute(T x1, T y1, T x2, T y2, T x3, T y3)
Definition: CircleEq.h:70
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:33
CircleEq::radius
constexpr auto radius() const
Definition: CircleEq.h:60
CircleEq::center
constexpr std::pair< T, T > center() const
Definition: CircleEq.h:58
T
long double T
Definition: Basic3DVectorLD.h:48
CircleEq::m_alpha
T m_alpha
Definition: CircleEq.h:65
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
CircleEq::dca
constexpr T dca(T x, T y) const
Definition: CircleEq.h:40