Mantid
Loading...
Searching...
No Matches
IndexSXPeaks.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11#include "MantidCrystal/DllConfig.h"
13#include "MantidKernel/V3D.h"
14#include <boost/tuple/tuple.hpp>
15
16#include <iterator>
17#include <set>
18
19namespace Mantid {
20namespace Crystal {
29struct MANTID_CRYSTAL_DLL index {
30 index(int h, int k, int l) : _h(h), _k(k), _l(l) {}
31 friend bool operator<(const index &i1, const index &i2) {
32 if (i1._h < i2._h)
33 return true;
34 else if (i1._h > i2._h)
35 return false;
36 if (i1._k < i2._k)
37 return true;
38 else if (i1._k > i2._k)
39 return false;
40 if (i1._l < i2._l)
41 return true;
42 else if (i1._l > i2._l)
43 return false;
44 return false;
45 }
46 friend bool operator==(const index &i1, const index &i2) {
47 if (i1._h != i2._h)
48 return false;
49 if (i1._k != i2._k)
50 return false;
51 if (i1._l != i2._l)
52 return false;
53 return true;
54 }
55 friend std::ostream &operator<<(std::ostream &os, const index &rhs) {
56 os << rhs._h << "," << rhs._k << "," << rhs._l;
57 return os;
58 }
59 int _h, _k, _l;
60};
61
62class MANTID_CRYSTAL_DLL PeakCandidate {
63public:
64 PeakCandidate(double qx, double qy, double qz) : _Q(qx, qy, qz) {}
65 double getdSpacing() const { return 1 / _Q.norm(); }
66 void addHKL(int h, int k, int l) { _hkls.insert(index(h, k, l)); }
68 if (_hkls.size() != 1) {
69 throw std::logic_error("Expecting a single HKL value for each peak. Refinement incomplete.");
70 }
71 Kernel::V3D result = Kernel::V3D(_hkls.begin()->_h, _hkls.begin()->_k, _hkls.begin()->_l);
72 return result;
73 }
74 size_t candidateHKLSize() const { return _hkls.size(); }
75 void delHKL(int h, int k, int l) {
76 auto it = std::find(_hkls.cbegin(), _hkls.cend(), index(h, k, l));
77 if (it != _hkls.cend())
78 _hkls.erase(it);
79 }
80 const Mantid::Kernel::V3D &getQ() const { return _Q; }
81 double angle(const PeakCandidate &rhs) const { return rhs._Q.angle(_Q); }
82 void setIndex(const std::set<index> &s) {
83 _hkls.clear();
84 _hkls = s;
85 }
86 void setFirst() {
87 if (!_hkls.empty()) {
88 auto it = _hkls.begin(); // Take the first possiblity
89 it++;
90 _hkls.erase(it, _hkls.end()); // Erase all others!
91 }
92 }
94 double measured_angle = this->angle(rhs);
95 std::set<index>::iterator it1, it2;
96 std::set<index> s1;
97 std::set<index> s2;
98 for (it1 = _hkls.begin(); it1 != _hkls.end(); ++it1) // All possible vectors for hkl on current instance
99 {
100 for (it2 = rhs._hkls.begin(); it2 != rhs._hkls.end(); ++it2) // All possible vectors for hkl on other
101 {
102 const index &index1 = *it1;
103 const index &index2 = *it2;
104
105 // calculate angle between each fictional primative vector on both this and other.
106 double reciprocalAngle = uc.recAngle(index1._h, index1._k, index1._l, index2._h, index2._k, index2._l, 1);
107
108 // If peak angles are the same as the dspacing angles we can say that this peak corresponds to privatve vector
109 // hkl and the other corresponds to primative vector hkl
110 if (std::abs(reciprocalAngle - measured_angle) < tolerance) {
111 s1.insert(index1);
112 s2.insert(index2);
113 }
114 }
115 }
116 setIndex(s1);
117 rhs.setIndex(s2);
118 }
119 friend std::ostream &operator<<(std::ostream &os, const PeakCandidate &rhs) {
120 os << "Peak" << rhs._Q[0] << "," << rhs._Q[1] << "," << rhs._Q[2] << "\n";
121 std::copy(rhs._hkls.begin(), rhs._hkls.end(), std::ostream_iterator<index>(os, ":"));
122 return os;
123 }
124
125private:
127 std::set<index> _hkls;
128};
129
130class MANTID_CRYSTAL_DLL IndexSXPeaks final : public API::Algorithm {
131public:
133 const std::string name() const override { return "IndexSXPeaks"; }
135 const std::string summary() const override {
136 return "Takes a PeaksWorkspace and a B-Matrix and determines the HKL "
137 "values corresponding to each Single Crystal peak. Sets indexes on "
138 "the input/output workspace.";
139 }
140
142 int version() const override { return 1; }
143 const std::vector<std::string> seeAlso() const override { return {"IndexPeaks"}; }
145 const std::string category() const override { return "Crystal\\Peaks"; }
146
147private:
148 // Helper method to cull potential hkls off each peak.
149 void cullHKLs(std::vector<PeakCandidate> &peakCandidates, Mantid::Geometry::UnitCell &unitcell);
150 // Helper method used to check that not all peaks are colinear.
151 void validateNotColinear(const std::vector<PeakCandidate> &peakCandidates) const;
152 // Overridden Algorithm methods
153 void init() override;
154 //
155 void exec() override;
156 //
157};
158
159} // namespace Crystal
160} // namespace Mantid
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
double tolerance
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Definition: IndexSXPeaks.h:143
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
Definition: IndexSXPeaks.h:145
const std::string summary() const override
Summary of algorithms purpose.
Definition: IndexSXPeaks.h:135
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition: IndexSXPeaks.h:142
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition: IndexSXPeaks.h:133
double angle(const PeakCandidate &rhs) const
Definition: IndexSXPeaks.h:81
friend std::ostream & operator<<(std::ostream &os, const PeakCandidate &rhs)
Definition: IndexSXPeaks.h:119
PeakCandidate(double qx, double qy, double qz)
Definition: IndexSXPeaks.h:64
void clean(PeakCandidate &rhs, const Mantid::Geometry::UnitCell &uc, double tolerance)
Definition: IndexSXPeaks.h:93
void delHKL(int h, int k, int l)
Definition: IndexSXPeaks.h:75
Mantid::Kernel::V3D getHKL() const
Definition: IndexSXPeaks.h:67
void addHKL(int h, int k, int l)
Definition: IndexSXPeaks.h:66
void setIndex(const std::set< index > &s)
Definition: IndexSXPeaks.h:82
const Mantid::Kernel::V3D & getQ() const
Definition: IndexSXPeaks.h:80
Class to implement unit cell of crystals.
Definition: UnitCell.h:44
double recAngle(double h1, double k1, double l1, double h2, double k2, double l2, const int angleunit=angDegrees) const
Calculate the angle in degrees or radians between two reciprocal vectors (h1,k1,l1) and (h2,...
Definition: UnitCell.cpp:718
Class for 3D vectors.
Definition: V3D.h:34
Helper class which provides the Collimation Length for SANS instruments.
Peak indexing algorithm, which works by assigning multiple possible HKL values to each peak and then ...
Definition: IndexSXPeaks.h:29
friend bool operator==(const index &i1, const index &i2)
Definition: IndexSXPeaks.h:46
friend std::ostream & operator<<(std::ostream &os, const index &rhs)
Definition: IndexSXPeaks.h:55
friend bool operator<(const index &i1, const index &i2)
Definition: IndexSXPeaks.h:31
index(int h, int k, int l)
Definition: IndexSXPeaks.h:30