#!/usr/bin/env python3
"""
Flattened depth-probe simulation:
Intensity as function of depth z for a few incident angles alpha_i.
"""

import bornagain as ba
from bornagain import ba_plot as bp, deg, nm


def get_sample():
    vac_mat = ba.Vacuum()
    a_color = (0.05, 0.62, 0.55)
    a_mat = ba.RefractiveMaterial("A", a_color, 6e-5, 0)
    sub_color = (0.28, 0.57, 0.82)
    sub_mat = ba.RefractiveMaterial("Substrate", sub_color, 3e-05, 0)

    sample = ba.Sample()
    sample.addLayer(ba.Layer(vac_mat))
    sample.addLayer(ba.Layer(a_mat, 100*nm))
    sample.addLayer(ba.Layer(sub_mat))

    return sample

def simulate(sample, alpha_i_deg):
    alpha = alpha_i_deg * deg
    scan = ba.AlphaScan(1, alpha, alpha)
    scan.setWavelength(0.3*nm)

    z_axis = ba.EquiDivision("z (nm)", 500, -130*nm, 30*nm)
    simulation = ba.DepthprobeSimulation(scan, sample, z_axis, 0)

    result = simulation.simulate().flat()
    result.setTitle(f'{alpha_i_deg} deg')
    return result

if __name__ == '__main__':
    sample = get_sample()
    angles = [0.4, 0.5, 0.6, 0.65, 0.7]
    results = [simulate(sample, ai) for ai in angles]
    plotargs = bp.parse_commandline()
    bp.plot_multicurve(results, legendloc='lower right', **plotargs)
    bp.export(**plotargs)
