actions
Loading...
Searching...
No Matches
track_provenance_example.cc
Go to the documentation of this file.
2
3// C++
4#include <cstdlib>
5#include <iostream>
6#include <vector>
7
25namespace {
26void add_track(GTrackProvenance& provenance, int tid, int mtid) {
27 provenance.record(11, tid, mtid, 100.0 + tid, G4ThreeVector(tid, 2 * tid, 3 * tid),
28 G4ThreeVector(4 * tid, 5 * tid, 6 * tid));
29}
30}
31
32int main() {
33 // Build the synthetic branching hierarchy documented above.
34 GTrackProvenance provenance(true);
35 add_track(provenance, 1, 0);
36 add_track(provenance, 2, 1);
37 add_track(provenance, 3, 1);
38 add_track(provenance, 4, 2);
39
40 // A primary is its own original track; every descendant resolves to that primary.
41 if (provenance.originalTrackId(1) != 1 || provenance.originalTrackId(4) != 1) {
42 std::cerr << "Incorrect original track ID\n";
43 return EXIT_FAILURE;
44 }
45
46 // Request overlapping paths, including a duplicate, and require every track exactly once.
47 const auto ancestors = provenance.ancestorsForTracks({4, 3, 4});
48 if (ancestors.size() != 4) {
49 std::cerr << "Expected four unique ancestor records, got " << ancestors.size() << '\n';
50 return EXIT_FAILURE;
51 }
52 // Output is sorted by track ID so all streamers receive deterministic rows.
53 for (std::size_t index = 0; index < ancestors.size(); ++index) {
54 if (ancestors[index].tid != static_cast<int>(index + 1)) {
55 std::cerr << "Ancestor records are not ordered by track ID\n";
56 return EXIT_FAILURE;
57 }
58 }
59
60 // Clearing at the next event boundary must remove both mappings and full records.
61 provenance.clear();
62 if (provenance.originalTrackId(4) != 0 || !provenance.ancestorsForTracks({4}).empty()) {
63 std::cerr << "Event reset retained provenance\n";
64 return EXIT_FAILURE;
65 }
66
67 // Original-only mode retains the compact ID mapping without allocating ancestor records.
68 GTrackProvenance original_only(false);
69 add_track(original_only, 1, 0);
70 add_track(original_only, 2, 1);
71 if (original_only.originalTrackId(2) != 1 || !original_only.ancestorsForTracks({2}).empty()) {
72 std::cerr << "Original-only mode retained ancestor records\n";
73 return EXIT_FAILURE;
74 }
75
76 return EXIT_SUCCESS;
77}
Worker-local, event-scoped track ancestry registry.
void record(const G4Track &track)
int originalTrackId(int track_id) const
std::vector< GTrackRecord > ancestorsForTracks(const std::unordered_set< int > &track_ids) const