diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui index e8ff1caa76d5dca07dda9e37d5bebd4c0e8406db..27e53b9921cb14a0a76e3380d7c421900a03a76a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui @@ -1,323 +1,410 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>ApplyPaalmanPings</class> - <widget class="QWidget" name="ApplyPaalmanPings"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>420</width> - <height>420</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QGroupBox" name="gbInput"> - <property name="title"> - <string>Input</string> - </property> - <layout class="QVBoxLayout" name="abscor_loInput"> + <class>ApplyPaalmanPings</class> + <widget class="QWidget" name="ApplyPaalmanPings"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>420</width> + <height>420</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="MantidQt::MantidWidgets::DataSelector" name="dsSample" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="autoLoad" stdset="0"> - <bool>true</bool> - </property> - <property name="workspaceSuffixes" stdset="0"> - <stringlist> - <string>_red</string> - <string>_sqw</string> - </stringlist> - </property> - <property name="fileBrowserSuffixes" stdset="0"> - <stringlist> - <string>_red.nxs</string> - <string>_sqw.nxs</string> - </stringlist> - </property> - <property name="showLoad" stdset="0"> - <bool>false</bool> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="gbOptions"> - <property name="title"> - <string>Options</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="1"> - <widget class="QComboBox" name="cbGeometry"> - <item> - <property name="text"> - <string>Flat Plate</string> - </property> - </item> - <item> - <property name="text"> - <string>Cylinder</string> - </property> - </item> - <item> - <property name="text"> - <string>Annulus</string> - </property> - </item> - </widget> - </item> - <item row="1" column="1"> - <widget class="MantidQt::MantidWidgets::DataSelector" name="dsCorrections" native="true"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="autoLoad" stdset="0"> - <bool>true</bool> - </property> - <property name="workspaceSuffixes" stdset="0"> - <stringlist> - <string>_flt_abs</string> - </stringlist> - </property> - <property name="fileBrowserSuffixes" stdset="0"> - <stringlist> - <string>_flt_abs.nxs</string> - </stringlist> - </property> - <property name="showLoad" stdset="0"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="lbGeometry"> - <property name="text"> - <string>Geometry:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="lbCorrection"> - <property name="text"> - <string>Corrections: </string> + <widget class="QGroupBox" name="gbInput"> + <property name="title"> + <string>Input</string> </property> + <layout class="QVBoxLayout" name="abscor_loInput"> + <item> + <widget class="MantidQt::MantidWidgets::DataSelector" name="dsSample" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="autoLoad" stdset="0"> + <bool>true</bool> + </property> + <property name="workspaceSuffixes" stdset="0"> + <stringlist> + <string>_red</string> + <string>_sqw</string> + </stringlist> + </property> + <property name="fileBrowserSuffixes" stdset="0"> + <stringlist> + <string>_red.nxs</string> + <string>_sqw.nxs</string> + </stringlist> + </property> + <property name="showLoad" stdset="0"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> </widget> - </item>S - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="gbPreview"> - <property name="title"> - <string>Preview</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_11"> - <item> - <widget class="MantidQt::MantidWidgets::PreviewPlot" name="ppPreview" native="true"> - <property name="canvasColour" stdset="0"> - <color> - <red>255</red> - <green>255</green> - <blue>255</blue> - </color> - </property> - <property name="showLegend" stdset="0"> - <bool>true</bool> - </property> - </widget> </item> <item> - <layout class="QVBoxLayout" name="loPlotOptions"> - <item> - <spacer name="verticalSpacer_0"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> + <widget class="QGroupBox" name="gbOptions"> + <property name="title"> + <string>Options</string> </property> - </spacer> - </item> - <item> - <widget class="QLabel" name="lbPreviewSpec"> - <property name="text"> - <string>Spectrum:</string> - </property> - </widget> - </item> - <item> - <widget class="QSpinBox" name="spPreviewSpec"/> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="gbOutput"> - <property name="title"> - <string>Output Options</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="lbPlotOutput"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Plot Output:</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="cbPlotOutput"> - <item> - <property name="text"> - <string>None</string> - </property> - </item> - <item> - <property name="text"> - <string>Contour</string> - </property> - </item> - <item> - <property name="text"> - <string>Spectra</string> - </property> - </item> - <item> - <property name="text"> - <string>Both</string> - </property> - </item> - </widget> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QCheckBox" name="ckUseCan"> + <property name="text"> + <string>Use Can:</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QCheckBox" name="ckUseCorrections"> + <property name="text"> + <string>Use Corrections:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="cbGeometry"> + <item> + <property name="text"> + <string>Flat Plate</string> + </property> + </item> + <item> + <property name="text"> + <string>Cylinder</string> + </property> + </item> + <item> + <property name="text"> + <string>Annulus</string> + </property> + </item> + </widget> + </item> + <item row="4" column="1"> + <widget class="MantidQt::MantidWidgets::DataSelector" name="dsCorrections" native="true"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="autoLoad" stdset="0"> + <bool>true</bool> + </property> + <property name="workspaceSuffixes" stdset="0"> + <stringlist> + <string>_flt_abs</string> + </stringlist> + </property> + <property name="fileBrowserSuffixes" stdset="0"> + <stringlist> + <string>_flt_abs.nxs</string> + </stringlist> + </property> + <property name="showLoad" stdset="0"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="MantidQt::MantidWidgets::DataSelector" name="dsContainer" native="true"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="autoLoad" stdset="0"> + <bool>true</bool> + </property> + <property name="workspaceSuffixes" stdset="0"> + <stringlist> + <string>_red</string> + <string>_sqw</string> + </stringlist> + </property> + <property name="fileBrowserSuffixes" stdset="0"> + <stringlist> + <string>_red.nxs</string> + <string>_sqw.nxs</string> + </stringlist> + </property> + <property name="showLoad" stdset="0"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="lbGeometry"> + <property name="text"> + <string>Geometry:</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QCheckBox" name="ckScaleCan"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Scale Can by factor:</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="3" column="1"> + <layout class="QHBoxLayout" name="loScaleFactor"> + <item> + <widget class="QDoubleSpinBox" name="spCanScale"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="maximum"> + <double>999.990000000000009</double> + </property> + <property name="singleStep"> + <double>0.100000000000000</double> + </property> + <property name="value"> + <double>1.000000000000000</double> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> </item> <item> - <spacer name="horizontalSpacer_1"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> + <widget class="QGroupBox" name="gbPreview"> + <property name="title"> + <string>Preview</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="MantidQt::MantidWidgets::PreviewPlot" name="ppPreview" native="true"> + <property name="canvasColour" stdset="0"> + <color> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </property> + <property name="showLegend" stdset="0"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="loPlotOptions"> + <item> + <spacer name="verticalSpacer_0"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="lbPreviewSpec"> + <property name="text"> + <string>Spectrum:</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spPreviewSpec"/> + </item> + </layout> + </item> + </layout> + </widget> </item> <item> - <widget class="QCheckBox" name="ckSave"> - <property name="text"> - <string>Save Result</string> - </property> - </widget> + <widget class="QGroupBox" name="gbOutput"> + <property name="title"> + <string>Output Options</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="lbPlotOutput"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Plot Output:</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="cbPlotOutput"> + <item> + <property name="text"> + <string>None</string> + </property> + </item> + <item> + <property name="text"> + <string>Contour</string> + </property> + </item> + <item> + <property name="text"> + <string>Spectra</string> + </property> + </item> + <item> + <property name="text"> + <string>Both</string> + </property> + </item> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_1"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="ckSave"> + <property name="text"> + <string>Save Result</string> + </property> + </widget> + </item> + </layout> + </widget> </item> - </layout> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>MantidQt::MantidWidgets::DataSelector</class> - <extends>QWidget</extends> - <header>MantidQtMantidWidgets/DataSelector.h</header> - </customwidget> - <customwidget> - <class>MantidQt::MantidWidgets::PreviewPlot</class> - <extends>QWidget</extends> - <header>MantidQtMantidWidgets/PreviewPlot.h</header> - <container>1</container> - </customwidget> - </customwidgets> - <resources/> - <connections> - <connection> - <sender>ckUseCan</sender> - <signal>toggled(bool)</signal> - <receiver>ckScaleCan</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>50</x> - <y>111</y> - </hint> - <hint type="destinationlabel"> - <x>61</x> - <y>142</y> - </hint> - </hints> - </connection> - <connection> - <sender>ckScaleCan</sender> - <signal>toggled(bool)</signal> - <receiver>spCanScale</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>133</x> - <y>143</y> - </hint> - <hint type="destinationlabel"> - <x>251</x> - <y>147</y> - </hint> - </hints> - </connection> - <connection> - <sender>ckUseCan</sender> - <signal>toggled(bool)</signal> - <receiver>dsContainer</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>119</x> - <y>114</y> - </hint> - <hint type="destinationlabel"> - <x>324</x> - <y>114</y> - </hint> - </hints> - </connection> - <connection> - <sender>ckUseCorrections</sender> - <signal>toggled(bool)</signal> - <receiver>dsCorrections</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>119</x> - <y>167</y> - </hint> - <hint type="destinationlabel"> - <x>324</x> - <y>167</y> - </hint> - </hints> - </connection> - </connections> -</ui> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>MantidQt::MantidWidgets::DataSelector</class> + <extends>QWidget</extends> + <header>MantidQtMantidWidgets/DataSelector.h</header> + </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::PreviewPlot</class> + <extends>QWidget</extends> + <header>MantidQtMantidWidgets/PreviewPlot.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections> + <connection> + <sender>ckUseCan</sender> + <signal>toggled(bool)</signal> + <receiver>ckScaleCan</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>50</x> + <y>111</y> + </hint> + <hint type="destinationlabel"> + <x>61</x> + <y>142</y> + </hint> + </hints> + </connection> + <connection> + <sender>ckScaleCan</sender> + <signal>toggled(bool)</signal> + <receiver>spCanScale</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>133</x> + <y>143</y> + </hint> + <hint type="destinationlabel"> + <x>251</x> + <y>147</y> + </hint> + </hints> + </connection> + <connection> + <sender>ckUseCan</sender> + <signal>toggled(bool)</signal> + <receiver>dsContainer</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>119</x> + <y>114</y> + </hint> + <hint type="destinationlabel"> + <x>324</x> + <y>114</y> + </hint> + </hints> + </connection> + <connection> + <sender>ckUseCorrections</sender> + <signal>toggled(bool)</signal> + <receiver>dsCorrections</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>119</x> + <y>167</y> + </hint> + <hint type="destinationlabel"> + <x>324</x> + <y>167</y> + </hint> + </hints> + </connection> + </connections> +</ui> \ No newline at end of file diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp index 042905b2189bc4cceae7a1884844230113b2705b..42270faab779a63de3226cd5b3b3cc4ebd2c2de6 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp @@ -1,3 +1,4 @@ + #include "MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h" #include "MantidQtCustomInterfaces/UserInputValidator.h" #include "MantidAPI/AnalysisDataService.h" @@ -68,50 +69,97 @@ void ApplyPaalmanPings::run() { absCorProps["SampleWorkspace"] = sampleWsName.toStdString(); } - QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName(); - - WorkspaceGroup_sptr corrections = - AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( - correctionsWsName.toStdString()); - bool interpolateAll = false; - for (size_t i = 0; i < corrections->size(); i++) { - MatrixWorkspace_sptr factorWs = - boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); - - // Check for matching binning - if (sampleWs && (sampleWs->blocksize() != factorWs->blocksize())) { - int result; - if (interpolateAll) { - result = QMessageBox::Yes; - } else { - QString text = "Number of bins on sample and " + - QString::fromStdString(factorWs->name()) + - " workspace does not match.\n" + - "Would you like to interpolate this workspace to " - "match the sample?"; - - result = QMessageBox::question(NULL, tr("Interpolate corrections?"), - tr(text), QMessageBox::YesToAll, - QMessageBox::Yes, QMessageBox::No); - } + bool useCan = m_uiForm.ckUseCan->isChecked(); + if (useCan) { + QString canWsName = m_uiForm.dsContainer->getCurrentDataName(); + MatrixWorkspace_sptr canWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + canWsName.toStdString()); + + // If not in wavelength then do conversion + std::string originalCanUnits = canWs->getAxis(0)->unit()->unitID(); + if (originalCanUnits != "Wavelength") { + g_log.information("Container workspace not in wavelength, need to " + "convert to continue."); + absCorProps["CanWorkspace"] = addConvertUnitsStep(canWs, "Wavelength"); + } else { + absCorProps["CanWorkspace"] = canWsName.toStdString(); + } + + bool useCanScale = m_uiForm.ckScaleCan->isChecked(); + if (useCanScale) { + double canScaleFactor = m_uiForm.spCanScale->value(); + applyCorrAlg->setProperty("CanScaleFactor", canScaleFactor); + } + + // Check for same binning across sample and container + if (!checkWorkspaceBinningMatches(sampleWs, canWs)) { + QString text = + "Binning on sample and container does not match." + "Would you like to rebin the sample to match the container?"; + + int result = QMessageBox::question(NULL, tr("Rebin sample?"), tr(text), + QMessageBox::Yes, QMessageBox::No, + QMessageBox::NoButton); - switch (result) { - case QMessageBox::YesToAll: - interpolateAll = true; - case QMessageBox::Yes: - addInterpolationStep(factorWs, absCorProps["SampleWorkspace"]); - break; - default: + if (result == QMessageBox::Yes) { + addRebinStep(sampleWsName, canWsName); + } else { m_batchAlgoRunner->clearQueue(); - g_log.error("ApplyPaalmanPings cannot run with corrections that do " - "not match sample binning."); + g_log.error("Cannot apply absorption corrections using a sample and " + "container with different binning."); return; } } } - applyCorrAlg->setProperty("CorrectionsWorkspace", - correctionsWsName.toStdString()); + bool useCorrections = m_uiForm.ckUseCorrections->isChecked(); + if (useCorrections) { + QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName(); + + WorkspaceGroup_sptr corrections = + AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( + correctionsWsName.toStdString()); + bool interpolateAll = false; + for (size_t i = 0; i < corrections->size(); i++) { + MatrixWorkspace_sptr factorWs = + boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); + + // Check for matching binning + if (sampleWs && (sampleWs->blocksize() != factorWs->blocksize())) { + int result; + if (interpolateAll) { + result = QMessageBox::Yes; + } else { + QString text = "Number of bins on sample and " + + QString::fromStdString(factorWs->name()) + + " workspace does not match.\n" + + "Would you like to interpolate this workspace to " + "match the sample?"; + + result = QMessageBox::question(NULL, tr("Interpolate corrections?"), + tr(text), QMessageBox::YesToAll, + QMessageBox::Yes, QMessageBox::No); + } + + switch (result) { + case QMessageBox::YesToAll: + interpolateAll = true; + case QMessageBox::Yes: + addInterpolationStep(factorWs, absCorProps["SampleWorkspace"]); + break; + default: + m_batchAlgoRunner->clearQueue(); + g_log.error("ApplyPaalmanPings cannot run with corrections that do " + "not match sample binning."); + return; + } + } + } + + applyCorrAlg->setProperty("CorrectionsWorkspace", + correctionsWsName.toStdString()); + } // Generate output workspace name int nameCutIndex = sampleWsName.lastIndexOf("_"); @@ -261,33 +309,63 @@ bool ApplyPaalmanPings::validate() { MatrixWorkspace_sptr sampleWs; - if (m_uiForm.dsCorrections->getCurrentDataName().compare("") == 0) { - uiv.addErrorMessage( - "Use Correction must contain a corrections file or workspace."); - } else { + bool useCan = m_uiForm.ckUseCan->isChecked(); + bool useCorrections = m_uiForm.ckUseCorrections->isChecked(); - QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName(); - WorkspaceGroup_sptr corrections = - AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( - correctionsWsName.toStdString()); - for (size_t i = 0; i < corrections->size(); i++) { - // Check it is a MatrixWorkspace - MatrixWorkspace_sptr factorWs = - boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); - if (!factorWs) { - QString msg = "Correction factor workspace " + QString::number(i) + - " is not a MatrixWorkspace"; - uiv.addErrorMessage(msg); - continue; - } + if (!(useCan || useCorrections)) + uiv.addErrorMessage("Must use either container subtraction or corrections"); + + if (useCan) { + uiv.checkDataSelectorIsValid("Container", m_uiForm.dsContainer); + + // Check can and sample workspaces are the same "type" (reduced or S(Q, w)) + QString sample = m_uiForm.dsSample->getCurrentDataName(); + QString sampleType = + sample.right(sample.length() - sample.lastIndexOf("_")); + QString container = m_uiForm.dsContainer->getCurrentDataName(); + QString containerType = + container.right(container.length() - container.lastIndexOf("_")); + + g_log.debug() << "Sample type is: " << sampleType.toStdString() + << std::endl; + g_log.debug() << "Can type is: " << containerType.toStdString() + << std::endl; - // Check X unit is wavelength - Mantid::Kernel::Unit_sptr xUnit = factorWs->getAxis(0)->unit(); - if (xUnit->caption() != "Wavelength") { - QString msg = "Correction factor workspace " + - QString::fromStdString(factorWs->name()) + - " is not in wavelength"; - uiv.addErrorMessage(msg); + if (containerType != sampleType) + uiv.addErrorMessage( + "Sample and can workspaces must contain the same type of data."); + } + + if (useCorrections) { + if (m_uiForm.dsCorrections->getCurrentDataName().compare("") == 0) { + uiv.addErrorMessage( + "Use Correction must contain a corrections file or workspace."); + } else { + + QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName(); + WorkspaceGroup_sptr corrections = + AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( + correctionsWsName.toStdString()); + for (size_t i = 0; i < corrections->size(); i++) { + // Check it is a MatrixWorkspace + MatrixWorkspace_sptr factorWs = + boost::dynamic_pointer_cast<MatrixWorkspace>( + corrections->getItem(i)); + if (!factorWs) { + QString msg = "Correction factor workspace " + QString::number(i) + + " is not a MatrixWorkspace"; + uiv.addErrorMessage(msg); + continue; + } + + // Check X unit is wavelength + Mantid::Kernel::Unit_sptr xUnit = factorWs->getAxis(0)->unit(); + if (xUnit->caption() != "Wavelength") { + QString msg = "Correction factor workspace " + + QString::fromStdString(factorWs->name()) + + " is not in wavelength"; + uiv.addErrorMessage(msg); + } } } } @@ -301,6 +379,7 @@ bool ApplyPaalmanPings::validate() { void ApplyPaalmanPings::loadSettings(const QSettings &settings) { m_uiForm.dsCorrections->readSettings(settings.group()); + m_uiForm.dsContainer->readSettings(settings.group()); m_uiForm.dsSample->readSettings(settings.group()); } @@ -335,6 +414,7 @@ void ApplyPaalmanPings::handleGeometryChange(int index) { * @param specIndex Spectrum index to plot */ void ApplyPaalmanPings::plotPreview(int specIndex) { + bool useCan = m_uiForm.ckUseCan->isChecked(); m_uiForm.ppPreview->clear(); @@ -347,7 +427,12 @@ void ApplyPaalmanPings::plotPreview(int specIndex) { m_uiForm.ppPreview->addSpectrum( "Corrected", QString::fromStdString(m_pythonExportWsName), specIndex, Qt::green); + + // Plot can + if (useCan) + m_uiForm.ppPreview->addSpectrum( + "Can", m_uiForm.dsContainer->getCurrentDataName(), specIndex, Qt::red); } } // namespace CustomInterfaces -} // namespace MantidQt +} // namespace MantidQt \ No newline at end of file