From 9d9889cf1aa474548cd872bcfd365ce89fb38c69 Mon Sep 17 00:00:00 2001 From: Anthony Lim <anthony.lim@stfc.ac.uk> Date: Fri, 25 May 2018 16:30:06 +0100 Subject: [PATCH] refs #22464 muon analysis can now store unnorm ws --- .../src/EstimateMuonAsymmetryFromCounts.cpp | 13 +++- .../Algorithms/src/MuonAsymmetryHelper.cpp | 8 ++- .../MuonGroupAsymmetryCalculator.h | 2 +- .../MuonGroupCalculator.h | 3 +- .../src/MuonGroupAsymmetryCalculator.cpp | 45 ++++++++----- .../src/MuonGroupCalculator.cpp | 4 +- .../WorkflowAlgorithms/src/MuonProcess.cpp | 4 +- .../Muon/MuonAnalysis.cpp | 27 +++++--- qt/scientific_interfaces/Muon/MuonAnalysis.h | 2 +- .../Muon/MuonAnalysisDataLoader.cpp | 4 +- .../Muon/MuonAnalysisDataLoader.h | 1 + .../Muon/MuonAnalysisFitDataPresenter.cpp | 66 ++----------------- .../Muon/MuonAnalysisFitDataPresenter.h | 2 +- .../Common/MuonFitPropertyBrowser.h | 2 - .../common/src/MuonFitPropertyBrowser.cpp | 40 ++++++----- 15 files changed, 100 insertions(+), 123 deletions(-) diff --git a/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp b/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp index 3d1ce388e9d..1fcb675423b 100644 --- a/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp +++ b/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp @@ -34,6 +34,9 @@ void EstimateMuonAsymmetryFromCounts::init() { declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( "InputWorkspace", "", Direction::Input), "The name of the input 2D workspace."); + declareProperty("WorkspaceName", "", + "The name used in the normalisation table. If this is blank the InputWorkspace's name will be used."); + declareProperty(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>( "OutputWorkspace", "", Direction::Output), "The name of the output 2D workspace."); @@ -98,6 +101,10 @@ void EstimateMuonAsymmetryFromCounts::exec() { std::vector<std::string> wsNames; // Get original workspace API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); + std::string wsName = getProperty("WorkspaceName"); + if (wsName == "") { + wsName = inputWS->getName(); + } auto numSpectra = inputWS->getNumberHistograms(); // Create output workspace with same dimensions as input API::MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); @@ -166,11 +173,11 @@ void EstimateMuonAsymmetryFromCounts::exec() { else { methods.push_back("Fixed"); } - if (numSpectra > 1) { - wsNames.push_back(inputWS->getName() + "_spec" + std::to_string(i)); + if (spectra.size() > 1) { + wsNames.push_back(wsName+ "_spec" + std::to_string(i)); } else { - wsNames.push_back(inputWS->getName()); + wsNames.push_back(wsName); } // Calculate the asymmetry diff --git a/Framework/Algorithms/src/MuonAsymmetryHelper.cpp b/Framework/Algorithms/src/MuonAsymmetryHelper.cpp index 48bee1ae43a..d701dcef835 100644 --- a/Framework/Algorithms/src/MuonAsymmetryHelper.cpp +++ b/Framework/Algorithms/src/MuonAsymmetryHelper.cpp @@ -173,19 +173,21 @@ Mantid::API::ITableWorkspace_sptr updateNormalizationTable(const std::string &ta for (size_t j = 0; j < wsNames.size(); j++) { bool updated = false; + std::string tmp = wsNames[j]; + std::replace(tmp.begin(), tmp.end(), ' ', ';'); for (size_t row = 0; row < table->rowCount(); row++) { - if (table->String(row, 1) == wsNames[j]) { + if (table->String(row, 1) ==tmp) { table->removeRow(row); table->insertRow(row); Mantid::API::TableRow tableRow = table->getRow(row); - tableRow << static_cast<double>(norms[j]) << wsNames[j] << methods[j]; + tableRow << static_cast<double>(norms[j]) << tmp << methods[j]; updated = true; } } if (!updated) { Mantid::API::TableRow tableRow = table->appendRow(); - tableRow << static_cast<double>(norms[j]) << wsNames[j] << methods[j]; + tableRow << static_cast<double>(norms[j]) << tmp << methods[j]; } } return table; diff --git a/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupAsymmetryCalculator.h b/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupAsymmetryCalculator.h index 0e3925d5aad..7a75523c125 100644 --- a/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupAsymmetryCalculator.h +++ b/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupAsymmetryCalculator.h @@ -36,7 +36,7 @@ public: const std::vector<int> summedPeriods, const std::vector<int> subtractedPeriods, const int groupIndex, const double start = 0.0, - const double end = 30.0); + const double end = 30.0, const std::string wsName=""); /// Performs group asymmetry calculation API::MatrixWorkspace_sptr calculate() const override; diff --git a/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupCalculator.h b/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupCalculator.h index 02468d42e37..7a038d07636 100644 --- a/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupCalculator.h +++ b/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/MuonGroupCalculator.h @@ -36,12 +36,13 @@ public: const std::vector<int> subtractedPeriods, const int groupIndex); void setStartEnd(const double start, const double end); - + void setWSName(const std::string wsName); protected: /// Workspace index of the group to analyse const int m_groupIndex; double m_startX; double m_endX; + std::string m_wsName; }; } // namespace WorkflowAlgorithms diff --git a/Framework/WorkflowAlgorithms/src/MuonGroupAsymmetryCalculator.cpp b/Framework/WorkflowAlgorithms/src/MuonGroupAsymmetryCalculator.cpp index 282332664c9..39617583462 100644 --- a/Framework/WorkflowAlgorithms/src/MuonGroupAsymmetryCalculator.cpp +++ b/Framework/WorkflowAlgorithms/src/MuonGroupAsymmetryCalculator.cpp @@ -1,4 +1,5 @@ #include "MantidWorkflowAlgorithms/MuonGroupAsymmetryCalculator.h" +#include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/TableRow.h" @@ -28,10 +29,11 @@ MuonGroupAsymmetryCalculator::MuonGroupAsymmetryCalculator( const Mantid::API::WorkspaceGroup_sptr inputWS, const std::vector<int> summedPeriods, const std::vector<int> subtractedPeriods, const int groupIndex, - const double start, const double end) + const double start, const double end,const std::string wsName) : MuonGroupCalculator(inputWS, summedPeriods, subtractedPeriods, groupIndex) { - MuonGroupCalculator::setStartEnd(start, end); + MuonGroupCalculator::setStartEnd(start, end); + MuonGroupCalculator::setWSName(wsName); } /** @@ -118,14 +120,28 @@ MatrixWorkspace_sptr MuonGroupAsymmetryCalculator::estimateAsymmetry(const Workspace_sptr &inputWS, const int index) const { std::vector<double> normEst; + const std::string normTableName = "MuonAnalysisTFNormalizations"; + API::AnalysisDataServiceImpl &ads = API::AnalysisDataService::Instance(); + if(!ads.doesExist(normTableName)) { + Mantid::API::ITableWorkspace_sptr table = Mantid::API::WorkspaceFactory::Instance().createTable(); + Mantid::API::AnalysisDataService::Instance().addOrReplace(normTableName, + table); + table->addColumn("double", "norm"); + table->addColumn("str", "name"); + table->addColumn("str", "method"); + table->removeRow(0); + } + MatrixWorkspace_sptr outWS; // calculate asymmetry if (inputWS) { IAlgorithm_sptr asym = AlgorithmManager::Instance().create("EstimateMuonAsymmetryFromCounts"); asym->setChild(true); - asym->setProperty("InputWorkspace", inputWS); - if (index > -1) { + + asym->setProperty("InputWorkspace", inputWS); + asym->setProperty("WorkspaceName", m_wsName); + if (index > -1) { std::vector<int> spec(1, index); asym->setProperty("Spectra", spec); } @@ -133,22 +149,17 @@ MuonGroupAsymmetryCalculator::estimateAsymmetry(const Workspace_sptr &inputWS, asym->setProperty("StartX", m_startX); asym->setProperty("EndX", m_endX); asym->setProperty("NormalizationIn", getStoredNorm()); + asym->setProperty("OutputUnNormData", true); + asym->setProperty("OutputUnNormWorkspace", "tmp_unNorm"); + asym->setProperty("NormalisationTable", normTableName); asym->execute(); - outWS = asym->getProperty("OutputWorkspace"); - auto tmp = asym->getPropertyValue("NormalizationConstant"); - // move to helper later as a function - normEst = Kernel::VectorHelper::splitStringIntoVector<double>(tmp); - ITableWorkspace_sptr table = WorkspaceFactory::Instance().createTable(); - - API::AnalysisDataService::Instance().addOrReplace("__norm__", table); - table->addColumn("double", "norm"); - table->addColumn("int", "spectra"); - for (double norm : normEst) { - API::TableRow row = table->appendRow(); + API::MatrixWorkspace_sptr unnorm = asym->getProperty("OutputUnNormWorkspace"); + MatrixWorkspace_sptr singleWS = extractSpectrum(unnorm, index); + ads.addOrReplace("tmp_unNorm", singleWS); - row << norm << index; - } + outWS = asym->getProperty("OutputWorkspace"); + } return outWS; } diff --git a/Framework/WorkflowAlgorithms/src/MuonGroupCalculator.cpp b/Framework/WorkflowAlgorithms/src/MuonGroupCalculator.cpp index 86aebd4e360..8c5b514d236 100644 --- a/Framework/WorkflowAlgorithms/src/MuonGroupCalculator.cpp +++ b/Framework/WorkflowAlgorithms/src/MuonGroupCalculator.cpp @@ -22,6 +22,8 @@ void MuonGroupCalculator::setStartEnd(const double start, const double end) { m_startX = start; m_endX = end; } - +void MuonGroupCalculator::setWSName(const std::string wsName) { + m_wsName = wsName; +} } // namespace WorkflowAlgorithms } // namespace Mantid diff --git a/Framework/WorkflowAlgorithms/src/MuonProcess.cpp b/Framework/WorkflowAlgorithms/src/MuonProcess.cpp index 95c46bfb79d..43eb20f37f1 100644 --- a/Framework/WorkflowAlgorithms/src/MuonProcess.cpp +++ b/Framework/WorkflowAlgorithms/src/MuonProcess.cpp @@ -118,6 +118,8 @@ void MuonProcess::init() { declareProperty("CropWorkspace", true, "Determines if the input workspace should be cropped"); + + declareProperty("WorkspaceName", "", "The name of the input workspace"); } //---------------------------------------------------------------------------------------------- @@ -185,7 +187,7 @@ void MuonProcess::exec() { } else if (outputType == "GroupAsymmetry") { asymCalc = Mantid::Kernel::make_unique<MuonGroupAsymmetryCalculator>( allPeriodsWS, summedPeriods, subtractedPeriods, groupIndex, - getProperty("Xmin"), getProperty("Xmax")); + getProperty("Xmin"), getProperty("Xmax"),getProperty("WorkspaceName")); } else if (outputType == "PairAsymmetry") { int first = getProperty("PairFirstIndex"); int second = getProperty("PairSecondIndex"); diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp index 58b8f1ca4f3..40e50da66bb 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.cpp +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.cpp @@ -449,20 +449,28 @@ std::string MuonAnalysis::addItem(ItemType itemType, int tableRow, PlotType plotType) { AnalysisDataServiceImpl &ads = AnalysisDataService::Instance(); - // Create workspace and a raw (unbinned) version of it - auto ws = createAnalysisWorkspace(itemType, tableRow, plotType); - auto wsRaw = createAnalysisWorkspace(itemType, tableRow, plotType, true); - // Find names for new workspaces const std::string wsName = getNewAnalysisWSName(itemType, tableRow, plotType); const std::string wsRawName = wsName + "_Raw"; + const std::string unnorm = "_unNorm"; + std::vector<std::string> wsNames = { wsName, wsRawName }; + // Create workspace and a raw (unbinned) version of it + auto ws = createAnalysisWorkspace(itemType, tableRow, plotType,wsName); + if (ads.doesExist("tmp_unNorm")) { + ads.rename("tmp_unNorm", wsName + unnorm); + wsNames.push_back(wsName+unnorm); + } + auto wsRaw = createAnalysisWorkspace(itemType, tableRow, plotType, wsRawName,true); + if (ads.doesExist("tmp_unNorm")) { + ads.rename("tmp_unNorm", wsRawName + unnorm); + wsNames.push_back(wsRawName+unnorm); + + } // Make sure they end up in the ADS ads.addOrReplace(wsName, ws); ads.addOrReplace(wsRawName, wsRaw); - // Make sure they are grouped - std::vector<std::string> wsNames = {wsName, wsRawName}; MuonAnalysisHelper::groupWorkspaces(m_currentLabel, wsNames); return wsName; } @@ -563,12 +571,13 @@ MuonAnalysis::parsePlotType(QComboBox *selector) { * @param tableRow :: Row in the group/pair table which contains the item * @param plotType :: What kind of plot we want to analyse * @param isRaw :: Whether binning should be applied to the workspace + * @param wsName :: The name of the workspace -> for saving the normalisation * @return Created workspace */ Workspace_sptr MuonAnalysis::createAnalysisWorkspace(ItemType itemType, int tableRow, PlotType plotType, - bool isRaw) { + std::string wsName, bool isRaw) { auto loadedWS = AnalysisDataService::Instance().retrieveWS<Workspace>(m_grouped_name); Muon::AnalysisOptions options(m_groupingHelper.parseGroupingTable()); @@ -580,7 +589,7 @@ Workspace_sptr MuonAnalysis::createAnalysisWorkspace(ItemType itemType, options.timeLimits.second = finishTime(); options.rebinArgs = isRaw ? "" : rebinParams(loadedWS); options.plotType = plotType; - + options.wsName = wsName; const auto *table = itemType == ItemType::Group ? m_uiForm.groupTable : m_uiForm.pairTable; options.groupPairName = table->item(tableRow, 0)->text().toStdString(); @@ -1900,7 +1909,6 @@ void MuonAnalysis::plotSpectrum(const QString &wsName, bool logScale) { } runPythonCode(pyS); - m_fitDataPresenter->storeNormalization(safeWSName.toStdString(), addToTable); } /** @@ -3074,7 +3082,6 @@ MuonAnalysis::groupWorkspace(const std::string &wsName, groupAlg->setProperty("xmax", m_dataSelector->getEndTime()); groupAlg->execute(); bool addToTable = getIfTFAsymmStore(); - m_fitDataPresenter->storeNormalization(wsName, addToTable); } catch (std::exception &e) { throw std::runtime_error("Unable to group workspace:\n\n" + diff --git a/qt/scientific_interfaces/Muon/MuonAnalysis.h b/qt/scientific_interfaces/Muon/MuonAnalysis.h index 476474da8fa..268a17a74ce 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysis.h +++ b/qt/scientific_interfaces/Muon/MuonAnalysis.h @@ -300,7 +300,7 @@ private: /// Creates workspace ready for analysis and plotting Mantid::API::Workspace_sptr createAnalysisWorkspace(Muon::ItemType itemType, int tableRow, - Muon::PlotType plotType, + Muon::PlotType plotType, std::string wsName, bool isRaw = false); /// Returns PlotType as chosen using given selector diff --git a/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.cpp b/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.cpp index 901ef458d72..2388d2e7849 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.cpp +++ b/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.cpp @@ -388,7 +388,9 @@ void MuonAnalysisDataLoader::setProcessAlgorithmProperties( if (!options.rebinArgs.empty()) { alg->setProperty("RebinParams", options.rebinArgs); } - + if (options.wsName != "") { + alg->setProperty("WorkspaceName", options.wsName); + } // ---- Analysis ---- // Find index of a name in a collection diff --git a/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.h b/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.h index 415c5ba0050..6dcd8c13158 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.h +++ b/qt/scientific_interfaces/Muon/MuonAnalysisDataLoader.h @@ -40,6 +40,7 @@ struct AnalysisOptions { std::string groupPairName; /// Name of group or pair to use const Mantid::API::Grouping grouping; /// Grouping to use PlotType plotType = {}; /// Type of analysis to perform + std::string wsName = ""; /// Name of the ws explicit AnalysisOptions(const Mantid::API::Grouping &g) : grouping(g) {} }; } // namespace Muon diff --git a/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.cpp b/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.cpp index 866782134b5..f2bb87a072d 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.cpp +++ b/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.cpp @@ -235,6 +235,11 @@ void MuonAnalysisFitDataPresenter::createWorkspacesToFit( AnalysisDataService::Instance().add(name, ws); if (!groupLabel.empty()) { MuonAnalysisHelper::groupWorkspaces(groupLabel, {name}); + if(Mantid::API::AnalysisDataService::Instance().doesExist("tmp_unNorm")) { + const std::string unnorm = "_unNorm"; + Mantid::API::AnalysisDataService::Instance().rename("tmp_unNorm", name + unnorm); + MuonAnalysisHelper::groupWorkspaces(groupLabel, { name+unnorm }); + } } } } @@ -381,60 +386,7 @@ std::vector<std::string> MuonAnalysisFitDataPresenter::generateWorkspaceNames( return workspaceNames; } -/** -* Stores the normalization into the table WS -* If the workspace is already in the table -* do nothing. -* @param name :: the name of the workspace to add. -* @param addToTable :: if to add the normalization data -* to the MuonAnalysisTFNormalizations table -*/ -void MuonAnalysisFitDataPresenter::storeNormalization(std::string name, - bool addToTable) const { - if (addToTable) { - if (!Mantid::API::AnalysisDataService::Instance().doesExist( - "MuonAnalysisTFNormalizations")) { - Mantid::API::ITableWorkspace_sptr table = - Mantid::API::WorkspaceFactory::Instance().createTable(); - AnalysisDataService::Instance().addOrReplace( - "MuonAnalysisTFNormalizations", table); - table->addColumn("double", "norm"); - table->addColumn("str", "name"); - table->addColumn("str", "method"); - } - - Mantid::API::ITableWorkspace_sptr table = - boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve( - "MuonAnalysisTFNormalizations")); - auto colName = table->getColumn("name"); - if (table->rowCount() > 1) { - std::string tmp = name; - // stored with ; instead of spaces - std::replace(tmp.begin(), tmp.end(), ' ', ';'); - for (size_t j = 0; j < table->rowCount(); j++) { - if (colName->cell<std::string>(j) == tmp) { // already exists - return; - } - } - } - Mantid::API::TableRow row = table->appendRow(); - std::string tmp = name; - // spaces stop the string being written - std::replace(tmp.begin(), tmp.end(), ' ', ';'); - // get data - if (Mantid::API::AnalysisDataService::Instance().doesExist("__norm__")) { - Mantid::API::ITableWorkspace_sptr tmpNorm = - boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve( - "__norm__")); - auto colNorm = tmpNorm->getColumn("norm"); - // saves data - row << (*colNorm)[0] << tmp << "Estimate"; - } - } -} /** * Create an analysis workspace given the required name. * @param name :: [input] Name of workspace to create (in format INST0001234; @@ -494,6 +446,7 @@ MuonAnalysisFitDataPresenter::createWorkspace(const std::string &name, analysisOptions.timeLimits.second = m_dataSelector->getEndTime(); analysisOptions.groupPairName = params.itemName; analysisOptions.plotType = params.plotType; + analysisOptions.wsName = name; outputWS = m_dataLoader.createAnalysisWorkspace(correctedData, analysisOptions); @@ -502,13 +455,6 @@ MuonAnalysisFitDataPresenter::createWorkspace(const std::string &name, err << "Failed to create analysis workspace " << name << ": " << ex.what(); g_log.error(err.str()); } - const auto grouping = m_grouping; - auto groupName = params.itemName; - if (std::find(grouping.groupNames.begin(), grouping.groupNames.end(), - groupName) != grouping.groupNames.end()) { - - storeNormalization(name, true); - } return outputWS; } diff --git a/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.h b/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.h index 40a92514a7f..632f8eddc54 100644 --- a/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.h +++ b/qt/scientific_interfaces/Muon/MuonAnalysisFitDataPresenter.h @@ -121,7 +121,7 @@ public: void checkAndUpdateFitLabel(bool sequentialFit); /// Generate names of workspaces to be created std::vector<std::string> generateWorkspaceNames(bool overwrite) const; - void storeNormalization(std::string wsName, bool addToTable) const; + signals: void setChosenGroupSignal(const QString &group); void setChosenPeriodSignal(const QString &period); diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h index 2b5ae8e68a3..6056ac0fc19 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MuonFitPropertyBrowser.h @@ -157,7 +157,6 @@ signals: protected: void showEvent(QShowEvent *e) override; - double normalization() const; void setNormalization(); private slots: @@ -245,7 +244,6 @@ private: }; std::map<std::string, double> readMultipleNormalization(); -std::vector<double> readNormalization(); } // MantidQt } // API diff --git a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp index fc878331001..049f1f07db4 100644 --- a/qt/widgets/common/src/MuonFitPropertyBrowser.cpp +++ b/qt/widgets/common/src/MuonFitPropertyBrowser.cpp @@ -520,11 +520,7 @@ void MuonFitPropertyBrowser::doubleChanged(QtProperty *prop) { } } } -/** @returns the normalization -*/ -double MuonFitPropertyBrowser::normalization() const { - return readNormalization()[0]; -} + void MuonFitPropertyBrowser::setNormalization() { setNormalization(workspaceName()); } @@ -537,6 +533,9 @@ void MuonFitPropertyBrowser::setNormalization(const std::string name) { QString label; auto norms = readMultipleNormalization(); std::string tmp = name; + if (rawData()) { + tmp = tmp + "_Raw"; + } // stored with ; instead of spaces std::replace(tmp.begin(), tmp.end(), ' ', ';'); auto it = norms.find(tmp); @@ -564,7 +563,21 @@ void MuonFitPropertyBrowser::boolChanged(QtProperty *prop) { if (prop == m_keepNorm) { const bool val = m_boolManager->value(prop); if (val) { // record data for later - double norm = readNormalization()[0]; + double norm = 0.0; + int j = m_enumManager->value(m_workspace); + std::string name = m_workspaceNames[j].toStdString(); + + auto norms = readMultipleNormalization(); + std::string tmp = name; + if (rawData()) { + tmp = tmp + "_Raw"; + } + // stored with ; instead of spaces + std::replace(tmp.begin(), tmp.end(), ' ', ';'); + auto it = norms.find(tmp); + if (it != norms.end()) { + norm = it->second; + } ITableWorkspace_sptr table = WorkspaceFactory::Instance().createTable(); AnalysisDataService::Instance().addOrReplace("__keepNorm__", table); table->addColumn("double", "norm"); @@ -842,22 +855,7 @@ Mantid::API::IFunction_sptr MuonFitPropertyBrowser::getTFAsymmFitFunction( return boost::dynamic_pointer_cast<IFunction>(multi); } -std::vector<double> readNormalization() { - std::vector<double> norm; - if (!AnalysisDataService::Instance().doesExist("__norm__")) { - norm.push_back(22.423); - } else { - Mantid::API::ITableWorkspace_sptr table = - boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve("__norm__")); - auto colNorm = table->getColumn("norm"); - for (size_t j = 0; j < table->rowCount(); j++) { - norm.push_back((*colNorm)[j]); // record and update norm.... - } - } - return norm; -} /** Reads the normalization constants and which WS * they belong to * @returns :: A map of normalization constants and WS names -- GitLab