File indexing completed on 2025-01-18 09:12:30
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/AmbiguityResolution/ScoreBasedAmbiguityResolution.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/EventData/MultiTrajectory.hpp"
0014 #include "Acts/EventData/TrackContainer.hpp"
0015 #include "Acts/EventData/TrackParameters.hpp"
0016 #include "Acts/EventData/TrackStatePropMask.hpp"
0017 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0018 #include "Acts/EventData/VectorTrackContainer.hpp"
0019 #include "Acts/EventData/detail/TestSourceLink.hpp"
0020 #include "Acts/EventData/detail/TestTrackState.hpp"
0021 #include "Acts/Utilities/TrackHelpers.hpp"
0022
0023 #include <map>
0024
0025 using Acts::MultiTrajectoryTraits::IndexType;
0026
0027 namespace Acts::Test {
0028
0029 BOOST_AUTO_TEST_SUITE(ScoreBasedAmbiguityResolutionTest)
0030
0031
0032 struct Fixture {
0033 ScoreBasedAmbiguityResolution::Config config;
0034
0035 using TrackFeatures = ScoreBasedAmbiguityResolution::TrackFeatures;
0036 using DetectorConfig = ScoreBasedAmbiguityResolution::DetectorConfig;
0037
0038 Fixture() {
0039
0040 config.volumeMap = {{8, 0}, {9, 0}, {10, 0}, {13, 0}, {14, 0},
0041 {15, 0}, {16, 0}, {17, 0}, {18, 0}, {19, 0},
0042 {20, 0}, {22, 1}, {23, 1}, {24, 1}};
0043
0044 auto tempDetector = DetectorConfig();
0045 std::vector<DetectorConfig> detectorConfigs = {tempDetector, tempDetector};
0046 config.detectorConfigs = detectorConfigs;
0047
0048 config.minScore = 0;
0049 config.minScoreSharedTracks = 100;
0050 config.maxShared = 5;
0051 config.maxSharedTracksPerMeasurement = 10;
0052 config.phiMax = 3.14;
0053 config.phiMin = -3.14;
0054 config.etaMax = 2.7;
0055 config.etaMin = -2.7;
0056 config.pTMax = 1400;
0057 config.pTMin = 0.5;
0058 config.useAmbiguityFunction = false;
0059 }
0060
0061 ~Fixture() = default;
0062 };
0063
0064 template <typename TrackContainer, typename FlagsPerState>
0065 auto createTestTrack(TrackContainer& tc, const FlagsPerState& flagsPerState) {
0066 auto t = tc.makeTrack();
0067 for (const auto& flags : flagsPerState) {
0068 auto ts = t.appendTrackState();
0069 for (auto f : flags) {
0070 ts.typeFlags().set(f);
0071 }
0072 }
0073
0074 calculateTrackQuantities(t);
0075
0076 return t;
0077 }
0078
0079 BOOST_FIXTURE_TEST_CASE(ComputeInitialStateTest, Fixture) {
0080 Fixture fixture;
0081
0082 ScoreBasedAmbiguityResolution tester(fixture.config);
0083
0084 VectorTrackContainer mutVtc;
0085 VectorMultiTrajectory mutMtj;
0086
0087 TrackContainer mutTc{mutVtc, mutMtj};
0088 static_assert(!mutTc.ReadOnly, "Unexpectedly read only");
0089
0090 auto t = createTestTrack(mutTc, std::vector<std::vector<TrackStateFlag>>{
0091 {MeasurementFlag},
0092 {OutlierFlag},
0093 {MeasurementFlag, SharedHitFlag},
0094 {HoleFlag},
0095 {OutlierFlag},
0096 {HoleFlag},
0097 {MeasurementFlag, SharedHitFlag},
0098 {OutlierFlag},
0099 });
0100
0101 BOOST_CHECK_EQUAL(t.nHoles(), 2);
0102 BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0103 BOOST_CHECK_EQUAL(t.nOutliers(), 3);
0104 BOOST_CHECK_EQUAL(t.nSharedHits(), 2);
0105
0106 ConstVectorTrackContainer vtc{std::move(mutVtc)};
0107 ConstVectorMultiTrajectory mtj{std::move(mutMtj)};
0108
0109 TrackContainer ctc{vtc, mtj};
0110
0111 std::vector<std::vector<TrackFeatures>> trackFeaturesVectors;
0112 trackFeaturesVectors = tester.computeInitialState(ctc);
0113
0114 BOOST_CHECK_EQUAL(trackFeaturesVectors.size(), ctc.size());
0115
0116 std::vector<double> trackScores;
0117 trackScores = tester.simpleScore(ctc, trackFeaturesVectors);
0118
0119 BOOST_CHECK_EQUAL(trackScores.size(), ctc.size());
0120
0121 trackScores = tester.ambiguityScore(ctc, trackFeaturesVectors);
0122
0123 BOOST_CHECK_EQUAL(trackScores.size(), ctc.size());
0124
0125
0126 }
0127
0128 BOOST_FIXTURE_TEST_CASE(GetCleanedOutTracksTest, Fixture) {
0129 Fixture fixture;
0130
0131 ScoreBasedAmbiguityResolution tester(fixture.config);
0132
0133 VectorTrackContainer mutVtc;
0134 VectorMultiTrajectory mutMtj;
0135
0136 TrackContainer mutTc{mutVtc, mutMtj};
0137 static_assert(!mutTc.ReadOnly, "Unexpectedly read only");
0138
0139 auto t = createTestTrack(mutTc, std::vector<std::vector<TrackStateFlag>>{
0140 {MeasurementFlag},
0141 {OutlierFlag},
0142 {MeasurementFlag, SharedHitFlag},
0143 {HoleFlag},
0144 {OutlierFlag},
0145 {HoleFlag},
0146 {MeasurementFlag, SharedHitFlag},
0147 {OutlierFlag},
0148 });
0149
0150 BOOST_CHECK_EQUAL(t.nHoles(), 2);
0151 BOOST_CHECK_EQUAL(t.nMeasurements(), 3);
0152 BOOST_CHECK_EQUAL(t.nOutliers(), 3);
0153 BOOST_CHECK_EQUAL(t.nSharedHits(), 2);
0154
0155 ConstVectorTrackContainer vtc{std::move(mutVtc)};
0156 ConstVectorMultiTrajectory mtj{std::move(mutMtj)};
0157
0158 TrackContainer ctc{vtc, mtj};
0159
0160 std::vector<std::vector<TrackFeatures>> trackFeaturesVectors;
0161 std::vector<std::vector<std::size_t>> measurementsPerTrackVector;
0162 std::map<std::size_t, std::size_t> nTracksPerMeasurement;
0163
0164 trackFeaturesVectors = tester.computeInitialState(ctc);
0165
0166 BOOST_CHECK_EQUAL(trackFeaturesVectors.size(), ctc.size());
0167
0168 for (std::size_t iMeasurement = 1; const auto& track : ctc) {
0169 std::vector<std::size_t> measurementsPerTrack;
0170 for (auto ts : track.trackStatesReversed()) {
0171 if (ts.typeFlags().test(Acts::TrackStateFlag::OutlierFlag) ||
0172 ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
0173 measurementsPerTrack.push_back(iMeasurement);
0174 if (nTracksPerMeasurement.find(iMeasurement) ==
0175 nTracksPerMeasurement.end()) {
0176 nTracksPerMeasurement[iMeasurement] = 0;
0177 }
0178 nTracksPerMeasurement[iMeasurement]++;
0179 }
0180
0181 iMeasurement++;
0182 }
0183 measurementsPerTrackVector.push_back(std::move(measurementsPerTrack));
0184 }
0185
0186 auto trackScore = tester.ambiguityScore(ctc, trackFeaturesVectors);
0187
0188 const auto& track = ctc.getTrack(0);
0189 std::size_t iTrack = track.index();
0190 bool accepted = tester.getCleanedOutTracks(track, trackScore[iTrack],
0191 measurementsPerTrackVector[iTrack],
0192 nTracksPerMeasurement);
0193
0194 BOOST_CHECK_EQUAL(accepted, false);
0195 }
0196
0197 BOOST_AUTO_TEST_SUITE_END()
0198
0199 }