#!/usr/bin/env python3
"""
An example of defining a reflectometry instrument
for a time-of-flight experiment with relative Q resolution.

The scan uses a purely q_z-defined beam (no explicit angle or wavelength).
Relative resolution means each Q point is smeared by sigma = 0.03 * q_z.
Compare TOFRWithResolution.py for the pointwise-resolution equivalent.
Note that these approaches work with SLD-based materials only.
"""
import numpy as np
import bornagain as ba
from bornagain import ba_plot as bp, std_samples, nm


def get_sample():
    return std_samples.alternating_layers()


def get_simulation(sample):
    "Specular simulation with a qz-defined beam and relative Q resolution"
    n = <%= test_mode ? 50 : 500 %>

    qzs = np.linspace(0.01, 1, n)  # qz-values
    distr = ba.DistributionGaussian(0., 1., 25, 2.)

    scan = ba.QzScan(qzs)
    scan.setRelativeQResolution(distr, 0.03)

    return ba.SpecularSimulation(scan, sample)


<%= include_partial("template/main/runsim.py",
    "ba.showSample3D(sample, sample_size=120*nm, seed=0)") -%>
