Peak.h 8.84 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

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

20
namespace Mantid {
21
22
23
24
25

namespace Geometry {
class InstrumentRayTracer;
}

26
27
28
29
30
31
32
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
33
class DLLExport Peak : public Geometry::IPeak {
34
35
36
37
38
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

  Peak();
Hahn, Steven's avatar
Hahn, Steven committed
39
40
41
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QLabFrame,
       boost::optional<double> detectorDistance = boost::none);
42
43
44
  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
45
       boost::optional<double> detectorDistance = boost::none);
46
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
47
       double m_Wavelength);
48
49
50
51
52
53
  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,
54
55
       double m_Wavelength);

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

LamarMoore's avatar
LamarMoore committed
59
60
61
62
63
  // 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
64

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

159
160
161
  std::string getBankName() const override;
  int getRow() const override;
  int getCol() const override;
162
163
  void setRow(int m_row);
  void setCol(int m_col);
164
165
  void setPeakNumber(int m_peakNumber) override;
  int getPeakNumber() const override;
166

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

232
233
234
  /// 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;
235

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

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

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

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

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

255
  int m_peakNumber;
Martyn Gigg's avatar
Martyn Gigg committed
256
257
  Mantid::Kernel::V3D m_intHKL;
  Mantid::Kernel::V3D m_intMNP;
258

259
260
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
261
262

  /// Peak shape
263
  Mantid::Geometry::PeakShape_const_sptr m_peakShape;
264
265
266

  /// Static logger
  static Mantid::Kernel::Logger g_log;
267
268

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
269
  std::string convention;
270
};
271
272

} // namespace DataObjects
273
} // namespace Mantid