diff --git a/image_analysis/RadialIntegrationProfile.cpp b/image_analysis/RadialIntegrationProfile.cpp index 46bc6dbe..7510c969 100644 --- a/image_analysis/RadialIntegrationProfile.cpp +++ b/image_analysis/RadialIntegrationProfile.cpp @@ -4,11 +4,14 @@ #include "RadialIntegrationProfile.h" #include "../common/JFJochException.h" -RadialIntegrationProfile::RadialIntegrationProfile(RadialIntegrationMapping &mapping) +RadialIntegrationProfile::RadialIntegrationProfile(RadialIntegrationMapping &mapping, + const DiffractionExperiment& experiment) : bin_to_q(mapping.GetBinToQ()), sum(mapping.GetBinNumber(), 0), - count(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 &in_sum, const std::vector &in_count) { @@ -23,24 +26,22 @@ void RadialIntegrationProfile::Add(const std::vector &in_sum, const std throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Mismatch in size of sum/count datasets"); } -std::vector RadialIntegrationProfile::GetResult(const DiffractionExperiment &experiment) const { +std::vector RadialIntegrationProfile::GetResult() 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 (experiment.GetSolidAngleCorrection()) - tmp /= experiment.CalcRadIntSolidAngleCorr(bin_to_q[i]); + tmp = static_cast(sum[i]) / static_cast(count[i]) * corrections[i]; rad_int_profile[i] = tmp; } return rad_int_profile; } -void RadialIntegrationProfile::GetPlot(JFJochProtoBuf::Plot &plot, const DiffractionExperiment &experiment) const { +void RadialIntegrationProfile::GetPlot(JFJochProtoBuf::Plot &plot) const { std::unique_lock ul(m); - std::vector rad_int_profile = GetResult(experiment); + std::vector 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()}; diff --git a/image_analysis/RadialIntegrationProfile.h b/image_analysis/RadialIntegrationProfile.h index 4a74faf7..c33d092f 100644 --- a/image_analysis/RadialIntegrationProfile.h +++ b/image_analysis/RadialIntegrationProfile.h @@ -15,11 +15,12 @@ class RadialIntegrationProfile { std::vector sum; std::vector count; std::vector bin_to_q; + std::vector corrections; public: - explicit RadialIntegrationProfile(RadialIntegrationMapping &mapping); + explicit RadialIntegrationProfile(RadialIntegrationMapping &mapping, const DiffractionExperiment &experiment); void Add(const std::vector &sum, const std::vector &count); - std::vector GetResult(const DiffractionExperiment &experiment) const; - void GetPlot(JFJochProtoBuf::Plot &plot, const DiffractionExperiment &experiment) const; + std::vector GetResult() const; + void GetPlot(JFJochProtoBuf::Plot &plot) const; }; #endif //JUNGFRAUJOCH_RADIALINTEGRATIONPROFILE_H diff --git a/receiver/JFJochReceiver.cpp b/receiver/JFJochReceiver.cpp index c7f4ff7e..1fc85b44 100644 --- a/receiver/JFJochReceiver.cpp +++ b/receiver/JFJochReceiver.cpp @@ -75,10 +75,10 @@ JFJochReceiver::JFJochReceiver(const JFJochProtoBuf::ReceiverInput &settings, logger.Info("GPU support missing"); rad_int_mapping = std::make_unique(experiment, one_byte_mask.data()); - rad_int_profile = std::make_unique(*rad_int_mapping); + rad_int_profile = std::make_unique(*rad_int_mapping, experiment); for (int i = 0; i < experiment.GetDataFileCount(); i++) - rad_int_profile_per_file.emplace_back(std::make_unique(*rad_int_mapping)); + rad_int_profile_per_file.emplace_back(std::make_unique(*rad_int_mapping, experiment)); spot_finder_mask = calib->CalculateOneByteMask(experiment); } @@ -589,10 +589,10 @@ void JFJochReceiver::FinalizeMeasurement() { if (rad_int_profile) message.rad_int_result["dataset"] - = rad_int_profile->GetResult(experiment); + = rad_int_profile->GetResult(); for (int i = 0; i < rad_int_profile_per_file.size(); i++) message.rad_int_result["file" + std::to_string(i)] - = rad_int_profile_per_file[i]->GetResult(experiment); + = rad_int_profile_per_file[i]->GetResult(); image_pusher.EndDataCollection(message); logger.Info("Disconnected from writers"); @@ -648,10 +648,10 @@ JFJochProtoBuf::Plot JFJochReceiver::GetPlots(const JFJochProtoBuf::PlotRequest case JFJochProtoBuf::RAD_INT: if (request.has_file_number()) { if (request.file_number() < rad_int_profile_per_file.size()) - rad_int_profile_per_file[request.file_number()]->GetPlot(ret, experiment); + rad_int_profile_per_file[request.file_number()]->GetPlot(ret); } else { if (rad_int_profile) - rad_int_profile->GetPlot(ret, experiment); + rad_int_profile->GetPlot(ret); } break; case JFJochProtoBuf::SPOT_COUNT: diff --git a/tests/HDF5WritingTest.cpp b/tests/HDF5WritingTest.cpp index 6c6a6700..04d7901f 100644 --- a/tests/HDF5WritingTest.cpp +++ b/tests/HDF5WritingTest.cpp @@ -148,15 +148,15 @@ TEST_CASE("HDF5MasterFile_RadInt", "[HDF5][Full]") { x.FilePrefix("test01_rad_int").ImagesPerTrigger(950); RadialIntegrationMapping mapping(x); - RadialIntegrationProfile profile(mapping); + RadialIntegrationProfile profile(mapping, x); StartMessage start_message; x.FillMessage(start_message); start_message.rad_int_bin_to_q = mapping.GetBinToQ(); EndMessage end_message; end_message.number_of_images = x.GetImageNum(); - end_message.rad_int_result["avg1"] = profile.GetResult(x); - end_message.rad_int_result["avg2"] = profile.GetResult(x); + end_message.rad_int_result["avg1"] = profile.GetResult(); + end_message.rad_int_result["avg2"] = profile.GetResult(); REQUIRE_NOTHROW(HDF5Metadata::NXmx(start_message, end_message)); } @@ -231,7 +231,7 @@ TEST_CASE("HDF5Writer_Rad_Int_Profile", "[HDF5][Full]") { x.QSpacingForRadialInt_recipA(0.1).LowQForRadialInt_recipA(0.1).HighQForRadialInt_recipA(4); RadialIntegrationMapping mapping(x); - RadialIntegrationProfile profile(mapping); + RadialIntegrationProfile profile(mapping, x); std::vector rad_int_profile(mapping.GetBinNumber(), 4.0); std::vector rad_int_avg(mapping.GetBinNumber(), 0.33); diff --git a/tests/RadialIntegrationTest.cpp b/tests/RadialIntegrationTest.cpp index f361efea..ebf7952f 100644 --- a/tests/RadialIntegrationTest.cpp +++ b/tests/RadialIntegrationTest.cpp @@ -85,7 +85,7 @@ TEST_CASE("RadialIntegrationProfile","[RadialIntegration]") { RadialIntegrationMapping mapping(x); - RadialIntegrationProfile profile(mapping); + RadialIntegrationProfile profile(mapping, x); std::vector sum(mapping.GetBinNumber()); std::vector count(mapping.GetBinNumber()); @@ -100,7 +100,7 @@ TEST_CASE("RadialIntegrationProfile","[RadialIntegration]") { REQUIRE_THROWS(profile.Add(sum_wr, count)); JFJochProtoBuf::Plot plot; - profile.GetPlot(plot, x); + profile.GetPlot(plot); REQUIRE(plot.x_size() == mapping.GetBinNumber()); REQUIRE(plot.y_size() == mapping.GetBinNumber());