-
Notifications
You must be signed in to change notification settings - Fork 122
/
ReflectometryReductionOne2.h
180 lines (172 loc) · 8.18 KB
/
ReflectometryReductionOne2.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
177
178
179
180
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2013 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 "MantidReflectometry/ReflectometryWorkflowBase2.h"
namespace Mantid {
// Forward declaration
namespace API {
class SpectrumInfo;
}
namespace Geometry {
class ReferenceFrame;
}
namespace HistogramData {
class HistogramX;
class HistogramY;
class HistogramE;
} // namespace HistogramData
namespace Reflectometry {
/** ReflectometryReductionOne2 : Reflectometry reduction of a single input TOF
workspace to an IvsQ workspace. Version 2 of the algorithm.
*/
class MANTID_REFLECTOMETRY_DLL ReflectometryReductionOne2
: public ReflectometryWorkflowBase2 {
public:
/// Algorithm's name for identification
const std::string name() const override {
return "ReflectometryReductionOne";
};
/// Summary of algorithms purpose
const std::string summary() const override {
return "Reduces a single TOF/Lambda reflectometry run into a mod Q vs I/I0 "
"workspace. Performs monitor normalization and transmission "
"corrections.";
}
/// Algorithm's version for identification.
int version() const override { return 2; };
const std::vector<std::string> seeAlso() const override {
return {"ReflectometryReductionOneAuto"};
}
/// Algorithm's category for identification.
const std::string category() const override { return "Reflectometry"; };
private:
/** Overridden Algorithm methods **/
// Initialize the algorithm
void init() override;
// Execute the algorithm
void exec() override;
// Validate inputs
std::map<std::string, std::string> validateInputs() override;
// Set default names for output workspaces
void setDefaultOutputWorkspaceNames();
// Create a direct beam workspace from input workspace in wavelength
Mantid::API::MatrixWorkspace_sptr
makeDirectBeamWS(Mantid::API::MatrixWorkspace_sptr inputWS);
// Performs direct beam correction
Mantid::API::MatrixWorkspace_sptr
directBeamCorrection(Mantid::API::MatrixWorkspace_sptr detectorWS);
// Performs transmission or algorithm correction
Mantid::API::MatrixWorkspace_sptr
transOrAlgCorrection(const Mantid::API::MatrixWorkspace_sptr &detectorWS,
const bool detectorWSReduced);
// Performs background subtraction
Mantid::API::MatrixWorkspace_sptr
backgroundSubtraction(Mantid::API::MatrixWorkspace_sptr detectorWS);
// Performs transmission corrections
Mantid::API::MatrixWorkspace_sptr
transmissionCorrection(const Mantid::API::MatrixWorkspace_sptr &detectorWS,
const bool detectorWSReduced);
// Performs transmission corrections using alternative correction algorithms
Mantid::API::MatrixWorkspace_sptr
algorithmicCorrection(const Mantid::API::MatrixWorkspace_sptr &detectorWS);
// Performs monitor corrections
Mantid::API::MatrixWorkspace_sptr
monitorCorrection(Mantid::API::MatrixWorkspace_sptr detectorWS);
// convert to momentum transfer
bool useDetectorAngleForQConversion(const MatrixWorkspace_sptr &ws) const;
Mantid::API::MatrixWorkspace_sptr
convertToQ(const Mantid::API::MatrixWorkspace_sptr &inputWS);
// Get the twoTheta width of a given detector
double getDetectorTwoThetaRange(const size_t spectrumIdx);
// Utility function to create name for diagnostic workspaces
std::string createDebugWorkspaceName(const std::string &inputName);
// Utility function to output a diagnostic workspace to the ADS
void outputDebugWorkspace(const API::MatrixWorkspace_sptr &ws,
const std::string &wsName,
const std::string &wsSuffix, const bool debug,
int &step);
// Create the output workspace in wavelength
Mantid::API::MatrixWorkspace_sptr makeIvsLam();
// Do the reduction by summation in Q
Mantid::API::MatrixWorkspace_sptr
sumInQ(const API::MatrixWorkspace_sptr &detectorWS);
// Do the summation in Q for a single input value
void sumInQProcessValue(const int inputIdx, const double twoTheta,
const double bTwoTheta,
const HistogramData::HistogramX &inputX,
const HistogramData::HistogramY &inputY,
const HistogramData::HistogramE &inputE,
const std::vector<size_t> &detectors,
const size_t outSpecIdx,
const API::MatrixWorkspace_sptr &IvsLam,
std::vector<double> &outputE);
// Share counts to a projected value for summation in Q
void sumInQShareCounts(const double inputCounts, const double inputErr,
const double bLambda, const double lambdaMin,
const double lambdaMax, const size_t outSpecIdx,
const API::MatrixWorkspace_sptr &IvsLam,
std::vector<double> &outputE);
void findWavelengthMinMax(const API::MatrixWorkspace_sptr &inputWS);
// Construct the output workspace
void findIvsLamRange(const API::MatrixWorkspace_sptr &detectorWS,
const std::vector<size_t> &detectors,
const double lambdaMin, const double lambdaMax,
double &projectedMin, double &projectedMax);
// Construct the output workspace
Mantid::API::MatrixWorkspace_sptr
constructIvsLamWS(const API::MatrixWorkspace_sptr &detectorWS);
// Whether summation should be done in Q or the default lambda
bool summingInQ() const;
// Get projected coordinates onto twoThetaR
void getProjectedLambdaRange(const double lambda, const double twoTheta,
const double bLambda, const double bTwoTheta,
const std::vector<size_t> &detectors,
double &lambdaTop, double &lambdaBot,
const bool outerCorners = true);
// Check whether two spectrum maps match
void verifySpectrumMaps(const API::MatrixWorkspace_const_sptr &ws1,
const API::MatrixWorkspace_const_sptr &ws2);
// Find and cache constants
void findDetectorGroups();
void findTheta0();
// Accessors for detectors and theta and lambda values
const std::vector<std::vector<size_t>> &detectorGroups() const {
return m_detectorGroups;
};
double theta0() { return m_theta0; }
double twoThetaR(const std::vector<size_t> &detectors);
size_t twoThetaRDetectorIdx(const std::vector<size_t> &detectors);
double wavelengthMin() { return m_wavelengthMin; };
double wavelengthMax() { return m_wavelengthMax; };
size_t findIvsLamRangeMinDetector(const std::vector<size_t> &detectors);
size_t findIvsLamRangeMaxDetector(const std::vector<size_t> &detectors);
double findIvsLamRangeMin(const Mantid::API::MatrixWorkspace_sptr &detectorWS,
const std::vector<size_t> &detectors,
const double lambda);
double findIvsLamRangeMax(const Mantid::API::MatrixWorkspace_sptr &detectorWS,
const std::vector<size_t> &detectors,
const double lambda);
API::MatrixWorkspace_sptr m_runWS;
const API::SpectrumInfo *m_spectrumInfo;
std::shared_ptr<const Mantid::Geometry::ReferenceFrame> m_refFrame;
bool m_convertUnits; // convert the input workspace to lambda
bool m_normaliseMonitors; // normalise by monitors and direct beam
bool m_normaliseTransmission; // transmission or algorithmic correction
bool m_sum; // whether to do summation
double m_theta0; // horizon angle
// groups of spectrum indices of the detectors of interest
std::vector<std::vector<size_t>> m_detectorGroups;
// Store the min/max wavelength we're interested in. These will be the
// input Wavelength min/max if summing in lambda, or the projected
// versions of these if summing in Q
double m_wavelengthMin;
double m_wavelengthMax;
// True if partial bins should be included in the summation in Q
bool m_partialBins;
};
} // namespace Reflectometry
} // namespace Mantid