Exemplo n.º 1
0
/**
 * @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;
}
Exemplo n.º 2
0
bool isItSorted(Comparator const &compare,
                const Mantid::API::MatrixWorkspace &inputWorkspace) {
  for (auto specNum = 0u; specNum < inputWorkspace.getNumberHistograms();
       specNum++) {
    if (!std::is_sorted(inputWorkspace.x(specNum).begin(),
                        inputWorkspace.x(specNum).end(),
                        [&](double lhs, double rhs) -> bool {
                          return compare(lhs, rhs);
                        })) {
      return false;
    }
  }
  return true;
}
Exemplo n.º 3
0
/**
 * @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();
}