Skip to content

Commit

Permalink
Merge pull request #18767 from mantidproject/18755_HistogramData_roll…
Browse files Browse the repository at this point in the history
…out_CF_to_RN

HistogramData rollout: ConvFit.cpp to ResNorm.cpp
  • Loading branch information
peterfpeterson committed Feb 14, 2017
2 parents 651ed80 + 2300488 commit 348d5cd
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 77 deletions.
29 changes: 9 additions & 20 deletions MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp
Expand Up @@ -7,12 +7,10 @@
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/FunctionDomain1D.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/TextAxis.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidGeometry/Instrument.h"

#include <QDoubleValidator>
#include <QFileInfo>
#include <QMenu>

#include <qwt_plot.h>
Expand Down Expand Up @@ -1108,28 +1106,19 @@ void ConvFit::plotGuess() {
m_cfInputWS->binIndexOf(m_dblManager->value(m_properties["EndX"]));
const size_t nData = binIndexHigh - binIndexLow;

std::vector<double> inputXData(nData);
const Mantid::MantidVec &XValues = m_cfInputWS->readX(0);
const bool isHistogram = m_cfInputWS->isHistogramData();
const auto &xPoints = m_cfInputWS->points(0);

for (size_t i = 0; i < nData; i++) {
if (isHistogram) {
inputXData[i] =
0.5 * (XValues[binIndexLow + i] + XValues[binIndexLow + i + 1]);
} else {
inputXData[i] = XValues[binIndexLow + i];
}
}
std::vector<double> dataX(nData);
std::copy(&xPoints[binIndexLow], &xPoints[binIndexLow + nData],
dataX.begin());

FunctionDomain1DVector domain(inputXData);
FunctionDomain1DVector domain(dataX);
FunctionValues outputData(domain);
function->function(domain, outputData);

QVector<double> dataX, dataY;

std::vector<double> dataY(nData);
for (size_t i = 0; i < nData; i++) {
dataX.append(inputXData[i]);
dataY.append(outputData.getCalculated(i));
dataY[i] = outputData.getCalculated(i);
}

IAlgorithm_sptr createWsAlg =
Expand All @@ -1139,8 +1128,8 @@ void ConvFit::plotGuess() {
createWsAlg->setLogging(false);
createWsAlg->setProperty("OutputWorkspace", "__GuessAnon");
createWsAlg->setProperty("NSpec", 1);
createWsAlg->setProperty("DataX", dataX.toStdVector());
createWsAlg->setProperty("DataY", dataY.toStdVector());
createWsAlg->setProperty("DataX", dataX);
createWsAlg->setProperty("DataY", dataY);
createWsAlg->execute();
MatrixWorkspace_sptr guessWs = createWsAlg->getProperty("OutputWorkspace");

Expand Down
9 changes: 2 additions & 7 deletions MantidQt/CustomInterfaces/src/Indirect/CorrectionsTab.cpp
@@ -1,12 +1,7 @@
#include "MantidQtCustomInterfaces/Indirect/CorrectionsTab.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/AnalysisDataService.h"
#include "boost/shared_ptr.hpp"

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <QSettings>
#include <QString>

using namespace Mantid::API;

Expand Down Expand Up @@ -52,8 +47,8 @@ bool CorrectionsTab::checkWorkspaceBinningMatches(
MatrixWorkspace_const_sptr left, MatrixWorkspace_const_sptr right) {
if (left && right) // check the workspaces actually point to something first
{
auto leftX = left->readX(0);
auto rightX = right->readX(0);
const auto leftX = left->x(0);
const auto rightX = right->x(0);
return std::equal(leftX.begin(), leftX.end(), rightX.begin());
} else {
throw std::runtime_error("CorrectionsTab: One of the operands is an "
Expand Down
4 changes: 2 additions & 2 deletions MantidQt/CustomInterfaces/src/Indirect/ISISCalibration.cpp
Expand Up @@ -411,7 +411,7 @@ void ISISCalibration::calPlotRaw() {
MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve(wsname.toStdString()));

const Mantid::MantidVec &dataX = input->readX(0);
const auto &dataX = input->x(0);
QPair<double, double> range(dataX.front(), dataX.back());

m_uiForm.ppCalibration->clear();
Expand Down Expand Up @@ -491,7 +491,7 @@ void ISISCalibration::calPlotEnergy() {
return;
}

const Mantid::MantidVec &dataX = energyWs->readX(0);
const auto &dataX = energyWs->x(0);
QPair<double, double> range(dataX.front(), dataX.back());

auto resBackground = m_uiForm.ppResolution->getRangeSelector("ResBackground");
Expand Down
2 changes: 1 addition & 1 deletion MantidQt/CustomInterfaces/src/Indirect/ISISDiagnostics.cpp
Expand Up @@ -311,7 +311,7 @@ void ISISDiagnostics::handleNewFile() {
Mantid::API::AnalysisDataService::Instance().retrieve(
wsname.toStdString()));

const Mantid::MantidVec &dataX = input->readX(0);
const auto &dataX = input->x(0);
QPair<double, double> range(dataX.front(), dataX.back());
int previewSpec =
static_cast<int>(m_dblManager->value(m_properties["PreviewSpec"])) -
Expand Down
10 changes: 4 additions & 6 deletions MantidQt/CustomInterfaces/src/Indirect/ISISEnergyTransfer.cpp
Expand Up @@ -2,11 +2,9 @@

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidGeometry/IDTypes.h"
#include "MantidQtCustomInterfaces/UserInputValidator.h"

#include <QFileInfo>
#include <QInputDialog>

using namespace Mantid::API;
using MantidQt::API::BatchAlgorithmRunner;
Expand Down Expand Up @@ -168,8 +166,8 @@ bool ISISEnergyTransfer::validate() {
if (m_uiForm.ckBackgroundRemoval->isChecked()) {
MatrixWorkspace_sptr tempWs =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name);
const double minBack = tempWs->readX(0)[0];
const double maxBack = tempWs->readX(0)[tempWs->blocksize()];
const double minBack = tempWs->x(0)[0];
const double maxBack = tempWs->x(0)[tempWs->blocksize()];

if (m_uiForm.spBackgroundStart->value() < minBack) {
uiv.addErrorMessage("The Start of Background Removal is less than the "
Expand Down Expand Up @@ -557,8 +555,8 @@ void ISISEnergyTransfer::plotRaw() {
if (m_uiForm.ckBackgroundRemoval->isChecked()) {
MatrixWorkspace_sptr tempWs =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name);
const double minBack = tempWs->readX(0)[0];
const double maxBack = tempWs->readX(0)[tempWs->blocksize()];
const double minBack = tempWs->x(0)[0];
const double maxBack = tempWs->x(0)[tempWs->blocksize()];

if (startBack < minBack) {
emit showMessageBox("The Start of Background Removal is less than the "
Expand Down
Expand Up @@ -216,7 +216,7 @@ std::map<std::string, double> IndirectDataReductionTab::getRangesFromInstrument(
convUnitsAlg->execute();
MatrixWorkspace_sptr tofWs = convUnitsAlg->getProperty("OutputWorkspace");

std::vector<double> tofData = tofWs->readX(0);
const auto tofData = tofWs->x(0);
ranges["peak-start-tof"] = tofData[0];
ranges["peak-end-tof"] = tofData[2];
ranges["back-start-tof"] = tofData[3];
Expand Down
7 changes: 2 additions & 5 deletions MantidQt/CustomInterfaces/src/Indirect/IndirectSymmetrise.cpp
Expand Up @@ -3,9 +3,6 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidKernel/Logger.h"
#include "MantidQtCustomInterfaces/UserInputValidator.h"

#include <QFileInfo>

namespace {
Mantid::Kernel::Logger g_log("IndirectSymmetrise");
Expand Down Expand Up @@ -423,8 +420,8 @@ void IndirectSymmetrise::previewAlgDone(bool error) {
int positiveIndex = propsTable->getColumn("PositiveXMinIndex")->cell<int>(0);

// Get the Y values for each XCut and the difference between them
double negativeY = sampleWS->dataY(0)[negativeIndex];
double positiveY = sampleWS->dataY(0)[positiveIndex];
double negativeY = sampleWS->y(0)[negativeIndex];
double positiveY = sampleWS->y(0)[positiveIndex];
double deltaY = fabs(negativeY - positiveY);

// Show values in property tree
Expand Down
9 changes: 2 additions & 7 deletions MantidQt/CustomInterfaces/src/Indirect/Iqt.cpp
Expand Up @@ -5,12 +5,7 @@
#include "MantidGeometry/Instrument.h"
#include "MantidQtMantidWidgets/RangeSelector.h"

#include <QFileInfo>

#include <qwt_plot.h>
#include <boost/lexical_cast.hpp>

#include <cmath>

namespace {
Mantid::Kernel::Logger g_log("Iqt");
Expand Down Expand Up @@ -154,7 +149,7 @@ void Iqt::PlotTiled() {

// Find x value where y > 1 in 0th spectra
const auto tiledPlotWsName = outWs->getName() + "_tiled";
const auto y_data = outWs->dataY(0);
const auto y_data = outWs->y(0);
const auto y_data_length = y_data.size();
auto crop_index = y_data.size();
for (size_t i = 0; i < y_data_length; i++) {
Expand All @@ -163,7 +158,7 @@ void Iqt::PlotTiled() {
break;
}
}
const auto crop_value = outWs->dataX(0)[crop_index];
const auto crop_value = outWs->x(0)[crop_index];

// Clone workspace before cropping to keep in ADS
IAlgorithm_sptr clone = AlgorithmManager::Instance().create("CloneWorkspace");
Expand Down
35 changes: 11 additions & 24 deletions MantidQt/CustomInterfaces/src/Indirect/IqtFit.cpp
Expand Up @@ -9,9 +9,7 @@
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/WorkspaceGroup.h"

#include <QFileInfo>
#include <QMenu>
#include <math.h>

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
Expand Down Expand Up @@ -616,8 +614,8 @@ void IqtFit::setDefaultParameters(const QString &name) {
double background = m_dblManager->value(m_properties["BackgroundA0"]);
// intensity is always 1-background
m_dblManager->setValue(m_properties[name + ".Intensity"], 1.0 - background);
auto x = m_iqtFInputWS->readX(0);
auto y = m_iqtFInputWS->readY(0);
auto x = m_iqtFInputWS->x(0);
auto y = m_iqtFInputWS->y(0);
double tau = 0;

if (x.size() > 4) {
Expand Down Expand Up @@ -944,40 +942,29 @@ void IqtFit::plotGuess(QtProperty *) {
m_iqtFRangeManager->value(m_properties["EndX"]));
const size_t nData = binIndxHigh - binIndxLow;

std::vector<double> inputXData(nData);
const auto &xPoints = m_iqtFInputWS->points(0);

const Mantid::MantidVec &XValues = m_iqtFInputWS->readX(0);
std::vector<double> dataX(nData);
std::copy(&xPoints[binIndxLow], &xPoints[binIndxLow + nData], dataX.begin());

const bool isHistogram = m_iqtFInputWS->isHistogramData();

for (size_t i = 0; i < nData; i++) {
if (isHistogram)
inputXData[i] =
0.5 * (XValues[binIndxLow + i] + XValues[binIndxLow + i + 1]);
else
inputXData[i] = XValues[binIndxLow + i];
}

FunctionDomain1DVector domain(inputXData);
FunctionDomain1DVector domain(dataX);
FunctionValues outputData(domain);
function->function(domain, outputData);

QVector<double> dataX;
QVector<double> dataY;

std::vector<double> dataY(nData);
for (size_t i = 0; i < nData; i++) {
dataX.append(inputXData[i]);
dataY.append(outputData.getCalculated(i));
dataY[i] = outputData.getCalculated(i);
}

IAlgorithm_sptr createWsAlg =
AlgorithmManager::Instance().create("CreateWorkspace");
createWsAlg->initialize();
createWsAlg->setChild(true);
createWsAlg->setLogging(false);
createWsAlg->setProperty("OutputWorkspace", "__GuessAnon");
createWsAlg->setProperty("NSpec", 1);
createWsAlg->setProperty("DataX", dataX.toStdVector());
createWsAlg->setProperty("DataY", dataY.toStdVector());
createWsAlg->setProperty("DataX", dataX);
createWsAlg->setProperty("DataY", dataY);
createWsAlg->execute();
MatrixWorkspace_sptr guessWs = createWsAlg->getProperty("OutputWorkspace");

Expand Down
8 changes: 4 additions & 4 deletions MantidQt/CustomInterfaces/src/Indirect/ResNorm.cpp
Expand Up @@ -289,12 +289,12 @@ void ResNorm::previewSpecChanged(int value) {
fitWsName);

MatrixWorkspace_sptr fit = WorkspaceFactory::Instance().create(fitWs, 1);
fit->setX(0, fitWs->refX(1));
fit->dataY(0) = fitWs->readY(1);
fit->dataE(0) = fitWs->readE(1);
fit->setSharedX(0, fit->sharedX(1));
fit->setSharedY(0, fit->sharedY(1));
fit->setSharedE(0, fit->sharedE(1));

for (size_t i = 0; i < fit->blocksize(); i++)
fit->dataY(0)[i] /= scaleFactors->cell<double>(m_previewSpec);
fit->mutableY(0)[i] /= scaleFactors->cell<double>(m_previewSpec);

m_uiForm.ppPlot->addSpectrum("Fit", fit, 0, Qt::red);
}
Expand Down

0 comments on commit 348d5cd

Please sign in to comment.