Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:38

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2020 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Surfaces/AnnulusBounds.hpp"
0013 #include "Acts/Surfaces/ConeBounds.hpp"
0014 #include "Acts/Surfaces/ConeSurface.hpp"
0015 #include "Acts/Surfaces/ConvexPolygonBounds.hpp"
0016 #include "Acts/Surfaces/CylinderBounds.hpp"
0017 #include "Acts/Surfaces/CylinderSurface.hpp"
0018 #include "Acts/Surfaces/DiamondBounds.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/DiscTrapezoidBounds.hpp"
0021 #include "Acts/Surfaces/EllipseBounds.hpp"
0022 #include "Acts/Surfaces/LineBounds.hpp"
0023 #include "Acts/Surfaces/PlaneSurface.hpp"
0024 #include "Acts/Surfaces/RadialBounds.hpp"
0025 #include "Acts/Surfaces/RectangleBounds.hpp"
0026 #include "Acts/Surfaces/StrawSurface.hpp"
0027 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0028 #include "Acts/Visualization/GeometryView3D.hpp"
0029 #include "Acts/Visualization/IVisualization3D.hpp"
0030 
0031 #include <fstream>
0032 #include <sstream>
0033 #include <string>
0034 
0035 namespace Acts::SurfaceView3DTest {
0036 
0037 /// Helper method to visualize all types of surfaces
0038 ///
0039 /// @param helper The visualization helper
0040 /// @param triangulate The directive whether to create triangular meshes
0041 /// @param tag The test tag (mode) identification
0042 ///
0043 /// @return an overall string including all written output
0044 static inline std::string run(IVisualization3D& helper, bool triangulate,
0045                               const std::string& tag) {
0046   auto gctx = GeometryContext();
0047   auto identity = Transform3::Identity();
0048   std::stringstream cStream;
0049 
0050   double halfPhiSector = M_PI / 4.;
0051   double centralPhi = M_PI / 2.;
0052 
0053   ViewConfig sConfig = s_viewSensitive;
0054   sConfig.triangulate = triangulate;
0055 
0056   //----------------------------------------------------
0057   // Cone Surface section
0058   std::vector<std::shared_ptr<ConeSurface>> coneSurfaces;
0059 
0060   double coneAlpha = 0.245;
0061   double coneMinZ = 0.;
0062   double coneCutZ = 2.;
0063   double coneMaxZ = 10.;
0064   // Full Cone
0065   auto coneBounds =
0066       std::make_shared<ConeBounds>(coneAlpha, -coneCutZ, coneMaxZ);
0067   auto cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0068   coneSurfaces.push_back(cone);
0069   GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0070                               sConfig);
0071   ;
0072   helper.write(std::string("Surfaces_ConeSurface") + tag);
0073   helper.write(cStream);
0074   helper.clear();
0075 
0076   // Sectoral Cone
0077   coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneMinZ, coneMaxZ,
0078                                             halfPhiSector);
0079   cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0080   coneSurfaces.push_back(cone);
0081   GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0082                               sConfig);
0083   ;
0084   helper.write(std::string("Surfaces_ConeSurfaceSector") + tag);
0085   helper.write(cStream);
0086   helper.clear();
0087 
0088   // Sectoral Cone Shifted
0089   coneBounds = std::make_shared<ConeBounds>(coneAlpha, coneCutZ, coneMaxZ,
0090                                             halfPhiSector, centralPhi);
0091   cone = Surface::makeShared<ConeSurface>(identity, coneBounds);
0092   coneSurfaces.push_back(cone);
0093   GeometryView3D::drawSurface(helper, *cone, gctx, Transform3::Identity(),
0094                               sConfig);
0095   ;
0096   helper.write(std::string("Surfaces_ConeSurfaceSectorShifted") + tag);
0097   helper.write(cStream);
0098   helper.clear();
0099 
0100   // All in one for radial bounds
0101   std::vector<Transform3> threeCones = {
0102       Transform3(Translation3{-0.5 * coneMaxZ, 0., 0.}),
0103       Transform3(Translation3{0., 0., 0.}),
0104       Transform3(Translation3{0.75 * coneMaxZ, 0., 0.})};
0105 
0106   for (std::size_t ic = 0; ic < coneSurfaces.size(); ++ic) {
0107     GeometryView3D::drawSurface(helper, *coneSurfaces[ic], gctx, threeCones[ic],
0108                                 sConfig);
0109   }
0110   helper.write(std::string("Surfaces_All_ConeSurfaces") + tag);
0111   helper.write(cStream);
0112   helper.clear();
0113 
0114   //----------------------------------------------------
0115   // Cylinder surface section
0116   std::vector<std::shared_ptr<CylinderSurface>> cylinderSurfaces;
0117 
0118   double cylinderRadius = 5.;
0119   double cylinderHalfZ = 10.;
0120 
0121   // Full Cylinder
0122   auto cylinderBounds =
0123       std::make_shared<CylinderBounds>(cylinderRadius, cylinderHalfZ);
0124   auto cylinder =
0125       Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0126   cylinderSurfaces.push_back(cylinder);
0127   GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0128                               sConfig);
0129   ;
0130   helper.write(std::string("Surfaces_CylinderSurface") + tag);
0131   helper.write(cStream);
0132   helper.clear();
0133 
0134   // Sectoral Cone
0135   cylinderBounds = std::make_shared<CylinderBounds>(
0136       cylinderRadius, cylinderHalfZ, halfPhiSector);
0137   cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0138   cylinderSurfaces.push_back(cylinder);
0139   GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0140                               sConfig);
0141   ;
0142   helper.write(std::string("Surfaces_CylinderSurfaceSector") + tag);
0143   helper.write(cStream);
0144   helper.clear();
0145 
0146   // Sectoral Cone Shifted
0147   cylinderBounds = std::make_shared<CylinderBounds>(
0148       cylinderRadius, cylinderHalfZ, halfPhiSector, centralPhi);
0149   cylinder = Surface::makeShared<CylinderSurface>(identity, cylinderBounds);
0150   cylinderSurfaces.push_back(cylinder);
0151   GeometryView3D::drawSurface(helper, *cylinder, gctx, Transform3::Identity(),
0152                               sConfig);
0153   ;
0154   helper.write(std::string("Surfaces_CylinderSurfaceSectorShifted") + tag);
0155   helper.write(cStream);
0156   helper.clear();
0157 
0158   // All in one for radial bounds
0159   std::vector<Transform3> threeCylinders = {
0160       Transform3(Translation3{-2 * cylinderRadius, 0., 0.}),
0161       Transform3(Translation3{0., 0., 0.}),
0162       Transform3(Translation3{2.5 * cylinderRadius, 0., 0.})};
0163 
0164   for (std::size_t ic = 0; ic < cylinderSurfaces.size(); ++ic) {
0165     GeometryView3D::drawSurface(helper, *cylinderSurfaces[ic], gctx,
0166                                 threeCylinders[ic], sConfig);
0167   }
0168   helper.write(std::string("Surfaces_All_CylinderSurfaces") + tag);
0169   helper.write(cStream);
0170   helper.clear();
0171 
0172   /// ------------- planar bounding box
0173   /// @param name of the file
0174   auto writeBoundingBox2D = [&](const RectangleBounds& rBounds,
0175                                 const std::string& path) -> void {
0176     std::string bbPath = path + tag + "_bbox";
0177 
0178     auto bbBounds = std::make_shared<RectangleBounds>(rBounds);
0179     auto bbSurface = Surface::makeShared<PlaneSurface>(identity, bbBounds);
0180     GeometryView3D::drawSurface(helper, *bbSurface, gctx,
0181                                 Transform3::Identity(), sConfig);
0182     ;
0183     helper.write(bbPath);
0184     helper.write(cStream);
0185     helper.clear();
0186   };
0187 
0188   //----------------------------------------------------
0189   // Disc Surface section
0190 
0191   double discRmin = 5.;
0192   double discRmax = 10.;
0193 
0194   std::vector<std::shared_ptr<DiscSurface>> radialSurfaces;
0195 
0196   // Full Disc
0197   auto radialBounds = std::make_shared<RadialBounds>(0., discRmax);
0198   auto disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0199   radialSurfaces.push_back(disc);
0200   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0201                               sConfig);
0202   ;
0203   helper.write(std::string("Surfaces_DiscSurfaceFull") + tag);
0204   helper.write(cStream);
0205   helper.clear();
0206 
0207   // Full Sectoral Disc
0208   radialBounds = std::make_shared<RadialBounds>(0., discRmax, halfPhiSector);
0209   disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0210   radialSurfaces.push_back(disc);
0211   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0212                               sConfig);
0213 
0214   helper.write(std::string("Surfaces_DiscSurfaceFullSector") + tag);
0215   helper.write(cStream);
0216   helper.clear();
0217 
0218   // Full Sectoral Shifted Disc
0219   radialBounds =
0220       std::make_shared<RadialBounds>(0., discRmax, halfPhiSector, centralPhi);
0221   disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0222   radialSurfaces.push_back(disc);
0223   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0224                               sConfig);
0225 
0226   helper.write(std::string("Surfaces_DiscSurfaceFullSectorShifted") + tag);
0227   helper.write(cStream);
0228   helper.clear();
0229 
0230   // Full Ring
0231   radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax);
0232   disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0233   radialSurfaces.push_back(disc);
0234   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0235                               sConfig);
0236 
0237   helper.write(std::string("Surfaces_DiscSurfaceRing") + tag);
0238   helper.write(cStream);
0239   helper.clear();
0240 
0241   // Full Sectoral Rin g
0242   radialBounds =
0243       std::make_shared<RadialBounds>(discRmin, discRmax, halfPhiSector);
0244   disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0245   radialSurfaces.push_back(disc);
0246   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0247                               sConfig);
0248 
0249   helper.write(std::string("Surfaces_DiscSurfaceRingSector") + tag);
0250   helper.write(cStream);
0251   helper.clear();
0252 
0253   // Full Sectoral Shifted Ring
0254   radialBounds = std::make_shared<RadialBounds>(discRmin, discRmax,
0255                                                 halfPhiSector, centralPhi);
0256   disc = Surface::makeShared<DiscSurface>(identity, radialBounds);
0257   radialSurfaces.push_back(disc);
0258   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0259                               sConfig);
0260 
0261   helper.write(std::string("Surfaces_DiscSurfaceRingSectorShifted") + tag);
0262   helper.write(cStream);
0263   helper.clear();
0264 
0265   // All in one for radial bounds
0266   std::vector<Transform3> sixDiscs = {
0267       Transform3(Translation3{-2.0 * discRmax, 1.5 * discRmax, 0.}),
0268       Transform3(Translation3{0., 1.5 * discRmax, 0.}),
0269       Transform3(Translation3{2.5 * discRmax, 1.5 * discRmax, 0.}),
0270       Transform3(Translation3{-2.0 * discRmax, -1.5 * discRmax, 0.}),
0271       Transform3(Translation3{0., -1.5 * discRmax, 0.}),
0272       Transform3(Translation3{2.5 * discRmax, -1.5 * discRmax, 0.})};
0273   for (std::size_t ir = 0; ir < radialSurfaces.size(); ++ir) {
0274     GeometryView3D::drawSurface(helper, *radialSurfaces[ir], gctx, sixDiscs[ir],
0275                                 sConfig);
0276   }
0277   helper.write(std::string("Surfaces_All_DiscSurfaces_RadialBounds") + tag);
0278   helper.write(cStream);
0279   helper.clear();
0280 
0281   std::vector<std::shared_ptr<DiscSurface>> anomalDiscSurfaces;
0282 
0283   double annulusMinPhi = 0.75;
0284   double annulusMaxPhi = 1.35;
0285   Vector2 offset(-4., 2.);
0286   auto annulus = std::make_shared<AnnulusBounds>(
0287       discRmin, discRmax, annulusMinPhi, annulusMaxPhi, offset);
0288   disc = Surface::makeShared<DiscSurface>(identity, annulus);
0289   anomalDiscSurfaces.push_back(disc);
0290   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0291                               sConfig);
0292 
0293   helper.write(std::string("Surfaces_DiscAnnulusBounds") + tag);
0294   helper.write(cStream);
0295   helper.clear();
0296 
0297   double discTrapezoidHxRmin = 3.;
0298   double discTrapezoidHxRmax = 6.;
0299   auto discTrapezoid = std::make_shared<DiscTrapezoidBounds>(
0300       discTrapezoidHxRmin, discTrapezoidHxRmax, discRmin, discRmax);
0301   disc = Surface::makeShared<DiscSurface>(identity, discTrapezoid);
0302   anomalDiscSurfaces.push_back(disc);
0303   GeometryView3D::drawSurface(helper, *disc, gctx, Transform3::Identity(),
0304                               sConfig);
0305 
0306   helper.write(std::string("Surfaces_DiscTrapezoidBounds") + tag);
0307   helper.write(cStream);
0308   helper.clear();
0309 
0310   // All in one for radial bounds
0311   std::vector<Transform3> twoAnomalDiscs = {
0312       Transform3(Translation3{-5., 0., 0.}),
0313       Transform3(Translation3{5., 0., 0.})};
0314   for (std::size_t id = 0; id < anomalDiscSurfaces.size(); ++id) {
0315     GeometryView3D::drawSurface(helper, *anomalDiscSurfaces[id], gctx,
0316                                 sixDiscs[id], sConfig);
0317   }
0318   helper.write(std::string("Surfaces_All_DiscSurfaces_AnomalBounds") + tag);
0319   helper.write(cStream);
0320   helper.clear();
0321 
0322   //----------------------------------------------------
0323   // Plane Surface section
0324   std::vector<std::shared_ptr<PlaneSurface>> planarSurfaces;
0325 
0326   // Ellipse shaped : Full Ellipse
0327   double ellipseR0min = 2;
0328   double ellipseR0max = 4;
0329   double ellipseR1min = 3;
0330   double ellipseR1max = 6;
0331   std::string name = "Surfaces_PlaneSurfaceEllipse";
0332   auto ellipse =
0333       std::make_shared<EllipseBounds>(0., 0., ellipseR1min, ellipseR1max);
0334   auto plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0335   planarSurfaces.push_back(plane);
0336   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0337                               sConfig);
0338   ;
0339   helper.write(name + tag);
0340   helper.write(cStream);
0341   helper.clear();
0342   writeBoundingBox2D(ellipse->boundingBox(), name);
0343 
0344   // Ellipse shaped : Ring Ellipse
0345   name = "Surfaces_PlaneSurfaceEllipseRing";
0346   ellipse = std::make_shared<EllipseBounds>(ellipseR0min, ellipseR0max,
0347                                             ellipseR1min, ellipseR1max);
0348   plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0349   planarSurfaces.push_back(plane);
0350   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0351                               sConfig);
0352   ;
0353   helper.write(name + tag);
0354   helper.write(cStream);
0355   helper.clear();
0356   writeBoundingBox2D(ellipse->boundingBox(), name);
0357 
0358   // Ellipse shaped : Ring Ellipse Sector
0359   name = "Surfaces_PlaneSurfaceEllipseRingSector";
0360   ellipse = std::make_shared<EllipseBounds>(
0361       ellipseR0min, ellipseR0max, ellipseR1min, ellipseR1max, halfPhiSector);
0362   plane = Surface::makeShared<PlaneSurface>(identity, ellipse);
0363   planarSurfaces.push_back(plane);
0364   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0365                               sConfig);
0366   ;
0367   helper.write(name + tag);
0368   helper.write(cStream);
0369   helper.clear();
0370   writeBoundingBox2D(ellipse->boundingBox(), name);
0371 
0372   // ConvexPolygon shaped example: Triangle
0373   name = "Surfaces_PlaneSurfaceTriangleRegular";
0374   std::vector<Vector2> tvertices = {{-3, -1.5}, {3, -1.5}, {0, 4.5}};
0375   auto triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
0376   plane = Surface::makeShared<PlaneSurface>(identity, triangle);
0377   planarSurfaces.push_back(plane);
0378   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0379                               sConfig);
0380   ;
0381   helper.write(name + tag);
0382   helper.write(cStream);
0383   helper.clear();
0384   writeBoundingBox2D(triangle->boundingBox(), name);
0385 
0386   // ConvexPolygon shaped example: Triangle
0387   name = "Surfaces_PlaneSurfaceTriangleGeneral";
0388   tvertices = {{-1., 4.5}, {4, 6.5}, {3, 8.5}};
0389   triangle = std::make_shared<ConvexPolygonBounds<3>>(tvertices);
0390   plane = Surface::makeShared<PlaneSurface>(identity, triangle);
0391   planarSurfaces.push_back(plane);
0392   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0393                               sConfig);
0394 
0395   helper.write(name + tag);
0396   helper.write(cStream);
0397   helper.clear();
0398   writeBoundingBox2D(triangle->boundingBox(), name);
0399 
0400   // ConvexPolygon shaped example: Triangle
0401   name = "Surfaces_PlaneSurfaceConvexPolygonGeneral";
0402   tvertices = {{-1., 4.5}, {4, 6.5}, {6, 8.5}, {0, 10.5}, {-3, 6.2}};
0403   auto dynamicpolygon =
0404       std::make_shared<ConvexPolygonBounds<PolygonDynamic>>(tvertices);
0405   plane = Surface::makeShared<PlaneSurface>(identity, dynamicpolygon);
0406   planarSurfaces.push_back(plane);
0407   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0408                               sConfig);
0409 
0410   helper.write(name + tag);
0411   helper.write(cStream);
0412   helper.clear();
0413   writeBoundingBox2D(dynamicpolygon->boundingBox(), name);
0414 
0415   // Diamond shaped
0416   name = "Surfaces_PlaneSurfaceDiamond";
0417   auto diamond = std::make_shared<DiamondBounds>(3., 6., 2., 2., 4.);
0418   plane = Surface::makeShared<PlaneSurface>(identity, diamond);
0419   planarSurfaces.push_back(plane);
0420   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0421                               sConfig);
0422 
0423   helper.write(name + tag);
0424   helper.write(cStream);
0425   helper.clear();
0426   writeBoundingBox2D(diamond->boundingBox(), name);
0427 
0428   // Rectangle plane
0429   name = "Surfaces_PlaneSurfaceRectangle";
0430   auto rectangle = std::make_shared<RectangleBounds>(2., 3.);
0431   plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
0432   planarSurfaces.push_back(plane);
0433   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0434                               sConfig);
0435 
0436   helper.write(name + tag);
0437   helper.write(cStream);
0438   helper.clear();
0439   writeBoundingBox2D(rectangle->boundingBox(), name);
0440 
0441   // Off-centered Rectangle plane:
0442   name = "Surfaces_PlaneSurfaceRectangleOffcentered";
0443   rectangle =
0444       std::make_shared<RectangleBounds>(Vector2{1., 2.}, Vector2{15., 12.});
0445   plane = Surface::makeShared<PlaneSurface>(identity, rectangle);
0446   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0447                               sConfig);
0448 
0449   helper.write(name + tag);
0450   helper.write(cStream);
0451   helper.clear();
0452   writeBoundingBox2D(rectangle->boundingBox(), name);
0453 
0454   // Trapezoidal plane:
0455   name = "Surfaces_PlaneSurfaceTrapezoid";
0456   auto trapezoid = std::make_shared<TrapezoidBounds>(2., 5., 3.);
0457   plane = Surface::makeShared<PlaneSurface>(identity, trapezoid);
0458   planarSurfaces.push_back(plane);
0459   GeometryView3D::drawSurface(helper, *plane, gctx, Transform3::Identity(),
0460                               sConfig);
0461 
0462   helper.write(name + tag);
0463   helper.write(cStream);
0464   helper.clear();
0465   writeBoundingBox2D(trapezoid->boundingBox(), name);
0466 
0467   // All planes
0468   std::vector<Transform3> ninePlanes = {
0469       Transform3(Translation3{-10., -10., 0.}),
0470       Transform3(Translation3{0., -10., 0.}),
0471       Transform3(Translation3{10., -10., 0.}),
0472       Transform3(Translation3{-10., 0., 0.}),
0473       Transform3(Translation3{0., -6., 0.}),
0474       Transform3(Translation3{10., -8., 0.}),
0475       Transform3(Translation3{-10, 10., 0.}),
0476       Transform3(Translation3{0., 10., 0.}),
0477       Transform3(Translation3{10., 10., 0.})};
0478   for (std::size_t ip = 0; ip < planarSurfaces.size(); ++ip) {
0479     GeometryView3D::drawSurface(helper, *planarSurfaces[ip], gctx,
0480                                 ninePlanes[ip], sConfig);
0481   }
0482   helper.write(std::string("Surfaces_All_PlaneSurfaces") + tag);
0483   helper.write(cStream);
0484   helper.clear();
0485 
0486   //----------------------------------------------------
0487   // Straw Surface section
0488   name = "Surfaces_StrawSurface";
0489   auto tube = std::make_shared<LineBounds>(2., 20.);
0490   auto straw = Surface::makeShared<StrawSurface>(identity, tube);
0491   GeometryView3D::drawSurface(helper, *straw, gctx, Transform3::Identity(),
0492                               sConfig);
0493 
0494   helper.write(name + tag);
0495   helper.write(cStream);
0496   helper.clear();
0497 
0498   return cStream.str();
0499 }
0500 
0501 }  // namespace Acts::SurfaceView3DTest