From a5c199afdaf972b42a07e87fba68f09d811dee12 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Tue, 17 Nov 2020 12:46:15 +0100
Subject: [PATCH] analysis ctd

---
 Sample/Fresnel/FormFactorCoherentSum.cpp | 16 ++++++----------
 devtools/architecture/Scattering.md      | 10 +++++++++-
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/Sample/Fresnel/FormFactorCoherentSum.cpp b/Sample/Fresnel/FormFactorCoherentSum.cpp
index 69fafb61fac..c2059a08eac 100644
--- a/Sample/Fresnel/FormFactorCoherentSum.cpp
+++ b/Sample/Fresnel/FormFactorCoherentSum.cpp
@@ -26,29 +26,25 @@ void FormFactorCoherentSum::addCoherentPart(const FormFactorCoherentPart& part)
 complex_t FormFactorCoherentSum::evaluate(const SimulationElement& sim_element) const
 {
     complex_t result{};
-    for (auto& part : m_parts) {
+    for (auto& part : m_parts)
         result += part.evaluate(sim_element);
-    }
     return result;
 }
 
 Eigen::Matrix2cd FormFactorCoherentSum::evaluatePol(const SimulationElement& sim_element) const
 {
     Eigen::Matrix2cd result = Eigen::Matrix2cd::Zero();
-    for (auto& part : m_parts) {
+    for (auto& part : m_parts)
         result += part.evaluatePol(sim_element);
-    }
     return result;
 }
 
 void FormFactorCoherentSum::scaleRelativeAbundance(double total_abundance)
 {
-    if (total_abundance > 0.0) {
-        m_abundance /= total_abundance;
-        return;
-    }
-    throw Exceptions::LogicErrorException("FormFactorCoherentSum::scaleRelativeAbundance: "
-                                          "Trying to scale with non strictly positive factor.");
+    if (total_abundance <= 0.0)
+        throw Exceptions::LogicErrorException("FormFactorCoherentSum::scaleRelativeAbundance: "
+                                              "Trying to scale with non strictly positive factor.");
+    m_abundance /= total_abundance;
 }
 
 double FormFactorCoherentSum::radialExtension() const
diff --git a/devtools/architecture/Scattering.md b/devtools/architecture/Scattering.md
index e052a9584da..ea840fabec0 100644
--- a/devtools/architecture/Scattering.md
+++ b/devtools/architecture/Scattering.md
@@ -40,7 +40,7 @@ The `ParticleLayoutComputation` constructor points the member `m_interference_fu
 
 `ParticleLayoutComputation::compute` increments `SimulationElement::m_intensity` by a scattering intensity times the `ProcessedLayout::surfaceDensity()`. The intensity is computed by `m_interference_function_strategy->evaluate`, which is implemented as `IInterferenceFunctionStrategy::evaluate`. Except for Monte-Carlo integration, this wraps just one call to `IInterferenceFunctionStrategy::evaluateSinglePoint`. For unpolarized scattering, and except for radial paracrystals, the next call goes to `DecouplingApproximationStrategy::scalarCalculation`.
 
-`DecouplingApproximationStrategy::scalarCalculation` performs a coherent and an incoherent summation over scattering amplitudes `ff` obtained from `ProcessedLayout::formFactorList()`, which is of type `FormFactorCoherentSum`. The mixed sum is sum
+`DecouplingApproximationStrategy::scalarCalculation` performs a coherent and an incoherent summation over scattering amplitudes `ff` obtained by calling `FormFactorCoherentSum::evaluate` on members of `ProcessedLayout::formFactorList()`. The mixed sum is sum
 
 > |ff|^2 + |sum ff|^2 * (coherence_factor - 1)
 
@@ -57,3 +57,11 @@ By default, outer_iff = 1, so that
 For the simplest of all interference functions, `InterferenceFunctionNone::iff_without_dw` just returns 1, so that
 
 > coherence_factor = 1.
+
+### Computing the particle formfactor
+
+`FormFactorCoherentSum::evaluate` returns the sum over `FormFactorCoherentPart::evaluate`.
+
+`FormFactorCoherentPart` wraps an `IFormFactor` and additionally holds members `m_fresnel_map` and ``m_layer_index` that are set by `FormFactorCoherentPart::setSpecularInfo`. This information is forwarded by calling `IFormFactor::setSpecularInfo`, which does nothing, unless overridden in `FormFactorDWBA::setSpecularInfo`.
+
+After this preparation, `FormFactorDWBA::evaluate` calls `IFormFactor::evaluate`, which is pure virtual, overridden by `FormFactorDWBA::evaluate`, which computes the sum over the four DWBA terms. This involves four calls to `m_form_factor->evaluate`. The member `m_form_factor` is probably of type `IFormFactorBorn`. `IFormFactorBorn::evaluate` calls `IFormFactorBorn::evaluate_for_q`, which is pure virtual, overriden by shape-specific classes like `FormFactorFullSphere`.
-- 
GitLab