Analysis Software
Documentation for sPHENIX simulation 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 
13 
14 #include <algorithm>
15 #include <cmath>
16 #include <utility>
17 #include <vector>
18 
19 namespace Acts {
20 namespace detail {
22 namespace VerticesHelper {
23 
32 std::vector<ActsScalar> phiSegments(ActsScalar phiMin = -M_PI,
33  ActsScalar phiMax = M_PI,
34  const std::vector<ActsScalar>& phiRefs = {},
35  ActsScalar phiTolerance = 1e-6);
36 
51 template <typename vertex_t, typename transform_t>
52 void createSegment(std::vector<vertex_t>& vertices,
53  std::pair<ActsScalar, ActsScalar> rxy, ActsScalar phi1,
54  ActsScalar phi2, unsigned int lseg, int addon = 0,
55  const vertex_t& offset = vertex_t::Zero(),
56  const transform_t& transform = transform_t::Identity()) {
57  // Calculate the number of segments - 1 is the minimum
58  unsigned int segs =
59  static_cast<unsigned int>(std::abs(phi2 - phi1) / (2 * M_PI) * lseg);
60  segs = segs > 0 ? segs : 1;
61  ActsScalar phistep = (phi2 - phi1) / segs;
62  // Create the segments
63  for (unsigned int iphi = 0; iphi < segs + addon; ++iphi) {
64  ActsScalar phi = phi1 + iphi * phistep;
65  vertex_t vertex = vertex_t::Zero();
66  vertex(0) = rxy.first * std::cos(phi);
67  vertex(1) = rxy.second * std::sin(phi);
68 
69  vertex = vertex + offset;
70  vertices.push_back(transform * vertex);
71  }
72 }
73 
84 std::vector<Vector2> ellipsoidVertices(ActsScalar innerRx, ActsScalar innerRy,
85  ActsScalar outerRx, ActsScalar outerRy,
86  ActsScalar avgPhi = 0.,
87  ActsScalar halfPhi = M_PI,
88  unsigned int lseg = 1);
89 
98 std::vector<Vector2> circularVertices(ActsScalar innerR, ActsScalar outerR,
99  ActsScalar avgPhi = 0.,
100  ActsScalar halfPhi = M_PI,
101  unsigned int lseg = 1);
112 template <typename vertex_t, typename vertex_container_t>
113 bool isInsidePolygon(const vertex_t& point,
114  const vertex_container_t& vertices) {
115  // when we move along the edges of a convex polygon, a point on the inside of
116  // the polygon will always appear on the same side of each edge.
117  // a point on the outside will switch sides at least once.
118 
119  // returns which side of the connecting line between `ll0` and `ll1` the point
120  // `p` is on. computes the sign of the z-component of the cross-product
121  // between the line normal vector and the vector from `ll0` to `p`.
122  auto lineSide = [&](auto&& ll0, auto&& ll1) {
123  auto normal = ll1 - ll0;
124  auto delta = point - ll0;
125  return std::signbit((normal[0] * delta[1]) - (normal[1] * delta[0]));
126  };
127 
128  auto iv = std::begin(vertices);
129  auto l0 = *iv;
130  auto l1 = *(++iv);
131  // use vertex0 to vertex1 to define reference sign and compare w/ all edges
132  auto reference = lineSide(l0, l1);
133  for (++iv; iv != std::end(vertices); ++iv) {
134  l0 = l1;
135  l1 = *iv;
136  if (lineSide(l0, l1) != reference) {
137  return false;
138  }
139  }
140  // manual check for last edge from last vertex back to the first vertex
141  if (lineSide(l1, *std::begin(vertices)) != reference) {
142  return false;
143  }
144  // point was always on the same side. point must be inside.
145  return true;
146 }
147 
158 template <typename vertex_t>
159 bool isInsideRectangle(const vertex_t& point, const vertex_t& lowerLeft,
160  const vertex_t& upperRight) {
161  return (lowerLeft[0] <= point[0]) && (point[0] < upperRight[0]) &&
162  (lowerLeft[1] <= point[1]) && (point[1] < upperRight[1]);
163 }
164 
170 bool onHyperPlane(const std::vector<Vector3>& vertices,
172 
173 } // namespace VerticesHelper
174 } // namespace detail
175 } // namespace Acts