diff --git a/writer/HDF5NXmx.cpp b/writer/HDF5NXmx.cpp index e3bb7b837..1010833a8 100644 --- a/writer/HDF5NXmx.cpp +++ b/writer/HDF5NXmx.cpp @@ -659,21 +659,28 @@ void NXmx::Metrology(const StartMessage &start, const EndMessage &end) { // the sample - so on a tilted detector it is not the beam position, and a program that wants the // beam position (XDS's ORGX/ORGY, for one) would otherwise have to redo the tilt arithmetic. Built // from the very values written just above and just below, so the three can never disagree. - DiffractionGeometry geometry; - geometry.BeamX_pxl(beam_center_x) - .BeamY_pxl(beam_center_y) - .DetectorDistance_mm(start.detector_distance * 1e3f) - .PixelSize_mm(start.pixel_size_x * 1e3f) - .Orientation(DetectorOrientation(start.detector_orientation_mirror_y, - start.detector_orientation_quarter_turns)) - .PoniRot1_rad(static_cast(rot1)) - .PoniRot2_rad(static_cast(rot2)) - .PoniRot3_rad(static_cast(rot3)); - const auto direct_beam = geometry.GetDirectBeam_pxl(); - SaveScalar(*hdf5_file, "/entry/instrument/detector/detectorSpecific/direct_beam_x", - direct_beam.first)->Units("pixel"); - SaveScalar(*hdf5_file, "/entry/instrument/detector/detectorSpecific/direct_beam_y", - direct_beam.second)->Units("pixel"); + // + // Only where there is a geometry to compute it from. DiffractionGeometry refuses a distance under + // 1 mm or a pixel size of zero, and a message can legitimately carry neither - a writer told to + // prove it can create the files never describes a detector. This dataset is a convenience for + // whoever reads the file later, so it is absent there rather than fatal. + if (start.detector_distance * 1e3f >= 1.0f && start.pixel_size_x > 0.0f) { + DiffractionGeometry geometry; + geometry.BeamX_pxl(beam_center_x) + .BeamY_pxl(beam_center_y) + .DetectorDistance_mm(start.detector_distance * 1e3f) + .PixelSize_mm(start.pixel_size_x * 1e3f) + .Orientation(DetectorOrientation(start.detector_orientation_mirror_y, + start.detector_orientation_quarter_turns)) + .PoniRot1_rad(static_cast(rot1)) + .PoniRot2_rad(static_cast(rot2)) + .PoniRot3_rad(static_cast(rot3)); + const auto direct_beam = geometry.GetDirectBeam_pxl(); + SaveScalar(*hdf5_file, "/entry/instrument/detector/detectorSpecific/direct_beam_x", + direct_beam.first)->Units("pixel"); + SaveScalar(*hdf5_file, "/entry/instrument/detector/detectorSpecific/direct_beam_y", + direct_beam.second)->Units("pixel"); + } HDF5Group transformations(*hdf5_file, "/entry/instrument/detector/transformations"); transformations.NXClass("NXtransformations");