13#include "MantidHistogramData/Histogram.h"
14#include "MantidHistogramData/Interpolate.h"
15#include "MantidHistogramData/LinearGenerator.h"
39 return "Joins workspaces containing ISIS reflectometry polarization "
40 "efficiency factors into a single workspace ready to be used with "
41 "PolarizationEfficiencyCor.";
45 return {
"CreatePolarizationEfficiencies",
"LoadISISPolarizationEfficiencies",
"PolarizationEfficiencyCor"};
55 "A matrix workspaces containing the Pp polarization efficiency.");
59 "A matrix workspaces containing the Ap polarization efficiency.");
63 "A matrix workspaces containing the Rho polarization efficiency.");
67 "A matrix workspaces containing the Alpha polarization efficiency.");
71 "A matrix workspaces containing the P1 polarization efficiency.");
75 "A matrix workspaces containing the P2 polarization efficiency.");
79 "A matrix workspaces containing the F1 polarization efficiency.");
83 "A matrix workspaces containing the F2 polarization efficiency.");
91 std::vector<MatrixWorkspace_sptr> workspaces;
92 for (
auto const &propName : props) {
94 if (ws->getNumberHistograms() != 1) {
95 throw std::runtime_error(
"Loaded workspace must contain a single histogram. Found " +
98 workspaces.emplace_back(ws);
110 std::vector<MatrixWorkspace_sptr>
const &workspaces) {
113 auto const &inWS = interpolatedWorkspaces.front();
114 MatrixWorkspace_sptr outWS = DataObjects::create<Workspace2D>(*inWS, labels.size(), inWS->histogram(0));
115 auto axis1 = std::make_unique<TextAxis>(labels.size());
116 auto axis1Raw = axis1.get();
117 outWS->replaceAxis(1, std::move(axis1));
118 outWS->getAxis(0)->setUnit(
"Wavelength");
120 for (
size_t i = 0; i < interpolatedWorkspaces.size(); ++i) {
121 auto &ws = interpolatedWorkspaces[i];
122 outWS->setHistogram(i, ws->histogram(0));
123 axis1Raw->setLabel(i, labels[i]);
132std::vector<MatrixWorkspace_sptr>
134 size_t minSize(std::numeric_limits<size_t>::max());
136 bool thereAreHistograms =
false;
137 bool allAreHistograms =
true;
140 for (
auto const &ws : workspaces) {
141 auto size = ws->blocksize();
142 if (size < minSize) {
145 if (size > maxSize) {
148 thereAreHistograms = thereAreHistograms || ws->isHistogramData();
149 allAreHistograms = allAreHistograms && ws->isHistogramData();
152 if (thereAreHistograms != allAreHistograms) {
153 throw std::invalid_argument(
"Cannot mix histograms and point data.");
157 if (minSize == maxSize) {
162 std::vector<MatrixWorkspace_sptr> interpolatedWorkspaces;
163 for (
auto const &ws : workspaces) {
164 if (ws->blocksize() < maxSize) {
165 if (allAreHistograms) {
171 interpolatedWorkspaces.emplace_back(ws);
175 return interpolatedWorkspaces;
179 size_t const maxSize) {
180 auto const &
x = ws->x(0);
181 auto const startX =
x.front();
182 auto const endX =
x.back();
183 Counts yVals(maxSize, 0.0);
184 auto const dX = (endX - startX) /
double(maxSize - 1);
185 Points xVals(maxSize, LinearGenerator(startX, dX));
186 auto newHisto = Histogram(xVals, yVals);
187 interpolateLinearInplace(ws->histogram(0), newHisto);
188 auto interpolatedWS = std::make_shared<Workspace2D>();
189 interpolatedWS->initialize(1, newHisto);
190 assert(interpolatedWS->y(0).size() == maxSize);
191 return interpolatedWS;
195 size_t const maxSize) {
196 ws->setDistribution(
true);
197 auto const &
x = ws->x(0);
198 auto const dX = (
x.back() -
x.front()) /
double(maxSize);
199 std::vector<double> params(2 * maxSize + 1);
200 for (
size_t i = 0; i < maxSize; ++i) {
201 params[2 * i] =
x.front() + dX * double(i);
202 params[2 * i + 1] = dX;
204 params.back() =
x.back();
206 alg->setProperty(
"InputWorkspace", ws);
207 alg->setProperty(
"Params", params);
208 alg->setProperty(
"OutputWorkspace",
"dummy");
211 assert(interpolatedWS->y(0).size() == maxSize);
212 assert(interpolatedWS->x(0).size() == maxSize + 1);
213 return interpolatedWS;
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
static std::string const Rho
static std::string const Ap
static std::string const P2
static std::string const Pp
Names of the efficiency properties.
static std::string const F1
static std::string const Alpha
void initOutputWorkspace()
static std::string const F2
static std::string const P1
JoinISISPolarizationEfficiencies : Joins reflectometry polarization efficiency correction factors to ...
API::MatrixWorkspace_sptr interpolateHistogramWorkspace(const API::MatrixWorkspace_sptr &ws, size_t const maxSize)
std::vector< API::MatrixWorkspace_sptr > interpolateWorkspaces(std::vector< API::MatrixWorkspace_sptr > const &workspaces)
Interpolate the workspaces so that all have the same blocksize.
API::MatrixWorkspace_sptr interpolatePointDataWorkspace(const API::MatrixWorkspace_sptr &ws, size_t const maxSize)
API::MatrixWorkspace_sptr createEfficiencies(std::vector< std::string > const &props) override
Load efficientcies from files and put them into a single workspace.
int version() const override
Algorithm's version for identification.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
void init() override
Initialize the algorithm's properties.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.