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

LamarMoore's avatar
LamarMoore 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;
LamarMoore's avatar
LamarMoore 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) override;
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
  void setWavelength(double wavelength) override;
  double getWavelength() const override;
  double getScattering() const override;
124
  double getAzimuthal() const override;
125
126
  double getDSpacing() const override;
  double getTOF() const override;
127

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

248
  // keep peak number
249
  int m_peakNumber;
250

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

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

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

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

} // namespace DataObjects
265
} // namespace Mantid
266

267
#endif /* MANTID_DATAOBJECTS_PEAK_H_ */