Beispiel #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;
}