Mantid
Loading...
Searching...
No Matches
CreatePolarizationEfficiencies.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 +
16#include "MantidKernel/Unit.h"
17
18#include <memory>
19
20#include <algorithm>
21
22using namespace Mantid::API;
23using namespace Mantid::Kernel;
24using namespace Mantid::Geometry;
25
26namespace {
27
28double calculatePolynomial(std::vector<double> const &coefficients, double x) {
29 double polynomial = coefficients[0];
30 double xPow = 1.0;
31 // Build up the polynomial in ascending powers of x
32 for (size_t i = 1; i < coefficients.size(); ++i) {
33 xPow *= x;
34 polynomial += coefficients[i] * xPow;
35 }
36 return polynomial;
37}
38
39} // namespace
40
41namespace Mantid::DataHandling {
42
44
45const std::string CreatePolarizationEfficiencies::name() const { return "CreatePolarizationEfficiencies"; }
46
48
49const std::string CreatePolarizationEfficiencies::summary() const {
50 return "Converts polynomial factors to histograms with polarization "
51 "efficiencies.";
52}
53
54const std::vector<std::string> CreatePolarizationEfficiencies::seeAlso() const {
55 return {"JoinISISPolarizationEfficiencies", "LoadISISPolarizationEfficiencies", "PolarizationEfficiencyCor"};
56}
57
60 std::make_unique<WorkspaceProperty<Mantid::API::MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
61 "An input workspace to use the x-values from.");
62
64 "Effective polarizing power of the polarizing system. "
65 "Expressed as a ratio 0 < Pp < 1");
66
68 "Effective polarizing power of the analyzing system. "
69 "Expressed as a ratio 0 < Ap < 1");
70
72 "Ratio of efficiencies of polarizer spin-down to polarizer "
73 "spin-up. This is characteristic of the polarizer flipper. "
74 "Values are constants for each term in a polynomial "
75 "expression.");
76
78 "Ratio of efficiencies of analyzer spin-down to analyzer "
79 "spin-up. This is characteristic of the analyzer flipper. "
80 "Values are factors for each term in a polynomial "
81 "expression.");
82
83 declareProperty(std::make_unique<ArrayProperty<double>>(P1, Direction::Input), "Polarizer efficiency.");
84
85 declareProperty(std::make_unique<ArrayProperty<double>>(P2, Direction::Input), "Analyzer efficiency.");
86
87 declareProperty(std::make_unique<ArrayProperty<double>>(F1, Direction::Input), "Polarizer flipper efficiency.");
88
89 declareProperty(std::make_unique<ArrayProperty<double>>(F2, Direction::Input), "Analyzer flipper efficiency.");
90
92}
93
98
99 std::vector<std::vector<double>> polynomialCoefficients;
100
101 for (auto const &label : labels) {
102 polynomialCoefficients.emplace_back<std::vector<double>>(getProperty(label));
103 }
104
105 MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
106 auto sharedInX = inWS->sharedX(0);
107
109 WorkspaceFactory::Instance().create(inWS, labels.size(), sharedInX->size(), inWS->blocksize());
110 auto axis1 = std::make_unique<TextAxis>(labels.size());
111 auto axis1Raw = axis1.get();
112 outWS->replaceAxis(1, std::move(axis1));
113 outWS->getAxis(0)->setUnit(inWS->getAxis(0)->unit()->unitID());
114
115 auto const x = inWS->points(0);
116 std::vector<double> y(x.size());
117 for (size_t i = 0; i < labels.size(); ++i) {
118 outWS->setSharedX(i, sharedInX);
119 auto const &coefficients = polynomialCoefficients[i];
120 std::transform(x.begin(), x.end(), y.begin(),
121 [&coefficients](double v) { return calculatePolynomial(coefficients, v); });
122 outWS->mutableY(i) = y;
123 axis1Raw->setLabel(i, labels[i]);
124 }
125
126 return outWS;
127}
128
129} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
static std::string const Pp
Names of the efficiency properties.
int version() const override
function to return a version of the algorithm, must be overridden in all algorithms
void init() override
Virtual method - must be overridden by concrete algorithm.
API::MatrixWorkspace_sptr createEfficiencies(std::vector< std::string > const &labels) override
Create the efficiencies workspace given names of input properties.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
const std::string summary() const override
function returns a summary message that will be displayed in the default GUI, and in the help.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
STL namespace.
@ Input
An input workspace.
Definition: Property.h:53