-
Notifications
You must be signed in to change notification settings - Fork 122
/
PoldiPeak.cpp
166 lines (136 loc) · 3.93 KB
/
PoldiPeak.cpp
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
#include "MantidSINQ/PoldiUtilities/PoldiPeak.h"
#include <cmath>
#include <stdexcept>
#include "boost/bind.hpp"
namespace Mantid {
namespace Poldi {
PoldiPeak_sptr PoldiPeak::clone() const
{
return PoldiPeak_sptr(new PoldiPeak(*this));
}
const MillerIndices &PoldiPeak::hkl() const
{
return m_hkl;
}
void PoldiPeak::setHKL(MillerIndices hkl)
{
m_hkl = hkl;
}
UncertainValue PoldiPeak::d() const
{
return m_d;
}
UncertainValue PoldiPeak::q() const
{
return m_q;
}
double PoldiPeak::twoTheta(double lambda) const
{
return 2.0 * asin(lambda / (2.0 * m_d));
}
UncertainValue PoldiPeak::fwhm(FwhmRelation relation) const
{
switch(relation) {
case AbsoluteQ:
return m_q.value() * m_fwhmRelative;
case AbsoluteD:
return m_d.value() * m_fwhmRelative;
default:
return m_fwhmRelative;
}
}
UncertainValue PoldiPeak::intensity() const
{
return m_intensity;
}
void PoldiPeak::setD(UncertainValue d)
{
if(d <= 0.0) {
throw std::domain_error("d-Value cannot be 0 or smaller.");
}
m_d = d;
m_q = PoldiPeak::dToQ(m_d);
}
void PoldiPeak::setQ(UncertainValue q)
{
if(q <= 0.0) {
throw std::domain_error("q-Value cannot be 0 or smaller.");
}
m_q = q;
m_d = PoldiPeak::qToD(m_q);
}
void PoldiPeak::setIntensity(UncertainValue intensity)
{
m_intensity = intensity;
}
void PoldiPeak::setFwhm(UncertainValue fwhm, FwhmRelation relation)
{
switch(relation) {
case AbsoluteQ:
if(m_q.value() <= 0) {
throw std::domain_error("Cannot store FWHM for peak with Q-Value less or equal to 0.");
}
m_fwhmRelative = fwhm / m_q.value();
break;
case AbsoluteD:
if(m_d.value() <= 0) {
throw std::domain_error("Cannot store FWHM for peak with d-Value less or equal to 0.");
}
m_fwhmRelative = fwhm / m_d.value();
break;
default:
m_fwhmRelative = fwhm;
break;
}
}
void PoldiPeak::multiplyErrors(double factor)
{
setQ(UncertainValue(m_q.value(), m_q.error() * factor));
setFwhm(UncertainValue(m_fwhmRelative.value(), m_fwhmRelative.error() * factor), PoldiPeak::Relative);
setIntensity(UncertainValue(m_intensity.value(), m_intensity.error() * factor));
}
UncertainValue PoldiPeak::dToQ(UncertainValue d)
{
return 2.0 * M_PI / d;
}
UncertainValue PoldiPeak::qToD(UncertainValue q)
{
return 2.0 * M_PI / q;
}
PoldiPeak_sptr PoldiPeak::create(UncertainValue qValue)
{
return PoldiPeak_sptr(new PoldiPeak(PoldiPeak::qToD(qValue)));
}
PoldiPeak_sptr PoldiPeak::create(double qValue)
{
return PoldiPeak::create(UncertainValue(qValue));
}
PoldiPeak_sptr PoldiPeak::create(UncertainValue qValue, UncertainValue intensity)
{
return PoldiPeak_sptr(new PoldiPeak(PoldiPeak::qToD(qValue), intensity));
}
PoldiPeak_sptr PoldiPeak::create(double qValue, double intensity)
{
return PoldiPeak::create(UncertainValue(qValue), UncertainValue(intensity));
}
PoldiPeak_sptr PoldiPeak::create(MillerIndices hkl, UncertainValue dValue, UncertainValue intensity, UncertainValue fwhmRelative)
{
return PoldiPeak_sptr(new PoldiPeak(dValue, intensity, fwhmRelative, hkl));
}
bool PoldiPeak::greaterThan(const PoldiPeak_sptr &first, const PoldiPeak_sptr &second, UncertainValue (PoldiPeak::*function)() const)
{
return static_cast<double>(boost::bind<UncertainValue>(function, first.get())()) > static_cast<double>(boost::bind<UncertainValue>(function, second.get())());
}
bool PoldiPeak::lessThan(const PoldiPeak_sptr &first, const PoldiPeak_sptr &second, UncertainValue (PoldiPeak::*function)() const)
{
return static_cast<double>(boost::bind<UncertainValue>(function, first.get())()) < static_cast<double>(boost::bind<UncertainValue>(function, second.get())());
}
PoldiPeak::PoldiPeak(UncertainValue d, UncertainValue intensity, UncertainValue fwhm, MillerIndices hkl) :
m_hkl(hkl),
m_intensity(intensity)
{
setD(d);
setFwhm(fwhm, Relative);
}
}
}