If for some reason the midpoint of a detector pixel is not representative for the average scattering intensity of the entire pixel it is possible to resort to Monte-Carlo integration.
To request Monte-Carlo integration over detector pixels, use
simulation.options().setMonteCarloIntegration(
True, n, seed=0, per_ray_fluxes=True)
where n is the number of scattering intensity evaluations per pixel,
and the optional seed determines the random sample.
Each detector pixel uses a fresh mt19937 generator seeded with seed,
so that results are reproducible and independent of the number of
threads. The GSL environment variables GSL_RNG_TYPE and GSL_RNG_SEED
have no influence.
By default, per_ray_fluxes=True recomputes exact outgoing fields at every
sampled scattering direction. Here “fluxes” means the outgoing transmission
T, reflection R and vertical wavevectors kz in each layer.
Set per_ray_fluxes=False explicitly to use the faster pixel-centre
approximation after checking that its accuracy is sufficient. Keep the
default when a critical angle lies inside the pixel (for example, at a
Yoneda edge), when the pixel crosses the horizon (alpha_f = 0), or for
verification.
For form-factor accuracy, estimate the vertical phase variation as
x = k * cos(alpha_f) * delta_alpha_f * h, where k = 2*pi/wavelength,
alpha_f is the central exit angle, delta_alpha_f is the pixel’s
exit-angle span in radians, and h is the particle extent normal to the
surface. Depending on the particle and pixel position, biases of about
1% at x = 0.3 and over 10% at x = 1 can occur. Near a form-factor
minimum inside the pixel, bias can be large even for small x. The phase
variation is an indicator, not an error bound; compare the approximation
with per-ray fields to check the accuracy you need.
Incoming fields are shared across the integral; each particle struct
computes its own outgoing fields for every sampled direction.
Relative to per_ray_fluxes=False, representative scalar calculations
with per-ray fields cost about 2x on a substrate and 14x for 50 bilayers;
the cost depends on the sample and particle shape.
Calls with zero to three arguments are still accepted. With the per-ray default, a polarized pixel crossing the horizon also validates the opposite exit medium and can reject an analyzer setting that the centre-field approximation did not check.
With False, outgoing transmission, reflection and vertical
wavevectors use the pixel centre while lateral wavevectors follow each
sampled direction. In a uniform nonmagnetic medium, fields follow the
sampled direction for both settings.
Two identical lossless nonmagnetic outer media without finite layers use
the exact Born geometry without repeating field propagation.
This argument has no effect when Monte-Carlo integration is disabled or
n is at most one. Roughness scattering remains evaluated at the pixel
centre.
per_ray_fluxes=False for speed. Their displayed diffraction
patterns and the peak search are insensitive to this choice, although
individual pixels can differ, especially near a Yoneda edge.