Skip to content

Commit 8980323

Browse files
mpuccioclaude
andcommitted
GenericTracking: bound the slice reach along chains, with the triplet cut
A triplet's first and third boxes overlap (tripletTimeCompatible), so two layers two links apart that share frames, with rows that are those frames, do not drift, whatever box lies between. chainReach bounds each chain by the lesser of the link sum and the two-link sum, and counts a chain's first link only where a taken link goes on from its target (a lone tracklet is on no road). Through the iTOF between ML6 and ML7, the pairwise bound let ML7 sit a frame from ML6; the triplet (ML6, iTOF, ML7) forbids it. Pb-Pb pass 2's gate goes from 4092 to 2046 ns, below the VD passes', and tracking with the TOF layers costs +5.2 % over TRKFT3 instead of +12.4 %. Tracks are unchanged, and so at every slice width tried. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7df85af commit 8980323

3 files changed

Lines changed: 266 additions & 15 deletions

File tree

‎Detectors/GenericTracking/tracking/include/GenericTracking/Tracking/SlicePlan.h‎

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,95 @@ template <DetectorLayout Det>
159159
return result;
160160
}
161161

162+
/// The reach of the chains one iteration builds on the links \a taken marks,
163+
/// with the triplets' time cut: in a chain `m0 m1 ... mk` of measurements on
164+
/// consecutive links, every pair `m(i) m(i+1)` overlaps (the tracklet) and so
165+
/// does every `m(i) m(i+2)` (`tripletTimeCompatible`, the triplet's first and
166+
/// third). So `m(i+2)` reaches `m(i)` as a pair on the layers two links
167+
/// apart, 0 both ways when those two share frames and their rows are them,
168+
/// whatever the layer between -- a narrow box, a TOF hit's, between two
169+
/// layers of the same frames moves neither.
170+
///
171+
/// Each bound is a sum of link and two-link reaches along the chain. For a
172+
/// chain ending `x -> a -> b`, `b` drifts from `m0` by at most the bound at `a`
173+
/// plus the link's reach and at most the bound at `x` plus the two-link
174+
/// reach: the lesser of the two. Per link, the largest such bound over the
175+
/// chains ending on it (`forwardTo`), and per layer over the chains ending
176+
/// there (`forwardAt`); upper bounds of the same terms, so the lesser of
177+
/// them bounds every chain (by induction along `layerOrder`). `R+` and `R-`
178+
/// are the largest over the links, the forward and the backward bound alike;
179+
/// the pair reaches are the links' own, as in `sliceReach`. A chain of two
180+
/// measurements alone -- a tracklet no triplet takes -- is on no road and in
181+
/// no level (a road holds a triplet), so a chain's first link counts in `R+`
182+
/// and `R-` only where a taken link goes on from its target; it always counts
183+
/// in the pair reaches, which size the halo's edge. Never more than
184+
/// `sliceReach` along the same links.
185+
template <DetectorLayout Det>
186+
[[nodiscard]] SliceReach chainReach(const HaloBounds<Det>& bounds, const GridGeometry<Det>& geometry, const std::array<bool, nLinks<Det>>& taken)
187+
{
188+
constexpr auto kLayers = HaloBounds<Det>::kLayerCount;
189+
const auto zero = [&](LayerID from, LayerID to) {
190+
return geometry.frames(from) == geometry.frames(to) && bounds.rowsAreFrames[from] && bounds.rowsAreFrames[to];
191+
};
192+
const auto forwardOf = [&](LayerID from, LayerID to) -> std::int64_t { return zero(from, to) ? 0 : bounds.widthPS[from]; };
193+
const auto backwardOf = [&](LayerID from, LayerID to) -> std::int64_t { return zero(from, to) ? 0 : bounds.widthPS[to]; };
194+
SliceReach result;
195+
std::array<std::int64_t, nLinks<Det>> forwardTo{};
196+
std::array<std::int64_t, nLinks<Det>> backwardTo{};
197+
std::array<std::int64_t, kLayers> forwardAt{};
198+
std::array<std::int64_t, kLayers> backwardAt{};
199+
for (const auto layer : layerOrder<Det>) {
200+
// Every link into this layer is done: its source comes earlier in the order.
201+
for (auto i = inLinks<Det>.begin(layer); i < inLinks<Det>.end(layer); ++i) {
202+
if (taken[inLinks<Det>.links[i]]) {
203+
forwardAt[layer] = std::max(forwardAt[layer], forwardTo[inLinks<Det>.links[i]]);
204+
backwardAt[layer] = std::max(backwardAt[layer], backwardTo[inLinks<Det>.links[i]]);
205+
}
206+
}
207+
for (auto o = outLinks<Det>.begin(layer); o < outLinks<Det>.end(layer); ++o) {
208+
const auto out = outLinks<Det>.links[o];
209+
if (!taken[out]) {
210+
continue;
211+
}
212+
const LayerID target = Det::layerLinks[out].to;
213+
const std::int64_t forward = forwardOf(layer, target);
214+
const std::int64_t backward = backwardOf(layer, target);
215+
result.pairForwardPS = std::max(result.pairForwardPS, forward);
216+
result.pairBackwardPS = std::max(result.pairBackwardPS, backward);
217+
// The chains with a measurement before this layer: three or more.
218+
std::int64_t longerForward = 0;
219+
std::int64_t longerBackward = 0;
220+
for (auto i = inLinks<Det>.begin(layer); i < inLinks<Det>.end(layer); ++i) {
221+
const auto in = inLinks<Det>.links[i];
222+
if (!taken[in]) {
223+
continue;
224+
}
225+
const LayerID before = Det::layerLinks[in].from;
226+
longerForward = std::max(longerForward, std::min(forwardTo[in] + forward, forwardAt[before] + forwardOf(before, target)));
227+
longerBackward = std::max(longerBackward, std::min(backwardTo[in] + backward, backwardAt[before] + backwardOf(before, target)));
228+
}
229+
// A chain starting on this layer is this link's pair, the bound of the
230+
// longer chains it starts.
231+
forwardTo[out] = std::max(forward, longerForward);
232+
backwardTo[out] = std::max(backward, longerBackward);
233+
// Only a chain of three or more measurements -- one with a triplet --
234+
// is on a road or a level: the pair alone counts where a taken link
235+
// goes on from its target.
236+
const bool continues = outLinks<Det>.end(target) > outLinks<Det>.begin(target) && [&] {
237+
for (auto n = outLinks<Det>.begin(target); n < outLinks<Det>.end(target); ++n) {
238+
if (taken[outLinks<Det>.links[n]]) {
239+
return true;
240+
}
241+
}
242+
return false;
243+
}();
244+
result.forwardPS = std::max({result.forwardPS, longerForward, continues ? forward : std::int64_t{0}});
245+
result.backwardPS = std::max({result.backwardPS, longerBackward, continues ? backward : std::int64_t{0}});
246+
}
247+
}
248+
return result;
249+
}
250+
162251
/// The time a slice's seeding needs past its core: the gate and the halo
163252
/// (`SliceReach::gatePS`, `haloPS`), each the largest of the iterations'.
164253
struct SeedingReach {
@@ -167,16 +256,17 @@ struct SeedingReach {
167256
};
168257

169258
/// The reach the seeding of \a iterations needs: each iteration's along the
170-
/// links it takes (its out-link lists, `takenLinks`); of their gates and of
171-
/// their halos the largest. A chain -- tracklet, triplet, neighbour, road, and
172-
/// the chains into a road its levels count -- belongs to one iteration (an
173-
/// iteration on its predecessor's graph, `sharedGraph`, takes the same links)
174-
/// and lies on its taken links; so a link no iteration takes, or a path
175-
/// through two iterations' links, widens no gate. The gate is each
176-
/// iteration's `R+ + R-`, and the largest of those -- not the largest `R+`
177-
/// plus the largest `R-`, which two iterations can make without either
178-
/// needing it. The follow does not work in slices. With no iterations, every
179-
/// link's (`sliceReach`).
259+
/// links it takes (its out-link lists, `takenLinks`), with the triplets' time
260+
/// cut (`chainReach`); of their gates and of their halos the largest. A
261+
/// chain -- tracklet, triplet, neighbour, road, and the chains into a road its
262+
/// levels count -- belongs to one iteration (an iteration on its
263+
/// predecessor's graph, `sharedGraph`, takes the same links) and lies on its
264+
/// taken links, every three consecutive measurements a triplet; so a link no
265+
/// iteration takes, or a path through two iterations' links, widens no gate.
266+
/// The gate is each iteration's `R+ + R-`, and the largest of those -- not
267+
/// the largest `R+` plus the largest `R-`, which two iterations can make
268+
/// without either needing it. The follow does not work in slices. With no
269+
/// iterations, every link's pairwise (`sliceReach`).
180270
template <DetectorLayout Det>
181271
[[nodiscard]] SeedingReach seedingReach(const HaloBounds<Det>& bounds, const GridGeometry<Det>& geometry, std::span<const IterationParameters<Det>> iterations)
182272
{
@@ -190,7 +280,7 @@ template <DetectorLayout Det>
190280
for (auto i = parameters.outLinkOffsets[0]; i < parameters.outLinkOffsets[HaloBounds<Det>::kLayerCount]; ++i) {
191281
taken[parameters.outLinkIndices[i]] = true;
192282
}
193-
const auto reach = sliceReach(bounds, geometry, &taken);
283+
const auto reach = chainReach(bounds, geometry, taken);
194284
result.gatePS = std::max(result.gatePS, reach.gatePS());
195285
result.haloPS = std::max(result.haloPS, reach.haloPS());
196286
}

‎Detectors/GenericTracking/tracking/test/testIteration.cxx‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,60 @@ BOOST_AUTO_TEST_CASE(AnIterationReachesAlongTheLinksItTakes)
347347
BOOST_TEST(seeding({}).haloPS == sliceReach(bounds, grid).haloPS());
348348
}
349349

350+
/// Of several iterations the gate is the largest of their gates, each its own
351+
/// `R+ + R-` -- not the largest `R+` plus the largest `R-`: one iteration on
352+
/// layers 3-6 across a narrow-box layer 5 of 1 BC frames (`R+` the long frame,
353+
/// `R-` the narrow box: its link out goes nowhere on in the iteration), one
354+
/// on layers 0-3 across the short-long frame edge (`R+` the short frame, `R-`
355+
/// the long one).
356+
BOOST_AUTO_TEST_CASE(TheGateIsTheLargestIterationsNotItsLargestParts)
357+
{
358+
using Det = detectors::ToyBarrel8;
359+
constexpr FrameTiming kShort{.lengthBC = 22, .firstStartBC = 0};
360+
constexpr FrameTiming kLong{.lengthBC = 81, .firstStartBC = 0};
361+
constexpr FrameTiming kNarrow{.lengthBC = 1, .firstStartBC = 0};
362+
const std::int64_t shortPS = psOfBC(22);
363+
const std::int64_t longPS = psOfBC(81);
364+
const std::int64_t narrowPS = psOfBC(1);
365+
const auto grid = chainGrid({kShort, kShort, kShort, kLong, kLong, kNarrow, kLong, kLong});
366+
auto bounds = framedBounds({static_cast<std::uint32_t>(shortPS), static_cast<std::uint32_t>(shortPS), static_cast<std::uint32_t>(shortPS), static_cast<std::uint32_t>(longPS), static_cast<std::uint32_t>(longPS),
367+
static_cast<std::uint32_t>(narrowPS), static_cast<std::uint32_t>(longPS), static_cast<std::uint32_t>(longPS)});
368+
bounds.rowsAreFrames[5] = false;
369+
const auto taken = [](std::uint64_t mask) {
370+
IterationSettings settings;
371+
settings.layerMask = mask;
372+
settings.minClusters = 3;
373+
return takenLinks<Det>(settings);
374+
};
375+
const auto narrow = chainReach(bounds, grid, taken(0x78U));
376+
BOOST_TEST(narrow.forwardPS == longPS);
377+
BOOST_TEST(narrow.backwardPS == narrowPS);
378+
// Pairwise the link out of the narrow layer reaches the long frame back.
379+
const auto narrowLinks = taken(0x78U);
380+
BOOST_TEST(sliceReach(bounds, grid, &narrowLinks).backwardPS == narrowPS + longPS);
381+
const auto edge = chainReach(bounds, grid, taken(0x0FU));
382+
BOOST_TEST(edge.forwardPS == shortPS);
383+
BOOST_TEST(edge.backwardPS == longPS);
384+
std::vector<IterationParameters<Det>> iterations(2);
385+
for (std::size_t i = 0; i < 2; ++i) {
386+
const auto links = taken(i == 0 ? 0x78U : 0x0FU);
387+
std::uint32_t kept = 0U;
388+
for (std::size_t layer = 0; layer < IterationParameters<Det>::kLayerCount; ++layer) {
389+
iterations[i].outLinkOffsets[layer] = kept;
390+
for (auto o = outLinks<Det>.begin(static_cast<LayerID>(layer)); o < outLinks<Det>.end(static_cast<LayerID>(layer)); ++o) {
391+
if (links[outLinks<Det>.links[o]]) {
392+
iterations[i].outLinkIndices[kept++] = static_cast<std::uint16_t>(outLinks<Det>.links[o]);
393+
}
394+
}
395+
}
396+
iterations[i].outLinkOffsets[IterationParameters<Det>::kLayerCount] = kept;
397+
}
398+
const auto seeding = seedingReach(bounds, grid, std::span<const IterationParameters<Det>>{iterations});
399+
BOOST_TEST(seeding.gatePS == std::max(longPS + narrowPS, shortPS + longPS));
400+
BOOST_TEST(seeding.gatePS < 2 * longPS);
401+
BOOST_TEST(seeding.haloPS == std::max(narrow.haloPS(), edge.haloPS()));
402+
}
403+
350404
/// A layer whose rows are not exactly its frames -- widened by a margin the
351405
/// producer applied, whatever the configuration says now -- reaches on both
352406
/// of its links.

‎Detectors/GenericTracking/tracking/test/testIterations.cxx‎

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,18 @@ BOOST_AUTO_TEST_CASE(ASlicePlanHoldsTheSlicesBoundsAndGate)
420420
const auto plan = tracker->planTimeframe(*fixture.frame, {}, 3, 0.);
421421
const auto& frame = *fixture.frame;
422422
BOOST_TEST(plan.slices.size() == static_cast<std::size_t>((fixture.geometry.blockCount() + 2) / 3));
423-
// The toys' blocks start at 0 and are whole picoseconds.
424-
const auto reach = sliceReach(frameBounds(frame), fixture.geometry).gatePS();
423+
// The toys' blocks start at 0 and are whole picoseconds. The gate is the
424+
// iterations' chains' (`chainReach`): the toy's rows are boxes of one width,
425+
// not frames, so a link reaches that width and so does a triplet's two, and
426+
// along the eight layers a chain drifts 4 widths each way -- 7 pairwise.
427+
const std::vector<IterationParameters<Det>> parameters{tracker->iteration(0U), tracker->iteration(1U)};
428+
const auto chains = chainReach(frameBounds(frame), fixture.geometry, takenLinks<Det>(iterations().front()));
429+
BOOST_TEST(seedingReach(frameBounds(frame), fixture.geometry, std::span<const IterationParameters<Det>>{parameters}).gatePS == chains.gatePS());
430+
const std::int64_t boxPS = test::kToyBoxWidthPS;
431+
BOOST_TEST(chains.forwardPS == 4 * boxPS);
432+
BOOST_TEST(chains.backwardPS == 4 * boxPS);
433+
BOOST_TEST(sliceReach(frameBounds(frame), fixture.geometry).forwardPS == 7 * boxPS);
434+
const auto reach = chains.gatePS();
425435
const auto width = fixture.geometry.blockWidth();
426436
BOOST_REQUIRE(fixture.geometry.partsPerPS() == 1);
427437
for (const auto& slicePlan : plan.slices) {
@@ -714,9 +724,9 @@ struct FramedRun {
714724
std::int64_t haloPS = 0;
715725
};
716726

717-
FramedRun trackFramed(const Fixture& fixture, std::int32_t widthBlocks)
727+
FramedRun trackFramed(const Fixture& fixture, std::int32_t widthBlocks, const std::vector<IterationSettings>& settings = iterations())
718728
{
719-
auto tracker = makeTracker(iterations(), false);
729+
auto tracker = makeTracker(settings, false);
720730
const auto result = tracker->run(*fixture.frame, tracker->planTimeframe(*fixture.frame, {}, widthBlocks, 0.));
721731
BOOST_REQUIRE(result.status == StageStatus::kComplete);
722732
FramedRun run{.tracks = found(result), .times = std::vector<TimeEstPS>(kCrossingBC.size()), .haloPS = result.iterations.front().haloPS};
@@ -776,6 +786,103 @@ BOOST_AUTO_TEST_CASE(TwoFrameLengthsSliceWithOneOuterFrameOfHalo)
776786
}
777787
}
778788

789+
/// The two-length toy with one outer layer of narrow boxes, as a TOF layer
790+
/// between two of the same frames: its grid frames 1 BC, each hit's box the
791+
/// BC before its time, [t - 1 BC, t], at the hit's picosecond, not a frame.
792+
/// The crossings at 81, 162, 243, 324 and 648 BC -- outer frames' starts,
793+
/// blocks' at 162, 324, 648 -- give narrow boxes straddling an outer frame's
794+
/// edge, and a block's. A triplet's third box overlaps its first, so through
795+
/// the narrow layer the two outer layers beside it stay in one frame.
796+
///
797+
/// On the outer layers alone (3-7, every frame 81 BC, as ALICE 3's ML 3-7
798+
/// pass with the iTOF): pairwise every link into the narrow layer reaches the
799+
/// long frame forward and the narrow box backward, every link out of it the
800+
/// reverse, `R+ = R- = long + narrow`. The chains: into the narrow layer the
801+
/// long frame forward and its box backward; after it, the next layer back in
802+
/// the frame before it, 0. Out of the narrow layer a chain starting on it
803+
/// reaches the long frame backward -- if a link goes on from its target
804+
/// (narrow layer 5: 5 -> 6 -> 7), not for the last link alone (6 -> 7,
805+
/// a tracklet no triplet takes). And on every layer, both iterations: less
806+
/// than pairwise. Each way the slices give the one-slice tracks.
807+
BOOST_AUTO_TEST_CASE(ANarrowBoxLayerBetweenLayersOfTheSameFrames)
808+
{
809+
constexpr std::array<std::int64_t, 12> kCrossings{5, 81, 100, 162, 170, 243, 324, 400, 480, 520, 648, 700};
810+
const auto longPS = psOfBC(kOuterFrameBC);
811+
const auto narrowPS = psOfBC(1);
812+
auto outer = iterations();
813+
for (auto& iteration : outer) {
814+
iteration.layerMask = 0xF8U;
815+
}
816+
for (const LayerID narrow : {LayerID{6}, LayerID{5}}) {
817+
BOOST_TEST_CONTEXT("narrow layer " << int{narrow})
818+
{
819+
auto params = twoLengthGrid();
820+
params.frames[narrow] = {.lengthBC = 1, .firstStartBC = 0};
821+
const auto boxOf = [&](const Hit& hit) {
822+
if (hit.point.layer != narrow) {
823+
return frameOf(hit, 0);
824+
}
825+
const auto t = std::llround(hit.timeNS * 1000.);
826+
return TimeEstPS{.start = static_cast<std::uint32_t>(t - narrowPS), .width = static_cast<std::uint32_t>(narrowPS)};
827+
};
828+
std::vector<Hit> hits;
829+
for (std::size_t track = 0; track < kCrossings.size(); ++track) {
830+
const auto k = static_cast<double>(track);
831+
const double pt = stiff(track) ? 2. + (0.2 * static_cast<double>(track % 5U)) : 0.4 + (0.06 * static_cast<double>(track % 5U));
832+
const auto one = sensorHelixHits(std::fmod(0.3 + (0.9 * k), 2 * std::numbers::pi_v<double>), 0.03 * std::cos(1.3 * k), pt, (static_cast<double>(kCrossings[track]) * kBunchNS) + 5.);
833+
BOOST_REQUIRE(one.size() == kLayers);
834+
hits.insert(hits.end(), one.begin(), one.end());
835+
}
836+
const Fixture fixture{hits, kFramedDurationNS, params, boxOf};
837+
const auto bounds = frameBounds(*fixture.frame);
838+
BOOST_TEST(!bounds.rowsAreFrames[narrow]);
839+
BOOST_TEST(bounds.widthPS[narrow] == narrowPS);
840+
const auto& geometry = fixture.geometry;
841+
std::size_t acrossFrame = 0, acrossBlock = 0;
842+
for (const auto& hit : hits) {
843+
if (hit.point.layer == narrow) {
844+
const auto box = boxOf(hit);
845+
// The BC a picosecond lies in, rounded down (bcOfPS rounds up: it inverts psOfBC).
846+
const auto bcAt = [](std::int64_t ps) { return (ps * kPSPerBCDenominator) / kPSPerBCNumerator; };
847+
acrossFrame += bcAt(box.start) / kOuterFrameBC != bcAt(box.start + box.width - 1) / kOuterFrameBC;
848+
acrossBlock += geometry.blockOfPS(box.start) != geometry.blockOfPS(box.start + box.width - 1);
849+
}
850+
}
851+
BOOST_TEST(acrossFrame >= 4U);
852+
BOOST_TEST(acrossBlock >= 2U);
853+
854+
const auto outerTracker = makeTracker(outer, false);
855+
const auto taken = takenLinks<Det>(outer.front());
856+
for (std::size_t link = 0; link < nLinks<Det>; ++link) {
857+
BOOST_TEST(taken[link] == (Det::layerLinks[link].from >= 3));
858+
}
859+
const auto pairwise = sliceReach(bounds, geometry, &taken);
860+
BOOST_TEST(pairwise.forwardPS == longPS + narrowPS);
861+
BOOST_TEST(pairwise.backwardPS == longPS + narrowPS);
862+
const auto chains = chainReach(bounds, geometry, taken);
863+
BOOST_TEST(chains.forwardPS == longPS);
864+
BOOST_TEST(chains.backwardPS == (narrow == 6 ? narrowPS : longPS));
865+
BOOST_TEST(outerTracker->planTimeframe(*fixture.frame, {}, 1, 0).haloPS == chains.haloPS());
866+
BOOST_TEST(chains.haloPS() < pairwise.haloPS());
867+
const auto every = makeTracker(iterations(), false)->planTimeframe(*fixture.frame, {}, 1, 0).haloPS;
868+
BOOST_TEST(every < sliceReach(bounds, geometry).haloPS());
869+
870+
const auto everyLayer = iterations();
871+
for (const auto* settings : std::array<const std::vector<IterationSettings>*, 2>{&outer, &everyLayer}) {
872+
const auto& chosen = *settings;
873+
BOOST_TEST_CONTEXT((settings == &outer ? "layers 3-7" : "every layer"))
874+
{
875+
const auto whole = trackFramed(fixture, geometry.blockCount(), chosen);
876+
BOOST_TEST(whole.tracks.size() == kCrossings.size());
877+
for (const std::int32_t width : {1, 2, 3}) {
878+
BOOST_TEST_CONTEXT("slices of " << width << " blocks") { BOOST_TEST((trackFramed(fixture, width, chosen).tracks == whole.tracks)); }
879+
}
880+
}
881+
}
882+
}
883+
}
884+
}
885+
779886
/// The same toy with its boxes widened by a margin while the grid still
780887
/// declares the frames -- as a dump keeps the boxes its producer widened,
781888
/// whatever margin the tracking is configured with: the rows are not their

0 commit comments

Comments
 (0)