本文整理汇总了C++中mantid::api::MatrixWorkspace_sptr类的典型用法代码示例。如果您正苦于以下问题:C++ MatrixWorkspace_sptr类的具体用法?C++ MatrixWorkspace_sptr怎么用?C++ MatrixWorkspace_sptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MatrixWorkspace_sptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set2DValues
void set2DValues(Mantid::API::MatrixWorkspace_sptr ws) {
const auto numberOfHistograms = ws->getNumberHistograms();
for (size_t index = 0; index < numberOfHistograms; ++index) {
auto &data = ws->dataY(index);
data = Mantid::MantidVec(data.size(), static_cast<double>(index));
}
}
示例2: slicePlotRaw
/**
* Redraw the raw input plot
*/
void IndirectDiagnostics::slicePlotRaw()
{
QString filename = m_uiForm.dsInputFiles->getFirstFilename();
// Only update if we have a different file
if(filename == m_lastDiagFilename)
return;
m_lastDiagFilename = filename;
disconnect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updatePreviewPlot()));
disconnect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(updatePreviewPlot()));
setDefaultInstDetails();
if ( m_uiForm.dsInputFiles->isValid() )
{
QFileInfo fi(filename);
QString wsname = fi.baseName();
int specMin = static_cast<int>(m_dblManager->value(m_properties["SpecMin"]));
int specMax = static_cast<int>(m_dblManager->value(m_properties["SpecMax"]));
if(!loadFile(filename, wsname, specMin, specMax))
{
emit showMessageBox("Unable to load file.\nCheck whether your file exists and matches the selected instrument in the EnergyTransfer tab.");
return;
}
Mantid::API::MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));
const Mantid::MantidVec & dataX = input->readX(0);
std::pair<double, double> range(dataX.front(), dataX.back());
plotMiniPlot(input, 0, "SlicePlot");
setXAxisToCurve("SlicePlot", "SlicePlot");
setPlotRange("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"], range);
setPlotRange("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"], range);
replot("SlicePlot");
}
else
{
emit showMessageBox("Selected input files are invalid.");
}
connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updatePreviewPlot()));
connect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(updatePreviewPlot()));
updatePreviewPlot();
}
示例3: setGoniometer
/*
* Set the goniometer values for the workspace
*
* @param workspace :: the workspace to set the goniometer values in
*/
void CreateMD::setGoniometer(Mantid::API::MatrixWorkspace_sptr workspace) {
Algorithm_sptr log_alg = createChildAlgorithm("SetGoniometer");
if (!workspace->run().getProperty("gl")) {
std::ostringstream temp_ss;
temp_ss << "Value of gl in log is: "
<< workspace->run().getPropertyAsSingleValue("gl");
throw std::invalid_argument(temp_ss.str());
}
log_alg->setProperty("Workspace", workspace);
log_alg->setProperty("Axis0", "gl,0,0,1,1");
log_alg->setProperty("Axis1", "gs,1,0,0,1");
log_alg->setProperty("Axis2", "psi,0,1,0,1");
log_alg->executeAsChildAlg();
}
示例4: invalid_argument
/*
* Add parameter logs and convert to MD for a single run
*
* @param input_workspace :: datasource workspace
* @param emode :: analysis mode "Elastic", "Direct" or "Indirect"
* @param efix :: datasource energy values in meV
* @param psi :: goniometer rotation in degrees
* @param gl :: goniometer rotation in degrees
* @param gs :: goniometer rotation in degrees
* @param in_place :: do merge step at the same time as converting to
*MDWorkspace
* @param alatt :: length of crystal lattice parameter in angstroms
* @param angdeg :: lattice angle
* @param u :: lattice vector parallel to incident neutron beam
* @param v :: lattice vector perpendicular to u in the horizontal plane
* @param out_mdws :output workspace to use if merge step is carried out
*/
Mantid::API::IMDEventWorkspace_sptr CreateMD::single_run(
Mantid::API::MatrixWorkspace_sptr input_workspace, const std::string &emode,
double efix, double psi, double gl, double gs, bool in_place,
const std::vector<double> &alatt, const std::vector<double> &angdeg,
const std::vector<double> &u, const std::vector<double> &v,
const std::string &filebackend_filename, const bool filebackend,
Mantid::API::IMDEventWorkspace_sptr out_mdws) {
std::vector<std::vector<double>> ub_params{alatt, angdeg, u, v};
if (any_given(ub_params) && !all_given(ub_params)) {
throw std::invalid_argument(
"Either specify all of alatt, angledeg, u, v or none of them");
} else {
if (input_workspace->sample().hasOrientedLattice()) {
g_log.warning() << "Sample already has a UB. This will not be "
"overwritten. Use ClearUB and re-run.\n";
} else {
setUB(input_workspace, alatt[0], alatt[1], alatt[2], angdeg[0], angdeg[1],
angdeg[2], u, v);
}
if (efix > 0.0) {
addSampleLog(input_workspace, "Ei", efix);
}
addSampleLog(input_workspace, "gl", gl);
addSampleLog(input_workspace, "gs", gs);
addSampleLog(input_workspace, "psi", psi);
setGoniometer(input_workspace);
return convertToMD(input_workspace, emode, in_place, filebackend_filename,
filebackend, out_mdws);
}
}
示例5: InstrumentDefinitionError
/// calculate distance from source to sample or detector
double ModeratorTzero::CalculateL1(Mantid::API::MatrixWorkspace_sptr inputWS, size_t i){
double L1(0);
// Get detector position
IDetector_const_sptr det;
try
{
det = inputWS->getDetector(i);
}
catch (Exception::NotFoundError&)
{
return 0;
}
if( det->isMonitor() )
{
L1=m_instrument->getSource()->getDistance(*det);
}
else
{
IComponent_const_sptr sample = m_instrument->getSample();
try
{
L1 = m_instrument->getSource()->getDistance(*sample);
}
catch (Exception::NotFoundError &)
{
g_log.error("Unable to calculate source-sample distance");
throw Exception::InstrumentDefinitionError("Unable to calculate source-sample distance", inputWS->getTitle());
}
}
return L1;
}
示例6: provideCollimationLength
/**
* Provide the collimation length which is associated with the instrument
* @param workspace: the input workspace
* @returns the collimation length
*/
double SANSCollimationLengthEstimator::provideCollimationLength(
Mantid::API::MatrixWorkspace_sptr workspace) {
// If the instrument does not have a correction specified then set the length
// to 4
const double defaultLColim = 4.0;
auto collimationLengthID = "collimation-length-correction";
if (!workspace->getInstrument()->hasParameter(collimationLengthID)) {
g_log.error("Error in SANSCollimtionLengthEstimator: The instrument "
"parameter file does not contain a collimation length "
"correction,"
"a default of 4 is provided. Please update the instrument "
"parameter file.");
return defaultLColim;
}
// Get the L1 length
const V3D samplePos = workspace->getInstrument()->getSample()->getPos();
const V3D sourcePos = workspace->getInstrument()->getSource()->getPos();
const V3D SSD = samplePos - sourcePos;
const double L1 = SSD.norm();
auto collimationLengthCorrection =
workspace->getInstrument()->getNumberParameter(collimationLengthID);
if (workspace->getInstrument()->hasParameter(
"special-default-collimation-length-method")) {
auto specialCollimationMethod =
workspace->getInstrument()->getStringParameter(
"special-default-collimation-length-method");
if (specialCollimationMethod[0] == "guide") {
try {
return getCollimationLengthWithGuides(workspace, L1,
collimationLengthCorrection[0]);
} catch (std::invalid_argument &ex) {
g_log.notice() << ex.what();
g_log.notice()
<< "SANSCollimationLengthEstimator: Not using any guides";
return L1 - collimationLengthCorrection[0];
}
} else {
throw std::invalid_argument("Error in SANSCollimationLengthEstimator: "
"Unknown special collimation method.");
}
}
return L1 - collimationLengthCorrection[0];
}
示例7: addFocusedRun
void EnggDiffMultiRunFittingWidgetPresenter::addFocusedRun(
const Mantid::API::MatrixWorkspace_sptr ws) {
const auto runNumber = ws->getRunNumber();
const auto bankID = guessBankID(ws);
m_model->addFocusedRun(RunLabel(runNumber, bankID), ws);
m_view->updateRunList(m_model->getAllWorkspaceLabels());
}
示例8: runtime_error
/// Constructor.
/// @param wsName :: Name of a MatrixWorkspace with the data for fitting.
/// @param wsIndex :: Workspace index of a spectrum in wsName to plot.
/// @param outputWSName :: Name of the Fit's output workspace containing at
/// least 3 spectra:
/// #0 - original data (the same as in wsName[wsIndex]), #1 - calculated
/// data, #3 - difference.
/// If empty - ignore this workspace.
DatasetPlotData::DatasetPlotData(const QString &wsName, int wsIndex,
const QString &outputWSName)
: m_dataCurve(new QwtPlotCurve(wsName + QString(" (%1)").arg(wsIndex))),
m_dataErrorCurve(NULL), m_calcCurve(NULL), m_diffCurve(NULL),
m_showDataErrorBars(false) {
// get the data workspace
auto ws = Mantid::API::AnalysisDataService::Instance()
.retrieveWS<Mantid::API::MatrixWorkspace>(wsName.toStdString());
if (!ws) {
QString mess =
QString("Workspace %1 either doesn't exist or isn't a MatrixWorkspace")
.arg(wsName);
throw std::runtime_error(mess.toStdString());
}
// check that the index is in range
if (static_cast<size_t>(wsIndex) >= ws->getNumberHistograms()) {
QString mess = QString("Spectrum %1 doesn't exist in workspace %2")
.arg(wsIndex)
.arg(wsName);
throw std::runtime_error(mess.toStdString());
}
// get the data workspace
Mantid::API::MatrixWorkspace_sptr outputWS;
if (!outputWSName.isEmpty()) {
std::string stdOutputWSName = outputWSName.toStdString();
if (Mantid::API::AnalysisDataService::Instance().doesExist(
stdOutputWSName)) {
try {
outputWS =
Mantid::API::AnalysisDataService::Instance()
.retrieveWS<Mantid::API::MatrixWorkspace>(stdOutputWSName);
} catch (Mantid::Kernel::Exception::NotFoundError &) {
QString mess =
QString(
"Workspace %1 either doesn't exist or isn't a MatrixWorkspace")
.arg(outputWSName);
throw std::runtime_error(mess.toStdString());
}
}
}
// create the curves
setData(ws.get(), wsIndex, outputWS.get());
}
示例9: shiftTimeInLogForTimeSeries
/**
* Shift the time in a time series. This is similar to the implementation in
* @param ws :: a matrix workspace
* @param prop :: a time series log
* @param timeShift :: the time shift in seconds
*/
void ChangeTimeZero::shiftTimeInLogForTimeSeries(
Mantid::API::MatrixWorkspace_sptr ws, Mantid::Kernel::Property *prop,
double timeShift) const {
if (auto timeSeries =
dynamic_cast<Mantid::Kernel::ITimeSeriesProperty *>(prop)) {
auto newlog = timeSeries->cloneWithTimeShift(timeShift);
ws->mutableRun().addProperty(newlog, true);
}
}
示例10: runtime_error
/**
* @brief Gets the X range of the first curve whose data is stored in the query
* workspace.
* @param workspace pointer to query workspace
* @return the range of the first curve associated to the workspace
* @exception std::runtime_error no stored curves are associated to the query
* workspace
*/
QPair<double, double> DisplayCurveFit::getCurveRange(
const Mantid::API::MatrixWorkspace_sptr workspace) {
curveTypes typesFound = this->getCurvesForWorkspace(workspace);
if (typesFound.size() == 0) {
throw std::runtime_error("No fitting curves associated to workspace" +
workspace->name());
}
return getCurveRange(typesFound[0]);
}
示例11: convertFromDistribution
void EnggDiffFittingModel::convertFromDistribution(
Mantid::API::MatrixWorkspace_sptr inputWS) {
const auto name = inputWS->getName();
auto convertFromDistAlg = Mantid::API::AlgorithmManager::Instance().create(
"ConvertFromDistribution");
convertFromDistAlg->initialize();
convertFromDistAlg->setProperty("Workspace", inputWS);
convertFromDistAlg->execute();
}
示例12: checkInput
/**
* Check the input workspace
* @param inWS: the input workspace
*/
void TOFSANSResolutionByPixel::checkInput(
Mantid::API::MatrixWorkspace_sptr inWS) {
// Make sure that input workspace has an instrument as we rely heavily on
// thisa
auto inst = inWS->getInstrument();
if (inst->getName().empty()) {
throw std::invalid_argument("TOFSANSResolutionByPixel: The input workspace "
"does not contain an instrument");
}
}
示例13: setXValuesOn1DWorkspaceWithPointData
void setXValuesOn1DWorkspaceWithPointData(
Mantid::API::MatrixWorkspace_sptr workspace, double xmin, double xmax) {
auto &xValues = workspace->dataX(0);
auto size = xValues.size();
double binWidth = (xmax - xmin) / static_cast<double>(size - 1);
for (size_t index = 0; index < size; ++index) {
xValues[index] = xmin;
xmin += binWidth;
}
}
示例14: plotAll
void IndirectFitAnalysisTab::plotAll(
Mantid::API::MatrixWorkspace_sptr workspace) {
auto const numberOfDataPoints = workspace->blocksize();
if (numberOfDataPoints > 1)
plotSpectrum(workspace);
else
showMessageBox(
"The plotting of data in one of the result workspaces failed:\n\n "
"Workspace has only one data point");
}
示例15: handleNewFile
void ISISDiagnostics::handleNewFile() {
if (!m_uiForm.dsInputFiles->isValid())
return;
QString filename = m_uiForm.dsInputFiles->getFirstFilename();
QFileInfo fi(filename);
QString wsname = fi.baseName();
int specMin = static_cast<int>(m_dblManager->value(m_properties["SpecMin"]));
int specMax = static_cast<int>(m_dblManager->value(m_properties["SpecMax"]));
if (!loadFile(filename, wsname, specMin, specMax)) {
emit showMessageBox("Unable to load file.\nCheck whether your file exists "
"and matches the selected instrument in the "
"EnergyTransfer tab.");
return;
}
Mantid::API::MatrixWorkspace_sptr input =
boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
Mantid::API::AnalysisDataService::Instance().retrieve(
wsname.toStdString()));
const Mantid::MantidVec &dataX = input->readX(0);
QPair<double, double> range(dataX.front(), dataX.back());
int previewSpec =
static_cast<int>(m_dblManager->value(m_properties["PreviewSpec"])) -
specMin;
m_uiForm.ppRawPlot->clear();
m_uiForm.ppRawPlot->addSpectrum("Raw", input, previewSpec);
setPlotPropertyRange(m_uiForm.ppRawPlot->getRangeSelector("SlicePeak"),
m_properties["PeakStart"], m_properties["PeakEnd"],
range);
setPlotPropertyRange(m_uiForm.ppRawPlot->getRangeSelector("SliceBackground"),
m_properties["BackgroundStart"],
m_properties["BackgroundEnd"], range);
m_uiForm.ppRawPlot->resizeX();
}