Skip to content

[ESSSPECTROSCOPY] Source the BIFROST Bragg peak monitor from the NXmonitor - #698

Open
SimonHeybrock wants to merge 3 commits into
mainfrom
bragg-peak-monitor-nxmonitor
Open

[ESSSPECTROSCOPY] Source the BIFROST Bragg peak monitor from the NXmonitor#698
SimonHeybrock wants to merge 3 commits into
mainfrom
bragg-peak-monitor-nxmonitor

Conversation

@SimonHeybrock

@SimonHeybrock SimonHeybrock commented Aug 11, 2026

Copy link
Copy Markdown
Member

get_calibrated_bragg_peak_detector required NeXusComponent[NXdetector], but the Bragg peak monitor is the elastic monitor (cbm5), written as an NXmonitor in CODA files, the geometry artifacts and the McStas simulation file alike. Loading therefore raised

ValueError: The NeXus group 'elastic_monitor' was expected to be a NXdetector but is a NXmonitor

against every real file. Only the user guide worked, by standing a detector triplet in for the monitor.

The monitor's component, transformation and event data now come from ElasticMonitor, which the workflow already declares in monitor_types — a re-pointing rather than new machinery. A monitor has no pixel offsets, so the position is the transformed origin as in get_calibrated_monitor. Analyzer is dropped: get_base_calibrated_detector_bifrost never reads it, and a monitor in the direct beam has none. The detector stand-in moves to simulation_providers, keeping the user guide working.

Assembly likewise uses assemble_monitor_data. assemble_detector_data groups events by event_id onto a detector_number grid, and a single-pixel monitor has nothing to group by; what remains is the geometry assignment assemble_monitor_data already does. This holds whether or not the events carry an event_id — a file-loaded cbm5_events group does, constant 1 throughout; a stream may not.

Also fixes a latent defect that is not monitor-specific: a time-dependent position makes ltotal carry time, but group_by_rotation has already renamed that dimension to a4, so the broadcast in detector_wavelength_data rejected it. This bites whenever the tank rotates. It stayed hidden because the user guide's stand-in position is static and the inelastic/Q-cut path uses a detector_wavelength_data that takes no ltotal.

Testing

No regression test for the monitor path here — the simulation file's elastic_monitor is histogram-mode, so there is no simulated Bragg peak monitor to drive. It is covered end to end in scipp/esslivedata#1236, where streamed monitor events and live rotation readbacks produce a populated (Qpar, Qperp) map over a multi-angle scan. That branch needs this PR, so it is blocked on it.

Open question

The scientists asked for the map in the laboratory frame, but project_momentum_transfer projects sample_table_momentum_transfer — the sample-table frame, which is what you want against an expected reciprocal lattice. Worth settling before merge.

SimonHeybrock and others added 2 commits August 11, 2026 09:17
The Bragg peak monitor is BIFROST's elastic monitor (cbm5), written as an
NXmonitor in CODA files, in the pinned geometry artifacts, and in the McStas
simulation file alike. The single-crystal workflow instead required it as
NeXusComponent[NXdetector], so loading raised

    ValueError: The NeXus group 'elastic_monitor' was expected to be a
    NXdetector but is a NXmonitor

against every real file. Only the user guide worked, by standing a detector
triplet in for the monitor.

Take the component, its transformation and its event data from ElasticMonitor,
which the workflow already declares in monitor_types, so all the loading nodes
exist. A monitor has no pixel offsets, so the position is the transformed
origin as in get_calibrated_monitor rather than compute_detector_position, and
no detector_number, so the single pixel is named explicitly for event assembly.
The Analyzer dependency is dropped: get_base_calibrated_detector_bifrost never
reads it, and a monitor in the direct beam has no analyzer.

Ltotal is a straight line for the same reason, so insert that provider rather
than leaving every caller to supply it.

Fix a latent defect this exposes: a time-dependent position makes ltotal depend
on 'time', but group_by_rotation has already renamed that same dimension to
'a4', so the broadcast in detector_wavelength_data rejected it. This bites
whenever the tank rotates; the user guide escaped it only because its stand-in
position is static.

The simulated data contains no Bragg peak monitor, so the detector stand-in
moves to simulation_providers and keeps the user guide working.
Streamed monitor events carry no event_id, so assemble_detector_data cannot
group them. The monitor is a single pixel, so assign its geometry onto the
events as assemble_monitor_data does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the essspectroscopy Issues for essspectroscopy. label Aug 11, 2026
@github-actions github-actions Bot changed the title Source the BIFROST Bragg peak monitor from the NXmonitor [ESSSPECTROSCOPY] Source the BIFROST Bragg peak monitor from the NXmonitor Aug 11, 2026
The reason for not using assemble_detector_data is not that streamed
events lack an event_id. It is that assemble_detector_data groups events
by event_id onto a detector_number grid, and the Bragg peak monitor is a
single pixel with nothing to group by. The detector_number assigned to it
existed only to satisfy that grouping and is now unused.

Call assemble_monitor_data, which is exactly the remaining operation:
assign the geometry onto the events. This drops the copy of its body and
the private _add_variances import. The result is independent of whether
the events carry an event_id, so one provider serves a file-loaded
cbm5_events group (which has one, constant 1) and a stream (which, in
esslivedata, does not: its adapter discards the ev44 pixel_id for
monitors not registered as pixellated).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essspectroscopy Issues for essspectroscopy.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant