Skip to content

Conversation

@rosswhitfield
Copy link
Member

@rosswhitfield rosswhitfield commented Jan 6, 2026

Description of work

This allows you to provide a GroupingWorkspace that will be used to group the events by detector id to the correct output spectra. This means a many-to-many relationtionship between bank and output spectra. By default without a GroupingWorkspace the events are put in a one-to-one bank to spectra mapping.

The current implementation only works when not using a splitter workpsace but that ability will be added next.

Refs:

To test:

Simple usgae example

inst = LoadEmptyInstrument(InstrumentName="VULCAN")
GenerateGroupingPowder(inst, GroupingWorkspace='powder_group', AngleStep=45)

ws = AlignAndFocusPowderSlim("VULCAN_218062.nxs.h5", GroupingWorkspace="powder_group",
                             L1=43.755,
                             L2=[2, 2.25, 2.5],
                             Polar=[90]*3)

print(ws.getNumberHistograms()) 

A easy way to test is to create a GroupingWorkspace with GenerateGroupingPowder which can then be compare to using GroupDetectors.

Using 10 degrees gives 12 output spectra

ws = LoadEventNexus("VULCAN_218062.nxs.h5", NumberOfBins=1)

GenerateGroupingPowder(ws, GroupingWorkspace='powder_group_10', AngleStep=10)

ws2 = GroupDetectors(ws, CopyGroupingFromWorkspace="powder_group_10")
ws2 = Rebin(ws2, "0,50000,50000", PreserveEvents=False)


ws3=AlignAndFocusPowderSlim("VULCAN_218062.nxs.h5", GroupingWorkspace="powder_group_10", XMin=0, XMax=50000, XDelta=50000, BinningMode="Linear", BinningUnits="TOF",
                             L1=43.755,
                             L2=[2]*12,
                             Polar=[90]*12,
                             Azimuthal=[0]*12)

CompareWorkspaces(ws2, ws3, CheckSpectraMap=False, CheckInstrument=False)

This is what the grouping looks like

groups_10

Using 45 degrees gives only 3 output spectra

ws = LoadEventNexus("VULCAN_218062.nxs.h5", NumberOfBins=1)

GenerateGroupingPowder(ws, GroupingWorkspace='powder_group_45', AngleStep=45)

ws3 = GroupDetectors(ws, CopyGroupingFromWorkspace="powder_group_45")
ws3 = Rebin(ws3, "0,50000,50000", PreserveEvents=False)


ws4=AlignAndFocusPowderSlim("VULCAN_218062.nxs.h5", GroupingWorkspace="powder_group_45", XMin=0, XMax=50000, XDelta=50000, BinningMode="Linear", BinningUnits="TOF",
                             L1=43.755,
                             L2=[2]*3,
                             Polar=[90]*3)

CompareWorkspaces(ws3, ws4, CheckSpectraMap=False, CheckInstrument=False)

The grouping looks like

groups_45

Grouping from calibartion file

If a calibration file but no GroupingWorkspace is provided then the grouping infortmation in the calibration file is used. e.g.

ws = AlignAndFocusPowderSlim(Filename="VULCAN_218062.nxs.h5",
                             CalFileName="B123456DIFCs-12Cross-3456Cal_v4.h5",
                             L1=43.755,
                             L2=[2.296, 2.296, 2.070, 2.070, 2.070, 2.530],
                             Polar=[90, 90, 120, 150, 157, 65.5],
                             Azimuthal=[180, 0, 0, 0, 0, 0])

Reviewer

Your comments will be used as part of the gatekeeper process. Comment clearly on what you have checked and tested during your review. Provide an audit trail for any changes requested.

As per the review guidelines:

  • Is the code of an acceptable quality? (Code standards/GUI standards)
  • Has a thorough functional test been performed? Do the changes handle unexpected input/situations?
  • Are appropriately scoped unit and/or system tests provided?
  • Do the release notes conform to the guidelines and describe the changes appropriately?
  • Has the relevant (user and developer) documentation been added/updated?
  • If the PR author isn’t in the mantid-developers or mantid-contributors teams, add a review comment rerun ci to authorize/rerun the CI

Gatekeeper

As per the gatekeeping guidelines:

  • Has a thorough first line review been conducted, including functional testing?
  • At a high-level, is the code quality sufficient?
  • Are the base, milestone and labels correct?

@github-actions github-actions bot added this to the Release 6.15 milestone Jan 6, 2026
@rosswhitfield rosswhitfield force-pushed the aafps_grouping2 branch 2 times, most recently from 4a6a5fc to acca369 Compare January 8, 2026 04:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for arbitrary detector grouping to AlignAndFocusPowderSlim by introducing a GroupingWorkspace input property. This enables a many-to-many relationship between detector banks and output spectra, moving beyond the previous one-to-one bank-to-spectra mapping.

Key Changes:

  • New GroupingWorkspace input property allows users to specify custom detector groupings
  • Refactored event processing to support arbitrary grouping through a new SpectraProcessingData structure
  • Modified BankCalibration and BankCalibrationFactory to handle grouping intersections with bank detectors

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Framework/Geometry/src/Instrument.cpp Added getDetectorIDsInBank method to retrieve detector IDs for a given bank
Framework/Geometry/inc/MantidGeometry/Instrument.h Header declaration for new getDetectorIDsInBank method
Framework/DataObjects/src/GroupingWorkspace.cpp Modified getGroupIDs to optionally exclude unset groups; changed return type of getDetectorIDsOfGroup
Framework/DataObjects/inc/MantidDataObjects/GroupingWorkspace.h Updated method signatures for grouping workspace operations
Framework/DataHandling/src/AlignAndFocusPowderSlim.cpp Major refactoring to support arbitrary grouping with validation and detector-to-spectrum mapping
Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim.h Added new helper methods and member variable for detector-to-spectrum mapping
Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim/SpectraProcessingData.h New structure for thread-safe accumulation of event counts using atomics
Framework/DataHandling/src/AlignAndFocusPowderSlim/ProcessBankTask.cpp Refactored to handle both direct and arbitrary grouping modes
Framework/DataHandling/src/AlignAndFocusPowderSlim/BankCalibration.cpp Changed to use std::set for detector IDs; simplified range determination logic
Framework/DataHandling/inc/MantidDataHandling/AlignAndFocusPowderSlim/BankCalibration.h Updated API to work with sets and support multiple calibrations per bank
Framework/DataHandling/test/AlignAndFocusPowderSlimTest.h Added comprehensive tests for 12-group and 3-group scenarios
Multiple test files Updated to use std::set instead of std::vector for detector IDs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rosswhitfield rosswhitfield added Diffraction Issues and pull requests related to diffraction Powder Issues and pull requests related to powder diffraction labels Jan 8, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rosswhitfield rosswhitfield marked this pull request as ready for review January 9, 2026 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Diffraction Issues and pull requests related to diffraction Powder Issues and pull requests related to powder diffraction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant