#!/usr/bin/env python3
"""
Depth-probe simulation of a Ti/Ni multilayer on a Si substrate.

Computes intensity as function of incident angle alpha and depth z
for a 10-bilayer TiNi stack. Compare Depthprobe1.py which uses a
single-layer sample.
"""
import bornagain as ba
from bornagain import ba_plot as bp, deg, nm


def get_sample():
    vacuum = ba.Vacuum()
    substrate_color = (0.28, 0.57, 0.82)
    substrate_mat = ba.RefractiveMaterial(
        "Si_substrate", substrate_color, 7.81e-7, 0)
    ni_color = (0.93, 0.48, 0.14)
    ni_mat = ba.RefractiveMaterial("Ni", ni_color, 3.557e-6, 0)
    ti_color = (0.05, 0.62, 0.55)
    ti_mat = ba.RefractiveMaterial("Ti", ti_color, -7.36e-7, 0)

    n_repetitions = 10
    stack = ba.LayerStack(n_repetitions)
    stack.addLayer(ba.Layer(ti_mat, 3*nm))
    stack.addLayer(ba.Layer(ni_mat, 7*nm))

    sample = ba.Sample()
    sample.addLayer(ba.Layer(vacuum))
    sample.addStack(stack)
    sample.addLayer(ba.Layer(substrate_mat))
    return sample


def get_simulation(sample):
    n = 20
    scan = ba.AlphaScan(n, 0.025*deg, 0.975*deg)
    scan.setWavelength(1*nm)
    z_axis = ba.EquiDivision("z (nm)", n, -100*nm, 100*nm)
    return ba.DepthprobeSimulation(scan, sample, z_axis)


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