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