Skip to content
Snippets Groups Projects
Commit a4ccef94 authored by T Jubb's avatar T Jubb
Browse files

Refs #23642 Add files.

parent 718000e6
No related branches found
No related tags found
No related merge requests found
...@@ -117,6 +117,22 @@ DLLExport bool checkValidPair(const std::string &name1, ...@@ -117,6 +117,22 @@ DLLExport bool checkValidPair(const std::string &name1,
/// Check whether a group or pair name is valid /// Check whether a group or pair name is valid
DLLExport bool checkValidGroupPairName(const std::string &name); DLLExport bool checkValidGroupPairName(const std::string &name);
DLLExport Mantid::API::MatrixWorkspace_sptr
sumPeriods(const Mantid::API::WorkspaceGroup_sptr &inputWS,
const std::vector<int> &periodsToSum);
DLLExport Mantid::API::MatrixWorkspace_sptr
subtractWorkspaces(const Mantid::API::MatrixWorkspace_sptr &lhs,
const Mantid::API::MatrixWorkspace_sptr &rhs);
DLLExport Mantid::API::MatrixWorkspace_sptr
extractSpectrum(const Mantid::API::Workspace_sptr &inputWS, const int index);
DLLExport void addSampleLog(Mantid::API::MatrixWorkspace_sptr workspace,
const std::string &logName,
const std::string &logValue);
// //
///// Saves grouping to the XML file specified ///// Saves grouping to the XML file specified
// DLLExport std::string groupingToXML(const Mantid::API::Grouping &grouping); // DLLExport std::string groupingToXML(const Mantid::API::Grouping &grouping);
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include "MantidAPI/Run.h" #include "MantidAPI/Run.h"
#include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/Workspace_fwd.h" #include "MantidAPI/Workspace_fwd.h"
#include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/PhysicalConstants.h" #include "MantidKernel/PhysicalConstants.h"
#include "MantidMuon/MuonAlgorithmHelper.h"
#include <cmath> #include <cmath>
#include <numeric> #include <numeric>
...@@ -68,7 +68,8 @@ void EstimateMuonAsymmetryFromCounts::init() { ...@@ -68,7 +68,8 @@ void EstimateMuonAsymmetryFromCounts::init() {
declareProperty( declareProperty(
make_unique<API::WorkspaceProperty<API::ITableWorkspace>>( make_unique<API::WorkspaceProperty<API::ITableWorkspace>>(
"NormalizationTable", "", Direction::InOut), "NormalizationTable", "", Direction::InOut,
API::PropertyMode::Optional),
"Name of the table containing the normalizations for the asymmetries."); "Name of the table containing the normalizations for the asymmetries.");
} }
...@@ -207,11 +208,21 @@ void EstimateMuonAsymmetryFromCounts::exec() { ...@@ -207,11 +208,21 @@ void EstimateMuonAsymmetryFromCounts::exec() {
} }
// update table // update table
Mantid::API::ITableWorkspace_sptr table = getProperty("NormalizationTable"); Mantid::API::ITableWorkspace_sptr table = getProperty("NormalizationTable");
updateNormalizationTable(table, wsNames, norm, methods); if (table) {
setProperty("NormalizationTable", table); updateNormalizationTable(table, wsNames, norm, methods);
setProperty("NormalizationTable", table);
}
// Update Y axis units // Update Y axis units
outputWS->setYUnit("Asymmetry"); outputWS->setYUnit("Asymmetry");
std::string normString =
std::accumulate(norm.begin() + 1, norm.end(), std::to_string(norm[0]),
[](const std::string &a, double b) {
return a + ',' + std::to_string(b);
});
MuonAlgorithmHelper::addSampleLog(outputWS, "analysis_asymmetry_norm",
normString);
setProperty("OutputWorkspace", outputWS); setProperty("OutputWorkspace", outputWS);
} }
} // namespace Algorithms } // namespace Algorithms
......
...@@ -516,5 +516,87 @@ bool checkValidGroupPairName(const std::string &name) { ...@@ -516,5 +516,87 @@ bool checkValidGroupPairName(const std::string &name) {
return true; return true;
} }
/**
* Sums the specified periods of the input workspace group
* @param periodsToSum :: [input] List of period indexes (1-based) to be summed
* @returns Workspace containing the sum
*/
MatrixWorkspace_sptr sumPeriods(const WorkspaceGroup_sptr &inputWS,
const std::vector<int> &periodsToSum) {
MatrixWorkspace_sptr outWS;
if (!periodsToSum.empty()) {
auto LHSWorkspace = inputWS->getItem(periodsToSum[0] - 1);
outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(LHSWorkspace);
if (outWS != nullptr && periodsToSum.size() > 1) {
int numPeriods = static_cast<int>(periodsToSum.size());
for (int i = 1; i < numPeriods; i++) {
auto RHSWorkspace = inputWS->getItem(periodsToSum[i] - 1);
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("Plus");
alg->setChild(true);
alg->setProperty("LHSWorkspace", outWS);
alg->setProperty("RHSWorkspace", RHSWorkspace);
alg->setProperty("OutputWorkspace", "__NotUsed__");
alg->execute();
outWS = alg->getProperty("OutputWorkspace");
}
}
}
return outWS;
}
/**
* Subtracts one workspace from another: lhs - rhs.
* @param lhs :: [input] Workspace on LHS of subtraction
* @param rhs :: [input] Workspace on RHS of subtraction
* @returns Result of the subtraction
*/
MatrixWorkspace_sptr subtractWorkspaces(const MatrixWorkspace_sptr &lhs,
const MatrixWorkspace_sptr &rhs) {
MatrixWorkspace_sptr outWS;
if (lhs && rhs) {
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("Minus");
alg->setChild(true);
alg->setProperty("LHSWorkspace", lhs);
alg->setProperty("RHSWorkspace", rhs);
alg->setProperty("OutputWorkspace", "__NotUsed__");
alg->execute();
outWS = alg->getProperty("OutputWorkspace");
}
return outWS;
}
/**
* Extracts a single spectrum from the given workspace.
* @param inputWS :: [input] Workspace to extract spectrum from
* @param index :: [input] Index of spectrum to extract
* @returns Result of the extraction
*/
MatrixWorkspace_sptr extractSpectrum(const Workspace_sptr &inputWS,
const int index) {
MatrixWorkspace_sptr outWS;
if (inputWS) {
IAlgorithm_sptr alg =
AlgorithmManager::Instance().create("ExtractSingleSpectrum");
alg->setChild(true);
alg->setProperty("InputWorkspace", inputWS);
alg->setProperty("WorkspaceIndex", index);
alg->setProperty("OutputWorkspace", "__NotUsed__");
alg->execute();
outWS = alg->getProperty("OutputWorkspace");
}
return outWS;
}
void addSampleLog(MatrixWorkspace_sptr workspace, const std::string& logName, const std::string& logValue) {
IAlgorithm_sptr alg = AlgorithmManager::Instance().create("AddSampleLog");
alg->setChild(true);
alg->setProperty("Workspace", workspace);
alg->setProperty("LogName", logName);
alg->setProperty("LogText", logValue);
alg->execute();
}
} // namespace MuonAlgorithmHelper } // namespace MuonAlgorithmHelper
} // namespace Mantid } // namespace Mantid
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment