From 541f3d48410a7fe356633b07f2799a9c608446d7 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 9 Mar 2023 22:13:49 +0100
Subject: [PATCH] BROKEN

---
 Sim/Scan/AlphaScan.cpp                  |  1 +
 Sim/Scan/AlphaScan.h                    |  2 ++
 Sim/Simulation/DepthprobeSimulation.cpp | 16 ++++++++++++++--
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Sim/Scan/AlphaScan.cpp b/Sim/Scan/AlphaScan.cpp
index cc55ad1afca..c2cb81e99ac 100644
--- a/Sim/Scan/AlphaScan.cpp
+++ b/Sim/Scan/AlphaScan.cpp
@@ -58,6 +58,7 @@ AlphaScan* AlphaScan::clone() const
     auto* result = new AlphaScan(*m_axis);
     result->setIntensity(intensity());
     result->setFootprint(m_footprint.get());
+    result->setAlphaOffset(alphaOffset());
 
     if (m_lambda_distrib)
         result->m_lambda_distrib.reset(m_lambda_distrib->clone());
diff --git a/Sim/Scan/AlphaScan.h b/Sim/Scan/AlphaScan.h
index 002017a95a9..7721d41dadd 100644
--- a/Sim/Scan/AlphaScan.h
+++ b/Sim/Scan/AlphaScan.h
@@ -56,6 +56,8 @@ public:
         return m_alpha_distrib.get();
     }
 
+    double alphaOffset() const { return m_alpha_offset; }
+
 private:
     void checkInitialization();
 
diff --git a/Sim/Simulation/DepthprobeSimulation.cpp b/Sim/Simulation/DepthprobeSimulation.cpp
index a053413461f..b64af793aba 100644
--- a/Sim/Simulation/DepthprobeSimulation.cpp
+++ b/Sim/Simulation/DepthprobeSimulation.cpp
@@ -28,6 +28,7 @@
 #include "Resample/Element/DepthprobeElement.h"
 #include "Sim/Computation/DepthprobeComputation.h"
 #include "Sim/Scan/AlphaScan.h"
+#include <iostream>
 
 DepthprobeSimulation::DepthprobeSimulation(const IBeamScan& scan, const MultiLayer& sample)
     : ISimulation(sample)
@@ -69,9 +70,15 @@ void DepthprobeSimulation::initDistributionHandler()
 
         switch (distribution.whichParameter()) {
         case ParameterDistribution::BeamInclinationAngle:
+        {
+            auto* s = dynamic_cast<AlphaScan*>(m_scan.get());
+            if (!s)
+                throw std::runtime_error("Alpha distribution not compatible with non-alpha scan");
             distributionHandler().defineCallbackForDistribution(
-                &distribution, [&](double d) { m_beam->setInclination(d); });
+                &distribution, [&](double d) { m_beam->setInclination(d);s->setAlphaOffset(d);
+                ASSERT( s->alphaOffset() == m_beam->alpha_i());});
             break;
+        }
         case ParameterDistribution::BeamWavelength:
             distributionHandler().defineCallbackForDistribution(
                 &distribution, [&](double d) { m_scan->setWavelength(d); });
@@ -84,7 +91,12 @@ void DepthprobeSimulation::initDistributionHandler()
 
 void DepthprobeSimulation::runComputation(const ReSample& re_sample, size_t i, double weight)
 {
-    const double result_angle = m_alpha_axis->bin(i).center() + m_beam->alpha_i();
+    const auto* s = dynamic_cast<AlphaScan*>(m_scan.get());
+    if (!s)
+        throw std::runtime_error("Alpha distribution not compatible with non-alpha scan");
+    std::cout << s->alphaOffset() << " vs " << m_beam->alpha_i() << std::endl;
+    ASSERT( s->alphaOffset() == m_beam->alpha_i());
+    const double result_angle = m_alpha_axis->bin(i).center() + s->alphaOffset();
     DepthprobeElement ele(m_scan->wavelength(), -result_angle, m_z_axis.get(),
                           0 < result_angle && result_angle < M_PI_2);
 
-- 
GitLab