Skip to content

Commit

Permalink
Fix logic for checking bin consistency in ConjoinWorkspaces algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashampson committed Jan 17, 2025
1 parent e63d5c8 commit c155bd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MANTID_ALGORITHMS_DLL ConjoinWorkspaces : public WorkspaceJoiners {
void init() override;
void exec() override;

bool checkBinning(const API::MatrixWorkspace_const_sptr &ws1, const API::MatrixWorkspace_const_sptr &ws2) const;
void checkForOverlap(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2, bool checkSpectra) const;
API::MatrixWorkspace_sptr conjoinEvents(const DataObjects::EventWorkspace &ws1,
const DataObjects::EventWorkspace &ws2);
Expand Down
23 changes: 21 additions & 2 deletions Framework/Algorithms/src/ConjoinWorkspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ void ConjoinWorkspaces::exec() {
g_log.error(message);
throw std::invalid_argument(message);
}
// Check if bins match

// Check whether bins match
bool checkBins = getProperty("CheckMatchingBins");
if (!WorkspaceHelpers::matchingBins(ws1, ws2) && checkBins) {
if (checkBins && !checkBinning(ws1, ws2)) {
const std::string message("The bins do not match in the input workspaces. "
"Consider using RebinToWorkspace to preprocess "
"the workspaces before conjoining them.");
Expand All @@ -88,6 +89,24 @@ void ConjoinWorkspaces::exec() {
AnalysisDataService::Instance().remove(getPropertyValue("InputWorkspace2"));
}

//----------------------------------------------------------------------------------------------
/** Checks whether the binning is consistent between two workspaces
* @param ws1 :: The first input workspace
* @param ws2 :: The second input workspace
* @return :: true if both workspaces have consistent binning.
*/
bool ConjoinWorkspaces::checkBinning(const API::MatrixWorkspace_const_sptr &ws1,
const API::MatrixWorkspace_const_sptr &ws2) const {
if (ws1->isRaggedWorkspace() || ws2->isRaggedWorkspace()) {
return false;
}

// If neither workspace is ragged, we only need to check the first specrum.
// Otherwise the matchingBins() function requires the two workspaces to have
// the same number of spectra.
return WorkspaceHelpers::matchingBins(ws1, ws2, true);
}

//----------------------------------------------------------------------------------------------
/** Checks that the two input workspaces have non-overlapping spectra numbers
* and contributing detectors
Expand Down

0 comments on commit c155bd1

Please sign in to comment.