forked from sPHENIX-Collaboration/acts
/
CylinderVolumeBounds.hpp
280 lines (247 loc) · 10.2 KB
/
CylinderVolumeBounds.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// This file is part of the Acts project.
//
// Copyright (C) 2016-2020 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Geometry/VolumeBounds.hpp"
#include "Acts/Utilities/BoundingBox.hpp"
#include "Acts/Utilities/Definitions.hpp"
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/detail/periodic.hpp"
#include <array>
#include <cmath>
#include <exception>
#include <vector>
namespace Acts {
class Surface;
class CylinderBounds;
class RadialBounds;
class PlanarBounds;
class IVisualization3D;
/// @class CylinderVolumeBounds
///
/// Bounds for a cylindrical Volume, the orientedSurfaces(..) method creates a
/// vector of up to 6 surfaces:
///
/// case A) 3 Surfaces (full cylindrical tube):
/// BoundarySurfaceFace [index]:
/// - negativeFaceXY [0] : Acts::DiscSurface with \f$ r_{inner}=0 \f$,
/// parallel to \f$ xy \f$ plane at negative \f$ z\f$
/// - positiveFaceXY [1] : Acts::DiscSurface with \f$ r_{inner}=0 \f$,
/// parallel to \f$ xy \f$ plane at positive \f$ z\f$
/// - cylinderCover [2] : Acts::CylinderSurface confining the Acts::Volume
///
/// case B) 4 Surfaces (tube with inner and outer radius):
/// BoundarySurfaceFace [index]:
/// - negativeFaceXY [0] : Acts::DiscSurface with \f$ r_{inner}>0 \f$,
/// parallel to \f$ xy \f$ plane at negative \f$ z\f$
/// - positiveFaceXY [1] : Acts::DiscSurface with \f$ r_{inner}>0 \f$,
/// parallel to \f$ xy \f$ plane at positive \f$ z\f$
/// - tubeOuterCover [2] : Acts::CylinderSurface with \f$ r = r_{outer} \f$
/// - tubeInnerCover [3] : Acts::CylinderSurface with \f$ r = r_{inner} \f$
///
/// case C) 6 Surfaces (sectoral tube with inner and outer radius):
/// BoundarySurfaceFace [index]:
/// - negativeFaceXY [0] : Acts::DiscSurface with \f$ r_{inner}>0\f$
/// and \f$ \phi < \pi \f$,
/// parallel to \f$ xy \f$ plane at negative \f$z\f$
/// - positiveFaceXY [1] : Acts::DiscSurface with \f$ r_{inner}>0 \f$
/// and \f$ \phi < \pi \f$,
/// parallel to \f$ xy \f$ plane at positive \f$z\f$
/// - tubeSectorOuterCover [2] : Acts::CylinderSurface with
/// \f$ r = r_{outer}\f$
/// - tubeSectorInnerCover [3] : Acts::CylinderSurface with
/// \f$ r = r_{inner} \f$
/// - tubeSectorNegativePhi [4] : Rectangular Acts::PlaneSurface attached to
/// [0] and [1] at negative \f$ \phi \f$
/// - tubeSectorNegativePhi [5] :
// Rectangular Acts::PlaneSurface attached to
/// [0] and [1] at positive \f$ \phi \f$
///
class CylinderVolumeBounds : public VolumeBounds {
public:
/// @enum BoundValues for streaming and access
enum BoundValues : unsigned int {
eMinR = 0,
eMaxR = 1,
eHalfLengthZ = 2,
eHalfPhiSector = 3,
eAveragePhi = 4,
eSize
};
CylinderVolumeBounds() = delete;
/// Constructor
///
/// @param rmin The inner radius of the cylinder
/// @param rmax The outer radius of the cylinder
/// @param halfz The half length in z
/// @param halfphi The half lopening angle
/// @param avgphi The average phi value
CylinderVolumeBounds(double rmin, double rmax, double halfz,
double halfphi = M_PI,
double avgphi = 0.) noexcept(false)
: m_values({rmin, rmax, halfz, halfphi, avgphi}) {
checkConsistency();
buildSurfaceBounds();
}
/// Constructor - from a fixed size array
///
/// @param values The bound values
CylinderVolumeBounds(const std::array<double, eSize>& values) noexcept(false)
: m_values(values) {
checkConsistency();
buildSurfaceBounds();
}
/// Constructor - extruded from cylinder bounds and thickness
///
/// @param cbounds the cylinder bounds
/// @param thickness of the extrusion
CylinderVolumeBounds(const CylinderBounds& cBounds,
double thickness) noexcept(false);
/// Constructor - extruded from radial bounds and thickness
///
/// @param rbounds the Radial bounds
/// @param thickness
CylinderVolumeBounds(const RadialBounds& rBounds,
double thickness) noexcept(false);
/// Copy Constructor
///
/// @param cylbo is the source cylinder volume bounds for the copy
CylinderVolumeBounds(const CylinderVolumeBounds& cylbo) = default;
~CylinderVolumeBounds() override = default;
CylinderVolumeBounds& operator=(const CylinderVolumeBounds& cylbo) = default;
VolumeBounds::BoundsType type() const final {
return VolumeBounds::eCylinder;
}
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
/// This method checks if position in the 3D volume
/// frame is inside the cylinder
///
/// @param pos is a global position to be checked
/// @param tol is the tolerance for the check
bool inside(const Vector3D& pos, double tol = 0.) const override;
/// Oriented surfaces, i.e. the decomposed boundary surfaces and the
/// according navigation direction into the volume given the normal
/// vector on the surface
///
/// @param transform is the 3D transform to be applied to the boundary
/// surfaces to position them in 3D space
///
/// It will throw an exception if the orientation prescription is not adequate
///
/// @return a vector of surfaces bounding this volume
OrientedSurfaces orientedSurfaces(
const Transform3D& transform = Transform3D::Identity()) const override;
/// Construct bounding box for this shape
/// @param trf Optional transform
/// @param envelope Optional envelope to add / subtract from min/max
/// @param entity Entity to associate this bounding box with
/// @return Constructed bounding box
Volume::BoundingBox boundingBox(const Transform3D* trf = nullptr,
const Vector3D& envelope = {0, 0, 0},
const Volume* entity = nullptr) const final;
/// Binning offset - overloaded for some R-binning types
///
/// @param bValue is the type used for the binning
Vector3D binningOffset(BinningValue bValue) const override;
/// Binning borders in double
///
/// @param bValue is the type used for the binning
double binningBorder(BinningValue bValue) const override;
/// Output Method for std::ostream
std::ostream& toStream(std::ostream& sl) const override;
/// Access to the bound values
/// @param bValue the class nested enum for the array access
double get(BoundValues bValue) const { return m_values[bValue]; }
private:
/// The internal version of the bounds can be float/double
std::array<double, eSize> m_values;
/// Bounds of the inner CylinderBounds
std::shared_ptr<const CylinderBounds> m_innerCylinderBounds{nullptr};
/// Bounds of the inner CylinderBounds
std::shared_ptr<const CylinderBounds> m_outerCylinderBounds{nullptr};
/// Bounds of the bottom/top Radial
std::shared_ptr<const RadialBounds> m_discBounds{nullptr};
/// Bounds of the sector planes
std::shared_ptr<const PlanarBounds> m_sectorPlaneBounds{nullptr};
/// Check the input values for consistency,
/// will throw a logic_exception if consistency is not given
void checkConsistency() noexcept(false);
/// Helper method to create the surface bounds
void buildSurfaceBounds();
/// Templated dumpT method
/// @tparam stream_t The type fo the dump stream
/// @param dt The dump stream object
template <class stream_t>
stream_t& dumpT(stream_t& dt) const;
};
inline bool CylinderVolumeBounds::inside(const Vector3D& pos,
double tol) const {
using VectorHelpers::perp;
using VectorHelpers::phi;
double ros = perp(pos);
bool insidePhi = cos(phi(pos)) >= cos(get(eHalfPhiSector)) - tol;
bool insideR = insidePhi
? ((ros >= get(eMinR) - tol) && (ros <= get(eMaxR) + tol))
: false;
bool insideZ =
insideR ? (std::abs(pos.z()) <= get(eHalfLengthZ) + tol) : false;
return (insideZ && insideR && insidePhi);
}
inline Vector3D CylinderVolumeBounds::binningOffset(BinningValue bValue)
const { // the medium radius is taken for r-type binning
if (bValue == Acts::binR || bValue == Acts::binRPhi) {
return Vector3D(0.5 * (get(eMinR) + get(eMaxR)), 0., 0.);
}
return VolumeBounds::binningOffset(bValue);
}
inline double CylinderVolumeBounds::binningBorder(BinningValue bValue) const {
if (bValue == Acts::binR) {
return 0.5 * (get(eMaxR) - get(eMinR));
}
if (bValue == Acts::binZ) {
return get(eHalfLengthZ);
}
return VolumeBounds::binningBorder(bValue);
}
template <class stream_t>
stream_t& CylinderVolumeBounds::dumpT(stream_t& dt) const {
dt << std::setiosflags(std::ios::fixed);
dt << std::setprecision(5);
dt << "Acts::CylinderVolumeBounds: (rMin, rMax, halfZ, halfPhi, "
"averagePhi) = ";
dt << get(eMinR) << ", " << get(eMaxR) << ", " << get(eHalfLengthZ) << ", "
<< get(eHalfPhiSector) << get(eAveragePhi);
return dt;
}
inline std::vector<double> CylinderVolumeBounds::values() const {
std::vector<double> valvector;
valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
return valvector;
}
inline void CylinderVolumeBounds::checkConsistency() noexcept(false) {
if (get(eMinR) < 0. or get(eMaxR) <= 0. or get(eMinR) >= get(eMaxR)) {
throw std::invalid_argument("CylinderVolumeBounds: invalid radial input.");
}
if (get(eHalfLengthZ) <= 0) {
throw std::invalid_argument(
"CylinderVolumeBounds: invalid longitudinal input.");
}
if (get(eHalfPhiSector) < 0. or get(eHalfPhiSector) > M_PI) {
throw std::invalid_argument(
"CylinderVolumeBounds: invalid phi sector setup.");
}
if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
throw std::invalid_argument(
"CylinderVolumeBounds: invalid phi positioning.");
}
}
} // namespace Acts