API::IFunction_sptr PoldiFitPeaks1D2::getRangeProfile(const RefinedRange_sptr &range, int n) const { CompositeFunction_sptr totalProfile(new CompositeFunction); totalProfile->initialize(); std::vector<PoldiPeak_sptr> peaks = range->getPeaks(); for (auto it = peaks.begin(); it != peaks.end(); ++it) { totalProfile->addFunction(getPeakProfile(*it)); } totalProfile->addFunction(FunctionFactory::Instance().createInitialized( "name=Chebyshev,n=" + boost::lexical_cast<std::string>(n) + ",StartX=" + boost::lexical_cast<std::string>(range->getXStart()) + ",EndX=" + boost::lexical_cast<std::string>(range->getXEnd()))); return totalProfile; }
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); }