From ddd9aab8c68e9d0bf01d4f3e0aec712aa0237611 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 17 Oct 2023 12:24:49 +0200 Subject: [PATCH 1/3] merge 2 fcts --- Device/Data/Datafield.cpp | 7 +------ Device/Data/Datafield.h | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Device/Data/Datafield.cpp b/Device/Data/Datafield.cpp index 38a8185c000..7f34ed8f7d7 100644 --- a/Device/Data/Datafield.cpp +++ b/Device/Data/Datafield.cpp @@ -446,11 +446,6 @@ Datafield Datafield::normalizedToMax() const } std::vector<std::vector<double>> Datafield::values2D() const -{ - return to2Dvector(m_values); -} - -std::vector<std::vector<double>> Datafield::to2Dvector(const std::vector<double>& in) const { ASSERT(rank() == 2); std::vector<std::vector<double>> result; @@ -463,7 +458,7 @@ std::vector<std::vector<double>> Datafield::to2Dvector(const std::vector<double> for (size_t row = 0; row < nrows; ++row) { result[row].resize(ncols, 0.0); for (size_t col = 0; col < ncols; ++col) - result[row][col] = in[row * ncols + col]; + result[row][col] = m_values[row * ncols + col]; } return result; diff --git a/Device/Data/Datafield.h b/Device/Data/Datafield.h index 90c67110260..e2062e0f7c5 100644 --- a/Device/Data/Datafield.h +++ b/Device/Data/Datafield.h @@ -167,8 +167,6 @@ private: //! between [xbinlow, xbinup]. Datafield* create_yProjection(int xbinlow, int xbinup) const; - std::vector<std::vector<double>> to2Dvector(const std::vector<double>& in) const; - #endif // SWIG }; -- GitLab From e9cd4f479d1af3046c8581903f88a07156283557 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 17 Oct 2023 12:38:59 +0200 Subject: [PATCH 2/3] provide and use Datafield::setVector2D --- Device/Data/Datafield.cpp | 22 ++++++++++++++++------ Device/Data/Datafield.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Device/Data/Datafield.cpp b/Device/Data/Datafield.cpp index 7f34ed8f7d7..b1758126396 100644 --- a/Device/Data/Datafield.cpp +++ b/Device/Data/Datafield.cpp @@ -132,12 +132,7 @@ Datafield::Datafield(const std::string& xlabel, const std::string& ylabel, newEquiDivision(ylabel, nrows, 0.0, (double)nrows)}; m_frame.reset(new Frame(std::move(axes))); - m_values.reserve(nrows * ncols); - for (size_t j = 0; j < nrows; ++j) { - ASSERT(vec[j].size() == ncols); - for (size_t i = 0; i < ncols; ++i) - m_values.push_back(vec[j][i]); - } + setVector2D(vec); } Datafield::Datafield(Datafield&&) noexcept = default; @@ -213,6 +208,21 @@ void Datafield::setVector(const std::vector<double>& vector) m_values = vector; } +void Datafield::setVector2D(const std::vector<std::vector<double>>& in) +{ + const size_t ncols = axis(0).size(); + const size_t nrows = axis(1).size(); + + ASSERT(in.size() == nrows); + m_values.clear(); + m_values.reserve(nrows * ncols); + for (size_t j = 0; j < nrows; ++j) { + ASSERT(in[j].size() == ncols); + for (size_t i = 0; i < ncols; ++i) + m_values.push_back(in[j][i]); + } +} + size_t Datafield::rank() const { return frame().rank(); diff --git a/Device/Data/Datafield.h b/Device/Data/Datafield.h index e2062e0f7c5..5428c6dc345 100644 --- a/Device/Data/Datafield.h +++ b/Device/Data/Datafield.h @@ -147,6 +147,7 @@ public: //! Sets new values to raw data vector. void setVector(const std::vector<double>& data_vector); + void setVector2D(const std::vector<std::vector<double>>& in); bool hasErrorSigmas() const; std::vector<double>& errorSigmas(); -- GitLab From 98107e2b29cf5af6846dc4e0010486dda25acf12 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 17 Oct 2023 12:43:09 +0200 Subject: [PATCH 3/3] use it in convolution --- Device/Resolution/ConvolutionDetectorResolution.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Device/Resolution/ConvolutionDetectorResolution.cpp b/Device/Resolution/ConvolutionDetectorResolution.cpp index 571e3a5981f..a8b69dcda46 100644 --- a/Device/Resolution/ConvolutionDetectorResolution.cpp +++ b/Device/Resolution/ConvolutionDetectorResolution.cpp @@ -92,7 +92,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* df) const // Truncate negative values that can arise because of finite precision of Fourier Transform for (double& e : result) e = std::max(0.0, e); - // Populate intensity map with results + df->setVector(result); } @@ -124,17 +124,12 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* df) const } kernel[ix] = row_vector; } + // Calculate convolution std::vector<std::vector<double>> result; Convolve().fftconvolve(df->values2D(), kernel, result); - // Populate intensity map with results - ASSERT(nx * ny == df->size()); - for (size_t i = 0; i < df->size(); ++i) { - size_t i0 = df->frame().projectedIndex(i, 0); - size_t i1 = df->frame().projectedIndex(i, 1); - (*df)[i] = std::max(0.0, result[i0][i1]); - } + df->setVector2D(result); } double ConvolutionDetectorResolution::getIntegratedPDF1d(double x, double step) const -- GitLab