diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ISISEnergyTransfer.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ISISEnergyTransfer.h index d164fa8aa6aae3a65e4c873d541e6d5527df0039..49090162ee653bd896774ab56d46edfcee8606f6 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ISISEnergyTransfer.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ISISEnergyTransfer.h @@ -6,68 +6,66 @@ #include "MantidKernel/System.h" #include "MantidQtCustomInterfaces/Background.h" -namespace MantidQt -{ -namespace CustomInterfaces -{ - /** ISISEnergyTransfer - Handles an energy transfer reduction for ISIS instruments. - - @author Dan Nixon - @date 23/07/2014 - - Copyright © 2013 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - This file is part of Mantid. - - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - File change history is stored at: <https://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport ISISEnergyTransfer : public IndirectDataReductionTab - { - Q_OBJECT - - public: - ISISEnergyTransfer(IndirectDataReduction * idrUI, QWidget * parent = 0); - virtual ~ISISEnergyTransfer(); - - virtual void setup(); - virtual void run(); - - public slots: - virtual bool validate(); - - private slots: - void algorithmComplete(bool error); - void setInstrumentDefault(); ///< Sets default parameters for current instrument - void mappingOptionSelected(const QString& groupType); ///< change ui to display appropriate options - void plotRaw(); ///< plot raw data from instrument - void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. - void pbRunFinding(); //< Called when the FileFinder starts finding the files. - void pbRunFinished(); //< Called when the FileFinder has finished finding the files. - void plotRawComplete(bool error); //< Called when the Plot Raw algorithmm chain completes - - private: - Ui::ISISEnergyTransfer m_uiForm; - - QPair<QString, QString> createMapFile(const QString& groupType); ///< create the mapping file with which to group results - std::vector<std::string> getSaveFormats(); ///< get a vector of save formats - - }; +namespace MantidQt { +namespace CustomInterfaces { +/** ISISEnergyTransfer + Handles an energy transfer reduction for ISIS instruments. + + @author Dan Nixon + @date 23/07/2014 + + Copyright © 2013 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class DLLExport ISISEnergyTransfer : public IndirectDataReductionTab { + Q_OBJECT + +public: + ISISEnergyTransfer(IndirectDataReduction *idrUI, QWidget *parent = 0); + virtual ~ISISEnergyTransfer(); + + virtual void setup(); + virtual void run(); + +public slots: + virtual bool validate(); + +private slots: + void algorithmComplete(bool error); + void + setInstrumentDefault(); ///< Sets default parameters for current instrument + void mappingOptionSelected(const QString &groupType); ///< change ui to display appropriate options + void plotRaw(); ///< plot raw data from instrument + void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. + void pbRunFinding(); //< Called when the FileFinder starts finding the files. + void pbRunFinished(); //< Called when the FileFinder has finished finding the files. + void plotRawComplete(bool error); //< Called when the Plot Raw algorithmm chain completes + +private: + Ui::ISISEnergyTransfer m_uiForm; + + QPair<QString, QString> createMapFile(const QString &groupType); ///< create the mapping file with which to group results + std::vector<std::string> getSaveFormats(); ///< get a vector of save formats +}; } // namespace CustomInterfaces } // namespace Mantid -#endif //MANTIDQTCUSTOMINTERFACES_ISISENERGYTRANSFER_H_ +#endif // MANTIDQTCUSTOMINTERFACES_ISISENERGYTRANSFER_H_ diff --git a/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp b/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp index 9839ec88af9df01154c45c2d067bd7529c35b23d..684a600758ee1da57dd55c4810ab16df27c780fe 100644 --- a/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp +++ b/MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp @@ -69,19 +69,19 @@ bool ISISEnergyTransfer::validate() { UserInputValidator uiv; // Run files input - if (!m_uiForm.dsRunFiles->isValid()){ + if (!m_uiForm.dsRunFiles->isValid()) { uiv.addErrorMessage("Run file range is invalid."); } // Calibration file input if (m_uiForm.ckUseCalib->isChecked() && - !m_uiForm.dsCalibrationFile->isValid()){ + !m_uiForm.dsCalibrationFile->isValid()) { uiv.addErrorMessage("Calibration file/workspace is invalid."); } // Mapping file if ((m_uiForm.cbGroupingOptions->currentText() == "File") && - (!m_uiForm.dsMapFile->isValid())){ + (!m_uiForm.dsMapFile->isValid())) { uiv.addErrorMessage("Mapping file is invalid."); } @@ -115,17 +115,63 @@ bool ISISEnergyTransfer::validate() { // Spectra Number check const int specMin = m_uiForm.spSpectraMin->value(); const int specMax = m_uiForm.spSpectraMax->value(); - if(specMin > specMax){ - uiv.addErrorMessage("Spectra Min must be less than Spectra Max"); + if (specMin > specMax) { + uiv.addErrorMessage("Spectra Min must be less than Spectra Max"); } // Background Removal (TOF) - if(m_uiForm.ckBackgroundRemoval->isChecked()){ - const int start = m_uiForm.spBackgroundStart->value(); - const int end = m_uiForm.spBackgroundEnd->value(); - if(start > end){ - uiv.addErrorMessage("Background Start must be less than Background End"); - } + if (m_uiForm.ckBackgroundRemoval->isChecked()) { + const int start = m_uiForm.spBackgroundStart->value(); + const int end = m_uiForm.spBackgroundEnd->value(); + if (start > end) { + uiv.addErrorMessage("Background Start must be less than Background End"); + } + } + + if (m_uiForm.dsRunFiles->isValid()) { + int detectorMin = m_uiForm.spPlotTimeSpecMin->value(); + int detectorMax = m_uiForm.spPlotTimeSpecMax->value(); + + QString rawFile = m_uiForm.dsRunFiles->getFirstFilename(); + auto pos = rawFile.lastIndexOf("."); + auto extension = rawFile.right(rawFile.length() - pos); + QFileInfo rawFileInfo(rawFile); + std::string name = rawFileInfo.baseName().toStdString(); + + IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("Load"); + loadAlg->initialize(); + loadAlg->setProperty("Filename", rawFile.toStdString()); + loadAlg->setProperty("OutputWorkspace", name); + if (extension.compare(".nxs") == 0) { + int64_t detectorMin = + static_cast<int64_t>(m_uiForm.spPlotTimeSpecMin->value()); + int64_t detectorMax = + static_cast<int64_t>(m_uiForm.spPlotTimeSpecMax->value()); + loadAlg->setProperty("SpectrumMin", detectorMin); + loadAlg->setProperty("SpectrumMax", detectorMax); + } else { + loadAlg->setProperty("SpectrumMin", detectorMin); + loadAlg->setProperty("SpectrumMax", detectorMax); + } + + loadAlg->execute(); + + if (m_uiForm.ckBackgroundRemoval->isChecked()) { + MatrixWorkspace_sptr tempWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name); + const double minBack = tempWs->readX(0)[0]; + const double maxBack = tempWs->readX(0)[tempWs->blocksize()]; + + if (m_uiForm.spBackgroundStart->value() < minBack) { + uiv.addErrorMessage("The Start of Background Removal is less than the " + "minimum of the data range"); + } + + if (m_uiForm.spBackgroundEnd->value() > maxBack) { + uiv.addErrorMessage("The End of Background Removal is more than the " + "maximum of the data range"); + } + } } QString error = uiv.generateErrorMessage(); @@ -446,10 +492,10 @@ void ISISEnergyTransfer::plotRaw() { "Minimum spectra must be less than or equal to maximum spectra."); return; } + const int startBack = m_uiForm.spBackgroundStart->value(); + const int endBack = m_uiForm.spBackgroundEnd->value(); if (m_uiForm.ckBackgroundRemoval->isChecked() == true) { - int startBack = m_uiForm.spBackgroundStart->value(); - int endBack = m_uiForm.spBackgroundEnd->value(); if (startBack > endBack) { emit showMessageBox("Background Start must be less than Background End"); return; @@ -462,7 +508,7 @@ void ISISEnergyTransfer::plotRaw() { QFileInfo rawFileInfo(rawFile); std::string name = rawFileInfo.baseName().toStdString(); - IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("Load"); + IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().create("Load"); loadAlg->initialize(); loadAlg->setProperty("Filename", rawFile.toStdString()); loadAlg->setProperty("OutputWorkspace", name); @@ -477,7 +523,27 @@ void ISISEnergyTransfer::plotRaw() { loadAlg->setProperty("SpectrumMin", detectorMin); loadAlg->setProperty("SpectrumMax", detectorMax); } - m_batchAlgoRunner->addAlgorithm(loadAlg); + + loadAlg->execute(); + + if (m_uiForm.ckBackgroundRemoval->isChecked()) { + MatrixWorkspace_sptr tempWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name); + const double minBack = tempWs->readX(0)[0]; + const double maxBack = tempWs->readX(0)[tempWs->blocksize()]; + + if (startBack < minBack) { + emit showMessageBox("The Start of Background Removal is less than the " + "minimum of the data range"); + return; + } + + if (endBack > maxBack) { + emit showMessageBox("The End of Background Removal is more than the " + "maximum of the data range"); + return; + } + } // Rebin the workspace to its self to ensure constant binning BatchAlgorithmRunner::AlgorithmRuntimeProps inputToRebin;