Ejemplo n.º 1
0
/**
 * Gets the energy mode from a workspace based on the X unit.
 *
 * Units of dSpacing typically denote diffraction, hence Elastic.
 * All other units default to spectroscopy, therefore Indirect.
 *
 * @param ws Pointer to the workspace
 * @return Energy mode
 */
std::string IndirectTab::getEMode(Mantid::API::MatrixWorkspace_sptr ws) {
  Mantid::Kernel::Unit_sptr xUnit = ws->getAxis(0)->unit();
  std::string xUnitName = xUnit->caption();

  g_log.debug() << "X unit name is: " << xUnitName << '\n';

  if (boost::algorithm::find_first(xUnitName, "d-Spacing"))
    return "Elastic";

  return "Indirect";
}
Ejemplo n.º 2
0
Mantid::API::MatrixWorkspace_sptr
provide1DWorkspace(NXcanSASTestParameters &parameters) {
  Mantid::API::MatrixWorkspace_sptr ws;
  if (parameters.hasDx) {
    ws = WorkspaceCreationHelper::create1DWorkspaceConstantWithXerror(
        parameters.size, parameters.value, parameters.error, parameters.xerror);
  } else {
    ws = WorkspaceCreationHelper::create1DWorkspaceConstant(
        parameters.size, parameters.value, parameters.error);
  }

  ws->setTitle(parameters.workspaceTitle);
  ws->getAxis(0)->unit() =
      Mantid::Kernel::UnitFactory::Instance().create("MomentumTransfer");

  // Add sample logs
  set_logs(ws, parameters.runNumber, parameters.userFile);

  // Set instrument
  set_instrument(ws, parameters.instrumentName);

  // Set to point data or histogram data
  if (parameters.isHistogram) {
    const std::string outName = "convert_to_histo_out_name";
    auto toHistAlg = Mantid::API::AlgorithmManager::Instance().createUnmanaged(
        "ConvertToHistogram");
    toHistAlg->initialize();
    toHistAlg->setChild(true);
    toHistAlg->setProperty("InputWorkspace", ws);
    toHistAlg->setProperty("OutputWorkspace", outName);
    toHistAlg->execute();
    ws = toHistAlg->getProperty("OutputWorkspace");
  }

  return ws;
}