Peak.h 9.06 KB
Newer Older
1
2
3
4
5
6
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
7
8
#ifndef MANTID_DATAOBJECTS_PEAK_H_
#define MANTID_DATAOBJECTS_PEAK_H_
9

Owen Arnold's avatar
Owen Arnold committed
10
#include "MantidGeometry/Crystal/IPeak.h"
11
#include "MantidGeometry/Crystal/PeakShape.h"
12
#include "MantidGeometry/Instrument.h"
13
#include "MantidKernel/Logger.h"
14
#include "MantidKernel/Matrix.h"
15
#include "MantidKernel/PhysicalConstants.h"
16
#include "MantidKernel/System.h"
17
#include "MantidKernel/V3D.h"
18
#include <boost/optional.hpp>
19
#include <boost/shared_ptr.hpp>
20

21
namespace Mantid {
22
23
24
25
26

namespace Geometry {
class InstrumentRayTracer;
}

27
28
29
30
31
32
33
namespace DataObjects {

/** Structure describing a single-crystal peak
 *
 * @author Janik Zikovsky
 * @date 2011-04-15 13:24:07.963491
 */
Owen Arnold's avatar
Owen Arnold committed
34
class DLLExport Peak : public Geometry::IPeak {
35
36
37
38
39
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

  Peak();
Hahn, Steven's avatar
Hahn, Steven committed
40
41
42
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QLabFrame,
       boost::optional<double> detectorDistance = boost::none);
43
44
45
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QSampleFrame,
       const Mantid::Kernel::Matrix<double> &goniometer,
Hahn, Steven's avatar
Hahn, Steven committed
46
       boost::optional<double> detectorDistance = boost::none);
47
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
48
       double m_Wavelength);
49
50
51
52
53
54
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
       double m_Wavelength, const Mantid::Kernel::V3D &HKL);
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
       double m_Wavelength, const Mantid::Kernel::V3D &HKL,
       const Mantid::Kernel::Matrix<double> &goniometer);
  Peak(const Geometry::Instrument_const_sptr &m_inst, double scattering,
55
56
       double m_Wavelength);

57
  /// Copy constructor
58
  Peak(const Peak &other);
59

LamarMoore's avatar
LamarMoore committed
60
61
62
63
64
  // MSVC 2015/17 can build with noexcept = default however
  // intellisense still incorrectly reports this as an error despite compiling.
  // https://connect.microsoft.com/VisualStudio/feedback/details/1795240/visual-c-2015-default-move-constructor-and-noexcept-keyword-bug
  // For that reason we still use the supplied default which should be noexcept
  // once the above is fixed we can remove this workaround
65

66
#if defined(_MSC_VER) && _MSC_VER <= 1910
67
68
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
LamarMoore's avatar
LamarMoore committed
69
#elif ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ <= 8))
DavidFair's avatar
DavidFair committed
70
71
  // The noexcept default declaration was fixed in GCC 4.9.0
  // so for versions 4.8.x and below use default only
72
  // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53903
73
74
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
75
#else
76
77
  Peak(Peak &&) noexcept = default;
  Peak &operator=(Peak &&) noexcept = default;
78
#endif
79

80
  // Construct a peak from a reference to the interface
81

Owen Arnold's avatar
Owen Arnold committed
82
  explicit Peak(const Geometry::IPeak &ipeak);
83

84
85
  void setDetectorID(int id) override;
  int getDetectorID() const override;
86
87
88
89
  void addContributingDetID(const int id);
  void removeContributingDetector(const int id);
  const std::set<int> &getContributingDetIDs() const;

90
  void setInstrument(const Geometry::Instrument_const_sptr &inst) override;
91
92
  Geometry::IDetector_const_sptr getDetector() const override;
  Geometry::Instrument_const_sptr getInstrument() const override;
93

94
  bool findDetector() override;
95
  bool findDetector(const Geometry::InstrumentRayTracer &tracer) override;
96

97
  int getRunNumber() const override;
98
  void setRunNumber(int m_runNumber) override;
99

100
  double getMonitorCount() const override;
101
  void setMonitorCount(double m_monitorCount) override;
102

103
104
105
106
  double getH() const override;
  double getK() const override;
  double getL() const override;
  Mantid::Kernel::V3D getHKL() const override;
Lynch, Vickie's avatar
Lynch, Vickie committed
107
  Mantid::Kernel::V3D getIntHKL() const override;
108
109
110
  void setH(double m_H) override;
  void setK(double m_K) override;
  void setL(double m_L) override;
111
  void setBankName(std::string m_bankName);
112
  void setHKL(double H, double K, double L) override;
113
  void setHKL(const Mantid::Kernel::V3D &HKL) override;
114
  void setIntHKL(const Mantid::Kernel::V3D HKL) override;
115
116
  void setSamplePos(double samX, double samY, double samZ) override;
  void setSamplePos(const Mantid::Kernel::V3D &XYZ) override;
117
118
  void resetHKL();

119
120
121
122
  Mantid::Kernel::V3D getQLabFrame() const override;
  Mantid::Kernel::V3D getQSampleFrame() const override;
  Mantid::Kernel::V3D getDetectorPosition() const override;
  Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
123

Hahn, Steven's avatar
Hahn, Steven committed
124
125
126
127
128
129
  void setQSampleFrame(
      const Mantid::Kernel::V3D &QSampleFrame,
      boost::optional<double> detectorDistance = boost::none) override;
  void
  setQLabFrame(const Mantid::Kernel::V3D &QLabFrame,
               boost::optional<double> detectorDistance = boost::none) override;
130

131
132
133
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
  double getScattering() const override;
134
  double getAzimuthal() const override;
135
136
  double getDSpacing() const override;
  double getTOF() const override;
137

138
139
  double getInitialEnergy() const override;
  double getFinalEnergy() const override;
140
  double getEnergyTransfer() const override;
141
142
  void setInitialEnergy(double m_initialEnergy) override;
  void setFinalEnergy(double m_finalEnergy) override;
143

144
145
  double getIntensity() const override;
  double getSigmaIntensity() const override;
146
  double getIntensityOverSigma() const override;
147

148
149
  void setIntensity(double m_intensity) override;
  void setSigmaIntensity(double m_sigmaIntensity) override;
150

151
  double getBinCount() const override;
152
  void setBinCount(double m_binCount) override;
153

154
  Mantid::Kernel::Matrix<double> getGoniometerMatrix() const override;
155
156
  void setGoniometerMatrix(
      const Mantid::Kernel::Matrix<double> &goniometerMatrix) override;
157

158
159
160
  std::string getBankName() const override;
  int getRow() const override;
  int getCol() const override;
161
162
  void setRow(int m_row);
  void setCol(int m_col);
163
164
  void setPeakNumber(int m_peakNumber) override;
  int getPeakNumber() const override;
165
  void setIntMNP(const Mantid::Kernel::V3D MNP) override;
166
  Mantid::Kernel::V3D getIntMNP() const override;
167

168
  virtual Mantid::Kernel::V3D getDetPos() const override;
169
  virtual Mantid::Kernel::V3D getSamplePos() const override;
170
171
  double getL1() const override;
  double getL2() const override;
172

173
  double getValueByColName(const std::string &name_in) const;
174

175
  /// Get the peak shape.
176
  const Mantid::Geometry::PeakShape &getPeakShape() const override;
177
178

  /// Set the PeakShape
179
  void setPeakShape(Mantid::Geometry::PeakShape *shape);
180

181
  /// Set the PeakShape
182
  void setPeakShape(Mantid::Geometry::PeakShape_const_sptr shape);
183

184
  /// Assignment
185
  Peak &operator=(const Peak &other);
186

187
  /// Get the approximate position of a peak that falls off the detectors
188
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
189

190
private:
191
192
  bool findDetector(const Mantid::Kernel::V3D &beam,
                    const Geometry::InstrumentRayTracer &tracer);
193

194
195
196
197
198
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

  /// Detector pointed to
  Geometry::IDetector_const_sptr m_det;
199

200
  /// Name of the parent bank
201
  std::string m_bankName;
202

203
  /// ID of the detector
204
  int m_detectorID;
205

206
207
  /// H of the peak
  double m_H;
208

209
210
  /// K of the peak
  double m_K;
211

212
213
  /// L of the peak
  double m_L;
214

215
  /// Integrated peak intensity
216
  double m_intensity;
217

218
  /// Error (sigma) on peak intensity
219
  double m_sigmaIntensity;
220

221
  /// Count in the bin at the peak
222
  double m_binCount;
223

224
  /// Initial energy of neutrons at the peak
225
  double m_initialEnergy;
226

227
  /// Final energy of the neutrons at peak (normally same as m_InitialEnergy)
228
  double m_finalEnergy;
229

230
231
  /// Orientation matrix of the goniometer angles.
  Mantid::Kernel::Matrix<double> m_GoniometerMatrix;
232

233
234
235
  /// Inverse of the goniometer rotation matrix; used to go from Q in lab frame
  /// to Q in sample frame
  Mantid::Kernel::Matrix<double> m_InverseGoniometerMatrix;
236

237
  /// Originating run number for this peak
238
  int m_runNumber;
239

240
  /// Integrated monitor count over TOF range for this run
241
  double m_monitorCount;
242

243
  /// Cached row in the detector
244
  int m_row;
245

246
  /// Cached column in the detector
247
  int m_col;
248

249
250
251
252
253
254
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
255

256
  /// save values before setHKL is called for use in SortHKL
257
258
259
  double m_orig_H;
  double m_orig_K;
  double m_orig_L;
260

261
  // keep peak number
262
  int m_peakNumber;
263
264
  Mantid::Kernel::V3D m_IntHKL;
  Mantid::Kernel::V3D m_IntMNP;
265

Lynch, Vickie's avatar
Lynch, Vickie committed
266
  /// integer HKL of the peak
267

268
269
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
270
271

  /// Peak shape
272
  Mantid::Geometry::PeakShape_const_sptr m_peakShape;
273
274
275

  /// Static logger
  static Mantid::Kernel::Logger g_log;
276
277

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
278
  std::string convention;
279
};
280
281

} // namespace DataObjects
282
} // namespace Mantid
283

284
#endif /* MANTID_DATAOBJECTS_PEAK_H_ */