Newer
Older
/*********************************************************************************
* PLEASE READ THIS!!!!!!!
*
* This collection of functions MAY NOT be used in any test from a package
*below
* DataObjects (e.g. Kernel, Geometry, API).
* Conversely, this file MAY NOT be modified to use anything from a package
*higher
* than DataObjects (e.g. any algorithm), even if going via the factory.
*********************************************************************************/
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidTestHelpers/InstrumentCreationHelper.h"
#include "MantidAPI/Algorithm.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidAPI/IAlgorithm.h"
#include "MantidAPI/NumericAxis.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/SpectraAxis.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Instrument/Component.h"
Gigg, Martyn Anthony
committed
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/Goniometer.h"
Gigg, Martyn Anthony
committed
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
Gigg, Martyn Anthony
committed
#include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidHistogramData/LinearGenerator.h"
#include "MantidKernel/MersenneTwister.h"
Janik Zikovsky
committed
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/VectorHelper.h"
#include "MantidKernel/make_unique.h"
#include <sstream>
namespace WorkspaceCreationHelper {
using namespace Mantid;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::HistogramData;
using Mantid::MantidVec;
using Mantid::MantidVecPtr;
MockAlgorithm::MockAlgorithm(size_t nSteps)
: m_Progress(
Mantid::Kernel::make_unique<API::Progress>(this, 0.0, 1.0, nSteps)) {}
EPPTableRow::EPPTableRow(const double peakCentre_, const double sigma_,
const double height_, const FitStatus fitStatus_)
: peakCentre(peakCentre_), peakCentreError(0), sigma(sigma_), sigmaError(0),
height(height_), heightError(0), chiSq(0), fitStatus(fitStatus_) {}
/**
* @param name :: The name of the workspace
* @param ws :: The workspace object
*/
void storeWS(const std::string &name, Mantid::API::Workspace_sptr ws) {
Mantid::API::AnalysisDataService::Instance().add(name, ws);
}
Gigg, Martyn Anthony
committed
/**
* Deletes a workspace
* @param name :: The name of the workspace
*/
void removeWS(const std::string &name) {
Mantid::API::AnalysisDataService::Instance().remove(name);
}
Gigg, Martyn Anthony
committed
/**
* Creates bin or point based histograms based on the data passed
* in for Y and E values and the bool specified.
*
* @param isHistogram :: Specifies whether the returned histogram
* should use points or bin edges for the x axis. True gives bin edges.
* @param yAxis :: Takes an rvalue (move) of the y axis for the new histogram
* @param eAxis :: Takes an rvalue (move) of the e axis for the new histogram
* @return :: Returns a histogram with the user specified X axis type
* and the data the user passed in.
*/
template <typename YType, typename EType>
Histogram createHisto(bool isHistogram, YType &&yAxis, EType &&eAxis) {
// We don't need to check if y.size() == e.size() as the histogram
// type does this at construction
const size_t yValsSize = yAxis.size();
if (isHistogram) {
BinEdges xAxis(yValsSize + 1, LinearGenerator(1, 1));
Histogram histo{std::move(xAxis), std::move(yAxis), std::move(eAxis)};
return histo;
} else {
Points xAxis(yValsSize, LinearGenerator(1, 1));
Histogram pointsHisto{std::move(xAxis), std::move(yAxis), std::move(eAxis)};
return pointsHisto;
}
}
Workspace2D_sptr create1DWorkspaceRand(int size, bool isHisto) {
Federico Montesino Pouzols
committed
MersenneTwister randomGen(DateAndTime::getCurrentTime().nanoseconds(), 0,
std::numeric_limits<int>::max());
Federico Montesino Pouzols
committed
auto randFunc = [&randomGen] { return randomGen.nextValue(); };
Counts counts(size, randFunc);
CountStandardDeviations errorVals(size, randFunc);
Federico Montesino Pouzols
committed
auto retVal = boost::make_shared<Workspace2D>();
retVal->initialize(1, createHisto(isHisto, counts, errorVals));
Gigg, Martyn Anthony
committed
Workspace2D_sptr create1DWorkspaceConstant(int size, double value, double error,
bool isHisto) {
Counts yVals(size, value);
CountStandardDeviations errVals(size, error);
auto retVal = boost::make_shared<Workspace2D>();
retVal->initialize(1, createHisto(isHisto, yVals, errVals));
Janik Zikovsky
committed
Workspace2D_sptr create1DWorkspaceConstantWithXerror(int size, double value,
double error,
auto ws = create1DWorkspaceConstant(size, value, error, isHisto);
auto dx1 = Kernel::make_cow<HistogramData::HistogramDx>(size, xError);
ws->setSharedDx(0, dx1);
return ws;
}
Workspace2D_sptr create1DWorkspaceFib(int size, bool isHisto) {
BinEdges xVals(size + 1, LinearGenerator(1, 1));
Counts yVals(size, FibSeries<double>());
CountStandardDeviations errVals(size);
auto retVal = boost::make_shared<Workspace2D>();
retVal->initialize(1, createHisto(isHisto, yVals, errVals));
Gigg, Martyn Anthony
committed
Workspace2D_sptr create2DWorkspace(int nhist, int numBoundaries) {
return create2DWorkspaceBinned(nhist, numBoundaries);
Janik Zikovsky
committed
/** Create a Workspace2D where the Y value at each bin is
* == to the workspace index
* @param nhist :: # histograms
* @param numBoundaries :: # of bins
* @return Workspace2D
*/
Workspace2D_sptr create2DWorkspaceWhereYIsWorkspaceIndex(int nhist,
Workspace2D_sptr out = create2DWorkspaceBinned(nhist, numBoundaries);
for (int workspaceIndex = 0; workspaceIndex < nhist; workspaceIndex++) {
std::vector<double> yValues(numBoundaries,
static_cast<double>(workspaceIndex));
out->mutableY(workspaceIndex) = std::move(yValues);
Workspace2D_sptr create2DWorkspaceThetaVsTOF(int nHist, int nBins) {
Workspace2D_sptr outputWS = create2DWorkspaceBinned(nHist, nBins);
auto const newAxis = new NumericAxis(nHist);
outputWS->replaceAxis(1, newAxis);
newAxis->unit() = boost::make_shared<Units::Degrees>();
for (int i = 0; i < nHist; ++i) {
newAxis->setValue(i, i + 1);
Gigg, Martyn Anthony
committed
create2DWorkspaceWithValues(int64_t nHist, int64_t nBins, bool isHist,
const std::set<int64_t> &maskedWorkspaceIndices,
double xVal, double yVal, double eVal) {
auto x1 = Kernel::make_cow<HistogramData::HistogramX>(
isHist ? nBins + 1 : nBins, LinearGenerator(xVal, 1.0));
Counts y1(nBins, yVal);
CountStandardDeviations e1(nBins, eVal);
auto retVal = boost::make_shared<Workspace2D>();
retVal->initialize(nHist, isHist ? nBins + 1 : nBins, nBins);
for (int i = 0; i < nHist; i++) {
retVal->setX(i, x1);
retVal->setCounts(i, y1);
retVal->setCountStandardDeviations(i, e1);
retVal->getSpectrum(i).setDetectorID(i);
Loading
Loading full blame...