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 HistogramData::BinEdges xAxis(0);
93 double eMin{std::nan("")};
94 double eMax{std::nan("")};
95 if (ebinParams.empty()) {
96 xAxis = inputWorkspace.binEdges(0);
97 } else if (ebinParams.size() == 1) {
98 inputWorkspace.getXMinMax(eMin, eMax);
99 createAxisFromRebinParams(ebinParams, xAxis.mutableRawData(), true, true, eMin, eMax);
100 } else {
101 createAxisFromRebinParams(ebinParams, xAxis.mutableRawData());
102 }
103 // Create a vector to temporarily hold the vertical ('y') axis and populate
104 // that
105 int yLength;
106 if (qbinParams.size() == 1) {
107 if (std::isnan(eMin)) {
108 inputWorkspace.getXMinMax(eMin, eMax);
109 }
110 double qMin;
111 double qMax;
112 std::tie(qMin, qMax) = emodeProperties.qBinHints(inputWorkspace, eMin, eMax);
113 yLength = createAxisFromRebinParams(qbinParams, qAxis, true, true, qMin, qMax);
114 } else {
115 yLength = createAxisFromRebinParams(qbinParams, qAxis);
116 }
117
118 // Create output workspace, bin edges are same as in inputWorkspace index 0
119 auto outputWorkspace = DataObjects::create<Workspace>(inputWorkspace, yLength - 1, xAxis);
120
121 // Create a binned numeric axis to replace the default vertical one
122 auto verticalAxis = std::make_unique<API::BinEdgeAxis>(qAxis);
123 auto verticalAxisRaw = verticalAxis.get();
124 outputWorkspace->replaceAxis(1, std::move(verticalAxis));
125
126 // Set the axis units
127 verticalAxisRaw->unit() = Kernel::UnitFactory::Instance().create("MomentumTransfer");
128 verticalAxisRaw->title() = "|Q|";
129
130 // Set the X axis title (for conversion to MD)
131 outputWorkspace->getAxis(0)->title() = "Energy transfer";
132
133 outputWorkspace->setYUnit("");
134 outputWorkspace->setYUnitLabel("Intensity");
135
136 return outputWorkspace;
137}
138
139} // namespace Algorithms
140} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
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
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
int 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.
Definition: SofQCommon.cpp:115