Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VerticesHelper.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VerticesHelper.cpp
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 
10 
11 #include <cmath>
12 #include <cstddef>
13 
14 std::vector<Acts::ActsScalar> Acts::detail::VerticesHelper::phiSegments(
16  const std::vector<ActsScalar>& phiRefs, ActsScalar phiTolerance) {
17  // This is to ensure that the extrema are built regardless of number
18  // of segments
19  std::vector<ActsScalar> phiSegments;
20  std::vector<ActsScalar> quarters = {-M_PI, -0.5 * M_PI, 0., 0.5 * M_PI, M_PI};
21  // It does not cover the full azimuth
22  if (phiMin != -M_PI or phiMax != M_PI) {
23  phiSegments.push_back(phiMin);
24  for (unsigned int iq = 1; iq < 4; ++iq) {
25  if (phiMin < quarters[iq] and phiMax > quarters[iq]) {
26  phiSegments.push_back(quarters[iq]);
27  }
28  }
29  phiSegments.push_back(phiMax);
30  } else {
31  phiSegments = quarters;
32  }
33  // Insert the reference phis if
34  if (not phiRefs.empty()) {
35  for (const auto& phiRef : phiRefs) {
36  // Trying to find the right patch
37  auto match = std::find_if(
38  phiSegments.begin(), phiSegments.end(), [&](ActsScalar phiSeg) {
39  return std::abs(phiSeg - phiRef) < phiTolerance;
40  });
41  if (match == phiSegments.end()) {
42  phiSegments.push_back(phiRef);
43  }
44  }
45  std::sort(phiSegments.begin(), phiSegments.end());
46  }
47  return phiSegments;
48 }
49 
51  ActsScalar innerRx, ActsScalar innerRy, ActsScalar outerRx,
52  ActsScalar outerRy, ActsScalar avgPhi, ActsScalar halfPhi,
53  unsigned int lseg) {
54  // List of vertices counter-clockwise starting at smallest phi w.r.t center,
55  // for both inner/outer ring/segment
56  std::vector<Vector2> rvertices; // return vertices
57  std::vector<Vector2> ivertices; // inner vertices
58  std::vector<Vector2> overtices; // outer verices
59 
60  bool innerExists = (innerRx > 0. and innerRy > 0.);
61  bool closed = std::abs(halfPhi - M_PI) < s_onSurfaceTolerance;
62 
63  // Get the phi segments from the helper method
65  avgPhi - halfPhi, avgPhi + halfPhi, {avgPhi});
66 
67  // The inner (if exists) and outer bow
68  for (unsigned int iseg = 0; iseg < phiSegs.size() - 1; ++iseg) {
69  int addon = (iseg == phiSegs.size() - 2 and not closed) ? 1 : 0;
70  if (innerExists) {
71  createSegment<Vector2, Transform2>(ivertices, {innerRx, innerRy},
72  phiSegs[iseg], phiSegs[iseg + 1], lseg,
73  addon);
74  }
75  createSegment<Vector2, Transform2>(overtices, {outerRx, outerRy},
76  phiSegs[iseg], phiSegs[iseg + 1], lseg,
77  addon);
78  }
79 
80  // We want to keep the same counter-clockwise orientation for displaying
81  if (not innerExists) {
82  if (not closed) {
83  // Add the center case we have a sector
84  rvertices.push_back(Vector2(0., 0.));
85  }
86  rvertices.insert(rvertices.end(), overtices.begin(), overtices.end());
87  } else if (not closed) {
88  rvertices.insert(rvertices.end(), overtices.begin(), overtices.end());
89  rvertices.insert(rvertices.end(), ivertices.rbegin(), ivertices.rend());
90  } else {
91  rvertices.insert(rvertices.end(), overtices.begin(), overtices.end());
92  rvertices.insert(rvertices.end(), ivertices.begin(), ivertices.end());
93  }
94  return rvertices;
95 }
96 
98  ActsScalar innerR, ActsScalar outerR, ActsScalar avgPhi, ActsScalar halfPhi,
99  unsigned int lseg) {
100  return ellipsoidVertices(innerR, innerR, outerR, outerR, avgPhi, halfPhi,
101  lseg);
102 }
103 
105  const std::vector<Acts::Vector3>& vertices, ActsScalar tolerance) {
106  // Obvious always on one surface
107  if (vertices.size() < 4) {
108  return true;
109  }
110  // Create the hyperplane
111  auto hyperPlane = Eigen::Hyperplane<ActsScalar, 3>::Through(
112  vertices[0], vertices[1], vertices[2]);
113  for (size_t ip = 3; ip < vertices.size(); ++ip) {
114  if (hyperPlane.absDistance(vertices[ip]) > tolerance) {
115  return false;
116  }
117  }
118  return true;
119 }