Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrapezoidVolumeBounds.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrapezoidVolumeBounds.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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 
18 
19 #include <cmath>
20 #include <cstddef>
21 #include <utility>
22 
24  double maxhalex,
25  double haley, double halez)
26  : VolumeBounds() {
27  m_values[eHalfLengthXnegY] = minhalex;
28  m_values[eHalfLengthXposY] = maxhalex;
29  m_values[eHalfLengthY] = haley;
30  m_values[eHalfLengthZ] = halez;
31  m_values[eAlpha] = atan2(2 * haley, (maxhalex - minhalex));
32  m_values[eBeta] = M_PI - get(eAlpha);
35 }
36 
38  double haley, double halez,
39  double alpha, double beta)
40  : VolumeBounds() {
41  m_values[eHalfLengthXnegY] = minhalex;
42  m_values[eHalfLengthY] = haley;
43  m_values[eHalfLengthZ] = halez;
45  m_values[eBeta] = beta;
46  // now calculate the remaining max half X
47  double gamma = (alpha > beta) ? (alpha - 0.5 * M_PI) : (beta - 0.5 * M_PI);
48  m_values[eHalfLengthXposY] = minhalex + (2. * haley) * tan(gamma);
49 
52 }
53 
55  const Transform3& transform) const {
56  OrientedSurfaces oSurfaces;
57  oSurfaces.reserve(6);
58 
59  // Face surfaces xy
60  RotationMatrix3 trapezoidRotation(transform.rotation());
61  Vector3 trapezoidX(trapezoidRotation.col(0));
62  Vector3 trapezoidY(trapezoidRotation.col(1));
63  Vector3 trapezoidZ(trapezoidRotation.col(2));
64  Vector3 trapezoidCenter(transform.translation());
65 
66  // (1) - At negative local z
67  auto nzTransform = transform * Translation3(0., 0., -get(eHalfLengthZ));
68  auto sf =
69  Surface::makeShared<PlaneSurface>(nzTransform, m_faceXYTrapezoidBounds);
70  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Positive));
71  // (2) - At positive local z
72  auto pzTransform = transform * Translation3(0., 0., get(eHalfLengthZ));
73  sf = Surface::makeShared<PlaneSurface>(pzTransform, m_faceXYTrapezoidBounds);
74  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Negative));
75 
76  double poshOffset = get(eHalfLengthY) / std::tan(get(eAlpha));
77  double neghOffset = get(eHalfLengthY) / std::tan(get(eBeta));
78  double topShift = poshOffset + neghOffset;
79 
80  // Face surfaces yz
81  // (3) - At point B, attached to beta opening angle
82  Vector3 fbPosition(-get(eHalfLengthXnegY) + neghOffset, 0., 0.);
83  auto fbTransform = transform * Translation3(fbPosition) *
84  AngleAxis3(-0.5 * M_PI + get(eBeta), Vector3(0., 0., 1.)) *
85  s_planeYZ;
86  sf =
87  Surface::makeShared<PlaneSurface>(fbTransform, m_faceBetaRectangleBounds);
88  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Positive));
89 
90  // (4) - At point A, attached to alpha opening angle
91  Vector3 faPosition(get(eHalfLengthXnegY) + poshOffset, 0., 0.);
92  auto faTransform =
93  transform * Translation3(faPosition) *
94  AngleAxis3(-0.5 * M_PI + get(eAlpha), Vector3(0., 0., 1.)) * s_planeYZ;
95  sf = Surface::makeShared<PlaneSurface>(faTransform,
96  m_faceAlphaRectangleBounds);
97  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Negative));
98 
99  // Face surfaces zx
100  // (5) - At negative local y
101  auto nxTransform =
102  transform * Translation3(0., -get(eHalfLengthY), 0.) * s_planeZX;
103  sf = Surface::makeShared<PlaneSurface>(nxTransform,
104  m_faceZXRectangleBoundsBottom);
105  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Positive));
106  // (6) - At positive local y
107  auto pxTransform =
108  transform * Translation3(topShift, get(eHalfLengthY), 0.) * s_planeZX;
109  sf = Surface::makeShared<PlaneSurface>(pxTransform,
110  m_faceZXRectangleBoundsTop);
111  oSurfaces.push_back(OrientedSurface(std::move(sf), Direction::Negative));
112 
113  return oSurfaces;
114 }
115 
117  m_faceXYTrapezoidBounds = std::make_shared<const TrapezoidBounds>(
118  get(eHalfLengthXnegY), get(eHalfLengthXposY), get(eHalfLengthY));
119 
120  m_faceAlphaRectangleBounds = std::make_shared<const RectangleBounds>(
121  get(eHalfLengthY) / cos(get(eAlpha) - 0.5 * M_PI), get(eHalfLengthZ));
122 
123  m_faceBetaRectangleBounds = std::make_shared<const RectangleBounds>(
124  get(eHalfLengthY) / cos(get(eBeta) - 0.5 * M_PI), get(eHalfLengthZ));
125 
126  m_faceZXRectangleBoundsBottom = std::make_shared<const RectangleBounds>(
127  get(eHalfLengthZ), get(eHalfLengthXnegY));
128 
129  m_faceZXRectangleBoundsTop = std::make_shared<const RectangleBounds>(
130  get(eHalfLengthZ), get(eHalfLengthXposY));
131 }
132 
133 bool Acts::TrapezoidVolumeBounds::inside(const Vector3& pos, double tol) const {
134  if (std::abs(pos.z()) > get(eHalfLengthZ) + tol) {
135  return false;
136  }
137  if (std::abs(pos.y()) > get(eHalfLengthY) + tol) {
138  return false;
139  }
140  Vector2 locp(pos.x(), pos.y());
141  bool inside(m_faceXYTrapezoidBounds->inside(
142  locp, BoundaryCheck(true, true, tol, tol)));
143  return inside;
144 }
145 
146 std::ostream& Acts::TrapezoidVolumeBounds::toStream(std::ostream& sl) const {
147  return dumpT<std::ostream>(sl);
148 }
149 
151  const Acts::Transform3* trf, const Vector3& envelope,
152  const Volume* entity) const {
153  double minx = get(eHalfLengthXnegY);
154  double maxx = get(eHalfLengthXposY);
155  double haley = get(eHalfLengthY);
156  double halez = get(eHalfLengthZ);
157 
158  std::array<Vector3, 8> vertices = {{{-minx, -haley, -halez},
159  {+minx, -haley, -halez},
160  {-maxx, +haley, -halez},
161  {+maxx, +haley, -halez},
162  {-minx, -haley, +halez},
163  {+minx, -haley, +halez},
164  {-maxx, +haley, +halez},
165  {+maxx, +haley, +halez}}};
166 
167  Transform3 transform = Transform3::Identity();
168  if (trf != nullptr) {
169  transform = *trf;
170  }
171 
172  Vector3 vmin = transform * vertices[0];
173  Vector3 vmax = transform * vertices[0];
174 
175  for (size_t i = 1; i < 8; i++) {
176  const Vector3 vtx = transform * vertices[i];
177  vmin = vmin.cwiseMin(vtx);
178  vmax = vmax.cwiseMax(vtx);
179  }
180 
181  return {entity, vmin - envelope, vmax + envelope};
182 }