Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 08:28:05

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Visualization/EventDataView3D.hpp"
0010 
0011 #include "Acts/Geometry/Polyhedron.hpp"
0012 #include "Acts/Surfaces/detail/FacesHelper.hpp"
0013 #include "Acts/Utilities/Helpers.hpp"
0014 
0015 #include <cmath>
0016 #include <utility>
0017 
0018 namespace Acts {
0019 class IVisualization3D;
0020 }  // namespace Acts
0021 
0022 void Acts::EventDataView3D::drawCovarianceCartesian(
0023     IVisualization3D& helper, const Vector2& lposition,
0024     const SquareMatrix2& covariance, const Transform3& transform,
0025     double locErrorScale, const ViewConfig& viewConfig) {
0026   auto [lambda0, lambda1, theta] = decomposeCovariance(covariance);
0027 
0028   std::vector<Vector3> ellipse = createEllipse(
0029       lambda0 * locErrorScale, lambda1 * locErrorScale, theta,
0030       viewConfig.quarterSegments, viewConfig.offset, lposition, transform);
0031 
0032   ellipse.push_back(transform *
0033                     Vector3(lposition.x(), lposition.y(), viewConfig.offset));
0034   auto [faces, triangularMesh] =
0035       detail::FacesHelper::convexFaceMesh(ellipse, true);
0036   Polyhedron ellipseHedron(ellipse, faces, triangularMesh);
0037   Acts::GeometryView3D::drawPolyhedron(helper, ellipseHedron, viewConfig);
0038 }
0039 
0040 void Acts::EventDataView3D::drawCovarianceAngular(
0041     IVisualization3D& helper, const Vector3& position, const Vector3& direction,
0042     const SquareMatrix<2>& covariance, double directionScale,
0043     double angularErrorScale, const ViewConfig& viewConfig) {
0044   auto [lambda0, lambda1, theta] = decomposeCovariance(covariance);
0045 
0046   // Anker point
0047   Vector3 anker = position + directionScale * direction;
0048 
0049   double dphi = VectorHelpers::phi(direction);
0050   double dtheta = VectorHelpers::theta(direction);
0051 
0052   Transform3 eplane(Translation3(anker) *
0053                     AngleAxis3(dphi, Vector3(0., 0., 1.)) *
0054                     AngleAxis3(dtheta, Vector3(0., 1., 0.)));
0055 
0056   // Now generate the ellipse points
0057   std::vector<Vector3> ellipse = createEllipse(
0058       angularErrorScale * directionScale * lambda0 * std::sin(dtheta),
0059       angularErrorScale * directionScale * lambda1, theta,
0060       viewConfig.quarterSegments, 0., {0., 0.}, eplane);
0061 
0062   std::vector<Vector3> coneTop = ellipse;
0063   coneTop.push_back(anker);
0064   auto [faces, triangularMesh] =
0065       detail::FacesHelper::convexFaceMesh(coneTop, true);
0066   Polyhedron coneTopHedron(coneTop, faces, triangularMesh);
0067   GeometryView3D::drawPolyhedron(helper, coneTopHedron, viewConfig);
0068 
0069   std::vector<Vector3> cone = ellipse;
0070   cone.push_back(position);
0071   // Force triangular
0072   ViewConfig coneViewConfig = viewConfig;
0073   coneViewConfig.triangulate = true;
0074   auto [facesCone, triangularMeshCone] =
0075       detail::FacesHelper::convexFaceMesh(cone, true);
0076   Polyhedron coneHedron(cone, facesCone, triangularMeshCone);
0077   GeometryView3D::drawPolyhedron(helper, coneHedron, coneViewConfig);
0078 }
0079 
0080 void Acts::EventDataView3D::drawTrack(IVisualization3D& helper,
0081                                       const AnyConstTrackProxy& track,
0082                                       const GeometryContext& gctx) {
0083   /// auto track = trackcontainer.getTrack(itrack); /// Need to change this to
0084   /// tacke ConstTrackProxy directly
0085   auto tparams = track.parameters();
0086   auto tphi = tparams[eBoundPhi];
0087   auto ttheta = tparams[eBoundTheta];
0088   Vector2 tlocpos{tparams[eBoundLoc0], tparams[eBoundLoc1]};
0089   Vector3 tlocdir{std::sin(ttheta) * std::cos(tphi),
0090                   std::sin(ttheta) * std::sin(tphi), std::cos(ttheta)};
0091 
0092   auto& rs = track.referenceSurface();
0093   auto tglobpos = rs.localToGlobal(gctx, tlocpos, tlocdir);
0094 
0095   auto previouspos = tglobpos;
0096 
0097   for (auto ts : track.trackStatesReversed()) {
0098     auto params = ts.parameters();
0099     auto phi = params[eBoundPhi];
0100     auto theta = params[eBoundTheta];
0101     Vector2 locpos{params[eBoundLoc0], params[eBoundLoc1]};
0102     Vector3 locdir{std::sin(theta) * std::cos(phi),
0103                    std::sin(theta) * std::sin(phi), std::cos(theta)};
0104     auto& s = ts.referenceSurface();
0105     auto currentpos = s.localToGlobal(gctx, locpos, locdir);
0106 
0107     helper.line(previouspos, currentpos);
0108     previouspos = currentpos;
0109   }
0110 }