/** * Calculates function values for domain. In contrast to CompositeFunction, the *summation * of values is performed in a different way: The values are set to zero once at *the beginning, * then it is expected of the member functions to use *FunctionValues::addToCalculated or add * their values otherwise, without erasing the values. * * @param domain :: Function domain which is passed on to the member functions. * @param values :: Function values. */ void Poldi2DFunction::function(const FunctionDomain &domain, FunctionValues &values) const { CompositeFunction::function(domain, values); if (m_iteration > 0) { for (size_t i = 0; i < values.size(); ++i) { values.setFitWeight(i, 1.0 / sqrt(values.getCalculated(i) + 0.1)); } } }
/// Update the peaks parameters after recalculationof the crystal field. /// @param spectrum :: A composite function containings the peaks to update. /// May contain other functions (background) fix indices /// < iFirst. /// @param peakShape :: A shape of each peak as a name of an IPeakFunction. /// @param centresAndIntensities :: A FunctionValues object containing centres /// and intensities for the peaks. First nPeaks calculated values are the /// centres and the following nPeaks values are the intensities. /// @param iFirst :: The first index in the composite function (spectrum) at /// which the peaks begin. /// @param xVec :: x-values of a tabulated width function. /// @param yVec :: y-values of a tabulated width function. /// @param fwhmVariation :: A variation in the peak width allowed in a fit. /// @param defaultFWHM :: A default value for the FWHM to use if xVec and yVec /// are empty. /// @param fixAllPeaks :: If true fix all peak parameters /// @return :: The new number of fitted peaks. size_t updateSpectrumFunction(API::CompositeFunction &spectrum, const std::string &peakShape, const FunctionValues ¢resAndIntensities, size_t iFirst, const std::vector<double> &xVec, const std::vector<double> &yVec, double fwhmVariation, double defaultFWHM, bool fixAllPeaks) { size_t nGoodPeaks = calculateNPeaks(centresAndIntensities); size_t maxNPeaks = calculateMaxNPeaks(nGoodPeaks); size_t nFunctions = spectrum.nFunctions(); for (size_t i = 0; i < maxNPeaks; ++i) { const bool isGood = i < nGoodPeaks; auto centre = isGood ? centresAndIntensities.getCalculated(i) : 0.0; auto intensity = isGood ? centresAndIntensities.getCalculated(i + nGoodPeaks) : 0.0; if (i < nFunctions - iFirst) { auto fun = spectrum.getFunction(i + iFirst); auto &peak = dynamic_cast<API::IPeakFunction &>(*fun); updatePeak(peak, centre, intensity, xVec, yVec, fwhmVariation, isGood, fixAllPeaks); } else { auto peakPtr = createPeak(peakShape, centre, intensity, xVec, yVec, fwhmVariation, defaultFWHM, isGood, fixAllPeaks); spectrum.addFunction(peakPtr); } } // If there are any peaks above the maxNPeaks, ignore them // but don't remove for (size_t i = maxNPeaks; i < nFunctions - iFirst; ++i) { auto fun = spectrum.getFunction(i + iFirst); auto &peak = dynamic_cast<API::IPeakFunction &>(*fun); const auto fwhm = peak.fwhm(); ignorePeak(peak, fwhm); } return nGoodPeaks; }