// 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.GetSolidAngleCorr()) { } const std::vector &RadialIntegrationProfile::GetSolidAngleCorr() const { return corrections; } void RadialIntegrationProfile::Add(const std::vector &in_sum, const std::vector &in_count) { std::unique_lock 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 RadialIntegrationProfile::GetResult(bool solid_angle_correction) const { std::vector rad_int_profile(sum.size(), 0); for (int i = 0; i < sum.size(); i++) { float tmp = 0; if (count[i] > 0) { tmp = static_cast(sum[i]) / static_cast(count[i]); if (solid_angle_correction) tmp *= corrections[i]; } rad_int_profile[i] = tmp; } return rad_int_profile; } void RadialIntegrationProfile::GetPlot(JFJochProtoBuf::Plot &plot, bool solid_angle_correction) const { std::unique_lock ul(m); std::vector rad_int_profile = GetResult(solid_angle_correction); *plot.mutable_x() = {bin_to_q.begin(), bin_to_q.end()}; *plot.mutable_y() = {rad_int_profile.begin(), rad_int_profile.end()}; }