Exemplo n.º 1
0
  /** Executes the algorithm
     *
     *  @throw Exception::RuntimeError If ... ...
     */
  void GetDetOffsetsMultiPeaks::importFitWindowTableWorkspace(TableWorkspace_sptr windowtablews)
  {
    // Check number of columns matches number of peaks
    size_t numcols = windowtablews->columnCount();
    size_t numpeaks = m_peakPositions.size();
    if (numcols != 2*numpeaks+1)
      throw std::runtime_error("Number of columns is not 2 times of number of referenced peaks. ");

    // Check number of spectra should be same to input workspace
    size_t numrows = windowtablews->rowCount();
    if (numrows != m_inputWS->getNumberHistograms())
      throw std::runtime_error("Number of spectra in fit window workspace does not match input workspace. ");

    // Create workspace
    m_vecFitWindow.clear();
    m_vecFitWindow.resize(numrows);

    for (size_t i = 0; i < numrows; ++i)
    {
      // spectrum number
      int spec = windowtablews->cell<int>(i, 0);
      if (spec < 0 || spec >= static_cast<int>(numrows))
      {
        std::stringstream ess;
        ess << "Peak fit windows at row " << i << " has spectrum " << spec
            << ", which is out of allowed range! ";
        throw std::runtime_error(ess.str());
      }
      else if (m_vecFitWindow[spec].size() != 0)
      {
        std::stringstream ess;
        ess << "Peak fit windows at row " << i << " has spectrum " << spec
            << ", which appears before in fit window table workspace. ";
        throw std::runtime_error(ess.str());
      }

      // fit windows
      std::vector<double> fitwindows(numcols-1);
      for (size_t j = 1; j < numcols; ++j)
      {
        double dtmp = windowtablews->cell<double>(i, j);
        fitwindows[j-1] = dtmp;
      }

      // add to vector of fit windows
      m_vecFitWindow[spec] = fitwindows;
    }

    return;
  }
Exemplo n.º 2
0
bool PoldiPeakCollection::checkColumns(
    const TableWorkspace_sptr &tableWorkspace) {
  if (tableWorkspace->columnCount() != 9) {
    return false;
  }

  std::vector<std::string> shouldNames{"HKL", "d", "delta d", "Q", "delta Q",
                                       "Intensity", "delta Intensity",
                                       "FWHM (rel.)", "delta FWHM (rel.)"};

  std::vector<std::string> columnNames = tableWorkspace->getColumnNames();

  return columnNames == shouldNames;
}
Exemplo n.º 3
0
/** Executes the algorithm
   *
   *  @throw Exception::RuntimeError If ... ...
   */
void GetDetOffsetsMultiPeaks::importFitWindowTableWorkspace(
    TableWorkspace_sptr windowtablews) {
  // Check number of columns matches number of peaks
  size_t numcols = windowtablews->columnCount();
  size_t numpeaks = m_peakPositions.size();

  if (numcols != 2 * numpeaks + 1)
    throw std::runtime_error(
        "Number of columns is not 2 times of number of referenced peaks. ");

  // Check number of spectra should be same to input workspace
  size_t numrows = windowtablews->rowCount();
  bool needuniversal = false;
  if (numrows < m_inputWS->getNumberHistograms())
    needuniversal = true;
  else if (numrows > m_inputWS->getNumberHistograms())
    throw std::runtime_error(
        "Number of rows in table workspace is larger than number of spectra.");

  // Clear and re-size of the vector for fit windows
  m_vecFitWindow.clear();
  m_vecFitWindow.resize(m_inputWS->getNumberHistograms());

  std::vector<double> vec_univFitWindow;
  bool founduniversal = false;

  // Parse the table workspace
  for (size_t i = 0; i < numrows; ++i) {
    // spectrum number
    int spec = windowtablews->cell<int>(i, 0);
    if (spec >= static_cast<int>(numrows)) {
      std::stringstream ess;
      ess << "Peak fit windows at row " << i << " has spectrum " << spec
          << ", which is out of allowed range! ";
      throw std::runtime_error(ess.str());
    }
    if (spec < 0 && founduniversal) {
      throw std::runtime_error("There are more than 1 universal spectrum (spec "
                               "< 0) in TableWorkspace.");
    } else if (spec >= 0 && m_vecFitWindow[spec].size() != 0) {
      std::stringstream ess;
      ess << "Peak fit windows at row " << i << " has spectrum " << spec
          << ", which appears before in fit window table workspace. ";
      throw std::runtime_error(ess.str());
    }

    // fit windows
    std::vector<double> fitwindows(numcols - 1);
    for (size_t j = 1; j < numcols; ++j) {
      double dtmp = windowtablews->cell<double>(i, j);
      fitwindows[j - 1] = dtmp;
    }

    // add to vector of fit windows
    if (spec >= 0)
      m_vecFitWindow[spec] = fitwindows;
    else {
      vec_univFitWindow = fitwindows;
      founduniversal = true;
    }
  }

  // Check and fill if using universal
  if (needuniversal && !founduniversal) {
    // Invalid case
    throw std::runtime_error("Number of rows in TableWorkspace is smaller than "
                             "number of spectra.  But "
                             "there is no universal fit window given!");
  } else if (founduniversal) {
    // Fill the universal
    for (size_t i = 0; i < m_inputWS->getNumberHistograms(); ++i)
      if (m_vecFitWindow[i].size() == 0)
        m_vecFitWindow[i] = vec_univFitWindow;
  }

  return;
}