Mantid
Loading...
Searching...
No Matches
SofQW.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 <stdexcept>
8
24
25namespace Mantid::Algorithms {
26
27// Register the algorithm into the AlgorithmFactory
29
30using namespace API;
31using namespace DataObjects;
32using namespace Kernel;
33
37const std::string SofQW::summary() const {
38 return "Computes S(Q,w) using a either centre point or parallel-piped "
39 "rebinning.\n"
40 "The output from each method is:\n"
41 "CentrePoint - centre-point rebin that takes no account of pixel "
42 "curvature or area overlap\n\n"
43 "Polygon - parallel-piped rebin, outputting a weighted-sum of "
44 "overlapping polygons\n\n"
45 "NormalisedPolygon - parallel-piped rebin, outputting a weighted-sum "
46 "of "
47 "overlapping polygons normalised by the fractional area of each "
48 "overlap";
49}
50
56
57 // Add the Method property to control which algorithm is called
58 const char *methodOptions[] = {"Centre", "Polygon", "NormalisedPolygon"};
59 this->declareProperty(
60 "Method", "Centre",
61 std::make_shared<StringListValidator>(std::vector<std::string>(methodOptions, methodOptions + 3)),
62 "Defines the method used to compute the output.");
63}
64
70 auto wsValidator = std::make_shared<CompositeValidator>();
71 wsValidator->add<WorkspaceUnitValidator>("DeltaE");
72 wsValidator->add<SpectraAxisValidator>();
73 wsValidator->add<CommonBinsValidator>();
74 wsValidator->add<HistogramValidator>();
75 wsValidator->add<InstrumentValidator>();
76 alg.declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input, wsValidator),
77 "Reduced data in units of energy transfer DeltaE.\nThe "
78 "workspace must contain histogram data and have common "
79 "bins across all spectra.");
80 alg.declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
81 "The name to use for the q-omega workspace.");
82 alg.declareProperty(std::make_unique<ArrayProperty<double>>("QAxisBinning", std::make_shared<RebinParamsValidator>()),
83 "The bin parameters to use for the q axis (in the format used by the "
84 ":ref:`algm-Rebin` algorithm).");
85
86 const std::vector<std::string> propOptions{"Direct", "Indirect"};
87 alg.declareProperty("EMode", "", std::make_shared<StringListValidator>(propOptions),
88 "The energy transfer analysis mode (Direct/Indirect)");
89 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
90 mustBePositive->setLower(0.0);
91 alg.declareProperty("EFixed", 0.0, mustBePositive,
92 "The value of fixed energy: :math:`E_i` (EMode=Direct) "
93 "or :math:`E_f` (EMode=Indirect) (meV).\nMust be set "
94 "here if not available in the instrument definition.");
95 alg.declareProperty("ReplaceNaNs", false,
96 "If true, all NaN values in the output workspace are "
97 "replaced using the ReplaceSpecialValues algorithm.",
100 std::make_unique<ArrayProperty<double>>("EAxisBinning", std::make_shared<RebinParamsValidator>(true)),
101 "The bin parameters to use for the E axis (optional, in the format "
102 "used by the :ref:`algm-Rebin` algorithm).");
103 alg.declareProperty(std::make_unique<WorkspaceProperty<TableWorkspace>>("DetectorTwoThetaRanges", "",
105 "A table workspace use by SofQWNormalisedPolygon containing a 'Detector "
106 "ID' column as well as 'Min two theta' and 'Max two theta' columns "
107 "listing the detector's min and max scattering angles in radians.");
108}
109
111 // Find the approopriate algorithm
112 std::string method = this->getProperty("Method");
113 std::string child = "SofQW" + method;
114
115 // Setup and run
116 Algorithm_sptr childAlg = std::dynamic_pointer_cast<Algorithm>(createChildAlgorithm(child, 0.0, 1.0));
117 // This will add the Method property to the child algorithm but it will be
118 // ignored anyway...
119 childAlg->copyPropertiesFrom(*this);
120 childAlg->execute();
121
122 MatrixWorkspace_sptr outputWS = childAlg->getProperty("OutputWorkspace");
123
124 this->setProperty("OutputWorkspace", outputWS);
125
126 // Progress reports & cancellation
127 MatrixWorkspace_const_sptr inputWorkspace = getProperty("InputWorkspace");
128 const size_t nHistos = inputWorkspace->getNumberHistograms();
129 auto m_progress = std::make_unique<Progress>(this, 0.0, 1.0, nHistos);
130 m_progress->report("Creating output workspace");
131}
132
133} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
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 validator which provides a TENTATIVE check that a workspace contains common bins in each spectrum.
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) override
Create a Child Algorithm.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
A validator which checks that a workspace has a valid instrument.
A validator which checks whether the input workspace has the Spectra number in the axis.
A property class for workspaces.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
static void createCommonInputProperties(API::Algorithm &alg)
Create the input properties on the given algorithm object.
Definition: SofQW.cpp:69
const std::string summary() const override
Summary of algorithms purpose.
Definition: SofQW.cpp:37
void init() override
Initialization code.
Definition: SofQW.cpp:54
void exec() override
Execution code.
Definition: SofQW.cpp:110
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition: Algorithm.h:61
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54