12#include "GaudiKernel/MsgStream.h"
24 bool iterate(
double x,
double y,
double c0x,
double c0y,
double c2x,
double c2y,
double rr)
const
30 int numNodes = 4 << t;
32 innerPolygonCoef[t] = 0.5 / std::cos(2.0*
M_PI / numNodes);
33 double c1x = (c0x + c2x) * innerPolygonCoef[t];
34 double c1y = (c0y + c2y) * innerPolygonCoef[t];
37 if (tx * tx + ty * ty <=
rr) {
40 double t2x = c2x - c1x;
41 double t2y = c2y - c1y;
42 if (tx * t2x + ty * t2y >= 0 && tx * t2x + ty * t2y <= t2x * t2x + t2y * t2y &&
43 (ty * t2x - tx * t2y >= 0 ||
rr * (t2x * t2x + t2y * t2y) >= (ty * t2x - tx * t2y) * (ty * t2x - tx * t2y))) {
46 double t0x = c0x - c1x;
47 double t0y = c0y - c1y;
48 if (tx * t0x + ty * t0y >= 0 && tx * t0x + ty * t0y <= t0x * t0x + t0y * t0y &&
49 (ty * t0x - tx * t0y <= 0 ||
rr * (t0x * t0x + t0y * t0y) >= (ty * t0x - tx * t0y) * (ty * t0x - tx * t0y))) {
52 outerPolygonCoef[t] = 0.5 / (std::cos(
M_PI / numNodes) * std::cos(
M_PI / numNodes));
53 double c3x = (c0x + c1x) * outerPolygonCoef[t];
54 double c3y = (c0y + c1y) * outerPolygonCoef[t];
55 if ((c3x -
x) * (c3x -
x) + (c3y -
y) * (c3y -
y) <
rr) {
60 double c4x = c1x - c3x + c1x;
61 double c4y = c1y - c3y + c1y;
62 if ((c4x -
x) * (c4x -
x) + (c4y -
y) * (c4y -
y) <
rr) {
67 double t3x = c3x - c1x;
68 double t3y = c3y - c1y;
69 if (ty * t3x - tx * t3y <= 0 ||
rr * (t3x * t3x + t3y * t3y) > (ty * t3x - tx * t3y) * (ty * t3x - tx * t3y)) {
70 if (tx * t3x + ty * t3y > 0) {
71 if (std::abs(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y ||
72 (
x - c3x) * (c0x - c3x) + (
y - c3y) * (c0y - c3y) >= 0) {
77 }
else if (-(tx * t3x + ty * t3y) <= t3x * t3x + t3y * t3y ||
78 (
x - c4x) * (c2x - c4x) + (
y - c4y) * (c2y - c4y) >= 0) {
92 bool collide(
double x0,
double y0,
double w,
double h,
double x1,
double y1,
double r)
const
94 double x = std::abs(x1 - x0);
95 double y = std::abs(y1 - y0);
100 if (
x *
x + (
h -
y) * (
h -
y) <=
r *
r || (w -
x) * (w -
x) +
y *
y <=
r *
r ||
101 x *
h +
y * w <= w *
h
102 || ((
x *
h +
y * w - w *
h) * (
x *
h +
y * w - w *
h) <=
r *
r * (w * w +
h *
h) &&
x * w -
y *
h >= -
h *
h &&
103 x * w -
y *
h <= w * w)) {
106 if ((
x - w) * (
x - w) + (
y -
h) * (
y -
h) <=
r *
r || (
x <= w &&
y -
r <=
h) || (
y <=
h &&
x -
r <= w)) {
113 double localCos =
x / R;
114 double deltaR = std::sqrt(
h *
h + (w * w -
h *
h) * localCos * localCos);
115 return deltaR >= R - std::sqrt(
x *
x +
y *
y);
174 std::vector<TDD_real_t> XX;
180 std::vector<TDD_real_t> YY;
187 m_maxXout = *std::max_element(XX.begin(), XX.end());
188 m_minXout = *std::min_element(XX.begin(), XX.end());
189 m_maxYout = *std::max_element(YY.begin(), YY.end());
190 m_minYout = *std::min_element(YY.begin(), YY.end());
229 double localR2 = localX * localX + localY * localY;
230 double localR = std::sqrt(localR2);
231 double localCos = localX / localR;
232 double localSin = localY / localR;
233 double deltaR = std::sqrt(tol2 * tol2 * localSin * localSin + tol1 * tol1 * localCos * localCos);
238 bool condRad = (localR < maxR + deltaR && localR >
minR -
deltaR);
244 return (condRad && condL && condR);
259 AmgMatrix(2, 2) lCovarianceCar = bchk.lCovariance;
262 double w = bchk.
nSigmas * std::sqrt(lCovarianceCar(0, 0));
263 double h = bchk.
nSigmas * std::sqrt(lCovarianceCar(1, 1));
266 double maxTol = std::max(w,
h);
267 double minTol = std::min(w,
h);
282 float theta = (lCovarianceCar(1, 0) != 0 && (lCovarianceCar(1, 1) - lCovarianceCar(0, 0)) != 0)
283 ? .5 * bchk.
FastArcTan(2 * lCovarianceCar(1, 0) / (lCovarianceCar(1, 1) - lCovarianceCar(0, 0)))
287 rotMatrix << scResult.
cosC, scResult.
sinC,
290 double x1 = tmp(0, 0);
291 double y1 = tmp(1, 0);
295 bool condR = (test.collide(x0, y0, w,
h, x1, y1, -
minR) && test.collide(x0, y0, w,
h, x1, y1,
maxR));
298 std::vector<KDOP> elementKDOP(4);
299 std::vector<Amg::Vector2D> elementP(4);
303 normal << 0, -1, 1, 0;
308 elementP[0] = (rotMatrix * (p - locpo));
311 elementP[1] = (rotMatrix * (p - locpo));
314 elementP[2] = (rotMatrix * (p - locpo));
317 elementP[3] = (rotMatrix * (p - locpo));
319 std::vector<Amg::Vector2D> axis = { normal * (elementP[0] - elementP[1]),
320 normal * (elementP[1] - elementP[2]),
321 normal * (elementP[2] - elementP[3]),
322 normal * (elementP[3] - elementP[0]) };
325 std::vector<KDOP> errelipseKDOP(4);
328 bool condSide = bchk.
TestKDOPKDOP(elementKDOP, errelipseKDOP);
339 return (condR && condSide);
353 double k = (y2 - y1) / (x2 - x1);
354 double d = y1 - k * x1;
356 double sign = k > 0. ? -1. : +1.;
374 double k = (y2 - y1) / (x2 - x1);
375 double d = y1 - k * x1;
404 double k = (y2 - y1) / (x2 - x1);
405 double d = y1 - k * x1;
434 double dist = std::min(distLine_L, distLine_R);
440 double distArc = std::min(distMin, distMax);
442 dist = std::min(dist, distArc);
444 if (
inside(locpo, 0., 0.)){
465 std::vector<double> solution;
474 double delta = 4. * k * d * k * d - 4. * (1 + k * k) * (d * d - R * R);
481 x1 = (-2. * k * d - std::sqrt(delta)) / (2. * (1 + k * k));
482 x2 = (-2. * k * d + std::sqrt(delta)) / (2. * (1 + k * k));
489 solution.push_back(x1);
490 solution.push_back(y1);
492 solution.push_back(x2);
493 solution.push_back(y2);
501 const std::vector<TDD_real_t>& P1,
502 const std::vector<TDD_real_t>& P2)
509 double A = P2x - P1x;
510 double B = P2y - P1y;
517 double u = (
A * (X - P1x) + B * (Y - P1y)) / (
A *
A + B * B);
528 return std::sqrt((X - P3x) * (X - P3x) + (Y - P3y) * (Y - P3y));
535 const std::vector<TDD_real_t>& sL,
536 const std::vector<TDD_real_t>& sR)
542 double tanlocPhi = X / Y;
543 double tanPhi_L = sL[0] / sL[1];
544 double tanPhi_R = sR[0] / sR[1];
546 if (tanlocPhi > tanPhi_L && tanlocPhi < tanPhi_R){
547 return std::fabs(std::sqrt(X * X + Y * Y) - R);
573 if (
h == 0 && k == 0)
590 m = (y2 - y1) / (x2 - x1);
594 return (std::fabs(c) < k);
596 return (std::fabs(c / m) <
h);
598 r = m * m *
h *
h + k * k;
599 s = 2 * m * c *
h *
h;
600 t =
h *
h * c * c -
h *
h * k * k;
602 d = s * s - 4 *
r * t;
609 d = std::fabs(x1) -
h;
617 std::array<std::pair<double, double>, 4>
corners;
630 sl << std::setiosflags(std::ios::fixed);
631 sl << std::setprecision(7);
632 sl <<
"Trk::AnnulusBounds: (minR, maxR, phi) = "
635 sl << std::setprecision(-1);
642 sl << std::setiosflags(std::ios::fixed);
643 sl << std::setprecision(7);
644 sl <<
"Trk::AnnulusBounds: (minR, maxR, phi) = "
647 sl << std::setprecision(-1);
660 std::array<TDD_real_t,4> returnArr{};
const boost::regex rr(r_r)
Scalar deltaR(const MatrixBase< Derived > &vec) const
#define AmgMatrix(rows, cols)
Header file for AthHistogramAlgorithm.
EllipseCollisionTest(int maxIterations)
bool iterate(double x, double y, double c0x, double c0y, double c2x, double c2y, double rr) const
bool collide(double x0, double y0, double w, double h, double x1, double y1, double r) const
Bounds for a annulus-like, planar Surface.
static bool isAbove(const Amg::Vector2D &locpo, double tol1, double tol2, double x1, double y1, double x2, double y2)
isAbove() method for checking whether a point lies above or under a straight line
double minR() const
This method returns the smaller radius.
bool operator==(const SurfaceBounds &annbo) const override
Equality operator.
double maxR() const
This method returns the bigger radius.
static std::vector< double > circleLineIntersection(double R, double k, double d)
Circle and line intersection.
virtual double minDistance(const Amg::Vector2D &pos) const override final
Minimal distance to boundary ( > 0 if outside and <=0 if inside)
static double distanceToLine(const Amg::Vector2D &locpo, const std::vector< TDD_real_t > &P1, const std::vector< TDD_real_t > &P2)
Distance to line.
static bool isLeft(const Amg::Vector2D &locpo, double tol1, double tol2, double x1, double y1, double x2, double y2)
virtual bool inside(const Amg::Vector2D &locpo, double tol1=0., double tol2=0.) const override final
This method returns the opening angle alpha in point A (negative local phi)
virtual MsgStream & dump(MsgStream &sl) const override
Output Method for MsgStream.
std::array< TDD_real_t, 4 > getEdgeLines() const
Returns the gradient and y-intercept of the left and right module edges.
static bool EllipseIntersectLine(const Amg::Vector2D &locpo, double h, double k, double x1, double y1, double x2, double y2)
std::vector< TDD_real_t > m_solution_L_min
std::vector< TDD_real_t > m_solution_R_max
double phiS() const
This method returns the tilt angle.
double phi() const
This method returns the opening angle.
virtual double r() const override
This method returns the maximal extension on the local plane.
std::vector< TDD_real_t > m_solution_R_min
static bool isRight(const Amg::Vector2D &locpo, double tol1, double tol2, double x1, double y1, double x2, double y2)
AnnulusBounds()
Default Constructor, needed for persistency.
static double distanceToArc(const Amg::Vector2D &locpo, double R, const std::vector< TDD_real_t > &sL, const std::vector< TDD_real_t > &sR)
Distance to arc.
std::vector< TDD_real_t > m_solution_L_max
std::array< std::pair< double, double >, 4 > corners() const
Returns the four corners of the bounds.
std::vector< TDD_real_t > m_boundValues
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
int nSigmas
allowed sigmas for chi2 boundary check
std::vector< Amg::Vector2D > EllipseToPoly(int resolution=3) const
bool TestKDOPKDOP(const std::vector< KDOP > &a, const std::vector< KDOP > &b) const
void ComputeKDOP(const std::vector< Amg::Vector2D > &v, const std::vector< Amg::Vector2D > &KDOPAxes, std::vector< KDOP > &kdop) const
Each Bounds has a method inside, which checks if a LocalPosition is inside the bounds.
double toleranceLoc2
absolute tolerance in local 2 coordinate
double FastArcTan(double x) const
sincosCache FastSinCos(double x) const
double toleranceLoc1
absolute tolerance in local 1 coordinate
Abstract base class for surface bounds to be specified.
void swap(double &b1, double &b2)
Swap method to be called from DiscBounds or TrapezoidalBounds.
Eigen::Matrix< double, 2, 1 > Vector2D
@ u
Enums for curvilinear frames.
hold the test vectors and ease the comparison