本文整理汇总了C++中api::MatrixWorkspace_sptr::getAxis方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr::getAxis方法的具体用法?C++ MatrixWorkspace_sptr::getAxis怎么用?C++ MatrixWorkspace_sptr::getAxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::MatrixWorkspace_sptr
的用法示例。
在下文中一共展示了MatrixWorkspace_sptr::getAxis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setTofInWS
void ConvertEmptyToTof::setTofInWS(const std::vector<double> &tofAxis,
API::MatrixWorkspace_sptr outputWS) {
const size_t numberOfSpectra = m_inputWS->getNumberHistograms();
int64_t numberOfSpectraInt64 =
static_cast<int64_t>(numberOfSpectra); // cast to make openmp happy
g_log.debug() << "Setting the TOF X Axis for numberOfSpectra="
<< numberOfSpectra << '\n';
Progress prog(this, 0.0, 0.2, numberOfSpectra);
PARALLEL_FOR2(m_inputWS, outputWS)
for (int64_t i = 0; i < numberOfSpectraInt64; ++i) {
PARALLEL_START_INTERUPT_REGION
// Just copy over
outputWS->dataY(i) = m_inputWS->readY(i);
outputWS->dataE(i) = m_inputWS->readE(i);
// copy
outputWS->setX(i, tofAxis);
prog.report();
PARALLEL_END_INTERUPT_REGION
} // end for i
PARALLEL_CHECK_INTERUPT_REGION
outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
}
示例2: convertInputToElasticQ
/**
* Converts the input workspaces to spectrum axis to ElasticQ and adds it to the
* ADS to be used by PlotPeakBylogValue
* @param inputWs - The MatrixWorkspace to be converted
* @param wsName - The desired name of the output workspace
*/
void ConvolutionFitSequential::convertInputToElasticQ(
API::MatrixWorkspace_sptr &inputWs, const std::string &wsName) {
auto axis = inputWs->getAxis(1);
if (axis->isSpectra()) {
auto convSpec = createChildAlgorithm("ConvertSpectrumAxis");
// Store in ADS to allow use by PlotPeakByLogValue
convSpec->setAlwaysStoreInADS(true);
convSpec->setProperty("InputWorkSpace", inputWs);
convSpec->setProperty("OutputWorkSpace", wsName);
convSpec->setProperty("Target", "ElasticQ");
convSpec->setProperty("EMode", "Indirect");
convSpec->executeAsChildAlg();
} else if (axis->isNumeric()) {
// Check that units are Momentum Transfer
if (axis->unit()->unitID() != "MomentumTransfer") {
throw std::runtime_error("Input must have axis values of Q");
}
auto cloneWs = createChildAlgorithm("CloneWorkspace");
// Store in ADS to allow use by PlotPeakByLogValue
cloneWs->setAlwaysStoreInADS(true);
cloneWs->setProperty("InputWorkspace", inputWs);
cloneWs->setProperty("OutputWorkspace", wsName);
cloneWs->executeAsChildAlg();
} else {
throw std::runtime_error(
"Input workspace must have either spectra or numeric axis.");
}
}
示例3: loadNonSpectraAxis
/**
* Loads the information contained in non-Spectra (ie, Text or Numeric) axis in the Nexus
* file into the workspace.
* @param local_workspace :: pointer to workspace object
* @param data :: reference to the NeXuS data for the axis
*/
void LoadNexusProcessed::loadNonSpectraAxis(API::MatrixWorkspace_sptr local_workspace, NXData & data)
{
Mantid::API::Axis* axis = local_workspace->getAxis(1);
if ( axis->isNumeric() )
{
NXDouble axisData = data.openNXDouble("axis2");
axisData.load();
for ( int i = 0; i < static_cast<int>(axis->length()); i++ )
{
axis->setValue(i, axisData[i]);
}
}
else if ( axis->isText() )
{
// We must cast the axis object to TextAxis so we may use ->setLabel
Mantid::API::TextAxis* textAxis = dynamic_cast<Mantid::API::TextAxis*>(axis);
NXChar axisData = data.openNXChar("axis2");
axisData.load();
std::string axisLabels = axisData();
// Use boost::tokenizer to split up the input
boost::char_separator<char> sep("\n");
boost::tokenizer<boost::char_separator<char> > tokenizer(axisLabels, sep);
boost::tokenizer<boost::char_separator<char> >::iterator tokIter;
int i = 0;
for ( tokIter = tokenizer.begin(); tokIter != tokenizer.end(); ++tokIter )
{
textAxis->setLabel(i, *tokIter);
++i;
}
}
}
示例4: getMonitorWorkspace
/** Checks and retrieves the monitor spectrum out of the input workspace
* @param inputWorkspace The input workspace.
* @param wsID The workspace ID.
* @returns A workspace containing the monitor spectrum only
* @throw std::runtime_error If the properties are invalid
*/
API::MatrixWorkspace_sptr NormaliseToMonitor::getMonitorWorkspace(API::MatrixWorkspace_sptr inputWorkspace,int &wsID)
{
// Get the workspace from the ADS. Will throw if it's not there.
MatrixWorkspace_sptr monitorWS = getProperty("MonitorWorkspace");
wsID = getProperty("MonitorWorkspaceIndex");
// Check that it's a single spectrum workspace
if ( static_cast<int>(monitorWS->getNumberHistograms()) < wsID )
{
throw std::runtime_error("The MonitorWorkspace must contain the MonitorWorkspaceIndex");
}
// Check that the two workspace come from the same instrument
if ( monitorWS->getInstrument()->getName() != inputWorkspace->getInstrument()->getName() )
{
throw std::runtime_error("The Input and Monitor workspaces must come from the same instrument");
}
// Check that they're in the same units
if ( monitorWS->getAxis(0)->unit()->unitID() != inputWorkspace->getAxis(0)->unit()->unitID() )
{
throw std::runtime_error("The Input and Monitor workspaces must have the same unit");
}
// In this case we need to test whether the bins in the monitor workspace match
m_commonBins = (m_commonBins &&
API::WorkspaceHelpers::matchingBins(inputWorkspace,monitorWS,true) );
// If the workspace passes all these tests, make a local copy because it will get changed
return this->extractMonitorSpectrum(monitorWS,wsID);
}
示例5: if
void StripVanadiumPeaks2::exec(){
// 1. Process input/output
API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
std::string outputWSName = getPropertyValue("OutputWorkspace");
int singleIndex = getProperty("WorkspaceIndex");
int param_fwhm = getProperty("FWHM");
int param_tolerance = getProperty("Tolerance");
bool singleSpectrum = !isEmpty(singleIndex);
// 2. Call StripPeaks
std::string peakpositions;
std::string unit = inputWS->getAxis(0)->unit()->unitID();
if (unit == "dSpacing")
{
peakpositions = "0.5044,0.5191,0.5350,0.5526,0.5936,0.6178,0.6453,0.6768,0.7134,0.7566,0.8089,0.8737,0.9571,1.0701,1.2356,1.5133,2.1401";
}
else if (unit == "MomentumTransfer")
{
g_log.error() << "Unit MomentumTransfer (Q-space) is NOT supported by StripVanadiumPeaks now.\n";
throw std::invalid_argument("Q-space is not supported");
// Comment out next line as it won't be reached.
//peakpositions = "2.9359, 4.1520, 5.0851, 5.8716, 6.5648, 7.1915, 7.7676, 8.3045, 8.8074, 9.2837, 9.7368, 10.1703, 10.5849, 11.3702, 11.7443, 12.1040, 12.4568";
} else {
g_log.error() << "Unit " << unit << " Is NOT supported by StripVanadiumPeaks, which only supports d-spacing" << std::endl;
throw std::invalid_argument("Not supported unit");
}
// Call StripPeak
double pro0 = 0.0;
double prof = 1.0;
bool sublog = true;
IAlgorithm_sptr stripPeaks = createChildAlgorithm("StripPeaks", pro0, prof, sublog);
stripPeaks->setProperty("InputWorkspace", inputWS);
stripPeaks->setPropertyValue("OutputWorkspace", outputWSName);
stripPeaks->setProperty("FWHM", param_fwhm);
stripPeaks->setProperty("Tolerance", param_tolerance);
stripPeaks->setPropertyValue("PeakPositions", peakpositions);
stripPeaks->setProperty<std::string>("BackgroundType", getProperty("BackgroundType"));
stripPeaks->setProperty<bool>("HighBackground", getProperty("HighBackground"));
if (singleSpectrum){
stripPeaks->setProperty("WorkspaceIndex", singleIndex);
}
stripPeaks->setProperty<double>("PeakPositionTolerance", getProperty("PeakPositionTolerance"));
stripPeaks->executeAsChildAlg();
// 3. Get and set output workspace
// API::MatrixWorkspace_sptr outputWS = AnalysisDataService::Instance().retrieveWS<API::MatrixWorkspace_sptr>(outputWSName);
// boost::shared_ptr<API::Workspace> outputWS = AnalysisDataService::Instance().retrieve(outputWSName);
API::MatrixWorkspace_sptr outputWS = stripPeaks->getProperty("OutputWorkspace");
this->setProperty("OutputWorkspace", outputWS);
return;
}
示例6: initialize
/** Initialization method:
@param bkgWS -- shared pointer to the workspace which contains background
@param sourceWS -- shared pointer to the workspace to remove background from
@param emode -- energy conversion mode used during internal units conversion
(0 -- elastic, 1-direct, 2 indirect, as defined in Units conversion
@param pLog -- pointer to the logger class which would report errors
@param nThreads -- number of threads to be used for background removal
@param inPlace -- if the background removal occurs from the existing workspace
or target workspace has to be cloned.
*/
void BackgroundHelper::initialize(const API::MatrixWorkspace_const_sptr &bkgWS,
const API::MatrixWorkspace_sptr &sourceWS,
int emode, Kernel::Logger *pLog, int nThreads,
bool inPlace) {
m_bgWs = bkgWS;
m_wkWS = sourceWS;
m_Emode = emode;
m_pgLog = pLog;
m_inPlace = inPlace;
std::string bgUnits = bkgWS->getAxis(0)->unit()->unitID();
if (bgUnits != "TOF")
throw std::invalid_argument(" Background Workspace: " + bkgWS->getName() +
" should be in the units of TOF");
if (!(bkgWS->getNumberHistograms() == 1 ||
sourceWS->getNumberHistograms() == bkgWS->getNumberHistograms()))
throw std::invalid_argument(" Background Workspace: " + bkgWS->getName() +
" should have the same number of spectra as "
"source workspace or be a single histogram "
"workspace");
auto WSUnit = sourceWS->getAxis(0)->unit();
if (!WSUnit)
throw std::invalid_argument(" Source Workspace: " + sourceWS->getName() +
" should have units");
Geometry::IComponent_const_sptr source =
sourceWS->getInstrument()->getSource();
m_Sample = sourceWS->getInstrument()->getSample();
if ((!source) || (!m_Sample))
throw std::invalid_argument(
"Instrument on Source workspace:" + sourceWS->getName() +
"is not sufficiently defined: failed to get source and/or sample");
m_L1 = source->getDistance(*m_Sample);
// just in case.
this->deleteUnitsConverters();
// allocate the array of units converters to avoid units reallocation within a
// loop
m_WSUnit.assign(nThreads, NULL);
for (int i = 0; i < nThreads; i++) {
m_WSUnit[i] = WSUnit->clone();
}
m_singleValueBackground = false;
if (bkgWS->getNumberHistograms() == 0)
m_singleValueBackground = true;
const MantidVec &dataX = bkgWS->dataX(0);
const MantidVec &dataY = bkgWS->dataY(0);
// const MantidVec& dataE = bkgWS->dataE(0);
m_NBg = dataY[0];
m_dtBg = dataX[1] - dataX[0];
// m_ErrSq = dataE[0]*dataE[0]; // needs further clarification
m_Efix = this->getEi(sourceWS);
}
示例7: checkInputsForNumericWorkspace
/**
* Validation of the inputs of the RingProfile algorithm.
*
* Inside this method, the Workspace is considered a 2D Matrix, where each
*spectrum is
* the rows of the matrix and have the variation in axis0. The columns of the
*matrix
* is the position of dataX(0)
*
* The main validation are:
* - the centre of the ring is inside the image it self.
* - The minimum ring is smaller than the limits of the image to allow
* @param inputWS: pointer to the input workspace
*/
void RingProfile::checkInputsForNumericWorkspace(
const API::MatrixWorkspace_sptr inputWS) {
g_log.notice() << "CheckingInputs For Numeric Workspace" << std::endl;
// The Axis0 is defined by the values of readX inside the spectra of the
// workspace.
// The limits of this axis will be get by inspection of the readX vector
// taking the first
// and the last value.
// check that centre is inside the range available for the instrument
const MantidVec &refX = inputWS->readX(inputWS->getNumberHistograms() / 2);
// get the limits of the axis 0 (X)
double min_v_x, max_v_x;
min_v_x = std::min(refX[0], refX[refX.size() - 1]);
max_v_x = std::max(refX[0], refX[refX.size() - 1]);
g_log.notice() << "Limits X = " << min_v_x << " " << max_v_x << std::endl;
// check centre is inside the X domain
if (centre_x < min_v_x || centre_x > max_v_x) {
std::stringstream s;
s << "The input value for centre (X=" << centre_x
<< ") is outside the limits of the instrument [" << min_v_x << ", "
<< max_v_x << "]";
throw std::invalid_argument(s.str());
}
// The Axis1 is defined by the spectra inside the workspace. Its limits and
// values are given by the
// ws->getAxis(1)
// get the limits of the axis1 (Y)
API::NumericAxis *oldAxis2 =
dynamic_cast<API::NumericAxis *>(inputWS->getAxis(1));
// we cannot have the positions in Y direction without a NumericAxis
if (!oldAxis2)
throw std::invalid_argument("Vertical axis is not a numeric axis. If it is "
"a spectra axis try running "
"ConvertSpectrumAxis first.");
double min_v_y = std::min(oldAxis2->getMin(), oldAxis2->getMax());
double max_v_y = std::max(oldAxis2->getMin(), oldAxis2->getMax());
g_log.notice() << "Limits Y = " << min_v_y << " " << max_v_y << std::endl;
// check centre is inside the Y domain
if (centre_y < min_v_y || centre_y > max_v_y) {
std::stringstream s;
s << "The input value for centre (Y=" << centre_y
<< ") is outside the limits of the instrument [" << min_v_y << ", "
<< max_v_y << "]";
throw std::invalid_argument(s.str());
}
g_log.notice() << "Centre: " << centre_x << " " << centre_y << std::endl;
// check minradius is inside the limits of the region of the instrument
if (centre_x - min_radius > max_v_x || centre_x + min_radius < min_v_x ||
centre_y - min_radius > max_v_y || centre_y + min_radius < min_v_y)
throw std::invalid_argument(
"The minimun radius is outside the region of the instrument");
}
示例8: getMinBinSizeForNumericImage
double RadiusSum::getMinBinSizeForNumericImage(API::MatrixWorkspace_sptr inWS) {
// The pixel dimensions:
// - width: image width/ number of pixels in one row
// - height: image height/ number of pixels in one column
// The minimum bin size is the smallest value between this two values.
std::vector<double> boundaries = getBoundariesOfNumericImage(inWS);
const MantidVec &refX = inWS->readX(inputWS->getNumberHistograms() / 2);
int nX = static_cast<int>(refX.size());
int nY = static_cast<int>(inWS->getAxis(1)->length());
// remembering boundaries is defined as { xMin, xMax, yMin, yMax}
return std::min(((boundaries[1] - boundaries[0]) / nX),
((boundaries[3] - boundaries[2]) / nY));
}
示例9: convertUnitsToDSpacing
/// Run ConvertUnits as a sub-algorithm to convert to dSpacing
MatrixWorkspace_sptr DiffractionFocussing::convertUnitsToDSpacing(const API::MatrixWorkspace_sptr& workspace)
{
const std::string CONVERSION_UNIT = "dSpacing";
Unit_const_sptr xUnit = workspace->getAxis(0)->unit();
g_log.information() << "Converting units from "<< xUnit->label() << " to " << CONVERSION_UNIT<<".\n";
API::IAlgorithm_sptr childAlg = createSubAlgorithm("ConvertUnits", 0.34, 0.66);
childAlg->setProperty("InputWorkspace", workspace);
childAlg->setPropertyValue("Target",CONVERSION_UNIT);
childAlg->executeAsSubAlg();
return childAlg->getProperty("OutputWorkspace");
}
示例10: invalid_argument
/** Assuming that the input workspace is a Numeric Image where the pixel
*positions depend on their
* relative position inside the workspace, this function extracts the position
*of the first and last
* pixel of the image.
*
* It is important that the input workspace must be a numeric image, and not an
*instrument related workspace.
* The function will raise exception (std::invalid_argument) if an invalid
*input is give.
*
* @see RadiusSum::inputWorkspaceHasInstrumentAssociated for reference.
*
* @param inWS reference to the workspace
* @return a list of values that defines the limits of the image in this order:
*Xmin, Xmax, Ymin, Ymax
*/
std::vector<double>
RadiusSum::getBoundariesOfNumericImage(API::MatrixWorkspace_sptr inWS) {
// horizontal axis
// get the pixel position in the horizontal axis from the middle of the image.
const MantidVec &refX = inWS->readX(inWS->getNumberHistograms() / 2);
double min_x, max_x;
const double &first_x(refX[0]);
const double &last_x(refX[refX.size() - 1]);
if (first_x < last_x) {
min_x = first_x;
max_x = last_x;
} else {
min_x = last_x;
max_x = first_x;
}
// vertical axis
API::NumericAxis *verticalAxis =
dynamic_cast<API::NumericAxis *>(inWS->getAxis(1));
if (!verticalAxis)
throw std::invalid_argument("Vertical axis is not a numeric axis. Can not "
"find the limits of the image.");
double min_y, max_y;
min_y = verticalAxis->getMin();
max_y = verticalAxis->getMax();
// check the assumption made that verticalAxis will provide the correct
// answer.
if (min_y > max_y) {
throw std::logic_error("Failure to get the boundaries of this image. "
"Internal logic error. Please, inform MantidHelp");
}
std::vector<double> output(4); // output = {min_x, max_x, min_y, max_y}; not
// supported in all compilers
output[0] = min_x;
output[1] = max_x;
output[2] = min_y;
output[3] = max_y;
return output;
}
示例11: getBinForPixel
/**
* Here is the main logic to perform the transformation, to calculate the bin
*position in degree for each spectrum.
*
* The first part of the method is to check if the pixel position is inside the
*ring defined as minRadio and maxRadio.
*
* To do this, it deducts the pixel position. This deduction follows the
*followin assumption:
*
* - the spectrum_index == row number
* - the position in the 'Y' direction is given by getAxis(1)[spectrum_index]
* - the position in the 'X' direction is the central point of the bin
*(dataX[column] + dataX[column+1])/2
*
* Having the position of the pixel, as defined above, if the distance is
*outside the ring defined by minRadio, maxRadio,
* it defines the bin position as -1.
*
* If the pixel is inside the ring, it calculates the angle of the pixel and
*calls fromAngleToBin to define the bin
* position.
* @param ws: pointer to the workspace
* @param spectrum_index: index of the spectrum
* @param bins_pos: bin positions (for each column inside the spectrum, the
*correspondent bin_pos)
*/
void RingProfile::getBinForPixel(const API::MatrixWorkspace_sptr ws,
int spectrum_index,
std::vector<int> &bins_pos) {
if (bins_pos.size() != ws->dataY(spectrum_index).size())
throw std::runtime_error("Invalid bin positions vector");
API::NumericAxis *oldAxis2 = dynamic_cast<API::NumericAxis *>(ws->getAxis(1));
// assumption y position is the ws->getAxis(1)(spectrum_index)
if (!oldAxis2) {
throw std::logic_error("Failed to cast workspace axis to NumericAxis");
}
// calculate ypos, the difference of y - centre and the square of this
// difference
double ypos = (*oldAxis2)(spectrum_index);
double diffy = ypos - centre_y;
double diffy_quad = pow(diffy, 2.0);
// the reference to X bins (the limits for each pixel in the horizontal
// direction)
auto xvec = ws->dataX(spectrum_index);
// for each pixel inside this row
for (size_t i = 0; i < xvec.size() - 1; i++) {
double xpos = (xvec[i] + xvec[i + 1]) /
2.0; // the x position is the centre of the bins boundaries
double diffx = xpos - centre_x;
// calculate the distance => norm of pixel position - centre
double distance = sqrt(pow(diffx, 2.0) + diffy_quad);
// check if the distance is inside the ring
if (distance < min_radius || distance > max_radius || distance == 0) {
bins_pos[i] = -1;
continue;
}
double angle = atan2(diffy, diffx);
// call fromAngleToBin (radians)
bins_pos[i] = fromAngleToBin(angle, false);
}
}
示例12: getInWSMonitorSpectrum
/** Checks and retrieves the requested spectrum out of the input workspace
* @param inputWorkspace The input workspace.
* @param spectra_num The spectra number.
* @returns A workspace containing the monitor spectrum only.
* @returns spectra number (WS ID) which is used to normalize by.
* @throw std::runtime_error If the properties are invalid
*/
API::MatrixWorkspace_sptr NormaliseToMonitor::getInWSMonitorSpectrum(
const API::MatrixWorkspace_sptr &inputWorkspace, int &spectra_num) {
// this is the index of the spectra within the workspace and we need to
// identify it either from DetID or from SpecID
// size_t spectra_num(-1);
// try monitor spectrum. If it is specified, it overrides everything
int monitorSpec = getProperty("MonitorSpectrum");
if (monitorSpec < 0) {
// Get hold of the monitor spectrum through detector ID
int monitorID = getProperty("MonitorID");
if (monitorID < 0) {
throw std::runtime_error(
"Both MonitorSpectrum and MonitorID can not be negative");
}
// set spectra of detector's ID of one selected monitor ID
std::vector<detid_t> detID(1, monitorID);
// got the index of correspondent spectra (should be only one).
auto indexList = inputWorkspace->getIndicesFromDetectorIDs(detID);
if (indexList.empty()) {
throw std::runtime_error(
"Can not find spectra, corresponding to the requested monitor ID");
}
if (indexList.size() > 1) {
throw std::runtime_error("More then one spectra corresponds to the "
"requested monitor ID, which is unheard of");
}
spectra_num = static_cast<int>(indexList[0]);
} else { // monitor spectrum is specified.
const SpectraAxis *axis =
dynamic_cast<const SpectraAxis *>(inputWorkspace->getAxis(1));
if (!axis) {
throw std::runtime_error("Cannot retrieve monitor spectrum - spectrum "
"numbers not attached to workspace");
}
auto specs = axis->getSpectraIndexMap();
if (!specs.count(monitorSpec)) {
throw std::runtime_error("Input workspace does not contain spectrum "
"number given for MonitorSpectrum");
}
spectra_num = static_cast<int>(specs[monitorSpec]);
}
return this->extractMonitorSpectrum(inputWorkspace, spectra_num);
}
示例13: setTofInWS
void ConvertEmptyToTof::setTofInWS(const std::vector<double> &tofAxis,
API::MatrixWorkspace_sptr outputWS) {
const size_t numberOfSpectra = m_inputWS->getNumberHistograms();
g_log.debug() << "Setting the TOF X Axis for numberOfSpectra="
<< numberOfSpectra << '\n';
auto axisPtr = Kernel::make_cow<HistogramData::HistogramX>(tofAxis);
HistogramData::BinEdges edges(tofAxis);
Progress prog(this, 0.0, 0.2, numberOfSpectra);
for (size_t i = 0; i < numberOfSpectra; ++i) {
// Replace bin edges with tof axis
outputWS->setBinEdges(i, edges);
prog.report();
} // end for i
outputWS->getAxis(0)->unit() = UnitFactory::Instance().create("TOF");
}
示例14: exec
void LoadDaveGrp::exec()
{
const std::string filename = this->getProperty("Filename");
int yLength = 0;
MantidVec *xAxis = new MantidVec();
MantidVec *yAxis = new MantidVec();
std::vector<MantidVec *> data;
std::vector<MantidVec *> errors;
this->ifile.open(filename.c_str());
if (this->ifile.is_open())
{
// Size of x axis
this->getAxisLength(this->xLength);
// Size of y axis
this->getAxisLength(yLength);
// This is also the number of groups (spectra)
this->nGroups = yLength;
// Read in the x axis values
this->getAxisValues(xAxis, static_cast<std::size_t>(this->xLength));
// Read in the y axis values
this->getAxisValues(yAxis, static_cast<std::size_t>(yLength));
// Read in the data
this->getData(data, errors);
}
this->ifile.close();
// Scale the x-axis if it is in micro-eV to get it to meV
const bool isUeV = this->getProperty("IsMicroEV");
if (isUeV)
{
MantidVec::iterator iter;
for (iter = xAxis->begin(); iter != xAxis->end(); ++iter)
{
*iter /= 1000.0;
}
}
// Create workspace
API::MatrixWorkspace_sptr outputWorkspace = \
boost::dynamic_pointer_cast<API::MatrixWorkspace>\
(API::WorkspaceFactory::Instance().create("Workspace2D", this->nGroups,
this->xLength, yLength));
// Force the workspace to be a distribution
outputWorkspace->isDistribution(true);
// Set the x-axis units
outputWorkspace->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create(this->getProperty("XAxisUnits"));
API::Axis* const verticalAxis = new API::NumericAxis(yLength);
// Set the y-axis units
verticalAxis->unit() = Kernel::UnitFactory::Instance().create(this->getProperty("YAxisUnits"));
outputWorkspace->replaceAxis(1, verticalAxis);
for(int i = 0; i < this->nGroups; i++)
{
outputWorkspace->dataX(i) = *xAxis;
outputWorkspace->dataY(i) = *data[i];
outputWorkspace->dataE(i) = *errors[i];
verticalAxis->setValue(i, yAxis->at(i));
delete data[i];
delete errors[i];
}
delete xAxis;
delete yAxis;
outputWorkspace->mutableRun().addProperty("Filename",filename);
this->setProperty("OutputWorkspace", outputWorkspace);
}
示例15: exec
/**
* Executes the algorithm
*/
void ScaleX::exec()
{
//Get input workspace and offset
const MatrixWorkspace_sptr inputW = getProperty("InputWorkspace");
m_algFactor = getProperty("Factor");
m_parname = getPropertyValue("InstrumentParameter");
m_combine = getProperty("Combine");
if(m_combine && m_parname.empty())
{
throw std::invalid_argument("Combine behaviour requested but the InstrumentParameter argument is blank.");
}
const std::string op = getPropertyValue("Operation");
API::MatrixWorkspace_sptr outputW = createOutputWS(inputW);
//Get number of histograms
int histnumber = static_cast<int>(inputW->getNumberHistograms());
m_progress = new API::Progress(this, 0.0, 1.0, histnumber+1);
m_progress->report("Scaling X");
m_wi_min = 0;
m_wi_max = histnumber-1;
//check if workspace indexes have been set
int tempwi_min = getProperty("IndexMin");
int tempwi_max = getProperty("IndexMax");
if ( tempwi_max != Mantid::EMPTY_INT() )
{
if ((m_wi_min <= tempwi_min) && (tempwi_min <= tempwi_max) && (tempwi_max <= m_wi_max))
{
m_wi_min = tempwi_min;
m_wi_max = tempwi_max;
}
else
{
g_log.error("Invalid Workspace Index min/max properties");
throw std::invalid_argument("Inconsistent properties defined");
}
}
// Setup appropriate binary function
const bool multiply = (op=="Multiply");
if(multiply) m_binOp = std::multiplies<double>();
else m_binOp = std::plus<double>();
//Check if its an event workspace
EventWorkspace_const_sptr eventWS = boost::dynamic_pointer_cast<const EventWorkspace>(inputW);
if (eventWS != NULL)
{
this->execEvent();
return;
}
// do the shift in X
PARALLEL_FOR2(inputW, outputW)
for (int i = 0; i < histnumber; ++i)
{
PARALLEL_START_INTERUPT_REGION
//Copy y and e data
auto & outY = outputW->dataY(i);
outY = inputW->dataY(i);
auto & outE = outputW->dataE(i);
outE = inputW->dataE(i);
auto & outX = outputW->dataX(i);
const auto & inX = inputW->readX(i);
//Change bin value by offset
if ((i >= m_wi_min) && (i <= m_wi_max))
{
double factor = getScaleFactor(inputW, i);
// Do the offsetting
std::transform(inX.begin(), inX.end(), outX.begin(), std::bind2nd(m_binOp, factor));
// reverse the vector if multiplicative factor was negative
if(multiply && factor < 0.0)
{
std::reverse( outX.begin(), outX.end() );
std::reverse( outY.begin(), outY.end() );
std::reverse( outE.begin(), outE.end() );
}
}
else
{
outX = inX; //copy
}
m_progress->report("Scaling X");
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
// Copy units
if (outputW->getAxis(0)->unit().get())
outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit();
try
{
if (inputW->getAxis(1)->unit().get())
outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit();
}
catch(Exception::IndexError &)
{
//.........这里部分代码省略.........