Mantid
Loading...
Searching...
No Matches
IndirectFitDataCreationHelper.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 +
9
11using namespace Mantid::API;
12
13MatrixWorkspace_sptr createWorkspace(int const &numberOfSpectra, int const &numberOfBins) {
14 return WorkspaceCreationHelper::create2DWorkspace(numberOfSpectra, numberOfBins);
15}
16
17MatrixWorkspace_sptr createInstrumentWorkspace(int const &xLength, int const &yLength) {
18 return WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(xLength, yLength - 1, false, false, true,
19 "testInst");
20}
21
22MatrixWorkspace_sptr createWorkspaceWithTextAxis(int const &numberOfSpectra, std::vector<std::string> const &labels,
23 int const &numberOfBins) {
24 if (static_cast<std::size_t>(numberOfSpectra) == labels.size()) {
25 auto workspace = createWorkspace(numberOfSpectra, numberOfBins);
26 workspace->replaceAxis(1, std::unique_ptr<Axis>(getTextAxis(numberOfSpectra, labels)));
27 return workspace;
28 } else
29 throw std::runtime_error("The number of spectra is not equal to the number of labels");
30}
31
32MatrixWorkspace_sptr createWorkspaceWithBinValues(int const &numberOfSpectra, std::vector<double> const &values,
33 int const &numberOfBins) {
34 if (static_cast<std::size_t>(numberOfBins) == values.size()) {
35 auto workspace = createWorkspace(numberOfSpectra, numberOfBins);
36 workspace->replaceAxis(0, std::unique_ptr<Axis>(getNumericAxis(numberOfBins, values)));
37 return workspace;
38 } else
39 throw std::runtime_error("The number of bins is not equal to the number of labels");
40}
41
42WorkspaceGroup_sptr createGroupWorkspace(std::size_t const &numberOfWorkspaces, int const &numberOfSpectra,
43 int const &numberOfBins) {
44 auto groupWorkspace = std::make_shared<WorkspaceGroup>();
45 for (auto i = 0u; i < numberOfWorkspaces; ++i)
46 groupWorkspace->addWorkspace(createWorkspace(numberOfSpectra, numberOfBins));
47 return groupWorkspace;
48}
49
50WorkspaceGroup_sptr createGroupWorkspaceWithTextAxes(std::size_t const &numberOfWorkspaces,
51 std::vector<std::string> const &labels, int const &numberOfSpectra,
52 int const &numberOfBins) {
53 auto groupWorkspace = std::make_shared<WorkspaceGroup>();
54 for (auto i = 0u; i < numberOfWorkspaces; ++i)
55 groupWorkspace->addWorkspace(createWorkspaceWithTextAxis(numberOfSpectra, labels, numberOfBins));
56 return groupWorkspace;
57}
58
59TextAxis *getTextAxis(int const &numberOfSpectra, std::vector<std::string> const &labels) {
60 auto axis = new TextAxis(numberOfSpectra);
61 for (auto index = 0; index < numberOfSpectra; ++index)
62 axis->setLabel(index, labels[index]);
63 return axis;
64}
65
66NumericAxis *getNumericAxis(int const &numberOfLabels, std::vector<double> const &values) {
67 auto axis = new NumericAxis(numberOfLabels);
68 for (auto index = 0; index < numberOfLabels; ++index)
69 axis->setValue(index, values[index]);
70 return axis;
71}
72
74 for (int i = 0; i < xLength; ++i)
75 workspace->setEFixed((i + 1), 0.50);
76 return workspace;
77}
78
80 Mantid::HistogramData::BinEdges const &binEdges) {
81 for (int i = 0; i < yLength; ++i)
82 workspace->setBinEdges(i, binEdges);
83 return workspace;
84}
85
87 Mantid::HistogramData::BinEdges binEdges(xLength - 1, 0.0);
88 int j = 0;
89 std::generate(begin(binEdges), end(binEdges), [&j] { return 0.5 + 0.75 * ++j; });
90 setWorkspaceBinEdges(workspace, yLength, binEdges);
91 return workspace;
92}
93
95 setWorkspaceBinEdges(workspace, xLength, yLength);
97 return workspace;
98}
99
100MatrixWorkspace_sptr createWorkspaceWithInstrument(int const &xLength, int const &yLength) {
101 auto workspace = createInstrumentWorkspace(xLength, yLength);
102 workspace->initialize(yLength, xLength, xLength - 1);
103 return setWorkspaceProperties(workspace, xLength, yLength);
104}
105
107 std::vector<double> L2 = {1.0}, polar = {M_PI_4}, azimuthal = {0.};
108 auto inputWS = WorkspaceCreationHelper::createProcessedInelasticWS(L2, polar, azimuthal, yLength - 1, -10, 20, 17.1);
109 return inputWS;
110}
111
112} // namespace Mantid::IndirectFitDataCreationHelper
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Class to represent a numeric axis of a workspace.
Definition: NumericAxis.h:29
Class to represent a text axis of a workspace.
Definition: TextAxis.h:36
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< T > createWorkspace(InitArgs... args)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Mantid::API::MatrixWorkspace_sptr createWorkspaceWithInstrument(int const &xLength, int const &yLength)
Mantid::API::NumericAxis * getNumericAxis(int const &numberOfLabels, std::vector< double > const &values)
Mantid::API::MatrixWorkspace_sptr setWorkspaceProperties(Mantid::API::MatrixWorkspace_sptr workspace, int const &xLength, int const &yLength)
Mantid::API::MatrixWorkspace_sptr createWorkspaceWithTextAxis(int const &numberOfSpectra, std::vector< std::string > const &labels, int const &numberOfBins=10)
Mantid::API::MatrixWorkspace_sptr setWorkspaceEFixed(Mantid::API::MatrixWorkspace_sptr workspace, int const &xLength)
Mantid::API::MatrixWorkspace_sptr setWorkspaceBinEdges(Mantid::API::MatrixWorkspace_sptr workspace, int const &yLength, Mantid::HistogramData::BinEdges const &binEdges)
Mantid::API::MatrixWorkspace_sptr createInstrumentWorkspace(int const &xLength, int const &yLength)
Mantid::API::WorkspaceGroup_sptr createGroupWorkspaceWithTextAxes(std::size_t const &numberOfWorkspaces, std::vector< std::string > const &labels, int const &numberOfSpectra, int const &numberOfBins=10)
Mantid::API::MatrixWorkspace_sptr createWorkspaceWithBinValues(int const &numberOfSpectra, std::vector< double > const &labels, int const &numberOfBins=10)
Mantid::API::MatrixWorkspace_sptr createWorkspaceWithInelasticInstrument(int const &yLength)
Mantid::API::WorkspaceGroup_sptr createGroupWorkspace(std::size_t const &numberOfWorkspaces, int const &numberOfSpectra, int const &numberOfBins=10)
Mantid::API::TextAxis * getTextAxis(int const &numberOfSpectra, std::vector< std::string > const &labels)
Mantid::API::MatrixWorkspace_sptr createProcessedInelasticWS(const std::vector< double > &L2, const std::vector< double > &polar, const std::vector< double > &azimutal, size_t numBins=4, double Emin=-10, double Emax=10, double Ei=11)
Create a workspace with all components needed for inelastic analysis and 3 detectors in specific plac...
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nhist, int nbins, bool includeMonitors=false, bool startYNegative=false, bool isHistogram=true, const std::string &instrumentName=std::string("testInst"), bool hasDx=false)
Create a test workspace with a fully defined instrument.
Mantid::DataObjects::Workspace2D_sptr create2DWorkspace(size_t nhist, size_t numBoundaries)