Mantid
Loading...
Searching...
No Matches
SofQW.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
13
20
21namespace Mantid {
22namespace Algorithms {
42struct SofQCommon;
43
44class MANTID_ALGORITHMS_DLL SofQW : public API::DataProcessorAlgorithm {
45public:
47 const std::string name() const override { return "SofQW"; }
49 const std::string summary() const override;
50
52 int version() const override { return (1); }
53 const std::vector<std::string> seeAlso() const override { return {"SofQWNormalisedPolygon", "Rebin2D"}; }
55 const std::string category() const override { return "Inelastic\\SofQW"; }
57 template <typename Workspace>
58 static std::unique_ptr<Workspace>
59 setUpOutputWorkspace(const API::MatrixWorkspace &inputWorkspace, const std::vector<double> &qbinParams,
60 std::vector<double> &qAxis, const std::vector<double> &ebinParams,
61 const SofQCommon &emodeProperties);
63 static void createCommonInputProperties(API::Algorithm &alg);
64
65private:
67 void init() override;
69 void exec() override;
70};
71
83template <typename Workspace>
84std::unique_ptr<Workspace>
85SofQW::setUpOutputWorkspace(const API::MatrixWorkspace &inputWorkspace, const std::vector<double> &qbinParams,
86 std::vector<double> &qAxis, const std::vector<double> &ebinParams,
87 const SofQCommon &emodeProperties) {
89 // Create vector to hold the new X axis values
90 std::vector<double> xnew;
91 double eMin{std::nan("")};
92 double eMax{std::nan("")};
93 if (ebinParams.empty()) {
94 xnew = inputWorkspace.binEdges(0).rawData();
95 } else if (ebinParams.size() == 1) {
96 inputWorkspace.getXMinMax(eMin, eMax);
97 createAxisFromRebinParams(ebinParams, xnew, true, true, eMin, eMax);
98 } else {
99 createAxisFromRebinParams(ebinParams, xnew);
100 }
101 HistogramData::BinEdges xAxis(std::move(xnew));
102 // Create a vector to temporarily hold the vertical ('y') axis and populate
103 // that
104 size_t yLength;
105 if (qbinParams.size() == 1) {
106 if (std::isnan(eMin)) {
107 inputWorkspace.getXMinMax(eMin, eMax);
108 }
109 double qMin;
110 double qMax;
111 std::tie(qMin, qMax) = emodeProperties.qBinHints(inputWorkspace, eMin, eMax);
112 yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, qMin, qMax);
113 } else {
114 yLength = createAxisFromRebinParams(qbinParams, qAxis);
115 }
116
117 // Create output workspace, bin edges are same as in inputWorkspace index 0
118 auto outputWorkspace = DataObjects::create<Workspace>(inputWorkspace, yLength - 1, xAxis);
119
120 // Create a binned numeric axis to replace the default vertical one
121 auto verticalAxis = std::make_unique<API::BinEdgeAxis>(qAxis);
122 auto verticalAxisRaw = verticalAxis.get();
123 outputWorkspace->replaceAxis(1, std::move(verticalAxis));
124
125 // Set the axis units
126 verticalAxisRaw->unit() = Kernel::UnitFactory::Instance().create("MomentumTransfer");
127 verticalAxisRaw->title() = "|Q|";
128
129 // Set the X axis title (for conversion to MD)
130 outputWorkspace->getAxis(0)->title() = "Energy transfer";
131
132 outputWorkspace->setYUnit("");
133 outputWorkspace->setYUnitLabel("Intensity");
134
135 return outputWorkspace;
136}
137
138} // namespace Algorithms
139} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
Data processor algorithm to be used as a parent to workflow algorithms.
Base MatrixWorkspace Abstract Class.
HistogramData::BinEdges binEdges(const size_t index) const
virtual void getXMinMax(double &xmin, double &xmax) const
const std::string category() const override
Algorithm's category for identification.
Definition SofQW.h:55
const std::string name() const override
Algorithm's name.
Definition SofQW.h:47
static std::unique_ptr< Workspace > setUpOutputWorkspace(const API::MatrixWorkspace &inputWorkspace, const std::vector< double > &qbinParams, std::vector< double > &qAxis, const std::vector< double > &ebinParams, const SofQCommon &emodeProperties)
Create the output workspace.
Definition SofQW.h:85
const std::vector< std::string > seeAlso() const override
Definition SofQW.h:53
int version() const override
Algorithm's version.
Definition SofQW.h:52
std::size_t MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > &params, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
Helper class which provides the Collimation Length for SANS instruments.
std::pair< double, double > qBinHints(const API::MatrixWorkspace &ws, const double minE, const double maxE) const
Estimate minimum and maximum momentum transfer.