46 "An input PeaksWorkspace with an instrument.");
50 std::vector<std::string> pgOptions;
53 [](
const auto &group) { return group->getSymbol(); });
55 [](
const auto &group) { return group->getName(); });
57 pgOptions.emplace_back(
"222 (Orthorombic)");
58 pgOptions.emplace_back(
"mm2 (Orthorombic)");
59 pgOptions.emplace_back(
"2mm (Orthorombic)");
60 pgOptions.emplace_back(
"m2m (Orthorombic)");
61 pgOptions.emplace_back(
"mmm (Orthorombic)");
62 declareProperty(
"PointGroup", pgOptions[0], std::make_shared<StringListValidator>(pgOptions),
63 "Which point group applies to this crystal?");
65 std::vector<std::string> centeringOptions;
66 centeringOptions.reserve(2 *
m_refConds.size());
68 [](
const auto &condition) { return condition->getSymbol(); });
70 [](
const auto &condition) { return condition->getName(); });
71 declareProperty(
"LatticeCentering", centeringOptions[0], std::make_shared<StringListValidator>(centeringOptions),
72 "Appropriate lattice centering for the peaks.");
75 "Output PeaksWorkspace");
79 "An output table workspace for the statistics of the peaks.");
83 "Append to output table workspace if true.\n"
84 "If false, new output table workspace (default).");
85 const std::vector<std::string> equivTypes{
"Mean",
"Median"};
86 declareProperty(
"EquivalentIntensities", equivTypes.front(), std::make_shared<StringListValidator>(equivTypes),
87 "Replace intensities by mean(default), "
90 "Removes peaks whose intensity deviates more than "
91 "SigmaCritical from the mean (or median).");
94 "Output Equivalent Intensities");
96 "Use weighted ZScore if true.\n"
97 "If false, standard ZScore (default).");
103 const std::vector<Peak> &inputPeaks = inputPeaksWorkspace->getPeaks();
107 g_log.
warning() <<
"Number of peaks should not be 0 for SortHKL.\n";
111 UnitCell cell = inputPeaksWorkspace->sample().getOrientedLattice();
114 std::string equivalentIntensities =
getPropertyValue(
"EquivalentIntensities");
115 double sigmaCritical =
getProperty(
"SigmaCritical");
119 "Workspace2D", uniqueReflections.
getReflections().size(), 20, 20);
122 auto tAxis = std::make_unique<TextAxis>(uniqueReflections.
getReflections().size());
129 if (unique.second.count() > 2) {
130 tAxis->setLabel(counter,
" " + unique.second.getHKL().toString());
131 auto &UniqX = UniqWksp->mutableX(counter);
132 auto &UniqY = UniqWksp->mutableY(counter);
133 auto &UniqE = UniqWksp->mutableE(counter);
135 auto wavelengths = unique.second.getWavelengths();
136 auto intensities = unique.second.getIntensities();
137 g_log.
debug() <<
"HKL " << unique.second.getHKL() <<
"\n";
139 for (
const auto &e : intensities)
142 std::vector<double> zScores;
146 auto sigmas = unique.second.getSigmas();
150 if (zScores.size() > maxPeaks)
151 maxPeaks = zScores.size();
153 auto outliersRemoved = unique.second.removeOutliers(sigmaCritical, weightedZ);
155 auto intensityStatistics =
158 g_log.
debug() <<
"Mean = " << intensityStatistics.mean <<
" Median = " << intensityStatistics.median <<
"\n";
160 for (
size_t i = 0; i < wavelengths.size(); i++) {
162 for (
size_t j = i + 1; j < wavelengths.size(); j++) {
163 if (wavelengths[j] < wavelengths[i0])
168 double temp = wavelengths[i0];
169 wavelengths[i0] = wavelengths[i];
170 wavelengths[i] = temp;
171 temp = intensities[i0];
172 intensities[i0] = intensities[i];
173 intensities[i] = temp;
176 for (
size_t i = 0; i < std::min(zScores.size(),
static_cast<size_t>(20)); ++i) {
177 UniqX[i] = wavelengths[i];
178 UniqY[i] = intensities[i];
179 if (zScores[i] > sigmaCritical)
180 UniqE[i] = intensities[i];
181 else if (equivalentIntensities ==
"Mean")
182 UniqE[i] = intensityStatistics.mean - intensities[i];
184 UniqE[i] = intensityStatistics.median - intensities[i];
194 for (int64_t i = 0; i < counter; ++i) {
195 auto &outSpec = UniqWksp2->getSpectrum(i);
196 const auto &inSpec = UniqWksp->getSpectrum(i);
197 outSpec.setHistogram(inSpec.histogram());
199 outSpec.copyInfoFrom(inSpec);
201 UniqWksp2->replaceAxis(1, std::move(tAxis));
207 PeaksStatistics peaksStatistics(uniqueReflections, equivalentIntensities, sigmaCritical, weightedZ);
210 const std::string tableName =
getProperty(
"StatisticsTable");
218 std::vector<Peak> &originalOutputPeaks = outputPeaksWorkspace->getPeaks();
219 originalOutputPeaks.swap(peaksStatistics.
m_peaks);
223 setProperty(
"OutputWorkspace", outputPeaksWorkspace);
232 std::vector<Peak> peaks;
233 peaks.reserve(inputPeaks.size());
235 std::remove_copy_if(inputPeaks.begin(), inputPeaks.end(), std::back_inserter(peaks), [](
const Peak &peak) {
236 return peak.getIntensity() <= 0.0 || peak.getSigmaIntensity() <= 0.0 || peak.getIntMNP() != V3D(0, 0, 0) ||
237 peak.getHKL() == V3D(0, 0, 0);
258 std::pair<double, double> dLimits =
getDLimits(peaks, cell);
272 [refCondName](
const auto &condition) { return condition->getName() == refCondName; });
286 size_t pos = pointGroupName.find(
"Orthorombic");
287 if (pos != std::string::npos) {
288 g_log.
warning() <<
"Orthorhomic is misspelled in your script.\n";
289 pointGroupName.replace(pos, 11,
"Orthorhombic");
290 g_log.
warning() <<
"Please correct to " << pointGroupName <<
".\n";
293 [&pointGroupName](
const auto &group) { return group->getName() == pointGroupName; });
305 auto dLimitIterators = std::minmax_element(peaks.begin(), peaks.end(), [cell](
const Peak &lhs,
const Peak &
rhs) {
306 return cell.d(lhs.getHKL()) < cell.d(rhs.getHKL());
309 return std::make_pair(cell.
d((*dLimitIterators.first).getHKL()), cell.
d((*dLimitIterators.second).getHKL()));
322 tablews = std::make_shared<TableWorkspace>();
323 tablews->addColumn(
"str",
"Resolution Shell");
324 tablews->addColumn(
"int",
"No. of Unique Reflections");
325 tablews->addColumn(
"double",
"Resolution Min");
326 tablews->addColumn(
"double",
"Resolution Max");
327 tablews->addColumn(
"double",
"Multiplicity");
328 tablews->addColumn(
"double",
"Mean ((I)/sd(I))");
329 tablews->addColumn(
"double",
"Rmerge");
330 tablews->addColumn(
"double",
"Rpim");
331 tablews->addColumn(
"double",
"Data Completeness");
341 throw std::runtime_error(
"Can't store statistics into Null-table.");
345 double completeness = 0.0;
346 if (
name.substr(0, 4) !=
"bank") {
355 << 100.0 * statistics.
m_rPim << 100.0 * completeness;
361 if (outputPeaksWorkspace != inputPeaksWorkspace) {
362 outputPeaksWorkspace = inputPeaksWorkspace->clone();
365 return outputPeaksWorkspace;
371 std::vector<std::pair<std::string, bool>> criteria{{
"H",
true}, {
"K",
true}, {
"L",
true}};
372 outputPeaksWorkspace->sort(criteria);
#define DECLARE_ALGORITHM(classname)
const std::vector< double > & rhs
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
Save a PeaksWorkspace to a Gsas-style ASCII .hkl file.
void sortOutputPeaksByHKL(const API::IPeaksWorkspace_sptr &outputPeaksWorkspace)
Sorts the peaks in the workspace by H, K and L.
std::vector< Mantid::Geometry::ReflectionCondition_sptr > m_refConds
Reflection conditions.
API::ITableWorkspace_sptr getStatisticsTable(const std::string &name) const
Create a TableWorkspace for the statistics with appropriate columns or get one from the ADS.
DataObjects::PeaksWorkspace_sptr getOutputPeaksWorkspace(const DataObjects::PeaksWorkspace_sptr &inputPeaksWorkspace) const
Returns a PeaksWorkspace which is either the input workspace or a clone.
std::pair< double, double > getDLimits(const std::vector< DataObjects::Peak > &peaks, const Geometry::UnitCell &cell) const
Returns the lowest and highest d-Value in the list.
void insertStatisticsIntoTable(const API::ITableWorkspace_sptr &table, const PeakStatisticsTools::PeaksStatistics &statistics) const
Inserts statistics the supplied PeaksStatistics-objects into the supplied TableWorkspace.
Geometry::ReflectionCondition_sptr getCentering() const
Returns the centering extracted from the user-supplied property.
Geometry::PointGroup_sptr getPointgroup() const
Returns the PointGroup-object constructed from the property supplied by the user.
std::vector< DataObjects::Peak > getNonZeroPeaks(const std::vector< DataObjects::Peak > &inputPeaks) const
Returns a vector which contains only peaks with I > 0, sigma > 0 and valid HKL.
const std::string name() const override
Algorithm's name for identification.
void init() override
Virtual method - must be overridden by concrete algorithm.
PeakStatisticsTools::UniqueReflectionCollection getUniqueReflections(const std::vector< DataObjects::Peak > &peaks, const Geometry::UnitCell &cell) const
SortHKL::getUniqueReflections.
std::vector< Mantid::Geometry::PointGroup_sptr > m_pointGroups
Point Groups possible.
void exec() override
Virtual method - must be overridden by concrete algorithm.
Structure describing a single-crystal peak.
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
Class to implement unit cell of crystals.
double d(double h, double k, double l) const
Return d-spacing ( ) for a given h,k,l coordinate.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< ReflectionCondition > ReflectionCondition_sptr
Shared pointer to a ReflectionCondition.
std::shared_ptr< PointGroup > PointGroup_sptr
Shared pointer to a PointGroup.
MANTID_GEOMETRY_DLL const ReflectionConditions & getAllReflectionConditions()
MANTID_GEOMETRY_DLL std::vector< PointGroup_sptr > getAllPointGroups()
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...
@ Input
An input workspace.
@ Output
An output workspace.