8#include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
9#include "Acts/Geometry/CuboidVolumeBounds.hpp"
10#include "Acts/Definitions/Tolerance.hpp"
11#include "Acts/Surfaces/detail/PlanarHelper.hpp"
12#include "Acts/Definitions/Units.hpp"
15using namespace Acts::PlanarHelper;
16using namespace Acts::UnitLiterals;
19std::string
toString(
const std::vector<TrapezoidBoundsExpander::TrapezoidPatch>& patches) {
20 std::stringstream sstr{};
21 for (
const auto& patch : patches) {
22 sstr<<
" **** "<<patch<<std::endl;
29 std::shared_ptr<const Acts::VolumeBounds> volBounds):
36 <<
", bounds: "<<(*bounds)
51 const Acts::Volume& volume){
52 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Bounds "<<volume.volumeBounds());
54 m_constituents.emplace_back(volume.localToGlobalTransform(tgContext),
55 volume.volumeBoundsPtr());
67 Amg::Vector3D::UnitY(), testMe).position();
68 return (testMe.x() - closest.x()) *Acts::toUnderlying(side);
72 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Assign "<<margin<<
" to all vertices");
77 const double marginY,
const double marginZ) {
82 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Assign "<<marginXlow<<
"/"<<marginXhigh
83 <<
" to x-edges , "<<marginY<<
" to the y-edge, "<<marginZ<<
" to the z-edge as extra margin");
86std::shared_ptr<Acts::VolumeBounds>
91 const auto boxMin =
minima();
92 const auto boxMax =
maxima();
98 return patch.
bounds->type() == Acts::VolumeBounds::BoundsType::eCuboid;
100 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" Only cuboids have been passed. Construct a cuboid");
111 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Trapezoid after shift: "<<trapezoid);
114 GeoTrf::CoordEulerAngles rotAngles = GeoTrf::getCoordRotationAngles(trapezoid.toCenter);
115 if (std::abs(rotAngles.gamma - 180._degree)< Acts::s_epsilon) {
117 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Flip trapezoid around Z: "
120 if (std::abs(rotAngles.alpha - 180._degree)< Acts::s_epsilon) {
122 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Flip trapezoid around X: "
127 std::array<Amg::Vector3D, 4> expandedCorners{Acts::filledArray<Amg::Vector3D, 4>(Amg::Vector3D::Zero())};
129 std::ranges::sort(
m_constituents, [side](
const auto&
a,
const auto& b){
132 if (std::abs(botA.y() - botB.y()) > Acts::s_onSurfaceTolerance) {
133 return botA.y() < botB.y();
135 return (botA.x() - botB.x()) * Acts::toUnderlying(side) > 0.;
137 std::size_t highPatch{0ul};
140 std::optional<std::size_t> lowPatch{};
141 for (std::size_t patch = 0ul; patch <
m_constituents.size(); ++ patch) {
142 if (!lowPatch.has_value() &&
m_constituents.at(patch).bounds->type() == Acts::VolumeBounds::eTrapezoid) {
149 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Test: "<<patch<<
" position: "
150 <<
Amg::toString(botB)<<
" --- best: "<<highPatch<<
" position: "
151 <<
Amg::toString(botA)<<
", distance: "<<(botB.x() - botA.x())<<
", side: "<<side);
152 if ((botB.x() - botA.x()) * Acts::toUnderlying(side) > 0.) {
156 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Expand corners at "<<side
158 <<
"\n ---- Selected upper trapezoid:\n"
163 lowPatch.value_or(0), highPatch);
179 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Created new bounds "<<(*
m_finalBounds));
186 const std::size_t lowPatch,
187 const std::size_t highPatch)
const {
192 Amg::Vector3D::UnitZ());
193 botCorner = intersectPlane(botCorner, edge, Amg::Vector3D::UnitY(), -
halfY).position();
194 topCorner = intersectPlane(topCorner, edge, Amg::Vector3D::UnitY(),
halfY).position();
199 if (v.y() <= botCorner.y()) {
202 const double m = (v.x() - botCorner.x()) / (v.y() - botCorner.y());
203 if(std::abs(m)> std::abs(steepM)) {
207 updateSlope(topCorner);
208 ACTS_DEBUG(__func__<<
"() "<<__LINE__<<
" - Identified "<<
Amg::toString(botCorner)
213 area += patch.area();
217 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Vertex at "<<lvl
223 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Shift the trapezoid.");
227 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - The farest "<<
Amg::toString(farestVtx)<<
" with distance "
229 <<
", start M: "<<(topCorner.x() - botCorner.x()) / (topCorner.y() - botCorner.y()));
232 botCorner = intersectPlane(farestVtx, edge, Amg::Vector3D::UnitY(), -
halfY).position();
233 topCorner = intersectPlane(farestVtx, edge, Amg::Vector3D::UnitY(),
halfY).position();
235 const double envArea = (std::abs(botCorner.x()) + std::abs(topCorner.x()))* 2.*
halfY;
236 ACTS_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Update corners to "<<
Amg::toString(botCorner)
237 <<
" (bottom) and "<<
Amg::toString(topCorner)<<
" (top) New area: "<<envArea
238 <<
", old area: "<<
area<<
", diff: "<<(
area/ envArea));
detray::unit< scalar_t > unit
static std::vector< Amg::Vector3D > cornerPoints(const Acts::GeometryContext &tgContext, const Acts::Volume &volume, const std::size_t nSegments=3)
Returns the vertices from a volume.
std::span< const double > maxima() const
Returns the triplet of the maximum coordinates from the ensemble of all seen vertices.
std::span< const double > minima() const
Returns the triplet of the minimum coordinates from the ensemble of all seen vertices.
Acts::Transform3 toVertexCenter() const
Returns the transform from the ATLAS frame to the center of all seen vertices.
void reCenter(std::span< const Amg::Vector3D > vertices)
Update the center point from a list of global vertices.
virtual std::shared_ptr< Acts::VolumeBounds > makeBounds(Acts::VolumeBoundFactory &factory) override final
void findTrapezoidEdge(Amg::Vector3D &botCorner, Amg::Vector3D &topCorner, const Side side, const std::size_t lowPatch, const std::size_t highPatch) const
Moves the position of the bottom and top corner of a trapezoid side such that all vertices are enclos...
std::vector< TrapezoidPatch > m_constituents
std::array< double, 4 > m_margin
void setMargin(const double margin)
Apply an extra margin to all four bound dimensions.
std::shared_ptr< Acts::VolumeBounds > m_finalBounds
static Amg::Vector3D makeVertex(const TrapezoidPatch &trapezoid, const Side side, const Level lvl)
Returns the vertex point from a trapezoid.
Level
Enum to select the top / bottom corners of a trapezoid.
Side
Enum to select the left / right corners of a trapezoid.
static double distanceToTrapezoid(const Amg::Vector3D &vertex, const Amg::Vector3D &edge, const Amg::Vector3D &testMe, const Side side)
Returns the distance to the inclided trapezoidal side Positive values imply that the test point is ou...
virtual void expand(const Acts::GeometryContext &tgContext, const Acts::Volume &volume) override final
static std::uint8_t toIndex(const Side side, const Level lvl)
Construct an index from [0;3] from the side and level.
Amg::Vector3D projectDirOntoPlane(const Amg::Vector3D &direction, const Amg::Vector3D &planeNorm)
Project the direction vector onto the plane and renormalize to unity.
Amg::Isometry3D getRotateX3D(double angle)
Rotate the coordinate system by an angle around the x-axis.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 1 > Vector3D
Amg::Isometry3D getRotateZ3D(double angle)
Rotate the coordinate system by an angle around the z-axis.
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
double halfY(const Acts::VolumeBounds &bounds)
Returns the half-Y length for the parsed volume bounds (Trapezoid/ Cuboid).
std::string toString(const MuonGMR4::MuonReadoutElement *re)
double halfZ(const Acts::VolumeBounds &bounds)
Returns the half-Z length for the parsed volume bounds (Trapezoid/ Cuboid).
double halfXhighY(const Acts::VolumeBounds &bounds)
Returns the half-Y length @ posiive Y for the parsed volume bounds (Trapezoid/ Cuboid).
double halfXlowY(const Acts::VolumeBounds &bounds)
Returns the half-X length @ negative Y for the parsed volume bounds (Trapezoid/ Cuboid).
Helper struct to describe a sub trapezoid that is not aligned with the center of the coordinate syste...
void print(std::ostream &ostr) const
Print the TrapezoidPatch.
Acts::Transform3 toCenter
The transform to move to the outer trapezoid center.
double area() const
Calculates the area in the x-y plane.
TrapezoidPatch(const Acts::Transform3 &trf, std::shared_ptr< const Acts::VolumeBounds > volBounds)
The constructor.
std::shared_ptr< const Acts::VolumeBounds > bounds
Pointer to the volume bounds.