Peak.h 7.84 KB
Newer Older
1
2
#ifndef MANTID_DATAOBJECTS_PEAK_H_
#define MANTID_DATAOBJECTS_PEAK_H_
3

Owen Arnold's avatar
Owen Arnold committed
4
#include "MantidGeometry/Crystal/IPeak.h"
5
#include "MantidGeometry/Instrument.h"
6
#include "MantidKernel/Logger.h"
7
8
#include "MantidKernel/Matrix.h"
#include "MantidKernel/V3D.h"
9
#include "MantidKernel/PhysicalConstants.h"
10
#include "MantidKernel/System.h"
11
#include "MantidGeometry/Crystal/PeakShape.h"
12
#include <boost/shared_ptr.hpp>
13
14
#include <boost/optional.hpp>

15
16
17
18
19
20
21
22
namespace Mantid {
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
23
class DLLExport Peak : public Geometry::IPeak {
24
25
26
27
28
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

  Peak();
Hahn, Steven's avatar
Hahn, Steven committed
29
30
31
  Peak(const Geometry::Instrument_const_sptr &m_inst,
       const Mantid::Kernel::V3D &QLabFrame,
       boost::optional<double> detectorDistance = boost::none);
32
33
34
  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
35
       boost::optional<double> detectorDistance = boost::none);
36
  Peak(const Geometry::Instrument_const_sptr &m_inst, int m_detectorID,
37
       double m_Wavelength);
38
39
40
41
42
43
  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,
44
45
       double m_Wavelength);

46
  /// Copy constructor
47
  Peak(const Peak &other);
48
49

// MSVC 2015/17 can build with noexcept = default however
David Fairbrother's avatar
David Fairbrother committed
50
// intellisense still incorrectly reports this as an error despite compiling.
51
52
53
54
// 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

55
#if defined(_MSC_VER) && _MSC_VER <= 1910
56
57
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
58
#elif((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ <= 8))
DavidFair's avatar
DavidFair committed
59
60
  // The noexcept default declaration was fixed in GCC 4.9.0
  // so for versions 4.8.x and below use default only
61
  // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53903
62
63
  Peak(Peak &&) = default;
  Peak &operator=(Peak &&) = default;
64
#else
65
66
  Peak(Peak &&) noexcept = default;
  Peak &operator=(Peak &&) noexcept = default;
67
#endif
68

69
  // Construct a peak from a reference to the interface
70

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

73
74
  void setDetectorID(int id) override;
  int getDetectorID() const override;
75
76
77
78
  void addContributingDetID(const int id);
  void removeContributingDetector(const int id);
  const std::set<int> &getContributingDetIDs() const;

79
  void setInstrument(const Geometry::Instrument_const_sptr &inst) override;
80
81
  Geometry::IDetector_const_sptr getDetector() const override;
  Geometry::Instrument_const_sptr getInstrument() const override;
82

83
  bool findDetector() override;
84

85
  int getRunNumber() const override;
86
  void setRunNumber(int m_runNumber) override;
87

88
  double getMonitorCount() const override;
89
  void setMonitorCount(double m_monitorCount) override;
90

91
92
93
94
95
96
97
  double getH() const override;
  double getK() const override;
  double getL() const override;
  Mantid::Kernel::V3D getHKL() const override;
  void setH(double m_H) override;
  void setK(double m_K) override;
  void setL(double m_L) override;
98
  void setBankName(std::string m_bankName);
99
  void setHKL(double H, double K, double L) override;
100
  void setHKL(const Mantid::Kernel::V3D &HKL) override;
101
102
  void resetHKL();

103
104
105
106
  Mantid::Kernel::V3D getQLabFrame() const override;
  Mantid::Kernel::V3D getQSampleFrame() const override;
  Mantid::Kernel::V3D getDetectorPosition() const override;
  Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
107

Hahn, Steven's avatar
Hahn, Steven committed
108
109
110
111
112
113
  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;
114

115
116
117
118
119
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
  double getScattering() const override;
  double getDSpacing() const override;
  double getTOF() const override;
120

121
122
  double getInitialEnergy() const override;
  double getFinalEnergy() const override;
123
124
  void setInitialEnergy(double m_initialEnergy) override;
  void setFinalEnergy(double m_finalEnergy) override;
125

126
127
  double getIntensity() const override;
  double getSigmaIntensity() const override;
128

129
130
  void setIntensity(double m_intensity) override;
  void setSigmaIntensity(double m_sigmaIntensity) override;
131

132
  double getBinCount() const override;
133
  void setBinCount(double m_binCount) override;
134

135
  Mantid::Kernel::Matrix<double> getGoniometerMatrix() const override;
136
137
  void setGoniometerMatrix(
      const Mantid::Kernel::Matrix<double> &goniometerMatrix) override;
138

139
140
141
  std::string getBankName() const override;
  int getRow() const override;
  int getCol() const override;
142
143
  void setRow(int m_row);
  void setCol(int m_col);
144

145
  virtual Mantid::Kernel::V3D getDetPos() const override;
146
147
  double getL1() const override;
  double getL2() const override;
148

149
  double getValueByColName(const std::string &name_in) const;
150

151
  /// Get the peak shape.
152
  const Mantid::Geometry::PeakShape &getPeakShape() const override;
153
154

  /// Set the PeakShape
155
  void setPeakShape(Mantid::Geometry::PeakShape *shape);
156

157
  /// Set the PeakShape
158
  void setPeakShape(Mantid::Geometry::PeakShape_const_sptr shape);
159

160
  /// Assignment
161
  Peak &operator=(const Peak &other);
162

163
  /// Get the approximate position of a peak that falls off the detectors
164
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
165

166
private:
167
  bool findDetector(const Mantid::Kernel::V3D &beam);
168

169
170
171
172
173
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

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

175
  /// Name of the parent bank
176
  std::string m_bankName;
177

178
  /// ID of the detector
179
  int m_detectorID;
180

181
182
  /// H of the peak
  double m_H;
183

184
185
  /// K of the peak
  double m_K;
186

187
188
  /// L of the peak
  double m_L;
189

190
  /// Integrated peak intensity
191
  double m_intensity;
192

193
  /// Error (sigma) on peak intensity
194
  double m_sigmaIntensity;
195

196
  /// Count in the bin at the peak
197
  double m_binCount;
198

199
  /// Initial energy of neutrons at the peak
200
  double m_initialEnergy;
201

202
  /// Final energy of the neutrons at peak (normally same as m_InitialEnergy)
203
  double m_finalEnergy;
204

205
206
  /// Orientation matrix of the goniometer angles.
  Mantid::Kernel::Matrix<double> m_GoniometerMatrix;
207

208
209
210
  /// 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;
211

212
  /// Originating run number for this peak
213
  int m_runNumber;
214

215
  /// Integrated monitor count over TOF range for this run
216
  double m_monitorCount;
217

218
  /// Cached row in the detector
219
  int m_row;
220

221
  /// Cached column in the detector
222
  int m_col;
223

224
225
226
227
228
229
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
230

231
  /// save values before setHKL is called for use in SortHKL
232
233
234
  double m_orig_H;
  double m_orig_K;
  double m_orig_L;
235

236
237
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
238
239

  /// Peak shape
240
  Mantid::Geometry::PeakShape_const_sptr m_peakShape;
241
242
243

  /// Static logger
  static Mantid::Kernel::Logger g_log;
244
245

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
246
  std::string convention;
247
};
248
249
250
251

} // namespace Mantid
} // namespace DataObjects

252
#endif /* MANTID_DATAOBJECTS_PEAK_H_ */