21 const double prefactor = std::sqrt(2.0 / M_PI);
22 double Transition(
double x,
double sigma);
23 double TransitionTanh(
double x);
28 auto N = sample.numberOfSlices();
29 m_materialdata.reserve(N);
31 m_zlimits.reserve(N - 1);
32 m_sigmas.reserve(N - 1);
34 auto& slices = sample.averageSlices();
35 for (
size_t i = 0; i < N; ++i) {
36 m_materialdata.push_back(slices[i].material().materialData());
38 m_zlimits.push_back(sample.sliceBottomZ(i));
39 if (
auto p_roughness = sample.bottomRoughness(i)) {
40 m_sigmas.push_back(p_roughness->getSigma());
42 m_sigmas.push_back(0.0);
51 std::vector<complex_t> ProfileHelper::calculateProfile(
const std::vector<double>& z_values)
const
53 complex_t top_value = m_materialdata.size() ? m_materialdata[0] : 0.0;
54 std::vector<complex_t> result(z_values.size(), top_value);
55 for (
size_t i = 0; i < m_zlimits.size(); ++i) {
56 auto sld_diff = m_materialdata[i + 1] - m_materialdata[i];
57 for (
size_t j = 0; j < z_values.size(); ++j) {
58 auto arg = (z_values[j] - m_zlimits[i]);
59 auto t = Transition(arg, m_sigmas[i]);
60 result[j] += sld_diff * t;
66 std::pair<double, double> ProfileHelper::defaultLimits()
const
68 if (m_zlimits.size() < 1)
70 double interface_span = m_zlimits.front() - m_zlimits.back();
71 double default_margin = interface_span > 0.0 ? interface_span / 20.0 : 10.0;
72 double top_margin = m_sigmas.front() > 0.0 ? 5.0 * m_sigmas.front() : default_margin;
73 double bottom_margin = m_sigmas.back() > 0.0 ? 5.0 * m_sigmas.back() : default_margin;
74 double z_min = m_zlimits.back() - bottom_margin;
75 double z_max = m_zlimits.front() + top_margin;
76 return {z_min, z_max};
79 ProfileHelper::~ProfileHelper() =
default;
83 double Transition(
double x,
double sigma)
86 return x < 0.0 ? 1.0 : 0.0;
87 return TransitionTanh(x / sigma);
89 double TransitionTanh(
double x)
91 return (1.0 - std::tanh(prefactor * x)) / 2.0;
Defines class LayerRoughness.
Defines class ProcessedSample.
Defines class ProfileHelper.
Data structure that contains all the necessary data for scattering calculations.