diff --git a/common/Reflection.h b/common/Reflection.h index 00b960dc..de877218 100644 --- a/common/Reflection.h +++ b/common/Reflection.h @@ -21,6 +21,7 @@ struct Reflection { float bkg; float sigma; float dist_ewald; + float lp; bool observed = false; }; diff --git a/docs/CBOR.md b/docs/CBOR.md index 68f86fab..c489bd63 100644 --- a/docs/CBOR.md +++ b/docs/CBOR.md @@ -146,6 +146,7 @@ See [DECTRIS documentation](https://github.com/dectris/documentation/tree/main/s | - sigma | float | standard deviation, estimated from counting statistics (photons) | | | | - image | float | image number (present for each spot) | | | | - dist_ewald | float | distance to Ewald sphere (present only for indexed spots) | | | +| - lp | float | Lorentz and polarization corrections | | | | spot_count | uint64 | Spot count | | | | spot_count_ice_rings | uint64 | Number of spots within identified rings (experimental) | | | | spot_count_low_res | uint64 | Number of spots in low resolution (prior to filtering) | | | diff --git a/frame_serialize/CBORStream2Deserializer.cpp b/frame_serialize/CBORStream2Deserializer.cpp index 1419c302..28695a5d 100644 --- a/frame_serialize/CBORStream2Deserializer.cpp +++ b/frame_serialize/CBORStream2Deserializer.cpp @@ -463,6 +463,8 @@ namespace { r.sigma = GetCBORFloat(map_value); else if (key == "image") r.image_number = GetCBORFloat(map_value); + else if (key == "rlp") + r.lp = GetCBORFloat(map_value); else if (key == "rp") r.dist_ewald = GetCBORFloat(map_value); else diff --git a/frame_serialize/CBORStream2Serializer.cpp b/frame_serialize/CBORStream2Serializer.cpp index 2a1012b9..dd26989d 100644 --- a/frame_serialize/CBORStream2Serializer.cpp +++ b/frame_serialize/CBORStream2Serializer.cpp @@ -243,6 +243,7 @@ inline void CBOR_ENC(CborEncoder &encoder, const Reflection& r) { CBOR_ENC(mapEncoder, "sigma", r.sigma); CBOR_ENC(mapEncoder, "image", r.image_number); CBOR_ENC(mapEncoder, "rp", r.dist_ewald); + CBOR_ENC(mapEncoder, "lp", r.lp); cborErr(cbor_encoder_close_container(&encoder, &mapEncoder)); } diff --git a/image_analysis/bragg_integration/BraggIntegrate2D.cpp b/image_analysis/bragg_integration/BraggIntegrate2D.cpp index fa6dc6b1..ad174b7a 100644 --- a/image_analysis/bragg_integration/BraggIntegrate2D.cpp +++ b/image_analysis/bragg_integration/BraggIntegrate2D.cpp @@ -63,6 +63,8 @@ void IntegrateReflection(Reflection &r, const T *image, size_t xpixel, size_t yp } } +#include + template std::vector IntegrateInternal(const DiffractionExperiment &experiment, const CompressedImage &image, @@ -100,6 +102,7 @@ std::vector IntegrateInternal(const DiffractionExperiment &experimen float two_theta = geom.TwoTheta_rad(r.predicted_x, r.predicted_y); corr *= std::sin(two_theta); } + r.lp = 1.0f / corr; r.I *= corr; r.bkg *= corr; r.sigma *= corr; diff --git a/reader/JFJochHDF5Reader.cpp b/reader/JFJochHDF5Reader.cpp index 9acbc39a..06546cbd 100644 --- a/reader/JFJochHDF5Reader.cpp +++ b/reader/JFJochHDF5Reader.cpp @@ -680,6 +680,7 @@ bool JFJochHDF5Reader::LoadImage_i(std::shared_ptr &dataset auto int_sum = source_file->ReadOptVector(image_group_name + "/int_sum"); auto int_err = source_file->ReadOptVector(image_group_name + "/int_err"); auto bkg = source_file->ReadOptVector(image_group_name + "/background_mean"); + auto lp = source_file->ReadOptVector(image_group_name + "/lp"); if (h.size() != l.size() || h.size() != k.size() || h.size() != d.size() || h.size() != predicted_x.size() || h.size() != predicted_y.size() @@ -687,6 +688,8 @@ bool JFJochHDF5Reader::LoadImage_i(std::shared_ptr &dataset throw JFJochException(JFJochExceptionCategory::HDF5, "Wrong size of reflections dataset"); for (size_t i = 0; i < h.size(); i++) { + float lp_val = 0.0; + if (lp.size() > i) lp_val = lp.at(i); Reflection r{ .h = h.at(i), .k = k.at(i), @@ -696,7 +699,8 @@ bool JFJochHDF5Reader::LoadImage_i(std::shared_ptr &dataset .d = d.at(i), .I = int_sum.at(i), .bkg = bkg.at(i), - .sigma = int_err.at(i) + .sigma = int_err.at(i), + .lp = lp_val }; message.reflections.emplace_back(r); } diff --git a/writer/HDF5DataFilePluginReflection.cpp b/writer/HDF5DataFilePluginReflection.cpp index fe9b24ca..ba6aa4d4 100644 --- a/writer/HDF5DataFilePluginReflection.cpp +++ b/writer/HDF5DataFilePluginReflection.cpp @@ -16,7 +16,7 @@ void HDF5DataFilePluginReflection::Write(const DataMessage &msg, uint64_t image_ return; std::vector h, k, l; - std::vector I, sigma, d; + std::vector I, sigma, d, lp; std::vector image, pred_x, pred_y, bkg; for (const auto &refl : msg.reflections) { @@ -30,6 +30,7 @@ void HDF5DataFilePluginReflection::Write(const DataMessage &msg, uint64_t image_ pred_x.emplace_back(refl.predicted_x); pred_y.emplace_back(refl.predicted_y); bkg.emplace_back(refl.bkg); + lp.emplace_back(refl.lp); } std::string image_group_name = fmt::format("image_{:06d}", image_number); @@ -45,6 +46,7 @@ void HDF5DataFilePluginReflection::Write(const DataMessage &msg, uint64_t image_ image_group.SaveVector("int_err", sigma); image_group.SaveVector("background_mean", bkg); image_group.SaveVector("observed_frame", image); + image_group.SaveVector("lp", lp); } void HDF5DataFilePluginReflection::WriteFinal(HDF5File &data_file) {