-
Notifications
You must be signed in to change notification settings - Fork 122
/
IndexSXPeaks.h
172 lines (161 loc) · 5.71 KB
/
IndexSXPeaks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IPeaksWorkspace_fwd.h"
#include "MantidCrystal/DllConfig.h"
#include "MantidGeometry/Crystal/UnitCell.h"
#include "MantidKernel/V3D.h"
#include <boost/tuple/tuple.hpp>
#include <iterator>
#include <set>
namespace Mantid {
namespace Crystal {
/** Peak indexing algorithm, which works by assigning multiple possible HKL
values to each peak and then culling these options
by comparison with neighbouring peaks.
@author L C Chapon, ISIS, Rutherford Appleton Laboratory
@date 11/08/2009
*/
struct MANTID_CRYSTAL_DLL index {
index(int h, int k, int l) : _h(h), _k(k), _l(l) {}
friend bool operator<(const index &i1, const index &i2) {
if (i1._h < i2._h)
return true;
else if (i1._h > i2._h)
return false;
if (i1._k < i2._k)
return true;
else if (i1._k > i2._k)
return false;
if (i1._l < i2._l)
return true;
else if (i1._l > i2._l)
return false;
return false;
}
friend bool operator==(const index &i1, const index &i2) {
if (i1._h != i2._h)
return false;
if (i1._k != i2._k)
return false;
if (i1._l != i2._l)
return false;
return true;
}
friend std::ostream &operator<<(std::ostream &os, const index &rhs) {
os << rhs._h << "," << rhs._k << "," << rhs._l;
return os;
}
int _h, _k, _l;
};
class MANTID_CRYSTAL_DLL PeakCandidate {
public:
PeakCandidate(double qx, double qy, double qz) : _Q(qx, qy, qz) {}
double getdSpacing() const { return 1 / _Q.norm(); }
void addHKL(int h, int k, int l) { _hkls.insert(index(h, k, l)); }
Mantid::Kernel::V3D getHKL() const {
if (_hkls.size() != 1) {
throw std::logic_error(
"Expecting a single HKL value for each peak. Refinement incomplete.");
}
Kernel::V3D result =
Kernel::V3D(_hkls.begin()->_h, _hkls.begin()->_k, _hkls.begin()->_l);
return result;
}
size_t candidateHKLSize() const { return _hkls.size(); }
void delHKL(int h, int k, int l) {
auto it = std::find(_hkls.cbegin(), _hkls.cend(), index(h, k, l));
if (it != _hkls.cend())
_hkls.erase(it);
}
const Mantid::Kernel::V3D &getQ() const { return _Q; }
double angle(const PeakCandidate &rhs) { return rhs._Q.angle(_Q); }
void setIndex(const std::set<index> &s) {
_hkls.clear();
_hkls = s;
}
void setFirst() {
if (!_hkls.empty()) {
auto it = _hkls.begin(); // Take the first possiblity
it++;
_hkls.erase(it, _hkls.end()); // Erase all others!
}
}
void clean(PeakCandidate &rhs, const Mantid::Geometry::UnitCell &uc,
double tolerance) {
double measured_angle = this->angle(rhs);
std::set<index>::iterator it1, it2;
std::set<index> s1;
std::set<index> s2;
for (it1 = _hkls.begin(); it1 != _hkls.end();
++it1) // All possible vectors for hkl on current instance
{
for (it2 = rhs._hkls.begin(); it2 != rhs._hkls.end();
++it2) // All possible vectors for hkl on other
{
const index &index1 = *it1;
const index &index2 = *it2;
double angle =
uc.recAngle(index1._h, index1._k, index1._l, index2._h, index2._k,
index2._l, 1); // calculate angle between each fictional
// primative vector on both this and
// other.
if (std::abs(angle - measured_angle) <
tolerance) // If peak angles are the same as the dspacing angles we
// can say that this peak corresponds to privatve vector
// hkl and the other corresponds to primative vector hkl
{
s1.insert(index1);
s2.insert(index2);
}
}
}
setIndex(s1);
rhs.setIndex(s2);
}
friend std::ostream &operator<<(std::ostream &os, const PeakCandidate &rhs) {
os << "Peak" << rhs._Q[0] << "," << rhs._Q[1] << "," << rhs._Q[2] << "\n";
std::copy(rhs._hkls.begin(), rhs._hkls.end(),
std::ostream_iterator<index>(os, ":"));
return os;
}
private:
Mantid::Kernel::V3D _Q;
std::set<index> _hkls;
};
class MANTID_CRYSTAL_DLL IndexSXPeaks : public API::Algorithm {
public:
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "IndexSXPeaks"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Takes a PeaksWorkspace and a B-Matrix and determines the HKL "
"values corresponding to each Single Crystal peak. Sets indexes on "
"the input/output workspace.";
}
/// Algorithm's version for identification overriding a virtual method
int version() const override { return (1); }
const std::vector<std::string> seeAlso() const override {
return {"IndexPeaks"};
}
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "Crystal\\Peaks"; }
private:
// Helper method to cull potential hkls off each peak.
void cullHKLs(std::vector<PeakCandidate> &peakCandidates,
Mantid::Geometry::UnitCell &unitcell);
// Helper method used to check that not all peaks are colinear.
void validateNotColinear(std::vector<PeakCandidate> &peakCandidates) const;
// Overridden Algorithm methods
void init() override;
//
void exec() override;
//
};
} // namespace Crystal
} // namespace Mantid