Mantid
Loading...
Searching...
No Matches
IntegrateEPP.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
14
15namespace Mantid::Algorithms {
16
19
20namespace {
22namespace PropertyNames {
23const static std::string EPP_WORKSPACE{"EPPWorkspace"};
24const static std::string INPUT_WORKSPACE{"InputWorkspace"};
25const static std::string OUTPUT_WORKSPACE{"OutputWorkspace"};
26const static std::string WIDTH{"HalfWidthInSigmas"};
27} // namespace PropertyNames
28} // namespace
29
30// Register the algorithm into the AlgorithmFactory
31DECLARE_ALGORITHM(IntegrateEPP)
32
33//----------------------------------------------------------------------------------------------
34
35
36const std::string IntegrateEPP::name() const { return "IntegrateEPP"; }
37
39int IntegrateEPP::version() const { return 1; }
40
42const std::string IntegrateEPP::category() const { return "Arithmetic;Transforms\\Rebin"; }
43
45const std::string IntegrateEPP::summary() const { return "Integrate a workspace around elastic peak positions."; }
46
47//----------------------------------------------------------------------------------------------
53 "A workspace to be integrated.");
56 "An workspace containing the integrated histograms.");
58 std::make_unique<WorkspaceProperty<API::ITableWorkspace>>(PropertyNames::EPP_WORKSPACE, "", Direction::Input),
59 "Table containing information on the elastic peaks.");
60 const auto mandatoryDouble = std::make_shared<Kernel::MandatoryValidator<double>>();
61 const auto positiveDouble = std::make_shared<Kernel::BoundedValidator<double>>();
62 positiveDouble->setLower(0.0);
63 positiveDouble->setLowerExclusive(true);
64 const auto mandatoryPositiveDouble = std::make_shared<Kernel::CompositeValidator>();
65 mandatoryPositiveDouble->add(mandatoryDouble);
66 mandatoryPositiveDouble->add(positiveDouble);
67 declareProperty(PropertyNames::WIDTH, 5.0, mandatoryPositiveDouble,
68 "Half of the integration width in multiplies of 'Sigma'.");
69}
70
71//----------------------------------------------------------------------------------------------
76 API::ITableWorkspace_const_sptr eppWS = getProperty(PropertyNames::EPP_WORKSPACE);
77 const double sigmaMultiplier = getProperty(PropertyNames::WIDTH);
78 const auto indexCol = eppWS->getColumn("WorkspaceIndex");
79 const auto sigmaCol = eppWS->getColumn("Sigma");
80 const auto centreCol = eppWS->getColumn("PeakCentre");
81 const auto statusCol = eppWS->getColumn("FitStatus");
82 std::vector<double> begins(inWS->getNumberHistograms(), 0.0);
83 std::vector<double> ends(begins.size(), 0.0);
84 for (size_t i = 0; i < eppWS->rowCount(); ++i) {
85 const auto &fitStatus = statusCol->cell<std::string>(i);
86 if (fitStatus != "success") {
87 continue;
88 }
89 const double centre = centreCol->toDouble(i);
90 const double halfWidth = sigmaMultiplier * sigmaCol->toDouble(i);
91 const int index = indexCol->cell<int>(i);
92 if (index < 0 || static_cast<size_t>(index) >= begins.size()) {
93 throw std::runtime_error("The 'WorkspaceIndex' column contains an invalid value.");
94 }
95 begins[index] = centre - halfWidth;
96 ends[index] = centre + halfWidth;
98 }
99 auto integrate = createChildAlgorithm("Integration", 0.0, 1.0);
100 integrate->setProperty("InputWorkspace", inWS);
101 const std::string outWSName = getProperty(PropertyNames::OUTPUT_WORKSPACE);
102 integrate->setPropertyValue("OutputWorkspace", outWSName);
103 integrate->setProperty("RangeLowerList", begins);
104 integrate->setProperty("RangeUpperList", ends);
105 integrate->setProperty("IncludePartialBins", true);
106 integrate->executeAsChildAlg();
107 API::MatrixWorkspace_sptr outWS = integrate->getProperty("OutputWorkspace");
109}
110
115std::map<std::string, std::string> IntegrateEPP::validateInputs() {
116 std::map<std::string, std::string> issues;
118 API::ITableWorkspace_const_sptr eppWS = getProperty(PropertyNames::EPP_WORKSPACE);
119
120 if (inWS && eppWS && eppWS->rowCount() > inWS->getNumberHistograms()) {
121 issues[PropertyNames::EPP_WORKSPACE] = "The EPP workspace contains too many rows.";
122 }
123 return issues;
124}
125
126} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
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
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.
Definition: Algorithm.cpp:842
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
A property class for workspaces.
IntegrateEPP : Integrate a workspace around the elastic peak positions given by a EPP table.
Definition: IntegrateEPP.h:18
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
void exec() override
Execute the algorithm.
std::map< std::string, std::string > validateInputs() override
Validate input properties.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static const std::string OUTPUT_WORKSPACE
static const std::string INPUT_WORKSPACE
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54