#!/usr/bin/env python3
"""
Same as CylindersAndSpecular.py, but with beam and detector
both rotated by phi = 1.34 deg.

This example tests that indexOfSpecular correctly handles non-zero phi.
The simulation result should be identical to CylindersAndSpecular.py.
"""
import bornagain as ba
from bornagain import ba_plot as bp, deg, nm

phi = 1.34*deg


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 with non-zero phi
    wavelength = 0.1*nm
    alpha_i = 0.2*deg
    beam = ba.Beam(1e9, wavelength, alpha_i, phi)

    # Detector rotated by phi, otherwise same as in CylindersAndSpecular
    n = 11
    detector = ba.SphericalDetector(n, -2*deg + phi, 2*deg + phi, n, 0., 3*deg)

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


if __name__ == '__main__':
    sample = get_sample()
    simulation = get_simulation(sample)
    result = simulation.simulate()
    from bornagain import ba_check
    ba_check.persistence_test(result)
