File indexing completed on 2025-01-18 09:13:01
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/EventData/GenericBoundTrackParameters.hpp"
0015 #include "Acts/EventData/TrackParameters.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Surfaces/PerigeeSurface.hpp"
0018 #include "Acts/Surfaces/Surface.hpp"
0019 #include "Acts/Utilities/Result.hpp"
0020 #include "Acts/Vertexing/GaussianGridTrackDensity.hpp"
0021
0022 #include <algorithm>
0023 #include <cstddef>
0024 #include <memory>
0025 #include <optional>
0026 #include <utility>
0027
0028 using namespace Acts::UnitLiterals;
0029
0030 namespace Acts::Test {
0031
0032 using Covariance = BoundSquareMatrix;
0033
0034
0035 GeometryContext geoContext = GeometryContext();
0036
0037 BOOST_AUTO_TEST_CASE(gaussian_grid_density_test) {
0038
0039 constexpr std::size_t mainGridSize = 400;
0040 constexpr std::size_t trkGridSize = 15;
0041
0042 using Grid = GaussianGridTrackDensity;
0043
0044 double binSize = 0.1;
0045 double zMinMax = mainGridSize / 2 * binSize;
0046
0047
0048 Grid::Config cfg(zMinMax, mainGridSize, trkGridSize);
0049 Grid grid(cfg);
0050
0051
0052 Covariance covMat;
0053 covMat << 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
0054 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1;
0055
0056 BoundVector paramVec1;
0057 paramVec1 << 0.01, 0.15, 0, 0, 0, 0;
0058
0059 BoundVector paramVec2;
0060 paramVec2 << trkGridSize * binSize - 0.1, 0.15, 0, 0, 0, 0;
0061
0062 BoundVector paramVec3;
0063 paramVec3 << trkGridSize * binSize + 0.01, 0.15, 0, 0, 0, 0;
0064
0065 BoundVector paramVec3_1;
0066 paramVec3_1 << -(trkGridSize * binSize + 0.01), 0.15, 0, 0, 0, 0;
0067
0068 BoundVector paramVec4;
0069 paramVec4 << 0.01, 19.95, 0, 0, 0, 0;
0070
0071 BoundVector paramVec5;
0072 paramVec5 << 0.01, -19.95, 0, 0, 0, 0;
0073
0074 BoundVector paramVec6;
0075 paramVec6 << 0.01, -100.0, 0, 0, 0, 0;
0076
0077 BoundVector paramVec7;
0078 paramVec7 << 0.01, +100.0, 0, 0, 0, 0;
0079
0080
0081 std::shared_ptr<PerigeeSurface> perigeeSurface =
0082 Surface::makeShared<PerigeeSurface>(Vector3(0., 0., 0.));
0083
0084 BoundTrackParameters params1(perigeeSurface, paramVec1, covMat,
0085 ParticleHypothesis::pion());
0086 BoundTrackParameters params2(perigeeSurface, paramVec2, covMat,
0087 ParticleHypothesis::pion());
0088 BoundTrackParameters params3(perigeeSurface, paramVec3, covMat,
0089 ParticleHypothesis::pion());
0090 BoundTrackParameters params3_1(perigeeSurface, paramVec3_1, covMat,
0091 ParticleHypothesis::pion());
0092 BoundTrackParameters params4(perigeeSurface, paramVec4, covMat,
0093 ParticleHypothesis::pion());
0094 BoundTrackParameters params5(perigeeSurface, paramVec5, covMat,
0095 ParticleHypothesis::pion());
0096 BoundTrackParameters params6(perigeeSurface, paramVec6, covMat,
0097 ParticleHypothesis::pion());
0098 BoundTrackParameters params7(perigeeSurface, paramVec7, covMat,
0099 ParticleHypothesis::pion());
0100
0101
0102 Grid::MainGridVector mainGrid = Grid::MainGridVector::Zero(mainGridSize);
0103
0104
0105
0106 std::pair<int, Grid::TrackGridVector> binAndTrackGrid;
0107
0108
0109 binAndTrackGrid = grid.addTrack(params3, mainGrid);
0110 binAndTrackGrid = grid.addTrack(params3_1, mainGrid);
0111
0112 binAndTrackGrid = grid.addTrack(params6, mainGrid);
0113 binAndTrackGrid = grid.addTrack(params7, mainGrid);
0114
0115
0116
0117 auto zeroGrid = Grid::MainGridVector::Zero(mainGridSize);
0118 BOOST_CHECK_EQUAL(mainGrid, zeroGrid);
0119
0120
0121 binAndTrackGrid = grid.addTrack(params1, mainGrid);
0122 auto gridCopy = mainGrid;
0123
0124 mainGrid = Grid::MainGridVector::Zero(mainGridSize);
0125 binAndTrackGrid = grid.addTrack(params2, mainGrid);
0126
0127
0128
0129 BOOST_CHECK_GT(gridCopy.sum(), mainGrid.sum());
0130
0131
0132
0133 binAndTrackGrid = grid.addTrack(params1, mainGrid);
0134 BOOST_CHECK_EQUAL(gridCopy.sum(), mainGrid.sum());
0135
0136 binAndTrackGrid = grid.addTrack(params4, mainGrid);
0137
0138
0139 BOOST_CHECK_EQUAL(
0140 mainGrid(mainGridSize - static_cast<int>((trkGridSize - 1) / 2) - 2), 0.);
0141 BOOST_CHECK_GT(
0142 mainGrid(mainGridSize - static_cast<int>((trkGridSize - 1) / 2) - 1), 0.);
0143 BOOST_CHECK_GT(mainGrid(mainGridSize - 1), 0.);
0144
0145 binAndTrackGrid = grid.addTrack(params5, mainGrid);
0146
0147 BOOST_CHECK_EQUAL(mainGrid(static_cast<int>((trkGridSize - 1) / 2) + 1), 0.);
0148 BOOST_CHECK_GT(mainGrid(static_cast<int>((trkGridSize - 1) / 2)), 0.);
0149 BOOST_CHECK_GT(mainGrid(0), 0.);
0150
0151
0152 auto maxRes = grid.getMaxZPosition(mainGrid);
0153 int maxBin = static_cast<int>((*maxRes / binSize) + mainGridSize / 2);
0154 BOOST_CHECK_EQUAL(maxBin, 0);
0155
0156
0157 mainGrid = Grid::MainGridVector::Zero(mainGridSize);
0158 auto maxResErr = grid.getMaxZPosition(mainGrid);
0159 BOOST_CHECK(!maxResErr.ok());
0160
0161
0162 binAndTrackGrid = grid.addTrack(params1, mainGrid);
0163 binAndTrackGrid = grid.addTrack(params2, mainGrid);
0164
0165 gridCopy = mainGrid;
0166 binAndTrackGrid = grid.addTrack(params4, mainGrid);
0167
0168 BOOST_CHECK_NE(gridCopy, mainGrid);
0169
0170 int zBin = binAndTrackGrid.first;
0171 auto trackGrid = binAndTrackGrid.second;
0172 grid.removeTrackGridFromMainGrid(zBin, trackGrid, mainGrid);
0173
0174 BOOST_CHECK_EQUAL(gridCopy, mainGrid);
0175 }
0176
0177
0178 BOOST_AUTO_TEST_CASE(gaussian_grid_sum_max_densitytest) {
0179
0180 constexpr int mainGridSize = 50;
0181 constexpr int trkGridSize = 11;
0182
0183 using Grid = Acts::GaussianGridTrackDensity;
0184
0185 double binSize = 0.1;
0186 double zMinMax = mainGridSize / 2 * binSize;
0187
0188
0189 Grid::Config cfg(zMinMax, mainGridSize, trkGridSize);
0190 cfg.useHighestSumZPosition = true;
0191 Grid grid(cfg);
0192
0193
0194 Covariance covMat;
0195 covMat << 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0,
0196 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2;
0197
0198 const double posZ1 = -1.75;
0199 const double posZ2 = 1.75;
0200
0201
0202
0203 BoundVector paramVec1;
0204 paramVec1 << 0.01, posZ1, 0, 0, 0, 0;
0205 BoundVector paramVec2;
0206 paramVec2 << 0.015, posZ2, 0, 0, 0, 0;
0207
0208
0209 std::shared_ptr<PerigeeSurface> perigeeSurface =
0210 Surface::makeShared<PerigeeSurface>(Vector3(0., 0., 0.));
0211
0212 BoundTrackParameters params1(perigeeSurface, paramVec1, covMat,
0213 ParticleHypothesis::pion());
0214 BoundTrackParameters params2(perigeeSurface, paramVec2, covMat,
0215 ParticleHypothesis::pion());
0216
0217
0218 Grid::MainGridVector mainGrid = Grid::MainGridVector::Zero(mainGridSize);
0219
0220
0221
0222 std::pair<int, Grid::TrackGridVector> binAndTrackGrid;
0223
0224 binAndTrackGrid = grid.addTrack(params1, mainGrid);
0225 binAndTrackGrid = grid.addTrack(params2, mainGrid);
0226
0227
0228 int maxZbin = static_cast<int>((posZ2 / binSize + mainGridSize / 2.));
0229 mainGrid(maxZbin - 1) += 1;
0230 mainGrid(maxZbin + 1) += 1;
0231
0232
0233
0234
0235 auto maxRes = grid.getMaxZPosition(mainGrid);
0236 BOOST_CHECK(maxRes.ok());
0237 BOOST_CHECK_EQUAL(*maxRes, posZ2);
0238 }
0239
0240
0241 BOOST_AUTO_TEST_CASE(gaussian_grid_seed_width_test) {
0242
0243 constexpr int mainGridSize = 50;
0244 constexpr int trkGridSize = 11;
0245
0246 using Grid = Acts::GaussianGridTrackDensity;
0247
0248 double binSize = 0.1;
0249 double zMinMax = mainGridSize / 2 * binSize;
0250
0251
0252 Grid::Config cfg(zMinMax, mainGridSize, trkGridSize);
0253 cfg.useHighestSumZPosition = true;
0254 Grid grid(cfg);
0255
0256
0257 Covariance covMat;
0258 covMat << 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0,
0259 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2, 0, 0, 0, 0, 0, 0, 1e-2;
0260
0261 const double posZ1 = -1.75;
0262 const double posZ2 = 1.75;
0263
0264
0265
0266 BoundVector paramVec1;
0267 paramVec1 << 0.01, posZ1, 0, 0, 0, 0;
0268 BoundVector paramVec2;
0269 paramVec2 << 0.015, posZ2, 0, 0, 0, 0;
0270
0271
0272 std::shared_ptr<PerigeeSurface> perigeeSurface =
0273 Surface::makeShared<PerigeeSurface>(Vector3(0., 0., 0.));
0274
0275 BoundTrackParameters params1(perigeeSurface, paramVec1, covMat,
0276 ParticleHypothesis::pion());
0277 BoundTrackParameters params2(perigeeSurface, paramVec2, covMat,
0278 ParticleHypothesis::pion());
0279
0280
0281 Grid::MainGridVector mainGrid = Grid::MainGridVector::Zero(mainGridSize);
0282
0283
0284
0285 std::pair<int, Grid::TrackGridVector> binAndTrackGrid;
0286
0287 binAndTrackGrid = grid.addTrack(params1, mainGrid);
0288 binAndTrackGrid = grid.addTrack(params2, mainGrid);
0289
0290
0291 int maxZbin = static_cast<int>((posZ2 / binSize + mainGridSize / 2.));
0292 mainGrid(maxZbin - 1) += 1;
0293 mainGrid(maxZbin + 1) += 1;
0294
0295
0296
0297
0298
0299 auto maxRes = grid.getMaxZPositionAndWidth(mainGrid);
0300 BOOST_CHECK(maxRes.ok());
0301 double z = (*maxRes).first;
0302 double width = (*maxRes).second;
0303
0304 BOOST_CHECK_EQUAL(z, posZ2);
0305
0306 BOOST_CHECK_NE(width, 0.);
0307 }
0308
0309 }