Skip to content
Snippets Groups Projects
Commit 0bd9534f authored by Moore's avatar Moore
Browse files

FindPeakBackground updated with HistogramData re #16882

parent 43a30ca1
No related merge requests found
......@@ -5,6 +5,12 @@
#include "MantidKernel/cow_ptr.h"
namespace Mantid {
namespace HistogramData {
class HistogramX;
class HistogramY;
}
namespace Algorithms {
/** FindPeakBackground : Calculate Zscore for a Matrix Workspace
......@@ -53,7 +59,8 @@ private:
/// Implement abstract Algorithm methods
void exec() override;
double moment4(MantidVec &X, size_t n, double mean);
void estimateBackground(const MantidVec &X, const MantidVec &Y,
void estimateBackground(const HistogramData::HistogramX &X,
const HistogramData::HistogramY &Y,
const size_t i_min, const size_t i_max,
const size_t p_min, const size_t p_max,
const bool hasPeak, double &out_bg0, double &out_bg1,
......
#include "MantidAlgorithms/FindPeakBackground.h"
#include "MantidAlgorithms/FindPeaks.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/Statistics.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAlgorithms/FindPeaks.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/ListValidator.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidKernel/Statistics.h"
#include <sstream>
......@@ -17,6 +17,8 @@ using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataObjects;
using namespace std;
using Mantid::HistogramData::HistogramX;
using Mantid::HistogramData::HistogramY;
namespace Mantid {
namespace Algorithms {
......@@ -90,16 +92,16 @@ void FindPeakBackground::exec() {
}
// Generate output
const MantidVec &inpX = inpWS->readX(inpwsindex);
size_t sizex = inpWS->readX(inpwsindex).size();
size_t sizey = inpWS->readY(inpwsindex).size();
auto &inpX = inpWS->x(inpwsindex);
size_t sizex = inpWS->x(inpwsindex).size();
size_t sizey = inpWS->x(inpwsindex).size();
size_t n = sizey;
size_t l0 = 0;
if (m_vecFitWindows.size() > 1) {
Mantid::Algorithms::FindPeaks fp;
l0 = fp.getVectorIndex(inpX, m_vecFitWindows[0]);
n = fp.getVectorIndex(inpX, m_vecFitWindows[1]);
l0 = fp.getIndex(inpX, m_vecFitWindows[0]);
n = fp.getIndex(inpX, m_vecFitWindows[1]);
if (n < sizey)
n++;
}
......@@ -122,7 +124,7 @@ void FindPeakBackground::exec() {
// Find background
const MantidVec &inpY = inpWS->readY(inpwsindex);
auto &inpY = inpWS->y(inpwsindex);
double Ymean, Yvariance, Ysigma;
MantidVec maskedY;
......@@ -244,7 +246,7 @@ void FindPeakBackground::exec() {
* @param out_bg2 :: a2 = 0
*/
void FindPeakBackground::estimateBackground(
const MantidVec &X, const MantidVec &Y, const size_t i_min,
const HistogramX &X, const HistogramY &Y, const size_t i_min,
const size_t i_max, const size_t p_min, const size_t p_max,
const bool hasPeak, double &out_bg0, double &out_bg1, double &out_bg2) {
// Validate input
......
......@@ -9,6 +9,7 @@
#include "MantidAPI/ITableWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include <numeric>
#include <cmath>
using namespace Mantid;
......@@ -70,21 +71,16 @@ public:
const size_t size = 20;
std::array<double, size> data = {{1, 2, 1, 1, 9, 11, 13, 20, 24, 32, 28, 48,
42, 77, 67, 33, 27, 20, 9, 2}};
std::array<double, size> data = {{1, 2, 1, 1, 9, 11, 13, 20, 24, 32,
28, 48, 42, 77, 67, 33, 27, 20, 9, 2}};
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(
WorkspaceFactory::Instance().create("Workspace2D", 1, size, size));
MantidVec &vecX = ws->dataX(0);
MantidVec &vecY = ws->dataY(0);
MantidVec &vecE = ws->dataE(0);
for (size_t i = 0; i < data.size(); ++i) {
vecX[i] = static_cast<double>(i);
vecY[i] = data[i];
vecE[i] = sqrt(data[i]);
}
ws->mutableY(0).assign(data.begin(), data.end());
std::iota(ws->mutableX(0).begin(), ws->mutableX(0).end(), 0);
std::transform(ws->y(0).cbegin(), ws->y(0).cend(), ws->mutableE(0).begin(),
[](const double &y) { return sqrt(y); });
return ws;
}
......@@ -184,52 +180,23 @@ public:
/** Generate a workspace with 2 spectra for test
*/
MatrixWorkspace_sptr generate2SpectraTestWorkspace() {
vector<double> data;
data.push_back(1);
data.push_back(2);
data.push_back(1);
data.push_back(1);
data.push_back(9);
data.push_back(11);
data.push_back(13);
data.push_back(20);
data.push_back(24);
data.push_back(32);
data.push_back(28);
data.push_back(48);
data.push_back(42);
data.push_back(77);
data.push_back(67);
data.push_back(33);
data.push_back(27);
data.push_back(20);
data.push_back(9);
data.push_back(2);
vector<double> data{1, 2, 1, 1, 9, 11, 13, 20, 24, 32,
28, 48, 42, 77, 67, 33, 27, 20, 9, 2};
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(
WorkspaceFactory::Instance().create("Workspace2D", 2, data.size(),
data.size()));
// Workspace index = 0
MantidVec &vecX = ws->dataX(0);
MantidVec &vecY = ws->dataY(0);
MantidVec &vecE = ws->dataE(0);
for (size_t i = 0; i < data.size(); ++i) {
vecX[i] = static_cast<double>(i);
vecY[i] = 0.0;
vecE[i] = 1.0;
}
ws->mutableY(0).assign(data.size(), 0.0);
ws->mutableE(0).assign(data.size(), 1.0);
std::iota(ws->mutableX(0).begin(), ws->mutableX(0).end(), 0);
// Workspace index = 1
MantidVec &vecX1 = ws->dataX(1);
MantidVec &vecY1 = ws->dataY(1);
MantidVec &vecE1 = ws->dataE(1);
for (size_t i = 0; i < data.size(); ++i) {
vecX1[i] = static_cast<double>(i);
vecY1[i] = data[i];
vecE1[i] = sqrt(data[i]);
}
ws->mutableY(1).assign(data.cbegin(), data.cend());
std::iota(ws->mutableX(1).begin(), ws->mutableX(1).end(), 0);
std::transform(ws->y(1).cbegin(), ws->y(1).cend(), ws->mutableE(1).begin(),
[](const double &y) { return sqrt(y); });
return ws;
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment