diff --git a/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp b/Framework/Algorithms/src/EstimateMuonAsymmetryFromCounts.cpp index 3d1ce388e9d173d8470a5b2882edb65576774807..1fcb675423baea5676f912413efca743d21c0dac 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 48bee1ae43a15ba95337b3c7c0215d1a60edbb9b..d701dcef835a2940da99f0e083fd5082ade73b41 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 0e3925d5aad1b95deeacece79dd352fc7635f6ba..7a75523c1250d9ae5c9b38221e4804c51be0d849 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 02468d42e37f6e792fd76bba35a576286cdf63b0..7a038d0763688bfdee6dafca8c91679dfac8e864 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 282332664c9dd2b161ec3932118d3bd819fde91e..3961758346244339bdd2aebc7a63afe879500684 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 86aebd4e36084330a84052f97f67be36aaf64a3d..8c5b514d236bdac4f5627930ac12c608ea0ea4f0 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 95c46bfb79da26a6d6c6f620a7f112332a86d21a..43eb20f37f1305c5c6a36219f2bc41a536b44448 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 58b8f1ca4f34a51fa581b4f51ab11a831447a975..40e50da66bb08296fabf603235f9123e9d926d83 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 476474da8fa7f9e971f025a5b232538868da5a07..268a17a74cef9090e026d0f9c1e393b8ddaf74f4 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 901ef458d728eacecff1c392b15ec43cefd2e924..2388d2e7849c6e1e643a07ee4edb6aff78b2fddf 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 415c5ba0050a50d71b87b4b6b03c36702183cce2..6dcd8c131584f75a813b92e1b8eceedbcab87d4a 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 866782134b55540c8a9942f3a34d8e18b4de9409..f2bb87a072d843bb3474740c58a334ed23481e52 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 40a92514a7f32844003d396092adcfda1829e031..632f8eddc54bdf6563e04195b071eac94ede8e4b 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 2b5ae8e68a39e245ba2143522827b9b0045a4785..6056ac0fc1992a5cc5142e41cf06025b66708beb 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 fc87833100107b096e7e224bd8c595ba8fd42750..049f1f07db47fba524497971e4997e2ac8890e31 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