/** * Constructs a title using the unicode methods of the UnitLabel * @param workspace The workspace containing the Y title information * @param plottingDistribution If true, the Y axis has been divided by the bin * width */ void PlotAxis::titleFromYData(const Mantid::API::MatrixWorkspace &workspace, const bool plottingDistribution) { // The workspace can have a custom label so we should use that as a // preference. // The workspace.YUnitLabel does some mangling of the string if the user set // no // custom label. See MatrixWorkspace::YUnitLabel const std::string customLabel = workspace.YUnitLabel(); const std::string yunit = workspace.YUnit(); if ((yunit == customLabel) || (customLabel.find("per") != std::string::npos)) { m_title = QString::fromStdString(yunit); if (plottingDistribution && workspace.axes() > 0 && workspace.getAxis(0)->unit()) { const auto xunit = workspace.getAxis(0)->unit(); const auto lbl = xunit->label(); if (!lbl.utf8().empty()) { m_title += " (" + QString::fromStdWString(lbl.utf8()) + ")" + QString::fromWCharArray(L"\u207b\u00b9"); } } } else { m_title = QString::fromStdString(customLabel); } }
/** * @brief Extract Q values from vertical dimension of the workspace, or compute * them. * @param workspace workspace possibly containing Q values. */ std::vector<double> FunctionQDepends::extractQValues( const Mantid::API::MatrixWorkspace &workspace) { std::vector<double> qs; // Check if the vertical axis has units of momentum transfer, then extract Q // values... auto axis_ptr = dynamic_cast<Mantid::API::NumericAxis *>(workspace.getAxis(1)); if (axis_ptr) { const boost::shared_ptr<Kernel::Unit> &unit_ptr = axis_ptr->unit(); if (unit_ptr->unitID() == "MomentumTransfer") { qs = axis_ptr->getValues(); } } // ...otherwise, compute the momentum transfer for each spectrum, if possible else { const auto &spectrumInfo = workspace.spectrumInfo(); size_t numHist = workspace.getNumberHistograms(); for (size_t wi = 0; wi < numHist; wi++) { if (spectrumInfo.hasDetectors(wi)) { const auto detID = spectrumInfo.detector(wi).getID(); double efixed = workspace.getEFixed(detID); double usignTheta = 0.5 * spectrumInfo.twoTheta(wi); double q = Mantid::Kernel::UnitConversion::convertToElasticQ(usignTheta, efixed); qs.push_back(q); } else { g_log.debug("Cannot populate Q values from workspace"); qs.clear(); break; } } } return qs; }
/** * @param workspace A reference to the workspace object that this data refers to */ void QwtWorkspaceBinData::init(const Mantid::API::MatrixWorkspace &workspace) { if(workspace.axes() != 2) { std::ostringstream os; os << "QwtWorkspaceBinData(): Workspace must have two axes, found " << workspace.axes(); throw std::invalid_argument(os.str()); } // Check binIndex is valid if(static_cast<size_t>(m_binIndex) >= workspace.blocksize()) { std::ostringstream os; os << "QwtWorkspaceBinData(): Index out of range. index=" << m_binIndex << ", nvalues=" << workspace.blocksize(); throw std::out_of_range(os.str()); } // Fill vectors of data const size_t nhist = workspace.getNumberHistograms(); auto* vertAxis = workspace.getAxis(1); //supplies X values m_X.resize(nhist); m_Y.resize(nhist); m_E.resize(nhist); for(size_t i = 0; i < nhist; ++i) { m_X[i] = vertAxis->getValue(i); m_Y[i] = workspace.readY(i)[m_binIndex]; m_E[i] = workspace.readE(i)[m_binIndex]; } // meta data m_xTitle = MantidQt::API::PlotAxis(workspace, 1).title(); m_yTitle = MantidQt::API::PlotAxis(workspace).title(); }