From df5cf01859430bae6d3cb894eb36ae89065ebaf7 Mon Sep 17 00:00:00 2001 From: Dan Nixon <dan@dan-nixon.com> Date: Wed, 15 Jul 2015 15:59:40 +0100 Subject: [PATCH] Rename interfaces Re #13104 --- .../MantidQt/CustomInterfaces/CMakeLists.txt | 16 +- .../Indirect/AbsorptionCorrections.h | 3 - .../Indirect/ApplyCorr.h | 52 -- .../Indirect/ApplyPaalmanPings.h | 46 ++ .../{ApplyCorr.ui => ApplyPaalmanPings.ui} | 4 +- .../Indirect/CalcCorr.h | 45 -- .../Indirect/CalculatePaalmanPings.h | 40 ++ .../{CalcCorr.ui => CalculatePaalmanPings.ui} | 4 +- .../Indirect/CorrectionsTab.h | 8 - .../Indirect/IndirectCorrections.h | 3 - .../Indirect/IndirectCorrections.ui | 10 +- .../src/Indirect/AbsorptionCorrections.cpp | 3 - .../src/Indirect/ApplyCorr.cpp | 447 ------------------ .../src/Indirect/ApplyPaalmanPings.cpp | 432 +++++++++++++++++ .../src/Indirect/CalcCorr.cpp | 413 ---------------- .../src/Indirect/CalculatePaalmanPings.cpp | 399 ++++++++++++++++ .../src/Indirect/CorrectionsTab.cpp | 10 +- .../src/Indirect/IndirectCorrections.cpp | 17 +- .../src/Indirect/IndirectDataAnalysis.cpp | 3 - .../interfaces/Indirect_Corrections.rst | 14 +- 20 files changed, 947 insertions(+), 1022 deletions(-) delete mode 100644 Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h create mode 100644 Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h rename Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/{ApplyCorr.ui => ApplyPaalmanPings.ui} (99%) delete mode 100644 Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h create mode 100644 Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h rename Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/{CalcCorr.ui => CalculatePaalmanPings.ui} (99%) delete mode 100644 Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp create mode 100644 Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp delete mode 100644 Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp create mode 100644 Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalculatePaalmanPings.cpp diff --git a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt index 5bcb9945afc..204087c2d85 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt @@ -5,8 +5,8 @@ set ( SRC_FILES src/DirectConvertToEnergy.cpp src/Homer.cpp src/Indirect/AbsorptionCorrections.cpp - src/Indirect/ApplyCorr.cpp - src/Indirect/CalcCorr.cpp + src/Indirect/ApplyPaalmanPings.cpp + src/Indirect/CalculatePaalmanPings.cpp src/Indirect/ConvFit.cpp src/Indirect/CorrectionsTab.cpp src/Indirect/DensityOfStates.cpp @@ -103,8 +103,8 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/DllConfig.h inc/MantidQtCustomInterfaces/Homer.h inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h - inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h - inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h + inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h + inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h inc/MantidQtCustomInterfaces/Indirect/ConvFit.h inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h inc/MantidQtCustomInterfaces/Indirect/DensityOfStates.h @@ -214,8 +214,8 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h inc/MantidQtCustomInterfaces/Homer.h inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h - inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h - inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h + inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h + inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h inc/MantidQtCustomInterfaces/Indirect/ConvFit.h inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h inc/MantidQtCustomInterfaces/Indirect/DensityOfStates.h @@ -295,8 +295,8 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h set ( UI_FILES inc/MantidQtCustomInterfaces/DataComparison.ui inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.ui - inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.ui - inc/MantidQtCustomInterfaces/Indirect/CalcCorr.ui + inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui + inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.ui inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui inc/MantidQtCustomInterfaces/Indirect/DensityOfStates.ui inc/MantidQtCustomInterfaces/Indirect/Elwin.ui diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h index a56e7c28eb7..06a452768ad 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h @@ -7,8 +7,6 @@ namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { class DLLExport AbsorptionCorrections : public CorrectionsTab { @@ -34,7 +32,6 @@ namespace IDA Ui::AbsorptionCorrections m_uiForm; }; -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h deleted file mode 100644 index e0d64dd4406..00000000000 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MANTIDQTCUSTOMINTERFACESIDA_APPLYCORR_H_ -#define MANTIDQTCUSTOMINTERFACESIDA_APPLYCORR_H_ - -#include "MantidAPI/MatrixWorkspace_fwd.h" -#include "ui_ApplyCorr.h" -#include "CorrectionsTab.h" - -namespace MantidQt -{ -namespace CustomInterfaces -{ -namespace IDA -{ - class DLLExport ApplyCorr : public CorrectionsTab - { - Q_OBJECT - - public: - ApplyCorr(QWidget * parent = 0); - - private slots: - /// Handles the geometry being changed - void handleGeometryChange(int index); - /// Handles a new sample being loaded - void newData(const QString &dataName); - /// Updates the preview mini plot - void plotPreview(int specIndex); - /// Handle abs. correction algorithm completion - void absCorComplete(bool error); - /// Handle convert units and save algorithm completion - void postProcessComplete(bool error); - - private: - virtual void setup(); - virtual void run(); - virtual bool validate(); - virtual void loadSettings(const QSettings & settings); - - void addRebinStep(QString toRebin, QString toMatch); - void addInterpolationStep(Mantid::API::MatrixWorkspace_sptr toInterpolate, std::string toMatch); - - Ui::ApplyCorr m_uiForm; - - std::string m_originalSampleUnits; - - }; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt - -#endif /* MANTIDQTCUSTOMINTERFACESIDA_APPLYCORR_H_ */ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h new file mode 100644 index 00000000000..ff9c02c688d --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h @@ -0,0 +1,46 @@ +#ifndef MANTIDQTCUSTOMINTERFACESIDA_APPLYPAALMANPINGS_H_ +#define MANTIDQTCUSTOMINTERFACESIDA_APPLYPAALMANPINGS_H_ + +#include "MantidAPI/MatrixWorkspace_fwd.h" +#include "ui_ApplyPaalmanPings.h" +#include "CorrectionsTab.h" + +namespace MantidQt { +namespace CustomInterfaces { +class DLLExport ApplyPaalmanPings : public CorrectionsTab { + Q_OBJECT + +public: + ApplyPaalmanPings(QWidget *parent = 0); + +private slots: + /// Handles the geometry being changed + void handleGeometryChange(int index); + /// Handles a new sample being loaded + void newData(const QString &dataName); + /// Updates the preview mini plot + void plotPreview(int specIndex); + /// Handle abs. correction algorithm completion + void absCorComplete(bool error); + /// Handle convert units and save algorithm completion + void postProcessComplete(bool error); + +private: + virtual void setup(); + virtual void run(); + virtual bool validate(); + virtual void loadSettings(const QSettings &settings); + + void addRebinStep(QString toRebin, QString toMatch); + void addInterpolationStep(Mantid::API::MatrixWorkspace_sptr toInterpolate, + std::string toMatch); + + Ui::ApplyPaalmanPings m_uiForm; + + std::string m_originalSampleUnits; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif /* MANTIDQTCUSTOMINTERFACESIDA_APPLYPAALMANPINGS_H_ */ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui similarity index 99% rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.ui rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui index 0cc347e24f3..70422beced5 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>ApplyCorr</class> - <widget class="QWidget" name="ApplyCorr"> + <class>ApplyPaalmanPings</class> + <widget class="QWidget" name="ApplyPaalmanPings"> <property name="geometry"> <rect> <x>0</x> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h deleted file mode 100644 index 8a384ab16f1..00000000000 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef MANTIDQTCUSTOMINTERFACESIDA_CALCCORR_H_ -#define MANTIDQTCUSTOMINTERFACESIDA_CALCCORR_H_ - -#include "ui_CalcCorr.h" -#include "CorrectionsTab.h" - -namespace MantidQt -{ -namespace CustomInterfaces -{ -namespace IDA -{ - class DLLExport CalcCorr : public CorrectionsTab - { - Q_OBJECT - - public: - CalcCorr(QWidget * parent = 0); - - private: - virtual void setup(); - virtual void run(); - virtual bool validate(); - virtual void loadSettings(const QSettings & settings); - - bool doValidation(bool silent = false); - - private slots: - void absCorComplete(bool error); - void postProcessComplete(bool error); - void getBeamWidthFromWorkspace(const QString& wsName); - - private: - void addShapeSpecificSampleOptions(Mantid::API::IAlgorithm_sptr alg, QString shape); - void addShapeSpecificCanOptions(Mantid::API::IAlgorithm_sptr alg, QString shape); - - Ui::CalcCorr m_uiForm; - - }; - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt - -#endif /* MANTIDQTCUSTOMINTERFACESIDA_CALCCORR_H_ */ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h new file mode 100644 index 00000000000..96b56e7552d --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h @@ -0,0 +1,40 @@ +#ifndef MANTIDQTCUSTOMINTERFACESIDA_CALCULATEPAALMANPINGS_H_ +#define MANTIDQTCUSTOMINTERFACESIDA_CALCULATEPAALMANPINGS_H_ + +#include "ui_CalculatePaalmanPings.h" +#include "CorrectionsTab.h" + +namespace MantidQt { +namespace CustomInterfaces { +class DLLExport CalculatePaalmanPings : public CorrectionsTab { + Q_OBJECT + +public: + CalculatePaalmanPings(QWidget *parent = 0); + +private: + virtual void setup(); + virtual void run(); + virtual bool validate(); + virtual void loadSettings(const QSettings &settings); + + bool doValidation(bool silent = false); + +private slots: + void absCorComplete(bool error); + void postProcessComplete(bool error); + void getBeamWidthFromWorkspace(const QString &wsName); + +private: + void addShapeSpecificSampleOptions(Mantid::API::IAlgorithm_sptr alg, + QString shape); + void addShapeSpecificCanOptions(Mantid::API::IAlgorithm_sptr alg, + QString shape); + + Ui::CalculatePaalmanPings m_uiForm; +}; + +} // namespace CustomInterfaces +} // namespace MantidQt + +#endif /* MANTIDQTCUSTOMINTERFACESIDA_CALCULATEPAALMANPINGS_H_ */ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.ui similarity index 99% rename from Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.ui rename to Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.ui index 1321aa249e9..5ce69e53592 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalcCorr.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>CalcCorr</class> - <widget class="QWidget" name="CalcCorr"> + <class>CalculatePaalmanPings</class> + <widget class="QWidget" name="CalculatePaalmanPings"> <property name="geometry"> <rect> <x>0</x> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h index a17f941cf97..850f14f7e49 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/CorrectionsTab.h @@ -3,7 +3,6 @@ #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/MatrixWorkspace_fwd.h" -#include "IndirectDataAnalysis.h" #include "IndirectTab.h" class QwtPlotCurve; @@ -43,8 +42,6 @@ namespace MantidQt namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { class DLLExport CorrectionsTab : public IndirectTab { @@ -89,12 +86,7 @@ namespace IDA /// Overidden by child class. virtual void loadSettings(const QSettings & settings) = 0; - - /// A pointer to the parent (friend) IndirectDataAnalysis object. - IndirectDataAnalysis * m_parent; - }; -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h index 3b25ca9ea19..7834f259b4e 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.h @@ -18,8 +18,6 @@ class QtStringPropertyManager; namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { // The assumption is made elsewhere that the ordering of these enums matches the ordering of the // tabs as they appear in the interface itself. @@ -90,7 +88,6 @@ namespace IDA std::map<unsigned int, CorrectionsTab*> m_tabs; }; -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui index fca2ec92889..362ff31f3e9 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectCorrections.ui @@ -26,19 +26,19 @@ <property name="currentIndex"> <number>0</number> </property> - <widget class="QWidget" name="tabCalcCorr"> + <widget class="QWidget" name="tabCalculatePaalmanPings"> <attribute name="title"> - <string>Calculate Corrections</string> + <string>Calculate Paalman Pings</string> </attribute> </widget> - <widget class="QWidget" name="tabApplyCorr"> + <widget class="QWidget" name="tabApplyPaalmanPings"> <attribute name="title"> - <string>Apply Corrections</string> + <string>Apply Paalman Pings</string> </attribute> </widget> <widget class="QWidget" name="tabAbsorptionCorrections"> <attribute name="title"> - <string>Absorption Corrections</string> + <string>Absorption</string> </attribute> </widget> </widget> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/AbsorptionCorrections.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/AbsorptionCorrections.cpp index c150dbebdf0..31940830dfe 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/AbsorptionCorrections.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/AbsorptionCorrections.cpp @@ -15,8 +15,6 @@ namespace namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { AbsorptionCorrections::AbsorptionCorrections(QWidget * parent) : CorrectionsTab(parent) @@ -274,6 +272,5 @@ namespace IDA } } -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp deleted file mode 100644 index 1fc9f4e10d1..00000000000 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp +++ /dev/null @@ -1,447 +0,0 @@ -#include "MantidQtCustomInterfaces/Indirect/ApplyCorr.h" -#include "MantidQtCustomInterfaces/UserInputValidator.h" -#include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/TextAxis.h" - -#include <QStringList> - - -using namespace Mantid::API; - -namespace -{ - Mantid::Kernel::Logger g_log("ApplyCorr"); -} - -namespace MantidQt -{ -namespace CustomInterfaces -{ -namespace IDA -{ - ApplyCorr::ApplyCorr(QWidget * parent) : - CorrectionsTab(parent) - { - m_uiForm.setupUi(parent); - - connect(m_uiForm.cbGeometry, SIGNAL(currentIndexChanged(int)), this, SLOT(handleGeometryChange(int))); - connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString&)), this, SLOT(newData(const QString&))); - connect(m_uiForm.spPreviewSpec, SIGNAL(valueChanged(int)), this, SLOT(plotPreview(int))); - - m_uiForm.spPreviewSpec->setMinimum(0); - m_uiForm.spPreviewSpec->setMaximum(0); - } - - - void ApplyCorr::setup() - { - } - - - /** - * Disables corrections when using S(Q, w) as input data. - * - * @param dataName Name of new data source - */ - void ApplyCorr::newData(const QString &dataName) - { - const MatrixWorkspace_sptr sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(dataName.toStdString()); - m_uiForm.spPreviewSpec->setMaximum(static_cast<int>(sampleWs->getNumberHistograms()) - 1); - - // Plot the sample curve - m_uiForm.ppPreview->clear(); - m_uiForm.ppPreview->addSpectrum("Sample", sampleWs, 0, Qt::black); - } - - - void ApplyCorr::run() - { - API::BatchAlgorithmRunner::AlgorithmRuntimeProps absCorProps; - IAlgorithm_sptr applyCorrAlg = AlgorithmManager::Instance().create("ApplyPaalmanPingsCorrection"); - applyCorrAlg->initialize(); - - QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); - MatrixWorkspace_sptr sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(sampleWsName.toStdString()); - m_originalSampleUnits = sampleWs->getAxis(0)->unit()->unitID(); - - // If not in wavelength then do conversion - if(m_originalSampleUnits != "Wavelength") - { - g_log.information("Sample workspace not in wavelength, need to convert to continue."); - absCorProps["SampleWorkspace"] = addConvertUnitsStep(sampleWs, "Wavelength"); - } - else - { - absCorProps["SampleWorkspace"] = sampleWsName.toStdString(); - } - - 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); - - if(result == QMessageBox::Yes) - { - addRebinStep(sampleWsName, canWsName); - } - else - { - m_batchAlgoRunner->clearQueue(); - g_log.error("Cannot apply absorption corrections using a sample and container with different binning."); - return; - } - } - } - - 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("ApplyCorr cannot run with corrections that do not match sample binning."); - return; - } - } - } - - applyCorrAlg->setProperty("CorrectionsWorkspace", correctionsWsName.toStdString()); - } - - // Generate output workspace name - int nameCutIndex = sampleWsName.lastIndexOf("_"); - if(nameCutIndex == -1) - nameCutIndex = sampleWsName.length(); - - QString correctionType; - switch(m_uiForm.cbGeometry->currentIndex()) - { - case 0: - correctionType = "flt"; - break; - case 1: - correctionType = "cyl"; - break; - } - const QString outputWsName = sampleWsName.left(nameCutIndex) + + "_" + correctionType + "_Corrected"; - - applyCorrAlg->setProperty("OutputWorkspace", outputWsName.toStdString()); - - // Add corrections algorithm to queue - m_batchAlgoRunner->addAlgorithm(applyCorrAlg, absCorProps); - - // Run algorithm queue - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(absCorComplete(bool))); - m_batchAlgoRunner->executeBatchAsync(); - - // Set the result workspace for Python script export - m_pythonExportWsName = outputWsName.toStdString(); - } - - - /** - * Adds a rebin to workspace step to the calculation for when using a sample and container that - * have different binning. - * - * @param toRebin - * @param toMatch - */ - void ApplyCorr::addRebinStep(QString toRebin, QString toMatch) - { - API::BatchAlgorithmRunner::AlgorithmRuntimeProps rebinProps; - rebinProps["WorkspaceToMatch"] = toMatch.toStdString(); - - IAlgorithm_sptr rebinAlg = AlgorithmManager::Instance().create("RebinToWorkspace"); - rebinAlg->initialize(); - - rebinAlg->setProperty("WorkspaceToRebin", toRebin.toStdString()); - rebinAlg->setProperty("OutputWorkspace", toRebin.toStdString()); - - m_batchAlgoRunner->addAlgorithm(rebinAlg, rebinProps); - } - - - /** - * Adds a spline interpolation as a step in the calculation for using legacy correction factor - * workspaces. - * - * @param toInterpolate Pointer to the workspace to interpolate - * @param toMatch Name of the workspace to match - */ - void ApplyCorr::addInterpolationStep(MatrixWorkspace_sptr toInterpolate, std::string toMatch) - { - API::BatchAlgorithmRunner::AlgorithmRuntimeProps interpolationProps; - interpolationProps["WorkspaceToMatch"] = toMatch; - - IAlgorithm_sptr interpolationAlg = AlgorithmManager::Instance().create("SplineInterpolation"); - interpolationAlg->initialize(); - - interpolationAlg->setProperty("WorkspaceToInterpolate", toInterpolate->name()); - interpolationAlg->setProperty("OutputWorkspace", toInterpolate->name()); - - m_batchAlgoRunner->addAlgorithm(interpolationAlg, interpolationProps); - } - - - /** - * Handles completion of the abs. correction algorithm. - * - * @param error True if algorithm failed. - */ - void ApplyCorr::absCorComplete(bool error) - { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(absCorComplete(bool))); - - if(error) - { - emit showMessageBox("Unable to apply corrections.\nSee Results Log for more details."); - return; - } - - // Convert back to original sample units - if(m_originalSampleUnits != "Wavelength") - { - auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_pythonExportWsName); - std::string eMode(""); - if(m_originalSampleUnits == "dSpacing") - eMode = "Elastic"; - addConvertUnitsStep(ws, m_originalSampleUnits, "", eMode); - } - - // Add save algorithms if required - bool save = m_uiForm.ckSave->isChecked(); - if(save) - addSaveWorkspaceToQueue(QString::fromStdString(m_pythonExportWsName)); - - // Run algorithm queue - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(postProcessComplete(bool))); - m_batchAlgoRunner->executeBatchAsync(); - } - - - /** - * Handles completion of the unit conversion and saving algorithm. - * - * @param error True if algorithm failed. - */ - void ApplyCorr::postProcessComplete(bool error) - { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(postProcessComplete(bool))); - - if(error) - { - emit showMessageBox("Unable to process corrected workspace.\nSee Results Log for more details."); - return; - } - - // Handle preview plot - plotPreview(m_uiForm.spPreviewSpec->value()); - - // Handle Mantid plotting - QString plotType = m_uiForm.cbPlotOutput->currentText(); - - if(plotType == "Spectra" || plotType == "Both") - plotSpectrum(QString::fromStdString(m_pythonExportWsName)); - - if(plotType == "Contour" || plotType == "Both") - plot2D(QString::fromStdString(m_pythonExportWsName)); - } - - - bool ApplyCorr::validate() - { - UserInputValidator uiv; - - uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample); - - MatrixWorkspace_sptr sampleWs; - - bool useCan = m_uiForm.ckUseCan->isChecked(); - bool useCorrections = m_uiForm.ckUseCorrections->isChecked(); - - 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; - - if(containerType != sampleType) - uiv.addErrorMessage("Sample and can workspaces must contain the same type of data."); - } - - if(useCorrections) - { - uiv.checkDataSelectorIsValid("Corrections", m_uiForm.dsCorrections); - - 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); - } - } - } - - // Show errors if there are any - if(!uiv.isAllInputValid()) - emit showMessageBox(uiv.generateErrorMessage()); - - return uiv.isAllInputValid(); - } - - - void ApplyCorr::loadSettings(const QSettings & settings) - { - m_uiForm.dsCorrections->readSettings(settings.group()); - m_uiForm.dsContainer->readSettings(settings.group()); - m_uiForm.dsSample->readSettings(settings.group()); - } - - - /** - * Handles when the type of geometry changes - * - * Updates the file extension to search for - */ - void ApplyCorr::handleGeometryChange(int index) - { - QString ext(""); - switch(index) - { - case 0: - // Geometry is flat - ext = "_flt_abs"; - break; - case 1: - // Geometry is cylinder - ext = "_cyl_abs"; - break; - case 2: - // Geometry is annulus - ext = "_ann_abs"; - break; - } - m_uiForm.dsCorrections->setWSSuffixes(QStringList(ext)); - m_uiForm.dsCorrections->setFBSuffixes(QStringList(ext + ".nxs")); - } - - - /** - * Replots the preview plot. - * - * @param specIndex Spectrum index to plot - */ - void ApplyCorr::plotPreview(int specIndex) - { - bool useCan = m_uiForm.ckUseCan->isChecked(); - - m_uiForm.ppPreview->clear(); - - // Plot sample - m_uiForm.ppPreview->addSpectrum("Sample", m_uiForm.dsSample->getCurrentDataName(), - specIndex, Qt::black); - - // Plot result - if(!m_pythonExportWsName.empty()) - 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 IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp new file mode 100644 index 00000000000..90dba8e1924 --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyPaalmanPings.cpp @@ -0,0 +1,432 @@ +#include "MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h" +#include "MantidQtCustomInterfaces/UserInputValidator.h" +#include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/TextAxis.h" + +#include <QStringList> + +using namespace Mantid::API; + +namespace { +Mantid::Kernel::Logger g_log("ApplyPaalmanPings"); +} + +namespace MantidQt { +namespace CustomInterfaces { +ApplyPaalmanPings::ApplyPaalmanPings(QWidget *parent) : CorrectionsTab(parent) { + m_uiForm.setupUi(parent); + + connect(m_uiForm.cbGeometry, SIGNAL(currentIndexChanged(int)), this, + SLOT(handleGeometryChange(int))); + connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString &)), this, + SLOT(newData(const QString &))); + connect(m_uiForm.spPreviewSpec, SIGNAL(valueChanged(int)), this, + SLOT(plotPreview(int))); + + m_uiForm.spPreviewSpec->setMinimum(0); + m_uiForm.spPreviewSpec->setMaximum(0); +} + +void ApplyPaalmanPings::setup() {} + +/** + * Disables corrections when using S(Q, w) as input data. + * + * @param dataName Name of new data source + */ +void ApplyPaalmanPings::newData(const QString &dataName) { + const MatrixWorkspace_sptr sampleWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + dataName.toStdString()); + m_uiForm.spPreviewSpec->setMaximum( + static_cast<int>(sampleWs->getNumberHistograms()) - 1); + + // Plot the sample curve + m_uiForm.ppPreview->clear(); + m_uiForm.ppPreview->addSpectrum("Sample", sampleWs, 0, Qt::black); +} + +void ApplyPaalmanPings::run() { + API::BatchAlgorithmRunner::AlgorithmRuntimeProps absCorProps; + IAlgorithm_sptr applyCorrAlg = + AlgorithmManager::Instance().create("ApplyPaalmanPingsCorrection"); + applyCorrAlg->initialize(); + + QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); + MatrixWorkspace_sptr sampleWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + sampleWsName.toStdString()); + m_originalSampleUnits = sampleWs->getAxis(0)->unit()->unitID(); + + // If not in wavelength then do conversion + if (m_originalSampleUnits != "Wavelength") { + g_log.information( + "Sample workspace not in wavelength, need to convert to continue."); + absCorProps["SampleWorkspace"] = + addConvertUnitsStep(sampleWs, "Wavelength"); + } else { + absCorProps["SampleWorkspace"] = sampleWsName.toStdString(); + } + + 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); + + if (result == QMessageBox::Yes) { + addRebinStep(sampleWsName, canWsName); + } else { + m_batchAlgoRunner->clearQueue(); + g_log.error("Cannot apply absorption corrections using a sample and " + "container with different binning."); + return; + } + } + } + + 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("_"); + if (nameCutIndex == -1) + nameCutIndex = sampleWsName.length(); + + QString correctionType; + switch (m_uiForm.cbGeometry->currentIndex()) { + case 0: + correctionType = "flt"; + break; + case 1: + correctionType = "cyl"; + break; + } + const QString outputWsName = + sampleWsName.left(nameCutIndex) + +"_" + correctionType + "_Corrected"; + + applyCorrAlg->setProperty("OutputWorkspace", outputWsName.toStdString()); + + // Add corrections algorithm to queue + m_batchAlgoRunner->addAlgorithm(applyCorrAlg, absCorProps); + + // Run algorithm queue + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(absCorComplete(bool))); + m_batchAlgoRunner->executeBatchAsync(); + + // Set the result workspace for Python script export + m_pythonExportWsName = outputWsName.toStdString(); +} + +/** + * Adds a rebin to workspace step to the calculation for when using a sample and + *container that + * have different binning. + * + * @param toRebin + * @param toMatch + */ +void ApplyPaalmanPings::addRebinStep(QString toRebin, QString toMatch) { + API::BatchAlgorithmRunner::AlgorithmRuntimeProps rebinProps; + rebinProps["WorkspaceToMatch"] = toMatch.toStdString(); + + IAlgorithm_sptr rebinAlg = + AlgorithmManager::Instance().create("RebinToWorkspace"); + rebinAlg->initialize(); + + rebinAlg->setProperty("WorkspaceToRebin", toRebin.toStdString()); + rebinAlg->setProperty("OutputWorkspace", toRebin.toStdString()); + + m_batchAlgoRunner->addAlgorithm(rebinAlg, rebinProps); +} + +/** + * Adds a spline interpolation as a step in the calculation for using legacy + *correction factor + * workspaces. + * + * @param toInterpolate Pointer to the workspace to interpolate + * @param toMatch Name of the workspace to match + */ +void ApplyPaalmanPings::addInterpolationStep(MatrixWorkspace_sptr toInterpolate, + std::string toMatch) { + API::BatchAlgorithmRunner::AlgorithmRuntimeProps interpolationProps; + interpolationProps["WorkspaceToMatch"] = toMatch; + + IAlgorithm_sptr interpolationAlg = + AlgorithmManager::Instance().create("SplineInterpolation"); + interpolationAlg->initialize(); + + interpolationAlg->setProperty("WorkspaceToInterpolate", + toInterpolate->name()); + interpolationAlg->setProperty("OutputWorkspace", toInterpolate->name()); + + m_batchAlgoRunner->addAlgorithm(interpolationAlg, interpolationProps); +} + +/** + * Handles completion of the abs. correction algorithm. + * + * @param error True if algorithm failed. + */ +void ApplyPaalmanPings::absCorComplete(bool error) { + disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(absCorComplete(bool))); + + if (error) { + emit showMessageBox( + "Unable to apply corrections.\nSee Results Log for more details."); + return; + } + + // Convert back to original sample units + if (m_originalSampleUnits != "Wavelength") { + auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + m_pythonExportWsName); + std::string eMode(""); + if (m_originalSampleUnits == "dSpacing") + eMode = "Elastic"; + addConvertUnitsStep(ws, m_originalSampleUnits, "", eMode); + } + + // Add save algorithms if required + bool save = m_uiForm.ckSave->isChecked(); + if (save) + addSaveWorkspaceToQueue(QString::fromStdString(m_pythonExportWsName)); + + // Run algorithm queue + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(postProcessComplete(bool))); + m_batchAlgoRunner->executeBatchAsync(); +} + +/** + * Handles completion of the unit conversion and saving algorithm. + * + * @param error True if algorithm failed. + */ +void ApplyPaalmanPings::postProcessComplete(bool error) { + disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(postProcessComplete(bool))); + + if (error) { + emit showMessageBox("Unable to process corrected workspace.\nSee Results " + "Log for more details."); + return; + } + + // Handle preview plot + plotPreview(m_uiForm.spPreviewSpec->value()); + + // Handle Mantid plotting + QString plotType = m_uiForm.cbPlotOutput->currentText(); + + if (plotType == "Spectra" || plotType == "Both") + plotSpectrum(QString::fromStdString(m_pythonExportWsName)); + + if (plotType == "Contour" || plotType == "Both") + plot2D(QString::fromStdString(m_pythonExportWsName)); +} + +bool ApplyPaalmanPings::validate() { + UserInputValidator uiv; + + uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample); + + MatrixWorkspace_sptr sampleWs; + + bool useCan = m_uiForm.ckUseCan->isChecked(); + bool useCorrections = m_uiForm.ckUseCorrections->isChecked(); + + 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; + + if (containerType != sampleType) + uiv.addErrorMessage( + "Sample and can workspaces must contain the same type of data."); + } + + if (useCorrections) { + uiv.checkDataSelectorIsValid("Corrections", m_uiForm.dsCorrections); + + 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); + } + } + } + + // Show errors if there are any + if (!uiv.isAllInputValid()) + emit showMessageBox(uiv.generateErrorMessage()); + + return uiv.isAllInputValid(); +} + +void ApplyPaalmanPings::loadSettings(const QSettings &settings) { + m_uiForm.dsCorrections->readSettings(settings.group()); + m_uiForm.dsContainer->readSettings(settings.group()); + m_uiForm.dsSample->readSettings(settings.group()); +} + +/** + * Handles when the type of geometry changes + * + * Updates the file extension to search for + */ +void ApplyPaalmanPings::handleGeometryChange(int index) { + QString ext(""); + switch (index) { + case 0: + // Geometry is flat + ext = "_flt_abs"; + break; + case 1: + // Geometry is cylinder + ext = "_cyl_abs"; + break; + case 2: + // Geometry is annulus + ext = "_ann_abs"; + break; + } + m_uiForm.dsCorrections->setWSSuffixes(QStringList(ext)); + m_uiForm.dsCorrections->setFBSuffixes(QStringList(ext + ".nxs")); +} + +/** + * Replots the preview plot. + * + * @param specIndex Spectrum index to plot + */ +void ApplyPaalmanPings::plotPreview(int specIndex) { + bool useCan = m_uiForm.ckUseCan->isChecked(); + + m_uiForm.ppPreview->clear(); + + // Plot sample + m_uiForm.ppPreview->addSpectrum( + "Sample", m_uiForm.dsSample->getCurrentDataName(), specIndex, Qt::black); + + // Plot result + if (!m_pythonExportWsName.empty()) + 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 diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp deleted file mode 100644 index 16258629a57..00000000000 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include "MantidAPI/AnalysisDataService.h" -#include "MantidQtCustomInterfaces/Indirect/CalcCorr.h" -#include "MantidQtCustomInterfaces/UserInputValidator.h" -#include "MantidQtMantidWidgets/WorkspaceSelector.h" - -#include <QLineEdit> -#include <QList> -#include <QValidator> -#include <QDoubleValidator> -#include <QRegExpValidator> - -using namespace Mantid::API; - -namespace -{ - Mantid::Kernel::Logger g_log("CalcCorr"); -} - -namespace MantidQt -{ -namespace CustomInterfaces -{ -namespace IDA -{ - CalcCorr::CalcCorr(QWidget * parent) : - CorrectionsTab(parent) - { - m_uiForm.setupUi(parent); - - connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString&)), this, SLOT(getBeamWidthFromWorkspace(const QString&))); - - QRegExp regex("[A-Za-z0-9\\-\\(\\)]*"); - QValidator *formulaValidator = new QRegExpValidator(regex, this); - m_uiForm.leSampleChemicalFormula->setValidator(formulaValidator); - m_uiForm.leCanChemicalFormula->setValidator(formulaValidator); - } - - - void CalcCorr::setup() - { - doValidation(true); - } - - - void CalcCorr::run() - { - // Get correct corrections algorithm - QString sampleShape = m_uiForm.cbSampleShape->currentText(); - QString algorithmName = sampleShape.replace(" ", "") + "PaalmanPingsCorrection"; - algorithmName = algorithmName.replace("Annulus", "Cylinder"); // Use the cylinder algorithm for annulus - - API::BatchAlgorithmRunner::AlgorithmRuntimeProps absCorProps; - IAlgorithm_sptr absCorAlgo = AlgorithmManager::Instance().create(algorithmName.toStdString()); - absCorAlgo->initialize(); - - // Sample details - QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); - MatrixWorkspace_sptr sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(sampleWsName.toStdString()); - - // If not in wavelength then do conversion - Mantid::Kernel::Unit_sptr sampleXUnit = sampleWs->getAxis(0)->unit(); - if(sampleXUnit->caption() != "Wavelength") - { - g_log.information("Sample workspace not in wavelength, need to convert to continue."); - absCorProps["SampleWorkspace"] = addConvertUnitsStep(sampleWs, "Wavelength"); - } - else - { - absCorProps["SampleWorkspace"] = sampleWsName.toStdString(); - } - - double sampleNumberDensity = m_uiForm.spSampleNumberDensity->value(); - absCorAlgo->setProperty("SampleNumberDensity", sampleNumberDensity); - - QString sampleChemicalFormula = m_uiForm.leSampleChemicalFormula->text(); - absCorAlgo->setProperty("SampleChemicalFormula", sampleChemicalFormula.toStdString()); - - addShapeSpecificSampleOptions(absCorAlgo, sampleShape); - - // Can details - 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 - Mantid::Kernel::Unit_sptr canXUnit = canWs->getAxis(0)->unit(); - if(canXUnit->caption() != "Wavelength") - { - g_log.information("Container workspace not in wavelength, need to convert to continue."); - absCorProps["CanWorkspace"] = addConvertUnitsStep(canWs, "Wavelength"); - } - else - { - absCorProps["CanWorkspace"] = canWsName.toStdString(); - } - - double canNumberDensity = m_uiForm.spCanNumberDensity->value(); - absCorAlgo->setProperty("CanNumberDensity", canNumberDensity); - - QString canChemicalFormula = m_uiForm.leCanChemicalFormula->text(); - absCorAlgo->setProperty("CanChemicalFormula", canChemicalFormula.toStdString()); - - addShapeSpecificCanOptions(absCorAlgo, sampleShape); - } - - std::string eMode = getEMode(sampleWs); - absCorAlgo->setProperty("EMode", eMode); - if(eMode == "Indirect") - absCorAlgo->setProperty("EFixed", getEFixed(sampleWs)); - - // Generate workspace names - int nameCutIndex = sampleWsName.lastIndexOf("_"); - if(nameCutIndex == -1) - nameCutIndex = sampleWsName.length(); - - QString correctionType; - switch(m_uiForm.cbSampleShape->currentIndex()) - { - case 0: - correctionType = "flt"; - break; - case 1: - correctionType = "cyl"; - break; - case 2: - correctionType = "ann"; - break; - } - - const QString outputWsName = sampleWsName.left(nameCutIndex) + "_" + correctionType + "_abs"; - absCorAlgo->setProperty("OutputWorkspace", outputWsName.toStdString()); - - // Add corrections algorithm to queue - m_batchAlgoRunner->addAlgorithm(absCorAlgo, absCorProps); - - // Add save algorithms if required - bool save = m_uiForm.ckSave->isChecked(); - if(save) - addSaveWorkspaceToQueue(outputWsName); - - // Run algorithm queue - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(absCorComplete(bool))); - m_batchAlgoRunner->executeBatchAsync(); - - // Set the result workspace for Python script export - m_pythonExportWsName = outputWsName.toStdString(); - } - - - bool CalcCorr::validate() - { - return doValidation(); - } - - - /** - * Does validation on the user input. - * - * @param silent Set to true to avoid creating an error message - * @return True if all user input is valid - */ - bool CalcCorr::doValidation(bool silent) - { - UserInputValidator uiv; - - uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample); - - // Validate chemical formula - if(uiv.checkFieldIsNotEmpty("Sample Chemical Formula", m_uiForm.leSampleChemicalFormula, m_uiForm.valSampleChemicalFormula)) - uiv.checkFieldIsValid("Sample Chemical Formula", m_uiForm.leSampleChemicalFormula, m_uiForm.valSampleChemicalFormula); - - bool useCan = m_uiForm.ckUseCan->isChecked(); - if(useCan) - { - uiv.checkDataSelectorIsValid("Can", m_uiForm.dsContainer); - - // Validate chemical formula - if(uiv.checkFieldIsNotEmpty("Can Chemical Formula", m_uiForm.leCanChemicalFormula, m_uiForm.valCanChemicalFormula)) - uiv.checkFieldIsValid("Can Chemical Formula", m_uiForm.leCanChemicalFormula, m_uiForm.valCanChemicalFormula); - - // Ensure sample and container are the same kind of data - QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); - QString sampleType = sampleWsName.right(sampleWsName.length() - sampleWsName.lastIndexOf("_")); - QString containerWsName = m_uiForm.dsContainer->getCurrentDataName(); - QString containerType = containerWsName.right(containerWsName.length() - containerWsName.lastIndexOf("_")); - - g_log.debug() << "Sample type is: " << sampleType.toStdString() << std::endl; - g_log.debug() << "Can type is: " << containerType.toStdString() << std::endl; - - if(containerType != sampleType) - uiv.addErrorMessage("Sample and can workspaces must contain the same type of data."); - } - - // Show error mssage if needed - if(!uiv.isAllInputValid() && !silent) - emit showMessageBox(uiv.generateErrorMessage()); - - return uiv.isAllInputValid(); - } - - - /** - * Handles completion of the correction algorithm. - * - * @param error True of the algorithm failed - */ - void CalcCorr::absCorComplete(bool error) - { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(absCorComplete(bool))); - - if(error) - { - emit showMessageBox("Absorption correction calculation failed.\nSee Results Log for more details."); - return; - } - - // Convert the spectrum axis of correction factors to Q - QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); - MatrixWorkspace_sptr sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(sampleWsName.toStdString()); - WorkspaceGroup_sptr corrections = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(m_pythonExportWsName); - for(size_t i = 0; i < corrections->size(); i++) - { - MatrixWorkspace_sptr factorWs = boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); - if(!factorWs || !sampleWs) - continue; - - std::string eMode = getEMode(sampleWs); - - if(eMode == "Indirect") - { - API::BatchAlgorithmRunner::AlgorithmRuntimeProps convertSpecProps; - IAlgorithm_sptr convertSpecAlgo = AlgorithmManager::Instance().create("ConvertSpectrumAxis"); - convertSpecAlgo->initialize(); - convertSpecAlgo->setProperty("InputWorkspace", factorWs); - convertSpecAlgo->setProperty("OutputWorkspace", factorWs->name()); - convertSpecAlgo->setProperty("Target", "ElasticQ"); - convertSpecAlgo->setProperty("EMode", "Indirect"); - - try - { - convertSpecAlgo->setProperty("EFixed", getEFixed(factorWs)); - } - catch(std::runtime_error &) {} - - m_batchAlgoRunner->addAlgorithm(convertSpecAlgo); - } - } - - // Run algorithm queue - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(postProcessComplete(bool))); - m_batchAlgoRunner->executeBatchAsync(); - } - - - /** - * Handles completion of the post processing algorithms. - * - * @param error True of the algorithm failed - */ - void CalcCorr::postProcessComplete(bool error) - { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(postProcessComplete(bool))); - - if(error) - { - emit showMessageBox("Correction factor post processing failed.\nSee Results Log for more details."); - return; - } - - // Handle Mantid plotting - QString plotType = m_uiForm.cbPlotOutput->currentText(); - - if(plotType == "Both" || plotType == "Wavelength") - plotSpectrum(QString::fromStdString(m_pythonExportWsName)); - - if(plotType == "Both" || plotType == "Angle") - plotTimeBin(QString::fromStdString(m_pythonExportWsName)); - } - - - void CalcCorr::loadSettings(const QSettings & settings) - { - m_uiForm.dsSample->readSettings(settings.group()); - m_uiForm.dsContainer->readSettings(settings.group()); - } - - - /** - * Gets the beam width from the instrument parameters on a given workspace - * and update the relevant options on the UI. - * - * @param wsName Name of the workspace - */ - void CalcCorr::getBeamWidthFromWorkspace(const QString& wsName) - { - auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName.toStdString()); - - if(!ws) - { - g_log.warning() << "Failed to find workspace " << wsName.toStdString() << std::endl; - return; - } - - auto instrument = ws->getInstrument(); - - const std::string beamWidthParamName = "Workflow.beam-width"; - if(instrument->hasParameter(beamWidthParamName)) - { - QString beamWidth = QString::fromStdString(instrument->getStringParameter(beamWidthParamName)[0]); - double beamWidthValue = beamWidth.toDouble(); - - m_uiForm.spCylBeamWidth->setValue(beamWidthValue); - m_uiForm.spAnnBeamWidth->setValue(beamWidthValue); - } - - const std::string beamHeightParamName = "Workflow.beam-height"; - if(instrument->hasParameter(beamHeightParamName)) - { - QString beamHeight = QString::fromStdString(instrument->getStringParameter(beamHeightParamName)[0]); - double beamHeightValue = beamHeight.toDouble(); - - m_uiForm.spCylBeamHeight->setValue(beamHeightValue); - m_uiForm.spAnnBeamHeight->setValue(beamHeightValue); - } - } - - - /** - * Sets algorithm properties specific to the sample for a given shape. - * - * @param alg Algorithm to set properties of - * @param shape Sample shape - */ - void CalcCorr::addShapeSpecificSampleOptions(IAlgorithm_sptr alg, QString shape) - { - if(shape == "FlatPlate") - { - double sampleThickness = m_uiForm.spFlatSampleThickness->value(); - alg->setProperty("SampleThickness", sampleThickness); - - double sampleAngle = m_uiForm.spFlatSampleAngle->value(); - alg->setProperty("SampleAngle", sampleAngle); - } - else if(shape == "Cylinder") - { - alg->setProperty("SampleInnerRadius", 0.0); - - double sampleOuterRadius = m_uiForm.spCylSampleOuterRadius->value(); - alg->setProperty("SampleOuterRadius", sampleOuterRadius); - - double beamWidth = m_uiForm.spCylBeamWidth->value(); - alg->setProperty("BeamWidth", beamWidth); - - double beamHeight = m_uiForm.spCylBeamHeight->value(); - alg->setProperty("BeamHeight", beamHeight); - - double stepSize = m_uiForm.spCylStepSize->value(); - alg->setProperty("StepSize", stepSize); - } - else if(shape == "Annulus") - { - double sampleInnerRadius = m_uiForm.spAnnSampleInnerRadius->value(); - alg->setProperty("SampleInnerRadius", sampleInnerRadius); - - double sampleOuterRadius = m_uiForm.spAnnSampleOuterRadius->value(); - alg->setProperty("SampleOuterRadius", sampleOuterRadius); - - double beamWidth = m_uiForm.spAnnBeamWidth->value(); - alg->setProperty("BeamWidth", beamWidth); - - double beamHeight = m_uiForm.spAnnBeamHeight->value(); - alg->setProperty("BeamHeight", beamHeight); - - double stepSize = m_uiForm.spAnnStepSize->value(); - alg->setProperty("StepSize", stepSize); - } - } - - - /** - * Sets algorithm properties specific to the container for a given shape. - * - * @param alg Algorithm to set properties of - * @param shape Sample shape - */ - void CalcCorr::addShapeSpecificCanOptions(IAlgorithm_sptr alg, QString shape) - { - if(shape == "FlatPlate") - { - double canFrontThickness = m_uiForm.spFlatCanFrontThickness->value(); - alg->setProperty("CanFrontThickness", canFrontThickness); - - double canBackThickness = m_uiForm.spFlatCanBackThickness->value(); - alg->setProperty("SampleThickness", canBackThickness); - } - else if(shape == "Cylinder") - { - double canOuterRadius = m_uiForm.spCylCanOuterRadius->value(); - alg->setProperty("CanOuterRadius", canOuterRadius); - } - else if(shape == "Annulus") - { - double canOuterRadius = m_uiForm.spAnnCanOuterRadius->value(); - alg->setProperty("CanOuterRadius", canOuterRadius); - } - } - - -} // namespace IDA -} // namespace CustomInterfaces -} // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalculatePaalmanPings.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalculatePaalmanPings.cpp new file mode 100644 index 00000000000..81277fad6d9 --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalculatePaalmanPings.cpp @@ -0,0 +1,399 @@ +#include "MantidAPI/AnalysisDataService.h" +#include "MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h" +#include "MantidQtCustomInterfaces/UserInputValidator.h" +#include "MantidQtMantidWidgets/WorkspaceSelector.h" + +#include <QLineEdit> +#include <QList> +#include <QValidator> +#include <QDoubleValidator> +#include <QRegExpValidator> + +using namespace Mantid::API; + +namespace { +Mantid::Kernel::Logger g_log("CalculatePaalmanPings"); +} + +namespace MantidQt { +namespace CustomInterfaces { +CalculatePaalmanPings::CalculatePaalmanPings(QWidget *parent) + : CorrectionsTab(parent) { + m_uiForm.setupUi(parent); + + connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString &)), this, + SLOT(getBeamWidthFromWorkspace(const QString &))); + + QRegExp regex("[A-Za-z0-9\\-\\(\\)]*"); + QValidator *formulaValidator = new QRegExpValidator(regex, this); + m_uiForm.leSampleChemicalFormula->setValidator(formulaValidator); + m_uiForm.leCanChemicalFormula->setValidator(formulaValidator); +} + +void CalculatePaalmanPings::setup() { doValidation(true); } + +void CalculatePaalmanPings::run() { + // Get correct corrections algorithm + QString sampleShape = m_uiForm.cbSampleShape->currentText(); + QString algorithmName = + sampleShape.replace(" ", "") + "PaalmanPingsCorrection"; + algorithmName = algorithmName.replace( + "Annulus", "Cylinder"); // Use the cylinder algorithm for annulus + + API::BatchAlgorithmRunner::AlgorithmRuntimeProps absCorProps; + IAlgorithm_sptr absCorAlgo = + AlgorithmManager::Instance().create(algorithmName.toStdString()); + absCorAlgo->initialize(); + + // Sample details + QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); + MatrixWorkspace_sptr sampleWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + sampleWsName.toStdString()); + + // If not in wavelength then do conversion + Mantid::Kernel::Unit_sptr sampleXUnit = sampleWs->getAxis(0)->unit(); + if (sampleXUnit->caption() != "Wavelength") { + g_log.information( + "Sample workspace not in wavelength, need to convert to continue."); + absCorProps["SampleWorkspace"] = + addConvertUnitsStep(sampleWs, "Wavelength"); + } else { + absCorProps["SampleWorkspace"] = sampleWsName.toStdString(); + } + + double sampleNumberDensity = m_uiForm.spSampleNumberDensity->value(); + absCorAlgo->setProperty("SampleNumberDensity", sampleNumberDensity); + + QString sampleChemicalFormula = m_uiForm.leSampleChemicalFormula->text(); + absCorAlgo->setProperty("SampleChemicalFormula", + sampleChemicalFormula.toStdString()); + + addShapeSpecificSampleOptions(absCorAlgo, sampleShape); + + // Can details + 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 + Mantid::Kernel::Unit_sptr canXUnit = canWs->getAxis(0)->unit(); + if (canXUnit->caption() != "Wavelength") { + g_log.information("Container workspace not in wavelength, need to " + "convert to continue."); + absCorProps["CanWorkspace"] = addConvertUnitsStep(canWs, "Wavelength"); + } else { + absCorProps["CanWorkspace"] = canWsName.toStdString(); + } + + double canNumberDensity = m_uiForm.spCanNumberDensity->value(); + absCorAlgo->setProperty("CanNumberDensity", canNumberDensity); + + QString canChemicalFormula = m_uiForm.leCanChemicalFormula->text(); + absCorAlgo->setProperty("CanChemicalFormula", + canChemicalFormula.toStdString()); + + addShapeSpecificCanOptions(absCorAlgo, sampleShape); + } + + std::string eMode = getEMode(sampleWs); + absCorAlgo->setProperty("EMode", eMode); + if (eMode == "Indirect") + absCorAlgo->setProperty("EFixed", getEFixed(sampleWs)); + + // Generate workspace names + int nameCutIndex = sampleWsName.lastIndexOf("_"); + if (nameCutIndex == -1) + nameCutIndex = sampleWsName.length(); + + QString correctionType; + switch (m_uiForm.cbSampleShape->currentIndex()) { + case 0: + correctionType = "flt"; + break; + case 1: + correctionType = "cyl"; + break; + case 2: + correctionType = "ann"; + break; + } + + const QString outputWsName = + sampleWsName.left(nameCutIndex) + "_" + correctionType + "_abs"; + absCorAlgo->setProperty("OutputWorkspace", outputWsName.toStdString()); + + // Add corrections algorithm to queue + m_batchAlgoRunner->addAlgorithm(absCorAlgo, absCorProps); + + // Add save algorithms if required + bool save = m_uiForm.ckSave->isChecked(); + if (save) + addSaveWorkspaceToQueue(outputWsName); + + // Run algorithm queue + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(absCorComplete(bool))); + m_batchAlgoRunner->executeBatchAsync(); + + // Set the result workspace for Python script export + m_pythonExportWsName = outputWsName.toStdString(); +} + +bool CalculatePaalmanPings::validate() { return doValidation(); } + +/** + * Does validation on the user input. + * + * @param silent Set to true to avoid creating an error message + * @return True if all user input is valid + */ +bool CalculatePaalmanPings::doValidation(bool silent) { + UserInputValidator uiv; + + uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample); + + // Validate chemical formula + if (uiv.checkFieldIsNotEmpty("Sample Chemical Formula", + m_uiForm.leSampleChemicalFormula, + m_uiForm.valSampleChemicalFormula)) + uiv.checkFieldIsValid("Sample Chemical Formula", + m_uiForm.leSampleChemicalFormula, + m_uiForm.valSampleChemicalFormula); + + bool useCan = m_uiForm.ckUseCan->isChecked(); + if (useCan) { + uiv.checkDataSelectorIsValid("Can", m_uiForm.dsContainer); + + // Validate chemical formula + if (uiv.checkFieldIsNotEmpty("Can Chemical Formula", + m_uiForm.leCanChemicalFormula, + m_uiForm.valCanChemicalFormula)) + uiv.checkFieldIsValid("Can Chemical Formula", + m_uiForm.leCanChemicalFormula, + m_uiForm.valCanChemicalFormula); + + // Ensure sample and container are the same kind of data + QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); + QString sampleType = sampleWsName.right(sampleWsName.length() - + sampleWsName.lastIndexOf("_")); + QString containerWsName = m_uiForm.dsContainer->getCurrentDataName(); + QString containerType = containerWsName.right( + containerWsName.length() - containerWsName.lastIndexOf("_")); + + g_log.debug() << "Sample type is: " << sampleType.toStdString() + << std::endl; + g_log.debug() << "Can type is: " << containerType.toStdString() + << std::endl; + + if (containerType != sampleType) + uiv.addErrorMessage( + "Sample and can workspaces must contain the same type of data."); + } + + // Show error mssage if needed + if (!uiv.isAllInputValid() && !silent) + emit showMessageBox(uiv.generateErrorMessage()); + + return uiv.isAllInputValid(); +} + +/** + * Handles completion of the correction algorithm. + * + * @param error True of the algorithm failed + */ +void CalculatePaalmanPings::absCorComplete(bool error) { + disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(absCorComplete(bool))); + + if (error) { + emit showMessageBox("Absorption correction calculation failed.\nSee " + "Results Log for more details."); + return; + } + + // Convert the spectrum axis of correction factors to Q + QString sampleWsName = m_uiForm.dsSample->getCurrentDataName(); + MatrixWorkspace_sptr sampleWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + sampleWsName.toStdString()); + WorkspaceGroup_sptr corrections = + AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>( + m_pythonExportWsName); + for (size_t i = 0; i < corrections->size(); i++) { + MatrixWorkspace_sptr factorWs = + boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); + if (!factorWs || !sampleWs) + continue; + + std::string eMode = getEMode(sampleWs); + + if (eMode == "Indirect") { + API::BatchAlgorithmRunner::AlgorithmRuntimeProps convertSpecProps; + IAlgorithm_sptr convertSpecAlgo = + AlgorithmManager::Instance().create("ConvertSpectrumAxis"); + convertSpecAlgo->initialize(); + convertSpecAlgo->setProperty("InputWorkspace", factorWs); + convertSpecAlgo->setProperty("OutputWorkspace", factorWs->name()); + convertSpecAlgo->setProperty("Target", "ElasticQ"); + convertSpecAlgo->setProperty("EMode", "Indirect"); + + try { + convertSpecAlgo->setProperty("EFixed", getEFixed(factorWs)); + } catch (std::runtime_error &) { + } + + m_batchAlgoRunner->addAlgorithm(convertSpecAlgo); + } + } + + // Run algorithm queue + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(postProcessComplete(bool))); + m_batchAlgoRunner->executeBatchAsync(); +} + +/** + * Handles completion of the post processing algorithms. + * + * @param error True of the algorithm failed + */ +void CalculatePaalmanPings::postProcessComplete(bool error) { + disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, + SLOT(postProcessComplete(bool))); + + if (error) { + emit showMessageBox("Correction factor post processing failed.\nSee " + "Results Log for more details."); + return; + } + + // Handle Mantid plotting + QString plotType = m_uiForm.cbPlotOutput->currentText(); + + if (plotType == "Both" || plotType == "Wavelength") + plotSpectrum(QString::fromStdString(m_pythonExportWsName)); + + if (plotType == "Both" || plotType == "Angle") + plotTimeBin(QString::fromStdString(m_pythonExportWsName)); +} + +void CalculatePaalmanPings::loadSettings(const QSettings &settings) { + m_uiForm.dsSample->readSettings(settings.group()); + m_uiForm.dsContainer->readSettings(settings.group()); +} + +/** + * Gets the beam width from the instrument parameters on a given workspace + * and update the relevant options on the UI. + * + * @param wsName Name of the workspace + */ +void CalculatePaalmanPings::getBeamWidthFromWorkspace(const QString &wsName) { + auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + wsName.toStdString()); + + if (!ws) { + g_log.warning() << "Failed to find workspace " << wsName.toStdString() + << std::endl; + return; + } + + auto instrument = ws->getInstrument(); + + const std::string beamWidthParamName = "Workflow.beam-width"; + if (instrument->hasParameter(beamWidthParamName)) { + QString beamWidth = QString::fromStdString( + instrument->getStringParameter(beamWidthParamName)[0]); + double beamWidthValue = beamWidth.toDouble(); + + m_uiForm.spCylBeamWidth->setValue(beamWidthValue); + m_uiForm.spAnnBeamWidth->setValue(beamWidthValue); + } + + const std::string beamHeightParamName = "Workflow.beam-height"; + if (instrument->hasParameter(beamHeightParamName)) { + QString beamHeight = QString::fromStdString( + instrument->getStringParameter(beamHeightParamName)[0]); + double beamHeightValue = beamHeight.toDouble(); + + m_uiForm.spCylBeamHeight->setValue(beamHeightValue); + m_uiForm.spAnnBeamHeight->setValue(beamHeightValue); + } +} + +/** + * Sets algorithm properties specific to the sample for a given shape. + * + * @param alg Algorithm to set properties of + * @param shape Sample shape + */ +void CalculatePaalmanPings::addShapeSpecificSampleOptions(IAlgorithm_sptr alg, + QString shape) { + if (shape == "FlatPlate") { + double sampleThickness = m_uiForm.spFlatSampleThickness->value(); + alg->setProperty("SampleThickness", sampleThickness); + + double sampleAngle = m_uiForm.spFlatSampleAngle->value(); + alg->setProperty("SampleAngle", sampleAngle); + } else if (shape == "Cylinder") { + alg->setProperty("SampleInnerRadius", 0.0); + + double sampleOuterRadius = m_uiForm.spCylSampleOuterRadius->value(); + alg->setProperty("SampleOuterRadius", sampleOuterRadius); + + double beamWidth = m_uiForm.spCylBeamWidth->value(); + alg->setProperty("BeamWidth", beamWidth); + + double beamHeight = m_uiForm.spCylBeamHeight->value(); + alg->setProperty("BeamHeight", beamHeight); + + double stepSize = m_uiForm.spCylStepSize->value(); + alg->setProperty("StepSize", stepSize); + } else if (shape == "Annulus") { + double sampleInnerRadius = m_uiForm.spAnnSampleInnerRadius->value(); + alg->setProperty("SampleInnerRadius", sampleInnerRadius); + + double sampleOuterRadius = m_uiForm.spAnnSampleOuterRadius->value(); + alg->setProperty("SampleOuterRadius", sampleOuterRadius); + + double beamWidth = m_uiForm.spAnnBeamWidth->value(); + alg->setProperty("BeamWidth", beamWidth); + + double beamHeight = m_uiForm.spAnnBeamHeight->value(); + alg->setProperty("BeamHeight", beamHeight); + + double stepSize = m_uiForm.spAnnStepSize->value(); + alg->setProperty("StepSize", stepSize); + } +} + +/** + * Sets algorithm properties specific to the container for a given shape. + * + * @param alg Algorithm to set properties of + * @param shape Sample shape + */ +void CalculatePaalmanPings::addShapeSpecificCanOptions(IAlgorithm_sptr alg, + QString shape) { + if (shape == "FlatPlate") { + double canFrontThickness = m_uiForm.spFlatCanFrontThickness->value(); + alg->setProperty("CanFrontThickness", canFrontThickness); + + double canBackThickness = m_uiForm.spFlatCanBackThickness->value(); + alg->setProperty("SampleThickness", canBackThickness); + } else if (shape == "Cylinder") { + double canOuterRadius = m_uiForm.spCylCanOuterRadius->value(); + alg->setProperty("CanOuterRadius", canOuterRadius); + } else if (shape == "Annulus") { + double canOuterRadius = m_uiForm.spAnnCanOuterRadius->value(); + alg->setProperty("CanOuterRadius", canOuterRadius); + } +} + +} // namespace CustomInterfaces +} // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CorrectionsTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CorrectionsTab.cpp index c5e16c72c36..4797b73095d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CorrectionsTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CorrectionsTab.cpp @@ -13,20 +13,15 @@ using namespace Mantid::API; namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { /** * Constructor. * - * @param parent :: the parent widget (an IndirectDataAnalysis object). + * @param parent :: the parent widget */ CorrectionsTab::CorrectionsTab(QWidget * parent) : IndirectTab(parent), - m_dblEdFac(NULL), m_blnEdFac(NULL), - m_parent(NULL) + m_dblEdFac(NULL), m_blnEdFac(NULL) { - m_parent = dynamic_cast<IndirectDataAnalysis*>(parent); - // Create Editor Factories m_dblEdFac = new DoubleEditorFactory(this); m_blnEdFac = new QtCheckBoxFactory(this); @@ -119,6 +114,5 @@ namespace IDA return outputName; } -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp index ede5c518d03..ab988fcc813 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectCorrections.cpp @@ -3,14 +3,8 @@ //---------------------- #include "MantidQtCustomInterfaces/Indirect/IndirectCorrections.h" -// IndirectDataAnalysisTab subclasses: -#include "MantidQtCustomInterfaces/Indirect/Elwin.h" -#include "MantidQtCustomInterfaces/Indirect/MSDFit.h" -#include "MantidQtCustomInterfaces/Indirect/Iqt.h" -#include "MantidQtCustomInterfaces/Indirect/IqtFit.h" -#include "MantidQtCustomInterfaces/Indirect/ConvFit.h" -#include "MantidQtCustomInterfaces/Indirect/CalcCorr.h" -#include "MantidQtCustomInterfaces/Indirect/ApplyCorr.h" +#include "MantidQtCustomInterfaces/Indirect/CalculatePaalmanPings.h" +#include "MantidQtCustomInterfaces/Indirect/ApplyPaalmanPings.h" #include "MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h" #include "MantidQtAPI/HelpWindow.h" @@ -24,8 +18,6 @@ namespace MantidQt { namespace CustomInterfaces -{ -namespace IDA { // Add this class to the list of specialised dialogs in this namespace DECLARE_SUBWINDOW(IndirectCorrections) @@ -44,8 +36,8 @@ namespace IDA // Allows us to get a handle on a tab using an enum, for example "m_tabs[ELWIN]". // All tabs MUST appear here to be shown in interface. // We make the assumption that each map key corresponds to the order in which the tabs appear. - m_tabs.insert(std::make_pair(CALC_CORR, new CalcCorr(m_uiForm.twTabs->widget(CALC_CORR)))); - m_tabs.insert(std::make_pair(APPLY_CORR, new ApplyCorr(m_uiForm.twTabs->widget(APPLY_CORR)))); + m_tabs.insert(std::make_pair(CALC_CORR, new CalculatePaalmanPings(m_uiForm.twTabs->widget(CALC_CORR)))); + m_tabs.insert(std::make_pair(APPLY_CORR, new ApplyPaalmanPings(m_uiForm.twTabs->widget(APPLY_CORR)))); m_tabs.insert(std::make_pair(ABSORPTION_CORRECTIONS, new AbsorptionCorrections(m_uiForm.twTabs->widget(ABSORPTION_CORRECTIONS)))); } @@ -169,6 +161,5 @@ namespace IDA showInformationBox(message); } -} // namespace IDA } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectDataAnalysis.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectDataAnalysis.cpp index 93d75ccec5a..b33b395fb2c 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectDataAnalysis.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectDataAnalysis.cpp @@ -9,9 +9,6 @@ #include "MantidQtCustomInterfaces/Indirect/Iqt.h" #include "MantidQtCustomInterfaces/Indirect/IqtFit.h" #include "MantidQtCustomInterfaces/Indirect/ConvFit.h" -#include "MantidQtCustomInterfaces/Indirect/CalcCorr.h" -#include "MantidQtCustomInterfaces/Indirect/ApplyCorr.h" -#include "MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h" #include "MantidQtAPI/HelpWindow.h" #include "MantidQtAPI/ManageUserDirectories.h" diff --git a/Code/Mantid/docs/source/interfaces/Indirect_Corrections.rst b/Code/Mantid/docs/source/interfaces/Indirect_Corrections.rst index 0d494091a9f..83b31e2455b 100644 --- a/Code/Mantid/docs/source/interfaces/Indirect_Corrections.rst +++ b/Code/Mantid/docs/source/interfaces/Indirect_Corrections.rst @@ -30,11 +30,11 @@ Manage Directories Opens the Manage Directories dialog allowing you to change your search directories and default save directory and enable/disable data archive search. -Calculate Corrections ---------------------- +Calculate Paalman Pings +----------------------- .. interface:: Corrections - :widget: tabCalcCorr + :widget: tabCalculatePaalmanPings Calculates absorption corrections in the Paalman & Pings absorption factors that could be applied to the data when given information about the sample (and @@ -167,13 +167,13 @@ References: 1. C J Carlile, Rutherford Laboratory report, RL-74-103 (1974) 2. A K Soper, W S Howells & A C Hannon, `RAL Report RAL-89-046 (1989) <http://wwwisis2.isis.rl.ac.uk/Disordered/Manuals/ATLAS/ATLAS%20manual%20v1.0%20Intro.pdf>`_ -3. H H Paalman & C J Pings, `J Appl Phys 33 2635 (1962) <http://dx.doi.org/10.1063/1.1729034> +3. H H Paalman & C J Pings, `J Appl Phys 33 2635 (1962) <http://dx.doi.org/10.1063/1.1729034>`_ -Apply Corrections ------------------ +Apply Paalman Pings +------------------- .. interface:: Corrections - :widget: tabApplyCorr + :widget: tabApplyPaalmanPings The Apply Corrections tab applies the corrections calculated in the Calculate Corrections tab of the Indirect Data Analysis interface. -- GitLab