# Muon collider GNN tracking, v3 models (2026-11-18)

| File | What |
|---|---|
| `graph_construction-MetricLearningT-v3.onnx` / `.pt` | embedding (ONNX / TorchScript) |
| `edge_classifier-InteractionGNN2-v3.onnx` / `.pt` | edge classifier (ONNX / TorchScript) |
| `best_ml_rotary_epoch14.ckpt` | acorn checkpoint of the embedding |
| `best_gnn_cosine_long_epoch154.ckpt` | acorn checkpoint of the edge classifier |

## What changed from v2

- **Embedding: hits must be sorted by phi** (`SortHitsByPhi`). It was trained on phi-sorted
  hits and uses rotary encodings of (phi, eta) in its attention. Do not feed it the
  feature-store order.
- **Edge classifier:** retrained on this embedding's graphs (180 epochs, best val loss at epoch 154).
- The inputs and outputs are the same as in v2:
  - embedding input: `node_features` [N, 5] = (r, phi, z, eta, toa), divided by (1000, 3.14, 1000, 1, 1)
  - embedding output: [N, 12]
  - graph building: radius 0.1, k_max 100
  - GNN input: `node_features` [N, 5], `edge_list` [2, E], `edge_attr` [E, 6] =
    (dr, dphi, dz, deta, phislope, rphislope)
  - GNN output: [E] edge scores

## Results (acorn, 993 valset events, full BIB, ATLAS matching at 0.5)

| Track building | Efficiency | Fake rate | Duplicate rate |
|---|---|---|---|
| CC + walk, cuts 0.01 / 0.1 / 0.6 (as in v2) | 0.976 | 0.422 | 0.049 |
| CC + best-predecessor walk, cuts 0.01 / 0.3 / 0.8, mean edge score >= 0.5, >= 7 hits | **0.990** | **0.019** | 0.003 |

The cuts were picked on the valset; they have not yet been confirmed on a separate test set.

The ONNX models were checked against the checkpoints on 10 full-occupancy events. The GNN
edge efficiency and purity, the track count and every muon matching number are identical.
Graph edges differ by at most 3 out of ~70k per event, from float rounding at the radius
cut.

## Best-predecessor walk

The best-predecessor rule: the walk goes from hit u to hit v only if u -> v is the
highest-scoring edge into v from any hit that is not yet used. Without this rule, a background
branch that joins the muon's chain further out takes the muon's hits.

In acorn it is enabled in the track-building config with `bestpred_walk: True`. Two
optional filters go with it: `min_track_score` (minimum mean edge score of a track) and
`min_track_hits` (minimum number of hits).

### Gaudi: `k4ActsTracking-bestpred-walk.patch`

This patch adds the same rule to `CCAndWalkTrackBuilding` in k4ActsTracking `GNNTrackFinding`,
with two new properties of `GNNTrackFinder`: `WalkBestPredecessor` and `MinMeanEdgeScore`. It
was made against key4hep/k4ActsTracking `4bf76dd` and applies cleanly to main as of 2026-11-18.

Apply it and rebuild:

```bash
cd k4ActsTracking
wget https://portal.nersc.gov/cfs/m3443/xju/muon_collider/trained_gnn/v3/k4ActsTracking-bestpred-walk.patch
git apply --check k4ActsTracking-bestpred-walk.patch   # dry run
git apply k4ActsTracking-bestpred-walk.patch
cmake --build build --target install                   # or your usual build
```

Then set these in the steering file:

```python
GNNTrackFinder(
    ...,
    TrackBuilding="cc-and-walk",
    EdgeClassifierCut=[0.01],
    WalkMinScore=0.3,
    WalkAddScore=0.8,
    WalkBestPredecessor=True,
    MinMeanEdgeScore=0.5,
    MinHitsPerTrack=7,
)
```

Both new properties are off by default, so the algorithm behaves as before unless they are set.

The patch was compiled only against stand-in Acts headers, not in a full key4hep build. On 100
valset events it gives the same tracks as acorn for 99.8% of tracks. The remaining
differences come from paths of equal length: acorn keeps the lowest-scoring branch, the C++
keeps the highest-scoring one, which retained more muon hits in 4 of the 5 events where the
muon's track differs.
