39 return "Converts the spectrum and TOF axes to real space values, integrating "
40 "the data in the process";
47 "An input workspace.");
49 "An output workspace.");
51 std::vector<std::string> propOptions;
61 declareProperty(
"VerticalAxis",
"y", std::make_shared<StringListValidator>(propOptions),
62 "What will be the vertical axis ?\n");
63 declareProperty(
"HorizontalAxis",
"2theta", std::make_shared<StringListValidator>(propOptions),
64 "What will be the horizontal axis?\n");
67 "The number of bins along the vertical axis.");
69 "The number of bins along the horizontal axis.");
78 std::vector<AxisData> axisVector = std::vector<AxisData>(2);
80 axisVector[0].label = hAxis;
81 axisVector[0].bins =
getProperty(
"NumberHorizontalBins");
83 axisVector[1].label = vAxis;
84 axisVector[1].bins =
getProperty(
"NumberVerticalBins");
85 for (
int axisIndex = 0; axisIndex < 2; ++axisIndex) {
86 axisVector[axisIndex].max = std::numeric_limits<double>::lowest();
87 axisVector[axisIndex].min = std::numeric_limits<double>::max();
98 std::string outName =
"_" + inputWs->getName() +
"_integrated";
99 alg->setProperty(
"OutputWorkspace", outName);
100 alg->executeAsChildAlg();
103 auto nHist =
static_cast<int>(summedWs->getNumberHistograms());
106 std::vector<SpectraData> dataVector(nHist);
110 const auto &spectrumInfo = summedWs->spectrumInfo();
113 for (
int i = 0; i < nHist; ++i) {
116 V3D pos = spectrumInfo.position(i);
117 double r, theta, phi;
121 for (
int axisIndex = 0; axisIndex < 2; ++axisIndex) {
122 double axisValue = std::numeric_limits<double>::min();
123 std::string axisSelection = axisVector[axisIndex].label;
126 if (axisSelection ==
"x") {
128 }
else if (axisSelection ==
"y") {
130 }
else if (axisSelection ==
"z") {
132 }
else if (axisSelection ==
"r") {
134 }
else if (axisSelection ==
"theta") {
136 }
else if (axisSelection ==
"phi") {
138 }
else if (axisSelection ==
"2theta") {
139 axisValue = spectrumInfo.twoTheta(i);
140 }
else if (axisSelection ==
"signed2theta") {
141 axisValue = spectrumInfo.signedTwoTheta(i);
144 if (axisIndex == 0) {
145 dataVector[i].horizontalValue = axisValue;
147 dataVector[i].verticalValue = axisValue;
151 if (axisValue > axisVector[axisIndex].max)
152 axisVector[axisIndex].max = axisValue;
153 if (axisValue < axisVector[axisIndex].min)
154 axisVector[axisIndex].min = axisValue;
157 g_log.
debug() <<
"Could not find detector for workspace index " << i <<
'\n';
160 dataVector[i].horizontalValue = std::numeric_limits<double>::min();
161 dataVector[i].verticalValue = std::numeric_limits<double>::min();
166 dataVector[i].intensity = summedWs->y(i)[0];
167 dataVector[i].error = summedWs->e(i)[0];
169 progress.report(
"Calculating new coords");
173 g_log.
warning() <<
"Could not find detector for " << failedCount <<
" spectra, see the debug log for more details.\n";
176 std::vector<double> x_tmp(axisVector[0].bins);
179 HistogramData::Points
x(std::move(x_tmp));
182 Unit_sptr xUnit = outputWs->getAxis(0)->unit();
183 std::shared_ptr<Units::Label> xlabel = std::dynamic_pointer_cast<Units::Label>(xUnit);
184 xlabel->setLabel(axisVector[0].label,
m_unitMap[axisVector[0].label]);
187 yRef.resize(axisVector[1].bins);
190 auto yAxis = std::make_unique<NumericAxis>(yRef);
191 std::shared_ptr<Units::Label> ylabel =
193 ylabel->setLabel(axisVector[1].label,
m_unitMap[axisVector[1].label]);
194 yAxis->unit() = ylabel;
195 outputWs->replaceAxis(1, std::move(yAxis));
200 for (
int i = 0; i < nHist; ++i) {
202 if (dataVector[i].horizontalValue == std::numeric_limits<double>::min()) {
203 dataVector[i].horizontalIndex = -1;
204 dataVector[i].verticalIndex = -1;
206 int xIndex =
static_cast<int>(
207 std::distance(
x.cbegin(), std::lower_bound(
x.cbegin(),
x.cend(), dataVector[i].horizontalValue)));
210 int yIndex =
static_cast<int>(
211 std::distance(
y->begin(), std::lower_bound(
y->begin(),
y->end(), dataVector[i].verticalValue)));
215 dataVector[i].horizontalIndex = xIndex;
216 dataVector[i].verticalIndex = yIndex;
218 progress.report(
"Calculating Rebinning");
222 auto nOutputHist =
static_cast<int>(outputWs->getNumberHistograms());
224 for (
int i = 0; i < nOutputHist; ++i) {
225 outputWs->setPoints(i,
x);
230 for (
int i = 0; i < nHist; ++i) {
231 int xIndex = dataVector[i].horizontalIndex;
232 int yIndex = dataVector[i].verticalIndex;
235 if ((xIndex == -1) || (yIndex == -1)) {
240 auto &yVec = outputWs->mutableY(yIndex);
241 yVec[xIndex] = yVec[xIndex] + dataVector[i].intensity;
242 auto &eVec = outputWs->mutableE(yIndex);
243 eVec[xIndex] = eVec[xIndex] + (dataVector[i].error * dataVector[i].error);
246 progress.report(
"Assigning to new grid");
251 for (
int i = 0; i < nOutputHist; ++i) {
252 auto &errorVec = outputWs->mutableE(i);
253 std::transform(errorVec.begin(), errorVec.end(), errorVec.begin(),
static_cast<double (*)(
double)
>(sqrt));
254 progress.report(
"Completing Error Calculation");
269 int numBins = axisData.
bins;
270 double binDelta = (axisData.
max - axisData.
min) /
static_cast<double>(numBins);
275 for (
int i = 0; i < numBins; ++i) {
276 vector[i] = axisData.
min + i * binDelta;
287 std::map<std::string, std::string> &unitMap,
const std::string &caption,
288 const std::string &unit) {
289 unitMap.emplace(caption, unit);
290 orderedVector.emplace_back(caption);
#define DECLARE_ALGORITHM(classname)
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_FOR_NO_WSP_CHECK()
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
A property class for workspaces.
ConvertAxesToRealSpace : Converts the spectrum and TOF axes to real space values, integrating the dat...
std::map< std::string, std::string > m_unitMap
void exec() override
Execute the algorithm.
const std::string category() const override
Algorithm's category for identification.
void fillUnitMap(std::vector< std::string > &orderedVector, std::map< std::string, std::string > &unitMap, const std::string &caption, const std::string &unit)
Fills the unit map and ordered vector with the same data.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
void fillAxisValues(MantidVec &vector, const AxisData &axisData, bool isHistogram)
Fills the values in an axis linearly from min to max for a given number of steps.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
void getSpherical(double &R, double &theta, double &phi) const noexcept
Return the vector's position in spherical coordinates.
constexpr double Z() const noexcept
Get z.
Implements a copy on write data template.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
summary data about an Axis
@ Input
An input workspace.
@ Output
An output workspace.