File indexing completed on 2026-09-14 08:18:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/AnyTrackProxy.hpp"
0014 #include "Acts/EventData/ParticleHypothesis.hpp"
0015 #include "Acts/EventData/TrackContainer.hpp"
0016 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0017 #include "Acts/EventData/VectorTrackContainer.hpp"
0018 #include "Acts/Geometry/GeometryContext.hpp"
0019 #include "Acts/Geometry/Polyhedron.hpp"
0020 #include "Acts/Surfaces/Surface.hpp"
0021 #include "Acts/Visualization/GeometryView3D.hpp"
0022 #include "Acts/Visualization/IVisualization3D.hpp"
0023 #include "Acts/Visualization/ViewConfig.hpp"
0024
0025 #include <array>
0026 #include <cmath>
0027 #include <cstddef>
0028 #include <numbers>
0029 #include <vector>
0030
0031 namespace Acts {
0032 class IVisualization3D;
0033
0034
0035 static ViewConfig s_viewParameter = {.color = {0, 0, 255}};
0036
0037 static ViewConfig s_viewMeasurement = {.color = {255, 102, 0}};
0038
0039 static ViewConfig s_viewPredicted = {.color = {51, 204, 51}};
0040
0041 static ViewConfig s_viewFiltered = {.color = {255, 255, 0}};
0042
0043 static ViewConfig s_viewSmoothed = {.color = {0, 102, 25}};
0044
0045
0046 struct EventDataView3D {
0047
0048
0049
0050
0051 static inline std::array<double, 3> decomposeCovariance(
0052 const SquareMatrix<2>& covariance) {
0053 double c00 = covariance(eBoundLoc0, eBoundLoc0);
0054 double c01 = covariance(eBoundLoc0, eBoundLoc1);
0055 double c11 = covariance(eBoundLoc1, eBoundLoc1);
0056
0057 double cdsq = std::pow((c00 - c11), 2) / 4.;
0058 double cosq = c01 * c01;
0059
0060
0061 double lambda0 = (c00 + c11) / 2. + std::sqrt(cdsq + cosq);
0062 double lambda1 = (c00 + c11) / 2. - std::sqrt(cdsq + cosq);
0063 double theta = std::atan2(lambda0 - c00, c01);
0064
0065 return {lambda0, lambda1, theta};
0066 }
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 static inline std::vector<Vector3> createEllipse(
0079 double lambda0, double lambda1, double theta, std::size_t lseg,
0080 double offset, const Vector2& lposition = Vector2(0., 0.),
0081 const Transform3& transform = Transform3::Identity()) {
0082 double ctheta = std::cos(theta);
0083 double stheta = std::sin(theta);
0084
0085 double l1sq = std::sqrt(lambda0);
0086 double l2sq = std::sqrt(lambda1);
0087
0088
0089 std::vector<Vector3> ellipse;
0090 ellipse.reserve(lseg);
0091 double thetaStep = 2 * std::numbers::pi / lseg;
0092 for (std::size_t it = 0; it < lseg; ++it) {
0093 double phi = -std::numbers::pi + it * thetaStep;
0094 double cphi = std::cos(phi);
0095 double sphi = std::sin(phi);
0096 double x = lposition.x() + (l1sq * ctheta * cphi - l2sq * stheta * sphi);
0097 double y = lposition.y() + (l1sq * stheta * cphi + l2sq * ctheta * sphi);
0098 ellipse.push_back(transform * Vector3(x, y, offset));
0099 }
0100 return ellipse;
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 static void drawCovarianceCartesian(
0112 IVisualization3D& helper, const Vector2& lposition,
0113 const SquareMatrix2& covariance, const Transform3& transform,
0114 double locErrorScale = 1, const ViewConfig& viewConfig = s_viewParameter);
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 static void drawCovarianceAngular(
0126 IVisualization3D& helper, const Vector3& position,
0127 const Vector3& direction, const SquareMatrix<2>& covariance,
0128 double directionScale = 1, double angularErrorScale = 1,
0129 const ViewConfig& viewConfig = s_viewParameter);
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 template <typename parameters_t>
0143 static inline void drawBoundTrackParameters(
0144 IVisualization3D& helper, const parameters_t& parameters,
0145 const GeometryContext& gctx =
0146 GeometryContext::dangerouslyDefaultConstruct(),
0147 double momentumScale = 1., double locErrorScale = 1.,
0148 double angularErrorScale = 1.,
0149 const ViewConfig& parConfig = s_viewParameter,
0150 const ViewConfig& covConfig = s_viewParameter,
0151 const ViewConfig& surfConfig = s_viewSensitive) {
0152 if (surfConfig.visible) {
0153 GeometryView3D::drawSurface(helper, parameters.referenceSurface(), gctx,
0154 Transform3::Identity(), surfConfig);
0155 }
0156
0157
0158 auto position = parameters.position(gctx);
0159 auto direction = parameters.direction();
0160 double p = parameters.absoluteMomentum();
0161
0162 ViewConfig lparConfig = parConfig;
0163 lparConfig.lineThickness = 0.05;
0164 Vector3 parLength = p * momentumScale * direction;
0165
0166 GeometryView3D::drawArrowBackward(
0167 helper, position, position + 0.5 * parLength, 100., 1.0, lparConfig);
0168
0169 GeometryView3D::drawArrowForward(helper, position + 0.5 * parLength,
0170 position + parLength, 4., 2.5, lparConfig);
0171
0172 if (parameters.covariance().has_value()) {
0173 auto paramVec = parameters.parameters();
0174 auto lposition = paramVec.template block<2, 1>(0, 0);
0175
0176
0177 const auto& covariance = *parameters.covariance();
0178 drawCovarianceCartesian(
0179 helper, lposition, covariance.template block<2, 2>(0, 0),
0180 parameters.referenceSurface().localToGlobalTransform(gctx),
0181 locErrorScale, covConfig);
0182
0183 drawCovarianceAngular(
0184 helper, position, direction, covariance.template block<2, 2>(2, 2),
0185 0.9 * p * momentumScale, angularErrorScale, covConfig);
0186 }
0187 }
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 static void drawMeasurement(
0200 IVisualization3D& helper, const Vector2& lposition,
0201 const SquareMatrix2& covariance, const Transform3& transform,
0202 const double locErrorScale = 1.,
0203 const ViewConfig& measurementConfig = s_viewMeasurement) {
0204 if (locErrorScale <= 0) {
0205 throw std::invalid_argument("locErrorScale must be > 0");
0206 }
0207 if (measurementConfig.visible) {
0208 drawCovarianceCartesian(helper, lposition, covariance, transform,
0209 locErrorScale, measurementConfig);
0210 }
0211 }
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 template <typename traj_t>
0231 static void drawMultiTrajectory(
0232 IVisualization3D& helper, const traj_t& multiTraj,
0233 const std::size_t& entryIndex,
0234 const GeometryContext& gctx =
0235 GeometryContext::dangerouslyDefaultConstruct(),
0236 double momentumScale = 1., double locErrorScale = 1.,
0237 double angularErrorScale = 1.,
0238 const ViewConfig& surfaceConfig = s_viewSensitive,
0239 const ViewConfig& measurementConfig = s_viewMeasurement,
0240 const ViewConfig& predictedConfig = s_viewPredicted,
0241 const ViewConfig& filteredConfig = s_viewFiltered,
0242 const ViewConfig& smoothedConfig = s_viewSmoothed) {
0243
0244
0245
0246 ParticleHypothesis particleHypothesis = ParticleHypothesis::pion();
0247
0248
0249 multiTraj.visitBackwards(entryIndex, [&](const auto& state) {
0250
0251 if (!state.typeFlags().hasMeasurement()) {
0252 return true;
0253 }
0254
0255
0256
0257 if (state.index() == 0) {
0258 locErrorScale = locErrorScale * 0.1;
0259 angularErrorScale = angularErrorScale * 0.1;
0260 }
0261
0262
0263 if (surfaceConfig.visible) {
0264 GeometryView3D::drawSurface(helper, state.referenceSurface(), gctx,
0265 Transform3::Identity(), surfaceConfig);
0266 }
0267
0268
0269
0270
0271 if (state.hasCalibrated() && state.calibratedSize() == 2) {
0272 const Vector2& lposition = state.template calibrated<2>();
0273 const SquareMatrix2 covariance =
0274 state.template calibratedCovariance<2>();
0275 drawMeasurement(helper, lposition, covariance,
0276 state.referenceSurface().localToGlobalTransform(gctx),
0277 locErrorScale, measurementConfig);
0278 }
0279
0280
0281
0282 if (predictedConfig.visible && state.hasPredicted()) {
0283 drawBoundTrackParameters(
0284 helper,
0285 BoundTrackParameters(state.referenceSurface().getSharedPtr(),
0286 state.predicted(), state.predictedCovariance(),
0287 particleHypothesis),
0288 gctx, momentumScale, locErrorScale, angularErrorScale,
0289 predictedConfig, predictedConfig, {.visible = false});
0290 }
0291
0292 if (filteredConfig.visible && state.hasFiltered()) {
0293 drawBoundTrackParameters(
0294 helper,
0295 BoundTrackParameters(state.referenceSurface().getSharedPtr(),
0296 state.filtered(), state.filteredCovariance(),
0297 particleHypothesis),
0298 gctx, momentumScale, locErrorScale, angularErrorScale,
0299 filteredConfig, filteredConfig, {.visible = false});
0300 }
0301
0302 if (smoothedConfig.visible && state.hasSmoothed()) {
0303 drawBoundTrackParameters(
0304 helper,
0305 BoundTrackParameters(state.referenceSurface().getSharedPtr(),
0306 state.smoothed(), state.smoothedCovariance(),
0307 particleHypothesis),
0308 gctx, momentumScale, locErrorScale, angularErrorScale,
0309 smoothedConfig, smoothedConfig, {.visible = false});
0310 }
0311 return true;
0312 });
0313 }
0314
0315
0316
0317
0318
0319
0320 static void drawTrack(IVisualization3D& helper,
0321 const AnyConstTrackProxy& track,
0322 const GeometryContext& gctx);
0323 };
0324
0325 }