/// Sets the profile function and replaces already existing functions in the /// internally stored CompositeFunction. void PawleyFunction::setProfileFunction(const std::string &profileFunction) { m_pawleyParameterFunction->setAttributeValue("ProfileFunction", profileFunction); /* At this point PawleyParameterFunction guarantees that it's an IPeakFunction * and all existing profile functions are replaced. */ for (size_t i = 0; i < m_peakProfileComposite->nFunctions(); ++i) { IPeakFunction_sptr oldFunction = boost::dynamic_pointer_cast<IPeakFunction>( m_peakProfileComposite->getFunction(i)); IPeakFunction_sptr newFunction = boost::dynamic_pointer_cast<IPeakFunction>( FunctionFactory::Instance().createFunction( m_pawleyParameterFunction->getProfileFunctionName())); newFunction->setCentre(oldFunction->centre()); try { newFunction->setFwhm(oldFunction->fwhm()); } catch (...) { // do nothing. } newFunction->setHeight(oldFunction->height()); m_peakProfileComposite->replaceFunction(i, newFunction); } // Update exposed parameters. m_compositeFunction->checkFunction(); }
void PoldiFitPeaks1D2::setValuesFromProfileFunction( PoldiPeak_sptr poldiPeak, const IFunction_sptr &fittedFunction) const { IPeakFunction_sptr peakFunction = boost::dynamic_pointer_cast<IPeakFunction>(fittedFunction); if (peakFunction) { poldiPeak->setIntensity( UncertainValue(peakFunction->height(), peakFunction->getError(0))); poldiPeak->setQ( UncertainValue(peakFunction->centre(), peakFunction->getError(1))); poldiPeak->setFwhm(UncertainValue(peakFunction->fwhm(), getFwhmWidthRelation(peakFunction) * peakFunction->getError(2))); } }
/// Creates a PoldiPeak from the given profile function/hkl pair. PoldiPeak_sptr PoldiFitPeaks2D::getPeakFromPeakFunction(IPeakFunction_sptr profileFunction, const V3D &hkl) { // Use EstimatePeakErrors to calculate errors of FWHM and so on IAlgorithm_sptr errorAlg = createChildAlgorithm("EstimatePeakErrors"); errorAlg->setProperty( "Function", boost::dynamic_pointer_cast<IFunction>(profileFunction)); errorAlg->setPropertyValue("OutputWorkspace", "Errors"); errorAlg->execute(); double centre = profileFunction->centre(); double fwhmValue = profileFunction->fwhm(); ITableWorkspace_sptr errorTable = errorAlg->getProperty("OutputWorkspace"); double centreError = errorTable->cell<double>(0, 2); double fwhmError = errorTable->cell<double>(2, 2); UncertainValue d(centre, centreError); UncertainValue fwhm(fwhmValue, fwhmError); UncertainValue intensity; bool useIntegratedIntensities = getProperty("OutputIntegratedIntensities"); if (useIntegratedIntensities) { double integratedIntensity = profileFunction->intensity(); double integratedIntensityError = errorTable->cell<double>(3, 2); intensity = UncertainValue(integratedIntensity, integratedIntensityError); } else { double height = profileFunction->height(); double heightError = errorTable->cell<double>(1, 2); intensity = UncertainValue(height, heightError); } // Create peak with extracted parameters and supplied hkl PoldiPeak_sptr peak = PoldiPeak::create(MillerIndices(hkl), d, intensity, UncertainValue(1.0)); peak->setFwhm(fwhm, PoldiPeak::FwhmRelation::AbsoluteD); return peak; }
/** Generate peaks in the given output workspace * @param functionmap :: map to contain the list of functions with key as their spectra * @param dataWS :: output matrix workspace */ void GeneratePeaks::generatePeaks(const std::map<specid_t, std::vector<std::pair<double, API::IFunction_sptr> > >& functionmap, API::MatrixWorkspace_sptr dataWS) { // Calcualte function std::map<specid_t, std::vector<std::pair<double, API::IFunction_sptr> > >::const_iterator mapiter; for (mapiter = functionmap.begin(); mapiter != functionmap.end(); ++mapiter) { // Get spec id and translated to wsindex in the output workspace specid_t specid = mapiter->first; specid_t wsindex; if (m_newWSFromParent) wsindex = specid; else wsindex = m_SpectrumMap[specid]; const std::vector<std::pair<double, API::IFunction_sptr> >& vec_centrefunc = mapiter->second; size_t numpeaksinspec = mapiter->second.size(); for (size_t ipeak = 0; ipeak < numpeaksinspec; ++ipeak) { const std::pair<double, API::IFunction_sptr>& centrefunc = vec_centrefunc[ipeak]; // Determine boundary API::IPeakFunction_sptr thispeak = getPeakFunction(centrefunc.second); double centre = centrefunc.first; double fwhm = thispeak->fwhm(); // const MantidVec& X = dataWS->dataX(wsindex); double leftbound = centre - m_numPeakWidth*fwhm; if (ipeak > 0) { // Not left most peak. API::IPeakFunction_sptr leftPeak = getPeakFunction(vec_centrefunc[ipeak-1].second); double middle = 0.5*(centre + leftPeak->centre()); if (leftbound < middle) leftbound = middle; } std::vector<double>::const_iterator left = std::lower_bound(X.begin(), X.end(), leftbound); if (left == X.end()) left = X.begin(); double rightbound = centre + m_numPeakWidth*fwhm; if (ipeak != numpeaksinspec-1) { // Not the rightmost peak IPeakFunction_sptr rightPeak = getPeakFunction(vec_centrefunc[ipeak+1].second); double middle = 0.5*(centre + rightPeak->centre()); if (rightbound > middle) rightbound = middle; } std::vector<double>::const_iterator right = std::lower_bound(left + 1, X.end(), rightbound); // Build domain & function API::FunctionDomain1DVector domain(left, right); //dataWS->dataX(wsindex)); // Evaluate the function API::FunctionValues values(domain); centrefunc.second->function(domain, values); // Put to output std::size_t offset = (left-X.begin()); std::size_t numY = values.size(); for (std::size_t i = 0; i < numY; i ++) { dataWS->dataY(wsindex)[i + offset] += values[i]; } } // ENDFOR(ipeak) } return; }