49 lines
1.8 KiB
C++
49 lines
1.8 KiB
C++
// Copyright (2019-2023) Paul Scherrer Institute
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "RadialIntegrationProfile.h"
|
|
#include "../common/JFJochException.h"
|
|
|
|
RadialIntegrationProfile::RadialIntegrationProfile(RadialIntegrationMapping &mapping,
|
|
const DiffractionExperiment& experiment)
|
|
: bin_to_q(mapping.GetBinToQ()),
|
|
sum(mapping.GetBinNumber(), 0),
|
|
count(mapping.GetBinNumber(), 0),
|
|
corrections(mapping.GetBinNumber(), 1.0f){
|
|
for (int i = 0; i < corrections.size(); i++)
|
|
corrections[i] = 1.0f / experiment.CalcRadIntSolidAngleCorr(bin_to_q[i]);
|
|
}
|
|
|
|
void RadialIntegrationProfile::Add(const std::vector<int32_t> &in_sum, const std::vector<int32_t> &in_count) {
|
|
std::unique_lock<std::mutex> ul(m);
|
|
|
|
if ((in_sum.size() == sum.size()) && (in_count.size() == count.size())) {
|
|
for (int i = 0; i < sum.size(); i++) {
|
|
sum[i] += in_sum[i];
|
|
count[i] += in_count[i];
|
|
}
|
|
} else if (!in_sum.empty() && !in_count.empty())
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Mismatch in size of sum/count datasets");
|
|
}
|
|
|
|
std::vector<float> RadialIntegrationProfile::GetResult() const {
|
|
std::vector<float> rad_int_profile(sum.size(), 0);
|
|
for (int i = 0; i < sum.size(); i++) {
|
|
float tmp = 0;
|
|
if (count[i] > 0)
|
|
tmp = static_cast<float>(sum[i]) / static_cast<float>(count[i]) * corrections[i];
|
|
rad_int_profile[i] = tmp;
|
|
}
|
|
return rad_int_profile;
|
|
}
|
|
|
|
|
|
void RadialIntegrationProfile::GetPlot(JFJochProtoBuf::Plot &plot) const {
|
|
std::unique_lock<std::mutex> ul(m);
|
|
|
|
std::vector<float> rad_int_profile = GetResult();
|
|
|
|
*plot.mutable_x() = {bin_to_q.begin(), bin_to_q.end()};
|
|
*plot.mutable_y() = {rad_int_profile.begin(), rad_int_profile.end()};
|
|
}
|