#!/usr/bin/env python3
"""
DWBA simulation of a GISAS experiment, including the specular peak.
Based on Cylinders.py.
"""
import bornagain as ba
from bornagain import ba_plot as bp, deg, nm


def get_sample():
    """
    Standard sample model: dilute random assembly of cylinders on a substrate.
    """
    from bornagain import std_samples
    return std_samples.cylinders()


def get_simulation(sample):
    # Beam
    wavelength = 0.1*nm
    alpha_i = 0.2*deg
    beam = ba.Beam(1e9, wavelength, alpha_i)

    # Detector
    n = 200
    detector = ba.SphericalDetector(n, -2*deg, 2*deg, n, 0., 3*deg)

    simulation = ba.ScatteringSimulation(beam, sample, detector)
    simulation.options().setIncludeSpecular(True)
    return simulation


if __name__ == '__main__':
    sample = get_sample()
    ba.showSample3D(sample, sample_size=120*nm, seed=0)
    simulation = get_simulation(sample)
    result = simulation.simulate()
    bp.plot_datafield(result, unit_aspect=1)
    bp.plt.show()
