-
Notifications
You must be signed in to change notification settings - Fork 122
/
SofQW.cpp
133 lines (118 loc) · 5.91 KB
/
SofQW.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include <stdexcept>
#include "MantidAPI/CommonBinsValidator.h"
#include "MantidAPI/HistogramValidator.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/SpectraAxisValidator.h"
#include "MantidAPI/SpectrumDetectorMapping.h"
#include "MantidAPI/WorkspaceUnitValidator.h"
#include "MantidAlgorithms/SofQW.h"
#include "MantidDataObjects/Histogram1D.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidGeometry/Instrument/DetectorGroup.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/CompositeValidator.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/RebinParamsValidator.h"
namespace Mantid::Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(SofQW)
using namespace API;
using namespace DataObjects;
using namespace Kernel;
/**
* @return A summary of the algorithm
*/
const std::string SofQW::summary() const {
return "Computes S(Q,w) using a either centre point or parallel-piped "
"rebinning.\n"
"The output from each method is:\n"
"CentrePoint - centre-point rebin that takes no account of pixel "
"curvature or area overlap\n\n"
"Polygon - parallel-piped rebin, outputting a weighted-sum of "
"overlapping polygons\n\n"
"NormalisedPolygon - parallel-piped rebin, outputting a weighted-sum "
"of "
"overlapping polygons normalised by the fractional area of each "
"overlap";
}
/**
* Create the input properties
*/
void SofQW::init() {
createCommonInputProperties(*this);
// Add the Method property to control which algorithm is called
const char *methodOptions[] = {"Centre", "Polygon", "NormalisedPolygon"};
this->declareProperty(
"Method", "Centre",
std::make_shared<StringListValidator>(std::vector<std::string>(methodOptions, methodOptions + 3)),
"Defines the method used to compute the output.");
}
/**
* Create the common set of input properties for the given algorithm
* @param alg An algorithm object
*/
void SofQW::createCommonInputProperties(API::Algorithm &alg) {
auto wsValidator = std::make_shared<CompositeValidator>();
wsValidator->add<WorkspaceUnitValidator>("DeltaE");
wsValidator->add<SpectraAxisValidator>();
wsValidator->add<CommonBinsValidator>();
wsValidator->add<HistogramValidator>();
wsValidator->add<InstrumentValidator>();
alg.declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input, wsValidator),
"Reduced data in units of energy transfer DeltaE.\nThe "
"workspace must contain histogram data and have common "
"bins across all spectra.");
alg.declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
"The name to use for the q-omega workspace.");
alg.declareProperty(std::make_unique<ArrayProperty<double>>("QAxisBinning", std::make_shared<RebinParamsValidator>()),
"The bin parameters to use for the q axis (in the format used by the "
":ref:`algm-Rebin` algorithm).");
const std::vector<std::string> propOptions{"Direct", "Indirect"};
alg.declareProperty("EMode", "", std::make_shared<StringListValidator>(propOptions),
"The energy transfer analysis mode (Direct/Indirect)");
auto mustBePositive = std::make_shared<BoundedValidator<double>>();
mustBePositive->setLower(0.0);
alg.declareProperty("EFixed", 0.0, mustBePositive,
"The value of fixed energy: :math:`E_i` (EMode=Direct) "
"or :math:`E_f` (EMode=Indirect) (meV).\nMust be set "
"here if not available in the instrument definition.");
alg.declareProperty("ReplaceNaNs", false,
"If true, all NaN values in the output workspace are "
"replaced using the ReplaceSpecialValues algorithm.",
Direction::Input);
alg.declareProperty(
std::make_unique<ArrayProperty<double>>("EAxisBinning", std::make_shared<RebinParamsValidator>(true)),
"The bin parameters to use for the E axis (optional, in the format "
"used by the :ref:`algm-Rebin` algorithm).");
alg.declareProperty(std::make_unique<WorkspaceProperty<TableWorkspace>>("DetectorTwoThetaRanges", "",
Direction::Input, PropertyMode::Optional),
"A table workspace use by SofQWNormalisedPolygon containing a 'Detector "
"ID' column as well as 'Min two theta' and 'Max two theta' columns "
"listing the detector's min and max scattering angles in radians.");
}
void SofQW::exec() {
// Find the approopriate algorithm
std::string method = this->getProperty("Method");
std::string child = "SofQW" + method;
// Setup and run
Algorithm_sptr childAlg = std::dynamic_pointer_cast<Algorithm>(createChildAlgorithm(child, 0.0, 1.0));
// This will add the Method property to the child algorithm but it will be
// ignored anyway...
childAlg->copyPropertiesFrom(*this);
childAlg->execute();
MatrixWorkspace_sptr outputWS = childAlg->getProperty("OutputWorkspace");
this->setProperty("OutputWorkspace", outputWS);
// Progress reports & cancellation
MatrixWorkspace_const_sptr inputWorkspace = getProperty("InputWorkspace");
const size_t nHistos = inputWorkspace->getNumberHistograms();
auto m_progress = std::make_unique<Progress>(this, 0.0, 1.0, nHistos);
m_progress->report("Creating output workspace");
}
} // namespace Mantid::Algorithms