Beispiel #1
0
PoldiPeakCollection_sptr
PoldiFitPeaks1D2::fitPeaks(const PoldiPeakCollection_sptr &peaks) {
  g_log.information() << "Peaks to fit: " << peaks->peakCount() << std::endl;

  std::vector<RefinedRange_sptr> rawRanges = getRefinedRanges(peaks);
  std::vector<RefinedRange_sptr> reducedRanges = getReducedRanges(rawRanges);

  g_log.information() << "Ranges used for fitting: " << reducedRanges.size()
                      << std::endl;

  Workspace2D_sptr dataWorkspace = getProperty("InputWorkspace");
  m_fitplots->removeAll();

  for (size_t i = 0; i < reducedRanges.size(); ++i) {
    RefinedRange_sptr currentRange = reducedRanges[i];
    int nMin = getBestChebyshevPolynomialDegree(dataWorkspace, currentRange);

    if (nMin > -1) {
      IAlgorithm_sptr fit = getFitAlgorithm(dataWorkspace, currentRange, nMin);
      fit->execute();

      IFunction_sptr fitFunction = fit->getProperty("Function");
      CompositeFunction_sptr composite =
          boost::dynamic_pointer_cast<CompositeFunction>(fitFunction);

      if (!composite) {
        throw std::runtime_error("Not a composite function!");
      }

      std::vector<PoldiPeak_sptr> peaks = currentRange->getPeaks();
      for (size_t i = 0; i < peaks.size(); ++i) {
        setValuesFromProfileFunction(peaks[i], composite->getFunction(i));
        MatrixWorkspace_sptr fpg = fit->getProperty("OutputWorkspace");
        m_fitplots->addWorkspace(fpg);
      }
    }
  }

  return getReducedPeakCollection(peaks);
}
Beispiel #2
0
void PoldiFitPeaks1D::exec() {
  setPeakFunction(getProperty("PeakFunction"));

  // Number of points around the peak center to use for the fit
  m_fwhmMultiples = getProperty("FwhmMultiples");

  // try to construct PoldiPeakCollection from provided TableWorkspace
  TableWorkspace_sptr poldiPeakTable = getProperty("PoldiPeakTable");
  m_peaks = getInitializedPeakCollection(poldiPeakTable);

  g_log.information() << "Peaks to fit: " << m_peaks->peakCount() << '\n';

  Workspace2D_sptr dataWorkspace = getProperty("InputWorkspace");

  auto fitPlotGroup = boost::make_shared<WorkspaceGroup>();

  for (size_t i = 0; i < m_peaks->peakCount(); ++i) {
    PoldiPeak_sptr currentPeak = m_peaks->peak(i);
    IFunction_sptr currentProfile = getPeakProfile(currentPeak);

    IAlgorithm_sptr fit =
        getFitAlgorithm(dataWorkspace, currentPeak, currentProfile);

    bool fitSuccess = fit->execute();

    if (fitSuccess) {
      setValuesFromProfileFunction(currentPeak, fit->getProperty("Function"));

      MatrixWorkspace_sptr fpg = fit->getProperty("OutputWorkspace");
      fitPlotGroup->addWorkspace(fpg);
    }
  }

  setProperty("OutputWorkspace", m_peaks->asTableWorkspace());
  setProperty("FitPlotsWorkspace", fitPlotGroup);
}