Mantid
Loading...
Searching...
No Matches
CreatePolarizationEfficienciesBase.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 +
15#include "MantidKernel/Unit.h"
16
17#include <algorithm>
18#include <memory>
19
20using namespace Mantid::API;
21using namespace Mantid::Kernel;
22using namespace Mantid::Geometry;
23
24namespace Mantid::DataHandling {
25
26std::string const CreatePolarizationEfficienciesBase::Pp("Pp");
27std::string const CreatePolarizationEfficienciesBase::Ap("Ap");
28std::string const CreatePolarizationEfficienciesBase::Rho("Rho");
29std::string const CreatePolarizationEfficienciesBase::Alpha("Alpha");
30std::string const CreatePolarizationEfficienciesBase::P1("P1");
31std::string const CreatePolarizationEfficienciesBase::P2("P2");
32std::string const CreatePolarizationEfficienciesBase::F1("F1");
33std::string const CreatePolarizationEfficienciesBase::F2("F2");
34
35const std::string CreatePolarizationEfficienciesBase::category() const { return "Reflectometry"; }
36
39 std::make_unique<WorkspaceProperty<Mantid::API::MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
40 "An output workspace.");
41}
42
44 auto const labelsFredrikze = getNonDefaultProperties({Pp, Ap, Rho, Alpha});
45 auto const labelsWildes = getNonDefaultProperties({P1, P2, F1, F2});
46
47 if (labelsFredrikze.empty() && labelsWildes.empty()) {
48 throw std::invalid_argument("At least one of the efficiencies must be set.");
49 }
50
51 if (!labelsFredrikze.empty() && !labelsWildes.empty()) {
52 throw std::invalid_argument("Efficiencies belonging to different methods cannot mix.");
53 }
54
55 MatrixWorkspace_sptr efficiencies;
56 if (!labelsFredrikze.empty()) {
57 efficiencies = createEfficiencies(labelsFredrikze);
58 } else {
59 efficiencies = createEfficiencies(labelsWildes);
60 }
61
62 setProperty("OutputWorkspace", efficiencies);
63}
64
67std::vector<std::string>
68CreatePolarizationEfficienciesBase::getNonDefaultProperties(std::vector<std::string> const &labels) const {
69 std::vector<std::string> outputLabels;
70 std::copy_if(labels.cbegin(), labels.cend(), std::back_inserter(outputLabels),
71 [this](const std::string &label) { return !isDefault(label); });
72 return outputLabels;
73}
74
75} // namespace Mantid::DataHandling
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
A property class for workspaces.
void exec() override
Virtual method - must be overridden by concrete algorithm.
const std::string category() const override
function to return a category of the algorithm.
static std::string const Pp
Names of the efficiency properties.
std::vector< std::string > getNonDefaultProperties(std::vector< std::string > const &props) const
Get names of non-default properties out of a list of names.
virtual API::MatrixWorkspace_sptr createEfficiencies(std::vector< std::string > const &labels)=0
Create the output workspace with efficiencies.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Output
An output workspace.
Definition: Property.h:54