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