void PoldiPeakSummary::storePeakSummary(TableRow tableRow, const PoldiPeak_sptr &peak) const { UncertainValue q = peak->q(); UncertainValue d = peak->d(); tableRow << MillerIndicesIO::toString(peak->hkl()) << UncertainValueIO::toString(q) << UncertainValueIO::toString(d) << d.error() / d.value() * 1e3 << UncertainValueIO::toString(peak->fwhm(PoldiPeak::Relative) * 1e3) << UncertainValueIO::toString(peak->intensity()); }
void PoldiPeakSearch::exec() { g_log.information() << "PoldiPeakSearch:" << std::endl; Workspace2D_sptr correlationWorkspace = getProperty("InputWorkspace"); MantidVec correlationQValues = correlationWorkspace->readX(0); MantidVec correlatedCounts = correlationWorkspace->readY(0); g_log.information() << " Auto-correlation data read." << std::endl; Unit_sptr xUnit = correlationWorkspace->getAxis(0)->unit(); if (xUnit->caption() == "") { g_log.information() << " Workspace does not have unit, defaulting to MomentumTransfer." << std::endl; xUnit = UnitFactory::Instance().create("MomentumTransfer"); } else { g_log.information() << " Unit of workspace is " << xUnit->caption() << "." << std::endl; } setMinimumDistance(getProperty("MinimumPeakSeparation")); setMinimumPeakHeight(getProperty("MinimumPeakHeight")); setMaximumPeakNumber(getProperty("MaximumPeakNumber")); if (m_doubleMinimumDistance > static_cast<int>(correlatedCounts.size())) { throw(std::runtime_error("MinimumPeakSeparation is smaller than number of " "spectrum points - no peaks possible.")); } g_log.information() << " Parameters set." << std::endl; MantidVec summedNeighborCounts = getNeighborSums(correlatedCounts); g_log.information() << " Neighboring counts summed, contains " << summedNeighborCounts.size() << " data points." << std::endl; std::list<MantidVec::const_iterator> peakPositionsSummed = findPeaks(summedNeighborCounts.begin(), summedNeighborCounts.end()); g_log.information() << " Peaks detected in summed spectrum: " << peakPositionsSummed.size() << std::endl; /* This step is required because peaks are actually searched in the * "sum-of-neighbors"-spectrum. * The mapping removes the offset from the peak position which results from * different beginning * of this vector compared to the original correlation counts. */ std::list<MantidVec::const_iterator> peakPositionsCorrelation = mapPeakPositionsToCorrelationData(peakPositionsSummed, summedNeighborCounts.begin(), correlatedCounts.begin()); g_log.information() << " Peak positions transformed to original spectrum." << std::endl; /* Since intensities are required for filtering, they are extracted from the * original count data, * along with the Q-values. */ std::vector<PoldiPeak_sptr> peakCoordinates = getPeaks(correlatedCounts.begin(), correlatedCounts.end(), peakPositionsCorrelation, correlationQValues, xUnit); g_log.information() << " Extracted peak positions in Q and intensity guesses." << std::endl; UncertainValue backgroundWithSigma = getBackgroundWithSigma(peakPositionsCorrelation, correlatedCounts); g_log.information() << " Calculated average background and deviation: " << UncertainValueIO::toString(backgroundWithSigma) << std::endl; if ((*getProperty("MinimumPeakHeight")).isDefault()) { setMinimumPeakHeight(minimumPeakHeightFromBackground(backgroundWithSigma)); } std::vector<PoldiPeak_sptr> intensityFilteredPeaks(peakCoordinates.size()); auto newEnd = std::remove_copy_if( peakCoordinates.begin(), peakCoordinates.end(), intensityFilteredPeaks.begin(), boost::bind(&PoldiPeakSearch::isLessThanMinimum, this, _1)); intensityFilteredPeaks.resize( std::distance(intensityFilteredPeaks.begin(), newEnd)); g_log.information() << " Peaks above minimum intensity (" << m_minimumPeakHeight << "): " << intensityFilteredPeaks.size() << std::endl; std::sort(intensityFilteredPeaks.begin(), intensityFilteredPeaks.end(), boost::bind<bool>(&PoldiPeak::greaterThan, _1, _2, &PoldiPeak::intensity)); for (std::vector<PoldiPeak_sptr>::const_iterator peak = intensityFilteredPeaks.begin(); peak != intensityFilteredPeaks.end(); ++peak) { m_peaks->addPeak(*peak); } /* The derived background error is set as error in the workspace containing * correlation data, so it may be used as weights for peak fitting later on. */ setErrorsOnWorkspace(correlationWorkspace, backgroundWithSigma.error()); setProperty("OutputWorkspace", m_peaks->asTableWorkspace()); }
/** Returns the minimum height a peak should have. * * This method is used when no user estimate of minimum required peak height is *given. It is set to background * plus 3 times Sn. * * @param backgroundWithSigma :: Background with error estimate. * @return Minimum peak height. */ double PoldiPeakSearch::minimumPeakHeightFromBackground( UncertainValue backgroundWithSigma) const { return 3.0 * backgroundWithSigma.error() + backgroundWithSigma.value(); }