Skip to content

Commit 60127b2

Browse files
authored
Fix ZOOM NormaliseByCurrent bug - Ensure period logs are added to monitor workspaces in line with Event workspaces (#39983)
### Description of work A change was made in #39322 that uses the `current_period` log to calculate the proton charge. This `current_period` log is added to all event workspaces that have certain logs associated with period data, even if the data only has one period:https://github.com/mantidproject/mantid/blob/583bca96a8f7b721c2efb5a024b0832f0d60d8e5/Framework/DataHandling/src/LoadEventNexus.cpp#L958 When loading monitors into a separate workspace as part of `LoadEventNexus`, `LoadNexusMonitors` in contrast does NOT add this property for workspaces that have only 1 period. This PR changes this so that the function enabling the `splitMutiPeriodHistrogramData` function to operates on all workspaces with periods of >0. Closes #39831
1 parent e9b19c5 commit 60127b2

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Framework/DataHandling/src/LoadNexusMonitors2.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void LoadNexusMonitors2::exec() {
203203
// this gets the ids from the "isis_vms_compat" group
204204
fixUDets(file);
205205

206-
if (numPeriods > 1) {
206+
if (numPeriods > 0) {
207207
m_multiPeriodCounts.resize(m_monitor_count);
208208
m_multiPeriodBinEdges.resize(m_monitor_count);
209209
}
@@ -349,8 +349,7 @@ void LoadNexusMonitors2::exec() {
349349
// add filename
350350
m_workspace->mutableRun().addProperty("Filename", m_filename);
351351

352-
// if multiperiod histogram data
353-
if ((numPeriods > 1) && (!useEventMon)) {
352+
if ((numPeriods > 0) && (!useEventMon)) {
354353
splitMutiPeriodHistrogramData(numPeriods);
355354
} else {
356355
this->setProperty("OutputWorkspace", m_workspace);
@@ -465,14 +464,6 @@ bool LoadNexusMonitors2::canOpenAsNeXus(const std::string &fname) {
465464
* @param numPeriods :: number of periods
466465
**/
467466
void LoadNexusMonitors2::splitMutiPeriodHistrogramData(const size_t numPeriods) {
468-
// protection - we should not have entered the routine if these are not true
469-
// More than 1 period
470-
if (numPeriods < 2) {
471-
g_log.warning() << "Attempted to split multiperiod histogram workspace with " << numPeriods
472-
<< "periods, aborted.\n";
473-
return;
474-
}
475-
476467
// Y array should be divisible by the number of periods
477468
if (m_multiPeriodCounts[0].size() % numPeriods != 0) {
478469
g_log.warning() << "Attempted to split multiperiod histogram workspace with " << m_multiPeriodCounts[0].size()
@@ -482,13 +473,14 @@ void LoadNexusMonitors2::splitMutiPeriodHistrogramData(const size_t numPeriods)
482473
return;
483474
}
484475

485-
WorkspaceGroup_sptr wsGroup(new WorkspaceGroup);
486476
size_t yLength = m_multiPeriodCounts[0].size() / numPeriods;
487477
size_t xLength = yLength + 1;
488478
size_t numSpectra = m_workspace->getNumberHistograms();
489479
API::ISISRunLogs monLogCreator(m_workspace->run());
490480

491481
BinEdges edges = m_multiPeriodBinEdges[0];
482+
std::vector<API::MatrixWorkspace_sptr> outputWorkspaces;
483+
outputWorkspaces.reserve(numPeriods);
492484

493485
for (size_t i = 0; i < numPeriods; i++) {
494486
// create the period workspace
@@ -506,12 +498,21 @@ void LoadNexusMonitors2::splitMutiPeriodHistrogramData(const size_t numPeriods)
506498
monLogCreator.addStatusLog(wsPeriod->mutableRun());
507499
monLogCreator.addPeriodLogs(static_cast<int>(i + 1), wsPeriod->mutableRun());
508500

509-
// add to workspace group
510-
wsGroup->addWorkspace(wsPeriod);
501+
outputWorkspaces.push_back(wsPeriod);
511502
}
512503

513-
// set the output workspace
514-
this->setProperty("OutputWorkspace", wsGroup);
504+
// set output workspace to either single period ws, or group ws.
505+
if (outputWorkspaces.size() > 1) {
506+
WorkspaceGroup_sptr wsGroup(new WorkspaceGroup);
507+
for (const auto &ws : outputWorkspaces) {
508+
wsGroup->addWorkspace(ws);
509+
}
510+
this->setProperty("OutputWorkspace", wsGroup);
511+
} else if (outputWorkspaces.size() == 1) {
512+
this->setProperty("OutputWorkspace", outputWorkspaces[0]);
513+
} else {
514+
g_log.error() << "No period workspaces generated to output.";
515+
}
515516
}
516517

517518
size_t LoadNexusMonitors2::getMonitorInfo(Nexus::File &file, size_t &numPeriods) {
@@ -747,7 +748,7 @@ void LoadNexusMonitors2::readHistoMonitorEntry(Nexus::File &file, size_t ws_inde
747748
file.getDataCoerce(tof);
748749
file.closeData();
749750

750-
if (numPeriods > 1) {
751+
if (numPeriods > 0) {
751752
m_multiPeriodBinEdges[ws_index] = std::move(tof);
752753
m_multiPeriodCounts[ws_index] = std::move(data);
753754
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- When loading monitors with period data (``LoadNexusMonitors2``), period sample logs are now added to the resultant workspace; This is in line with the creation of Event Workspaces. This fixes a bug that occurred when ``NormaliseByCurrent`` was used on the monitor workspace.

0 commit comments

Comments
 (0)