Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sequential fits in Muon Analysis interface #14807

Merged
merged 1 commit into from Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion MantidQt/CustomInterfaces/src/Muon/MuonAnalysis.cpp
Expand Up @@ -3100,7 +3100,6 @@ Workspace_sptr MuonAnalysis::loadDeadTimes(const std::string& filename) const
ITableWorkspace_sptr MuonAnalysis::getDeadTimeCorrection(
boost::shared_ptr<LoadResult> loadResult) const {
// Dead time table which will be used
ITableWorkspace_sptr deadTimesTable;
Workspace_sptr deadTimes;

if (m_uiForm.deadTimeType->currentText() != "None") {
Expand Down Expand Up @@ -3150,6 +3149,9 @@ Algorithm_sptr MuonAnalysis::createLoadAlgorithm()
loadAlg->setProperty("Mode", "Combined");

// -- Dead Time Correction --------------------------------------------------
// If ApplyDeadTimeCorrection is set, the algorithm must have DeadTimeTable
// set too. If it can't be set here (from disk file), the sequential fit
// must load the dead times from each file.

if (m_uiForm.deadTimeType->currentIndex() != 0)
{
Expand Down
41 changes: 40 additions & 1 deletion MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp
Expand Up @@ -3,6 +3,8 @@

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmProxy.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/ITableWorkspace.h"

namespace MantidQt
{
Expand Down Expand Up @@ -369,13 +371,30 @@ namespace MantidWidgets
MatrixWorkspace_sptr ws;

try {
// If ApplyDeadTimeCorrection is set but no dead time table is set,
// we need to load one from the file.
bool loadDeadTimesFromFile = false;
bool applyDTC = m_loadAlg->getProperty("ApplyDeadTimeCorrection");
if (applyDTC) {
if (auto deadTimes =
m_loadAlg->getPointerToProperty("DeadTimeTable")) {
if (deadTimes->value() == "") {
// No workspace set for dead time table - we need to load one
loadDeadTimesFromFile = true;
}
}
}

// Use LoadMuonNexus to load the file
auto loadAlg = AlgorithmManager::Instance().create("LoadMuonNexus");
loadAlg->initialize();
loadAlg->setChild(true);
loadAlg->setRethrows(true);
loadAlg->setPropertyValue("Filename", fileIt->toStdString());
loadAlg->setPropertyValue("OutputWorkspace", "__NotUsed");
if (loadDeadTimesFromFile) {
loadAlg->setPropertyValue("DeadTimeTable", "__DeadTimes");
}
loadAlg->execute();
Workspace_sptr loadedWS = loadAlg->getProperty("OutputWorkspace");
double loadedTimeZero = loadAlg->getProperty("TimeZero");
Expand All @@ -391,10 +410,30 @@ namespace MantidWidgets
process->setPropertyValue("OutputWorkspace", "__YouDontSeeMeIAmNinja");
if (m_fitPropBrowser->rawData()) // TODO: or vice verca?
process->setPropertyValue("RebinParams", "");
if (loadDeadTimesFromFile) {
Workspace_sptr deadTimes = loadAlg->getProperty("DeadTimeTable");
ITableWorkspace_sptr deadTimesTable;
if (auto table =
boost::dynamic_pointer_cast<ITableWorkspace>(deadTimes)) {
deadTimesTable = table;
} else if (auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(
deadTimes)) {
deadTimesTable =
boost::dynamic_pointer_cast<ITableWorkspace>(group->getItem(0));
}
process->setProperty("DeadTimeTable", deadTimesTable);
}

process->execute();

ws = process->getProperty("OutputWorkspace");
Workspace_sptr outputWS = process->getProperty("OutputWorkspace");
ws = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
} catch (const std::exception &ex) {
g_log.error(ex.what());
QMessageBox::critical(
this, "Loading failed",
"Unable to load one of the files.\n\nCheck log for details");

} catch (...) {
QMessageBox::critical(
this, "Loading failed",
Expand Down