Peak.h 8.11 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

Hahn, Steven's avatar
Hahn, Steven 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
  virtual Mantid::Kernel::V3D getDetPos() const override;
154
155
  double getL1() const override;
  double getL2() const override;
156

157
  double getValueByColName(const std::string &name_in) const;
158

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

  /// Set the PeakShape
163
  void setPeakShape(Mantid::Geometry::PeakShape *shape);
164

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

168
  /// Assignment
169
  Peak &operator=(const Peak &other);
170

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

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

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

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

184
  /// Name of the parent bank
185
  std::string m_bankName;
186

187
  /// ID of the detector
188
  int m_detectorID;
189

190
191
  /// H of the peak
  double m_H;
192

193
194
  /// K of the peak
  double m_K;
195

196
197
  /// L of the peak
  double m_L;
198

199
  /// Integrated peak intensity
200
  double m_intensity;
201

202
  /// Error (sigma) on peak intensity
203
  double m_sigmaIntensity;
204

205
  /// Count in the bin at the peak
206
  double m_binCount;
207

208
  /// Initial energy of neutrons at the peak
209
  double m_initialEnergy;
210

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

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

217
218
219
  /// 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;
220

221
  /// Originating run number for this peak
222
  int m_runNumber;
223

224
  /// Integrated monitor count over TOF range for this run
225
  double m_monitorCount;
226

227
  /// Cached row in the detector
228
  int m_row;
229

230
  /// Cached column in the detector
231
  int m_col;
232

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

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

245
246
  /// List of contributing detectors IDs
  std::set<int> m_detIDs;
Owen Arnold's avatar
Owen Arnold committed
247
248

  /// Peak shape
249
  Mantid::Geometry::PeakShape_const_sptr m_peakShape;
250
251
252

  /// Static logger
  static Mantid::Kernel::Logger g_log;
253
254

  // ki-kf for Inelastic convention; kf-ki for Crystallography convention
255
  std::string convention;
256
};
257
258

} // namespace DataObjects
259
} // namespace Mantid
260

261
#endif /* MANTID_DATAOBJECTS_PEAK_H_ */