+++
title = "Depth probe"
weight = 80
+++

## Depth probe simulation

Depth probe simulation is an auxiliary simulation type, which helps to visualize
the total intensity in dependence on the beam incidence angle and the position in
the sample.

#### Compute intensity

The depth-probe simulation computes the local **field intensity**
|ψ(z)|²/|ψ_i|² — the squared wave amplitude relative to the incident
wave.
This quantity is **not** the energy flux density, and it is **not** the
Fresnel transmission coefficient T.
Due to standing waves, it can exceed 1, whereas T ≤ 1 always.

To compute the total wave intensity as function of $\alpha_\text{i}$ and z,
use
```python
import bornagain as ba
scan = ...
sample = ...
z_axis = ba.EquiDivision("z (nm)", nz, z_min, z_max)
simulation = ba.DepthprobeSimulation(scan, sample, z_axis)
# ... set options
result = simulation.simulate()
```

Supported scan types: grazing angle scan, wavelength scan, wavenumber qz scan.

For the constructor arguments, see sections [scan](/ref/instr/scan),
[sample](/ref/sample).

For optional settings, see [simulation options](/ref/sim/setup/options).

For the return type of function `simulate()`,
see [Datafield](/ref/data/datafield).

#### Partial waves, modulus, phase

The constructor takes an optional `flags` argument
```
simulation = ba.DepthprobeSimulation(scan, sample, z_axis, flags)
```

Flags may designate a partial beam
```
ba.ZDirection_None        # = 0, may be ommitted: total field
ba.ZDirection_Reflected   # = 1, reflected beam only
ba.ZDirection_Transmitted # = 2, transmitted beam only
```
or/and a property of the simulated wave field
```
ba.WaveProperty_Intensity # = 0, may be ommitted: intensity, |psi|^2
ba.WaveProperty_Modulus   # = 4, modulus of wave amplitude, |psi|
ba.WaveProperty_Phase     # = 8, phase of wave amplitude, arg(psi), in rad
```
To combine flags from each of these groups, combine them with the "or" operator:
```
flags = ba.ZDirection_Reflected | ba.WaveProperty_Modulus
```

#### Examples

- [Basic example: thin film on substrate](depthprobe1)
- [Fresnel transmission](transmission)
- [Transmitted amplitude modulus](transmitted_modulus)
- [Opaque sample](opaque)
- [Resonator](resonator)

#### History

Depth probe simulation was introduced in BornAgain 1.12.
It was first used and documented in
Frielinghaus et al, [Nucl Instr Meth A 871, 72 (2017)](https://doi.org/10.1016/j.nima.2017.07.064)
and
Adlmann et al, [J Phys Condens Matter 30, 165901 (2018)](https://doi.org/10.1088/1361-648X/aab573).
