/** Creates PoldiPeak-objects from peak position iterators * * In this method, PoldiPeak objects are created from the raw peak position *data and the original x-data. Estimates for peak height and FWHM * provided along with the position. * * @param baseListStart :: Starting iterator of the vector which the peak *positions refer to. * @param peakPositions :: List with peakPositions. * @param xData :: Vector with x-values of the correlation spectrum. * @return Vector with PoldiPeak objects constructed from the raw peak position *data. */ std::vector<PoldiPeak_sptr> PoldiPeakSearch::getPeaks(const MantidVec::const_iterator &baseListStart, const MantidVec::const_iterator &baseListEnd, std::list<MantidVec::const_iterator> peakPositions, const MantidVec &xData, const Unit_sptr &unit) const { std::vector<PoldiPeak_sptr> peakData; peakData.reserve(peakPositions.size()); for (std::list<MantidVec::const_iterator>::const_iterator peak = peakPositions.begin(); peak != peakPositions.end(); ++peak) { size_t index = std::distance(baseListStart, *peak); double xDataD = getTransformedCenter(xData[index], unit); double fwhmEstimate = getFWHMEstimate(baseListStart, baseListEnd, *peak, xData); UncertainValue fwhm(fwhmEstimate / xData[index]); PoldiPeak_sptr newPeak = PoldiPeak::create( MillerIndices(), UncertainValue(xDataD), UncertainValue(**peak), fwhm); peakData.push_back(newPeak); } return peakData; }
/// 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; }
/** * Tries to refine the initial cell using the supplied peaks * * This method tries to refine the initial unit cell using the indexed peaks * that are supplied in the PoldiPeakCollection. If there are unindexed peaks, * the cell will not be refined at all, instead the unmodified initial cell * is returned. * * @param initialCell :: String with the initial unit cell * @param crystalSystem :: Crystal system name * @param peakCollection :: Collection of bragg peaks, must be indexed * * @return String for refined unit cell */ std::string PoldiFitPeaks2D::getRefinedStartingCell( const std::string &initialCell, const std::string &latticeSystem, const PoldiPeakCollection_sptr &peakCollection) { Geometry::UnitCell cell = Geometry::strToUnitCell(initialCell); ILatticeFunction_sptr latticeFunction = boost::dynamic_pointer_cast<ILatticeFunction>( FunctionFactory::Instance().createFunction("LatticeFunction")); latticeFunction->setLatticeSystem(latticeSystem); latticeFunction->fix(latticeFunction->parameterIndex("ZeroShift")); latticeFunction->setUnitCell(cell); // Remove errors from d-values PoldiPeakCollection_sptr clone = peakCollection->clone(); for (size_t i = 0; i < clone->peakCount(); ++i) { PoldiPeak_sptr peak = clone->peak(i); // If there are unindexed peaks, don't refine, just return the initial cell if (peak->hkl() == MillerIndices()) { return initialCell; } peak->setD(UncertainValue(peak->d().value())); } TableWorkspace_sptr peakTable = clone->asTableWorkspace(); IAlgorithm_sptr fit = createChildAlgorithm("Fit"); fit->setProperty("Function", boost::static_pointer_cast<IFunction>(latticeFunction)); fit->setProperty("InputWorkspace", peakTable); fit->setProperty("CostFunction", "Unweighted least squares"); fit->execute(); Geometry::UnitCell refinedCell = latticeFunction->getUnitCell(); return Geometry::unitCellToStr(refinedCell); }
void PoldiPeakCollection::setPeaks(const std::vector<V3D> &hkls, const std::vector<double> &dValues, const std::vector<double> &fSquared) { if (hkls.size() != dValues.size()) { throw std::invalid_argument( "hkl-vector and d-vector do not have the same length."); } if (!m_pointGroup) { throw std::runtime_error("Cannot set peaks without point group."); } m_peaks.clear(); for (size_t i = 0; i < hkls.size(); ++i) { double multiplicity = static_cast<double>(m_pointGroup->getEquivalents(hkls[i]).size()); addPeak(PoldiPeak::create( MillerIndices(hkls[i]), UncertainValue(dValues[i]), UncertainValue(multiplicity * fSquared[i]), UncertainValue(0.0))); } }