Peak.h 8.23 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/Crystal/PeakShape.h"
6
#include "MantidGeometry/Instrument.h"
7
#include "MantidKernel/Logger.h"
8
#include "MantidKernel/Matrix.h"
9
#include "MantidKernel/PhysicalConstants.h"
10
#include "MantidKernel/System.h"
11
#include "MantidKernel/V3D.h"
12
#include <boost/optional.hpp>
13
#include <boost/shared_ptr.hpp>
14

15
namespace Mantid {
16
17
18
19
20

namespace Geometry {
class InstrumentRayTracer;
}

21
22
23
24
25
26
27
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
28
class DLLExport Peak : public Geometry::IPeak {
29
30
31
32
33
public:
  /// Allow PeakColumn class to directly access members.
  friend class PeakColumn;

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

51
  /// Copy constructor
52
  Peak(const Peak &other);
53

Owen Arnold's avatar
Owen Arnold committed
54
55
56
57
58
// 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
59

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

74
  // Construct a peak from a reference to the interface
75

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

78
79
  void setDetectorID(int id) override;
  int getDetectorID() const override;
80
81
82
83
  void addContributingDetID(const int id);
  void removeContributingDetector(const int id);
  const std::set<int> &getContributingDetIDs() const;

84
  void setInstrument(const Geometry::Instrument_const_sptr &inst) override;
85
86
  Geometry::IDetector_const_sptr getDetector() const override;
  Geometry::Instrument_const_sptr getInstrument() const override;
87

88
  bool findDetector() override;
89
  bool findDetector(const Geometry::InstrumentRayTracer &tracer);
90

91
  int getRunNumber() const override;
92
  void setRunNumber(int m_runNumber) override;
93

94
  double getMonitorCount() const override;
95
  void setMonitorCount(double m_monitorCount) override;
96

97
98
99
100
101
102
103
  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;
104
  void setBankName(std::string m_bankName);
105
  void setHKL(double H, double K, double L) override;
106
  void setHKL(const Mantid::Kernel::V3D &HKL) override;
107
108
  void resetHKL();

109
110
111
112
  Mantid::Kernel::V3D getQLabFrame() const override;
  Mantid::Kernel::V3D getQSampleFrame() const override;
  Mantid::Kernel::V3D getDetectorPosition() const override;
  Mantid::Kernel::V3D getDetectorPositionNoCheck() const override;
113

Lynch, Vickie's avatar
Lynch, Vickie committed
114
115
116
117
118
119
  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;
120

121
122
123
124
125
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
  double getScattering() const override;
  double getDSpacing() const override;
  double getTOF() const override;
126

127
128
  double getInitialEnergy() const override;
  double getFinalEnergy() const override;
129
  double getEnergyTransfer() const override;
130
131
  void setInitialEnergy(double m_initialEnergy) override;
  void setFinalEnergy(double m_finalEnergy) override;
132

133
134
  double getIntensity() const override;
  double getSigmaIntensity() const override;
135
  double getIntensityOverSigma() const override;
136

137
138
  void setIntensity(double m_intensity) override;
  void setSigmaIntensity(double m_sigmaIntensity) override;
139

140
  double getBinCount() const override;
141
  void setBinCount(double m_binCount) override;
142

143
  Mantid::Kernel::Matrix<double> getGoniometerMatrix() const override;
144
145
  void setGoniometerMatrix(
      const Mantid::Kernel::Matrix<double> &goniometerMatrix) override;
146

147
148
149
  std::string getBankName() const override;
  int getRow() const override;
  int getCol() const override;
150
151
  void setRow(int m_row);
  void setCol(int m_col);
152
153
  void setPeakNumber(int m_peakNumber);
  int getPeakNumber() const override;
154

155
  virtual Mantid::Kernel::V3D getDetPos() const override;
156
157
  double getL1() const override;
  double getL2() const override;
158

159
  double getValueByColName(const std::string &name_in) const;
160

161
  /// Get the peak shape.
162
  const Mantid::Geometry::PeakShape &getPeakShape() const override;
163
164

  /// Set the PeakShape
165
  void setPeakShape(Mantid::Geometry::PeakShape *shape);
166

167
  /// Set the PeakShape
168
  void setPeakShape(Mantid::Geometry::PeakShape_const_sptr shape);
169

170
  /// Assignment
171
  Peak &operator=(const Peak &other);
172

173
  /// Get the approximate position of a peak that falls off the detectors
174
  Kernel::V3D getVirtualDetectorPosition(const Kernel::V3D &detectorDir) const;
175

176
private:
177
178
  bool findDetector(const Mantid::Kernel::V3D &beam,
                    const Geometry::InstrumentRayTracer &tracer);
179

180
181
182
183
184
  /// Shared pointer to the instrument (for calculating some values )
  Geometry::Instrument_const_sptr m_inst;

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

186
  /// Name of the parent bank
187
  std::string m_bankName;
188

189
  /// ID of the detector
190
  int m_detectorID;
191

192
193
  /// H of the peak
  double m_H;
194

195
196
  /// K of the peak
  double m_K;
197

198
199
  /// L of the peak
  double m_L;
200

201
  /// Integrated peak intensity
202
  double m_intensity;
203

204
  /// Error (sigma) on peak intensity
205
  double m_sigmaIntensity;
206

207
  /// Count in the bin at the peak
208
  double m_binCount;
209

210
  /// Initial energy of neutrons at the peak
211
  double m_initialEnergy;
212

213
  /// Final energy of the neutrons at peak (normally same as m_InitialEnergy)
214
  double m_finalEnergy;
215

216
217
  /// Orientation matrix of the goniometer angles.
  Mantid::Kernel::Matrix<double> m_GoniometerMatrix;
218

219
220
221
  /// 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;
222

223
  /// Originating run number for this peak
224
  int m_runNumber;
225

226
  /// Integrated monitor count over TOF range for this run
227
  double m_monitorCount;
228

229
  /// Cached row in the detector
230
  int m_row;
231

232
  /// Cached column in the detector
233
  int m_col;
234

235
236
237
238
239
240
  /// Cached source position
  Mantid::Kernel::V3D sourcePos;
  /// Cached sample position
  Mantid::Kernel::V3D samplePos;
  /// Cached detector position
  Mantid::Kernel::V3D detPos;
241

242
  /// save values before setHKL is called for use in SortHKL
243
244
245
  double m_orig_H;
  double m_orig_K;
  double m_orig_L;
246

247
248
249
  // keep peak number
  int m_peakNumber;

250
251
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
252
253

  /// Peak shape
254
  Mantid::Geometry::PeakShape_const_sptr m_peakShape;
255
256
257

  /// Static logger
  static Mantid::Kernel::Logger g_log;
258
259

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
260
  std::string convention;
261
};
262
263

} // namespace DataObjects
264
} // namespace Mantid
265

266
#endif /* MANTID_DATAOBJECTS_PEAK_H_ */