Mantid
Loading...
Searching...
No Matches
IntegratePeakTimeSlices.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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/*
8 * IntegratePeakTimeSlices.h
9 *
10 * Created on: May 5, 2011
11 * Author: ruth
12 */
13#pragma once
14
15#include "MantidAPI/Algorithm.h"
20#include "MantidCrystal/DllConfig.h"
25#include "MantidKernel/V3D.h"
27
28#include <array>
29
30// Forward Declarations
31namespace Mantid {
32namespace HistogramData {
33class HistogramX;
34}
35} // namespace Mantid
36namespace Mantid {
37namespace Crystal {
48public:
50
51 DataModeHandler(const DataModeHandler &handler);
52 DataModeHandler(double baseRCRadius, double lastRCRadius, double lastRow, double lastCol, double CellWidth,
53 double CellHeight, bool CalcVariance, int MinCol, int MaxCol, int MinRow, int MaxRow) {
54 init();
55 this->baseRCRadius = baseRCRadius;
56 this->lastRCRadius = lastRCRadius;
57 this->lastRow = lastRow;
58 this->lastCol = lastCol;
59 this->CellWidth = CellWidth;
60 this->CellHeight = CellHeight;
61 this->CalcVariance = CalcVariance;
62 this->MaxCol = MaxCol;
63 this->MaxRow = MaxRow;
64 this->MinCol = MinCol;
65 this->MinRow = MinRow;
66 }
67
68 void setTime(double time) { this->time = time; }
69
70 // Returns true if "Edge Peak" otherwise returns false
71 bool setStatBase(std::vector<double> const &StatBase);
72
73 bool isEdgePeak(const double *params, int nparams);
74
75 void setHeightHalfWidthInfo(const MantidVec &xvals, const MantidVec &yvals, const MantidVec &counts);
76
78 void setCurrentCenter(const Kernel::V3D &newCenter) {
79 Kernel::V3D XX(newCenter);
80 currentPosition = XX;
81 }
82
83 double getCurrentRadius() { return currentRadius; }
85 void updateEdgeXsize(double newsize) {
86 if (EdgeX < 0)
87
88 EdgeX = newsize;
89
90 else if (newsize < EdgeX)
91
92 EdgeX = newsize;
93 }
94
95 void updateEdgeYsize(double newsize) {
96 if (EdgeY < 0)
97
98 EdgeY = newsize;
99
100 else if (newsize < EdgeY)
101
102 EdgeY = newsize;
103 }
104
105 void CalcVariancesFromData(double background, double meanx, double meany, double &Varxx, double &Varxy, double &Varyy,
106 const std::vector<double> &StatBase);
107
108 bool IsEnoughData(const double *ParameterValues, Kernel::Logger &);
109
110 double getNewRCRadius();
111
112 double getInitBackground() { return back_calc; }
113
114 double getInitRow() { return row_calc; }
115
116 double getInitCol() { return col_calc; }
117
118 double getInitIntensity() { return Intensity_calc; }
119
120 double getInitVarx() { return Vx_calc; }
121
122 double getInitVary() { return Vy_calc; }
123
124 double getInitVarxy() { return Vxy_calc; }
125
126 std::string CalcConstraints(std::vector<std::pair<double, double>> &Bounds, bool CalcVariances);
127 std::string getTies() { return ""; }
128
129 bool CalcVariances();
130
131 std::vector<double> GetParams(double b);
132
133 double StatBaseVals(int index) {
134 if (index < 0 || index >= (int)StatBase.size())
135 return 0.0;
136 return StatBase[index];
137 }
138
139 double CalcISAWIntensity(const double *params);
140
141 double CalcISAWIntensityVariance(const double *params, const double *errs, double chiSqOvDOF);
142
146 double CalcSampleIntensityMultiplier(const double *params) const;
147
153 std::vector<double> InitValues(double Varx, double Vary, double b);
158
159 double lastRow;
161 double lastCol;
163 double time;
164 double CellWidth;
166
167 double VarxHW, VaryHW;
170 std::vector<double> StatBase;
171
172 double EdgeX, EdgeY;
175 bool case4; // if true result of successful merge of dir =1 chan=0 and chan=1
177
178private:
179 void init() {
180 baseRCRadius = -1;
181 lastRCRadius = -1;
182 lastRow = -1;
183 lastCol = -1;
184 EdgeX = EdgeY = -1;
185 calcNewRCRadius = -1;
186 MaxRow = -1;
187 MaxCol = -1;
188 MinRow = -1;
189 MinCol = -1;
190 time = -1;
191 CalcVariance = true;
192 CellWidth = CellHeight = 0;
193 currentRadius = -1;
195 lastISAWVariance = -1;
198 case4 = false;
199
200 VarxHW = -1;
201 VaryHW = -1;
203 }
204};
205
206class MANTID_CRYSTAL_DLL IntegratePeakTimeSlices : public Mantid::API::Algorithm {
207public:
210
212 ~IntegratePeakTimeSlices() override;
213
215 const std::string name() const override { return "IntegratePeakTimeSlices"; }
216
218 const std::string summary() const override {
219 return "The algorithm uses CurveFitting::BivariateNormal for fitting a "
220 "time slice";
221 }
222
224 int version() const override { return 1; }
225 const std::vector<std::string> seeAlso() const override { return {"PeakIntegration"}; }
226
228 const std::string category() const override { return "Crystal\\Integration"; }
229
230private:
231 void init() override;
232 void exec() override;
233
235
236 std::string m_AttributeNames[20];
237
238 std::string m_ParameterNames[7];
239
240 std::shared_ptr<DataModeHandler> m_AttributeValues;
241 std::array<double, 7> m_ParameterValues;
242
244
245 int *m_NeighborIDs; // Stores IDs of nearest neighbors
246 double m_R0;
247
251 double m_ROW;
252 double m_COL;
254 double m_cellWidth;
258
259 void SetUpData(API::MatrixWorkspace_sptr &Data, API::MatrixWorkspace_const_sptr const &inpWkSpace,
260 const std::shared_ptr<Geometry::IComponent> &comp, const int chanMin, const int chanMax, double CentX,
261 double CentY, Kernel::V3D &CentNghbr,
262
263 double &neighborRadius, // from CentDet
264 double Radius, std::string &spec_idList);
265
266 bool getNeighborPixIDs(const std::shared_ptr<Geometry::IComponent> &comp, const Kernel::V3D &Center, double &Radius,
267 int *&ArryofID);
268
269 int CalculateTimeChannelSpan(Geometry::IPeak const &peak, const double dQ, const Mantid::HistogramData::HistogramX &X,
270 const int specNum, int &Centerchan);
271
272 double CalculatePositionSpan(DataObjects::Peak const &peak, const double dQ);
273
274 void InitializeColumnNamesInTableWorkspace(DataObjects::TableWorkspace_sptr &TabWS);
275
278 void SetUpData1(API::MatrixWorkspace_sptr &Data, API::MatrixWorkspace_const_sptr const &inpWkSpace, const int chanMin,
279 const int chanMax, double Radius, const Kernel::V3D &CentPos, std::string &spec_idList
280
281 );
282
286 void PreFit(API::MatrixWorkspace_sptr &Data, double &chisqOverDOF, bool &done, std::vector<std::string> &names,
287 std::vector<double> &params, std::vector<double> &errs, double lastRow, double lastCol,
288 double neighborRadius);
289
290 void Fit(API::MatrixWorkspace_sptr &Data, double &chisqOverDOF, bool &done, std::vector<std::string> &names,
291 std::vector<double> &params, std::vector<double> &errs, double lastRow, double lastCol,
292 double neighborRadius);
293
294 std::string CalculateFunctionProperty_Fit();
295
296 bool isGoodFit(std::vector<double> const &params, std::vector<double> const &errs,
297 std::vector<std::string> const &names, double chisqOverDOF);
298 // returns last row added
299 int UpdateOutputWS(DataObjects::TableWorkspace_sptr &TabWS, const int dir, const double chan,
300 std::vector<double> const &params, std::vector<double> const &errs,
301 std::vector<std::string> const &names, const double Chisq, const double time,
302 std::string spec_idList);
303
304 void updatePeakInformation(std::vector<double> const &params, std::vector<double> const &errs,
305 std::vector<std::string> const &names, double &TotVariance, double &TotIntensity,
306 double const TotSliceIntensity, double const TotSliceVariance, double const chisqdivDOF,
307 const int ncells);
308
309 void updateStats(const double intensity, const double variance, const double row, const double col,
310 std::vector<double> &StatBase);
311
312 int findNameInVector(std::string const &oneName, std::vector<std::string> const &nameList);
313
314 double CalculateIsawIntegrateError(const double background, const double backError, const double ChiSqOverDOF,
315 const double TotVariance, const int ncells);
316
317 void FindPlane(Kernel::V3D &center, Kernel::V3D &xvec, Kernel::V3D &yvec, double &ROW, double &COL, int &NROWS,
318 int &NCOLS, double &pixWidthx, double &pixHeighty, DataObjects::Peak const &peak) const;
319
320 int findTimeChannel(const Mantid::HistogramData::HistogramX &X, const double time);
321
322 // returns true if Neighborhood list is changed
323 bool updateNeighbors(const std::shared_ptr<Geometry::IComponent> &comp, const Kernel::V3D &CentPos,
324 const Kernel::V3D &oldCenter, double NewRadius, double &neighborRadius);
325};
326} // namespace Crystal
327} // namespace Mantid
double radius
Definition: Rasterize.cpp:31
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Integrates each time slice using the BivariateNormal formula, adding the results to the peak object.
void setHeightHalfWidthInfo(const MantidVec &xvals, const MantidVec &yvals, const MantidVec &counts)
For edge peaks, the sample standard deviations do not work.
double CalcISAWIntensity(const double *params)
Calculates the Intensity designed for Edge Peaks.
double CalcISAWIntensityVariance(const double *params, const double *errs, double chiSqOvDOF)
Calculates the Error in the Intensity designed for Edge Peaks.
std::vector< double > InitValues(double Varx, double Vary, double b)
Returns init values with background and variances replaced by arguments.
bool isEdgePeak(const double *params, int nparams)
Determines if a Peak is an edge peak.
bool CalcVariances()
Determines whether the Variances can be calculated.
double getNewRCRadius()
Calculates the new radius for neighborhoods so as to include almost all of a peak.
void CalcVariancesFromData(double background, double meanx, double meany, double &Varxx, double &Varxy, double &Varyy, const std::vector< double > &StatBase)
Utility method to calculate variances from data given background and means.
double CalcSampleIntensityMultiplier(const double *params) const
For Edge Peaks.
std::vector< double > GetParams(double b)
Calculates the initial values of the parameters given background b.
DataModeHandler(double baseRCRadius, double lastRCRadius, double lastRow, double lastCol, double CellWidth, double CellHeight, bool CalcVariance, int MinCol, int MaxCol, int MinRow, int MaxRow)
bool IsEnoughData(const double *ParameterValues, Kernel::Logger &)
Calculates if there is enough data to for there to be a peak.
std::string CalcConstraints(std::vector< std::pair< double, double > > &Bounds, bool CalcVariances)
Calculates the string form of the constraints to be sent to the Fit Algorithm and also saves it in a ...
bool setStatBase(std::vector< double > const &StatBase)
Sets the Accumulated data values into this class, then updates other information like initial values.
void setCurrentCenter(const Kernel::V3D &newCenter)
double m_COL
for Describing the Column(or 0) describing the center of the
Kernel::V3D m_center
for Describing the Plane at the Peak
Kernel::V3D m_yvec
for Describing the Plane at the Peak
Kernel::V3D m_xvec
for Describing the Plane at the Peak
std::shared_ptr< DataModeHandler > m_AttributeValues
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
double m_ROW
for Describing the Row(or 0) describing the center of the Peak
double m_cellHeight
for Describing the Plane at the Peak
int version() const override
Algorithm's version for identification overriding a virtual method.
double m_R0
for Weak Peaks, these can be set using info from close
const std::string summary() const override
Summary of algorithms purpose.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
A generic fitting algorithm.
Definition: Fit.h:78
Structure describing a single-crystal peak.
Definition: Peak.h:34
Structure describing a single-crystal peak.
Definition: IPeak.h:26
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
Class for 3D vectors.
Definition: V3D.h:34
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
Helper class which provides the Collimation Length for SANS instruments.
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition: cow_ptr.h:172
Peak indexing algorithm, which works by assigning multiple possible HKL values to each peak and then ...
Definition: IndexSXPeaks.h:29