Shift of particle position in SLD when using form factor parameter distribution

Dear all,

There seems to be a shift of the particle lower boundary with respect to the substrate when the shape of the particle is varied with a parameter distribution. I.e. the particles are not attached to the substrate. This occurs in sample_tools.materialProfile, in the SDL calculation. I haven't checked if it also affects the scattering.

Here is a modified version of Examples/varia/MaterialProfileWithParticles.py, which illustrates this issue. The cone radius is distributed with a Gaussian, which should not affect the cone height (identical results are also obtained with a truncated sphere form factor).

Example code offset SLD
#!/usr/bin/env python3
"""
Plot an SLD profile for a sample with a sliced particle layer.
"""

import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, sample_tools
import numpy as np
import matplotlib.pyplot as plt


def get_sample():
    # materials
    m_ambient = ba.MaterialBySLD("Ambient", 0, 0)
    m_particle = ba.MaterialBySLD("Particle", 5e-6, 0)
    m_substrate = ba.MaterialBySLD("SiSubstrate", 2.0704e-06, 0)

    # layers
    ambient_layer = ba.Layer(m_ambient)
    substrate_layer = ba.Layer(m_substrate)

    # particle layout
    layout = ba.ParticleLayout()
    
    radius_distr = ba.DistributionGaussian(5*nm, 1*nm, 5)
    for radius_parsample in radius_distr.distributionSamples():
        ff = ba.Cone(radius_parsample.value, 10*nm, 75*deg)
        particle = ba.Particle(m_particle, ff)
        layout.addParticle(particle,radius_parsample.weight)
    
    iff = ba.Interference2DLattice(ba.SquareLattice2D(10*nm, 0))
    layout.setInterference(iff)
    ambient_layer.addLayout(layout)
    ambient_layer.setNumberOfSlices(200)

    # sample
    sample = ba.MultiLayer()
    sample.addLayer(ambient_layer)
    sample.addLayer(substrate_layer)

    return sample


if __name__ == '__main__':
    bp.parse_args()

    sample = get_sample()
    zpoints, slds = sample_tools.materialProfile(sample, 400)

    plt.figure()
    plt.plot(zpoints, np.real(slds))

    bp.show_or_export()

BornAgain: version 20.0, Python 3.9.16, Win 10

Expected result:

It is expected that the SLD would increase at z = 0 up to the SLD of the Cone base, followed by the decrease caused by the decreasing diameter of the cone (as in the original Examples/varia/MaterialProfileWithParticles.py, number of slices increased to 200):

grafik

Actual result:

Instead, there is now a minimum at z = 0.

grafik

To me it looks like the vertical particle position is incorrect, i.e. some particles are placed too high above the substrate. This is surprising to me since the particle height is not (directly) altered. Do you have any idea what might be the cause for this?

Cheers,

Timo

Related issue: #342

Edited by Timo Fuchs