45 "An input PeaksWorkspace with an instrument.");
49 std::vector<std::string> pgOptions;
52 [](
const auto &
group) { return group->getSymbol(); });
54 [](
const auto &
group) { return group->getName(); });
56 pgOptions.emplace_back(
"222 (Orthorombic)");
57 pgOptions.emplace_back(
"mm2 (Orthorombic)");
58 pgOptions.emplace_back(
"2mm (Orthorombic)");
59 pgOptions.emplace_back(
"m2m (Orthorombic)");
60 pgOptions.emplace_back(
"mmm (Orthorombic)");
61 declareProperty(
"PointGroup", pgOptions[0], std::make_shared<StringListValidator>(pgOptions),
62 "Which point group applies to this crystal?");
64 std::vector<std::string> centeringOptions;
65 centeringOptions.reserve(2 *
m_refConds.size());
67 [](
const auto &condition) { return condition->getSymbol(); });
69 [](
const auto &condition) { return condition->getName(); });
70 declareProperty(
"LatticeCentering", centeringOptions[0], std::make_shared<StringListValidator>(centeringOptions),
71 "Appropriate lattice centering for the peaks.");
74 "Output PeaksWorkspace");
78 "An output table workspace for the statistics of the peaks.");
82 "Append to output table workspace if true.\n"
83 "If false, new output table workspace (default).");
84 const std::vector<std::string> equivTypes{
"Mean",
"Median"};
85 declareProperty(
"EquivalentIntensities", equivTypes.front(), std::make_shared<StringListValidator>(equivTypes),
86 "Replace intensities by mean(default), "
89 "Removes peaks whose intensity deviates more than "
90 "SigmaCritical from the mean (or median).");
93 "Output Equivalent Intensities");
95 "Use weighted ZScore if true.\n"
96 "If false, standard ZScore (default).");
102 const std::vector<Peak> &inputPeaks = inputPeaksWorkspace->getPeaks();
106 g_log.
warning() <<
"Number of peaks should not be 0 for SortHKL.\n";
110 UnitCell cell = inputPeaksWorkspace->sample().getOrientedLattice();
113 std::string equivalentIntensities =
getPropertyValue(
"EquivalentIntensities");
114 double sigmaCritical =
getProperty(
"SigmaCritical");
118 "Workspace2D", uniqueReflections.
getReflections().size(), 20, 20);
121 auto tAxis = std::make_unique<TextAxis>(uniqueReflections.
getReflections().size());
122 UniqWksp->getAxis(0)->unit() = UnitFactory::Instance().create(
"Wavelength");
128 if (unique.second.count() > 2) {
129 tAxis->setLabel(counter,
" " + unique.second.getHKL().toString());
130 auto &UniqX = UniqWksp->mutableX(counter);
131 auto &UniqY = UniqWksp->mutableY(counter);
132 auto &UniqE = UniqWksp->mutableE(counter);
134 auto wavelengths = unique.second.getWavelengths();
135 auto intensities = unique.second.getIntensities();
136 g_log.
debug() <<
"HKL " << unique.second.getHKL() <<
"\n";
138 for (
const auto &e : intensities)
141 std::vector<double> zScores;
145 auto sigmas = unique.second.getSigmas();
149 if (zScores.size() > maxPeaks)
150 maxPeaks = zScores.size();
152 auto outliersRemoved = unique.second.removeOutliers(sigmaCritical, weightedZ);
154 auto intensityStatistics =
157 g_log.
debug() <<
"Mean = " << intensityStatistics.mean <<
" Median = " << intensityStatistics.median <<
"\n";
159 for (
size_t i = 0; i < wavelengths.size(); i++) {
161 for (
size_t j = i + 1; j < wavelengths.size(); j++) {
162 if (wavelengths[j] < wavelengths[i0])
167 double temp = wavelengths[i0];
168 wavelengths[i0] = wavelengths[i];
169 wavelengths[i] = temp;
170 temp = intensities[i0];
171 intensities[i0] = intensities[i];
172 intensities[i] = temp;
175 for (
size_t i = 0; i < std::min(zScores.size(),
static_cast<size_t>(20)); ++i) {
176 UniqX[i] = wavelengths[i];
177 UniqY[i] = intensities[i];
178 if (zScores[i] > sigmaCritical)
179 UniqE[i] = intensities[i];
180 else if (equivalentIntensities ==
"Mean")
181 UniqE[i] = intensityStatistics.mean - intensities[i];
183 UniqE[i] = intensityStatistics.median - intensities[i];
193 for (int64_t i = 0; i < counter; ++i) {
194 auto &outSpec = UniqWksp2->getSpectrum(i);
195 const auto &inSpec = UniqWksp->getSpectrum(i);
196 outSpec.setHistogram(inSpec.histogram());
198 outSpec.copyInfoFrom(inSpec);
200 UniqWksp2->replaceAxis(1, std::move(tAxis));
206 PeaksStatistics peaksStatistics(uniqueReflections, equivalentIntensities, sigmaCritical, weightedZ);
209 const std::string tableName =
getProperty(
"StatisticsTable");
217 std::vector<Peak> &originalOutputPeaks = outputPeaksWorkspace->getPeaks();
218 originalOutputPeaks.swap(peaksStatistics.
m_peaks);
222 setProperty(
"OutputWorkspace", outputPeaksWorkspace);
225 AnalysisDataService::Instance().addOrReplace(tableName, statisticsTable);
231 std::vector<Peak> peaks;
232 peaks.reserve(inputPeaks.size());
234 std::remove_copy_if(inputPeaks.begin(), inputPeaks.end(), std::back_inserter(peaks), [](
const Peak &peak) {
235 return peak.getIntensity() <= 0.0 || peak.getSigmaIntensity() <= 0.0 || peak.getIntMNP() != V3D(0, 0, 0) ||
236 peak.getHKL() == V3D(0, 0, 0);
257 std::pair<double, double> dLimits =
getDLimits(peaks, cell);
271 [refCondName](
const auto &condition) { return condition->getName() == refCondName; });
282 PointGroup_sptr pointGroup = PointGroupFactory::Instance().createPointGroup(
"-1");
285 size_t pos = pointGroupName.find(
"Orthorombic");
286 if (pos != std::string::npos) {
287 g_log.
warning() <<
"Orthorhomic is misspelled in your script.\n";
288 pointGroupName.replace(pos, 11,
"Orthorhombic");
289 g_log.
warning() <<
"Please correct to " << pointGroupName <<
".\n";
292 [&pointGroupName](
const auto &
group) { return group->getName() == pointGroupName; });
304 auto dLimitIterators = std::minmax_element(peaks.begin(), peaks.end(), [cell](
const Peak &lhs,
const Peak &
rhs) {
305 return cell.d(lhs.getHKL()) < cell.d(rhs.getHKL());
308 return std::make_pair(cell.
d((*dLimitIterators.first).getHKL()), cell.
d((*dLimitIterators.second).getHKL()));
318 if (append && AnalysisDataService::Instance().doesExist(
name)) {
321 tablews = std::make_shared<TableWorkspace>();
322 tablews->addColumn(
"str",
"Resolution Shell");
323 tablews->addColumn(
"int",
"No. of Unique Reflections");
324 tablews->addColumn(
"double",
"Resolution Min");
325 tablews->addColumn(
"double",
"Resolution Max");
326 tablews->addColumn(
"double",
"Multiplicity");
327 tablews->addColumn(
"double",
"Mean ((I)/sd(I))");
328 tablews->addColumn(
"double",
"Rmerge");
329 tablews->addColumn(
"double",
"Rpim");
330 tablews->addColumn(
"double",
"Data Completeness");
340 throw std::runtime_error(
"Can't store statistics into Null-table.");
344 double completeness = 0.0;
345 if (rowName.substr(0, 4) !=
"bank") {
354 << 100.0 * statistics.
m_rPim << 100.0 * completeness;
360 if (outputPeaksWorkspace != inputPeaksWorkspace) {
361 outputPeaksWorkspace = inputPeaksWorkspace->clone();
364 return outputPeaksWorkspace;
370 std::vector<std::pair<std::string, bool>> criteria{{
"H",
true}, {
"K",
true}, {
"L",
true}};
371 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.