Mantid
Loading...
Searching...
No Matches
MuonPairAsymmetryCalculator.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 +
8
13
15
16//----------------------------------------------------------------------------------------------
29 const std::vector<int> &summedPeriods,
30 const std::vector<int> &subtractedPeriods,
31 const int firstPairIndex, const int secondPairIndex,
32 const double alpha)
33 : IMuonAsymmetryCalculator(inputWS, summedPeriods, subtractedPeriods), m_alpha(alpha),
34 m_firstPairIndex(firstPairIndex), m_secondPairIndex(secondPairIndex) {}
35
43
44 int numPeriods = m_inputWS->getNumberOfEntries();
45 if (numPeriods > 1) {
46
47 auto summedWS = sumPeriods(m_summedPeriods);
48 auto subtractedWS = sumPeriods(m_subtractedPeriods);
49
50 // Summed periods asymmetry
51 MatrixWorkspace_sptr asymSummedPeriods = asymmetryCalc(summedWS);
52
53 if (!m_subtractedPeriods.empty()) {
54 // Subtracted periods asymmetry
55 MatrixWorkspace_sptr asymSubtractedPeriods = asymmetryCalc(subtractedWS);
56 // Now subtract
57 outWS = subtractWorkspaces(asymSummedPeriods, asymSubtractedPeriods);
58 } else {
59 outWS = asymSummedPeriods;
60 }
61
62 } else {
63 outWS = asymmetryCalc(m_inputWS->getItem(0));
64 }
65
66 return outWS;
67}
68
76
77 if (inputWS) {
78 // Pair indices as vectors
79 std::vector<int> fwd(1, m_firstPairIndex + 1);
80 std::vector<int> bwd(1, m_secondPairIndex + 1);
81
82 auto alg = AlgorithmManager::Instance().create("AsymmetryCalc");
83 alg->setChild(true);
84 alg->setProperty("InputWorkspace", inputWS);
85 alg->setProperty("ForwardSpectra", fwd);
86 alg->setProperty("BackwardSpectra", bwd);
87 alg->setProperty("Alpha", m_alpha);
88 alg->setProperty("OutputWorkspace", "__NotUsed__");
89 alg->execute();
90 outWS = alg->getProperty("OutputWorkspace");
91 }
92
93 return outWS;
94}
95
96} // namespace Mantid::WorkflowAlgorithms
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 : Abstract base class for muon asymmetry calculations.
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.
const std::vector< int > m_summedPeriods
List of summed periods.
MuonPairAsymmetryCalculator(const API::WorkspaceGroup_sptr &inputWS, const std::vector< int > &summedPeriods, const std::vector< int > &subtractedPeriods, const int firstPairIndex, const int secondPairIndex, const double alpha=1)
Constructor.
API::MatrixWorkspace_sptr calculate() const override
Performs pair asymmetry calculation.
API::MatrixWorkspace_sptr asymmetryCalc(const API::Workspace_sptr &inputWS) const
Calculate asymmetry for the given workspace.
const int m_secondPairIndex
Workspace index of the second group of the pair.
const int m_firstPairIndex
Workspace index of the first group of the pair.
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