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 {
54 return {"SofQWCentre", "SofQWPolygon", "SofQWNormalisedPolygon", "Rebin2D"};
55 }
57 const std::string category() const override { return "Inelastic\\SofQW"; }
59 template <typename Workspace>
60 static std::unique_ptr<Workspace>
61 setUpOutputWorkspace(const API::MatrixWorkspace &inputWorkspace, const std::vector<double> &qbinParams,
62 std::vector<double> &qAxis, const std::vector<double> &ebinParams,
63 const SofQCommon &emodeProperties);
65 static void createCommonInputProperties(API::Algorithm &alg);
66
67private:
69 void init() override;
71 void exec() override;
72};
73
85template <typename Workspace>
86std::unique_ptr<Workspace>
87SofQW::setUpOutputWorkspace(const API::MatrixWorkspace &inputWorkspace, const std::vector<double> &qbinParams,
88 std::vector<double> &qAxis, const std::vector<double> &ebinParams,
89 const SofQCommon &emodeProperties) {
91 // Create vector to hold the new X axis values
92 std::vector<double> xnew;
93 double eMin{std::nan("")};
94 double eMax{std::nan("")};
95 if (ebinParams.empty()) {
96 xnew = inputWorkspace.binEdges(0).rawData();
97 } else if (ebinParams.size() == 1) {
98 inputWorkspace.getXMinMax(eMin, eMax);
99 createAxisFromRebinParams(ebinParams, xnew, true, true, eMin, eMax);
100 } else {
101 createAxisFromRebinParams(ebinParams, xnew);
102 }
103 HistogramData::BinEdges xAxis(std::move(xnew));
104 // Create a vector to temporarily hold the vertical ('y') axis and populate
105 // that
106 size_t yLength;
107 if (qbinParams.size() == 1) {
108 if (std::isnan(eMin)) {
109 inputWorkspace.getXMinMax(eMin, eMax);
110 }
111 double qMin;
112 double qMax;
113 std::tie(qMin, qMax) = emodeProperties.qBinHints(inputWorkspace, eMin, eMax);
114 yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, qMin, qMax);
115 } else {
116 yLength = createAxisFromRebinParams(qbinParams, qAxis);
117 }
118
119 // Create output workspace, bin edges are same as in inputWorkspace index 0
120 auto outputWorkspace = DataObjects::create<Workspace>(inputWorkspace, yLength - 1, xAxis);
121
122 // Create a binned numeric axis to replace the default vertical one
123 auto verticalAxis = std::make_unique<API::BinEdgeAxis>(qAxis);
124 auto verticalAxisRaw = verticalAxis.get();
125 outputWorkspace->replaceAxis(1, std::move(verticalAxis));
126
127 // Set the axis units
128 verticalAxisRaw->unit() = Kernel::UnitFactory::Instance().create("MomentumTransfer");
129 verticalAxisRaw->title() = "|Q|";
130
131 // Set the X axis title (for conversion to MD)
132 outputWorkspace->getAxis(0)->title() = "Energy transfer";
133
134 outputWorkspace->setYUnit("");
135 outputWorkspace->setYUnitLabel("Intensity");
136
137 return outputWorkspace;
138}
139
140} // namespace Algorithms
141} // 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:57
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:87
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.