Skip to content
Snippets Groups Projects
Unverified Commit 24b8db8a authored by Nick Draper's avatar Nick Draper Committed by GitHub
Browse files

Merge pull request #23001 from mantidproject/22988_IndirectDataRedGrouping

Indirect - Data Reduction - ISISEnergyTransfer - Ensure detectors are grouped as specified
parents cae87c9d 17d9d820
No related merge requests found
#include "ISISEnergyTransfer.h"
#include "../General/UserInputValidator.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "../General/UserInputValidator.h"
#include <QFileInfo>
using namespace Mantid::API;
using MantidQt::API::BatchAlgorithmRunner;
namespace {
std::string createRangeString(std::size_t from, std::size_t to) {
return std::to_string(from) + "-" + std::to_string(to);
}
std::string createGroupString(std::size_t start, std::size_t size) {
return createRangeString(start, start + size - 1);
}
std::string createGroupingString(std::size_t groupSize,
std::size_t numberOfGroups) {
auto groupingString = createRangeString(0, groupSize - 1);
for (auto i = groupSize; i < groupSize * numberOfGroups; i += groupSize)
groupingString += "," + createGroupString(i, groupSize);
return groupingString;
}
std::string createDetectorGroupingString(std::size_t groupSize,
std::size_t numberOfGroups,
std::size_t numberOfDetectors) {
const auto groupingString = createGroupingString(groupSize, numberOfGroups);
const auto remainder = numberOfDetectors % numberOfGroups;
if (remainder == 0)
return groupingString;
return groupingString + "," + createRangeString(numberOfDetectors - remainder,
numberOfDetectors - 1);
}
std::string createDetectorGroupingString(std::size_t numberOfDetectors,
std::size_t numberOfGroups) {
const auto groupSize = numberOfDetectors / numberOfGroups;
if (groupSize == 0)
return createRangeString(0, numberOfDetectors - 1);
return createDetectorGroupingString(groupSize, numberOfGroups,
numberOfDetectors);
}
} // namespace
namespace MantidQt {
namespace CustomInterfaces {
//----------------------------------------------------------------------------------------------
......@@ -457,7 +497,7 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) {
return std::make_pair("File", groupFile.toStdString());
} else if (groupType == "Groups")
return std::make_pair("Custom", createDetectorGroupingString());
return std::make_pair("Custom", getDetectorGroupingString());
else if (groupType == "Default")
return std::make_pair("IPF", "");
else if (groupType == "Custom")
......@@ -469,25 +509,12 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) {
}
}
const std::string ISISEnergyTransfer::createDetectorGroupingString() {
std::string ISISEnergyTransfer::getDetectorGroupingString() const {
const unsigned int nGroups = m_uiForm.spNumberGroups->value();
const unsigned int nSpectra =
m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value();
const unsigned int groupSize = nSpectra / nGroups;
auto n = groupSize;
std::stringstream groupingString;
groupingString << "0-" << std::to_string(n);
for (auto i = 1u; i < nGroups; ++i) {
groupingString << ", " << std::to_string(n + 1) << "-";
n += groupSize;
groupingString << std::to_string(n);
}
if (n != nSpectra) // add remainder as extra group
groupingString << ", " << std::to_string(n + 1) << "-"
<< std::to_string(nSpectra);
return groupingString.str();
1 + m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value();
return createDetectorGroupingString(static_cast<std::size_t>(nSpectra),
static_cast<std::size_t>(nGroups));
}
/**
......@@ -575,6 +602,7 @@ void ISISEnergyTransfer::plotRaw() {
if (m_uiForm.ckBackgroundRemoval->isChecked()) {
MatrixWorkspace_sptr tempWs =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name);
const double minBack = tempWs->x(0)[0];
const double maxBack = tempWs->x(0)[tempWs->blocksize()];
......@@ -744,4 +772,4 @@ void ISISEnergyTransfer::saveClicked() {
}
} // namespace CustomInterfaces
} // namespace Mantid
} // namespace MantidQt
......@@ -76,7 +76,7 @@ private:
std::vector<std::string>
m_outputWorkspaces; ///< get a vector of workspaces to plot
QString validateDetectorGrouping();
const std::string createDetectorGroupingString();
std::string getDetectorGroupingString() const;
};
} // namespace CustomInterfaces
} // namespace Mantid
......
......@@ -289,7 +289,11 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spNumberGroups"/>
<widget class="QSpinBox" name="spNumberGroups">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
......@@ -313,19 +317,19 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>, allows you to specify additional indices. 1,2,4 will keep indices 1, 2 and 4 only.
: indicates a continuous range of indices. For example, 1:5 is the same as 1,2,3,4,5.
+ sums two spectra together. 7+9 will produce a single spectra listing the sum of 7 and 9, ignoring any others.
- sums a range of spectra together. For example, 3-8 is the same as 3+4+5+6+7+8.
</string>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>, allows you to specify additional indices. 1,2,4 will keep indices 1, 2 and 4 only.
: indicates a continuous range of indices. For example, 1:5 is the same as 1,2,3,4,5.
+ sums two spectra together. 7+9 will produce a single spectra listing the sum of 7 and 9, ignoring any others.
- sums a range of spectra together. For example, 3-8 is the same as 3+4+5+6+7+8.
</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
......@@ -572,7 +576,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
......@@ -580,7 +593,16 @@
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment