27 std::vector<double> wavelengths;
28 wavelengths.reserve(
m_peaks.size());
30 std::transform(
m_peaks.begin(),
m_peaks.end(), std::back_inserter(wavelengths),
39 std::vector<double> intensities;
40 intensities.reserve(
m_peaks.size());
42 std::transform(
m_peaks.begin(),
m_peaks.end(), std::back_inserter(intensities),
51 std::vector<double> sigmas;
54 std::transform(
m_peaks.begin(),
m_peaks.end(), std::back_inserter(sigmas),
63 if (sigmaCritical <= 0.0) {
64 throw std::invalid_argument(
"Critical sigma value has to be greater than 0.");
71 std::vector<double> zScores;
79 for (
size_t i = 0; i < zScores.size(); ++i) {
80 if (zScores[i] <= sigmaCritical) {
85 for (
const auto &peak :
m_peaks) {
96 peak.setIntensity(intensity);
97 peak.setSigmaIntensity(
sigma);
116 : m_reflections(), m_pointgroup(
std::move(pointGroup)) {
118 auto dFilter = std::make_shared<const HKLFilterDRange>(cell, dLimits.first, dLimits.second);
119 auto centeringFilter = std::make_shared<const HKLFilterCentering>(centering);
120 auto filter = dFilter & centeringFilter;
123 for (
const auto &hkl : generator) {
124 if (filter->isAllowed(hkl)) {
134 for (
auto const &peak : peaks) {
135 V3D hkl = peak.getHKL();
141 (*reflection).second.addPeak(peak);
158 return std::count_if(
160 [=](
const std::pair<Kernel::V3D, UniqueReflection> &item) { return item.second.count() > moreThan; });
165 std::vector<V3D> reflections;
169 if (reflection.second.count() == 0) {
170 reflections.emplace_back(reflection.first);
180 [](
size_t totalReflections,
const std::pair<Kernel::V3D, UniqueReflection> &item) {
181 return totalReflections + item.second.count();
207 std::string &equivalentIntensities,
double &sigmaCritical,
209 double rMergeNumerator = 0.0;
210 double rPimNumerator = 0.0;
211 double intensitySumRValues = 0.0;
212 double iOverSigmaSum = 0.0;
214 for (
const auto &unique : uniqueReflections) {
218 if (unique.second.count() > 0) {
222 auto outliersRemoved = unique.second.removeOutliers(sigmaCritical, weightedZ);
226 auto intensities = outliersRemoved.getIntensities();
227 auto sigmas = outliersRemoved.getSigmas();
232 if (outliersRemoved.count() > 1) {
237 double meanIntensity = intensityStatistics.mean;
238 if (equivalentIntensities ==
"Median")
239 meanIntensity = intensityStatistics.median;
245 m_chiSquared += intensityStatistics.standard_deviation / meanIntensity;
248 double sumOfDeviationsFromMean =
249 std::accumulate(intensities.begin(), intensities.end(), 0.0, [meanIntensity](
double sum,
double intensity) {
250 return sum + fabs(intensity - meanIntensity);
254 rMergeNumerator += sumOfDeviationsFromMean;
257 double rPimFactor = sqrt(1.0 / (
static_cast<double>(outliersRemoved.count()) - 1.0));
258 rPimNumerator += (rPimFactor * sumOfDeviationsFromMean);
261 intensitySumRValues += std::accumulate(intensities.begin(), intensities.end(), 0.0);
264 const std::vector<Peak> &reflectionPeaks = outliersRemoved.getPeaks();
265 m_peaks.insert(
m_peaks.end(), reflectionPeaks.begin(), reflectionPeaks.end());
277 if (intensitySumRValues > 0.0) {
278 m_rMerge = rMergeNumerator / intensitySumRValues;
279 m_rPim = rPimNumerator / intensitySumRValues;
294 const std::vector<double> &intensities)
const {
295 return std::inner_product(intensities.begin(), intensities.end(), sigmas.begin(), 0.0, std::plus<double>(),
296 std::divides<double>());
301 double sumOfSquares = std::inner_product(data.begin(), data.end(), data.begin(), 0.0);
303 return sqrt(sumOfSquares /
static_cast<double>(data.size()));
309 return std::make_pair(0.0, 0.0);
312 auto dspacingLimitIterators = std::minmax_element(peaks.begin(), peaks.end(), [](
const Peak &lhs,
const Peak &
rhs) {
313 return lhs.getDSpacing() < rhs.getDSpacing();
316 return std::make_pair((*(dspacingLimitIterators.first)).getDSpacing(),
317 (*(dspacingLimitIterators.second)).getDSpacing());
const std::vector< double > & rhs
Structure describing a single-crystal peak.
Class to implement unit cell of crystals.
void round() noexcept
Round each component to the nearest integer.
std::shared_ptr< ReflectionCondition > ReflectionCondition_sptr
Shared pointer to a ReflectionCondition.
std::shared_ptr< PointGroup > PointGroup_sptr
Shared pointer to a PointGroup.
Statistics getStatistics(const std::vector< TYPE > &data, const unsigned int flags=StatOptions::AllStats)
Return a statistics object for the given data set.
std::vector< double > getZscore(const std::vector< TYPE > &data)
Return the Z score values for a dataset.
std::vector< double > getWeightedZscore(const std::vector< TYPE > &data, const std::vector< TYPE > &weights)
There are enough special cases in determining the Z score where it useful to put it in a single funct...