-
Notifications
You must be signed in to change notification settings - Fork 122
/
ConvertCWPDMDToSpectra.h
176 lines (144 loc) · 6.27 KB
/
ConvertCWPDMDToSpectra.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
173
174
175
176
#ifndef MANTID_MDALGORITHMS_CONVERTCWPDMDTOSPECTRA_H_
#define MANTID_MDALGORITHMS_CONVERTCWPDMDTOSPECTRA_H_
#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IMDEventWorkspace.h"
namespace Mantid {
namespace MDAlgorithms {
//----------------------------------------------------------------------------------------------
/** Calculate d-space value from detector's position (2theta/theta) and
* wavelength
* @brief calculateDspaceFrom2Theta
* @param twotheta
* @param wavelength
* @return
*/
inline double calculateDspaceFrom2Theta(const double &twotheta,
const double &wavelength) {
return (0.5 * wavelength / sin(twotheta * 0.5 * M_PI / 180.));
}
//----------------------------------------------------------------------------------------------
/** Calcualte detector's 2theta value from d-spacing value
* 2theta = 2*asin(lamba/2/d)
* @brief calculate2ThetaFromD
* @param dspace
* @param wavelength
* @return
*/
inline double calculate2ThetaFromD(const double &dspace,
const double &wavelength) {
return (2.0 * asin(0.5 * wavelength / dspace) * 180. / M_PI);
}
//----------------------------------------------------------------------------------------------
/** Calculate Q value from detector's positin (2theta/theta) and wavelength
* q = 2 k sin(theta) = (4 pi)/(lambda) * sin(theta)
* @brief calculateQ
* @param twotheta
* @param wavelength
* @return
*/
inline double calculateQFrom2Theta(const double &twotheta,
const double &wavelength) {
return (4. * M_PI * sin(twotheta * 0.5 * M_PI / 180.) / wavelength);
}
//----------------------------------------------------------------------------------------------
/** Calculate detector's 2theta value from Q
* 2theta = 2*asin(lambda*Q/(4pi))
* @brief calcualte2ThetaFromQ
* @param q
* @param wavelength
* @return
*/
inline double calcualte2ThetaFromQ(const double &q, const double &wavelength) {
return (2.0 * asin(q * wavelength * 0.25 / M_PI) * 180. / M_PI);
}
//----------------------------------------------------------------------------------------------
/** Calculate 2theta value of detector postion from sample position
* @brief calculate2Theta
* @param detpos
* @param samplepos
* @return
*/
inline double calculate2Theta(const Kernel::V3D &detpos,
const Kernel::V3D &samplepos) {
return detpos.angle(samplepos);
}
/** ConvertCWPDMDToSpectra : Convert one MDWorkspaces containing reactor-source
powder diffractometer's data to single spectrum matrix workspace
by merging and binning the detectors' counts by their 2theta value.
Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ConvertCWPDMDToSpectra : public API::Algorithm {
public:
ConvertCWPDMDToSpectra();
virtual ~ConvertCWPDMDToSpectra();
/// Algorithm's name
virtual const std::string name() const { return "ConvertCWPDMDToSpectra"; }
/// Summary of algorithms purpose
virtual const std::string summary() const {
return "Convert constant wavelength (CW) powder diffraction (PD) data in "
"MDEventWorksapces "
" to a single-spectrum MatrixWorkspace, i.e., binning the "
"diffraction data "
" to single spectrum according to neutron's scattering angle, "
"d-spacing or Q. ";
}
/// Algorithm's version
virtual int version() const { return (1); }
/// Algorithm's category for identification
virtual const std::string category() const {
return "Diffraction;MDAlgorithms";
}
private:
/// Initialisation code
void init();
/// Execution code
void exec();
/// Main algorithm to reduce powder diffraction data
API::MatrixWorkspace_sptr reducePowderData(
API::IMDEventWorkspace_const_sptr dataws,
API::IMDEventWorkspace_const_sptr monitorws, const std::string targetunit,
const std::map<int, double> &map_runwavelength, const double xmin,
const double xmax, const double binsize, bool dolinearinterpolation);
/// Find the binning boundary according to detectors' positions
void findXBoundary(API::IMDEventWorkspace_const_sptr dataws,
const std::string &targetunit,
const std::map<int, double> &map_runwavelength,
double &xmin, double &xmax);
/// Bin signals to its 2theta position
void binMD(API::IMDEventWorkspace_const_sptr mdws, const char &unitbit,
const std::map<int, double> &map_runlambda,
const std::vector<double> &vecx, std::vector<double> &vecy);
/// Do linear interpolation to zero counts if bin is too small
void linearInterpolation(API::MatrixWorkspace_sptr matrixws,
const double &infinitesimal);
/// Set up sample logs
void setupSampleLogs(API::MatrixWorkspace_sptr matrixws,
API::IMDEventWorkspace_const_sptr inputmdws);
/// Scale reduced data
void scaleMatrixWorkspace(API::MatrixWorkspace_sptr matrixws,
const double &scalefactor,
const double &infinitesimal);
/// Convert units from 2theta to d-spacing or Q
void convertUnits(API::MatrixWorkspace_sptr matrixws,
const std::string &targetunit, const double &wavelength);
/// Infinitesimal value
double m_infitesimal;
};
} // namespace MDAlgorithms
} // namespace Mantid
#endif /* MANTID_MDALGORITHMS_CONVERTCWPDMDTOSPECTRA_H_ */