Mantid
Loading...
Searching...
No Matches
MuonGroupAsymmetryCalculator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include "MantidAPI/TableRow.h"
13
20
22
23//----------------------------------------------------------------------------------------------
35 const std::vector<int> &summedPeriods,
36 const std::vector<int> &subtractedPeriods,
37 const int groupIndex, const double start, const double end,
38 const std::string &wsName)
39 : MuonGroupCalculator(inputWS, summedPeriods, subtractedPeriods, groupIndex) {
42}
43
50 // The output workspace
51
53 int numPeriods = m_inputWS->getNumberOfEntries();
54 if (numPeriods > 1) {
55 // Several period workspaces were supplied
56
57 auto summedWS = sumPeriods(m_summedPeriods);
58 auto subtractedWS = sumPeriods(m_subtractedPeriods);
59
60 // Remove decay (summed periods ws)
61 MatrixWorkspace_sptr asymSummedPeriods = estimateAsymmetry(summedWS, m_groupIndex);
62
63 if (!m_subtractedPeriods.empty()) {
64 // Remove decay (subtracted periods ws)
65 MatrixWorkspace_sptr asymSubtractedPeriods = estimateAsymmetry(subtractedWS, m_groupIndex);
66
67 // Now subtract
68 tempWS = subtractWorkspaces(asymSummedPeriods, asymSubtractedPeriods);
69 } else {
70 tempWS = asymSummedPeriods;
71 }
72 } else {
73 // Only one period was supplied
74 tempWS = estimateAsymmetry(m_inputWS->getItem(0),
75 m_groupIndex); // change -1 to m_groupIndex and
76 // follow through to store as a
77 // table for later.
78 }
79
80 // Extract the requested spectrum
82 return outWS;
83}
84
93 const int index) const {
95 // Remove decay
96 if (inputWS) {
97 auto asym = AlgorithmManager::Instance().create("RemoveExpDecay");
98 asym->setChild(true);
99 asym->setProperty("InputWorkspace", inputWS);
100 if (index > 0) {
101 // GroupIndex as vector
102 // Necessary if we want RemoveExpDecay to fit only the requested
103 // spectrum
104 std::vector<int> spec(1, index);
105 asym->setProperty("Spectra", spec);
106 }
107 asym->setProperty("OutputWorkspace", "__NotUsed__");
108 asym->execute();
109 outWS = asym->getProperty("OutputWorkspace");
110 }
111 return outWS;
112}
121 const int index) const {
122 const std::string normTableName = "MuonAnalysisTFNormalizations";
124 if (!ads.doesExist(normTableName)) {
126 Mantid::API::AnalysisDataService::Instance().addOrReplace(normTableName, table);
127 table->addColumn("double", "norm");
128 table->addColumn("str", "name");
129 table->addColumn("str", "method");
130 }
131
133 // calculate asymmetry
134 if (inputWS) {
135 auto asym = AlgorithmManager::Instance().create("EstimateMuonAsymmetryFromCounts");
136 asym->setChild(true);
137
138 asym->setProperty("InputWorkspace", inputWS);
139 asym->setProperty("WorkspaceName", m_wsName);
140 if (index > -1) {
141 std::vector<int> spec(1, index);
142 asym->setProperty("Spectra", spec);
143 }
144 asym->setProperty("OutputWorkspace", "__NotUsed__");
145 asym->setProperty("StartX", m_startX);
146 asym->setProperty("EndX", m_endX);
147 asym->setProperty("NormalizationIn", getStoredNorm());
148 asym->setProperty("OutputUnNormData", true);
149 asym->setProperty("OutputUnNormWorkspace", "tmp_unNorm");
150 asym->setProperty("NormalizationTable", normTableName);
151 asym->execute();
152
153 API::MatrixWorkspace_sptr unnorm = asym->getProperty("OutputUnNormWorkspace");
154 MatrixWorkspace_sptr singleWS = extractSpectrum(unnorm, index);
155 ads.addOrReplace("tmp_unNorm", singleWS);
156
157 outWS = asym->getProperty("OutputWorkspace");
158 }
159 return outWS;
160}
161/*
162 * Reads in the stored normalization
163 * if >0 then it is used instead of
164 * estimating the norm.
165 */
167 if (!API::AnalysisDataService::Instance().doesExist("__keepNorm__")) {
168 return 0.0;
169 } else {
171 std::dynamic_pointer_cast<API::ITableWorkspace>(API::AnalysisDataService::Instance().retrieve("__keepNorm__"));
172 auto colNorm = table->getColumn("norm");
173 return (*colNorm)[0];
174 }
175}
176
177} // namespace Mantid::WorkflowAlgorithms
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
void addOrReplace(const std::string &name, const std::shared_ptr< API::Workspace > &workspace) override
Overridden addOrReplace member to attach the name to the workspace when a workspace object is added t...
bool doesExist(const std::string &name) const
Check to see if a data object exists in the store.
Definition: DataService.h:370
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
API::MatrixWorkspace_sptr subtractWorkspaces(const API::MatrixWorkspace_sptr &lhs, const API::MatrixWorkspace_sptr &rhs) const
Subtracts one workspace from another (lhs - rhs)
const API::WorkspaceGroup_sptr m_inputWS
Input workspace.
const std::vector< int > m_subtractedPeriods
List of subtracted periods.
API::MatrixWorkspace_sptr sumPeriods(const std::vector< int > &periodsToSum) const
Sums the specified periods in the input workspace group.
API::MatrixWorkspace_sptr extractSpectrum(const API::Workspace_sptr &inputWS, const int index) const
Extracts a single spectrum from a workspace.
const std::vector< int > m_summedPeriods
List of summed periods.
API::MatrixWorkspace_sptr removeExpDecay(const API::Workspace_sptr &inputWS, const int index) const
Removes exponential decay from the workspace.
MuonGroupAsymmetryCalculator(const API::WorkspaceGroup_sptr &inputWS, const std::vector< int > &summedPeriods, const std::vector< int > &subtractedPeriods, const int groupIndex, const double start=0.0, const double end=30.0, const std::string &wsName="")
Constructor.
API::MatrixWorkspace_sptr calculate() const override
Performs group asymmetry calculation.
API::MatrixWorkspace_sptr estimateAsymmetry(const API::Workspace_sptr &inputWS, const int index) const
Estimate the asymmetrey for the given workspace (TF data).
MuonGroupCalculator : Base class for Muon group counts/asymmetry calculators.
const int m_groupIndex
Workspace index of the group to analyse.
void setStartEnd(const double start, const double end)
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class