EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VerticesHelper.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VerticesHelper.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
12 
13 #include <utility>
14 #include <vector>
15 
16 namespace Acts {
17 namespace detail {
19 namespace VerticesHelper {
20 
29 std::vector<double> phiSegments(double phiMin = -M_PI, double phiMax = M_PI,
30  const std::vector<double>& phiRefs = {},
31  double phiTolerance = 1e-6);
32 
47 template <typename vertex_t, typename transform_t>
48 void createSegment(std::vector<vertex_t>& vertices,
49  std::pair<double, double> rxy, double phi1, double phi2,
50  unsigned int lseg, int addon = 0,
51  const vertex_t& offset = vertex_t::Zero(),
52  const transform_t& transform = transform_t::Identity()) {
53  // Calculate the number of segments - 1 is the minimum
54  unsigned int segs = std::abs(phi2 - phi1) / (2 * M_PI) * lseg;
55  segs = segs > 0 ? segs : 1;
56  double phistep = (phi2 - phi1) / segs;
57  // Create the segments
58  for (unsigned int iphi = 0; iphi < segs + addon; ++iphi) {
59  double phi = phi1 + iphi * phistep;
60  vertex_t vertex = vertex_t::Zero();
61  vertex(0) = rxy.first * std::cos(phi);
62  vertex(1) = rxy.second * std::sin(phi);
63  vertex = vertex + offset;
64  vertices.push_back(transform * vertex);
65  }
66 }
67 
78 std::vector<Vector2D> ellipsoidVertices(double innerRx, double innerRy,
79  double outerRx, double outerRy,
80  double avgPhi = 0.,
81  double halfPhi = M_PI,
82  unsigned int lseg = 1);
83 
92 std::vector<Vector2D> circularVertices(double innerR, double outerR,
93  double avgPhi = 0.,
94  double halfPhi = M_PI,
95  unsigned int lseg = 1);
106 template <typename vertex_t, typename vertex_container_t>
107 bool isInsidePolygon(const vertex_t& point,
108  const vertex_container_t& vertices) {
109  // when we move along the edges of a convex polygon, a point on the inside of
110  // the polygon will always appear on the same side of each edge.
111  // a point on the outside will switch sides at least once.
112 
113  // returns which side of the connecting line between `ll0` and `ll1` the point
114  // `p` is on. computes the sign of the z-component of the cross-product
115  // between the line normal vector and the vector from `ll0` to `p`.
116  auto lineSide = [&](auto&& ll0, auto&& ll1) {
117  auto normal = ll1 - ll0;
118  auto delta = point - ll0;
119  return std::signbit((normal[0] * delta[1]) - (normal[1] * delta[0]));
120  };
121 
122  auto iv = std::begin(vertices);
123  auto l0 = *iv;
124  auto l1 = *(++iv);
125  // use vertex0 to vertex1 to define reference sign and compare w/ all edges
126  auto reference = lineSide(l0, l1);
127  for (++iv; iv != std::end(vertices); ++iv) {
128  l0 = l1;
129  l1 = *iv;
130  if (lineSide(l0, l1) != reference) {
131  return false;
132  }
133  }
134  // manual check for last edge from last vertex back to the first vertex
135  if (lineSide(l1, *std::begin(vertices)) != reference) {
136  return false;
137  }
138  // point was always on the same side. point must be inside.
139  return true;
140 }
141 
152 template <typename vertex_t>
153 bool isInsideRectangle(const vertex_t& point, const vertex_t& lowerLeft,
154  const vertex_t& upperRight) {
155  return (lowerLeft[0] <= point[0]) && (point[0] < upperRight[0]) &&
156  (lowerLeft[1] <= point[1]) && (point[1] < upperRight[1]);
157 }
158 
164 bool onHyperPlane(const std::vector<Vector3D>& vertices,
166 
167 } // namespace VerticesHelper
168 } // namespace detail
169 } // namespace Acts