Skip to content
Snippets Groups Projects
Commit d0f280b0 authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Updated nameing and added NormalizationIn Re #23642

Child algorithms are added to seeAlso of MuonGroupingAsymmetry
is_alnum_method moved to MuonAlgorithmHelper
NormalizationIn added as property to MuonGroupingAsymmetry
calculateMuonAsymmetry renamed to estimateMuonAsymmetry
Docs updated for clarity
parent 128d9bc7
No related branches found
No related tags found
No related merge requests found
......@@ -139,6 +139,8 @@ DLLExport void addSampleLog(Mantid::API::MatrixWorkspace_sptr workspace,
const std::string &logName,
const std::string &logValue);
DLLExport bool is_alphanumerical_or_underscore(char character);
//
///// Saves grouping to the XML file specified
// DLLExport std::string groupingToXML(const Mantid::API::Grouping &grouping);
......
......@@ -29,7 +29,7 @@ public:
"grouping in Muon data.";
}
const std::vector<std::string> seeAlso() const override {
return {"MuonProcess"};
return {"MuonProcess", "EstimateMuonAsymmetryFromCounts", "Minus", "Plus"};
}
private:
......
......@@ -607,5 +607,9 @@ void addSampleLog(MatrixWorkspace_sptr workspace, const std::string &logName,
alg->execute();
}
bool is_alphanumerical_or_underscore(char character) {
return (isalpha(character) || isdigit(character) || (character == '_'));
}
} // namespace MuonAlgorithmHelper
} // namespace Mantid
......@@ -24,10 +24,6 @@ using namespace Mantid::Kernel;
namespace {
bool is_alnum_underscore(char c) {
return (isalpha(c) || isdigit(c) || (c == '_'));
}
bool checkPeriodInWorkspaceGroup(const int &period,
WorkspaceGroup_sptr workspace) {
return period <= workspace->getNumberOfEntries();
......@@ -42,7 +38,7 @@ bool checkPeriodInWorkspaceGroup(const int &period,
*/
MatrixWorkspace_sptr estimateAsymmetry(const Workspace_sptr &inputWS,
const int index, const double startX,
const double endX) {
const double endX, const double normalizationIn) {
IAlgorithm_sptr asym =
AlgorithmManager::Instance().create("EstimateMuonAsymmetryFromCounts");
asym->setChild(true);
......@@ -55,7 +51,7 @@ MatrixWorkspace_sptr estimateAsymmetry(const Workspace_sptr &inputWS,
asym->setProperty("OutputWorkspace", "__NotUsed__");
asym->setProperty("StartX", startX);
asym->setProperty("EndX", endX);
asym->setProperty("NormalizationIn", 0.0);
asym->setProperty("NormalizationIn", normalizationIn);
asym->setProperty("OutputUnNormData", false);
asym->setProperty("OutputUnNormWorkspace", "tmp_unNorm");
asym->execute();
......@@ -65,10 +61,11 @@ MatrixWorkspace_sptr estimateAsymmetry(const Workspace_sptr &inputWS,
}
Mantid::API::MatrixWorkspace_sptr
calculateMuonAsymmetry(WorkspaceGroup_sptr inputWS,
estimateMuonAsymmetry(WorkspaceGroup_sptr inputWS,
const std::vector<int> &summedPeriods,
const std::vector<int> &subtractedPeriods,
int groupIndex, const double startX, const double endX) {
int groupIndex, const double startX,
const double endX, const double normalizationIn) {
MatrixWorkspace_sptr tempWS;
int numPeriods = inputWS->getNumberOfEntries();
if (numPeriods > 1) {
......@@ -80,12 +77,12 @@ calculateMuonAsymmetry(WorkspaceGroup_sptr inputWS,
// Remove decay (summed periods ws)
MatrixWorkspace_sptr asymSummedPeriods =
estimateAsymmetry(summedWS, groupIndex, startX, endX);
estimateAsymmetry(summedWS, groupIndex, startX, endX, normalizationIn);
if (!subtractedPeriods.empty()) {
// Remove decay (subtracted periods ws)
MatrixWorkspace_sptr asymSubtractedPeriods =
estimateAsymmetry(subtractedWS, groupIndex, startX, endX);
estimateAsymmetry(subtractedWS, groupIndex, startX, endX, normalizationIn);
// Now subtract
tempWS = Mantid::MuonAlgorithmHelper::subtractWorkspaces(
......@@ -96,7 +93,7 @@ calculateMuonAsymmetry(WorkspaceGroup_sptr inputWS,
} else {
// Only one period was supplied
tempWS = estimateAsymmetry(inputWS->getItem(0), groupIndex, startX,
endX); // change -1 to m_groupIndex and
endX, normalizationIn); // change -1 to m_groupIndex and
// follow through to store as a
// table for later.
}
......@@ -169,15 +166,19 @@ void MuonGroupingAsymmetry::init() {
"IDs or hyphenated ranges of IDs.");
declareProperty("AsymmetryTimeMin", 0.0,
"Start time for the asymmetry calculation (in micro "
"Start time for the asymmetry estimation (in micro "
"seconds). Defaults to the start time of the InputWorkspace.",
Direction::Input);
declareProperty("AsymmetryTimeMax", 32.0,
"End time for the asymmetry calculation (in micro seconds). "
"End time for the asymmetry estimation (in micro seconds). "
"Defaults to the end time of the InputWorkspace.",
Direction::Input);
declareProperty("NormalizationIn", 0.0,
"If this value is non-zero then this is used for the normalization, instead of being estimated.",
Direction::Input);
declareProperty(make_unique<ArrayProperty<int>>(
"SummedPeriods", defaultPeriods,
IValidator_sptr(new NullValidator), Direction::Input),
......@@ -208,7 +209,7 @@ std::map<std::string, std::string> MuonGroupingAsymmetry::validateInputs() {
}
if (!std::all_of(std::begin(groupName), std::end(groupName),
is_alnum_underscore)) {
Mantid::MuonAlgorithmHelper::is_alphanumerical_or_underscore)) {
errors["GroupName"] =
"The group name must contain alphnumeric characters and _ only.";
}
......@@ -285,14 +286,15 @@ void MuonGroupingAsymmetry::exec() {
const double startX = getProperty("AsymmetryTimeMin");
const double endX = getProperty("AsymmetryTimeMax");
const double normalizationIn = getProperty("NormalizationIn");
std::vector<int> summedPeriods = getProperty("SummedPeriods");
std::vector<int> subtractedPeriods = getProperty("SubtractedPeriods");
WorkspaceGroup_sptr groupedWS = createGroupWorkspace(inputWS);
outWS = calculateMuonAsymmetry(groupedWS, summedPeriods, subtractedPeriods, 0,
startX, endX);
outWS = estimateMuonAsymmetry(groupedWS, summedPeriods, subtractedPeriods, 0,
startX, endX, normalizationIn);
addGroupingAsymmetrySampleLogs(outWS);
setProperty("OutputWorkspace", outWS);
......
......@@ -336,6 +336,33 @@ public:
TS_ASSERT_DELTA(wsOut->readE(0)[0], 0.0002351, 0.00001);
TS_ASSERT_DELTA(wsOut->readE(0)[1], 0.0002460, 0.00001);
}
void
test_grouping_asymmetry_with_specified_normalization_gives_correct_values() {
auto ws = createMultiPeriodAsymmetryData(3, 2, 10, "group_asym");
std::vector<int> detectors = {1, 2};
auto alg =
setUpAlgorithmWithoutOptionalProperties(ws, "group_asym", detectors);
std::vector<int> summedPeriods = {3, 2};
std::vector<int> subtractedPeriods = {1};
alg->setProperty("SummedPeriods", summedPeriods);
alg->setProperty("SubtractedPeriods", subtractedPeriods);
alg->setProperty("NormalizationIn", 15.0);
alg->execute();
auto wsOut = getOutputWorkspace(alg);
TS_ASSERT_DELTA(wsOut->readX(0)[0], 0.000, 0.001);
TS_ASSERT_DELTA(wsOut->readX(0)[4], 0.400, 0.001);
TS_ASSERT_DELTA(wsOut->readX(0)[9], 0.900, 0.001);
TS_ASSERT_DELTA(wsOut->readY(0)[0], 1.39055, 0.001);
TS_ASSERT_DELTA(wsOut->readY(0)[1], 0.92922, 0.001);
TS_ASSERT_DELTA(wsOut->readE(0)[0], 0.0000577, 0.00001);
TS_ASSERT_DELTA(wsOut->readE(0)[1], 0.0000604, 0.00001);
}
};
#endif /* MANTID_MUON_MUONGROUPINGASYMMETRYTEST_H_ */
......@@ -27,7 +27,7 @@ The group must be given a name via **GroupName** which can consist of letters, n
The group name does not affect the data; however the name is used in the muon interface when automatically generating workspace names from group data.
After the grouping is performed, the analysis described in :ref:`algm-EstimateMuonAsymmetryFromCounts` will be run; effectively estimating the muon decay curve and subtracting it from the grouped data. The range over which the estimate is performed is controlled by the **AsymmetryTimeMin** and **AsymmetryTimeMax** inputs.
After the grouping is performed, the analysis described in :ref:`algm-EstimateMuonAsymmetryFromCounts` will be run; effectively estimating the muon decay curve and subtracting it from the grouped data and then estimating the asymmetry on the grouped data. The range over which the estimate is performed is controlled by the **AsymmetryTimeMin** and **AsymmetryTimeMax** inputs.
**Note** : The workspaces supplied to the algorithm must have a number of good frames set in their sample logs. The sample log is called "goodfrm" and can be set using;
......@@ -91,8 +91,8 @@ Output:
[40, 50, 60, 50, 40]
ws1 = CreateWorkspace(dataX, dataY_period1, NSpec=2)
ws2 = CreateWorkspace(dataX, dataY_period2, NSpec=2)
AddSampleLog(Workspace=ws1, LogName='goodfrm', LogText="10")
AddSampleLog(Workspace=ws2, LogName='goodfrm', LogText="10")
AddSampleLog(Workspace=ws1, LogName='goodfrm', LogText="1")
AddSampleLog(Workspace=ws2, LogName='goodfrm', LogText="1")
for i in range(2):
# set detector IDs to be 1,2,3,4
# these do not have to be the same as the spectrum numbers
......
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