Mantid
Loading...
Searching...
No Matches
IMuonAsymmetryCalculator.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 +
7#include <utility>
8
10
17
19
20//----------------------------------------------------------------------------------------------
29 std::vector<int> subtractedPeriods)
30 : m_inputWS(std::move(inputWS)), m_summedPeriods(std::move(summedPeriods)),
31 m_subtractedPeriods(std::move(subtractedPeriods)) {}
32
38MatrixWorkspace_sptr IMuonAsymmetryCalculator::sumPeriods(const std::vector<int> &periodsToSum) const {
40 if (!periodsToSum.empty()) {
41 auto LHSWorkspace = m_inputWS->getItem(periodsToSum[0] - 1);
42 outWS = std::dynamic_pointer_cast<MatrixWorkspace>(LHSWorkspace);
43 if (outWS != nullptr && periodsToSum.size() > 1) {
44 auto numPeriods = static_cast<int>(periodsToSum.size());
45 for (int i = 1; i < numPeriods; i++) {
46 auto RHSWorkspace = m_inputWS->getItem(periodsToSum[i] - 1);
47 auto alg = AlgorithmManager::Instance().create("Plus");
48 alg->setChild(true);
49 alg->setProperty("LHSWorkspace", outWS);
50 alg->setProperty("RHSWorkspace", RHSWorkspace);
51 alg->setProperty("OutputWorkspace", "__NotUsed__");
52 alg->execute();
53 outWS = alg->getProperty("OutputWorkspace");
54 }
55 }
56 }
57 return outWS;
58}
59
67 const MatrixWorkspace_sptr &rhs) const {
69 if (lhs && rhs) {
70 auto alg = AlgorithmManager::Instance().create("Minus");
71 alg->setChild(true);
72 alg->setProperty("LHSWorkspace", lhs);
73 alg->setProperty("RHSWorkspace", rhs);
74 alg->setProperty("OutputWorkspace", "__NotUsed__");
75 alg->execute();
76 outWS = alg->getProperty("OutputWorkspace");
77 }
78 return outWS;
79}
80
89 if (inputWS) {
90 auto alg = AlgorithmManager::Instance().create("ExtractSingleSpectrum");
91 alg->setChild(true);
92 alg->setProperty("InputWorkspace", inputWS);
93 alg->setProperty("WorkspaceIndex", index);
94 alg->setProperty("OutputWorkspace", "__NotUsed__");
95 alg->execute();
96 outWS = alg->getProperty("OutputWorkspace");
97 }
98 return outWS;
99}
100
101} // namespace Mantid::WorkflowAlgorithms
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Base MatrixWorkspace Abstract Class.
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...
IMuonAsymmetryCalculator(API::WorkspaceGroup_sptr inputWS, std::vector< int > summedPeriods, std::vector< int > subtractedPeriods)
Constructor.
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.
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.
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< 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
STL namespace.