---
title: "Fit top-hat and Gaussian jets to GW170817"
description: "Fit two jet shapes to 42 real GW170817 detections with one Python script: the Gaussian fits, the sharp edge fails, and the angle stays loose."
canonical_url: "https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/fit-top-hat-and-gaussian-jets-to-gw170817/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/gamma-ray-burst-afterglows/fit-top-hat-and-gaussian-jets-to-gw170817/"
last_modified: "2026-11-22"
---

[Gamma-ray burst afterglows and off-axis jets](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/)

# Fit top-hat and Gaussian jets to GW170817

Sandbox Physics · 2026-11-22

This guide fits two jet shapes to 42 real detections of the GW170817 afterglow. A Gaussian jet seen about $21^\circ$ off its axis fits with $\chi^2=53.7$. The best sharp-edged jet only reaches $\chi^2=204$, because it cannot rise slowly enough. Holding the viewing angle anywhere from $15^\circ$ to $35^\circ$ and refitting the rest changes $\chi^2$ by at most 4, while the ratio of viewing angle to core width stays between 6.71 and 6.82. The Python scripts below let you check the fit and follow up with a second test on withheld data.

Read [off-axis structured jets and GW170817](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/off-axis-structured-jets-and-gw170817/) first. The dots are telescope measurements. Our thin-shell model draws the curves.

## Get the files

Extract the [complete reproduction ZIP](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/gw170817-afterglow-reproduction.zip) into an empty folder. The original fit also runs with these individual files:

- [README.md](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/README.md), run instructions, conventions and limits
- [afterglow\_model.py](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/afterglow_model.py), the thin-shell patch model
- [fit\_jets.py](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/fit_jets.py), the misfit and a Nelder–Mead minimizer
- [reproduce.py](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/reproduce.py), runs both fits and the viewing-angle scan, then compares
- [gw170817-frozen-slice.json](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/gw170817-frozen-slice.json), the frozen observations
- [expected-outputs.json](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/expected-outputs.json), the numbers quoted on this page
- [provenance.json](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/materials/provenance.json), sources and SHA-256 checksums

Then run:

```
python3 reproduce.py
```

No packages are needed. The script prints every fit, compares each number with the saved outputs and exits with status 0 when all agree to within 0.01 or 0.2 percent, whichever is larger. The replay passed in Python 3.12.12. A full run takes a few minutes. Use the separate output files for modified runs.

## The frozen slice

The observations come from the uniform table of Makhathini and collaborators, copied from the LaTeX source of the arXiv version. The slice has 22 VLA detections and one upper limit at 3 GHz, nine Hubble F606W detections and two optical upper limits, and eleven 1 keV detections with one upper limit from Chandra or XMM-Newton. That gives 42 detections and four upper limits. [The panchromatic afterglow of GW170817, Sec. 2 and data table](https://arxiv.org/abs/2006.02382v3)

The file records the source tarball checksum and its own checksum is in provenance.json. Asymmetric X-ray errors are kept: the misfit uses the upper error when the model lies above a point and the lower error when it lies below. Upper limits stay out of $\chi^2$; the script checks that each best fit lies below every one of them.

## The model

afterglow\_model.py treats each patch of the jet as a piece of a spherical blast wave carrying the local energy $E(\theta)$, as in the course chapters:

1. The Lorentz factor follows the energy equation of Huang, Dai and Lu, with $\Gamma_0=300$ and no sideways spreading.
2. Arrival times use $\tau=t_{\rm lab}-R/c$ plus the path difference $R(1-\cos\chi)/c$ for every patch. The angle $\chi$ is measured from the observer’s line of sight.
3. Each patch radiates the Sari–Piran–Narayan broken power law, Doppler shifted by $\delta$ and scaled by $\delta^3$. Self-absorption is left out.
4. The sky is cut into 40 rings and 16 azimuth samples per jet, and both jets are summed.

The distance is 40 Mpc and the redshift is neglected. The Lab uses the same physics in TypeScript on a finer grid, 56 rings and 36 azimuth cells.

Three numbers are fixed: $p=2.168$ from the measured spectral slope, $\epsilon_e=0.1$ and $\epsilon_B=10^{-4}$. Four are fitted: viewing angle, core width, $\log_{10}E_0$ and $\log_{10}n$.

## What the fits give

**Table 4.1** Best fits to the 42 detections. Slopes are the model's 3 GHz slope between days 15 and 60.

| Jet | $\theta_{\rm obs}$ | $\theta_c$ | $\log_{10}E_0$ | $\log_{10}n$ | $\theta_{\rm obs}/\theta_c$ | $\chi^2$ | Rise slope |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Gaussian | $20.94^\circ$ | $3.11^\circ$ | 52.29 | $-2.98$ | 6.73 | 53.7 | 1.10 |
| Top-hat | $20.07^\circ$ | $8.14^\circ$ | 51.93 | $-3.45$ | 2.47 | 204.2 | 2.93 |

The Gaussian fit gives $\chi^2$ per detection of 1.28. Both fits respect every upper limit.

The top-hat fails for the reason the closure relations predict. With no energy outside the core, the only way to see light at day 15 is a wide core seen not far from its edge. Even then the model rises as $t^{2.9}$, against the measured $t^{0.86}$, and its misfit is almost four times the Gaussian one.

## Hold out the optical and X-ray data

Run the command below. It fits just the 22 radio detections and then predicts the optical and X-ray amplitudes with those parameters held fixed. This check uses the electron index inferred from the original broadband study. It tests how the radio-calibrated temporal models transfer across bands at that spectral slope.

```
python3 held_bands.py --output held-bands.json
```

**Table 4.2** Chi-square per detection after fitting the radio data.

| Jet | Radio fit | Held Hubble F606W | Held 1 keV |
| --- | --- | --- | --- |
| Gaussian | 1.37 | 1.17 | 1.36 |
| Top-hat | 6.56 | 1.76 | 4.51 |

Each value is chi-square per detection. The largest separation between the predictions and the held data is in the X-ray comparison. After day 200 the original slice still has nine radio and five X-ray detections. The JSON gives the predicted flux and the signed residual for each measurement. Its upper limits are compared separately.

The README gives the download address for the pinned paper archive. The second command below checks all 46 local rows against that archive. The archive also contains an independent arrival-time calculation, so the sky geometry can be checked without using the fit.

```
python3 verify_observations.py --source-archive makhathini-v3.tar.gz --output source-check.json
```

## The degeneracy scan

reproduce.py then fixes the viewing angle at five values and refits the other three parameters.

**Table 4.3** Gaussian fits with the viewing angle held fixed.

| $\theta_{\rm obs}$ | $\theta_c$ | $\log_{10}E_0$ | $\log_{10}n$ | $\theta_{\rm obs}/\theta_c$ | $\chi^2$ |
| --- | --- | --- | --- | --- | --- |
| $15^\circ$ | $2.24^\circ$ | 52.57 | $-3.82$ | 6.71 | 53.9 |
| $20^\circ$ | $2.97^\circ$ | 52.33 | $-3.10$ | 6.73 | 53.6 |
| $25^\circ$ | $3.70^\circ$ | 52.15 | $-2.53$ | 6.76 | 54.1 |
| $30^\circ$ | $4.42^\circ$ | 52.00 | $-2.07$ | 6.79 | 55.4 |
| $35^\circ$ | $5.14^\circ$ | 51.87 | $-1.68$ | 6.82 | 57.6 |

The ratio barely moves. The density moves by two orders of magnitude to keep the peak time fixed, as the break-time formula $t_{\rm b}\propto(E_0/n)^{1/3}(\theta_{\rm obs}+1.24\theta_c)^{8/3}$ requires. Allowing $\epsilon_e$ and $\epsilon_B$ to vary would introduce two more ways to trade off parameters.

Ryan and collaborators found the same pattern with a different model and dataset. Their Gaussian fit constrained $\theta_{\rm obs}/\theta_c=6.12\pm0.18$ much better than either angle, and the angle itself only after adding the gravitational-wave inclination as a prior. [Gamma-ray burst afterglows in the multi-messenger era, Sec. 5](https://arxiv.org/abs/1909.11691v1)

## What the angle ratio tells you

The shape of the valley reflects the assumed independent angular patches and fixed microphysics. Adding sideways spreading or refreshed shocks changes the light-curve model. A gravitational-wave inclination likelihood and the radio image's proper motion add independent information. Computing a credible interval needs those choices and a stated prior.

This fit gives a ratio near 6.7. Ryan's earlier model fit gives 6.12, about nine percent lower relative to our value. The approximation from the rise gives 5.6, about sixteen percent lower. The three estimates use different models or subsets of the data.

## Try it yourself

1. Edit FIXED in fit\_jets.py to set $\epsilon_B=10^{-3}$ and rerun with --write. Predict which fitted parameter moves most.
2. Remove the X-ray rows from the slice and refit. Does the top-hat do better when only radio and optical points remain?
3. Set the sliders of [the off-axis afterglow Lab](https://sandboxphysics.com/labs/off-axis-afterglow-jets/) to the best Gaussian fit and check that its curves pass through the dots in all three bands. The Lab's misfit readout uses the 22 radio detections. The tutorial's fit uses all 42 detections and reports $\chi^2$.

## Try it in the Lab

[Off-axis GRB afterglow jets](https://sandboxphysics.com/labs/off-axis-afterglow-jets/): Set the Lab to the best Gaussian fit and check all three bands.

## Sources

1. [The panchromatic afterglow of GW170817, Sec. 2 and data table](https://arxiv.org/abs/2006.02382v3)
2. [Gamma-ray burst afterglows in the multi-messenger era, Sec. 5](https://arxiv.org/abs/1909.11691v1)

## Keep reading

Gamma-ray burst afterglows and off-axis jets · Reading path

### From a beamed blast wave to GW170817

1. [Article **Why the GW170817 afterglow kept brightening for months**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/why-the-gw170817-afterglow-kept-brightening/)
2. [Article **Beaming and arrival times of a slowing blast wave**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/blast-wave-beaming-and-arrival-times/)
3. [Article **The synchrotron spectrum and the jet break**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/synchrotron-spectrum-and-the-jet-break/)
4. [Article **Off-axis structured jets and GW170817**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/off-axis-structured-jets-and-gw170817/)
5. [You are here **Fit top-hat and Gaussian jets to GW170817**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/fit-top-hat-and-gaussian-jets-to-gw170817/)
6. [Article **How to read Ryan et al. 2020 on structured-jet afterglows**](https://sandboxphysics.com/stories/gamma-ray-burst-afterglows/reading-ryan-2020-structured-jet-afterglows/)
